opulent 1.0.9 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9baf3c32e813f2550fb722422d6c633f6eebe36f
4
- data.tar.gz: 2f90f83587e077dde2c39bb064bde69a4b20e744
3
+ metadata.gz: fb989f9b5f0876f4af2c6951f7ddb013f03f2b83
4
+ data.tar.gz: 56271859c6703789c2b56157817fca15044256a9
5
5
  SHA512:
6
- metadata.gz: 96e3437d935c6e9d1d32c092adf5cadc527df97f13a965be7cddbf83da87c8c8048910f34d4cb42030a27969336309660bd1c93885a8bb98f41704185cd0fa68
7
- data.tar.gz: 9bee9a6acc7cb0d209cc4c92bf3448d782a649b685bb16d0dc2f1b384c6434b7443794940477445837a474a5b3b9c2601a8b85c2c80566a08ac42f48952bf182
6
+ metadata.gz: bb801aa49723ef35738eff275ca1b96edc3db5c2080292b13c9e0ff96c9600cb5f5ebe9cb0a63ece21824814b2700be25d348565fbcc63f44e728dc855cac59b
7
+ data.tar.gz: 82cffc61c9c99d51583b7050ef37bb394358de4ae94927b6b595edea121efb50cb76fbab18e0cbc7430ac423465af137654a59e78db2f86ff6e99d90abd18394
@@ -5,4 +5,4 @@ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
5
5
  require 'opulent'
6
6
  require 'opulent/exec'
7
7
 
8
- Haml::Exec.start ARGV
8
+ Opulent::CLI.new ARGV
@@ -0,0 +1,129 @@
1
+ require 'json'
2
+ require 'yaml'
3
+ require 'opulent/version'
4
+
5
+ # @Opulent
6
+ module Opulent
7
+ # @CLI
8
+ class CLI
9
+ Extension = /\.(op|opl|opulent)\Z/
10
+
11
+ Keywords = %w(context layout locals version help)
12
+
13
+ def initialize(arguments)
14
+ i = 0
15
+
16
+ while arguments[i]
17
+ case arguments[i]
18
+
19
+ # opulent input.op output.op
20
+ when Extension
21
+ @input = arguments[i]
22
+ unless arguments[i + 1] =~ /\A\-/ || Keywords.include?(arguments[i+1])
23
+ @output = arguments[(i += 1)]
24
+ end
25
+
26
+ # opulent -v
27
+ when '-l', 'layout'
28
+ if arguments[i + 1] =~ Extension
29
+ @layout = arguments[(i += 1)]
30
+ else
31
+ error "Missing input or incorrect file extension for layout [-l] argument. " +
32
+ "#{"Found #{arguments[i+1]} instead." if arguments[i+1] }"
33
+ end
34
+
35
+ # opulent -v
36
+ when '-v', 'version'
37
+ write "Version #{Opulent::VERSION} is currently installed."
38
+ return
39
+
40
+ # opulent -c
41
+ when '-c', 'context', '-lc', 'locals'
42
+ @locals_file = arguments[(i += 1)]
43
+ error "Given context file #{@locals_file.inspect} does not exist or an incorrect path has been specified." unless File.file? @locals_file
44
+
45
+ if File.extname(@locals_file) == '.json'
46
+ @locals = JSON.parse File.read(@locals_file), symbolize_keys: true
47
+ elsif File.extname(@locals_file) == '.yml'
48
+ @locals = YAML.load_file @locals_file
49
+ else
50
+ error "Unknown file extension #{@locals_file.inspect} given as locals file. Please use JSON or YAML as input."
51
+ end
52
+
53
+ # opulent -h
54
+ when '-h', 'help'
55
+ write help
56
+ return
57
+ else
58
+ error "Unknown input argument [#{arguments[i]}] has been encountered."
59
+ end
60
+
61
+ i += 1
62
+ end
63
+
64
+ if @input
65
+ @locals ||= {}
66
+ error "Given input file #{@input.inspect} does not exist or an incorrect path has been specified." unless File.file? @input
67
+
68
+ message = ""
69
+ opulent = Opulent.new
70
+ if @layout
71
+ output = Proc.new do
72
+ opulent.render_file(@layout, @locals) {
73
+ opulent.render_file(@input, @locals){}
74
+ }
75
+ end[]
76
+ else
77
+ output = Proc.new do
78
+ opulent.render_file(@input, @locals)
79
+ end[]
80
+ end
81
+
82
+ if @output
83
+ File.open @output, 'w' do |file| file.write output end
84
+ message += "Successfully rendered #{@input.inspect} to #{@output.inspect}."
85
+ #message += "Used #{@locals_file.inspect} as local context file." if @locals_file
86
+ else
87
+ message += "Successfully rendered #{@input.inspect}.\n\n"
88
+ #message += "Used #{@locals_file.inspect} as local context file.\n\n" if @locals_file
89
+ message += "No output file specified. Writing result to terminal.\n\n#{output}"
90
+ end
91
+
92
+ write message
93
+ else
94
+ error "You haven't specified an input file."
95
+ end
96
+ end
97
+
98
+ def help(extra = "")
99
+ "#{extra}You can use the following commands with the Opulent Command Line Interface: \n\n
100
+ opulent input.op output.op Render an input file and write the result to the output file.\n
101
+ opulent layout [-l] layout.op Render an input file using given input layout file.\n
102
+ opulent help [-h] Show available command line options.\n
103
+ opulent version [-v] Show installed version.\n"
104
+ end
105
+
106
+ # Give an explicit response for the given input arguments
107
+ #
108
+ # @param message [String] Response message to display to the user
109
+ #
110
+ def write(message)
111
+ # Reconstruct lines to display where errors occur
112
+ puts "\nOpulent " + Logger.green('[Engine]') +
113
+ "\n---\n" +
114
+ "#{message}\n\n\n"
115
+ end
116
+
117
+ # Give an explicit error report where an unexpected sequence of tokens
118
+ # appears and give indications on how to solve it
119
+ #
120
+ # @param message [String] Error message to display to the user
121
+ #
122
+ def error(message)
123
+ # Reconstruct lines to display where errors occur
124
+ fail "\nOpulent " + Logger.red('[Engine]') +
125
+ "\n---\n" +
126
+ "#{message}\n\n#{help}\n\n\n"
127
+ end
128
+ end
129
+ end
@@ -1,4 +1,4 @@
1
1
  # @Opulent
