@@ -4,14 +4,13 @@ Generating a Rails 5.1.4 app on Ruby 2.5.0.
4
4
<img src =" katapult.png " width =" 200px " align =" right " />
5
5
6
6
7
- Katapult is a kickstart generator for Rails applications . It creates new Rails
8
- applications with [ lots of pre-configuration] ( https://github.com/makandra/katapult/blob/master/lib/generators/katapult/basics/basics_generator.rb )
7
+ Katapult is a kickstart generator for Rails. It prepares a new
8
+ application with [ lots of pre-configuration] ( https://github.com/makandra/katapult/blob/master/lib/generators/katapult/basics/basics_generator.rb )
9
9
and offers [ makandra-flavored] ( https://leanpub.com/growing-rails ) code
10
- generation from an application model. These two features significally speed up
11
- the initial phase of a Rails project by doing in minutes what otherwise would
12
- cost you weeks.
13
- After modeling your application, which takes about an hour, you can instantly
14
- start implementing the meat of your application.
10
+ generation from an application model. This significantly speeds up the initial
11
+ phase of Rails development by doing in minutes what would cost you weeks. When
12
+ Katapult has finished, you can instantly start implementing the interesting
13
+ parts of your application.
15
14
16
15
17
16
## Prerequisites
@@ -23,77 +22,104 @@ Also, it drops the Rails asset pipeline in favor of *Webpacker*, so you'll need
23
22
The required * Ruby* version is 2.5.0. You'll need the * Bundler* and * Rake* gems,
24
23
which are probably already installed on your system.
25
24
25
+ When you're using the ` katapult ` binary (you should), you'll also need * Git* .
26
26
27
- ## Installation
28
27
29
- Install the ` katapult ` gem with
28
+ ## Installation
30
29
31
30
gem install katapult
32
31
33
- If you intend to extend an existing application, add it to the development group
34
- in your Gemfile.
35
-
36
32
37
33
## Usage
38
34
39
- Katapult does two distinct things for you :
35
+ There are two usage scenarios for Katapult :
40
36
41
- 1 . It creates a new Rails application, prepared with gems, snippets,
42
- configuration, databases, testing libraries etc.
43
- 2 . It generates code from an application model, i.e. it generates models and
44
- views, controllers, styles etc.
37
+ 1 . Starting a fresh Rails application
38
+ 2 . Extending an existing Rails application
45
39
46
- You may use both or only one of them. Read on for details .
40
+ Choose your use case and read on below .
47
41
48
42
49
- ## 1) Creating a new Rails application
43
+ ## Starting a fresh Rails application
50
44
51
- To get started , run the following command:
45
+ To create a new Rails application with Katapult , run the following command:
52
46
53
47
katapult new $APPLICATION_NAME
54
48
55
- This will create a new Rails application and prepare it in more than 20 steps.
56
- Read the [ BasicsGenerator ] ( https://github.com/makandra/katapult/blob/master/lib/generators/katapult/basics/basics_generator.rb )
57
- for details: Its methods are executed one-by-one, while the method names are a
58
- description of what they do .
49
+ This will create a new Rails application, prepared and configured: bundled,
50
+ database set up, RSpec, Cucumber and Capistrano installed and much more.
51
+ Please read the [ BasicsGenerator ] ( https://github.com/makandra/katapult/blob/master/lib/generators/katapult/basics/basics_generator.rb )
52
+ for details (its methods are executed one-by-one from top to bottom) .
59
53
60
- #### Alternative: Using Katapult in an existing Rails application
61
- Katapult generates a fresh application. If you have an existing Rails
62
- application, you * may* use Katapult to configure it.
63
- Be warned: it is not designed to respect existing files, although it will usually
64
- ask before overwriting something.
54
+ When Katapult is done, you will find a default application model in
55
+ ` lib/katapult/application_model.rb ` . It contains a full example of Katapult's
56
+ DSL that you can use as an inspiration for creating your own application model.
65
57
66
- After adding it to the Gemfile, invoke the basics generator manually:
58
+ Next, check the templates in ` lib/templates/katapult ` . They will be used
59
+ to generate the corresponding files, e.g. HAML views. Please modify the templates
60
+ to match your requirements. (Actually, you can customize much more templates.
61
+ Each template in Katapult's ` lib/generators/katapult/<generator>/templates/ ` can
62
+ be overridden with a file at ` lib/templates/katapult/<generator>/ ` in your
63
+ application.)
67
64
68
- bin/rails generate katapult:basics
65
+ When your application model and the templates are ready, let Katapult generate
66
+ your code:
69
67
68
+ katapult fire
70
69
71
- ## 2) Generating code from an application model
70
+ This will create models, migrations, views, styles, controllers, routes,
71
+ Cucumber features, specs, factories and more. It will also commit the results
72
+ and migrate the database.
72
73
73
- After running ` katapult new ` , you will find a default application model in
74
- ` lib/katapult/application_model.rb ` . It contains a full example of Katapult's
75
- features that you can use as an inspiration for creating _ your_ application model.
74
+ When this is done, your application is ready to use! Start a development
75
+ server and try it out.
76
76
77
- When your application model is ready, transform it using:
78
77
79
- katapult fire [path/to/application_model]
78
+ ## Extending an existing Rails application
80
79
81
- The path is optional and defaults to the generated application model. If you
82
- later want to extend your application, you may create a second application model
83
- and invoke ` katapult fire ` with its path.
80
+ You can use Katapult for code generation in an existing application as well.
84
81
85
- Below you find an overview of the application model DSL. The respective sections
86
- hold examples of what options are available to each element. For details, dive
87
- into ` lib/generators/katapult ` where all generators are stored. The method names
88
- of a generator tell what it does.
82
+ First, add Katapult to the development group in your Gemfile:
83
+ ```
84
+ gem 'katapult'
85
+ ```
89
86
90
- ### Generic DSL syntax example
91
- The DSL consists of _ elements_ , e.g. ` Model ` or ` WebUI ` . Each Katapult element
92
- has the following syntax, taking a name, options, and a block:
87
+ Next, generate the default application model:
93
88
94
- element_type 'name', options: 'example' do |element|
95
- element.some_method
96
- end
89
+ ```
90
+ bundle exec rails generate katapult:app_model
91
+ ```
92
+
93
+ You'll find the application model at ` lib/katapult/application_model.rb ` . It
94
+ contains a full example of Katapult's features: Use it as an inspiration for
95
+ modeling your own application. (When you're used to the application model DSL,
96
+ you don't need to generate the default model. Just create a Ruby file and start
97
+ modeling.)
98
+
99
+ Next, copy Katapult's template files to your application:
100
+
101
+ ```
102
+ katapult templates
103
+ ```
104
+
105
+ This will copy some of Katapult's file templates to ` lib/templates/katapult ` .
106
+ Modify them, especially the view templates, to match the current state of your
107
+ application. You can customize even more templates, see the "Starting …" section
108
+ above.
109
+
110
+ When model and templates are ready, trigger code generation with:
111
+
112
+ ```
113
+ katapult fire path/to/your_model.rb
114
+ ```
115
+
116
+
117
+ ## DSL reference
118
+
119
+ Below you find an overview of the application model DSL. The respective sections
120
+ hold examples of what options are available to each element. For details, dive
121
+ into the respective generator at ` lib/generators/katapult/*/*_generator.rb ` . The
122
+ method names of a generator tell what it does.
97
123
98
124
### Crud
99
125
Shortcut for creating a model together with a WebUI with CRUD actions. The block
@@ -121,7 +147,7 @@ needed.
121
147
# Default type :string
122
148
model.attr :name
123
149
124
- # Inferred type :email (when attr name matches /email/)
150
+ # Inferred type :email (attribute name matches /email/)
125
151
model.attr :email
126
152
127
153
# Inferred type :password. Password fields are rendered as password_field in
@@ -207,7 +233,7 @@ Rails, including Clearance mails like password reset requests.
207
233
### Getting started
208
234
` Katapult ` is tested with [ RSpec] ( http://rspec.info/ ) and
209
235
[ Cucumber] ( https://cucumber.io/ ) + [ Aruba] ( https://github.com/cucumber/aruba )
210
- ([ API-Doc ] ( http://www.rubydoc.info/github/cucumber/aruba/master/ ) ).
236
+ ([ API documentation ] ( http://www.rubydoc.info/github/cucumber/aruba/master/ ) ).
211
237
212
238
For its full-stack integration tests, Katapult requires a PostgreSQL account.
213
239
Create a dedicated account on your local PostgreSQL server:
@@ -228,22 +254,24 @@ included in the `katapult` gem.
228
254
229
255
The generators of Katapult extend the ` rails/generators ` you probably know
230
256
from generating migration files or scaffolds. However, Katapult lifts them on a
231
- new level by invoking them programmatically with a model object instead
257
+ higher level by passing them a model object instead
232
258
of plain text arguments. This way, the Katapult generators can explore the whole
233
- application model and are not restricted to a few string's they've been given.
234
-
235
- There are three Rails generators that are intended for invocation from bash.
236
- They can be considered the next-lower level API of Katapult:
237
-
238
- - ` katapult:basics ` generator: Enhances a pristine Rails app with all of the basic
239
- configuration Katapult brings.
240
- - ` katapult:app_model ` generator: Installs a boilerplate application model that serves as
241
- a starting point for modeling your own application.
242
- - ` katapult:transform ` generator: Parses the application model into an internal
259
+ application model and are not restricted to a few strings they've been given.
260
+
261
+ There are a few "public" Rails generators. They can be considered the next API
262
+ level after the ` katapult ` binary:
263
+
264
+ - ` katapult:basics ` : Enhances a pristine Rails app with all of the
265
+ basic configuration.
266
+ - ` katapult:app_model ` : Installs a boilerplate application model that
267
+ serves as a starting point for modeling an application.
268
+ - ` katapult:templates ` : Copies some generator templates to the target
269
+ application.
270
+ - ` katapult:transform ` : Parses the application model into an internal
243
271
representation, which will be turned into code by all the other generators.
244
272
245
- Note that the ` katapult ` binary is the only Rails-independent part of Katapult;
246
- everything else runs in the context of the Rails application.
273
+ Note that the ` katapult ` binary is the only Rails-independent part of Katapult.
274
+ Everything else runs in the context of the Rails application.
247
275
248
276
### Suggested workflow
249
277
When adding a feature to Katapult, it will usually take you some time to
@@ -255,11 +283,12 @@ Here's a process for building larger code generation features:
255
283
1 ) ** Start with a test:** Create a Cucumber scenario that creates and transforms
256
284
an application model. Also, write a first draft of the code that generates
257
285
what you expect.
258
- 2 ) Run your scenario.
286
+ 2 ) Run your scenario. This will transform your test application model.
259
287
3 ) Make a commit inside the generated test application, so you'll have a clean
260
288
working directory: ` script/kta git add --all && script/kta git commit -m 'x' `
261
- 4 ) ** Tune the generated code to meet your expectations.** Boot a development
262
- server with ` script/kta rails s ` if you like.
289
+ 4 ) ** Modify the generated code** inside the generated test application until it
290
+ meets your expectations. If you like, boot a development server with
291
+ ` script/kta rails s ` .
263
292
5 ) ** Finish your test:** Once you've figured how the generated code should look
264
293
like, it's time to write steps that test it. For this purpose, tag your
265
294
scenario with @no-clobber and comment out the model transformation step. This
@@ -269,7 +298,7 @@ Here's a process for building larger code generation features:
269
298
see your changes.
270
299
6 ) ** Write code:** When you've completed your scenario, write the code that
271
300
generates what is needed to satisfy the test.
272
- 7 ) Remove the @no-clobber tag and comment in the transformation step. Stop the
301
+ 7 ) Remove the @no-clobber tag and uncomment the transformation step. Stop the
273
302
development server if you've started one.
274
303
8 ) Run your scenario normally and iterate over your code generation code until
275
304
your scenario is green.
@@ -280,19 +309,19 @@ Please respect the following guidelines during development:
280
309
- The application model should be order-agnostic. There is a #prepare_render
281
310
method in ` ApplicationModel ` for things that need to happen between parsing
282
311
and rendering the application model.
283
- - The application model should be idempotent, meaning it should be possible to
284
- generate it over and over again without breaking code .
312
+ - Transformation should be idempotent: it should be possible to generate the
313
+ application model over and over again without crashing or breaking things .
285
314
286
315
### Debugging
287
- Add the ` @announce-output ` tag to Katapult features in order to have any output
316
+ Add the ` @announce-output ` tag to Katapult scenarios in order to have output
288
317
logged to your terminal. Note that each step will print all output to date, so
289
318
you will see things multiple times.
290
319
291
320
To precisely debug errors occurring _ inside_ the generated application, use
292
321
` script/kta ` . It is a helper script that will execute whatever command you pass
293
322
it, but in the directory of the generated application. While you could cd to the
294
323
test app and run your command there, you'd need to ` cd ../../aruba/katapult_test_app `
295
- after each test run , because the tmp/aruba directory gets wiped before each test.
324
+ between test runs , because the tmp/aruba directory gets wiped before each test.
296
325
297
326
When fixing issues in the generated app, make a commit in the app first. When
298
327
you've fixed it, the diff will show you what you need to port back to katapult.
0 commit comments