Created
January 19, 2012 09:52
-
-
Save mimosz/1639114 to your computer and use it in GitHub Desktop.
帮着优化优化呗~~
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def show_props(str) | |
props = str.split(';') # 切割 | |
if props.is_a?(Array) | |
str = "<dl class='props'>" | |
props.each do |property| | |
prop_arr = property.split(':') # 切割 | |
if prop_arr.is_a?(Array) && prop_arr.count == 4 | |
str += "<dt title='#{prop_arr[0]}'>#{prop_arr[2]}</dt><dd title='#{prop_arr[1]}'>#{prop_arr[3]}</dd>" | |
else | |
str += "<dt class='warning'>提示:</dt><dd>无属性</dd>" | |
end | |
end | |
str += "</dl>" | |
end | |
str | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Array#split => # an array
所以应该不需要再判断是不是数组了吧另外,像
prop_arr[0]
这种 看了完全不知所云啊 能不能有更好的办法呢其实在view里面使用helper一点也不OO啊 建议看看
draper