cadenza 0.7.1 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/cadenza +1 -1
- data/lib/cadenza/cli.rb +15 -24
- data/lib/cadenza/cli/options.rb +47 -0
- data/lib/cadenza/context.rb +15 -10
- data/lib/cadenza/text_renderer.rb +2 -2
- data/lib/cadenza/version.rb +1 -1
- metadata +3 -2
data/bin/cadenza
CHANGED
data/lib/cadenza/cli.rb
CHANGED
@@ -1,38 +1,29 @@
|
|
1
1
|
require 'optparse'
|
2
|
+
require 'cadenza/cli/options'
|
2
3
|
require 'multi_json'
|
3
4
|
|
4
5
|
module Cadenza
|
5
|
-
|
6
|
-
class Options < OptionParser
|
7
|
-
attr_reader :options
|
8
|
-
|
9
|
-
def self.parse!
|
10
|
-
parser = new("Cadenza")
|
11
|
-
parser.set_opts.parse!
|
12
|
-
parser.options
|
13
|
-
end
|
14
|
-
|
15
|
-
def initialize(*args)
|
16
|
-
@options = {}
|
17
|
-
super
|
18
|
-
end
|
6
|
+
module Cli
|
19
7
|
|
20
|
-
|
21
|
-
@options[:context] = MultiJson.load(context)
|
22
|
-
end
|
8
|
+
def self.run!(path, options={})
|
23
9
|
|
24
|
-
|
25
|
-
|
26
|
-
|
10
|
+
load_paths =
|
11
|
+
if options[:root]
|
12
|
+
[options[:root]]
|
13
|
+
elsif options.key?(:load_paths) && [:load_paths].any?
|
14
|
+
options[:load_paths]
|
15
|
+
else
|
16
|
+
[Dir.pwd]
|
27
17
|
end
|
18
|
+
|
19
|
+
load_paths.each do |path|
|
20
|
+
Cadenza::BaseContext.add_load_path path
|
28
21
|
end
|
29
|
-
end
|
30
22
|
|
31
|
-
def self.run!(path, context)
|
32
|
-
Cadenza::BaseContext.add_loader Cadenza::FilesystemLoader.new(File.expand_path('.'))
|
33
23
|
Cadenza::BaseContext.whiny_template_loading = true
|
34
24
|
|
35
|
-
Cadenza.render_template path, context
|
25
|
+
Cadenza.render_template path, options[:context]
|
26
|
+
|
36
27
|
end
|
37
28
|
|
38
29
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Cadenza::Cli
|
2
|
+
|
3
|
+
class Options < OptionParser
|
4
|
+
attr_reader :options
|
5
|
+
|
6
|
+
def self.parse!
|
7
|
+
parser = new("Cadenza")
|
8
|
+
parser.set_opts.parse!
|
9
|
+
parser.options
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(*args)
|
13
|
+
@options = {}
|
14
|
+
super
|
15
|
+
end
|
16
|
+
|
17
|
+
def context_option(context)
|
18
|
+
if File.exist?(context)
|
19
|
+
context = File.read(context)
|
20
|
+
end
|
21
|
+
@options[:context] = MultiJson.load(context)
|
22
|
+
end
|
23
|
+
|
24
|
+
def add_load_path(path)
|
25
|
+
@options[:load_paths] ||= []
|
26
|
+
@options[:load_paths] << path
|
27
|
+
end
|
28
|
+
|
29
|
+
def set_opts
|
30
|
+
on("--context json") do |value|
|
31
|
+
context_option value
|
32
|
+
end
|
33
|
+
on("-c json") do |value|
|
34
|
+
context_option value
|
35
|
+
end
|
36
|
+
on("--root path") do |value|
|
37
|
+
@options[:root] = value
|
38
|
+
end
|
39
|
+
on("-I", "--load-path PATH", "Add a path for the filesystem loader") do |path|
|
40
|
+
add_load_path(path)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
data/lib/cadenza/context.rb
CHANGED
@@ -195,18 +195,23 @@ module Cadenza
|
|
195
195
|
block.call(self, nodes, parameters)
|
196
196
|
end
|
197
197
|
|
198
|
-
#
|
199
|
-
#
|
200
|
-
# the string given as a path for it.
|
198
|
+
# constructs a {FilesystemLoader} with the string given as its path and
|
199
|
+
# adds the loader to the end of the loader list.
|
201
200
|
#
|
202
|
-
# @param [
|
201
|
+
# @param [String] path to use for loader
|
202
|
+
# @return [Loader] the loader that was created
|
203
|
+
def add_load_path(path)
|
204
|
+
loader = FilesystemLoader.new(path)
|
205
|
+
add_loader(loader)
|
206
|
+
loader
|
207
|
+
end
|
208
|
+
|
209
|
+
# adds the given loader to the end of the loader list.
|
210
|
+
#
|
211
|
+
# @param [Loader] loader the loader to add
|
203
212
|
# @return nil
|
204
213
|
def add_loader(loader)
|
205
|
-
|
206
|
-
@loaders.push FilesystemLoader.new(loader)
|
207
|
-
else
|
208
|
-
@loaders.push loader
|
209
|
-
end
|
214
|
+
@loaders.push loader
|
210
215
|
nil
|
211
216
|
end
|
212
217
|
|
@@ -337,4 +342,4 @@ module Cadenza
|
|
337
342
|
|
338
343
|
end
|
339
344
|
|
340
|
-
end
|
345
|
+
end
|
@@ -36,7 +36,7 @@ module Cadenza
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def render_block(node, context, blocks)
|
39
|
-
(blocks[node.name] || node).children.each {|x| render(x, context) }
|
39
|
+
(blocks[node.name] || node).children.each {|x| render(x, context, blocks) }
|
40
40
|
end
|
41
41
|
|
42
42
|
def render_text(node, context, blocks)
|
@@ -48,7 +48,7 @@ module Cadenza
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def render_if(node, context, blocks)
|
51
|
-
node.evaluate_expression_for_children(context).each {|x| render(x, context) }
|
51
|
+
node.evaluate_expression_for_children(context).each {|x| render(x, context, blocks) }
|
52
52
|
end
|
53
53
|
|
54
54
|
def render_for(node, context, blocks)
|
data/lib/cadenza/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cadenza
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: multi_json
|
@@ -170,6 +170,7 @@ files:
|
|
170
170
|
- lib/cadenza/functional_variables/standard_functional_variables.rb
|
171
171
|
- lib/cadenza/version.rb
|
172
172
|
- lib/cadenza/text_renderer.rb
|
173
|
+
- lib/cadenza/cli/options.rb
|
173
174
|
- lib/cadenza/parser.rb
|
174
175
|
- lib/cadenza/base_renderer.rb
|
175
176
|
- lib/cadenza/token.rb
|