templator 0.2 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour --format documentation
data/CHANGES CHANGED
@@ -1,3 +1,7 @@
1
+ = 0.2.1
2
+ * Fix gemspec errors
3
+ = 0.2
4
+ * Refactor the Parameter DSL loading mechanism in order to display more comprehensible error messages.
1
5
  = 0.1.1 / 2012-02-03
2
6
  * Fix bug when doing recursive calls to include_file action,
3
7
  only the result of the last call was included in the generated file.
@@ -1,3 +1,3 @@
1
1
  module Templator
2
- VERSION=0.2
2
+ VERSION="0.2.1"
3
3
  end
@@ -0,0 +1,3 @@
1
+ first line
2
+ second line
3
+ third line
@@ -0,0 +1,4 @@
1
+ export :parameter1 => "value1"
2
+ group "group1" do
3
+ export :parameter2 => "value2"
4
+ end
@@ -0,0 +1 @@
1
+ parameter 2
@@ -0,0 +1,15 @@
1
+
2
+ def parameter_dir_path
3
+ File.join(File.dirname(__FILE__), 'data', 'parameter_dir')
4
+ end
5
+
6
+ def parameter_file_content(*paths)
7
+ content = paths.sort.inject("") { |c, path| c+= File.read(path)}
8
+ end
9
+
10
+ def in_file(filename, content)
11
+ File.open(filename, "w") do |f|
12
+ f.puts content
13
+ end
14
+ end
15
+
data/templator.gemspec ADDED
@@ -0,0 +1,35 @@
1
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
2
+ require 'templator/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "templator"
6
+ s.version = Templator::VERSION
7
+
8
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.3.6") if s.respond_to? :required_rubygems_version=
9
+ s.author = "Christophe Arguel"
10
+ s.email = "christophe.arguel@free.fr"
11
+ s.homepage = "https://github.com/carguel/templator"
12
+ s.summary = "A command line tool allowing to generate text documents from ERB template"
13
+ s.description = <<-DESCRIPTION
14
+ Templator is a command line tool allowing to generate text documents from templates written
15
+ in the ERB template language.
16
+
17
+ It also provides a Domain Specific Language, the Parameter DSL, to define a set of parameters
18
+ that can be referenced from template files in order to generate the target document
19
+ with the expected values.
20
+ DESCRIPTION
21
+
22
+ s.platform = Gem::Platform::RUBY
23
+ s.files = `git ls-files`.split("\n") - %w[.gitignore .travis.yml]
24
+ s.require_paths = ["lib"]
25
+ s.bindir = 'bin'
26
+ s.executables << 'templator'
27
+ s.extra_rdoc_files = ["CHANGES", "LICENSE", "README.md", "TODO"]
28
+ s.test_files = s.files.select { |p| p =~ /^spec\/.*_spec.rb/ }
29
+
30
+ s.add_development_dependency(%q<bundler>, ["~> 1.2.1"])
31
+ s.add_development_dependency(%q<rake>, [">= 0.9"])
32
+ s.add_development_dependency(%q<rspec>, ["~> 2.12.0"])
33
+ s.add_development_dependency(%q<yard>, ["~> 0.8.3"])
34
+ s.add_runtime_dependency(%q<thor>, ["~>0.16.0"])
35
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: templator
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: '1.0'
21
+ version: 1.2.1
22
22
  type: :development
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: '1.0'
29
+ version: 1.2.1
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: rake
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -50,7 +50,7 @@ dependencies:
50
50
  requirements:
51
51
  - - ~>
52
52
  - !ruby/object:Gem::Version
53
- version: '2.7'
53
+ version: 2.12.0
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
@@ -58,7 +58,7 @@ dependencies:
58
58
  requirements:
59
59
  - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: '2.7'
61
+ version: 2.12.0
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: yard
64
64
  requirement: !ruby/object:Gem::Requirement
@@ -66,7 +66,7 @@ dependencies:
66
66
  requirements:
67
67
  - - ~>
68
68
  - !ruby/object:Gem::Version
69
- version: 0.7.3
69
+ version: 0.8.3
70
70
  type: :development
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
@@ -74,7 +74,7 @@ dependencies:
74
74
  requirements:
75
75
  - - ~>
