ccios 4.1.0 → 5.1.0

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.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/CHANGELOG.md +35 -0
  4. data/Gemfile.lock +34 -15
  5. data/MAINTAINER.md +8 -0
  6. data/README.md +188 -56
  7. data/ccios.gemspec +2 -2
  8. data/lib/ccios/argument_template_parameter.rb +33 -0
  9. data/lib/ccios/code_templater.rb +24 -8
  10. data/lib/ccios/config.rb +41 -91
  11. data/lib/ccios/file_creator.rb +37 -24
  12. data/lib/ccios/file_template_definition.rb +95 -0
  13. data/lib/ccios/flag_template_parameter.rb +17 -0
  14. data/lib/ccios/group_template_definition.rb +54 -0
  15. data/lib/ccios/pbxproj_parser.rb +4 -55
  16. data/lib/ccios/snippet_template_definition.rb +27 -0
  17. data/lib/ccios/template_definition.rb +116 -0
  18. data/lib/ccios/templates/{coordinator.mustache → Coordinator/coordinator.mustache} +5 -2
  19. data/lib/ccios/templates/Coordinator/template.yml +19 -0
  20. data/lib/ccios/templates/{interactor_implementation.mustache → Interactor/interactor_implementation.mustache} +2 -2
  21. data/lib/ccios/templates/Interactor/template.yml +24 -0
  22. data/{templates_library/async → lib/ccios/templates/Presenter}/dependency_provider.mustache +6 -2
  23. data/lib/ccios/templates/{presenter_implementation.mustache → Presenter/presenter_implementation.mustache} +4 -1
  24. data/lib/ccios/templates/Presenter/template.yml +55 -0
  25. data/lib/ccios/templates/{view_contract.mustache → Presenter/view_contract.mustache} +2 -1
  26. data/lib/ccios/templates/{view_controller.mustache → Presenter/view_controller.mustache} +4 -0
  27. data/{templates_library/async/repository.mustache → lib/ccios/templates/Presenter/view_model.mustache} +2 -3
  28. data/lib/ccios/templates/Presenter/view_model_mapper.mustache +16 -0
  29. data/lib/ccios/templates/Repository/template.yml +25 -0
  30. data/lib/ccios/templates_loader.rb +31 -0
  31. data/lib/ccios.rb +65 -43
  32. data/templates_library/async/Coordinator/template.yml +20 -0
  33. data/{lib/ccios/templates → templates_library/async/Presenter}/presenter.mustache +2 -0
  34. data/templates_library/async/Presenter/template.yml +49 -0
  35. metadata +40 -34
  36. data/lib/ccios/coordinator_generator.rb +0 -18
  37. data/lib/ccios/interactor_generator.rb +0 -33
  38. data/lib/ccios/presenter_generator.rb +0 -71
  39. data/lib/ccios/repository_generator.rb +0 -44
  40. data/templates_library/async/interactor.mustache +0 -13
  41. data/templates_library/async/interactor_assembly.mustache +0 -5
  42. data/templates_library/async/interactor_implementation.mustache +0 -22
  43. data/templates_library/async/repository_assembly.mustache +0 -6
  44. data/templates_library/async/repository_implementation.mustache +0 -20
  45. /data/lib/ccios/templates/{interactor.mustache → Interactor/interactor.mustache} +0 -0
  46. /data/lib/ccios/templates/{interactor_assembly.mustache → Interactor/interactor_assembly.mustache} +0 -0
  47. /data/{templates_library/async → lib/ccios/templates/Presenter}/presenter.mustache +0 -0
  48. /data/lib/ccios/templates/{presenter_assembly.mustache → Presenter/presenter_assembly.mustache} +0 -0
  49. /data/lib/ccios/templates/{repository.mustache → Repository/repository.mustache} +0 -0
  50. /data/lib/ccios/templates/{repository_assembly.mustache → Repository/repository_assembly.mustache} +0 -0
  51. /data/lib/ccios/templates/{repository_implementation.mustache → Repository/repository_implementation.mustache} +0 -0
  52. /data/templates_library/async/{coordinator.mustache → Coordinator/coordinator.mustache} +0 -0
  53. /data/{lib/ccios/templates → templates_library/async/Presenter}/dependency_provider.mustache +0 -0
  54. /data/templates_library/async/{presenter_assembly.mustache → Presenter/presenter_assembly.mustache} +0 -0
  55. /data/templates_library/async/{presenter_implementation.mustache → Presenter/presenter_implementation.mustache} +0 -0
  56. /data/templates_library/async/{view_contract.mustache → Presenter/view_contract.mustache} +0 -0
  57. /data/templates_library/async/{view_controller.mustache → Presenter/view_controller.mustache} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6854ecea6f4dd2478a49675e65dac4f292ddd1e2cae94d526b5903ea507efaf0
