doc/templates.md in power_stencil-0.4.18 vs doc/templates.md in power_stencil-0.4.19

- old
+ new

@@ -144,12 +144,37 @@ - `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. - `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`). - `build_target` will return the entity that you are currently building. - `project_config` is a shortcut to the project entity. You could actually retrieve it using the `entity(:project_config, 'Project Config')` method. -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 ! +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 doing this during the process of detemplating could lead to strange behaviours ! +Nevertheless you can of course use entities data and methods within your templates. Any data can be directly accessed using [entity field] mechanism. But entities may bring as well methods you may want to use within your templates. How can we know what can be done with an entity **without reading the code** ? The answer is `power_stencil describe`... + +:information_source: If you do `power_stencil describe` on any entity type, you will get a comprehensive report of what you can do with this or this entity type (by default all entity types are displayed). + +Here is a (not so interesting) example: + +``` +$ power_stencil describe simple_exec +-------------------------------------------------------------------------------- +=> simple_exec (class: PowerStencil::SystemEntityDefinitions::SimpleExec) + - PARENT ENTITY TYPE: base_entity + - FIELDS: + - description + - post_process: + - has_one: process_descriptor + - not_null: true + - METHODS: + - delete + - valid? + - save +``` + +This should be self explanatory, there is another part that could be displayed in case you defined complex relation using the [reverse methods] mechanism... + + # Where do I create templates ? **When an entity is [buildable] you can find its templates in the `<entity_type>/<entity_name>` from the root of the project.** 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... @@ -322,10 +347,11 @@ [entities]: entities.md "Entities in PowerStencil" [builds]: builds.md "Builds in PowerStencil" [plugins]: plugins.md "Plugins in PowerStencil" [example use cases]: example_use_cases.md "Example uses cases using PowerStencil" [buildable]: entities.md#buildable-and-buildable_by "How to make an entity buildable ?" - +[entity field]: entities.md#field "How to access basic entity data" +[reverse methods]: entities.md#has_one "Check reverse methods" <!-- Code links --> <!-- Illustrations --> [entity-creation-flow]: images/power-stencil-entity-creation.svg \ No newline at end of file