Class: HtmlBuilder
- Inherits:
-
Object
- Object
- HtmlBuilder
- Defined in:
- lib/html-builder.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_child(name, *args, &block) ⇒ Object
- #build_tree(root_name, *args, &block) ⇒ Object
-
#initialize ⇒ HtmlBuilder
constructor
A new instance of HtmlBuilder.
- #inspect ⇒ Object
- #to_s(*args) ⇒ Object
- #yield_block(e, &block) ⇒ Object
Constructor Details
#initialize ⇒ HtmlBuilder
Returns a new instance of HtmlBuilder.
55 56 57 58 |
# File 'lib/html-builder.rb', line 55 def initialize @root = nil @stack = [] end |
Class Method Details
.def_tag(name) ⇒ Object
79 80 81 82 83 |
# File 'lib/html-builder.rb', line 79 def self.def_tag name define_method name do |*args, &block| add_child name, *args, &block end end |
.generate(root_ele, *args, &block) ⇒ Object
50 51 52 53 54 |
# File 'lib/html-builder.rb', line 50 def self.generate root_ele, *args, &block x = self.new x.build_tree root_ele, *args, &block x.to_s end |
.html(*args, &block) ⇒ Object
47 48 49 |
# File 'lib/html-builder.rb', line 47 def self.html *args, &block generate :html, *args, &block end |
Instance Method Details
#add_child(name, *args, &block) ⇒ Object
75 76 77 78 |
# File 'lib/html-builder.rb', line 75 def add_child name, *args, &block e = HtmlBuilderNode.new @stack.last, name, *args yield_block e, &block end |
#build_tree(root_name, *args, &block) ⇒ Object
65 66 67 68 |
# File 'lib/html-builder.rb', line 65 def build_tree root_name, *args, &block @root = HtmlBuilderNode.new nil, root_name, *args yield_block @root, &block end |
#inspect ⇒ Object
59 60 61 |
# File 'lib/html-builder.rb', line 59 def inspect nil end |
#to_s(*args) ⇒ Object
62 63 64 |
# File 'lib/html-builder.rb', line 62 def to_s *args @root.to_s *args end |
#yield_block(e, &block) ⇒ Object
69 70 71 72 73 74 |
# File 'lib/html-builder.rb', line 69 def yield_block e, &block return unless block @stack << e instance_eval &block @stack.pop end |