Module: SinatraMore::AssetTagHelpers
- Defined in:
- lib/sinatra_more/markup_plugin/asset_tag_helpers.rb
Instance Method Summary collapse
-
#flash_tag(kind, options = {}) ⇒ Object
Creates a div to display the flash of given type if it exists flash_tag(:notice, :class => ‘flash’, :id => ‘flash-notice’).
-
#image_path(src) ⇒ Object
Returns the path to the image, either relative or absolute.
-
#image_tag(url, options = {}) ⇒ Object
Creates an image element with given url and options image_tag(‘icons/avatar.png’).
-
#javascript_include_tag(*sources) ⇒ Object
javascript_include_tag ‘application’, ‘special’.
-
#link_to(*args, &block) ⇒ Object
Creates a link element with given name, url and options link_to ‘click me’, ‘/dashboard’, :class => ‘linky’ link_to(‘/dashboard’, :class => ‘blocky’) do …
-
#stylesheet_link_tag(*sources) ⇒ Object
Returns a stylesheet link tag for the sources specified as arguments stylesheet_link_tag ‘style’, ‘application’, ‘layout’.
Instance Method Details
#flash_tag(kind, options = {}) ⇒ Object
Creates a div to display the flash of given type if it exists flash_tag(:notice, :class => ‘flash’, :id => ‘flash-notice’)
6 7 8 9 10 11 |
# File 'lib/sinatra_more/markup_plugin/asset_tag_helpers.rb', line 6 def flash_tag(kind, ={}) flash_text = flash[kind] return '' if flash_text.blank? .reverse_merge!(:class => 'flash') content_tag(:div, flash_text, ) end |
#image_path(src) ⇒ Object
Returns the path to the image, either relative or absolute
52 53 54 55 |
# File 'lib/sinatra_more/markup_plugin/asset_tag_helpers.rb', line 52 def image_path(src) src.gsub!(/\s/, '') src =~ %r{^\s*(/|http)} ? src : File.join('/images', src) end |
#image_tag(url, options = {}) ⇒ Object
Creates an image element with given url and options image_tag(‘icons/avatar.png’)
33 34 35 36 |
# File 'lib/sinatra_more/markup_plugin/asset_tag_helpers.rb', line 33 def image_tag(url, ={}) .reverse_merge!(:src => image_path(url)) tag(:img, ) end |
#javascript_include_tag(*sources) ⇒ Object
javascript_include_tag ‘application’, ‘special’
46 47 48 49 |
# File 'lib/sinatra_more/markup_plugin/asset_tag_helpers.rb', line 46 def javascript_include_tag(*sources) = sources..symbolize_keys sources.collect { |script| javascript_tag(script, ) }.join("\n") end |
#link_to(*args, &block) ⇒ Object
Creates a link element with given name, url and options link_to ‘click me’, ‘/dashboard’, :class => ‘linky’ link_to(‘/dashboard’, :class => ‘blocky’) do … end parameters: name, url=‘javascript:void(0)’, options={}, &block
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/sinatra_more/markup_plugin/asset_tag_helpers.rb', line 17 def link_to(*args, &block) if block_given? url, = (args[0] || 'javascript:void(0);'), (args[1] || {}) .reverse_merge!(:href => url) link_content = capture_html(&block) result_link = content_tag(:a, link_content, ) block_is_template?(block) ? concat_content(result_link) : result_link else name, url, = args.first, (args[1] || 'javascript:void(0);'), (args[2] || {}) .reverse_merge!(:href => url) content_tag(:a, name, ) end end |
#stylesheet_link_tag(*sources) ⇒ Object
Returns a stylesheet link tag for the sources specified as arguments stylesheet_link_tag ‘style’, ‘application’, ‘layout’
40 41 42 43 |
# File 'lib/sinatra_more/markup_plugin/asset_tag_helpers.rb', line 40 def stylesheet_link_tag(*sources) = sources..symbolize_keys sources.collect { |sheet| stylesheet_tag(sheet, ) }.join("\n") end |