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.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/CODE_OF_CONDUCT.md +13 -0
  3. data/{LICENSE → LICENSE.md} +0 -0
  4. data/bin/opulent +0 -0
  5. data/lib/opulent.rb +10 -10
  6. data/lib/opulent/compiler.rb +15 -9
  7. data/lib/opulent/compiler/buffer.rb +123 -62
  8. data/lib/opulent/compiler/comment.rb +3 -4
  9. data/lib/opulent/compiler/control.rb +20 -26
  10. data/lib/opulent/compiler/define.rb +88 -36
  11. data/lib/opulent/compiler/doctype.rb +20 -22
  12. data/lib/opulent/compiler/eval.rb +23 -2
  13. data/lib/opulent/compiler/filter.rb +4 -5
  14. data/lib/opulent/compiler/node.rb +18 -12
  15. data/lib/opulent/compiler/root.rb +4 -5
  16. data/lib/opulent/compiler/text.rb +7 -2
  17. data/lib/opulent/compiler/yield.rb +2 -3
  18. data/lib/opulent/engine.rb +21 -20
  19. data/lib/opulent/exec.rb +21 -63
  20. data/lib/opulent/logger.rb +230 -3
  21. data/lib/opulent/parser.rb +14 -76
  22. data/lib/opulent/parser/comment.rb +45 -34
  23. data/lib/opulent/parser/control.rb +132 -111
  24. data/lib/opulent/parser/define.rb +15 -12
  25. data/lib/opulent/parser/doctype.rb +15 -15
  26. data/lib/opulent/parser/eval.rb +16 -6
  27. data/lib/opulent/parser/expression.rb +87 -84
  28. data/lib/opulent/parser/filter.rb +31 -25
  29. data/lib/opulent/parser/include.rb +38 -42
  30. data/lib/opulent/parser/node.rb +136 -118
  31. data/lib/opulent/parser/root.rb +24 -18
  32. data/lib/opulent/parser/text.rb +150 -123
  33. data/lib/opulent/parser/yield.rb +23 -23
  34. data/lib/opulent/settings.rb +70 -51
  35. data/lib/opulent/tokens.rb +17 -15
  36. data/lib/opulent/utils.rb +5 -4
  37. data/lib/opulent/version.rb +1 -1
  38. metadata +4 -43
  39. data/.libold/opulent.rb +0 -96
  40. data/.libold/opulent/context.rb +0 -80
  41. data/.libold/opulent/engine.rb +0 -88
  42. data/.libold/opulent/filter.rb +0 -101
  43. data/.libold/opulent/logger.rb +0 -67
  44. data/.libold/opulent/nodes.rb +0 -13
  45. data/.libold/opulent/nodes/block.rb +0 -29
  46. data/.libold/opulent/nodes/comment.rb +0 -35
  47. data/.libold/opulent/nodes/control.rb +0 -230
  48. data/.libold/opulent/nodes/define.rb +0 -42
  49. data/.libold/opulent/nodes/eval.rb +0 -41
  50. data/.libold/opulent/nodes/expression.rb +0 -28
  51. data/.libold/opulent/nodes/filter.rb +0 -70
  52. data/.libold/opulent/nodes/helper.rb +0 -69
  53. data/.libold/opulent/nodes/node.rb +0 -101
  54. data/.libold/opulent/nodes/root.rb +0 -62
  55. data/.libold/opulent/nodes/text.rb +0 -54
  56. data/.libold/opulent/nodes/theme.rb +0 -36
  57. data/.libold/opulent/parser.rb +0 -252
  58. data/.libold/opulent/parser/block.rb +0 -70
  59. data/.libold/opulent/parser/comment.rb +0 -32
  60. data/.libold/opulent/parser/control.rb +0 -83
  61. data/.libold/opulent/parser/define.rb +0 -39
  62. data/.libold/opulent/parser/eval.rb +0 -33
  63. data/.libold/opulent/parser/expression.rb +0 -350
  64. data/.libold/opulent/parser/filter.rb +0 -41
  65. data/.libold/opulent/parser/node.rb +0 -232
  66. data/.libold/opulent/parser/root.rb +0 -96
  67. data/.libold/opulent/parser/text.rb +0 -114
  68. data/.libold/opulent/parser/theme.rb +0 -36
  69. data/.libold/opulent/preprocessor.rb +0 -102
  70. data/.libold/opulent/runtime.rb +0 -144
  71. data/.libold/opulent/template.rb +0 -43
  72. data/.libold/opulent/tokens.rb +0 -276
  73. data/.libold/opulent/version.rb +0 -5
  74. data/.travis.yml +0 -4
  75. data/benchmark/benchmark.rb +0 -57
  76. data/benchmark/cases/node/node.haml +0 -7
  77. data/benchmark/cases/node/node.op +0 -7
  78. data/benchmark/cases/node/node.slim +0 -7