4
- data.tar.gz: eeaa057288fe8c0d0c6d02e0a94453e967e8c1d904a068d5c185f0d49224c252
3
+ metadata.gz: dc6f5c81e7b9f2abf46e0f373717896e51762b3565f616205bd6a666d888fc65
4
+ data.tar.gz: 0f8661b91001f98ebe5e6435e8572bf1d671d871a22c120d85d29783d294cb36
5
5
  SHA512:
6
- metadata.gz: 34837239dd73f4e62f167a078a48fb3083b49296c9970032f86ba768128af08b991c5f46adc72b032fbc909d4937e82487fcdea65d0cb6b9eaaa9049c2261580
7
- data.tar.gz: a480d7df1ee5dc7a9d595ec6fcb4c68ad968ca2b62e9c57065ff7a3e3ad5528f2ffd0e3d76dfe01f6f6ba2cad71fab65ffafc5148b2fbbf202e978b0a65c1f61
6
+ metadata.gz: 7113bdee060f5d5808bb43951a0e0485b45cc058d857ccd0c64e36702a6418ed893e62a6a1dc9695ffa2c770c177931b9705a533cf2f2f8727bbabbbe0c25244
7
+ data.tar.gz: b0d3109396e17b9d8d3b4979901b3c2b6183de19da7df9f60ad784d6e0c7b26b6da9a730f6f0c607f4fd344634d8ca9f1ae505207f86131e677261fee451a4a1
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.2.2
1
+ 3.3.0
data/CHANGELOG.md CHANGED
@@ -4,6 +4,41 @@ All notable changes to this project will be documented in this file.
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [5.1.0]
8
+
9
+ ### Changed
10
+
11
+ - Target variable is now optional, an empty string or an unset value will use the first target of the project. This change allows templates to not overrides global target settings in `.ccios.yml`
12
+ - When multiple targets are provided for a file, `{{project_name}}` will now be replaced by the name of the project instead of the name of the first target
13
+ - `@MainActor` has been added to relevent files in Coordinator and Presenter templates to improve Swift 6 support
14
+ - dependency provider snippets has been updated to handle Swift 6 issue (see [this issue](https://github.com/Swinject/Swinject/issues/571) for why this is required)
15
+
16
+ ## [5.0.0]
17
+
18
+ This release is an entire rewrite of the templating system, allowing customization of template and settings.
19
+
20
+ ### Added
21
+
22
+ - New templating system that allows definition of custom templates per project
23
+ - A template can now declare multiple CLI arguments and flags
24
+ - Generated files can be added to multiple targets
25
+ - The base_path group and target can be configured independently for each generated file if needed.
26
+ - Add validation that each variable used in a mustache file is provided by the template. The default provided variables are: `filename`, `lowercase_filename`, `project_name`, `full_username` and `date`
27
+ - List of known templates is available using `ccios --help`
28
+
29
+ ### Changed
30
+
31
+ - Default templates has been migrated to the new format
32
+ - Configuration file (`.ccios`) format has been changed
33
+ - Command line invocation has changed:
34
+ - `ccios -p Example [-d]` is now `ccios presenter Example [-d]`
35
+ - `ccios -c Example [-d]` is now `ccios coordinator Example [-d]`
36
+ - `ccios -i Example [-d]` is now `ccios interactor Example`
37
+ - `ccios -r Example [-d]` is now `ccios repository Example`
38
+ - Some default provided mustache variables have been renamed:
39
+ - `name` is now `filename`
40
+ - `lowercased_name` is now `lowercased_filename`
41
+
7
42
  ## [4.1.0]
8
43
 
9
44
  ### Added
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ccios (4.1.0)
4
+ ccios (5.1.0)
5
5
  activesupport (> 4)
6
6
  mustache (~> 1.0)
7
7
  xcodeproj (~> 1.4)
@@ -9,33 +9,52 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- CFPropertyList (3.0.6)
12
+ CFPropertyList (3.0.7)
13
+ base64
14
+ nkf
13
15
  rexml
14
- activesupport (7.0.8)
15
- concurrent-ruby (~> 1.0, >= 1.0.2)
16
+ activesupport (8.0.1)
17
+ base64
18
+ benchmark (>= 0.3)
19
+ bigdecimal
20
+ concurrent-ruby (~> 1.0, >= 1.3.1)
21
+ connection_pool (>= 2.2.5)
22
+ drb
16
23
  i18n (>= 1.6, < 2)
24
+ logger (>= 1.4.2)
17
25
  minitest (>= 5.1)
18
- tzinfo (~> 2.0)
26
+ securerandom (>= 0.3)
27
+ tzinfo (~> 2.0, >= 2.0.5)
28
+ uri (>= 0.13.1)
19
29
  atomos (0.1.3)
30
+ base64 (0.2.0)
31
+ benchmark (0.4.0)
32
+ bigdecimal (3.1.9)
20
33
  claide (1.1.0)
21
34
  colored2 (3.1.2)
22
- concurrent-ruby (1.2.2)
23
- i18n (1.14.1)
35
+ concurrent-ruby (1.3.5)
36
+ connection_pool (2.5.0)
37
+ drb (2.2.1)
38
+ i18n (1.14.7)
24
39
  concurrent-ruby (~> 1.0)
25
- minitest (5.20.0)
40
+ logger (1.6.6)
41
+ minitest (5.25.4)
26
42
  mustache (1.1.1)
27
- nanaimo (0.3.0)
28
- rake (12.3.3)
29
- rexml (3.2.6)
43
+ nanaimo (0.4.0)
44
+ nkf (0.2.0)
45
+ rake (13.2.1)
46
+ rexml (3.4.1)
47
+ securerandom (0.4.1)
30
48
  tzinfo (2.0.6)
31
49
  concurrent-ruby (~> 1.0)
32
- xcodeproj (1.23.0)
50
+ uri (1.0.3)
51
+ xcodeproj (1.27.0)
33
52
  CFPropertyList (>= 2.3.3, < 4.0)
34
53
  atomos (~> 0.1.3)
35
54
  claide (>= 1.0.2, < 2.0)
36
55
  colored2 (~> 3.1)
37
- nanaimo (~> 0.3.0)
38
- rexml (~> 3.2.4)
56
+ nanaimo (~> 0.4.0)
57
+ rexml (>= 3.3.6, < 4.0)
39
58
 
40
59
  PLATFORMS
41
60
  ruby
@@ -43,7 +62,7 @@ PLATFORMS
43
62
  DEPENDENCIES
44
63
  ccios!
45
64
  minitest (~> 5.11)
46
- rake (~> 12.3)
65
+ rake (~> 13.2)
47
66
 
48
67
  BUNDLED WITH
49
68
  2.4.10
data/MAINTAINER.md ADDED
@@ -0,0 +1,8 @@
1
+
2
+ ## How to release a new version
3
+
4
+ - Create the release branch `release/vA.B.C`
5
+ - Complete the changelog and add the new vertion title
6
+ - Update the version in ccios.gemspec & run `bundle install`
7
+ - Create a Pull Request
8
+ - Once merged, create a tag `A.B.C` on the merged commit
data/README.md CHANGED
@@ -21,14 +21,24 @@ To run the tests run:
21
21
  Go to your `.xcodeproj` folder `cd /paht/to/my/xcodeproj`.
22
22
  Then generate files with prefix `Example`:
23
23
 
24
+ ```bash
25
+ ccios <template_name> [template_arguments...] [template_options]
24
26
  ```
25
- ccios [-p|-i|-r|-c] Example [-d]
27
+
28
+ The list of known templates is visible using the following command:
29
+ ```bash
30
+ ccios --help
26
31
  ```
27
32
 
28
- Generated templates can be found [here](https://github.com/felginep/ccios/tree/master/lib/ccios/templates)
33
+ Generated templates can be found [here](https://github.com/fabernovel/ccios/tree/master/lib/ccios/templates)
34
+
35
+ ## Default templates
36
+
37
+ ### `presenter`
29
38
 
30
- ### `-p`
31
- `-p` stands for `presenter`
39
+ ```bash
40
+ ccios presenter Example [-d]
41
+ ```
32
42
 
33
43
  This generates 4 files: `ExampleViewController`, `ExampleViewContract`, `ExamplePresenter`, `ExamplePresenterImplementation`. If the `-d` option is supplied the protocol `ExamplePresenterDelegate` will be generated.
34
44
 
@@ -51,8 +61,11 @@ The following structure is created for you in the Xcode project:
51
61
  | | +-- Model/
52
62
  ```
53
63
 
54
- ### `-i`
55
- `-i` stands for `interactor`
64
+ ### `interactor`
65
+
66
+ ```bash
67
+ ccios interactor Example
68
+ ```
56
69
 
57
70
  This generates 2 files: `ExampleInteractor` and `ExampleInteractorImplementation`.
58
71
 
@@ -69,8 +82,11 @@ The following structure is created for you in the Xcode project:
69
82
  | | | +-- ExampleInteractorImplementation
70
83
  ```
71
84
 
72
- ### `-r`
73
- `-r` stands for `repository`
85
+ ### `repository`
86
+
87
+ ```bash
88
+ ccios repository Example
89
+ ```
74
90
 
75
91
  This generates 2 files: `ExampleRepository` and `ExampleRepositoryImplementation`.
76
92
 
@@ -89,8 +105,11 @@ The following structure is created for you in the Xcode project:
89
105
  | | +-- ExampleRepositoryImplementation
90
106
  ```
91
107
 
92
- ### `-c`
93
- `-c` stands for `coordinator`
108
+ ### `coordinator`
109
+
110
+ ```bash
111
+ ccios coordinator Example [-d]
112
+ ```
94
113
 
95
114
  This generates one file: `ExampleCoordinator`. If the `-d` option is supplied the protocol `ExampleCoordinatorDelegate` will be generated.
96
115
 
@@ -104,64 +123,177 @@ The following structure is created for you in the Xcode project:
104
123
 
105
124
  ## Configuration
106
125
 
107
-
108
- Each project is different. You can configure the groups to use in the xcodeproj for the new files.
126
+ Each project is different. You can configure the available templates that can be used
127
+ You can configure the groups to use in the xcodeproj for the new files.
109
128
 
110
129
  Create a file `.ccios.yml` at the root of your project.
111
130
 
112
- By default, if no file is present, the following configuration will be used:
113
- ```
114
- app:
115
- project: MyProject.xcodeproj
131
+ An empty config file is valid as all properties are optional.
132
+
133
+ ```yml
134
+ # Path to an additional collection of templates. [Optional]
135
+ # Templates present in this folder will be available. If the collection use the same name as a default template, it will override it.
136
+ templates_collection: ccios/templates
137
+
138
+ # Global overrides of variables [Optional]
139
+ variables:
140
+ project: Project.xcodeproj
141
+ target: SomeDefaultTarget
142
+
143
+ # Per template variables override
144
+ templates_config:
145
+ # Use the template name (in template.yml) to specify overrides on this template:
146
+ TEMPLATE_NAME:
147
+ # This overrides the default template variables
148
+ variables:
149
+ project: "Project.pbxproj"
150
+ # You can specify multiple target for generated files.
151
+ target:
152
+ - SomeTarget
153
+ - SomeOtherTarget
154
+ - ThirdTarget
155
+ # Per element variable override
156
+ elements_variables:
157
+ # This overrides the default variables for the element named "ELEMENT_NAME_1"
158
+ ELEMENT_NAME_1:
159
+ base_path: Core/Data
160
+ target: Core
161
+ ELEMENT_NAME_2:
162
+ base_path: Data
163
+ target: Data
164
+ # Another template variable override
116
165
  presenter:
117
- group: Classes/App
166
+ variables:
167
+ base_path: MyProject/App
168
+ elements_variables:
169
+ repository:
170
+ base_path: "Core/Data"
118
171
  coordinator:
119
- group: Classes/Coordinator
120
-
121
- core:
122
- project: MyProject.xcodeproj
123
- interactor:
124
- group: Classes/Core/Interactor
125
- repository:
126
- group: Classes/Core/Data
127
-
128
- data:
129
- project: MyProject.xcodeproj
130
- repository:
131
- group: Classes/Data
172
+ variables:
173
+ base_path: MyProject/Coordinator
132
174
  ```
133
175
 
134
- But you could imagine more complex project structures with multiple xcodeproj:
135
- ```
136
- app:
137
- project: MyProject/MyProject.xcodeproj
138
- target: MyProject # optional
139
- presenter:
140
- group: Classes/App
141
- coordinator:
142
- group: Classes/Coordinator
176
+ *Note*: The path of the new files will be infered from the path of the group. It works with *Group with folder* and *Group without folder* in Xcode.
143
177
 
144
- core:
145
- project: MyProjectCore/MyProjectCore.xcodeproj
146
- target: MyProjectCore # optional
147
- interactor:
148
- group: MyProjectCore/Interactors
149
- repository:
150
- group: MyProjectCore/Repository
178
+ ## Template definition
151
179
 
152
- data:
153
- project: MyProjectData/MyProjectData.xcodeproj
154
- target: MyProjectData # optional
155
- repository:
156
- group: MyProjectData/Sources/Repositories
157
- ```
180
+ Default templates can be found [here](https://github.com/fabernovel/ccios/tree/master/lib/ccios/templates), and can be used to see what is possible.
158
181
 
159
- *Note*: The path of the new files will be infered from the path of the group. It works with *Group with folder* and *Group without folder* in Xcode.
182
+ A template is a folder containing a file `template.yml` next to all templating files that will be used during generation.
183
+ Example for the default Interactor template:
184
+ ```
185
+ Interactor/
186
+ template.yml
187
+ interactor.mustache
188
+ interactor_assembly.mustache
189
+ interactor_implementation.mustache
190
+ ```
160
191
 
161
- And lastly you may want to use your own templates, by adding this parameter to the file:
192
+ ### `template.yml` format
193
+
194
+ ```yml
195
+ # name of the template to use in the CLI. [required]
196
+ name: "custom_template"
197
+ # description of the template. [optional]
198
+ description: "Custom template definition"
199
+ # List of the parameters that will be given to the file templates. [required]
200
+ # The parameters can be used in template files, and in file path.
201
+ parameters:
202
+ # Use this to represent a string argument parameter in the CLI
203
+ # By default the argument will be passed to template renderer under the name "name", to use another name, specify a `template_variable_name`
204
+ - argument: "name"
205
+ # Description used in the help command. [Optional]
206
+ description: "name argument description"
207
+ # When present, the argument will be usable in templates under the provided name. [Optional]
208
+ template_variable_name: "in_template_variable_name"
209
+ # When present, will remove the provided suffix from the argument given. Example "MySuffix" will be tranformed into "My". [Optional]
210
+ removeSuffix: "Suffix"
211
+ # When present, the lowercased argument will be usable in templates under the provided name. [Optional]
212
+ lowercased_variable_name: "name_of_the_lowercased_variable"
213
+ # Use this to represent a flag parameter in the CLI, the flag will be provided to templates as `true` when present in the executed command.
214
+ - flag: "long_name"
215
+ # The short name of this flag to use on CLI. [optional]
216
+ short_name: "n"
217
+ # Description used in the help command. [Optional]
218
+ description: "Description for the long_name flag"
219
+ # When present, the argument will be usable in templates under the provided name. [Optional]
220
+ template_variable_name: "in_template_flag_name"
221
+ # List of templates variables that is used to generate files in an xcode project. [Optional]
222
+ # Those variables can be overridden in config file, see section "Variable hierarchy" for more informations.
223
+ variables:
224
+ # The name of the xcode project. "*.xcodeproj" will use the first it finds. [required]
225
+ project: "*.xcodeproj"
226
+ # The base path used to generate an element. This variable must be defined once here, or on each elements below.
227
+ base_path: "path/to/base_group"
228
+ # The target in which files are added. Can be a string, a list of strings, or an empty string. This variable must be defined once here, or on each elements below. If this variable is not set or if an empty string is provided, it will use the first target found in the Xcode project. If present it will override the global default target. [Optional]
229
+ target: "SomeTarget"
230
+ # List of generated elements. [Required]
231
+ # Each element can be a file (using `file`), or an empty folder (using `group`)
232
+ generated_elements:
233
+ # Path from the `base_path` variable where the file will be generated
234
+ - file: "{{ name }}/{{ name }}File.swift"
235
+ # This name identifies this generated file to allow variable overrides in config file. [Required]
236
+ name: "file"
237
+ # The template specifies the name of template that will be used from `template_file_source`
238
+ template: "file"
239
+ # List of default element variable. [Optional]
240
+ variables: {}
241
+ # Path from the `base_path` variable where the directory will be generated
242
+ - group: "{{ name }}/group"
243
+ # This name identifies this generated file to allow variable overrides in config file. [Required]
244
+ name: "group"
245
+ # List of default element variable. [Optional]
246
+ variables:
247
+ - base_path: "path/override/to/base_group"
248
+ # List of code snippets that will be printed by the CLI after the generation of files. [Optional]
249
+ code_snippets:
250
+ # The name will be used in the printed line "Add this snippet to FilenameInWhichTheSnippetIsExpected" before the generated code snippet.
251
+ # This name will also be given to the snippet template under the variable `filename` and `lowercased_filename`. [Required]
252
+ - name: FilenameInWhichTheSnippetIsExpected
253
+ # The template specifies the name of template that will be used from `template_file_source`. [Required]
254
+ template: "file_snippets"
255
+ # List of templating files used for element generation or code snippets. [Required]
256
+ # The key is used as an identifier in `generated_elements` or `code_snippets`, the value is the path from the template directory.
257
+ template_file_source:
258
+ file: "file.mustache"
259
+ file_snippets: "file_snippets.mustache"
162
260
  ```
163
- templates:
164
- path: Path/To/Users/Templates
261
+
262
+ ### Variable hierarchy
263
+
264
+ In `template.yml`
265
+ ```yml
266
+ # [...]
267
+ variables:
268
+ # -> Default templates variables
269
+ generated_elements:
270
+ - name: element_name
271
+ # [...]
272
+ variables:
273
+ # -> Default Element variables
165
274
  ```
166
275
 
276
+ In `.ccios.yml`
277
+ ```yml
278
+ variables:
279
+ # -> Config Global variables
280
+ templates_config:
281
+ repository:
282
+ variables:
283
+ # -> Config Template variables
284
+ element_variables:
285
+ element_name:
286
+ # -> Config Element variables
287
+ ```
167
288
 
289
+ Templates will use variables in this order (first in this list is used):
290
+ - Config Template variables
291
+ - Default templates variables
292
+ - Config Global variables
293
+
294
+ Element will use variables in this order (first in this list is used): (For files, groups and code snippets)
295
+ - Config Element variables
296
+ - Default Element variables
297
+ - Config Template variables
298
+ - Default templates variables
299
+ - Config Global variables
data/ccios.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'ccios'
3
- s.version = '4.1.0'
3
+ s.version = '5.1.0'
4
4
  s.executables << 'ccios'
5
5
  s.date = '2016-08-03'
6
6
  s.summary = "Clean Code iOS Generator"
@@ -15,6 +15,6 @@ Gem::Specification.new do |s|
15
15
  s.add_dependency 'xcodeproj', '~> 1.4'
16
16
  s.add_dependency "mustache", "~> 1.0"
17
17
 
18
- s.add_development_dependency 'rake', '~> 12.3'
18
+ s.add_development_dependency 'rake', '~> 13.2'
19
19
  s.add_development_dependency 'minitest', '~> 5.11'
20
20
  end
@@ -0,0 +1,33 @@
1
+ class ArgumentTemplateParameter
2
+ attr_reader :name, :description, :template_variable_name
3
+
4
+ def initialize(parameter_template_definition_hash)
5
+ @name = parameter_template_definition_hash["argument"]
6
+ @description = parameter_template_definition_hash["description"] || ""
7
+ @template_variable_name = parameter_template_definition_hash["template_variable_name"] || @name
8
+ @removeSuffix = parameter_template_definition_hash["removeSuffix"] || ""
9
+ @lowercased_name = parameter_template_definition_hash["lowercased_variable_name"] || ""
10
+
11
+ raise "Missing argument name" if @name.nil? || @name.empty?
12
+ raise "Invalid argument template_variable_name for #{@name}" if @template_variable_name.nil? || template_variable_name.empty?
13
+ end
14
+
15
+ def update_context(context)
16
+ if !@removeSuffix.empty?
17
+ value = context[@template_variable_name]
18
+ context[@template_variable_name] = value.gsub(@removeSuffix, "")
19
+ end
20
+ if !@lowercased_name.empty? && !context[@lowercased_name]
21
+ context[@lowercased_name] = context[@template_variable_name].camelize(:lower)
22
+ end
23
+ context
24
+ end
25
+
26
+ def provided_context_keys
27
+ context_keys = [@template_variable_name]
28
+ if !@lowercased_name.empty?
29
+ context_keys.append(@lowercased_name)
30
+ end
31
+ context_keys
32
+ end
33
+ end
@@ -2,15 +2,31 @@ require 'mustache'
2
2
  require 'active_support/core_ext/string'
3
3
 
4
4
  class CodeTemplater
5
- def initialize(options = {}, templates_path)
6
- @options = options
7
- @templates_path = templates_path
5
+
6
+ def render_string(template, context)
7
+ Mustache.render(template, context)
8
+ end
9
+
10
+ def get_unknown_context_keys_for_string(template)
11
+ stringView = Mustache.new
12
+ stringView.template = template
13
+ tags = stringView.template.tags || []
14
+ tags = tags.map { |t| t.split(".")[-1] }.to_set
15
+ tags
16
+ end
17
+
18
+ def render_file_content_from_template(template_path, filename, context)
19
+ filename = File.basename(filename, File.extname(filename))
20
+ context = context.merge({filename: filename, lowercased_filename: filename.camelize(:lower)})
21
+ Mustache.render(File.read(template_path), context)
8
22
  end
9
23
 
10
- def content_for_suffix(prefix, suffix)
11
- template_name = suffix.underscore
12
- options = @options.merge({name: prefix, lowercased_name: prefix.camelize(:lower)})
13
- template_file = File.join(@templates_path, "#{template_name}.mustache")
14
- Mustache.render(File.read(template_file), options)
24
+ def get_unknown_context_keys_for_template(template_path)
25
+ templateView = Mustache.new
26
+ templateView.template_file = template_path
27
+ tags = (templateView.template.tags || [])
28
+ tags = tags.map { |t| t.split(".")[-1] }.to_set
29
+ tags.subtract(Set["filename", "lowercased_filename"])
30
+ tags
15
31
  end
16
32
  end