Skip to content

Commit 699c36e

Browse files
committed
Rewrite "usage" section in README to better meet the users’ needs
1 parent f112d35 commit 699c36e

File tree

2 files changed

+103
-74
lines changed

2 files changed

+103
-74
lines changed

README.md

+102-73
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@ Generating a Rails 5.1.4 app on Ruby 2.5.0.
44
<img src="katapult.png" width="200px" align="right" />
55

66

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)
99
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.
1514

1615

1716
## Prerequisites
@@ -23,77 +22,104 @@ Also, it drops the Rails asset pipeline in favor of *Webpacker*, so you'll need
2322
The required *Ruby* version is 2.5.0. You'll need the *Bundler* and *Rake* gems,
2423
which are probably already installed on your system.
2524

25+
When you're using the `katapult` binary (you should), you'll also need *Git*.
2626

27-
## Installation
2827

29-
Install the `katapult` gem with
28+
## Installation
3029

3130
gem install katapult
3231

33-
If you intend to extend an existing application, add it to the development group
34-
in your Gemfile.
35-
3632

3733
## Usage
3834

39-
Katapult does two distinct things for you:
35+
There are two usage scenarios for Katapult:
4036

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
4539

46-
You may use both or only one of them. Read on for details.
40+
Choose your use case and read on below.
4741

4842

49-
## 1) Creating a new Rails application
43+
## Starting a fresh Rails application
5044

51-
To get started, run the following command:
45+
To create a new Rails application with Katapult, run the following command:
5246

5347
katapult new $APPLICATION_NAME
5448

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).
5953

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.
6557

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.)
6764

68-
bin/rails generate katapult:basics
65+
When your application model and the templates are ready, let Katapult generate
66+
your code:
6967

68+
katapult fire
7069

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.
7273

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.
7676

77-
When your application model is ready, transform it using:
7877

79-
katapult fire [path/to/application_model]
78+
## Extending an existing Rails application
8079

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.
8481

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+
```
8986

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:
9388

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.
97123

98124
### Crud
99125
Shortcut for creating a model together with a WebUI with CRUD actions. The block
@@ -121,7 +147,7 @@ needed.
121147
# Default type :string
122148
model.attr :name
123149

124-
# Inferred type :email (when attr name matches /email/)
150+
# Inferred type :email (attribute name matches /email/)
125151
model.attr :email
126152

127153
# Inferred type :password. Password fields are rendered as password_field in
@@ -207,7 +233,7 @@ Rails, including Clearance mails like password reset requests.
207233
### Getting started
208234
`Katapult` is tested with [RSpec](http://rspec.info/) and
209235
[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/)).
211237

212238
For its full-stack integration tests, Katapult requires a PostgreSQL account.
213239
Create a dedicated account on your local PostgreSQL server:
@@ -228,22 +254,24 @@ included in the `katapult` gem.
228254

229255
The generators of Katapult extend the `rails/generators` you probably know
230256
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
232258
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
243271
representation, which will be turned into code by all the other generators.
244272

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.
247275

248276
### Suggested workflow
249277
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:
255283
1) **Start with a test:** Create a Cucumber scenario that creates and transforms
256284
an application model. Also, write a first draft of the code that generates
257285
what you expect.
258-
2) Run your scenario.
286+
2) Run your scenario. This will transform your test application model.
259287
3) Make a commit inside the generated test application, so you'll have a clean
260288
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`.
263292
5) **Finish your test:** Once you've figured how the generated code should look
264293
like, it's time to write steps that test it. For this purpose, tag your
265294
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:
269298
see your changes.
270299
6) **Write code:** When you've completed your scenario, write the code that
271300
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
273302
development server if you've started one.
274303
8) Run your scenario normally and iterate over your code generation code until
275304
your scenario is green.
@@ -280,19 +309,19 @@ Please respect the following guidelines during development:
280309
- The application model should be order-agnostic. There is a #prepare_render
281310
method in `ApplicationModel` for things that need to happen between parsing
282311
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.
285314

286315
### 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
288317
logged to your terminal. Note that each step will print all output to date, so
289318
you will see things multiple times.
290319

291320
To precisely debug errors occurring _inside_ the generated application, use
292321
`script/kta`. It is a helper script that will execute whatever command you pass
293322
it, but in the directory of the generated application. While you could cd to the
294323
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.
296325

297326
When fixing issues in the generated app, make a commit in the app first. When
298327
you've fixed it, the diff will show you what you need to port back to katapult.

Rakefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ task :update_readme do
1919

2020
readme = File.read readme_path
2121
readme.sub! /\A# Katapult.*\nGenerating.*\n/, '# ' + `bin/katapult version`
22-
readme.sub! /(required Ruby version is )[\d\.]+\d/, "\\1#{Katapult::RUBY_VERSION}"
22+
readme.sub! /(required .Ruby. version is )[\d\.]+\d/, "\\1#{Katapult::RUBY_VERSION}"
2323

2424
File.open readme_path, 'w' do |f|
2525
f.write readme

0 commit comments

Comments
 (0)