@@ -1,42 +0,0 @@
1
- # @Opulent
2
- module Opulent
3
- # @Nodes
4
- module Nodes
5
- # @Define
6
- #
7
- # Define a custom HTML element
8
- #
9
- class Define < Node
10
- # Node evaluation method which goes through all the child nodes and
11
- # evaluates them using their own eval method
12
- #
13
- def evaluate(context, blocks = {})
14
- yields = @yields.clone
15
-
16
- @children.map do |child|
17
- evaluated_child = child.evaluate context
18
-
19
- # Check to see if the child element being mapped is one of the yield
20
- # node parent pointers
21
- if yields.include? child
22
- yields.delete child
23
-
24
- # We need to replace the yield nodes with the matching named block
25
- # in order to map the yield node correctly
26
- evaluated_child.children.map! do |subchild|
27
- if subchild.is_a?(Yield) && blocks[subchild.name]
28
- blocks[subchild.name]
29
- else
30
- subchild
31
- end
32
- end
33
- evaluated_child.children.compact!
34
- evaluated_child.children.flatten!
35
- end
36
-
37
- evaluated_child
38
- end
39
- end
40
- end
41
- end
42
- end
@@ -1,41 +0,0 @@
1
- # @Opulent
2
- module Opulent
3
- # @Nodes
4
- module Nodes
5
- # @Evaluate
6
- #
7
- # The eval node evaluates ruby code in the given context without printing
8
- # any output in the page
9
- #
10
- class Evaluate
11
- attr_accessor :value, :parent, :indent, :children, :name
12
-
13
- # Ruby code evaluation node
14
- #
15
- # @param name [String] name of the html node
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(value = '', parent = nil, indent = 0, children = [])
21
- @name = :eval
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 << node
32
- self
33
- end
34
-
35
- def evaluate(context)
36
- context.evaluate @value
37
- return nil
38
- end
39
- end
40
- end
41
- end
@@ -1,28 +0,0 @@
1
- # @Opulent
2
- module Opulent
3
- # @Nodes
4
- module Nodes
5
- # @Expression
6
- #
7
- # Literals are static values that have a Ruby representation, eg.: a string, a number,
8
- # true, false, nil, etc.
9
- #
10
- class Expression
11
- attr_accessor :value, :escaped
12
-
13
- def initialize(value = '')
14
- @value = value
15
- @escaped = true
16
- end
17
-
18
- def to_s
19
- @value
20
- end
21
-
22
- def evaluate(context)
23
- evaluated = context.evaluate @value
24
- @escaped ? Runtime.escape(evaluated) : evaluated
25
- end
26
- end
27
- end
28
- end
@@ -1,70 +0,0 @@
1
- # @Opulent
2
- module Opulent
3
- # @Nodes
4
- module Nodes
5
- # @Filter
6
- #
7
- # Node class used to run a value interpretation
8
- #
9
- class Filter
10
- # Allow direct access to node variables
11
- attr_accessor :name, :attributes, :value, :parent, :indent
12
-
13
- # Initialize node instance variables
14
- #
15
- # @param name [String] name of the html node
16
- # @param indentation [Fixnum] node indentation for restructuring
17
- # @param attributes [Hash] stores key="value" attributes
18
- # @param value [String] Contents to be interpreted
19
- #
20
- def initialize(name = '', attributes = {}, parent = nil, indent = 0, value = '')
21
- @name = name
22
- @parent = parent
23
- @indent = indent
24
- @attributes = attributes
25
- @value = value
26
- end
27
-
28
- # Update attributes with values from current evaluation context
29
- #
30
- def get_attributes(context)
31
- Hash[@attributes.map{ |key, val|
32
- unless val.nil?
33
- value = val.evaluate(context)
34
- value.flatten! if value.is_a?(Array)
35
- end
36
- [key, value]
37
- }]
38
- end
39
-
40
- # Node evaluation method which goes through all the child nodes and evaluates
41
- # them using their own eval method
42
- #
43
- def evaluate(context)
44
- # Set attributes for current context
45
- attributes = Runtime.attributes @attributes, nil, context
46
-
47
- # Check if filter is registered
48
- Runtime.error :filter_registered, name unless Engine.filter? name
49
-
50
- # Load the required filter
51
- Engine.filters[name].load_filter
52
-
53
- # Render output using the chosen engine
54
- output = Engine.filters[name].render @value
55
-
56
- # Main output node which contains filter rendered value
57
- text_node = Text.new output, false, @parent, @indent
58
-
59
- # If we have a provided filter tag, wrap the text node in the wrapper
60
- # node tag and further indent
61
- if (wrapper_tag = Engine.filters[name].options[:tag])
62
- text_node.indent = @indent + Engine[:indent]
63
- return Node.new wrapper_tag, Engine.filters[name].options[:attributes], @parent, @indent, [text_node]
64
- else
65
- return text_node
66
- end
67
- end
68
- end
69
- end
70
- end
@@ -1,69 +0,0 @@
1
- # @Opulent
2
- module Opulent
3
- # @Nodes
4
- module Nodes
5
- # @NodeFactory
6
- class Helper
7
- def root
8
- Root.new
9
- end
10
-
11
- def node(name = '', atts = {}, parent = nil, indent = 0, children = [])
12
- Node.new name, atts, parent, indent, children
13
- end
14
-
15
- def block_yield(name = '', parent = nil, indent = 0, children = [])
16
- Yield.new name, {}, parent, indent, children
17
- end
18
-
19
- def block(name = '', parent = nil, indent = 0, children = [])
20
- Block.new name, {}, parent, indent, children
21
- end
22
-
23
- def theme(name = '', parent = nil, indent = 0, children = [])
24
- Theme.new name, parent, indent, children
25
- end
26
-
27
- def filter(name = '', atts = {}, parent = nil, indent = 0, value = '')
28
- Filter.new name, atts, parent, indent, value
29
- end
30
-
31
- def evaluate(value, parent = nil, indent = 0, children = [])
32
- Evaluate.new value, parent, indent, children
33
- end
34
-
35
- def control(name, value = '', parent = nil, indent = 0, children = [[]])
36
- case name
37
- when :if, :unless
38
- CnditionalControl.new name, value, parent, indent, children
39
- when :case
40
- CaseControl.new name, value, parent, indent, children.first
41
- when :while, :until
42
- LoopControl.new name, value, parent, indent, children.first
43
- when :each
44
- EachControl.new name, value, parent, indent, children.first
45
- end
46
- end
47
-
48
- def expression(value = [])
49
- Expression.new value
50
- end
51
-
52
- def definition(name, params = [], parent = nil, indent = 0)
53
- Define.new name, params, parent, indent
54
- end
55
-
56
- def text(value = nil, escaped = true, parent = nil, indent = 0)
57
- Text.new value, escaped, parent, indent
58
- end
59
-
60
- def print(value = nil, escaped = true, parent = nil, indent = 0)
61
- Print.new value, escaped, parent, indent
62
- end
63
-
64
- def comment(value = nil, parent = nil, indent = 0)
65
- Comment.new value, parent, indent
66
- end
67
- end
68
- end
69
- end
@@ -1,101 +0,0 @@
1
- # @Opulent
2
- module Opulent
3
- # @Nodes
4
- module Nodes
5
- # @Node
6
- #
7
- # Node class used to describe a HTML Element used for building a
8
- # page model during the parsing process
9
- #
10
- class Node
11
- # Allow direct access to node variables
12
- attr_accessor :name, :attributes, :children, :whitespace, :parent, :indent, :extension, :theme, :blocks, :yields, :self_enclosing
13
-
14
- # Initialize node instance variables
15
- #
16
- # @param name [String] name of the html node
17
- # @param indentation [Fixnum] node indentation for restructuring
18
- # @param attributes [Hash] stores key="value" attributes
19
- # @param children [Array] collection of the node's child elements
20
- #
21
- def initialize(name = '', attributes = {}, parent = nil, indent = 0, children = [])
22
- @name = name
23
- @parent = parent
24
- @indent = indent
25
- @attributes = attributes
26
- @children = children
27
- @extension = nil
28
- @theme = Engine::DEFAULT_THEME
29
- @self_enclosing = Engine::SELF_ENCLOSING.include? name
30
- @whitespace = [nil, nil]
31
- @blocks = {
32
- Engine::DEFAULT_YIELD => @children
33
- }
34
- @yields = []
35
- end
36
-
37
- # Add a new node to the nodes array
38
- #
39
- def push(node)
40
- @children << node
41
- self
42
- end
43
-
44
- # Return extended attributes if an extension was set using the [extend]
45
- # identifier of the node
46
- #
47
- def extend_attributes(attributes, extension)
48
- return attributes if extension.nil?
49
-
50
- extension.each do |key, value|
51
- case attributes[key]
52
- when Array
53
- attributes[key] = (attributes[key] << value).flatten
54
- when Hash
55
- attributes[key] = value.merge attributes[key]
56
- when nil
57
- attributes[key] = value
58
- end
59
- end
60
-
61
- attributes
62
- end
63
-
64
- # Node evaluation method which goes through all the child nodes and evaluates
65
- # them using their own eval method
66
- #
67
- def evaluate(context)
68
- # Set attributes for current context
69
- attributes = Runtime.attributes @attributes, @extension, context
70
-
71
- # Evaluate all provided blocks
72
- blocks = Hash[@blocks.map{ |key, value|
73
- children = value.map do |child|
74
- child.evaluate context
75
- end.flatten.compact
76
-
77
- [key, children]
78
- }]
79
-
80
- # Map self to a different node and set evaluated children nodes and
81
- # evaluated attributes and add a pointer to the children block
82
- mapped_node = self.dup
83
- mapped_node.attributes = attributes
84
- mapped_node.blocks = blocks
85
- mapped_node.children = mapped_node.blocks[Engine::DEFAULT_YIELD]
86
-
87
- # Replace node with its definition if it has one
88
- if Runtime[@theme]
89
- if Runtime[@theme][@name] && @name != context.name
90
- return Runtime.define mapped_node, attributes, context
91
- else
92
- return mapped_node
93
- end
94
- else
95
- # Theme does not exist
96
- Runtime.error :theme, @theme
97
- end
98
- end
99
- end
100
- end
101
- end
@@ -1,62 +0,0 @@
1
- # @Opulent
2
- module Opulent
3
- # @Nodes
4
- module Nodes
5
- # @Root
6
- #
7
- # HTML Root from which the construction of the final page starts. The root
8
- # stores all the node definitions that will be replaced in the components.
9
- #
10
- class Root
11
- # Allow direct access to node variables
12
- attr_accessor :themes, :children, :indent, :blocks, :yields
13
-
14
- # Initialize node instance variables
15
- #
16
- # @param definitions [Hash] node definitions to be replaced in children
17
- # @param children [Array] collection of the node's child elements
18
- #
19
- def initialize
20
- @themes = {
21
- Engine::DEFAULT_THEME => {}
22
- }
23
- @children = []
24
- @blocks = {}
25
- @yields = {}
26
- @indent = -1
27
- end
28
-
29
- # Add a new node to the nodes array
30
- #
31
- # @param node [Node] Node to be added to the parent
32
- #
33
- def push(node)
34
- @children << node
35
- self
36
- end
37
-
38
- # Shorthand theme access for root definitions
39
- #
40
- # @param key [Symbol] definition or theme name
41
- #
42
- def [](key)
43
- if @themes.has_key? key
44
- @themes[key]
45
- else
46
- @themes[Engine::DEFAULT_THEME][key]
47
- end
48
- end
49
-
50
- # Evaluate all child nodes using the given context and the
51
- # node definitions from the root knowledgebase
52
- #
53
- # @param context [Context] Call environment binding object
54
- #
55
- def evaluate(context)
56
- @children.map do |node|
57
- node.evaluate(context)
58
- end.flatten.compact
59
- end
60
- end
61
- end
62
- end
@@ -1,54 +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 Text
10
- # Allow direct access to literal value and type
11
- attr_accessor :value, :escaped, :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, escaped = true, parent = nil, indent = 0)
18
- @value = value
19
- @escaped = escaped
20
- @parent = parent
21
- @indent = indent
22
- @name = :text
23
- end
24
-
25
- # Value evaluation method which returns the processed value of the
26
- # literal
27
- #
28
- def evaluate(context)
29
- value = context.evaluate "\"#{@value}\""
30
-
31
- evaluated_text = self.dup
32
- evaluated_text.value = @escaped ? Runtime.escape(value) : value
33
- return evaluated_text
34
- end
35
- end
36
-
37
- # @Print
38
- #
39
- # The print class will evaluate the ruby code and return a new text
40
- # node containing the escaped or unescaped eval sequence
41
- #
42
- class Print < Text
43
- # Value evaluation method which returns the processed value of the literal
44
- #
45
- def evaluate(context)
46
- value = context.evaluate @value
47
-
48
- evaluated_text = self.dup
49
- evaluated_text.value = @escaped ? Runtime.escape(value) : value
50
- return evaluated_text
51
- end
52
- end
53
- end
54
- end