opulent 1.6.5 → 1.6.6
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/lib/opulent/compiler/define.rb +16 -16
- data/lib/opulent/parser.rb +47 -0
- data/lib/opulent/parser/node.rb +43 -46
- data/lib/opulent/tokens.rb +3 -0
- data/lib/opulent/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2cc679a1295d1bf93f8b99c868fce7dedc384b22
|
4
|
+
data.tar.gz: e611419e1736b5e2b648c0d4bfef2214cddaf1c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b019b7a8acc18c742719c1c1804b45a5f207a939d33f7d94616f5d9aafdd30bf5a2a9d3987746a91373432fb5edbf944b3e7775c8250d6647ffe05456463494
|
7
|
+
data.tar.gz: 8d4281c2386d63aecc1857bf71c94826814ee9b3e9ca882d372d4ba157517f446add48f19177c0f2169aecf4c640988ed62ccb05be65fd7e8734a2f539fc7547
|
@@ -40,24 +40,24 @@ module Opulent
|
|
40
40
|
# method name
|
41
41
|
key = "_opulent_definition_#{node[@value].to_s.tr '-', '_'}"
|
42
42
|
|
43
|
-
# Set call variable
|
44
|
-
call_node = node[@options][:call]
|
45
43
|
|
46
44
|
# If we have attributes set for our defined node, we will need to create
|
47
45
|
# an extension parameter which will be o
|
48
|
-
if
|
46
|
+
if node[@options][:attributes].empty?
|
49
47
|
# Call method without any extension
|
50
48
|
method_call = "#{key}"
|
51
49
|
|
52
50
|
# Call arguments set to true, in correct order
|
53
51
|
arguments = []
|
54
|
-
@definitions[
|
55
|
-
arguments <<
|
52
|
+
@definitions[node[@value]][@options][:parameters].keys.each do |k|
|
53
|
+
arguments << @definitions[
|
54
|
+
node[@value]
|
55
|
+
][@options][:parameters][k][@value]
|
56
56
|
end
|
57
57
|
arguments << '{}'
|
58
58
|
|
59
59
|
method_call += '(' + arguments.join(', ') + ')'
|
60
|
-
method_call += ' do' unless
|
60
|
+
method_call += ' do' unless node[@children].empty?
|
61
61
|
|
62
62
|
buffer_eval method_call
|
63
63
|
else
|
@@ -66,27 +66,27 @@ module Opulent
|
|
66
66
|
# Extract node definition arguments in the correct order. If the given
|
67
67
|
# key does not exist, set the value to default or true
|
68
68
|
@definitions[
|
69
|
-
|
69
|
+
node[@value]
|
70
70
|
][@options][:parameters].keys.each do |k|
|
71
|
-
if
|
72
|
-
arguments <<
|
71
|
+
if node[@options][:attributes].key? k
|
72
|
+
arguments << node[@options][:attributes].delete(k)[@value]
|
73
73
|
else
|
74
74
|
arguments << @definitions[
|
75
|
-
|
75
|
+
node[@value]
|
76
76
|
][@options][:parameters][k][@value]
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
80
|
call_attributes = buffer_attributes_to_hash(
|
81
|
-
|
81
|
+
node[@options][:attributes]
|
82
82
|
)
|
83
83
|
|
84
84
|
# If the call node is extended as well, merge the call attributes hash
|
85
85
|
# with the extension hash
|
86
|
-
if
|
86
|
+
if node[@options][:extension]
|
87
87
|
# .merge!(var_name)
|
88
88
|
call_attributes += '.merge!(' \
|
89
|
-
"#{
|
89
|
+
"#{node[@options][:extension][@value]}" \
|
90
90
|
')'
|
91
91
|
|
92
92
|
# { |key, value1, value2|
|
@@ -106,19 +106,19 @@ module Opulent
|
|
106
106
|
arguments << call_attributes
|
107
107
|
|
108
108
|
call = "#{key}(#{arguments.join ', '})"
|
109
|
-
call += ' do' unless
|
109
|
+
call += ' do' unless node[@children].empty?
|
110
110
|
|
111
111
|
buffer_eval call
|
112
112
|
end
|
113
113
|
|
114
114
|
# Set call node children as block evaluation. Very useful for
|
115
115
|
# performance and evaluating them in the parent context
|
116
|
-
|
116
|
+
node[@children].each do |child|
|
117
117
|
root child, indent + @settings[:indent]
|
118
118
|
end
|
119
119
|
|
120
120
|
# End block
|
121
|
-
buffer_eval 'end' unless
|
121
|
+
buffer_eval 'end' unless node[@children].empty?
|
122
122
|
end
|
123
123
|
end
|
124
124
|
end
|
data/lib/opulent/parser.rb
CHANGED
@@ -70,9 +70,56 @@ module Opulent
|
|
70
70
|
# nodes and definitions
|
71
71
|
root @root
|
72
72
|
|
73
|
+
# Check whether nodes inside definitions have a custom definition
|
74
|
+
@definitions.each do |name, node|
|
75
|
+
@current_def = name
|
76
|
+
apply_definitions node
|
77
|
+
end
|
78
|
+
@current_def = nil
|
79
|
+
|
80
|
+
# Check whether nodes have a custom definition
|
81
|
+
apply_definitions @root
|
82
|
+
|
83
|
+
# Return root element
|
73
84
|
[@root, @definitions]
|
74
85
|
end
|
75
86
|
|
87
|
+
# Set each node as a defined node if a definition exists with the given
|
88
|
+
# node name, unless we're inside a definition with the same name as the node
|
89
|
+
# because we want to avoid recursion.
|
90
|
+
#
|
91
|
+
# @param node [Node] Input Node to checked for existence of definitions
|
92
|
+
#
|
93
|
+
def apply_definitions(node)
|
94
|
+
# Apply definition check to all of the node's children
|
95
|
+
process_definitions = proc do |children|
|
96
|
+
children.each do |child|
|
97
|
+
# Check if we have a definition
|
98
|
+
is_definition = if child[@value] == @current_def
|
99
|
+
child[@options][:recursive]
|
100
|
+
else
|
101
|
+
@definitions.key?(child[@value])
|
102
|
+
end
|
103
|
+
|
104
|
+
# Set child as a defined node
|
105
|
+
child[@type] = :def if is_definition
|
106
|
+
|
107
|
+
# Recursively apply definitions to child nodes
|
108
|
+
apply_definitions child if child[@children]
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
# Apply definitions to each case of the control node
|
113
|
+
if %i(if unless case each while until).include? node[@type]
|
114
|
+
node[@children].each do |array|
|
115
|
+
process_definitions[array]
|
116
|
+
end
|
117
|
+
# Apply definition to all of the node's children
|
118
|
+
else
|
119
|
+
process_definitions[node[@children]]
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
76
123
|
# Check and accept or reject a given token as long as we have tokens
|
77
124
|
# remaining. Shift the code with the match length plus any extra character
|
78
125
|
# count around the capture group
|
data/lib/opulent/parser/node.rb
CHANGED
@@ -13,6 +13,7 @@ module Opulent
|
|
13
13
|
return unless (name = lookahead(:node_lookahead) ||
|
14
14
|
lookahead(:shorthand_lookahead))
|
15
15
|
|
16
|
+
# Skip node if it's a reserved keyword
|
16
17
|
return nil if KEYWORDS.include? name[0].to_sym
|
17
18
|
|
18
19
|
# Accept either explicit node_name or implicit :div node_name
|
@@ -27,6 +28,9 @@ module Opulent
|
|
27
28
|
# Node creation options
|
28
29
|
options = {}
|
29
30
|
|
31
|
+
# Get leading whitespace
|
32
|
+
options[:recursive] = accept(:recursive)
|
33
|
+
|
30
34
|
# Get leading whitespace
|
31
35
|
options[:leading_whitespace] = accept_stripped(:leading_whitespace)
|
32
36
|
|
@@ -78,64 +82,57 @@ module Opulent
|
|
78
82
|
# Add the current node to the root
|
79
83
|
root current_node, indent
|
80
84
|
|
81
|
-
#
|
82
|
-
|
83
|
-
if @definitions.keys.include?(node_name)
|
84
|
-
@definition_stack << node_name
|
85
|
-
parent[@children] << process_definition(node_name, current_node)
|
86
|
-
@definition_stack.pop
|
87
|
-
else
|
88
|
-
parent[@children] << current_node
|
89
|
-
end
|
85
|
+
# Add the parsed node to the parent
|
86
|
+
parent[@children] << current_node
|
90
87
|
end
|
91
88
|
|
89
|
+
# Deprecated @version 1.6.6
|
90
|
+
#
|
92
91
|
# When entering a definition model, we replace all the node types with their
|
93
92
|
# know definitions at definition call time.
|
94
93
|
#
|
95
94
|
# @param node_name [Symbol] Node identifier
|
96
95
|
# @param call_context [Node] Initial node call with its attributes
|
97
96
|
#
|
98
|
-
def process_definition(node_name, call_context)
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
end
|
119
|
-
|
97
|
+
# def process_definition(node_name, call_context)
|
98
|
+
# model = [
|
99
|
+
# :def,
|
100
|
+
# node_name,
|
101
|
+
# {},
|
102
|
+
# [],
|
103
|
+
# call_context[@indent]
|
104
|
+
# ]
|
105
|
+
#
|
106
|
+
# model[@options] = {}.merge model[@options]
|
107
|
+
# model[@options][:call] = call_context
|
108
|
+
#
|
109
|
+
# Recursively map each child nodes to their definitions
|
110
|
+
# for the initial call node children and for the model
|
111
|
+
# children
|
112
|
+
# process_definition_child model[@options][:call]
|
113
|
+
# process_definition_child model
|
114
|
+
# model
|
115
|
+
# end
|
116
|
+
#
|
120
117
|
# Process definition children for the current node.
|
121
118
|
#
|
122
119
|
# @param node [Node] Callee node
|
123
120
|
#
|
124
|
-
def process_definition_child(node)
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
end
|
121
|
+
# def process_definition_child(node)
|
122
|
+
# node[@children].map! do |child|
|
123
|
+
# if child[@type] == :node
|
124
|
+
# if !@definition_stack.include?(child[@value]) &&
|
125
|
+
# @definitions.key?(child[@value])
|
126
|
+
# process_definition child[@value], child
|
127
|
+
# else
|
128
|
+
# process_definition_child child if child[@children]
|
129
|
+
# child
|
130
|
+
# end
|
131
|
+
# else
|
132
|
+
# child
|
133
|
+
# end
|
134
|
+
# end
|
135
|
+
# end
|
139
136
|
|
140
137
|
# Helper method to create an array of values when an attribute is set
|
141
138
|
# multiple times. This happens unless the key is id, which is unique
|
data/lib/opulent/tokens.rb
CHANGED
data/lib/opulent/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opulent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.6.
|
4
|
+
version: 1.6.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Grozav
|
@@ -163,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
163
163
|
version: '0'
|
164
164
|
requirements: []
|
165
165
|
rubyforge_project:
|
166
|
-
rubygems_version: 2.4.
|
166
|
+
rubygems_version: 2.4.8
|
167
167
|
signing_key:
|
168
168
|
specification_version: 4
|
169
169
|
summary: Intelligent Templating Engine for Creative Web Developers.
|