76
76
  - !ruby/object:Gem::Version
77
- version: 0.7.3
77
+ version: 0.8.3
78
78
  - !ruby/object:Gem::Dependency
79
79
  name: thor
80
80
  requirement: !ruby/object:Gem::Requirement
@@ -82,7 +82,7 @@ dependencies:
82
82
  requirements:
83
83
  - - ~>
84
84
  - !ruby/object:Gem::Version
85
- version: 0.14.6
85
+ version: 0.16.0
86
86
  type: :runtime
87
87
  prerelease: false
88
88
  version_requirements: !ruby/object:Gem::Requirement
@@ -90,111 +90,12 @@ dependencies:
90
90
  requirements:
91
91
  - - ~>
92
92
  - !ruby/object:Gem::Version
93
- version: 0.14.6
94
- description: ! "Templator\n=========\n\nDescription\n-----------\nTemplator is a command
95
- line tool allowing to generate text documents from templates written \nin the [ERB](http://www.ruby-doc.org/stdlib-1.9.3/libdoc/erb/rdoc/ERB.html)
96
- template language.\n\nIt also provides a Domain Specific Language, the _Parameter
97
- DSL_, to define a set of parameters\nthat can be referenced from template files
98
- in order to generate the target document\nwith expected values.\n\nTemplator is
99
- developped in Ruby. It requires Ruby 1.8.7 and higher, or any version of the 1.9
100
- branch.\n\nInstallation\n------------\n\nTo quickly install Templator, use the following
101
- command:\n\n gem install templator\n\nUsage\n-----\n\nThe following command allows
102
- to display the online help:\n\n $ templator help\n\nTwo tasks are available from
103
- the command line:\n\n * __gen__ \n\nThis task is responsible for the transformation
104
- of a given template to a target document, \ntaking into account any provided parameter
105
- files.\n\nHere is the most simple command line invokation.\n \n $ templator
106
- gen path/to/template path/to/target\n\nFiles that define parameters can be passed
107
- to Templator with the __-p__ switch:\n\n $ templator gen path/to/template path/to/target
108
- -p path/to/paramaters1 path/to/parameters2\n\nWhen parameter files are passed, Templator
109
- firstly parses these files with respect to the Parameter DSL (see below).\nFiles
110
- are parsed in the same order that they are provided by the __-p__ switch. \nAll
111
- parameters exported from these files are then visible by the template.\n\nThe __-c__
112
- switch allows to define a default context from which Templator will try to\nresolve
113
- parameter names that are not fully qualified in the template. More details are provided\nat
114
- the end of this document.\n\n\n * __get_param__\n\nThis task allows to get the value
115
- of a parameter from the provided parameter files.\n\n $ templator get_param 'my_parameter'
116
- -p path/to/parameters \n\nParameter DSL\n-------------\n\nThe set of parameters
117
- is expressed in a Ruby DSL that provides following methods:\n\n * __export__\n\nThis
118
- method allows to define new parameters and make them visible from a template during\nthe
119
- generation process. Following example shows how to define the parameter 'my_parameter'
120
- with\nthe value 'my_value'\n\n export \"my_parameter\" => \"my_value\"\n\nIt
121
- is also possible to define several parameters in a single export line:\n\n export
122
- \"my_parameter\" => \"my_value\", \"my_other_parameter\" => \"my_other_value\"\n\n\nIt
123
- is worth noting that parameter names can be a Ruby Symbol:\n\n export :my_parameter
124
- => \"my_value\"\n\nMore over, the parameter value can be any Ruby valid expression,
125
- for example:\n\n export :integer => 3\n export :now => Time.now\n export
126
- :upper_parameter => \"my_value\".upcase\n\nLast but not least, you can use the value
127
- of previously defined parameters to build a \nmore complex parameter:\n\n export
128
- :parameter1 => 1\n export :parameter2 => 2\n export :sum => parameter1 + parameter2\n\nEach
129
- time the Parameter DSL parser encounters an exported parameter, it defines \na method
130
- with the same name. In the previous example, the value of :parameter1\nand :parameter2
131
- is gotten by invoking the corresponding methods, parameter1 et parameter2. \n\n
132
- * __group__\n\nThe group method allows to define a subset of parameters.\n\n group
133
- :my_group do\n export :my_parameter => \"my_value\"\n end\n\nNested group
134
- is also possible:\n\n group :top do\n group :inner do\n ...\n
135
- \ end\n end\n\nValue of parameters defined in other groups must be retrieved
136
- with \nthe fully qualified name of the parameter in dot notation.\n\n group :foo_group
137
- do\n export :foo => \"foo\"\n end\n\n group :bar_group do\n export
138
- :bar => \"bar\"\n end\n\n group :foobar_group do\n export :foobar =>
139
- foo_group.foo + bar_group.bar\n end\n\nA group can de defined multiple times.
140
- The resulting group is a merge of all\ndefinitions taking into account the order
141
- of the parsing:\n\n #file1\n group :my_group do\n export :parameter1
142
- => 1\n export :parameter2 => 2\n end\n\n #file2\n group :my_group
143
- do\n export :parameter1 => 0.99999\n export :parameter3 => 3\n end\n\nAssuming
144
- that file1 and file2 are parsed in this order, the resulting group \nis semantically
145
- equivalent to this one:\n\n group :my_group do\n export :parameter1 =>
146
- 0.99999\n export :parameter2 => 2\n export :parameter3 => 3\n end\n\n
147
- * __include_group__\n\nThe include_group method is an interesting way to share some
148
- common parameters between different groups.\nIt allows to mix the parameters of
149
- a group in another one.\nIt is conceptually equivalent to the well known Ruby include
150
- method.\n\nConsider the following example:\n\n group :mixin do\n export
151
- :mixme => \"some value\"\n end\n\n group :my_group do\n include_group
152
- :mixin\n export :another_parameter => \"another_value\"\n end\n\nThus,
153
- the resulting group is equivalent to :\n\n group :my_group do\n export
154
- :mixme => \"some value\"\n export :another_parameter => \"another_value\"\n
155
- \ end\n\nTemplate Actions\n----------------\n\nAs said before, the template language
156
- used by Templator is ERB.\n\nIn addition to the features provided by ERB, the following
157
- extra methods can be invoked from a template:\n\n * __param__\n\nThis method allows
158
- to retrieve the value of parameters passed to Templator by the __-p__ swicth. \n\nHere
159
- is a concrete example:\n\nFile _parameters.txt_:\n\n group :my_group do\n export
160
- :my_parameter => \"my_value\"\n end\n ...\n\nFile _template.txt_:\n\n The
161
- value of the parameter \"my_parameter\" defined in the group \"my_group\" is <%=
162
- param \"my_group.my_parameter\" %>\n\nCommand line invokation from the shell:\n\n
163
- \ $ templator gen template.txt output -p parameters.txt\n\nThe resulting _output_
164
- file should have the following content:\n\n The value of the parameter \"my_parameter\"
165
- defined in the group \"my_group\" is my_value\n\n * __param_exists?__\n\nThis method
166
- tests if a parameter is defined. \nConsider the following template example:\n\n
167
- \ <% if param_exists? \"my_group.my_parameter\" %>\n The parameter \"my_parameter\"
168
- is well defined in group \"my_group\".\n <% else %>\n There is no parameter
169
- \"my_parameter\" defined in group \"my_group\".\n <% end %>\n\n * __include_file__\n\n\nThis
170
- method parses the content of the given file as an ERB template, \nand appends the
171
- resulting text into the output stream of the source template.\n\nThis is a convenient
172
- method to spread a template on multiple files.\n\nHere is an example that dynamically
173
- generates the name of the template to\ninclude according to the value of a parameter:\n\n
174
- \ blah blah blah\n <%= include_file \"#{param :my_parameter}.txt\" %>\n\nThe
175
- path of the template to include is interpreted relatively from the path\nof the
176
- source template. \n\nContextual resolution of parameter names\n\nContext\n-------\n\nA
177
- context is defined with the __-c__ switch. It is eventually\nused by the __param__
178
- and __param_exists?__ methods to resolve\nthe provided parameter names.\nWhenever
179
- the resolution of a parameter name fails, \nif a context is defined, it is prepended
180
- to the parameter name \nand a new resolution is tried with the resulting name. In
181
- this case,\nyou must ensure that the context matches a valid fully qualified group
182
- name.\n\nContext is a convenient way to generate different documents from the same
183
- template,\nassuming that a group of parameters is defined for each expected documents.\n\nHere
184
- is a concrete example where the objective is to generate a Debian /etc/network/interfaces
185
- \nfile for three different hosts.\n\nFile _hosts.txt_:\n\n group :common_parameters
186
- do\n export :gateway => \"192.168.121.254\"\n end\n\n group :host_a
187
- do\n export :address => \"192.168.121.1\"\n export :netmask => \"255.255.255.0\"\n
188
- \ include_group :common_parameters\n end\n\n group :host_b do\n export
189
- :address => \"192.168.121.2\"\n export :netmask => \"255.255.255.0\"\n include_group
190
- :common_parameters\n end\n\n group :host_c do\n export :address =>
191
- \"192.168.121.3\"\n export :netmask => \"255.255.255.0\"\n include_group
192
- :common_parameters\n end\n\nFile _interfaces.txt_:\n\n iface eth0 inet static\n
193
- \ address <%= param :address %>\n netmask <%= param :netmask %>\n gateway
194
- <%= param :gateway %>\n\nCommand line execution from shell:\n\n for host in host_a
195
- host_b host_c\n do\n templator gen interfaces.txt interfaces.$host -p
196
- hosts.txt -c $host\n done\n\nCopyright\n---------\n\nCopyright © 2011 Christophe
197
- Arguel. See LICENSE for details.\n"
93
+ version: 0.16.0
94
+ description: ! " Templator is a command line tool allowing to generate text documents
95
+ from templates written\n in the ERB template language.\n\n It also provides a
96
+ Domain Specific Language, the Parameter DSL, to define a set of parameters\n that
97
+ can be referenced from template files in order to generate the target document\n
98
+ \ with the expected values.\n"
198
99
  email: christophe.arguel@free.fr
199
100
  executables:
200
101
  - templator
@@ -205,23 +106,29 @@ extra_rdoc_files:
205
106
  - README.md
206
107
  - TODO
207
108
  files:
208
- - TODO
109
+ - .rspec
209
110
  - CHANGES
111
+ - Gemfile
112
+ - Gemfile.lock
210
113
  - LICENSE
211
114
  - README.md
212
- - Gemfile.lock
213
115
  - Rakefile
214
- - Gemfile
215
- - lib/templator/version.rb
216
- - lib/templator/parameter_file_selector.rb
116
+ - TODO
117
+ - bin/templator
217
118
  - lib/templator/actions.rb
218
- - lib/templator/parameters.rb
219
119
  - lib/templator/parameter_dsl.rb
220
- - spec/templator/parameter_file_selector_spec.rb
120
+ - lib/templator/parameter_file_selector.rb
121
+ - lib/templator/parameters.rb
122
+ - lib/templator/version.rb
123
+ - spec/data/file_to_include
124
+ - spec/data/parameter_dir/parameter1
125
+ - spec/data/parameter_dir/parameter2
126
+ - spec/spec_helper.rb
221
127
  - spec/templator/actions_spec.rb
222
128
  - spec/templator/parameter_dsl_spec.rb
129
+ - spec/templator/parameter_file_selector_spec.rb
223
130
  - spec/templator/parameters_spec.rb
224
- - bin/templator
131
+ - templator.gemspec
225
132
  homepage: https://github.com/carguel/templator
226
133
  licenses: []
227
134
  post_install_message:
@@ -236,7 +143,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
236
143
  version: '0'
237
144
  segments:
238
145
  - 0
239
- hash: 3420970963505475500
146
+ hash: 4468909134283378695
240
147
  required_rubygems_version: !ruby/object:Gem::Requirement
241
148
  none: false
242
149
  requirements:
@@ -250,7 +157,7 @@ signing_key:
250
157
  specification_version: 3
251
158
  summary: A command line tool allowing to generate text documents from ERB template
252
159
  test_files:
253
- - spec/templator/parameter_file_selector_spec.rb
254
160
  - spec/templator/actions_spec.rb
255
161
  - spec/templator/parameter_dsl_spec.rb
162
+ - spec/templator/parameter_file_selector_spec.rb
256
163
  - spec/templator/parameters_spec.rb