opulent 0.0.8 → 0.0.9
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.rb +15 -28
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e616139da8f4b17f4fc7f52bb66b3e18d4d42be
|
4
|
+
data.tar.gz: eb8dfdcaae0b2fb04c83430a742c7ae31ad34364
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aca80c297f91ccc02b465534f6da7c755749092a10c14ca9b733e64df2f1aa90c551aeaa0383fa49ffd15ea3ecf81e6035df4b48e4bc6163e80aa41a4e0af048
|
7
|
+
data.tar.gz: 7363ff73b1572727aa7aecaa42b86b04c6e101b82e399b763d25a3538a9c2aee1e1974254b34be5073cc08d1aa8e0dc0269746de8215af2d5a41670fb20751ea
|
data/lib/opulent.rb
CHANGED
@@ -6,15 +6,26 @@ require_relative 'opulent/preprocessor'
|
|
6
6
|
require_relative 'opulent/tokens'
|
7
7
|
require_relative 'opulent/nodes'
|
8
8
|
require_relative 'opulent/parser'
|
9
|
+
require_relative 'opulent/runtime'
|
9
10
|
|
10
11
|
module Opulent
|
11
12
|
class << self
|
12
|
-
|
13
|
+
# Analyze the input code and check for matching tokens. In case no match was
|
14
|
+
# found, throw an exception. In special cases, modify the token hash.
|
15
|
+
#
|
16
|
+
# @param file [String] The file that needs to be analyzed
|
17
|
+
# @param context [Hash | String] Processing environment data
|
18
|
+
#
|
19
|
+
def render(file, context = nil)
|
20
|
+
# Get the code from the input file
|
21
|
+
@code = PreProcessor.process(file)
|
22
|
+
|
23
|
+
# Accept both ruby hashes and JSON files as database environments
|
24
|
+
@context = Runtime.apply context
|
25
|
+
|
13
26
|
# Instantiate required language components
|
14
27
|
@syntax = Parser.parse code
|
15
28
|
|
16
|
-
pp @syntax
|
17
|
-
|
18
29
|
pretty = Proc.new do |elements, indent|
|
19
30
|
if elements.is_a? Nodes::Text
|
20
31
|
puts " " * indent + "text: " + elements.value
|
@@ -28,7 +39,7 @@ module Opulent
|
|
28
39
|
end
|
29
40
|
puts text
|
30
41
|
|
31
|
-
if element.is_a?(Nodes::Text) || element.children.empty?
|
42
|
+
if element.is_a?(Nodes::Text) || element.is_a?(Nodes::Print) || element.is_a?(Nodes::Comment) || element.children.empty?
|
32
43
|
elsif [Nodes::CnditionalControl, Nodes::CaseControl].any? do |node| element.is_a? node end
|
33
44
|
element.children.each do |c| pretty[c, indent+2] end
|
34
45
|
else
|
@@ -48,30 +59,6 @@ module Opulent
|
|
48
59
|
end
|
49
60
|
puts "\n\nNodes\n---"
|
50
61
|
pretty[@syntax.children, 0]
|
51
|
-
|
52
|
-
|
53
|
-
#pp @syntax
|
54
|
-
end
|
55
|
-
|
56
|
-
# Analyze the input code and check for matching tokens. In case no match was
|
57
|
-
# found, throw an exception. In special cases, modify the token hash.
|
58
|
-
#
|
59
|
-
# @param file [String] The file that needs to be analyzed
|
60
|
-
# @param context [Hash | String] Processing environment data
|
61
|
-
#
|
62
|
-
def render(file, context = {})
|
63
|
-
@file = file
|
64
|
-
|
65
|
-
# Accept both ruby hashes and JSON files as database environments
|
66
|
-
case context
|
67
|
-
when Hash
|
68
|
-
@context = context
|
69
|
-
when String
|
70
|
-
@context = JSON.parse(File.read context)
|
71
|
-
end
|
72
|
-
|
73
|
-
# Run all the processors
|
74
|
-
compile PreProcessor.process @file
|
75
62
|
end
|
76
63
|
end
|
77
64
|
end
|