Add this line to your application's Gemfile:
gem 'trailblazer-generator', require: false
And then execute:
$ bundle
Or install it yourself as:
$ gem install trailblazer-generator
Available commands: cell
, contract
, finder
, operation
and activity
.
Concept name and class name are required and validated before going ahead with the generation.
Examples:
trailblazer g operation post create
-> will return an class_name errortrailblazer g operation Post Create
-> will create the fileapp/concepts/post/operation/create.rb
using thecreate
templatetrailblazer g operation Post Custom
-> will create the fileapp/concepts/post/operation/custom.rb
using thegeneric
template and showing a Notice message saying that template custom template is not found and a generic one is used
The cell
and cells
commands will create also the corrispective view file unless option --view
is set to none
.
Examples:
trailblazer g cell Post New
-> will create 2 filesapp/concepts/post/cell/new.rb
andapp/concepts/post/view/new.slim
trailblazer g cell Post New --view=none
-> will create 1 file onlyapp/concepts/post/cell/new.rb
Available commands: concept
, cells
and operations
Concept name is required and default arrays are used to generate the files
Example:
trailblazer g operations Post
-> will generateindex.rb
,create.rb
,show.rb
andupdate.rb
inapp/concepts/post/operation
plural
and singular
(default one) are the possible options
Examples:
trailblazer g operation Post Create --layout=singular
-> will create the fileapp/concepts/post/operation/create.rb
(which is the default)trailblazer g operation Post Create --layout=plural
-> will create the fileapp/concepts/post/operations/create.rb
allows to use a specific existing template
Examples:
trailblazer g operation Post Create --actiom=index
-> will create the fileapp/concepts/post/operation/create.rb
user theindex
template
If template is not found a Notice message saying that index template is not found and a generic one is used
allows to pass a custom folder as source where the template will be searched into
Requirements:
erb
file- expected stubs folder to have cell, contract, operation, view structure
allows to generate the view file with a template engine other than the default erb
, when passing --view=none
the view file will not be created
Examples:
trailblazer g cell Post Create --view=slim
-> will create 2 filesapp/concepts/post/cell/create.rb
andapp/concepts/post/view/create.slim
allows to specify a different destination folder for the generating file (available in all commands)
trailblazer g operation Post Create --path=custom_path
-> will create 1 filecustom_path/post/operation/create.rb
allows to add/remove the type (operation, contract,...) from the generate class namespace and the file destination path. It's a boolean option so:
--add_type_to_namespace
->true
--no-add_type_to_namespace
->false
Example:
trailblazer g operation Post Crete --no-add_type_to_namespace
-> will create an operation with namespacePost::Create
inapp/concepts/post/create.rb
allows to change the application folder
Example:
trailblazer g concept Post --app_dir=anything
-> will create aPost
concept inside anythinganything/concepts/post
allows to change the concepts folder
Example:
trailblazer g concept Post --concepts_folder=anything
-> will create aPost
concept inside using anything as concepts folderapp/anything/post
allows to select which strategy to use.
Supported strategies: path
, fast_track
and railway
Example:
trailblazer g activity Post Create --activity_strategy=railway
-> will create anActivity
inapp/concepts/activity/create.rb
addingextend Trailblazer::Activity::Railway()
It's possible to override the default options also using a trailblazer_generator.yml
file saved in the root path of your application.
Available keys:
view: slim
stubs: anything
add_type_to_namespace: false
app_folder: anything
concepts_folder: anything
activity_strategy: only_supported_ones (path, fast_track and railway)
file_list:
operation: [new, create]
cell: [custom, custom2]
contract: []
finder: []
view: []
activity: []
All the keys needs to be a string instead the nested keys under file_list
must be an array of string otherwise a warning message will be shown and the file will not be used.
The keys under file_list
are the default template used to create files and are also used to loop through to create multiple files, the cobination of stubs
and those keys will allow you to set up a new templates set.
This is a work in progress.
The main idea we want with generator in the end, is that it also generates what's inside your files for the most basic aspects, think of validations, etc.