Module: Flatrack::View::TagHelper
- Includes:
- ERB::Util, CaptureHelper
- Included in:
- Flatrack::View, LinkHelper
- Defined in:
- lib/flatrack/view/tag_helper.rb
Overview
View helpers for rendering various html tags
Constant Summary collapse
- PRE_CONTENT_STRINGS =
{ textarea: "\n" }
- BOOLEAN_ATTRIBUTES =
%w(disabled readonly multiple checked autobuffer autoplay controls loop selected hidden scoped async defer reversed ismap seamless muted required autofocus novalidate formnovalidate open pubdate itemscope allowfullscreen default inert sortable truespeed typemustmatch).to_set
Instance Method Summary collapse
-
#html_tag(name, *args, &block) ⇒ Object
Creates an HTML tag.
-
#image_tag(uri, options = {}) ⇒ String
Returns an HTML image tag.
-
#javascript_tag(uri) ⇒ String
Returns an HTML script tag for javascript.
-
#stylesheet_tag(uri) ⇒ String
Returns an HTML link tag for css.
Instance Method Details
#html_tag(name, content, options = {}) ⇒ String #html_tag(name, options = {}) { ... } ⇒ String
Creates an HTML tag
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/flatrack/view/tag_helper.rb', line 40 def html_tag(name, *args, &block) content, , escape = args if block_given? check_arguments [name, *args], 1..3 , escape = content, content = capture(&block) else check_arguments [name, *args], 2..4 end escape = true if escape.nil? html_tag_string(name, content, , escape) end |
#image_tag(uri, options = {}) ⇒ String
Returns an HTML image tag
57 58 59 60 61 |
# File 'lib/flatrack/view/tag_helper.rb', line 57 def image_tag(uri, = {}) uri = asset_path(uri) unless uri =~ %r{^(http)?(s)?:?\/\/} .merge! src: uri html_tag(:img, nil, ) end |
#javascript_tag(uri) ⇒ String
Returns an HTML script tag for javascript
66 67 68 69 |
# File 'lib/flatrack/view/tag_helper.rb', line 66 def javascript_tag(uri) uri = asset_path(uri) + '.js' if uri.is_a? Symbol html_tag(:script, '', src: uri, type: 'application/javascript') end |
#stylesheet_tag(uri) ⇒ String
Returns an HTML link tag for css
74 75 76 77 |
# File 'lib/flatrack/view/tag_helper.rb', line 74 def stylesheet_tag(uri) uri = asset_path(uri) + '.css' if uri.is_a? Symbol html_tag(:link, nil, rel: 'stylesheet', type: 'text/css', href: uri) end |