class HtmlTagBuilder
tag.ul do |n|
1.upto(3) do |num| n.li do |n| n.i '.arrow' n.span num n.id end end
end
Attributes
data[R]
Public Class Methods
build(attrs, node=nil, text=nil) { |opts| ... }
click to toggle source
build html node
# File lib/common/html_tag_builder.rb, line 49 def build attrs, node=nil, text=nil opts = '' attrs.each do |k,v| opts += ' '+k.to_s.gsub(/_/,'-')+'="'+v.to_s.gsub(/"/,'"')+'"' if v.present? end return opts unless node text = yield opts if block_given? text ||= '' unless ['input', 'img', 'meta', 'link', 'hr', 'br'].include?(node.to_s) text ? %{<#{node}#{opts}>#{text}</#{node}>} : %{<#{node}#{opts} />} end
call(class_name, &block)
click to toggle source
tag.div(class: 'klasa') do -> tag.('klasa') do
# File lib/common/html_tag_builder.rb, line 63 def call class_name, &block tag(:div, { class: class_name }, &block) end
method_missing(tag_name, *args, &block)
click to toggle source
tag.div -> tag.tag :div
# File lib/common/html_tag_builder.rb, line 14 def method_missing tag_name, *args, &block tag tag_name, args[0], args[1], &block end
new()
click to toggle source
# File lib/common/html_tag_builder.rb, line 73 def initialize @data = [] end
tag(name=nil, opts={}) { |inline, opts| ... }
click to toggle source
tag :div, { 'class'=>'iform' } do
# File lib/common/html_tag_builder.rb, line 19 def tag name=nil, opts={}, data=nil # covert tag.a '.foo.bar' to class names # covert tag.a '#id' to id names if opts.is_a?(String) case opts[0,1] when '.' opts = { class: opts.sub('.', '').gsub('.', ' ') } when '#' opts = { id: opts.sub('#', '') } end else end # fix data and opts unless opts is Hash data, opts = opts, {} unless opts.class == Hash if block_given? inline = new data = yield(inline, opts) # if data is pushed to passed node, use that data data = inline.data if inline.data.first end data = data.join('') if data.is_a?(Array) build opts, name, data end
Public Instance Methods
call(class_name, &block)
click to toggle source
n.div(class: 'klasa') do -> n.('klasa') do
# File lib/common/html_tag_builder.rb, line 83 def call class_name, &block @data.push self.class.tag(:div, { class: class_name }, &block) end
method_missing(tag_name, *args, &block)
click to toggle source
forward to class
# File lib/common/html_tag_builder.rb, line 88 def method_missing tag_name, *args, &block @data.push self.class.tag(tag_name, args[0], args[1], &block) end
push(data)
click to toggle source
push data to stack
# File lib/common/html_tag_builder.rb, line 78 def push data @data.push data end