Module: TJBootstrapHelper::Helper
- Defined in:
- lib/tj_bootstrap_helper/helper.rb
Instance Method Summary collapse
-
#nav_li(*args, &block) ⇒ Object
Just like
link_to
, but wrap with li tag and set class=“active” to corresponding page. - #notice_message ⇒ Object
-
#page_header(*args, &block) ⇒ Object
title, size = 1.
- #record_message(object) ⇒ Object
-
#spans(resources, options = {}, &block) ⇒ Object
- Options span
-
integer between 1..12.
-
#thumbs(resources, image_url_method, options = {}, &block) ⇒ Object
- Options span
-
integer between 1..12.
Instance Method Details
#nav_li(*args, &block) ⇒ Object
Just like link_to
, but wrap with li tag and set class=“active” to corresponding page.
42 43 44 45 46 47 48 49 |
# File 'lib/tj_bootstrap_helper/helper.rb', line 42 def nav_li *args, &block = (block_given? ? args.first : args.second) || {} url = url_for() active = "active" if url == request.path || url == request.url content_tag :li, :class => active do link_to *args, &block end end |
#notice_message ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/tj_bootstrap_helper/helper.rb', line 7 def = [] flash.each do |type, | type = case type when :notice then :success when :alert then :error end content = content_tag :div, :class => "alert fade in alert-#{type}" do ("x", :class => "close", "data-dismiss" => "alert") + end << content if .present? end .join("\n").html_safe end |
#page_header(*args, &block) ⇒ Object
title, size = 1
size = 1, &block
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/tj_bootstrap_helper/helper.rb', line 25 def page_header *args, &block if block_given? size = (1..6) === args.first ? args.first : 1 content_tag :div, :class => "page-header" do content_tag "h#{size}" do capture(&block) end end else title = args.first size = (1..6) === args.second ? args.second : 1 content_tag :div, content_tag("h#{size}", title), :class => "page-header" end end |
#record_message(object) ⇒ Object
3 4 5 |
# File 'lib/tj_bootstrap_helper/helper.rb', line 3 def object object, :class=>"alert alert-block alert-error", :header_tag=>"h4" end |
#spans(resources, options = {}, &block) ⇒ Object
Options
- span
-
integer between 1..12. Item size.
- slice
-
integer between 1..12. Items per slice (row).
- fluid
-
boolean. Whether the div tag is fluid.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/tj_bootstrap_helper/helper.rb', line 55 def spans resources, = {}, &block return unless resources.is_a?(Array) || resources.is_a?(ActiveRecord::Relation) [:span] ||= 4 [:slice] ||= 12/[:span] [:fluid] ||= false klass = [:fluid] ? "row-fluid" : "row" ret = "".html_safe resources.each_slice([:slice]) do |slice| ret += content_tag :div, :class=>klass do slice.inject("".html_safe) do |sum, resource| send_args = resource.is_a?(ActiveRecord::Base) ? [:content_tag_for, :div, resource] : [:content_tag, :div] send_args << {:class => "span#{[:span]}"} sum + send(*send_args) do capture(resource, &block) end end end end ret end |
#thumbs(resources, image_url_method, options = {}, &block) ⇒ Object
Options
- span
-
integer between 1..12. Item size.
- slice
-
integer between 1..12. Items per slice.
- url_method
-
string or symbol. URL method of items, default is resources’ RESTful URL.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/tj_bootstrap_helper/helper.rb', line 81 def thumbs resources, image_url_method, = {}, &block return unless resources.is_a?(Array) || resources.is_a?(ActiveRecord::Relation) [:span] ||= 4 [:slice] ||= 12/[:span] ret = "".html_safe resources.each_slice([:slice]) do |slice| ret += content_tag :ul, :class => "thumbnails" do slice.inject("".html_safe) do |sum, resource| img_url = resource.send(image_url_method) url = [:url_method] ? resource.send([:url_method]) : url_for(resource) send_args = resource.is_a?(ActiveRecord::Base) ? [:content_tag_for, :li, resource] : [:content_tag, :li] send_args << {:class => "span#{[:span]}"} sum + send(*send_args) do if block_given? content_tag :div, :class => "thumbnail" do image_tag(img_url) + capture(resource, &block) end else link_to image_tag(img_url), url, :class => "thumbnail" end end end end end ret end |