erber 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 81431aea1c26ea28cd1c488a06105d2c0e1bf571
4
+ data.tar.gz: 2e962279bc91bda4c624ec66cbd37e7f93f2fdb6
5
+ SHA512:
6
+ metadata.gz: 731af80fba50311ac18362295f0915eed101bad0164baca76c054e72e67102316fcd0963a387835f5dd9e488c53f0795c654515c156895dd214bd4c90941ed4d
7
+ data.tar.gz: 6a8f50a9a2c35c30ef247acb7608170edfb3d85bff51fa0e7ff4a18d03ec7dd48cbc32a630650a9914402309bf710d2abdeab1aef6f82f014235a4b37c7b34b9
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in erber.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Ed Ropple
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # `erber`
2
+ Here in devops-land, I find myself needing to do template substitutions on the regular--enough that it'd be a pain to do it with `sed` but not enough that I want to build a dedicated tool for that one project. (I had enough of that with [`terraframe`](https://github.com/eropple/terraframe), I don't need more.)
3
+
4
+ So today I whipped out `erber`, a simple
5
+
6
+ All you need to do to use `erber` is:
7
+ ```bash
8
+ gem install erber
9
+
10
+ erber -p props1.json -p props2.yaml template.txt.erb > your_output.txt
11
+ ```
12
+
13
+ One note: `erber` uses `Hashie::Mash` internally, so you can use either method names or hash chain syntax, as you prefer. I don't judge.
14
+
15
+ ## Contributing
16
+
17
+ 1. Fork it ( https://github.com/eropple/erber/fork )
18
+ 2. Create your feature branch (`git checkout -b develop/my-new-feature`)
19
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
20
+ 4. Push to the branch (`git push origin develop/my-new-feature`)
21
+ 5. Create a new Pull Request!
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/erber ADDED
@@ -0,0 +1,8 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
4
+ $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
5
+
6
+ require 'erber/cli'
7
+
8
+ Erber::CLI::go
data/erber.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'erber/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "erber"
8
+ spec.version = Erber::VERSION
9
+ spec.authors = ["Ed Ropple"]
10
+ spec.email = ["ed@edropple.com"]
11
+ spec.summary = %q{A simple tool for wrangling ERBs and dumb data.}
12
+ spec.homepage = ""
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.7"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "pry"
23
+
24
+ spec.add_runtime_dependency 'hashie', '~> 3.3.2'
25
+ spec.add_runtime_dependency 'trollop', '~> 2.0'
26
+ spec.add_runtime_dependency 'deep_merge', '~> 1.0.1'
27
+ end
data/lib/erber/cli.rb ADDED
@@ -0,0 +1,42 @@
1
+ require 'json'
2
+ require 'yaml'
3
+
4
+ require 'trollop'
5
+ require 'deep_merge'
6
+
7
+ require 'erber/templater'
8
+
9
+ module Erber
10
+ module CLI
11
+ def self.go
12
+ parser = Trollop::Parser.new do
13
+ opt :property_file, "Property file to include (JSON or YAML)", :type => :string, :multi => true
14
+ end
15
+
16
+ opts = parser.parse(ARGV)
17
+ filenames = parser.leftovers
18
+
19
+ if filenames.length != 1
20
+ $stderr.puts "Usage: erber [-p props1.yaml [-p props2.json [...]]] template.erb"
21
+ Kernel.exit(1)
22
+ end
23
+
24
+ templater = Erber::Templater.new(IO.read(filenames[0]))
25
+
26
+ props = {}
27
+ opts[:property_file].each do |property_file|
28
+ case File.extname(property_file)
29
+ when ".yaml"
30
+ props.deep_merge!(YAML.load(IO.read(property_file)))
31
+ when ".json"
32
+ props.deep_merge!(JSON.parse(IO.read(property_file)))
33
+ else
34
+ $stderr.puts "ERROR: unrecognized property format '#{property_file}'."
35
+ Kernel.exit(1)
36
+ end
37
+ end
38
+
39
+ puts templater.render(props)
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,24 @@
1
+ require 'erb'
2
+ require 'hashie'
3
+
4
+ module Erber
5
+ module BindingMixin
6
+ def get_binding
7
+ binding()
8
+ end
9
+ end
10
+
11
+ class Templater
12
+ def initialize(template_text)
13
+ @template = ERB.new(template_text, 0, "% <> > -")
14
+ end
15
+
16
+ def render(properties_hash)
17
+ mash = Hashie::Mash.new(properties_hash)
18
+
19
+ mash.extend BindingMixin
20
+
21
+ @template.result(mash.get_binding)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module Erber
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,8 @@
1
+ a:
2
+ test:
3
+ for:
4
+ some:
5
+ yaml:
6
+ - 1
7
+ - 2
8
+ - 3
@@ -0,0 +1,15 @@
1
+ {
2
+ "a": {
3
+ "test": {
4
+ "for": {
5
+ "some": {
6
+ "json": [
7
+ 10,
8
+ 20,
9
+ 30
10
+ ]
11
+ }
12
+ }
13
+ }
14
+ }
15
+ }
@@ -0,0 +1,3 @@
1
+ <%= a.test.for.some.json %>
2
+ <%= a.test.for.some.yaml %>
3
+ <%= a.test.for.some %>
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: erber
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ed Ropple
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: hashie
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 3.3.2
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 3.3.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: trollop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: deep_merge
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.0.1
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.0.1
97
+ description:
98
+ email:
99
+ - ed@edropple.com
100
+ executables:
101
+ - erber
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - bin/erber
111
+ - erber.gemspec
112
+ - lib/erber/cli.rb
113
+ - lib/erber/templater.rb
114
+ - lib/erber/version.rb
115
+ - test-data/props1.yaml
116
+ - test-data/props2.json
117
+ - test-data/test.erb
118
+ homepage: ''
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.2.2
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: A simple tool for wrangling ERBs and dumb data.
142
+ test_files: []