Module: Rad::Html::BasicHtmlHelper

Defined in:
lib/rad/html/_helpers/basic_html_helper.rb

Constant Summary collapse

BOOLEAN_ATTRIBUTES =
%w(disabled readonly multiple checked autobuffer
autoplay controls loop selected hidden scoped async
defer reversed ismap seemless muted required
autofocus novalidate formnovalidate open).to_set

Instance Method Summary collapse

Instance Method Details

#h(obj) ⇒ Object

Escape



51
# File 'lib/rad/html/_helpers/basic_html_helper.rb', line 51

def h obj; obj.to_s.html_escape end

#image_tag(src, opt = {}) ⇒ Object

Assets



22
23
24
25
# File 'lib/rad/html/_helpers/basic_html_helper.rb', line 22

def image_tag src, opt = {}
  opt[:src] = src
  tag :img, '', opt
end

#label_tag(name, text, options = {}) ⇒ Object

Common HTML tags



31
32
33
# File 'lib/rad/html/_helpers/basic_html_helper.rb', line 31

def label_tag name, text, options = {}
  tag :label, text, options.merge(for: name)
end

JavaScript & StyleSheets



12
13
14
15
16
# File 'lib/rad/html/_helpers/basic_html_helper.rb', line 12

def stylesheet_link_tag *stylesheets
  stylesheets.collect{|ssheet|
    tag :link, '', href: "#{ssheet}", media: "screen", rel: "stylesheet", type: "text/css"
  }.join("\n")
end

#tag(name, content_or_options_with_block = nil, options = nil, escape = true, &block) ⇒ Object

Special



39
40
41
42
43
44
45
46
47
48
# File 'lib/rad/html/_helpers/basic_html_helper.rb', line 39

def tag name, content_or_options_with_block = nil, options = nil, escape = true, &block
  if block_given?
    options = content_or_options_with_block if content_or_options_with_block.is_a?(Hash)
    content = capture(&block)
    concat "<#{name}#{tag_options(options)}>#{content}</#{name}>"
  else
    content = content_or_options_with_block
    "<#{name}#{tag_options(options)}>#{content}</#{name}>"
  end
end