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, content_or_options_with_block = nil, options = nil, escape = true, &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 |
# File 'lib/flatrack/view/tag_helper.rb', line 40 def html_tag(name, = nil, = nil, escape = true, &block) if block_given? if .is_a?(Hash) = end html_tag_string(name, capture(&block), , escape) else html_tag_string(name, , , escape) end end |
#image_tag(uri, options = {}) ⇒ String
Returns an HTML image tag
56 57 58 59 60 |
# File 'lib/flatrack/view/tag_helper.rb', line 56 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
65 66 67 68 |
# File 'lib/flatrack/view/tag_helper.rb', line 65 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
73 74 75 76 |
# File 'lib/flatrack/view/tag_helper.rb', line 73 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 |