templator 0.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.
@@ -0,0 +1,27 @@
1
+ require 'templator/parameters'
2
+ require 'spec_helper'
3
+
4
+ module Templator
5
+
6
+ describe Parameters do
7
+
8
+
9
+ describe "#load_files" do
10
+
11
+
12
+ context "parameter files that contain only simple parameter definitions" do
13
+
14
+ it "should load the given file and return a Parameters instance" do
15
+ path = File.join(parameter_dir_path, 'parameter1')
16
+
17
+ parameters = Parameters.load_files(path)
18
+
19
+ parameters.should be_kind_of Parameters
20
+
21
+ parameters.get(:parameter1).should == 'value1'
22
+ parameters.get("group1.parameter2").should == 'value2'
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,256 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: templator
3
+ version: !ruby/object:Gem::Version
4
+ hash: 9
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ version: "0.1"
10
+ platform: ruby
11
+ authors:
12
+ - Christophe Arguel
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-12-19 00:00:00 Z
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
20
+ name: bundler
21
+ prerelease: false
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ hash: 15
28
+ segments:
29
+ - 1
30
+ - 0
31
+ version: "1.0"
32
+ type: :development
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: rake
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 25
43
+ segments:
44
+ - 0
45
+ - 9
46
+ version: "0.9"
47
+ type: :development
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: rspec
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ hash: 13
58
+ segments:
59
+ - 2
60
+ - 7
61
+ version: "2.7"
62
+ type: :development
63
+ version_requirements: *id003
64
+ - !ruby/object:Gem::Dependency
65
+ name: yard
66
+ prerelease: false
67
+ requirement: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ~>
71
+ - !ruby/object:Gem::Version
72
+ hash: 5
73
+ segments:
74
+ - 0
75
+ - 7
76
+ - 3
77
+ version: 0.7.3
78
+ type: :development
79
+ version_requirements: *id004
80
+ - !ruby/object:Gem::Dependency
81
+ name: thor
82
+ prerelease: false
83
+ requirement: &id005 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ~>
87
+ - !ruby/object:Gem::Version
88
+ hash: 43
89
+ segments:
90
+ - 0
91
+ - 14
92
+ - 6
93
+ version: 0.14.6
94
+ type: :runtime
95
+ version_requirements: *id005
96
+ description: "Templator\n\
97
+ =========\n\n\
98
+ Description\n\
99
+ -----------\n\
100
+ Templator is a command line tool allowing to generate text documents from templates written \n\
101
+ in the [ERB](http://www.ruby-doc.org/stdlib-1.9.3/libdoc/erb/rdoc/ERB.html) template language.\n\n\
102
+ It also provides a Domain Specific Language, the _Parameter DSL_, to define a set of parameters\n\
103
+ that can be referenced from template files in order to generate the target document\n\
104
+ with expected values.\n\n\
105
+ Templator is developped in Ruby. It requires Ruby 1.8.7 and higher, or any version of the 1.9 branch.\n\n\
106
+ Installation\n\
107
+ ------------\n\n\
108
+ To quickly install Templator, use the following command:\n\n gem install templator\n\n\
109
+ Usage\n\
110
+ -----\n\n\
111
+ The following command allows to display the online help:\n\n $ templator help\n\n\
112
+ Two tasks are available from the command line:\n\n * __gen__ \n\n\
113
+ This task is responsible for the transformation of a given template to a target document, \n\
114
+ taking into account any provided parameter files.\n\n\
115
+ Here is the most simple command line invokation.\n \n $ templator gen path/to/template path/to/target\n\n\
116
+ Files that define parameters can be passed to Templator with the __-p__ switch:\n\n $ templator gen path/to/template path/to/target -p path/to/paramaters1 path/to/parameters2\n\n\
117
+ When parameter files are passed, Templator firstly parses these files with respect to the Parameter DSL (see below).\n\
118
+ Files are parsed in the same order that they are provided by the __-p__ switch. \n\
119
+ All parameters exported from these files are then visible by the template.\n\n\
120
+ The __-c__ switch allows to define a default context from which Templator will try to\n\
121
+ resolve parameter names that are not fully qualified in the template. More details are provided\n\
122
+ at the end of this document.\n\n\n * __get_param__\n\n\
123
+ This task allows to get the value of a parameter from the provided parameter files.\n\n $ templator get_param 'my_parameter' -p path/to/parameters \n\n\
124
+ Parameter DSL\n\
125
+ -------------\n\n\
126
+ The set of parameters is expressed in a Ruby DSL that provides following methods:\n\n * __export__\n\n\
127
+ This method allows to define new parameters and make them visible from a template during\n\
128
+ the generation process. Following example shows how to define the parameter 'my_parameter' with\n\
129
+ the value 'my_value'\n\n export \"my_parameter\" => \"my_value\"\n\n\
130
+ It is also possible to define several parameters in a single export line:\n\n export \"my_parameter\" => \"my_value\", \"my_other_parameter\" => \"my_other_value\"\n\n\n\
131
+ It is worth noting that parameter names can be a Ruby Symbol:\n\n export :my_parameter => \"my_value\"\n\n\
132
+ More over, the parameter value can be any Ruby valid expression, for example:\n\n export :integer => 3\n export :now => Time.now\n export :upper_parameter => \"my_value\".upcase\n\n\
133
+ Last but not least, you can use the value of previously defined parameters to build a \n\
134
+ more complex parameter:\n\n export :parameter1 => 1\n export :parameter2 => 2\n export :sum => parameter1 + parameter2\n\n\
135
+ Each time the Parameter DSL parser encounters an exported parameter, it defines \n\
136
+ a method with the same name. In the previous example, the value of :parameter1\n\
137
+ and :parameter2 is gotten by invoking the corresponding methods, parameter1 et parameter2. \n\n * __group__\n\n\
138
+ The group method allows to define a subset of parameters.\n\n group :my_group {\n export :my_parameter => \"my_value\"\n }\n\n\
139
+ Nested group is also possible:\n\n group :top {\n group :inner {\n ...\n }\n }\n\n\
140
+ Value of parameters defined in other groups must be retrieved with \n\
141
+ the fully qualified name of the parameter in dot notation.\n\n group :foo_group {\n export :foo => \"foo\"\n }\n\n group :bar_group {\n export :bar => \"bar\"\n }\n\n group :foobar_group {\n export :foobar => foo_group.foo + bar_group.bar\n }\n\n\
142
+ A group can de defined multiple times. The resulting group is a merge of all\n\
143
+ definitions taking into account the order of the parsing:\n\n #file1\n group :my_group {\n export :parameter1 => 1\n export :parameter2 => 2\n }\n\n #file2\n group :my_group {\n export :parameter1 => 0.99999\n export :parameter3 => 3\n }\n\n\
144
+ Assuming that file1 and file2 are parsed in this order, the resulting group \n\
145
+ is semantically equivalent to this one:\n\n group :my_group {\n export :parameter1 => 0.99999\n export :parameter2 => 2\n export :parameter3 => 3\n }\n\n * __include_group__\n\n\
146
+ The include_group method is an interesting way to share some common parameters between different groups.\n\
147
+ It allows to mix the parameters of a group in another one.\n\
148
+ It is conceptually equivalent to the well known Ruby include method.\n\n\
149
+ Consider the following example:\n\n group :mixin {\n export :mixme => \"some value\"\n }\n\n group :my_group {\n include_group :mixin\n export :another_parameter => \"another_value\"\n }\n\n\
150
+ Thus, the resulting group is equivalent to :\n\n group :my_group {\n export :mixme => \"some value\"\n export :another_parameter => \"another_value\"\n }\n\n\
151
+ Template Actions\n\
152
+ ----------------\n\n\
153
+ As said before, the template language used by Templator is ERB.\n\n\
154
+ In addition to the features provided by ERB, the following extra methods can be invoked from a template:\n\n * __param__\n\n\
155
+ This method allows to retrieve the value of a parameter. \n\n\
156
+ Here is a concrete example:\n\n\
157
+ File _parameters.txt_:\n\n group :my_group {\n export my_parameter => \"my_value\"\n }\n ...\n\n\
158
+ File _template.txt_:\n\n The value of the parameter \"my_parameter\" defined in the group \"my_group\" is <%= param \"my_group.my_parameter\" %>\n\n\
159
+ Command line invokation from the shell:\n\n $ templator gen template.txt output -p parameters.txt\n\n\
160
+ The resulting _output_ file should have the following content:\n\n The value of the parameter \"my_parameter\" defined in the group \"my_group\" is my_value\n\n * __param_exists?__\n\n\
161
+ This method tests if a parameter is defined. \n\
162
+ Consider the following template example:\n\n <% if param_exists? \"my_group.my_parameter\" %>\n The parameter \"my_parameter\" is well defined in group \"my_group\".\n <% else %>\n There is no parameter \"my_parameter\" defined in group \"my_group\".\n <% end %>\n\n * __include_file__\n\n\n\
163
+ This method parses the content of the given file as an ERB template, \n\
164
+ and appends the resulting text into the output stream of the source template.\n\n\
165
+ This is a convenient method to spread a template on multiple files.\n\n\
166
+ Here is an example that dynamically generates the name of the template to\n\
167
+ include according to the value of a parameter:\n\n blah blah blah\n <%= include_file \"#{param :my_parameter}.txt\"\n\n\
168
+ The path of the template to include is interpreted relatively from the path\n\
169
+ of the source template. \n\n\
170
+ Contextual resolution of parameter names\n\n\
171
+ Context\n\
172
+ -------\n\n\
173
+ A context is defined with the __-c__ switch. It is eventually\n\
174
+ used by the __param__ and __param_exists?__ methods to resolve\n\
175
+ the provided parameter names.\n\
176
+ Whenever the resolution of a parameter name fails, \n\
177
+ if a context is defined, it is prepended to the parameter name \n\
178
+ and a new resolution is tried with the resulting name. In this case,\n\
179
+ you must ensure that the context matches a valid fully qualified group name.\n\n\
180
+ Context is a convenient way to generate different documents from the same template,\n\
181
+ assuming that a group of parameters is defined for each expected documents.\n\n\
182
+ Here is a concrete example where the objective is to generate a Debian /etc/network/interfaces \n\
183
+ file for three different hosts.\n\n\
184
+ File _hosts.txt_:\n\n group :host_a {\n export :address => \"192.168.121.1\"\n export :netmask => \"255.255.255.0\"\n export :gateway => \"192.168.121.254\"\n }\n\n group :host_b {\n export :address => \"192.168.122.1\"\n export :netmask => \"255.255.255.0\"\n export :gateway => \"192.168.122.254\"\n }\n\n group :host_c {\n export :address => \"192.168.123.1\"\n export :netmask => \"255.255.255.0\"\n export :gateway => \"192.168.123.254\"\n }\n\n\
185
+ File _interfaces.txt_:\n\n iface eth0 inet static\n address <%= param :address %>\n netmask <%= param :netmask %>\n gateway <%= param :gateway %>\n\n\
186
+ Command line execution from shell:\n\n for host in host_a host_b host_c\n do\n templator gen interfaces.txt interfaces.$host -p hosts.txt -c $host\n done\n\n\
187
+ Copyright\n\
188
+ ---------\n\n\
189
+ Copyright \xC2\xA9 2011 Christophe Arguel. See LICENSE for details.\n"
190
+ email: christophe.arguel@free.fr
191
+ executables:
192
+ - templator
193
+ extensions: []
194
+
195
+ extra_rdoc_files:
196
+ - CHANGES
197
+ - LICENSE
198
+ - README.md
199
+ - TODO
200
+ files:
201
+ - Gemfile.lock
202
+ - CHANGES
203
+ - Gemfile
204
+ - Rakefile
205
+ - LICENSE
206
+ - TODO
207
+ - README.md
208
+ - lib/templator/parameters.rb
209
+ - lib/templator/parameter_code_loader.rb
210
+ - lib/templator/actions.rb
211
+ - lib/templator/parameter_dsl.rb
212
+ - spec/templator/parameter_dsl_spec.rb
213
+ - spec/templator/parameter_code_loader_spec.rb
214
+ - spec/templator/actions_spec.rb
215
+ - spec/templator/parameters_spec.rb
216
+ - bin/templator
217
+ homepage: https://github.com/carguel/templator
218
+ licenses: []
219
+
220
+ post_install_message:
221
+ rdoc_options: []
222
+
223
+ require_paths:
224
+ - lib
225
+ required_ruby_version: !ruby/object:Gem::Requirement
226
+ none: false
227
+ requirements:
228
+ - - ">="
229
+ - !ruby/object:Gem::Version
230
+ hash: 3
231
+ segments:
232
+ - 0
233
+ version: "0"
234
+ required_rubygems_version: !ruby/object:Gem::Requirement
235
+ none: false
236
+ requirements:
237
+ - - ">="
238
+ - !ruby/object:Gem::Version
239
+ hash: 23
240
+ segments:
241
+ - 1
242
+ - 3
243
+ - 6
244
+ version: 1.3.6
245
+ requirements: []
246
+
247
+ rubyforge_project:
248
+ rubygems_version: 1.8.10
249
+ signing_key:
250
+ specification_version: 3
251
+ summary: A command line tool allowing to generate text documents from ERB template
252
+ test_files:
253
+ - spec/templator/parameter_dsl_spec.rb
254
+ - spec/templator/parameter_code_loader_spec.rb
255
+ - spec/templator/actions_spec.rb
256
+ - spec/templator/parameters_spec.rb