opulent 1.5.5 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CODE_OF_CONDUCT.md +13 -0
- data/{LICENSE → LICENSE.md} +0 -0
- data/bin/opulent +0 -0
- data/lib/opulent.rb +10 -10
- data/lib/opulent/compiler.rb +15 -9
- data/lib/opulent/compiler/buffer.rb +123 -62
- data/lib/opulent/compiler/comment.rb +3 -4
- data/lib/opulent/compiler/control.rb +20 -26
- data/lib/opulent/compiler/define.rb +88 -36
- data/lib/opulent/compiler/doctype.rb +20 -22
- data/lib/opulent/compiler/eval.rb +23 -2
- data/lib/opulent/compiler/filter.rb +4 -5
- data/lib/opulent/compiler/node.rb +18 -12
- data/lib/opulent/compiler/root.rb +4 -5
- data/lib/opulent/compiler/text.rb +7 -2
- data/lib/opulent/compiler/yield.rb +2 -3
- data/lib/opulent/engine.rb +21 -20
- data/lib/opulent/exec.rb +21 -63
- data/lib/opulent/logger.rb +230 -3
- data/lib/opulent/parser.rb +14 -76
- data/lib/opulent/parser/comment.rb +45 -34
- data/lib/opulent/parser/control.rb +132 -111
- data/lib/opulent/parser/define.rb +15 -12
- data/lib/opulent/parser/doctype.rb +15 -15
- data/lib/opulent/parser/eval.rb +16 -6
- data/lib/opulent/parser/expression.rb +87 -84
- data/lib/opulent/parser/filter.rb +31 -25
- data/lib/opulent/parser/include.rb +38 -42
- data/lib/opulent/parser/node.rb +136 -118
- data/lib/opulent/parser/root.rb +24 -18
- data/lib/opulent/parser/text.rb +150 -123
- data/lib/opulent/parser/yield.rb +23 -23
- data/lib/opulent/settings.rb +70 -51
- data/lib/opulent/tokens.rb +17 -15
- data/lib/opulent/utils.rb +5 -4
- data/lib/opulent/version.rb +1 -1
- metadata +4 -43
- data/.libold/opulent.rb +0 -96
- data/.libold/opulent/context.rb +0 -80
- data/.libold/opulent/engine.rb +0 -88
- data/.libold/opulent/filter.rb +0 -101
- data/.libold/opulent/logger.rb +0 -67
- data/.libold/opulent/nodes.rb +0 -13
- data/.libold/opulent/nodes/block.rb +0 -29
- data/.libold/opulent/nodes/comment.rb +0 -35
- data/.libold/opulent/nodes/control.rb +0 -230
- data/.libold/opulent/nodes/define.rb +0 -42
- data/.libold/opulent/nodes/eval.rb +0 -41
- data/.libold/opulent/nodes/expression.rb +0 -28
- data/.libold/opulent/nodes/filter.rb +0 -70
- data/.libold/opulent/nodes/helper.rb +0 -69
- data/.libold/opulent/nodes/node.rb +0 -101
- data/.libold/opulent/nodes/root.rb +0 -62
- data/.libold/opulent/nodes/text.rb +0 -54
- data/.libold/opulent/nodes/theme.rb +0 -36
- data/.libold/opulent/parser.rb +0 -252
- data/.libold/opulent/parser/block.rb +0 -70
- data/.libold/opulent/parser/comment.rb +0 -32
- data/.libold/opulent/parser/control.rb +0 -83
- data/.libold/opulent/parser/define.rb +0 -39
- data/.libold/opulent/parser/eval.rb +0 -33
- data/.libold/opulent/parser/expression.rb +0 -350
- data/.libold/opulent/parser/filter.rb +0 -41
- data/.libold/opulent/parser/node.rb +0 -232
- data/.libold/opulent/parser/root.rb +0 -96
- data/.libold/opulent/parser/text.rb +0 -114
- data/.libold/opulent/parser/theme.rb +0 -36
- data/.libold/opulent/preprocessor.rb +0 -102
- data/.libold/opulent/runtime.rb +0 -144
- data/.libold/opulent/template.rb +0 -43
- data/.libold/opulent/tokens.rb +0 -276
- data/.libold/opulent/version.rb +0 -5
- data/.travis.yml +0 -4
- data/benchmark/benchmark.rb +0 -57
- data/benchmark/cases/node/node.haml +0 -7
- data/benchmark/cases/node/node.op +0 -7
- data/benchmark/cases/node/node.slim +0 -7
@@ -6,9 +6,8 @@ module Opulent
|
|
6
6
|
#
|
7
7
|
# @param node [Array] Node code generation data
|
8
8
|
# @param indent [Fixnum] Size of the indentation to be added
|
9
|
-
# @param context [Context] Processing environment data
|
10
9
|
#
|
11
|
-
def if_node(node, indent
|
10
|
+
def if_node(node, indent)
|
12
11
|
# Check if we have any condition met, or an else branch
|
13
12
|
node[@value].each_with_index do |value, index|
|
14
13
|
# If we have a branch that meets the condition, generate code for the
|
@@ -21,7 +20,7 @@ module Opulent
|
|
21
20
|
|
22
21
|
# Evaluate child nodes
|
23
22
|
node[@children][index].each do |child|
|
24
|
-
root child, indent
|
23
|
+
root child, indent
|
25
24
|
end
|
26
25
|
end
|
27
26
|
|
@@ -33,9 +32,8 @@ module Opulent
|
|
33
32
|
#
|
34
33
|
# @param node [Array] Node code generation data
|
35
34
|
# @param indent [Fixnum] Size of the indentation to be added
|
36
|
-
# @param context [Context] Processing environment data
|
37
35
|
#
|
38
|
-
def unless_node(node, indent
|
36
|
+
def unless_node(node, indent)
|
39
37
|
# Check if we have any condition met, or an else branch
|
40
38
|
node[@value].each_with_index do |value, index|
|
41
39
|
# If we have a branch that meets the condition, generate code for the
|
@@ -47,7 +45,7 @@ module Opulent
|
|
47
45
|
|
48
46
|
# Evaluate child nodes
|
49
47
|
node[@children][index].each do |child|
|
50
|
-
root child, indent
|
48
|
+
root child, indent
|
51
49
|
end
|
52
50
|
end
|
53
51
|
|
@@ -59,9 +57,8 @@ module Opulent
|
|
59
57
|
#
|
60
58
|
# @param node [Array] Node code generation data
|
61
59
|
# @param indent [Fixnum] Size of the indentation to be added
|
62
|
-
# @param context [Context] Processing environment data
|
63
60
|
#
|
64
|
-
def case_node(node, indent
|
61
|
+
def case_node(node, indent)
|
65
62
|
# Evaluate the switching condition
|
66
63
|
buffer_eval "case #{node[@options][:condition]}"
|
67
64
|
|
@@ -70,67 +67,64 @@ module Opulent
|
|
70
67
|
# If we have a branch that meets the condition, generate code for the
|
71
68
|
# children related to that specific branch
|
72
69
|
case value
|
73
|
-
when node[@value].last then buffer_eval
|
70
|
+
when node[@value].last then buffer_eval 'else'
|
74
71
|
else buffer_eval "when #{value}"
|
75
72
|
end
|
76
73
|
|
77
74
|
# Evaluate child nodes
|
78
75
|
node[@children][index].each do |child|
|
79
|
-
root child, indent
|
76
|
+
root child, indent
|
80
77
|
end
|
81
78
|
end
|
82
79
|
|
83
80
|
# End
|
84
|
-
buffer_eval
|
81
|
+
buffer_eval 'end'
|
85
82
|
end
|
86
83
|
|
87
84
|
# Generate the code for a while control structure
|
88
85
|
#
|
89
86
|
# @param node [Array] Node code generation data
|
90
87
|
# @param indent [Fixnum] Size of the indentation to be added
|
91
|
-
# @param context [Context] Processing environment data
|
92
88
|
#
|
93
|
-
def while_node(node, indent
|
89
|
+
def while_node(node, indent)
|
94
90
|
# While we have a branch that meets the condition, generate code for the
|
95
91
|
# children related to that specific branch
|
96
92
|
buffer_eval "while #{node[@value]}"
|
97
93
|
|
98
94
|
# Evaluate child nodes
|
99
95
|
node[@children].each do |child|
|
100
|
-
root child, indent
|
96
|
+
root child, indent
|
101
97
|
end
|
102
98
|
|
103
99
|
#End
|
104
|
-
buffer_eval
|
100
|
+
buffer_eval 'end'
|
105
101
|
end
|
106
102
|
|
107
103
|
# Generate the code for a while control structure
|
108
104
|
#
|
109
105
|
# @param node [Array] Node code generation data
|
110
106
|
# @param indent [Fixnum] Size of the indentation to be added
|
111
|
-
# @param context [Context] Processing environment data
|
112
107
|
#
|
113
|
-
def until_node(node, indent
|
108
|
+
def until_node(node, indent)
|
114
109
|
# Until we have a branch that doesn't meet the condition, generate code for the
|
115
110
|
# children related to that specific branch
|
116
111
|
buffer_eval "until #{node[@value]}"
|
117
112
|
|
118
113
|
# Evaluate child nodes
|
119
114
|
node[@children].each do |child|
|
120
|
-
root child, indent
|
115
|
+
root child, indent
|
121
116
|
end
|
122
117
|
|
123
118
|
# End
|
124
|
-
buffer_eval
|
119
|
+
buffer_eval 'end'
|
125
120
|
end
|
126
121
|
|
127
122
|
# Generate the code for a while control structure
|
128
123
|
#
|
129
124
|
# @param node [Array] Node code generation data
|
130
125
|
# @param indent [Fixnum] Size of the indentation to be added
|
131
|
-
# @param context [Context] Processing environment data
|
132
126
|
#
|
133
|
-
def each_node(node, indent
|
127
|
+
def each_node(node, indent)
|
134
128
|
# Process named variables for each structure
|
135
129
|
variables = node[@value][1].clone
|
136
130
|
|
@@ -143,12 +137,12 @@ module Opulent
|
|
143
137
|
|
144
138
|
# Value argument name provided only
|
145
139
|
if variables.length == 1
|
146
|
-
variables.unshift Settings::
|
140
|
+
variables.unshift Settings::DEFAULT_EACH_KEY
|
147
141
|
|
148
142
|
# Missing key and value arguments
|
149
143
|
elsif variables.empty?
|
150
|
-
variables[0] = Settings::
|
151
|
-
variables[1] = Settings::
|
144
|
+
variables[0] = Settings::DEFAULT_EACH_KEY
|
145
|
+
variables[1] = Settings::DEFAULT_EACH_VALUE
|
152
146
|
end
|
153
147
|
|
154
148
|
# Choose whether to apply each with index (Arrays) or each (Hashes) methods
|
@@ -162,11 +156,11 @@ module Opulent
|
|
162
156
|
|
163
157
|
# Evaluate child nodes
|
164
158
|
node[@children].each do |child|
|
165
|
-
root child, indent
|
159
|
+
root child, indent
|
166
160
|
end
|
167
161
|
|
168
162
|
# End
|
169
|
-
buffer_eval
|
163
|
+
buffer_eval 'end'
|
170
164
|
end
|
171
165
|
end
|
172
166
|
end
|
@@ -2,71 +2,123 @@
|
|
2
2
|
module Opulent
|
3
3
|
# @Compiler
|
4
4
|
class Compiler
|
5
|
+
# Write out definition node using ruby def
|
6
|
+
#
|
7
|
+
# @param node [Node] Current node data with options
|
8
|
+
#
|
9
|
+
def define(node)
|
10
|
+
# Write out def method_name
|
11
|
+
definition = "def _opulent_definition_#{node[@value].to_s.tr '-', '_'}"
|
12
|
+
|
13
|
+
# Node attributes
|
14
|
+
parameters = []
|
15
|
+
node[@options][:parameters].each do |key, value|
|
16
|
+
parameters << "#{key} = #{value[@value]}"
|
17
|
+
end
|
18
|
+
parameters << 'attributes = {}'
|
19
|
+
parameters << '&block'
|
20
|
+
definition += '(' + parameters.join(', ') + ')'
|
21
|
+
|
22
|
+
buffer_eval 'instance_eval do'
|
23
|
+
buffer_eval definition
|
24
|
+
|
25
|
+
node[@children].each do |child|
|
26
|
+
root child, 0
|
27
|
+
end
|
28
|
+
|
29
|
+
buffer_eval 'end'
|
30
|
+
buffer_eval 'end'
|
31
|
+
end
|
32
|
+
|
5
33
|
# Generate code for all nodes by calling the method with their type name
|
6
34
|
#
|
7
35
|
# @param current [Array] Current node data with options
|
8
36
|
# @param indent [Fixnum] Indentation size for current node
|
9
|
-
# @param context [Context] Context holding environment variables
|
10
37
|
#
|
11
|
-
def def_node(node, indent
|
38
|
+
def def_node(node, indent)
|
12
39
|
# Set a namespace for the current node definition and make it a valid ruby
|
13
40
|
# method name
|
14
|
-
key = "_opulent_definition_#{node[@value]
|
41
|
+
key = "_opulent_definition_#{node[@value].to_s.tr '-', '_'}"
|
15
42
|
|
16
43
|
# Set call variable
|
17
44
|
call_node = node[@options][:call]
|
18
45
|
|
19
|
-
# Create the definition
|
20
|
-
buffer_eval "instance_eval do"
|
21
|
-
buffer_eval "def #{key}(attributes = {}, &block)"
|
22
|
-
|
23
|
-
# Set each parameter as a local variable
|
24
|
-
node[@options][:parameters].each do |parameter, value|
|
25
|
-
set_argument_code = "#{parameter} = attributes.delete(:#{parameter})"
|
26
|
-
set_argument_code += " || #{value[@value]}" if value[@value]
|
27
|
-
buffer_eval set_argument_code
|
28
|
-
end
|
29
|
-
|
30
|
-
# Evaluate definition child elements
|
31
|
-
node[@children].each do |child|
|
32
|
-
root child, indent + Settings[:indent], context
|
33
|
-
end
|
34
|
-
|
35
|
-
# End
|
36
|
-
buffer_eval "end"
|
37
|
-
buffer_eval "end"
|
38
|
-
|
39
46
|
# If we have attributes set for our defined node, we will need to create
|
40
47
|
# an extension parameter which will be o
|
41
48
|
if call_node[@options][:attributes].empty?
|
42
49
|
# Call method without any extension
|
43
|
-
|
50
|
+
method_call = "#{key}"
|
51
|
+
|
52
|
+
# Call arguments set to true, in correct order
|
53
|
+
arguments = []
|
54
|
+
@definitions[call_node[@value]][@options][:parameters].keys.each do
|
55
|
+
arguments << 'true'
|
56
|
+
end
|
57
|
+
arguments << '{}'
|
58
|
+
|
59
|
+
method_call += '(' + arguments.join(', ') + ')'
|
60
|
+
method_call += ' do' unless call_node[@children].empty?
|
61
|
+
|
62
|
+
buffer_eval method_call
|
44
63
|
else
|
45
|
-
|
64
|
+
arguments = []
|
46
65
|
|
47
|
-
#
|
48
|
-
|
66
|
+
# Extract node definition arguments in the correct order. If the given
|
67
|
+
# key does not exist, set the value to default or true
|
68
|
+
@definitions[
|
69
|
+
call_node[@value]
|
70
|
+
][@options][:parameters].keys.each do |k|
|
71
|
+
if call_node[@options][:attributes].keys.include? k
|
72
|
+
arguments << call_node[@options][:attributes].delete(k)[@value]
|
73
|
+
else
|
74
|
+
arguments << @definitions[
|
75
|
+
call_node[@value]
|
76
|
+
][@options][:parameters][k][@value]
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
call_attributes = buffer_attributes_to_hash(
|
81
|
+
call_node[@options][:attributes]
|
82
|
+
)
|
49
83
|
|
50
|
-
# If the call node is extended as well, merge the call attributes hash
|
51
|
-
# the extension hash
|
84
|
+
# If the call node is extended as well, merge the call attributes hash
|
85
|
+
# with the extension hash
|
52
86
|
if call_node[@options][:extension]
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
87
|
+
# .merge!(var_name)
|
88
|
+
call_attributes += '.merge!(' \
|
89
|
+
"#{call_node[@options][:extension][@value]}" \
|
90
|
+
')'
|
91
|
+
|
92
|
+
# { |key, value1, value2|
|
93
|
+
call_attributes += " { |#{OPULENT_KEY}, " \
|
94
|
+
"#{OPULENT_VALUE}1, #{OPULENT_VALUE}2|"
|
95
|
+
|
96
|
+
# class ? value1 + value2 : value2
|
97
|
+
call_attributes += "#{OPULENT_KEY} == :class ? (" \
|
98
|
+
"#{OPULENT_VALUE}1 += " \
|
99
|
+
"#{OPULENT_VALUE}2) : (#{OPULENT_VALUE}2" \
|
100
|
+
')'
|
101
|
+
|
102
|
+
# }
|
103
|
+
call_attributes += '}'
|
57
104
|
end
|
58
105
|
|
59
|
-
|
106
|
+
arguments << call_attributes
|
107
|
+
|
108
|
+
call = "#{key}(#{arguments.join ', '})"
|
109
|
+
call += ' do' unless call_node[@children].empty?
|
110
|
+
|
111
|
+
buffer_eval call
|
60
112
|
end
|
61
113
|
|
62
114
|
# Set call node children as block evaluation. Very useful for
|
63
115
|
# performance and evaluating them in the parent context
|
64
116
|
call_node[@children].each do |child|
|
65
|
-
root child, indent +
|
117
|
+
root child, indent + @settings[:indent]
|
66
118
|
end
|
67
119
|
|
68
120
|
# End block
|
69
|
-
buffer_eval
|
121
|
+
buffer_eval 'end' unless call_node[@children].empty?
|
70
122
|
end
|
71
123
|
end
|
72
124
|
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
# @Opulent
|
3
2
|
module Opulent
|
4
3
|
# @Compiler
|
@@ -7,29 +6,28 @@ module Opulent
|
|
7
6
|
#
|
8
7
|
# @param node [Array] Node code generation data
|
9
8
|
# @param indent [Fixnum] Size of the indentation to be added
|
10
|
-
# @param context [Context] Processing environment data
|
11
9
|
#
|
12
|
-
def doctype_node(node, indent
|
10
|
+
def doctype_node(node, indent)
|
13
11
|
value = case node[@value]
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
12
|
+
when :"", :html, :"5"
|
13
|
+
'!DOCTYPE html'
|
14
|
+
when :"1.1"
|
15
|
+
'!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"'
|
16
|
+
when :strict
|
17
|
+
'!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"'
|
18
|
+
when :frameset
|
19
|
+
'!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"'
|
20
|
+
when :mobile
|
21
|
+
'!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd"'
|
22
|
+
when :basic
|
23
|
+
'!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd"'
|
24
|
+
when :transitional
|
25
|
+
'!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"'
|
26
|
+
when :xml
|
27
|
+
'?xml version="1.0" encoding="utf-8" ?'
|
28
|
+
when :'xml ISO-8859-1'
|
29
|
+
'?xml version="1.0" encoding="iso-8859-1" ?'
|
30
|
+
end
|
33
31
|
|
34
32
|
@node_stack << :doctype
|
35
33
|
buffer_freeze "<#{value}>"
|
@@ -6,10 +6,31 @@ module Opulent
|
|
6
6
|
#
|
7
7
|
# @param node [Array] Node code generation data
|
8
8
|
# @param indent [Fixnum] Size of the indentation to be added
|
9
|
-
# @param context [Context] Processing environment data
|
10
9
|
#
|
11
|
-
def evaluate(node, indent
|
10
|
+
def evaluate(node, indent)
|
11
|
+
# Check if this is a substructure of a control block and remove the last
|
12
|
+
# end evaluation if it is
|
13
|
+
if node[@value] =~ Settings::END_REMOVAL
|
14
|
+
@template.pop if @template[-1] == [:eval, 'end']
|
15
|
+
end
|
16
|
+
|
17
|
+
# Check for explicit end node
|
18
|
+
if node[@value] =~ Settings::END_EXPLICIT
|
19
|
+
Logger.error :compile, @template, :explicit_end, node
|
20
|
+
end
|
21
|
+
|
22
|
+
# Evaluate the current expression
|
12
23
|
buffer_eval node[@value]
|
24
|
+
|
25
|
+
# If the node has children, evaluate each one of them
|
26
|
+
if node[@children]
|
27
|
+
node[@children].each do |child|
|
28
|
+
root child, indent + @settings[:indent]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Check if the node is actually a block expression
|
33
|
+
buffer_eval 'end' if node[@value] =~ Settings::END_INSERTION
|
13
34
|
end
|
14
35
|
end
|
15
36
|
end
|
@@ -6,14 +6,13 @@ module Opulent
|
|
6
6
|
#
|
7
7
|
# @param node [Array] Node code generation data
|
8
8
|
# @param indent [Fixnum] Size of the indentation to be added
|
9
|
-
# @param context [Context] Processing environment data
|
10
9
|
#
|
11
|
-
def filter(node, indent
|
10
|
+
def filter(node, indent)
|
12
11
|
# Evaluate and generate node attributes, then process each one to
|
13
12
|
# by generating the required attribute code
|
14
13
|
attributes = {}
|
15
14
|
node[@options].each do |key, attribute|
|
16
|
-
attributes[key] = map_attribute key, attribute
|
15
|
+
attributes[key] = map_attribute key, attribute
|
17
16
|
end
|
18
17
|
|
19
18
|
# Get registered filter name
|
@@ -44,10 +43,10 @@ module Opulent
|
|
44
43
|
wrapper_node = [:node, wrapper_tag, {attributes: atts}, [text_node], indent]
|
45
44
|
|
46
45
|
# Begin code generation from the wrapper node
|
47
|
-
root wrapper_node, indent
|
46
|
+
root wrapper_node, indent
|
48
47
|
else
|
49
48
|
# Generate code for output text node
|
50
|
-
root text_node, indent
|
49
|
+
root text_node, indent
|
51
50
|
end
|
52
51
|
end
|
53
52
|
end
|
@@ -7,43 +7,49 @@ module Opulent
|
|
7
7
|
#
|
8
8
|
# @param node [Array] Node code generation data
|
9
9
|
# @param indent [Fixnum] Size of the indentation to be added
|
10
|
-
# @param context [Context] Processing environment data
|
11
10
|
#
|
12
|
-
def node(node, indent
|
13
|
-
indentation =
|
11
|
+
def node(node, indent)
|
12
|
+
indentation = ' ' * indent
|
14
13
|
|
15
14
|
# Add the tag opening, with leading whitespace to the code buffer
|
16
|
-
buffer_freeze
|
15
|
+
buffer_freeze ' ' if node[@options][:leading_whitespace]
|
17
16
|
buffer_freeze "<#{node[@value]}"
|
18
17
|
|
19
18
|
# Evaluate node extension in the current context
|
20
|
-
|
21
|
-
buffer_set_variable :extension,
|
19
|
+
if node[@options][:extension]
|
20
|
+
extension_name = buffer_set_variable :extension,
|
21
|
+
node[@options][:extension][@value]
|
22
|
+
|
23
|
+
extension = {
|
24
|
+
name: extension_name,
|
25
|
+
escaped: node[@options][:extension][@options][:escaped]
|
26
|
+
}
|
22
27
|
end
|
23
28
|
|
24
29
|
# Evaluate and generate node attributes, then process each one to
|
25
30
|
# by generating the required attribute code
|
26
|
-
attributes = {}
|
27
|
-
buffer_attributes node[@options][:attributes],
|
31
|
+
# attributes = {}
|
32
|
+
buffer_attributes node[@options][:attributes],
|
33
|
+
extension
|
28
34
|
|
29
35
|
|
30
36
|
# Check if the current node is self enclosing. Self enclosing nodes
|
31
37
|
# do not have any child elements
|
32
38
|
if node[@options][:self_enclosing]
|
33
39
|
# If the tag is self enclosing, it cannot have any child elements.
|
34
|
-
buffer_freeze
|
40
|
+
buffer_freeze '>'
|
35
41
|
else
|
36
42
|
# Set tag ending code
|
37
|
-
buffer_freeze
|
43
|
+
buffer_freeze '>'
|
38
44
|
|
39
45
|
# Process each child element recursively, increasing indentation
|
40
46
|
node[@children].each do |child|
|
41
|
-
root child, indent +
|
47
|
+
root child, indent + @settings[:indent]
|
42
48
|
end
|
43
49
|
|
44
50
|
# Set tag closing code
|
45
51
|
buffer_freeze "</#{node[@value]}>"
|
46
|
-
buffer_freeze
|
52
|
+
buffer_freeze ' ' if node[@options][:trailing_whitespace]
|
47
53
|
end
|
48
54
|
end
|
49
55
|
end
|