Module: Utils::ViewHelper
- Defined in:
- lib/utils/view_helper.rb
Instance Method Summary collapse
-
#bool_label(val) ⇒ Object
输出布尔值标签.
-
#info_paginate(collection, options = {}) ⇒ Object
分页显示标签.
-
#str_trim(str, length, postfix = '...') ⇒ Object
字符串截取.
-
#thumbnail(file, width = 150, use_thumb = true) ⇒ Object
输出预览图.
Instance Method Details
#bool_label(val) ⇒ Object
输出布尔值标签
5 6 7 8 9 |
# File 'lib/utils/view_helper.rb', line 5 def bool_label(val) output = "<span class=\"label " + (val ? 'label-success' : 'label-default') + "\">" + (val ? '是' : '否') +"</span>" output.html_safe end |
#info_paginate(collection, options = {}) ⇒ Object
分页显示标签
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/utils/view_helper.rb', line 33 def info_paginate(collection, = {}) pre_page = collection.current_page - 1 next_page = collection.current_page + 1 html = "" html += "<div id=\"" + [:container] = "\">" unless [:container].nil? html += "<span>共<span>" + collection.total_entries.to_s + "</span>条记录<span>" + collection.total_pages.to_s + "</span>页</span>" if [:show_total] html += "<span><a id=\"first\" href=\"" + url_for(params.merge(:page=> "1")) + "\">第一页</a></span>" if [:full_link] && collection.current_page > 1 if pre_page > 0 html += "<span><a id=\"prev\" href=\"" + url_for(params.merge(:page=> pre_page)) + "\"" html += " class=\"" + [:class] + "\"" unless [:class].nil? html += ">上一页</a></span>" end html += "<span>当前第<span>" + collection.current_page.to_s + "</span>页</span>" if [:full_link] if next_page <= collection.total_pages html += "<span><a id=\"next\" href=\"" + url_for(params.merge(:page=> next_page)) + "\"" html += " class=\"" + [:class] + "\"" unless [:class].nil? html += ">下一页</a></span>" end html += "<span><a id=\"last\" href=\"" + url_for(params.merge(:page=> collection.total_pages)) + "\">最后一页</a></span>" if [:full_link] && collection.current_page < collection.total_pages html += "</div>" unless [:container].nil? html.html_safe end |
#str_trim(str, length, postfix = '...') ⇒ Object
字符串截取
28 29 30 |
# File 'lib/utils/view_helper.rb', line 28 def str_trim(str,length,postfix='...') str[0,length]+(str.length > length ? postfix : "") if str end |
#thumbnail(file, width = 150, use_thumb = true) ⇒ Object
输出预览图
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/utils/view_helper.rb', line 12 def thumbnail(file,width=150,use_thumb=true) output = '暂无图片' unless file.blank? if use_thumb thumb_file = Utils::FileUtil.get_thumb_file(file) full_name = Rails.root.join("public",thumb_file.to_s) file = thumb_file if File.file?(full_name) end file = "/" + file if !file.start_with?("/") && !file.start_with?("http://") output = "<div class=\"img-thumbnail\">" + image_tag(file,:width=>width) +"</div>" end output.html_safe end |