power_stencil 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +5 -0
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +198 -0
  9. data/Rakefile +6 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +8 -0
  12. data/bin/update_plugin_template +79 -0
  13. data/doc/builds.md +267 -0
  14. data/doc/entities.md +964 -0
  15. data/doc/example_use_cases.md +59 -0
  16. data/doc/images/power-stencil-entity-build.svg +481 -0
  17. data/doc/images/power-stencil-entity-creation.svg +375 -0
  18. data/doc/images/power-stencil-simple-flow.svg +265 -0
  19. data/doc/plugins.md +169 -0
  20. data/doc/templates.md +333 -0
  21. data/etc/base_commands_definition.yml +259 -0
  22. data/etc/meta_templates/plugin_seed/etc/command_line.yaml +12 -0
  23. data/etc/meta_templates/plugin_seed/etc/plugin_config.yaml +4 -0
  24. data/etc/meta_templates/plugin_seed/etc/templates/.git_keep +0 -0
  25. data/etc/meta_templates/plugin_seed/lib/{entity}.rb.erb +34 -0
  26. data/etc/meta_templates/plugin_seed/lib/{entity}/entity_definitions/{entity}_entity.rb.erb +11 -0
  27. data/etc/meta_templates/plugin_seed/lib/{entity}/plugin_helper.rb.erb +17 -0
  28. data/etc/meta_templates/plugin_seed/lib/{entity}/version.rb.erb +3 -0
  29. data/etc/meta_templates/plugin_seed/lib/{entity}/{entity}_processor.rb.erb +19 -0
  30. data/etc/meta_templates/plugin_seed/psplugin_{entity}.gemspec +36 -0
  31. data/etc/power_stencil.yaml +92 -0
  32. data/etc/templates/plugin_definition/.gitignore +11 -0
  33. data/etc/templates/plugin_definition/.rspec +3 -0
  34. data/etc/templates/plugin_definition/.travis.yml +5 -0
  35. data/etc/templates/plugin_definition/CODE_OF_CONDUCT.md +74 -0
  36. data/etc/templates/plugin_definition/Gemfile +6 -0
  37. data/etc/templates/plugin_definition/LICENSE.txt +21 -0
  38. data/etc/templates/plugin_definition/README.md +43 -0
  39. data/etc/templates/plugin_definition/Rakefile +6 -0
  40. data/etc/templates/plugin_definition/bin/console +14 -0
  41. data/etc/templates/plugin_definition/bin/setup +8 -0
  42. data/etc/templates/plugin_definition/etc/command_line.yaml +12 -0
  43. data/etc/templates/plugin_definition/etc/plugin_config.yaml +4 -0
  44. data/etc/templates/plugin_definition/etc/templates/.git_keep +1 -0
  45. data/etc/templates/plugin_definition/lib/{entity}.rb.erb +34 -0
  46. data/etc/templates/plugin_definition/lib/{entity}/entity_definitions/{entity}_entity.rb.erb +11 -0
  47. data/etc/templates/plugin_definition/lib/{entity}/plugin_helper.rb.erb +17 -0
  48. data/etc/templates/plugin_definition/lib/{entity}/version.rb.erb +3 -0
  49. data/etc/templates/plugin_definition/lib/{entity}/{entity}_processor.rb.erb +19 -0
  50. data/etc/templates/plugin_definition/psplugin_{entity}.gemspec +36 -0
  51. data/etc/templates/plugin_definition/spec/spec_helper.rb +14 -0
  52. data/etc/templates/plugin_definition/spec/{entity}_spec.rb +9 -0
  53. data/etc/templates/project/.copy_ignore +2 -0
  54. data/etc/templates/project/.gitignore.erb +6 -0
  55. data/etc/templates/project/.ps_project/entities/.gitkeep +0 -0
  56. data/etc/templates/project/.ps_project/entities/README.md +11 -0
  57. data/etc/templates/project/.ps_project/entity_definitions/.gitkeep +0 -0
  58. data/etc/templates/project/.ps_project/entity_definitions/README.md +15 -0
  59. data/etc/templates/project/.ps_project/personal-config.yaml +8 -0
  60. data/etc/templates/project/.ps_project/plugins/.gitkeep +0 -0
  61. data/etc/templates/project/.ps_project/templates-templates/.gitkeep +0 -0
  62. data/etc/templates/project/.ps_project/templates-templates/README.md +13 -0
  63. data/etc/templates/project/.ps_project/user_entities/.gitkeep +0 -0
  64. data/etc/templates/project/.ps_project/user_entities/README.md +12 -0
  65. data/etc/templates/project/.ps_project/versioned-config.yaml +6 -0
  66. data/etc/templates/simple_exec/main.sh +4 -0
  67. data/exe/power_stencil +28 -0
  68. data/lib/power_stencil.rb +53 -0
  69. data/lib/power_stencil/command_processors/build.rb +43 -0
  70. data/lib/power_stencil/command_processors/check.rb +35 -0
  71. data/lib/power_stencil/command_processors/create.rb +70 -0
  72. data/lib/power_stencil/command_processors/delete.rb +38 -0
  73. data/lib/power_stencil/command_processors/edit.rb +35 -0
  74. data/lib/power_stencil/command_processors/entity_helper.rb +105 -0
  75. data/lib/power_stencil/command_processors/get.rb +22 -0
  76. data/lib/power_stencil/command_processors/info.rb +41 -0
  77. data/lib/power_stencil/command_processors/init.rb +47 -0
  78. data/lib/power_stencil/command_processors/new_plugin.rb +31 -0
  79. data/lib/power_stencil/command_processors/root.rb +27 -0
  80. data/lib/power_stencil/command_processors/shell.rb +37 -0
  81. data/lib/power_stencil/command_processors/trace_helper.rb +20 -0
  82. data/lib/power_stencil/dsl/base.rb +24 -0
  83. data/lib/power_stencil/dsl/entities.rb +46 -0
  84. data/lib/power_stencil/dsl/plugin_generation.rb +17 -0
  85. data/lib/power_stencil/engine/base.rb +50 -0
  86. data/lib/power_stencil/engine/build_handling.rb +77 -0
  87. data/lib/power_stencil/engine/directory_processor.rb +111 -0
  88. data/lib/power_stencil/engine/entities_definitions.rb +42 -0
  89. data/lib/power_stencil/engine/entities_handling.rb +76 -0
  90. data/lib/power_stencil/engine/entity_engine.rb +20 -0
  91. data/lib/power_stencil/engine/init_engine.rb +18 -0
  92. data/lib/power_stencil/engine/project_engine.rb +75 -0
  93. data/lib/power_stencil/engine/renderers/erb.rb +21 -0
  94. data/lib/power_stencil/error.rb +20 -0
  95. data/lib/power_stencil/initializer.rb +87 -0
  96. data/lib/power_stencil/plugins/base.rb +54 -0
  97. data/lib/power_stencil/plugins/capabilities.rb +30 -0
  98. data/lib/power_stencil/plugins/command_line.rb +27 -0
  99. data/lib/power_stencil/plugins/config.rb +32 -0
  100. data/lib/power_stencil/plugins/dependencies.rb +32 -0
  101. data/lib/power_stencil/plugins/gem.rb +57 -0
  102. data/lib/power_stencil/plugins/require.rb +77 -0
  103. data/lib/power_stencil/plugins/templates.rb +21 -0
  104. data/lib/power_stencil/project/base.rb +79 -0
  105. data/lib/power_stencil/project/config.rb +54 -0
  106. data/lib/power_stencil/project/create.rb +30 -0
  107. data/lib/power_stencil/project/info.rb +72 -0
  108. data/lib/power_stencil/project/paths.rb +119 -0
  109. data/lib/power_stencil/project/plugins.rb +89 -0
  110. data/lib/power_stencil/project/proxy.rb +13 -0
  111. data/lib/power_stencil/project/templates.rb +56 -0
  112. data/lib/power_stencil/project/versioning.rb +29 -0
  113. data/lib/power_stencil/system_entity_definitions/all.rb +14 -0
  114. data/lib/power_stencil/system_entity_definitions/buildable.rb +23 -0
  115. data/lib/power_stencil/system_entity_definitions/entity_override.rb +8 -0
  116. data/lib/power_stencil/system_entity_definitions/entity_project_common.rb +33 -0
  117. data/lib/power_stencil/system_entity_definitions/has_associated_files.rb +13 -0
  118. data/lib/power_stencil/system_entity_definitions/non_persistent.rb +14 -0
  119. data/lib/power_stencil/system_entity_definitions/plugin.rb +17 -0
  120. data/lib/power_stencil/system_entity_definitions/process_descriptor.rb +15 -0
  121. data/lib/power_stencil/system_entity_definitions/project_config.rb +24 -0
  122. data/lib/power_stencil/system_entity_definitions/project_entity.rb +16 -0
  123. data/lib/power_stencil/system_entity_definitions/simple_exec.rb +47 -0
  124. data/lib/power_stencil/utils/directory_processor.rb +54 -0
  125. data/lib/power_stencil/utils/file_edit.rb +87 -0
  126. data/lib/power_stencil/utils/file_helper.rb +56 -0
  127. data/lib/power_stencil/utils/gem_utils.rb +13 -0
  128. data/lib/power_stencil/utils/secure_require.rb +26 -0
  129. data/lib/power_stencil/utils/semantic_version.rb +128 -0
  130. data/lib/power_stencil/version.rb +3 -0
  131. data/power_stencil.gemspec +32 -0
  132. metadata +287 -0
