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

Instance Method Details

#html_tag(name, content, options = {}) ⇒ String #html_tag(name, options = {}) { ... } ⇒ String

Creates an HTML tag

Overloads:

  • #html_tag(name, content, options = {}) ⇒ String

    Creates an html tag using the provided content as the content of the tag.

  • #html_tag(name, options = {}) { ... } ⇒ String

    Creates an html tag using the provided content as the content of the tag.

    Yields:

    • the tag content



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/flatrack/view/tag_helper.rb', line 40

def html_tag(name, content_or_options_with_block = nil, options = nil,
  escape = true, &block)
  if block_given?
    if content_or_options_with_block.is_a?(Hash)
      options = content_or_options_with_block
    end
    html_tag_string(name, capture(&block), options, escape)
  else
    html_tag_string(name, content_or_options_with_block, options, 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, options = {})
  uri = asset_path(uri) unless uri =~ %r{^(http)?(s)?:?\/\/}
  options.merge! src: uri
  html_tag(:img, nil, options)
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