2
2
  module Opulent
3
- VERSION = "1.0.9"
3
+ VERSION = "1.1.0"
4
4
  end
@@ -35,5 +35,4 @@ Gem::Specification.new do |spec|
35
35
 
36
36
  spec.add_runtime_dependency 'htmlentities'
37
37
  spec.add_runtime_dependency 'tilt'
38
- spec.add_runtime_dependency 'thor'
39
38
  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: 1.0.9
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Grozav
@@ -80,20 +80,6 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: thor
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :runtime
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
83
  description: Opulent is an intelligent Templating Engine created to speed up web development
98
84
  through fast rendering and custom web component definitions.
99
85
  email:
@@ -152,7 +138,6 @@ files:
152
138
  - docs/syntax.md
153
139
  - docs/usage.md
154
140
  - lib/opulent.rb
155
- - lib/opulent/cli.rb
156
141
  - lib/opulent/compiler.rb
157
142
  - lib/opulent/compiler/block.rb
158
143
  - lib/opulent/compiler/comment.rb
@@ -165,6 +150,7 @@ files:
165
150
  - lib/opulent/compiler/text.rb
166
151
  - lib/opulent/context.rb
167
152
  - lib/opulent/engine.rb
153
+ - lib/opulent/exec.rb
168
154
  - lib/opulent/filters.rb
169
155
  - lib/opulent/logger.rb
170
156
  - lib/opulent/parser.rb
@@ -1,12 +0,0 @@
1
- require 'thor'
2
-
3
- # @Opulent
4
- module Opulent
5
- # @CLI
6
- class CLI < Thor
7
- desc 'hello NAME', 'Display greeting with given NAME'
8
- def hello(name)
9
- puts "Hello #{name}"
10
- end
11
- end
12
- end