Module: AnyView::Helpers::AssetTagHelpers
- Defined in:
- lib/any_view/asset_tag_helpers.rb
Constant Summary collapse
- MAIL_ATTRIBUTES =
[:cc, :bcc, :subject, :body]
Instance Method Summary collapse
-
#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(“/url”, :class => “foo”){ “link text” } link_to ‘click me’, ‘/dashboard’, :class => ‘linky’.
-
#mail_to(email, caption = nil, options = {}) ⇒ Object
Creates a mail link element with given name and caption mail_to “[email protected]” => <a href=“[email protected]”>[email protected]</a> mail_to “[email protected]”, “My Email” => <a href=“[email protected]”>My Email</a>.
-
#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
#image_path(src) ⇒ Object
Returns the path to the image, either relative or absolute
54 55 56 57 |
# File 'lib/any_view/asset_tag_helpers.rb', line 54 def image_path(src) src.gsub!(/\s/, '') src =~ %r{^\s*(/|http)} ? src : uri_root_path('images', src) end |
#image_tag(url, options = {}) ⇒ Object
Creates an image element with given url and options image_tag(‘icons/avatar.png’)
35 36 37 38 |
# File 'lib/any_view/asset_tag_helpers.rb', line 35 def image_tag(url, ={}) .reverse_merge!(:src => image_path(url)) tag(:img, ) end |
#javascript_include_tag(*sources) ⇒ Object
javascript_include_tag ‘application’, ‘special’
48 49 50 51 |
# File 'lib/any_view/asset_tag_helpers.rb', line 48 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(“/url”, :class => “foo”){ “link text” } link_to ‘click me’, ‘/dashboard’, :class => ‘linky’
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/any_view/asset_tag_helpers.rb', line 9 def link_to(*args, &block) = args. text, url = args if url.nil? url = text text = capture_content(&block) end .reverse_merge!(:href => url) [:content] = text result = tag(:a, ) block.nil? ? result : concat_content(result) end |
#mail_to(email, caption = nil, options = {}) ⇒ Object
Creates a mail link element with given name and caption mail_to “[email protected]” => <a href=“[email protected]”>[email protected]</a> mail_to “[email protected]”, “My Email” => <a href=“[email protected]”>My Email</a>
25 26 27 28 29 30 31 |
# File 'lib/any_view/asset_tag_helpers.rb', line 25 def mail_to(email, =nil, ={}) , = .partition{|k,v| MAIL_ATTRIBUTES.include?(k)} , = Hash[], Hash[] mail_query = Rack::Utils.build_query().gsub(/\+/, '%20').gsub('%40', '@') mail_href = "mailto:#{email}"; mail_href << "?#{mail_query}" if mail_query.present? link_to ( || email), mail_href, end |
#stylesheet_link_tag(*sources) ⇒ Object
Returns a stylesheet link tag for the sources specified as arguments stylesheet_link_tag ‘style’, ‘application’, ‘layout’
42 43 44 45 |
# File 'lib/any_view/asset_tag_helpers.rb', line 42 def stylesheet_link_tag(*sources) = sources..symbolize_keys sources.collect { |sheet| stylesheet_tag(sheet, ) }.join("\n") end |