ccios 4.1.0 → 5.0.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +26 -0
- data/Gemfile.lock +1 -1
- data/README.md +187 -56
- data/ccios.gemspec +1 -1
- data/lib/ccios/argument_template_parameter.rb +33 -0
- data/lib/ccios/code_templater.rb +24 -8
- data/lib/ccios/config.rb +41 -91
- data/lib/ccios/file_creator.rb +24 -22
- data/lib/ccios/file_template_definition.rb +94 -0
- data/lib/ccios/flag_template_parameter.rb +17 -0
- data/lib/ccios/group_template_definition.rb +54 -0
- data/lib/ccios/pbxproj_parser.rb +3 -54
- data/lib/ccios/snippet_template_definition.rb +27 -0
- data/lib/ccios/template_definition.rb +116 -0
- data/lib/ccios/templates/Coordinator/template.yml +20 -0
- data/lib/ccios/templates/Interactor/template.yml +25 -0
- data/lib/ccios/templates/Presenter/template.yml +49 -0
- data/lib/ccios/templates/Repository/template.yml +26 -0
- data/lib/ccios/templates_loader.rb +31 -0
- data/lib/ccios.rb +65 -43
- data/templates_library/async/Coordinator/template.yml +20 -0
- data/templates_library/async/Presenter/template.yml +49 -0
- metadata +35 -32
- data/lib/ccios/coordinator_generator.rb +0 -18
- data/lib/ccios/interactor_generator.rb +0 -33
- data/lib/ccios/presenter_generator.rb +0 -71
- data/lib/ccios/repository_generator.rb +0 -44
- data/templates_library/async/interactor.mustache +0 -13
- data/templates_library/async/interactor_assembly.mustache +0 -5
- data/templates_library/async/interactor_implementation.mustache +0 -22
- data/templates_library/async/repository.mustache +0 -13
- data/templates_library/async/repository_assembly.mustache +0 -6
- data/templates_library/async/repository_implementation.mustache +0 -20
- /data/lib/ccios/templates/{coordinator.mustache → Coordinator/coordinator.mustache} +0 -0
- /data/lib/ccios/templates/{interactor.mustache → Interactor/interactor.mustache} +0 -0
- /data/lib/ccios/templates/{interactor_assembly.mustache → Interactor/interactor_assembly.mustache} +0 -0
- /data/lib/ccios/templates/{interactor_implementation.mustache → Interactor/interactor_implementation.mustache} +0 -0
- /data/lib/ccios/templates/{dependency_provider.mustache → Presenter/dependency_provider.mustache} +0 -0
- /data/lib/ccios/templates/{presenter.mustache → Presenter/presenter.mustache} +0 -0
- /data/lib/ccios/templates/{presenter_assembly.mustache → Presenter/presenter_assembly.mustache} +0 -0
- /data/lib/ccios/templates/{presenter_implementation.mustache → Presenter/presenter_implementation.mustache} +0 -0
- /data/lib/ccios/templates/{view_contract.mustache → Presenter/view_contract.mustache} +0 -0
- /data/lib/ccios/templates/{view_controller.mustache → Presenter/view_controller.mustache} +0 -0
- /data/lib/ccios/templates/{repository.mustache → Repository/repository.mustache} +0 -0
- /data/lib/ccios/templates/{repository_assembly.mustache → Repository/repository_assembly.mustache} +0 -0
- /data/lib/ccios/templates/{repository_implementation.mustache → Repository/repository_implementation.mustache} +0 -0
- /data/templates_library/async/{coordinator.mustache → Coordinator/coordinator.mustache} +0 -0
- /data/templates_library/async/{dependency_provider.mustache → Presenter/dependency_provider.mustache} +0 -0
- /data/templates_library/async/{presenter.mustache → Presenter/presenter.mustache} +0 -0
- /data/templates_library/async/{presenter_assembly.mustache → Presenter/presenter_assembly.mustache} +0 -0
- /data/templates_library/async/{presenter_implementation.mustache → Presenter/presenter_implementation.mustache} +0 -0
- /data/templates_library/async/{view_contract.mustache → Presenter/view_contract.mustache} +0 -0
- /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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d0173944aad4daed89817a5a20eb66ebeb7cacb57d96f6bd1ab60ff79569680b
|
4
|
+
data.tar.gz: 927fecdf93f40d5636a1fcdefa173410b307ece874ffc6015ec9bb6e405cd7af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35a7291a319e2384a3c25662d58925dc8a77ca459fabc606a16d84ed257618f03584c42eb7dfd98d3103e3f2b3b2ceabcfe0a5663397c16d58a98e7b18e2b9c7
|
7
|
+
data.tar.gz: 5a254c0e5d56a4f9076da36dabab143673ae58a12351fc93eccb30ab7a1f07a9d240ee97f500d1a5023b210fcaf6fc6fbaa25507bca0257786fb79b97c31eabd
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,32 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
|
5
5
|
## [Unreleased]
|
6
6
|
|
7
|
+
## [5.0.0]
|
8
|
+
|
9
|
+
This release is an entire rewrite of the templating system, allowing customization of template and settings.
|
10
|
+
|
11
|
+
### Added
|
12
|
+
|
13
|
+
- New templating system that allows definition of custom templates per project
|
14
|
+
- A template can now declare multiple CLI arguments and flags
|
15
|
+
- Generated files can be added to multiple targets
|
16
|
+
- The base_path group and target can be configured independently for each generated file if needed.
|
17
|
+
- 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`
|
18
|
+
- List of known templates is available using `ccios --help`
|
19
|
+
|
20
|
+
### Changed
|
21
|
+
|
22
|
+
- Default templates has been migrated to the new format
|
23
|
+
- Configuration file (`.ccios`) format has been changed
|
24
|
+
- Command line invocation has changed:
|
25
|
+
- `ccios -p Example [-d]` is now `ccios presenter Example [-d]`
|
26
|
+
- `ccios -c Example [-d]` is now `ccios coordinator Example [-d]`
|
27
|
+
- `ccios -i Example [-d]` is now `ccios interactor Example`
|
28
|
+
- `ccios -r Example [-d]` is now `ccios repository Example`
|
29
|
+
- Some default provided mustache variables have been renamed:
|
30
|
+
- `name` is now `filename`
|
31
|
+
- `lowercased_name` is now `lowercased_filename`
|
32
|
+
|
7
33
|
## [4.1.0]
|
8
34
|
|
9
35
|
### Added
|
data/Gemfile.lock
CHANGED
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
|
-
|
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/
|
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
|
-
|
31
|
-
|
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
|
-
###
|
55
|
-
|
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
|
-
###
|
73
|
-
|
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
|
-
###
|
93
|
-
|
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,176 @@ The following structure is created for you in the Xcode project:
|
|
104
123
|
|
105
124
|
## Configuration
|
106
125
|
|
107
|
-
|
108
|
-
|
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
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
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
|
+
|
142
|
+
# Per template variables override
|
143
|
+
templates_config:
|
144
|
+
# Use the template name (in template.yml) to specify overrides on this template:
|
145
|
+
TEMPLATE_NAME:
|
146
|
+
# This overrides the default template variables
|
147
|
+
variables:
|
148
|
+
project: "Project.pbxproj"
|
149
|
+
# You can specify multiple target for generated files.
|
150
|
+
target:
|
151
|
+
- SomeTarget
|
152
|
+
- SomeOtherTarget
|
153
|
+
- ThirdTarget
|
154
|
+
# Per element variable override
|
155
|
+
elements_variables:
|
156
|
+
# This overrides the default variables for the element named "ELEMENT_NAME_1"
|
157
|
+
ELEMENT_NAME_1:
|
158
|
+
base_path: Core/Data
|
159
|
+
target: Core
|
160
|
+
ELEMENT_NAME_2:
|
161
|
+
base_path: Data
|
162
|
+
target: Data
|
163
|
+
# Another template variable override
|
116
164
|
presenter:
|
117
|
-
|
165
|
+
variables:
|
166
|
+
base_path: MyProject/App
|
167
|
+
elements_variables:
|
168
|
+
repository:
|
169
|
+
base_path: "Core/Data"
|
118
170
|
coordinator:
|
119
|
-
|
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
|
171
|
+
variables:
|
172
|
+
base_path: MyProject/Coordinator
|
132
173
|
```
|
133
174
|
|
134
|
-
|
135
|
-
```
|
136
|
-
app:
|
137
|
-
project: MyProject/MyProject.xcodeproj
|
138
|
-
target: MyProject # optional
|
139
|
-
presenter:
|
140
|
-
group: Classes/App
|
141
|
-
coordinator:
|
142
|
-
group: Classes/Coordinator
|
175
|
+
*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
176
|
|
144
|
-
|
145
|
-
project: MyProjectCore/MyProjectCore.xcodeproj
|
146
|
-
target: MyProjectCore # optional
|
147
|
-
interactor:
|
148
|
-
group: MyProjectCore/Interactors
|
149
|
-
repository:
|
150
|
-
group: MyProjectCore/Repository
|
177
|
+
## Template definition
|
151
178
|
|
152
|
-
|
153
|
-
project: MyProjectData/MyProjectData.xcodeproj
|
154
|
-
target: MyProjectData # optional
|
155
|
-
repository:
|
156
|
-
group: MyProjectData/Sources/Repositories
|
157
|
-
```
|
179
|
+
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
180
|
|
159
|
-
|
181
|
+
A template is a folder containing a file `template.yml` next to all templating files that will be used during generation.
|
182
|
+
Example for the default Interactor template:
|
183
|
+
```
|
184
|
+
Interactor/
|
185
|
+
template.yml
|
186
|
+
interactor.mustache
|
187
|
+
interactor_assembly.mustache
|
188
|
+
interactor_implementation.mustache
|
189
|
+
```
|
160
190
|
|
161
|
-
|
191
|
+
### `template.yml` format
|
192
|
+
|
193
|
+
```yml
|
194
|
+
# name of the template to use in the CLI. [required]
|
195
|
+
name: "custom_template"
|
196
|
+
# description of the template. [optional]
|
197
|
+
description: "Custom template definition"
|
198
|
+
# List of the parameters that will be given to the file templates. [required]
|
199
|
+
# The parameters can be used in template files, and in file path.
|
200
|
+
parameters:
|
201
|
+
# Use this to represent a string argument parameter in the CLI
|
202
|
+
# By default the argument will be passed to template renderer under the name "name", to use another name, specify a `template_variable_name`
|
203
|
+
- argument: "name"
|
204
|
+
# Description used in the help command. [Optional]
|
205
|
+
description: "name argument description"
|
206
|
+
# When present, the argument will be usable in templates under the provided name. [Optional]
|
207
|
+
template_variable_name: "in_template_variable_name"
|
208
|
+
# When present, will remove the provided suffix from the argument given. Example "MySuffix" will be tranformed into "My". [Optional]
|
209
|
+
removeSuffix: "Suffix"
|
210
|
+
# When present, the lowercased argument will be usable in templates under the provided name. [Optional]
|
211
|
+
lowercased_variable_name: "name_of_the_lowercased_variable"
|
212
|
+
# 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.
|
213
|
+
- flag: "long_name"
|
214
|
+
# The short name of this flag to use on CLI. [optional]
|
215
|
+
short_name: "n"
|
216
|
+
# Description used in the help command. [Optional]
|
217
|
+
description: "Description for the long_name flag"
|
218
|
+
# When present, the argument will be usable in templates under the provided name. [Optional]
|
219
|
+
template_variable_name: "in_template_flag_name"
|
220
|
+
# List of templates variables that is used to generate files in an xcode project. [Optional]
|
221
|
+
# Those variables can be overridden in config file, see section "Variable hierarchy" for more informations.
|
222
|
+
variables:
|
223
|
+
# The name of the xcode project. "*.xcodeproj" will use the first it finds. [required]
|
224
|
+
project: "*.xcodeproj"
|
225
|
+
# The base path used to generate an element. This variable must be defined once here, or on each elements below.
|
226
|
+
base_path: "path/to/base_group"
|
227
|
+
# 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 an empty string is provided, it will use the first target found in the Xcode project.
|
228
|
+
target: ""
|
229
|
+
# List of generated elements. [Required]
|
230
|
+
# Each element can be a file (using `file`), or an empty folder (using `group`)
|
231
|
+
generated_elements:
|
232
|
+
# Path from the `base_path` variable where the file will be generated
|
233
|
+
- file: "{{ name }}/{{ name }}File.swift"
|
234
|
+
# This name identifies this generated file to allow variable overrides in config file. [Required]
|
235
|
+
name: "file"
|
236
|
+
# The template specifies the name of template that will be used from `template_file_source`
|
237
|
+
template: "file"
|
238
|
+
# List of default element variable. [Optional]
|
239
|
+
variables: {}
|
240
|
+
# Path from the `base_path` variable where the directory will be generated
|
241
|
+
- group: "{{ name }}/group"
|
242
|
+
# This name identifies this generated file to allow variable overrides in config file. [Required]
|
243
|
+
name: "group"
|
244
|
+
# List of default element variable. [Optional]
|
245
|
+
variables:
|
246
|
+
- base_path: "path/override/to/base_group"
|
247
|
+
# List of code snippets that will be printed by the CLI after the generation of files. [Optional]
|
248
|
+
code_snippets:
|
249
|
+
# The name will be used in the printed line "Add this snippet to FilenameInWhichTheSnippetIsExpected" before the generated code snippet.
|
250
|
+
# This name will also be given to the snippet template under the variable `filename` and `lowercased_filename`. [Required]
|
251
|
+
- name: FilenameInWhichTheSnippetIsExpected
|
252
|
+
# The template specifies the name of template that will be used from `template_file_source`. [Required]
|
253
|
+
template: "file_snippets"
|
254
|
+
# List of templating files used for element generation or code snippets. [Required]
|
255
|
+
# The key is used as an identifier in `generated_elements` or `code_snippets`, the value is the path from the template directory.
|
256
|
+
template_file_source:
|
257
|
+
file: "file.mustache"
|
258
|
+
file_snippets: "file_snippets.mustache"
|
162
259
|
```
|
163
|
-
|
164
|
-
|
260
|
+
|
261
|
+
### Variable hierarchy
|
262
|
+
|
263
|
+
In `template.yml`
|
264
|
+
```yml
|
265
|
+
# [...]
|
266
|
+
variables:
|
267
|
+
# -> Default templates variables
|
268
|
+
generated_elements:
|
269
|
+
- name: element_name
|
270
|
+
# [...]
|
271
|
+
variables:
|
272
|
+
# -> Default Element variables
|
165
273
|
```
|
166
274
|
|
275
|
+
In `.ccios.yml`
|
276
|
+
```yml
|
277
|
+
variables:
|
278
|
+
# -> Config Global variables
|
279
|
+
templates_config:
|
280
|
+
repository:
|
281
|
+
variables:
|
282
|
+
# -> Config Template variables
|
283
|
+
element_variables:
|
284
|
+
element_name:
|
285
|
+
# -> Config Element variables
|
286
|
+
```
|
167
287
|
|
288
|
+
Templates will use variables in this order (first in this list is used):
|
289
|
+
- Config Template variables
|
290
|
+
- Default templates variables
|
291
|
+
- Config Global variables
|
292
|
+
|
293
|
+
Element will use variables in this order (first in this list is used): (For files, groups and code snippets)
|
294
|
+
- Config Element variables
|
295
|
+
- Default Element variables
|
296
|
+
- Config Template variables
|
297
|
+
- Default templates variables
|
298
|
+
- Config Global variables
|
data/ccios.gemspec
CHANGED
@@ -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
|
data/lib/ccios/code_templater.rb
CHANGED
@@ -2,15 +2,31 @@ require 'mustache'
|
|
2
2
|
require 'active_support/core_ext/string'
|
3
3
|
|
4
4
|
class CodeTemplater
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
data/lib/ccios/config.rb
CHANGED
@@ -2,11 +2,12 @@ require 'yaml'
|
|
2
2
|
|
3
3
|
class Config
|
4
4
|
|
5
|
-
attr_reader :
|
5
|
+
attr_reader :variables, :templates_collection
|
6
6
|
|
7
7
|
def self.parse(source_path)
|
8
8
|
if File.exist?(source_path)
|
9
9
|
config = YAML.load_file(source_path)
|
10
|
+
raise "Invalid config file" unless config.is_a?(Hash)
|
10
11
|
self.new config, source_path
|
11
12
|
else
|
12
13
|
puts "File #{source_path} does not exist. Using default config."
|
@@ -14,120 +15,69 @@ class Config
|
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
17
|
-
def self.default_config_hash
|
18
|
-
project = "*.xcodeproj"
|
19
|
-
{
|
20
|
-
"app" => {
|
21
|
-
"project" => project,
|
22
|
-
"presenter" => {"group" => "Classes/App"},
|
23
|
-
"coordinator" => {"group" => "Classes/Coordinator"}
|
24
|
-
},
|
25
|
-
"core" => {
|
26
|
-
"project" => project,
|
27
|
-
"interactor" => {"group" => "Classes/Core/Interactor"},
|
28
|
-
"repository" => {"group" => "Classes/Core/Data"}
|
29
|
-
},
|
30
|
-
"data" => {
|
31
|
-
"project" => project,
|
32
|
-
"repository" => {"group" => "Classes/Data"}
|
33
|
-
},
|
34
|
-
"templates" => self.default_templates_hash
|
35
|
-
}
|
36
|
-
end
|
37
|
-
|
38
18
|
def self.default
|
39
19
|
self.new default_config_hash
|
40
20
|
end
|
41
21
|
|
42
|
-
def self.
|
43
|
-
{
|
22
|
+
def self.default_config_hash
|
23
|
+
{}
|
44
24
|
end
|
45
25
|
|
46
26
|
def initialize(config_hash, source_path = nil)
|
47
|
-
@
|
48
|
-
|
49
|
-
@
|
50
|
-
|
51
|
-
@
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
27
|
+
@variables = config_hash["variables"] || {}
|
28
|
+
@templates_collection = config_hash["templates_collection"] || nil
|
29
|
+
@templates_config = {}
|
30
|
+
|
31
|
+
raise "Invalid \"templates_collection\" in config, should be a string" unless @templates_collection.is_a?(String) || @templates_collection.nil?
|
32
|
+
|
33
|
+
templates_config = config_hash["templates_config"] || {}
|
34
|
+
raise "Invalid \"templates_config\" in configuration, it should be a dictionary" unless templates_config.is_a?(Hash)
|
35
|
+
templates_config.each do |key, hash|
|
36
|
+
raise "Invalid template configuration for \"#{key}\"" unless hash.is_a?(Hash)
|
37
|
+
template_config = TemplateConfig.new(hash)
|
38
|
+
@templates_config[key] = template_config
|
56
39
|
end
|
57
40
|
end
|
58
41
|
|
59
|
-
def
|
60
|
-
|
61
|
-
|
62
|
-
validate_path hash, "app.coordinator.group"
|
63
|
-
|
64
|
-
validate_path hash, "core.project"
|
65
|
-
validate_path hash, "core.interactor.group"
|
66
|
-
validate_path hash, "core.repository.group"
|
67
|
-
|
68
|
-
validate_path hash, "data.project"
|
69
|
-
validate_path hash, "data.repository.group"
|
42
|
+
def variables_for_template(template)
|
43
|
+
template_config = @templates_config[template.name] || TemplateConfig.new({})
|
44
|
+
@variables.merge(template.variables).merge(template_config.variables)
|
70
45
|
end
|
71
46
|
|
72
|
-
def
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
keys << component
|
78
|
-
if hash.nil?
|
79
|
-
message = "Key \"#{keys.join(".")}\" is missing"
|
80
|
-
message += " in #{@source_path}" unless @source_path.nil?
|
81
|
-
raise message
|
82
|
-
end
|
83
|
-
end
|
47
|
+
def variables_for_template_element(template, element_name, element_default_variables = {})
|
48
|
+
template_config = @templates_config[template.name] || TemplateConfig.new({})
|
49
|
+
element_config = template_config.element_configuration_for(element_name)
|
50
|
+
template_variables = @variables.merge(template.variables).merge(template_config.variables)
|
51
|
+
template_variables.merge(element_default_variables).merge(element_config.variables)
|
84
52
|
end
|
85
53
|
end
|
86
54
|
|
87
|
-
class
|
88
|
-
attr_reader :project, :target, :presenter, :coordinator
|
55
|
+
class TemplateConfig
|
89
56
|
|
90
|
-
|
91
|
-
@project = hash["project"]
|
92
|
-
@target = hash["target"]
|
93
|
-
@presenter = ObjectConfig.new hash["presenter"]
|
94
|
-
@coordinator = ObjectConfig.new hash["coordinator"]
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
class CoreConfig
|
99
|
-
attr_reader :project, :target, :interactor, :repository
|
57
|
+
attr_reader :variables
|
100
58
|
|
101
59
|
def initialize(hash)
|
102
|
-
@
|
103
|
-
@
|
104
|
-
|
105
|
-
|
60
|
+
@variables = hash["variables"] || {}
|
61
|
+
@template_element_config = {}
|
62
|
+
|
63
|
+
elements_variables = hash["elements_variables"] || {}
|
64
|
+
raise "Invalid configuration, \"elements_variables\" should be a dictionary" unless elements_variables.is_a?(Hash)
|
65
|
+
elements_variables.each do |key, hash|
|
66
|
+
raise "Invalid element variable configuration for \"#{key}\"" unless hash.is_a?(Hash)
|
67
|
+
@template_element_config[key] = TemplateElementConfig.new(hash)
|
68
|
+
end
|
106
69
|
end
|
107
|
-
end
|
108
70
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
def initialize(hash)
|
113
|
-
@project = hash["project"]
|
114
|
-
@target = hash["target"]
|
115
|
-
@repository = ObjectConfig.new hash["repository"]
|
71
|
+
def element_configuration_for(element)
|
72
|
+
@template_element_config[element] || TemplateConfig.new({})
|
116
73
|
end
|
117
74
|
end
|
118
75
|
|
119
|
-
class
|
120
|
-
attr_reader :group
|
76
|
+
class TemplateElementConfig
|
121
77
|
|
122
|
-
|
123
|
-
@group = hash["group"]
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
class TemplatesConfig
|
128
|
-
attr_reader :path
|
78
|
+
attr_reader :variables
|
129
79
|
|
130
80
|
def initialize(hash)
|
131
|
-
@
|
81
|
+
@variables = hash
|
132
82
|
end
|
133
|
-
end
|
83
|
+
end
|