opulent 1.5.5 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/.libold/opulent/filter.rb
DELETED
@@ -1,101 +0,0 @@
|
|
1
|
-
# @Opulent
|
2
|
-
module Opulent
|
3
|
-
# @Filter
|
4
|
-
module Filter
|
5
|
-
# @Filter
|
6
|
-
class Filter
|
7
|
-
attr_accessor :name, :options, :loaded
|
8
|
-
|
9
|
-
# Set tag and attribute options for filter
|
10
|
-
#
|
11
|
-
def initialize(name, options)
|
12
|
-
@name = name
|
13
|
-
@options = options
|
14
|
-
@loaded = false
|
15
|
-
end
|
16
|
-
|
17
|
-
# Error output in case the filter does not exist
|
18
|
-
#
|
19
|
-
def load_filter
|
20
|
-
unless @loaded
|
21
|
-
# Try to load the library associated to the chosen filter
|
22
|
-
begin
|
23
|
-
require gem_name
|
24
|
-
@loaded = true
|
25
|
-
rescue LoadError => error
|
26
|
-
# Error output with filter name and installation instructions
|
27
|
-
Runtime.error :filter_load, @name, install_error
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
# Error message to be shown in order to provide installation instructions
|
33
|
-
# for the developer
|
34
|
-
#
|
35
|
-
def install_error
|
36
|
-
"gem install #{gem_name}"
|
37
|
-
end
|
38
|
-
|
39
|
-
# Process input code using this filter and return the output to the
|
40
|
-
# evaluation method from the Filter Node
|
41
|
-
#
|
42
|
-
def render(code, options = {})
|
43
|
-
raise NoMethodError
|
44
|
-
end
|
45
|
-
|
46
|
-
# RubyGems name for explicit library require
|
47
|
-
#
|
48
|
-
def gem_name
|
49
|
-
raise NoMethodError
|
50
|
-
# "gem_name"
|
51
|
-
end
|
52
|
-
|
53
|
-
# After defining how to render the code,
|
54
|
-
#
|
55
|
-
# Engine.register self, :filter, tag: :tag, attributes: { type: 'text/css' }
|
56
|
-
end
|
57
|
-
|
58
|
-
|
59
|
-
# Add the default registered rendering filters for Opulent
|
60
|
-
|
61
|
-
# @CoffeeScript
|
62
|
-
class CoffeeScript < Filter
|
63
|
-
def render(code, options = {})
|
64
|
-
::CoffeeScript.compile code, options
|
65
|
-
end
|
66
|
-
|
67
|
-
def gem_name
|
68
|
-
"coffee-script"
|
69
|
-
end
|
70
|
-
|
71
|
-
Engine.register self, :coffeescript, tag: :script, attributes: { type: 'javascript' }
|
72
|
-
end
|
73
|
-
|
74
|
-
# @Scss
|
75
|
-
class Scss < Filter
|
76
|
-
def render(code, options = {})
|
77
|
-
::Sass.compile code, options
|
78
|
-
end
|
79
|
-
|
80
|
-
def gem_name
|
81
|
-
"sass"
|
82
|
-
end
|
83
|
-
|
84
|
-
Engine.register self, :scss, tag: :style, attributes: { type: 'text/css' }
|
85
|
-
end
|
86
|
-
|
87
|
-
# @Sass
|
88
|
-
class Sass < Filter
|
89
|
-
def render(code, options = {})
|
90
|
-
options[:syntax] = :sass
|
91
|
-
::Sass.compile code, options
|
92
|
-
end
|
93
|
-
|
94
|
-
def gem_name
|
95
|
-
"sass"
|
96
|
-
end
|
97
|
-
|
98
|
-
Engine.register self, :sass, tag: :style, attributes: { type: 'text/css' }
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
data/.libold/opulent/logger.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
# @Opulent
|
2
|
-
module Opulent
|
3
|
-
# @Logger
|
4
|
-
module Logger
|
5
|
-
# @Singleton
|
6
|
-
class << self
|
7
|
-
# Color the input text with the chosen color
|
8
|
-
#
|
9
|
-
# @param text [String] the string that will be colored
|
10
|
-
# @param color_code [String] preset code for certain colors
|
11
|
-
#
|
12
|
-
def colorize(text, color_code)
|
13
|
-
require_windows_libs
|
14
|
-
"#{color_code}#{text}\e[0m"
|
15
|
-
end
|
16
|
-
|
17
|
-
# Colors available in the terminal
|
18
|
-
#
|
19
|
-
def black(text); colorize(text, "\e[30m"); end
|
20
|
-
def red(text); colorize(text, "\e[31m"); end
|
21
|
-
def green(text); colorize(text, "\e[32m"); end
|
22
|
-
def yellow(text); colorize(text, "\e[33m"); end
|
23
|
-
def blue(text); colorize(text, "\e[34m"); end
|
24
|
-
def magenta(text); colorize(text, "\e[35m"); end
|
25
|
-
def cyan(text); colorize(text, "\e[36m"); end
|
26
|
-
def white(text); colorize(text, "\e[37m"); end
|
27
|
-
def default(text); colorize(text, "\e[38m"); end
|
28
|
-
|
29
|
-
# Require windows libraries for ANSI Console output
|
30
|
-
#
|
31
|
-
def require_windows_libs
|
32
|
-
begin
|
33
|
-
require 'Win32/Console/ANSI' if RUBY_PLATFORM =~ /win32/
|
34
|
-
rescue LoadError
|
35
|
-
raise 'You must run "gem install win32console" to use Opulent\'s
|
36
|
-
error reporting on Windows.'
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
# Pretty print Nodes with their important details
|
41
|
-
#
|
42
|
-
def pretty_print(model, indent = 0)
|
43
|
-
model.each do |node|
|
44
|
-
case node
|
45
|
-
when Nodes::Node
|
46
|
-
puts " " * indent +
|
47
|
-
node.name.to_s +
|
48
|
-
"::" + node.class.to_s.split('::').last +
|
49
|
-
" #{node.attributes unless node.attributes.empty?}"
|
50
|
-
pretty_print node.children, indent + 2
|
51
|
-
when Nodes::Text, Nodes::Print
|
52
|
-
puts " " * indent +
|
53
|
-
"text" +
|
54
|
-
"::" + node.class.to_s.split('::').last +
|
55
|
-
" {:value => \"#{node.value}\"}"
|
56
|
-
when NilClass
|
57
|
-
else
|
58
|
-
puts " " * indent +
|
59
|
-
node.name.to_s +
|
60
|
-
"::" + node.class.to_s.split('::').last +
|
61
|
-
" {:value => \"#{node.value}\"}"
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
data/.libold/opulent/nodes.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
# Include Opulent nodes which know how to evaluate themselves
|
2
|
-
require_relative 'nodes/helper'
|
3
|
-
require_relative 'nodes/root'
|
4
|
-
require_relative 'nodes/node'
|
5
|
-
require_relative 'nodes/define'
|
6
|
-
require_relative 'nodes/eval'
|
7
|
-
require_relative 'nodes/expression'
|
8
|
-
require_relative 'nodes/text'
|
9
|
-
require_relative 'nodes/filter'
|
10
|
-
require_relative 'nodes/control'
|
11
|
-
require_relative 'nodes/theme'
|
12
|
-
require_relative 'nodes/block'
|
13
|
-
require_relative 'nodes/comment'
|
@@ -1,29 +0,0 @@
|
|
1
|
-
# @Opulent
|
2
|
-
module Opulent
|
3
|
-
# @Nodes
|
4
|
-
module Nodes
|
5
|
-
# @Yield
|
6
|
-
#
|
7
|
-
class Yield < Node
|
8
|
-
# Node evaluation method which goes through all the child nodes and evaluates
|
9
|
-
# them using their own eval method
|
10
|
-
#
|
11
|
-
def evaluate(context)
|
12
|
-
self
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
# @Block
|
17
|
-
#
|
18
|
-
class Block < Node
|
19
|
-
# Node evaluation method which goes through all the child nodes and evaluates
|
20
|
-
# them using their own eval method
|
21
|
-
#
|
22
|
-
def evaluate(context)
|
23
|
-
@children.map do |child|
|
24
|
-
child.evaluate context
|
25
|
-
end.flatten.compact
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
# @Opulent
|
2
|
-
module Opulent
|
3
|
-
# @Nodes
|
4
|
-
module Nodes
|
5
|
-
# @Text
|
6
|
-
#
|
7
|
-
# The text class will output raw or escaped HTML text
|
8
|
-
#
|
9
|
-
class Comment
|
10
|
-
# Allow direct access to literal value and type
|
11
|
-
attr_accessor :value, :visible, :parent, :indent, :name
|
12
|
-
|
13
|
-
# Initialize literal instance variables
|
14
|
-
#
|
15
|
-
# @param value stores the literal's explicit value
|
16
|
-
#
|
17
|
-
def initialize(value = nil, parent = nil, indent = 0)
|
18
|
-
@value = value
|
19
|
-
@parent = parent
|
20
|
-
@indent = indent
|
21
|
-
@name = :comment
|
22
|
-
end
|
23
|
-
|
24
|
-
# Value evaluation method which returns the processed value of the
|
25
|
-
# literal
|
26
|
-
#
|
27
|
-
def evaluate(context)
|
28
|
-
comment = self.dup
|
29
|
-
comment.value = context.evaluate "\"#{@value}\""
|
30
|
-
|
31
|
-
return comment
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,230 +0,0 @@
|
|
1
|
-
# @Opulent
|
2
|
-
module Opulent
|
3
|
-
# @Nodes
|
4
|
-
module Nodes
|
5
|
-
# @CnditionalControl
|
6
|
-
#
|
7
|
-
# Control structure for if-elsif-else and unless
|
8
|
-
#
|
9
|
-
class CnditionalControl
|
10
|
-
attr_accessor :name, :value, :parent, :indent, :children
|
11
|
-
|
12
|
-
# Ruby code evaluation node
|
13
|
-
#
|
14
|
-
# @param name [String] name of the html node
|
15
|
-
# @param value [String] condition to be met
|
16
|
-
# @param parent [Node] parent of the element
|
17
|
-
# @param indent [Fixnum] node indentation for restructuring
|
18
|
-
# @param children [Array] contents to be interpreted
|
19
|
-
#
|
20
|
-
def initialize(name = '', value = '', parent = nil, indent = 0, children = [[]])
|
21
|
-
@name = name
|
22
|
-
@value = [value]
|
23
|
-
@parent = parent
|
24
|
-
@indent = indent
|
25
|
-
@children = children
|
26
|
-
end
|
27
|
-
|
28
|
-
# Add a new node to the nodes array
|
29
|
-
#
|
30
|
-
def push(node)
|
31
|
-
@children[-1] << node
|
32
|
-
self
|
33
|
-
end
|
34
|
-
|
35
|
-
# Node evaluation method which goes through all the child nodes and evaluates
|
36
|
-
# them using their own eval method
|
37
|
-
#
|
38
|
-
def evaluate(context)
|
39
|
-
index = @value.index do |value|
|
40
|
-
value.empty? || context.evaluate(value)
|
41
|
-
end
|
42
|
-
|
43
|
-
if index
|
44
|
-
@children[index].map do |child|
|
45
|
-
child.evaluate context
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
# @IfControl
|
52
|
-
#
|
53
|
-
# Control structure for if-elsif-else directive
|
54
|
-
#
|
55
|
-
class CaseControl
|
56
|
-
attr_accessor :name, :case, :value, :parent, :indent, :children
|
57
|
-
|
58
|
-
# Ruby code evaluation node
|
59
|
-
#
|
60
|
-
# @param name [String] name of the html node
|
61
|
-
# @param value [String] condition to be met
|
62
|
-
# @param parent [Node] parent of the element
|
63
|
-
# @param indent [Fixnum] node indentation for restructuring
|
64
|
-
# @param children [Array] contents to be interpreted
|
65
|
-
#
|
66
|
-
def initialize(name = '', switch_case = '', parent = nil, indent = 0, children = [[]])
|
67
|
-
@name = name
|
68
|
-
@case = switch_case
|
69
|
-
@value = []
|
70
|
-
@parent = parent
|
71
|
-
@indent = indent
|
72
|
-
@children = children
|
73
|
-
end
|
74
|
-
|
75
|
-
# Add a new node to the nodes array
|
76
|
-
#
|
77
|
-
def push(node)
|
78
|
-
@children[-1] << node
|
79
|
-
self
|
80
|
-
end
|
81
|
-
|
82
|
-
# Node evaluation method which goes through all the child nodes and evaluates
|
83
|
-
# them using their own eval method
|
84
|
-
#
|
85
|
-
def evaluate(context)
|
86
|
-
switch_case = context.evaluate @case
|
87
|
-
index = @value.index do |value|
|
88
|
-
value.empty? || switch_case == context.evaluate(value)
|
89
|
-
end
|
90
|
-
|
91
|
-
if index
|
92
|
-
@children[index].map do |child|
|
93
|
-
child.evaluate context
|
94
|
-
end.flatten.compact
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
# @LoopControl
|
100
|
-
#
|
101
|
-
# Control structure for while and until directives
|
102
|
-
#
|
103
|
-
class LoopControl
|
104
|
-
attr_accessor :name, :value, :parent, :indent, :children
|
105
|
-
|
106
|
-
# Ruby code evaluation node
|
107
|
-
#
|
108
|
-
# @param name [String] name of the html node
|
109
|
-
# @param value [String] condition to be met
|
110
|
-
# @param parent [Node] parent of the element
|
111
|
-
# @param indent [Fixnum] node indentation for restructuring
|
112
|
-
# @param children [Array] contents to be interpreted
|
113
|
-
#
|
114
|
-
def initialize(name = '', value = '', parent = nil, indent = 0, children = [])
|
115
|
-
@name = name
|
116
|
-
@value = value
|
117
|
-
@parent = parent
|
118
|
-
@indent = indent
|
119
|
-
@children = children
|
120
|
-
end
|
121
|
-
|
122
|
-
# Add a new node to the nodes array
|
123
|
-
#
|
124
|
-
def push(node)
|
125
|
-
@children << node
|
126
|
-
self
|
127
|
-
end
|
128
|
-
|
129
|
-
# Node evaluation method which goes through all the child nodes and evaluates
|
130
|
-
# them using their own eval method
|
131
|
-
#
|
132
|
-
def evaluate(context)
|
133
|
-
result = []
|
134
|
-
|
135
|
-
evaluate_children = Proc.new do |context|
|
136
|
-
result << @children.map do |child|
|
137
|
-
child.evaluate context
|
138
|
-
end.flatten
|
139
|
-
end
|
140
|
-
|
141
|
-
case @name
|
142
|
-
when :while
|
143
|
-
while context.evaluate @value
|
144
|
-
evaluate_children[context]
|
145
|
-
end
|
146
|
-
when :until
|
147
|
-
until context.evaluate @value
|
148
|
-
evaluate_children[context]
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
return result.flatten.compact
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
# @EachControl
|
157
|
-
#
|
158
|
-
# Control structure for while and until directives
|
159
|
-
#
|
160
|
-
class EachControl < LoopControl
|
161
|
-
# Node evaluation method which goes through all the child nodes and evaluates
|
162
|
-
# them using their own eval method
|
163
|
-
#
|
164
|
-
def evaluate(context)
|
165
|
-
result = []
|
166
|
-
|
167
|
-
# Process named variables for each structure
|
168
|
-
variables = @value[0].clone
|
169
|
-
|
170
|
-
# The each structure accept missing arguments as well, therefore we need to
|
171
|
-
# substitute them with our defaults
|
172
|
-
#
|
173
|
-
# each in iterable
|
174
|
-
# each value in iterable
|
175
|
-
# each key, value in iterable
|
176
|
-
|
177
|
-
# Value argument name provided only
|
178
|
-
if variables.length == 1
|
179
|
-
variables.unshift Engine[:each][:default_key]
|
180
|
-
|
181
|
-
# Missing key and value arguments
|
182
|
-
elsif variables.empty?
|
183
|
-
variables[0] = Engine[:each][:default_key]
|
184
|
-
variables[1] = Engine[:each][:default_value]
|
185
|
-
end
|
186
|
-
|
187
|
-
# Evaluate in current context and add to results
|
188
|
-
evaluate_children = Proc.new do |key, value, context|
|
189
|
-
# Update the local variables in the each context with the values from the
|
190
|
-
# current loop iteration
|
191
|
-
locals = {
|
192
|
-
variables[0] => key,
|
193
|
-
variables[1] => value
|
194
|
-
}
|
195
|
-
context.extend_context locals
|
196
|
-
|
197
|
-
# Add the mapped child elements
|
198
|
-
result << @children.map do |child|
|
199
|
-
child.evaluate context
|
200
|
-
end.flatten
|
201
|
-
end
|
202
|
-
|
203
|
-
# Create a new context based on the parent context and progressively update
|
204
|
-
# variables in the new context
|
205
|
-
each_context = Context.new({}, context.binding.clone)
|
206
|
-
|
207
|
-
# Evaluate the iterable object
|
208
|
-
enumerable = each_context.evaluate(@value[1])
|
209
|
-
|
210
|
-
# Check if input can be iterated
|
211
|
-
Runtime.error :enumerable, @value[1] unless enumerable.respond_to? :each
|
212
|
-
|
213
|
-
# Selectively iterate through the input and add the result using the previously
|
214
|
-
# defined proc object
|
215
|
-
case enumerable
|
216
|
-
when Hash
|
217
|
-
enumerable.each do |key, value|
|
218
|
-
evaluate_children[key, value, context]
|
219
|
-
end
|
220
|
-
else
|
221
|
-
enumerable.each_with_index do |value, key|
|
222
|
-
evaluate_children[key, value, context]
|
223
|
-
end
|
224
|
-
end
|
225
|
-
|
226
|
-
return result.flatten.compact
|
227
|
-
end
|
228
|
-
end
|
229
|
-
end
|
230
|
-
end
|