Module: Reins::View::Helpers
- Included in:
- Controller, Reins::View
- Defined in:
- lib/reins/view/helpers.rb
Constant Summary collapse
- VOID_ELEMENTS =
%i[area base br col embed hr img input link meta source track wbr].freeze
Instance Method Summary collapse
- #image_tag(src, **attrs) ⇒ Object
- #javascript_include_tag(name) ⇒ Object
- #link_to(text, url, **attrs) ⇒ Object
- #stylesheet_link_tag(name) ⇒ Object
- #tag(name, content = nil, **attrs) ⇒ Object
- #url_for(path, **query) ⇒ Object
Instance Method Details
#image_tag(src, **attrs) ⇒ Object
20 21 22 |
# File 'lib/reins/view/helpers.rb', line 20 def image_tag(src, **attrs) tag(:img, src: "/#{src}", **attrs) end |
#javascript_include_tag(name) ⇒ Object
34 35 36 |
# File 'lib/reins/view/helpers.rb', line 34 def javascript_include_tag(name) tag(:script, "", src: "/js/#{name}.js") end |
#link_to(text, url, **attrs) ⇒ Object
8 9 10 |
# File 'lib/reins/view/helpers.rb', line 8 def link_to(text, url, **attrs) tag(:a, text, href: url, **attrs) end |
#stylesheet_link_tag(name) ⇒ Object
30 31 32 |
# File 'lib/reins/view/helpers.rb', line 30 def stylesheet_link_tag(name) tag(:link, rel: "stylesheet", href: "/css/#{name}.css") end |
#tag(name, content = nil, **attrs) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/reins/view/helpers.rb', line 12 def tag(name, content = nil, **attrs) if VOID_ELEMENTS.include?(name) "<#{name}#{format_attrs(attrs)}>" else "<#{name}#{format_attrs(attrs)}>#{content}</#{name}>" end end |
#url_for(path, **query) ⇒ Object
24 25 26 27 28 |
# File 'lib/reins/view/helpers.rb', line 24 def url_for(path, **query) return path if query.empty? "#{path}?#{query.map { |k, v| "#{k}=#{CGI.escape(v.to_s)}" }.join('&')}" end |