Class: EideticRML::PageBuilder
- Inherits:
-
Object
- Object
- EideticRML::PageBuilder
show all
- Defined in:
- lib/erml.rb
Instance Method Summary
collapse
Constructor Details
Returns a new instance of PageBuilder.
46
47
48
49
50
51
52
53
|
# File 'lib/erml.rb', line 46
def initialize(doc)
@stack = [doc]
@tag_aliases = {}
EideticRML::STANDARD_ALIASES.each do |a|
a = a.dup
define(a.delete('id'), a['tag'], a)
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(id, *args, &block) ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/erml.rb', line 59
def method_missing(id, *args, &block)
if current.respond_to?(id)
current.send(id, *args)
return current
else
tag, attrs = @tag_aliases[id.to_s] || [id.to_s, {}]
attrs = attrs.merge(fix_attrs(args.first))
attrs['tag'] = id unless tag == id
factory = Widgets::StdWidgetFactory.instance raise ArgumentError, "Unknown tag: #{tag}." unless factory.has_widget?(tag)
widget = factory.make_widget(tag, current, attrs)
@stack.push(widget)
result = if block_given?
yield
current
else
self.clone
end
@stack.pop
return result
end
end
|
Instance Method Details
#define(new_tag, old_tag, attrs) ⇒ Object
82
83
84
|
# File 'lib/erml.rb', line 82
def define(new_tag, old_tag, attrs)
@tag_aliases[new_tag.to_s] = [old_tag.to_s, attrs.clone.freeze]
end
|
#initialize_copy(other) ⇒ Object
55
56
57
|
# File 'lib/erml.rb', line 55
def initialize_copy(other)
@stack = @stack.clone
end
|