@@ -0,0 +1,169 @@
1
+ Plugins
2
+ =======
3
+
4
+ <!-- TOC -->
5
+
6
+ - [Why plugins ?](#why-plugins-)
7
+ - [Capitalize on your custom entity types](#capitalize-on-your-custom-entity-types)
8
+ - [Functional code growing](#functional-code-growing)
9
+ - [Need of very specific post actions developed in Ruby](#need-of-very-specific-post-actions-developed-in-ruby)
10
+ - [Enhance `power_stencil` command line](#enhance-power_stencil-command-line)
11
+ - [What are plugins ?](#what-are-plugins-)
12
+ - [Creating plugin local to the project](#creating-plugin-local-to-the-project)
13
+
14
+ <!-- /TOC -->
15
+ [:back:][Documentation root]
16
+
17
+ # Why plugins ?
18
+
19
+ If you read everything about [entities], [templates] and [builds], you may wonder why you may ever need to create plugins. There are nevertheless good reasons to build real plugins.
20
+
21
+ ## Capitalize on your custom entity types
22
+
23
+ You have designed super nicely crafted entity types that you may want to **re-use** in other projects.
24
+
25
+ ## Functional code growing
26
+
27
+ If you start developing a lot of code around your entity types, it may become a bad idea to keep everything within your entity types code and you may want to **structure** your code, add tests to it etc...
28
+
29
+ ## Need of very specific post actions developed in Ruby
30
+
31
+ If calling an executable after the [build][builds] process completed is not enough and you want some custom Ruby to be run right after the [build][builds] completion.
32
+
33
+ ## Enhance `power_stencil` command line
34
+
35
+ If you want to have new custom sub-commands or options available.
36
+
37
+
38
+ # What are plugins ?
39
+
40
+ Plugins are actually Ruby Gems with a specific structure. Plugins can be part of the project or provided as a separated stand-alone Gem.
41
+
42
+ The normal process would be to begin with a plugin within the project and once you're ok with its features you may release it as a standalone Ruby Gem.
43
+
44
+ - Plugins local to the project are automatically taken in account.
45
+ - To use plugins provided as Gems you have to set the `:plugins:` array property in the `.ps_project/versioned-config.yaml`
46
+
47
+ :warning: Plugins provided as standalone Gems are not thoroughly tested, for the time being you may use plugins local to the project.
48
+
49
+
50
+ # Creating plugin local to the project
51
+
52
+ The is a command provided for that, that will create a whole plugin skeleton.
53
+
54
+ ```shell
55
+ $ power_stencil new-plugin myplugin
56
+ Generated new plugin 'myplugin'
57
+
58
+ $ ll .ps_project/plugins/myplugin
59
+ total 60
60
+ drwxrwxr-x 6 laurent laurent 4096 août 28 14:38 ./
61
+ drwxrwxr-x 3 laurent laurent 4096 août 28 14:38 ../
62
+ drwxrwxr-x 2 laurent laurent 4096 août 28 14:38 bin/
63
+ -rw-rw-r-- 1 laurent laurent 3228 août 28 14:38 CODE_OF_CONDUCT.md
64
+ drwxrwxr-x 3 laurent laurent 4096 août 28 14:38 etc/
65
+ -rw-rw-r-- 1 laurent laurent 163 août 28 14:38 Gemfile
66
+ -rw-rw-r-- 1 laurent laurent 113 août 28 14:38 .gitignore
67
+ drwxrwxr-x 3 laurent laurent 4096 août 28 14:38 lib/
68
+ -rw-rw-r-- 1 laurent laurent 1077 août 28 14:38 LICENSE.txt
69
+ -rw-rw-r-- 1 laurent laurent 1491 août 28 14:38 psplugin_myplugin.gemspec
70
+ -rw-rw-r-- 1 laurent laurent 117 août 28 14:38 Rakefile
71
+ -rw-rw-r-- 1 laurent laurent 1770 août 28 14:38 README.md
72
+ -rw-rw-r-- 1 laurent laurent 53 août 28 14:38 .rspec
73
+ drwxrwxr-x 2 laurent laurent 4096 août 28 14:38 spec/
74
+ -rw-rw-r-- 1 laurent laurent 88 août 28 14:38 .travis.yml
75
+ ```
76
+
77
+ You can see that it looks a lot like a Ruby Gem, and it's normal because it is ;-)...
78
+
79
+ So what was the impact on the project.
80
+
81
+ If you do a `power_stencil info` you see a new part appeared in the report
82
+
83
+ ```
84
+ --------------------------------------------------------------------------------
85
+ Plugins:
86
+ --> Plugin 'myplugin' has following capabilities:
87
+ - command_line: true
88
+ - local_config: true
89
+ - processors: true
90
+ - build: false
91
+ - dsl: false
92
+ - entity_definitions: true
93
+ - code: true
94
+ - version: true
95
+ - templates: true
96
+ ```
97
+ Each of the lines correspond to what is called a _plugin capability_.
98
+
99
+ Obviously by default the plugin does nothing, but it defined some placeholders. For example in the ouput here above it says `command_line: true`. What could it mean ?
100
+
101
+ Let's try to see to help:
102
+
103
+ ```shell
104
+ $ power_stencil --help
105
+ This is power_stencil. A powerful templating engine.
106
+ -- Options ---------------------------------------------------------------------
107
+ -v, --verbose Displays extra runtime information.
108
+ -h, --help Displays this help.
109
+ --program-version, -V, --version Displays program version.
110
+ --simulate Will not perform actual actions
111
+ --debug Debug mode
112
+ --debug-on-err, --debug-on-stderr Sends debugging to SDTERR
113
+ --log-level Defines the level of logging (0 to 5)
114
+ --log-file Specifies a file to log into
115
+ --truncate-log-file Truncates the log file (appends by default)
116
+ --project-path Specifies a startup path to use instead of '.'
117
+ --auto Bypasses command-line confirmations to the user
118
+
119
+ --------------------------------------------------------------------------------
120
+ Following subcommands exist too:
121
+ For more information you can always issue sub_command_name --help...
122
+ --------------------------------------------------------------------------------
123
+ * init: Initializes a PowerStencil repository ...
124
+ * info: Generic information about the repository ...
125
+ * new-plugin: Generates the skeleton for a plugin ...
126
+ * get: Query entities from repository ...
127
+ * shell: Opens a shell to interact with entities ...
128
+ * check: Check repository entities consistency ...
129
+ * create: Creates entities in the repository ...
130
+ * edit: Edit entities from repository ...
131
+ * delete: Delete entities from repository ...
132
+ * build: Builds entities ...
133
+ * myplugin: Does nothing useful Added by plugin myplugin
134
+ ```
135
+
136
+ You can see that the plugin brought a new sub-command `myplugin`.
137
+
138
+ Let's try it:
139
+
140
+ ```shell
141
+ $ power_stencil myplugin
142
+ MYPLUGIN PLUGIN WAZ HERE
143
+ ```
144
+
145
+ Wow it worked ! Useless, but worked !
146
+
147
+
148
+ The documentation for plugins is not yet done, so you are encouraged to read the code, the capabilities (in the output of `power_stencil info`) give you an idea of what plugins can do.
149
+
150
+ :warning: As opposed to the rest of `PowerStencil`, the functionnality is nevertheless not completely frozen.
151
+
152
+
153
+ [:back:][Documentation root]
154
+ <!-- End of Document -->
155
+
156
+ <!-- Pages -->
157
+ [Documentation root]: ../README.md "Back to documentation root"
158
+ [entities]: entities.md "Entities in PowerStencil"
159
+ [builds]: builds.md "Builds in PowerStencil"
160
+ [templates]: templates.md "Templates in PowerStencil"
161
+
162
+
163
+ <!-- Code links -->
164
+
165
+
166
+ <!-- Illustrations -->
167
+
168
+
169
+ <!-- External links -->
@@ -0,0 +1,333 @@
1
+ Templates
2
+ =========
3
+
4
+ <!-- TOC -->
5
+
6
+ - [Templates overview](#templates-overview)
7
+ - [Templates discovery with `simple_exec` entity type](#templates-discovery-with-simple_exec-entity-type)
8
+ - [What can I do within templates ?](#what-can-i-do-within-templates-)
9
+ - [ERB for newbies](#erb-for-newbies)
10
+ - [The `PowerStencil` DSL](#the-powerstencil-dsl)
11
+ - [Where do I create templates ?](#where-do-i-create-templates-)
12
+ - [Creating templates-templates of your own](#creating-templates-templates-of-your-own)
13
+ - [basics](#basics)
14
+ - [`.xxx_ignore` files](#xxx_ignore-files)
15
+ - [Application to our example](#application-to-our-example)
16
+
17
+ <!-- /TOC -->
18
+ [:back:][Documentation root]
19
+
20
+ # Templates overview
21
+
22
+ Templates are the key feature of `PowerStencil` (hence the name). Templates are what will use the [entities] you carefully crafted in order to produce something during the [build][builds] process.
23
+
24
+ Currently the underlying engine is [ERB].
25
+
26
+ When an entity type has some templates associated and you create an entity, it will create a directory `<entity_type>/<entity_name>` where you will fond those templates.
27
+
28
+ # Templates discovery with `simple_exec` entity type
29
+
30
+ In the basic entity types, the only one having templates is the `simple_exec` entity type. So let's try with it:
31
+
32
+ ```shell
33
+ $ power_stencil create simple_exec/demo_templates
34
+ Created 'simple_exec/demo_templates'
35
+
36
+ $ power_stencil check simple_exec/demo_templates
37
+ RAW ENTITIES
38
+ 'simple_exec/demo_templates':
39
+ - Storage path : '/tmp/tst3/.ps_project/entities/simple_exec/demo_templates.yaml'
40
+ - Templates path : '/tmp/tst3/simple_exec/demo_templates'
41
+ - Status : Valid
42
+ - Buildable : true
43
+ ```
44
+ As you can see the output of `power_stencil check` shows more information than entities we already created. First we see that this entity is `buildable`, and we'll detail that in the [builds] document, but for the moment what we will focus on the `Templates path` information.
45
+
46
+ And it's true if we have a look in the `simple_exec/demo_templates` from the root of the project, a file appeared there:
47
+
48
+ ```shell
49
+ $ ls -l simple_exec/demo_templates
50
+ total 4
51
+ -rwxrwxr-x 1 laurent laurent 57 août 23 16:44 main.sh
52
+
53
+ $ cat simple_exec/demo_templates/main.sh
54
+ #!/usr/bin/env bash
55
+
56
+ echo "Nothing to do... Easy task..."
57
+ ```
58
+
59
+ Humm... This stuff doesn't look like a template...looks like a regular bash script. It's true and we'll come back to the internals of `simple_exec` in the [builds], where does this script come from etc... So don't focus too much on this file for the moment.
60
+
61
+ We will just first experiment our first build !
62
+
63
+ ```shell
64
+ $ power_stencil build simple_exec/demo_templates -v
65
+ De-templating files for 'simple_exec/demo_templates' into '/tmp/tst3/build/20190823-1709-54271-simple_exec_demo_templates/simple_exec_demo_templates'
66
+ Entities analysis completed.
67
+ Running '/tmp/tst3/build/20190823-1709-54271-simple_exec_demo_templates/simple_exec_demo_templates/main.sh'
68
+ Nothing to do... Easy task...
69
+ End of process 15572
70
+ - 'simple_exec/demo_templates' has been correctly built
71
+ ```
72
+
73
+ What can we see there ?
74
+
75
+ The first line is the most interesting one for us. It says "De-templating ... into ...", and it's true that a brand new directory named `build` appeared at the root of the project. Again we won't focus too much on the name of the sub-directory as we will see that in the [builds], but if we have a look in the generated directory we see the same content as what we had in `simple_exec/demo_templates`...
76
+ And by the way the generated script seems to have been run, as we can see in the output.
77
+
78
+ :warning: If bash is not installed on your system, the output will obviously be different as `PowerStencil` won't be able to run the script, yet all the files should have been generated correctly.
79
+
80
+ Ok is it possible, that everything inside `simple_exec/demo_templates` is actually considered as templates ? **The answer is yes !!**
81
+
82
+ Let prove it and replace the content of `simple_exec/demo_templates/main.sh` by the following:
83
+
84
+ ```shell
85
+ #!/usr/bin/env bash
86
+
87
+ echo "This script has been generated on <%= Time.now %>"
88
+
89
+ echo "It was done in the scope of '<%= build_target.name %>' (which is of the type '<%= build_target.type %>')..."
90
+ ```
91
+ Ah ok... now it looks like an ERB template !
92
+
93
+ Let's rebuild...
94
+
95
+ ```shell
96
+ $ power_stencil build simple_exec/demo_templates -v
97
+ De-templating files for 'simple_exec/demo_templates' into '/tmp/tst3/build/20190823-1733-08665-simple_exec_demo_templates/simple_exec_demo_templates'
98
+ Entities analysis completed.
99
+ Running '/tmp/tst3/build/20190823-1733-08665-simple_exec_demo_templates/simple_exec_demo_templates/main.sh'
100
+ This script has been generated on 2019-08-23 17:33:08 +0200
101
+ It was done in the scope of 'demo_templates' (which is of the type 'simple_exec')...
102
+ End of process 415
103
+ - 'simple_exec/demo_templates' has been correctly built
104
+ ```
105
+
106
+ And it's true, if I have a look at the generated script (replace with your own path):
107
+
108
+ ```shell
109
+ $ cat /tmp/tst3/build/20190823-1733-08665-simple_exec_demo_templates/simple_exec_demo_templates/main.sh
110
+ #!/usr/bin/env bash
111
+
112
+ echo "This script has been generated on 2019-08-23 17:33:08 +0200"
113
+
114
+ echo "It was done in the scope of 'demo_templates' (which is of the type 'simple_exec')..."
115
+ ```
116
+
117
+ The content has been "de-templated"... :+1: sooo cool !
118
+
119
+ :information_source: Here the template directory of the `simple_exec/demo_templates` was containing only on file (the bash script), but **any file in any sub-directory of that directory would have been considered as a template** (yet there are some mechanism to control and limit which files have to be processed, like for example imagine there would be images, or zip files, probably you don't want them to be processed. All of this will be covered in the [builds] document).
120
+
121
+ # What can I do within templates ?
122
+
123
+ ## ERB for newbies
124
+
125
+ So you noticed the [ERB] syntax. If you already developed within a [Ruby on Rails] project you are probably used to it. Basically [ERB] introduces two main types of tags:
126
+
127
+ - `<% %>` between those tags you can put **any valid [Ruby] code**.
128
+ - `<%= %>` what is returned by the enclosed [Ruby] code will be inserted _here_ in the resulting document.
129
+
130
+ There are some other minor tags like comments, or insertion without carriage return... You are encouraged to have a look at [ERB] if you don't know it, but it's fairly simple like most templating engine are.
131
+
132
+ ## The `PowerStencil` DSL
133
+
134
+ On top of any Ruby legit code you can use special methods provided by `PowerStencil` to ease the access to entities, configuration etc...
135
+
136
+ Here are the main methods:
137
+
138
+ - `entity(type, name)` will return any entity from the repository. The method is self-explanatory, this is the most generic way to access any entity of the repository.
139
+ - `entities(criterion: nil, value: nil, &filter_block)` which is a more generic entities query method where `criterion` can be `:by_name` or `:by_type` and that will return an array (that you can potentially filter using the `filter_block`).
140
+ - `build_target` will return the entity that you are currently building.
141
+ - `project_config` is a shortcut to the project entity. You could actually retrieve it using the `entity(type, name)` method.
142
+
143
+ And of course you have access like in `power_stencil shell` to any class brought by `PowerStencil`, you could create entities there, destroy some, **but you should not do it**, as it would be very weird to do that during the process of detemplating !
144
+
145
+ # Where do I create templates ?
146
+
147
+ **When an entity is [buildable] you can find its templates in the `<entity_type>/<entity_name>` from the root of the project.**
148
+
149
+ But by default, that directory is not created, and if no templates is created at this place for a [buildable] entity, the build will fail saying it didn't find any template...
150
+
151
+ Yet, you probably noticed that when we created an entity of `simple_exec` type, a file (the bash script `main.sh`) _automagically_ appeared in the right place so that we could immediatelly build it. How can you achieve that with entity types of your own ? **This is what is called _templates-templates_**...
152
+
153
+ First let's have a look at the output of `power_stencil info`, focusing on `simple_exec`:
154
+
155
+ ```shell
156
+ $ power_stencil info
157
+ .
158
+ .
159
+ .
160
+ - Type 'simple_exec' --> PowerStencil::SystemEntityDefinitions::SimpleExec (template-template path: '/opt/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/power_stencil-0.2.18/etc/templates/simple_exec')
161
+ ```
162
+
163
+ `simple_exec` is an entity type coming with `PowerStencil`, and you can see that it takes its _template-template_ from within the `PowerStencil` gem itself !
164
+
165
+ But within the `PowerStencil` project, there is a place to create _templates-templates_ of your own: `.ps_projet/templates-templates/<entity_type>`.
166
+
167
+ To summarize about templates and _templates-templates_:
168
+
169
+ ![entity-creation-flow]
170
+
171
+ :information_source: There is actually a third place where you could find entity types and _templates-templates_, this is within [plugins], but we will cover that in the [plugins] part...
172
+
173
+ # Creating templates-templates of your own
174
+
175
+ ## basics
176
+
177
+ Let's imagine we have a custom buildable entity type defined in `.ps_project/entity_definitions/custom_buildable_entity.rb` and which content is:
178
+
179
+ ```ruby
180
+ class CustomBuildableEntity < PowerStencil::SystemEntityDefinitions::ProjectEntity
181
+ entity_type :custom_buildable_entity
182
+ buildable
183
+ end
184
+ ```
185
+ We could have (useless) _templates-templates_ defined in `.ps_project/templates-templates/custom_buildable_entity`.
186
+
187
+ :information_source: A whole tree structure can be defined there, not only one file.
188
+
189
+ Let's create there a text file named `a_useless_text_file.txt` with the following content:
190
+
191
+ ```
192
+ This text has been generated on the <%= Time.now %>
193
+
194
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit,
195
+ sed do eiusmod tempor incididunt ....
196
+ ```
197
+
198
+ Let's now create an entity of this type:
199
+
200
+ ```shell
201
+ $ power_stencil create custom_buildable_entity/test1
202
+ Created 'custom_buildable_entity/test1'
203
+
204
+ $ ll custom_buildable_entity/test1
205
+ total 12
206
+ drwxrwxr-x 2 laurent laurent 4096 août 26 13:40 ./
207
+ drwxrwxr-x 3 laurent laurent 4096 août 26 13:40 ../
208
+ -rw-rw-r-- 1 laurent laurent 26 août 26 13:40 a_useless_text_file.txt
209
+ ```
210
+ Everything, seems ok. The entity `custom_buildable_entity/test1` has been created and there is now a new folder at the root of the project named `custom_buildable_entity/test1` and which content is a text file named `a_useless_text_file.txt`... So far so good.
211
+
212
+ And what is the content of this file ?
213
+
214
+ ```shell
215
+ $ cat custom_buildable_entity/test1/a_useless_text_file.txt
216
+ This text has been generated on the 2019-08-26 13:50:35 +0200
217
+
218
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit,
219
+ sed do eiusmod tempor incididunt ....
220
+ ```
221
+
222
+ **Oops !!** It looks like the _template-template_ content has been processed as templates and the `<%= Time.now %>` code has been replaced by its result. This is not **at all** what we could have expected !! The idea was that the entity type template (the _template-template_) would become the entity template, ready for the build...
223
+
224
+ **:warning: In `PowerStencil`, the concept is that everywhere there is a template defined (and _templates-templates_ are), they are really treated as templates unless you explicitely say the opposite !**
225
+
226
+ So, how can we avoid that, so that the _templates-templates_ are not processed as templates ?
227
+
228
+ A bad answer would be to have [ERB] code to generate [ERB] tags and code... :scream: (although sometimes in very specific cases you may really want to do that).
229
+
230
+ No in this case we would like the _template-template_ to be simply not processed as a template. There is a solution for that _.xxx_ignore files_...
231
+
232
+ ## `.xxx_ignore` files
233
+
234
+ When any file is processed using the `PowerStencil` framework to generate another file, there are 3 operations/checks that are always applied:
235
+
236
+ 1. Is the file eligible to the process (ie should it be completely ignored by the process) ?
237
+ 2. Is the file eligible to the templating process ?
238
+ 3. Should the file be renamed ?
239
+
240
+ This is managed through a set of files that work the same way `.git_ignore` files work for Git. You can have those files anywhere within the tree of files that are processed.
241
+
242
+ Their syntax is very simple. Each line can either be:
243
+
244
+ - an empty line
245
+ - a comment line starting with `#`
246
+ - a line specifying a [Dir::glob pattern]
247
+
248
+ As you probably now guessed, there are three different `.xxx_ignore` types of files available:
249
+
250
+ - the `.copy_ignore` file will define which files should be completely ignored by the process. A good example would be for example a README file describing what is in the directory, but that you don't want to copy. Those files are simply ignored.
251
+ - the `.subst_ignore` file will define which files should be copied as-is and not processed as templates.
252
+ - later in the process files could be renamed (for example, by default `.erb` files see their `.erb` extension removed, but sometimes you may not want this to happen). The `.rename_ignore` file will define which files should not be renamed.
253
+
254
+ This feature is actually coming from the [dir_glob_ignore] Gem.
255
+
256
+ ## Application to our example
257
+
258
+ Let's come back to [our example](#basics), and create the relevant `.xxx_ignore` files.
259
+
260
+ First we don't want the `.ps_project/templates-templates/custom_buildable_entity/a_useless_text_file.txt` to be considered as a template. So let's create the `.ps_project/templates-templates/custom_buildable_entity/.subst_ignore` file with the following content:
261
+
262
+ ```ignore
263
+ # Ignore everything in this directory and sub folders
264
+ **
265
+ ```
266
+
267
+ But if we let things like that, the `.subst_ignore` would not be processed by the templating engine (because it matches `**` from a `Dir::glob` point of view), but would be copied. And we don't want that !
268
+ So let's create a `.ps_project/templates-templates/custom_buildable_entity/.copy_ignore` with the following content:
269
+
270
+ ```ignore
271
+ # This files should not be processed at all
272
+ .subst_ignore
273
+ .copy_ignore
274
+ ```
275
+
276
+ Et voilà, let's verify:
277
+
278
+ ```shell
279
+ $ power_stencil create custom_buildable_entity/test2
280
+ Created 'custom_buildable_entity/test2'
281
+
282
+ $ ls -la custom_buildable_entity/test2
283
+ total 12
284
+ drwxrwxr-x 2 laurent laurent 4096 août 26 18:37 .
285
+ drwxrwxr-x 4 laurent laurent 4096 août 26 18:37 ..
286
+ -rw-rw-r-- 1 laurent laurent 148 août 26 18:37 a_useless_text_file.txt
287
+
288
+ $ cat custom_buildable_entity/test2/a_useless_text_file.txt
289
+ This text has been generated on the <%= Time.now %>
290
+
291
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit,
292
+ sed do eiusmod tempor incididunt ....
293
+ ```
294
+ :+1: Success ! None of the `.xxx_ignore` files are in the resulting folder, and the `custom_buildable_entity/test2/a_useless_text_file.txt` has not been processed, ready for the [build process][builds]. We can verify this too:
295
+
296
+ ```shell
297
+ $ power_stencil build custom_buildable_entity/test2 -v
298
+ De-templating files for 'custom_buildable_entity/test2' into '/tmp/tst3/build/20190826-1842-27501-custom_buildable_entity_test2/custom_buildable_entity_test2'
299
+ Entities analysis completed.
300
+ - 'custom_buildable_entity/test2' has been correctly built
301
+
302
+ $ cat /tmp/tst3/build/20190826-1842-27501-custom_buildable_entity_test2/custom_buildable_entity_test2/a_useless_text_file.txt
303
+ This text has been generated on the 2019-08-26 18:42:27 +0200
304
+
305
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit,
306
+ sed do eiusmod tempor incididunt ....
307
+
308
+ ```
309
+ Flawless victory !!
310
+
311
+ [:back:][Documentation root]
312
+ <!-- End of Document -->
313
+
314
+ <!-- Pages -->
315
+ [Documentation root]: ../README.md "Back to documentation root"
316
+ [entities]: entities.md "Entities in PowerStencil"
317
+ [builds]: builds.md "Builds in PowerStencil"
318
+ [plugins]: plugins.md "Plugins in PowerStencil"
319
+ [example use cases]: example_use_cases.md "Example uses cases using PowerStencil"
320
+ [buildable]: entities.md#buildable--buildable_by "How to make an entity buildable ?"
321
+
322
+ <!-- Code links -->
323
+
324
+
325
+ <!-- Illustrations -->
326
+ [entity-creation-flow]: images/power-stencil-entity-creation.svg
327
+
328
+ <!-- External links -->
329
+ [ERB]: https://ruby-doc.org/stdlib-2.6.3/libdoc/erb/rdoc/ERB.html "Quick ERB description"
330
+ [Ruby On Rails]: https://rubyonrails.org/ "One of the best Web framework"
331
+ [Ruby]: https://www.ruby-lang.org "The powerful Ruby language"
332
+ [Dir::glob pattern]: https://ruby-doc.org/core-2.6.3/Dir.html#method-c-glob "Ruby documentation"
333
+ [dir_glob_ignore]: https://gitlab.com/lbriais/dir_glob_ignore "An extension to the Ruby `Dir::glob` feature"