erber 0.0.1 → 0.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: 81431aea1c26ea28cd1c488a06105d2c0e1bf571
4
- data.tar.gz: 2e962279bc91bda4c624ec66cbd37e7f93f2fdb6
3
+ metadata.gz: 90e87ce83e90a4a879cd85cae5712d3f9e127d7c
4
+ data.tar.gz: 56b50895bd0d6142b0af86f930193f600c313969
5
5
  SHA512:
6
- metadata.gz: 731af80fba50311ac18362295f0915eed101bad0164baca76c054e72e67102316fcd0963a387835f5dd9e488c53f0795c654515c156895dd214bd4c90941ed4d
7
- data.tar.gz: 6a8f50a9a2c35c30ef247acb7608170edfb3d85bff51fa0e7ff4a18d03ec7dd48cbc32a630650a9914402309bf710d2abdeab1aef6f82f014235a4b37c7b34b9
6
+ metadata.gz: 3f8668a674c24b5fb991b54991fa8b9ca4a6e77700cdf9cf02ecc1c36006dff48b0f0b6b1376d97140d81dabf2ad0158fbf9c838746e631cf8380c439f548d87
7
+ data.tar.gz: 29b9d74e20ea3d8b5c21ef8f872bab0e5e68182ef4b091ee1edd2475283e21efd34396ccccc5f3407fee63439ba910fbc3bc62ddf3ac60bf69fe4f29038b4881
data/lib/erber/cli.rb CHANGED
@@ -11,13 +11,14 @@ module Erber
11
11
  def self.go
12
12
  parser = Trollop::Parser.new do
13
13
  opt :property_file, "Property file to include (JSON or YAML)", :type => :string, :multi => true
14
+ opt :override_property, "'dotted.key.name=value' property to inject.", :type => :string, :multi => true
14
15
  end
15
16
 
16
17
  opts = parser.parse(ARGV)
17
18
  filenames = parser.leftovers
18
19
 
19
20
  if filenames.length != 1
20
- $stderr.puts "Usage: erber [-p props1.yaml [-p props2.json [...]]] template.erb"
21
+ $stderr.puts "Usage: erber [-p props1.yaml [-p props2.json [...]]] [-o foo=bar [-o baz.boop=beep [...]]] template.erb"
21
22
  Kernel.exit(1)
22
23
  end
23
24
 
@@ -36,7 +37,22 @@ module Erber
36
37
  end
37
38
  end
38
39
 
40
+ props.deep_merge!(unroll_flat_properties(opts[:override_property].map { |o| o.split("=", 2) } ))
41
+
39
42
  puts templater.render(props)
40
43
  end
44
+
45
+
46
+ def self.unroll_flat_properties(overrides)
47
+ hash_trees = overrides.map do |main_key, main_value|
48
+ main_key.to_s.split(".").reverse.inject(main_value) do |value, key|
49
+ {key.to_s => value}
50
+ end
51
+ end
52
+
53
+ retval = {}
54
+ hash_trees.each { |h| retval.deep_merge!(h) }
55
+ retval
56
+ end
41
57
  end
42
58
  end
data/lib/erber/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Erber
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -5,4 +5,6 @@ a:
5
5
  yaml:
6
6
  - 1
7
7
  - 2
8
- - 3
8
+ - 3
9
+ the:
10
+ cli: "nope, not here"
data/test-data/test.erb CHANGED
@@ -1,3 +1,5 @@
1
1
  <%= a.test.for.some.json %>
2
2
  <%= a.test.for.some.yaml %>
3
- <%= a.test.for.some %>
3
+ <%= a.test.for.some %>
4
+
5
+ <%= a.test.for.the.cli %>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: erber
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ed Ropple