Class: Weblet
- Inherits:
-
Object
- Object
- Weblet
- Defined in:
- lib/weblet.rb
Instance Method Summary collapse
-
#initialize(raws, marker: nil, debug: false) ⇒ Weblet
constructor
A new instance of Weblet.
- #render(*args) ⇒ Object
- #to_h ⇒ Object
- #to_outline ⇒ Object
- #to_xml ⇒ Object
Constructor Details
#initialize(raws, marker: nil, debug: false) ⇒ Weblet
Returns a new instance of Weblet.
85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/weblet.rb', line 85 def initialize(raws, marker: nil, debug: false) @debug = debug s, _ = RXFHelper.read(raws.strip) obj = s[0] == '<' ? s : WebletBuilder.new(s, marker: marker, \ debug: debug).to_a puts 'obj: ' + obj.inspect if @debug @doc = Rexle.new(obj) @h = scan @doc.root end |
Instance Method Details
#render(*args) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/weblet.rb', line 111 def render(*args) b = args.pop if args.last.is_a? Binding if args.first.is_a? String then path = args.first.split('/').map(&:to_sym) else path = *args.flatten(1) end #r = @h.dig *path r = digx(@h, path) # check for interpolated substitution tags e.g/ <:card/svg/link> r.gsub!(/<:([^>]+)>/) {|x| self.render($1) } if r puts 'r: ' + r.inspect if @debug if r.nil? then found = @doc.root.element("//node[@id='#{path.join}']") r = found.cdatas.join if found end eval('%Q(' + r + ')', b) if r end |
#to_h ⇒ Object
99 100 101 |
# File 'lib/weblet.rb', line 99 def to_h() @h end |
#to_outline ⇒ Object
103 104 105 |
# File 'lib/weblet.rb', line 103 def to_outline() treeize(scan_h(@h)) end |
#to_xml ⇒ Object
107 108 109 |
# File 'lib/weblet.rb', line 107 def to_xml() @doc.root.xml pretty: true end |