opulent 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/opulent.rb +15 -28
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a157e5d1656574b3e10e7be95442def3d8492944
4
- data.tar.gz: c82f2a8c9cf6bb67776f8f424ceb56346334553c
3
+ metadata.gz: 6e616139da8f4b17f4fc7f52bb66b3e18d4d42be
4
+ data.tar.gz: eb8dfdcaae0b2fb04c83430a742c7ae31ad34364
5
5
  SHA512:
6
- metadata.gz: 805f557356a0d1a07496247844a45eb6aa1df4429d763e83b545b5f79c8ff1a9c838fbe9ce64e4ed1c10ae84a95cd8675b8b4d047bb3db88e684c39c89a8cb39
7
- data.tar.gz: 2fd74584d3f2d8839d5b07e18f0c239ac7fcbddfe9df59e01acd7952fc3f94ec30813a2c9cdeee6d73c66d18c76d1427d94e146546d1ec680bdc80c3f4a1e00d
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
- def compile(code = "")
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
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: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Grozav