Module: Eldr::Rendering::Tags

Defined in:
lib/eldr/rendering/tag_helpers.rb

Constant Summary collapse

ESCAPE_VALUES =
{
  '&' => '&',
  '<' => '&lt;',
  '>' => '&gt;',
  '"' => '&quot;'
}.freeze
ESCAPE_REGEXP =
Regexp.union(*ESCAPE_VALUES.keys).freeze
BOOLEAN_ATTRIBUTES =
[
  :autoplay,
  :autofocus,
  :formnovalidate,
  :checked,
  :disabled,
  :hidden,
  :loop,
  :multiple,
  :muted,
  :readonly,
  :required,
  :selected,
  :declare,
  :defer,
  :ismap,
  :itemscope,
  :noresize,
  :novalidate
].freeze
DATA_ATTRIBUTES =
[
  :method,
  :remote,
  :confirm
].freeze
NEWLINE =
"\n".html_safe.freeze

Instance Method Summary collapse

Instance Method Details

#content_tag(name, content = nil, options = nil, &block) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/eldr/rendering/tag_helpers.rb', line 51

def (name, content = nil, options = nil, &block)
  if block_given?
    options = content if content.is_a?(Hash)
    content = capture_html(&block)
  end

  options    = parse_data_options(name, options)
  attributes = tag_attributes(options)
  output = ActiveSupport::SafeBuffer.new
  output.safe_concat "<#{name}#{attributes}>"
  if content.respond_to?(:each) && !content.is_a?(String)
    content.each { |item| output.concat item; output.safe_concat NEWLINE }
  else
    output.concat content.to_s
  end
  output.safe_concat "</#{name}>"

  output
end

#tag(name, options = nil, open = false) ⇒ Object



45
46
47
48
49
# File 'lib/eldr/rendering/tag_helpers.rb', line 45

def tag(name, options = nil, open = false)
  options = parse_data_options(name, options)
  attributes = tag_attributes(options)
  "<#{name}#{attributes}#{open ? '>' : ' />'}".html_safe
end