Skip to content

Commit

Permalink
Merge pull request #161 from shakacode/andy/add-help-option-for-gener…
Browse files Browse the repository at this point in the history
…ator

add more detailed description when adding --help option to generator.
  • Loading branch information
justin808 committed Dec 23, 2015
2 parents 009db0d + aa60078 commit a9b7d47
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 23 deletions.
99 changes: 99 additions & 0 deletions lib/generators/USAGE
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
Description:

The react_on_rails:install generator combined with the example pull requests of
generator runs will get you up and running efficiently. There's a fair bit of
setup involved when ~with~ integrating Webpack with Rails. Defaults for options
are such that the default is for the flag to be off. For example, the default for
`-R` is that redux is off, and the default of -b means that skip-bootstrap is off.

* Redux

Passing the --redux generator option causes the generated Hello World example
to integrate the Redux state container framework. The necessary node modules
will be automatically included for you.

The generator uses the organizational `paradigm of "bundles"`. These are like
application domains and are used for grouping your code into webpack bundles
in case you decide to create different bundles for deployment. This is also
useful for separating out logical parts of your application. We recommend that
that each bundle will have it's own Redux store. If you have code that you
want to reuse across bundles, such as middleware or common utilities, place them
under `/client/app/lib`. You can then import them in your client code:
`import MyModule from 'lib/MyModule'`; since we have configured webpack to
automatically resolve the word lib to point to this folder.

* Using Images and Fonts

The generator has amended the folders created in `client/assets/` to Rails's
asset path. We recommend that if you have any existing assets that you want
to use with your client code, you should move them to these folders and use
webpack as normal. This allows webpack's development server to have access
to your assets, as it will not be able to see any assets in the default Rails
directories which are above the `/client` directory.

Alternatively, if you have many existing assets and don't wish to move them,
you could consider creating symlinks from `client/assets` that point to your
Rails assets folders inside of `app/assets/`. The assets there will then be
visible to both Rails and webpack.

* Bootstrap Integration

React on Rails ships with Twitter Bootstrap already integrated into the build.
Note that the generator removes require_tree in both the application.js and
application.css.scss files. This is to ensure the correct load order for the
bootstrap integration, and is usually a good idea in general. You will therefore
need to explicitly require your files.

How the Bootstrap library is loaded depends upon whether one is using the Rails
server or the HMR development server.

1. Bootstrap via Rails Server

The Rails server loads bootstrap-sprockets, provided
by the bootstrap-sass ruby gem (added automatically to your Gemfile by
the generator), via the `app/assets/stylesheets/_bootstrap-custom.scss`
partial.

This allows for using Bootstrap in your regular Rails stylesheets. If you
wish to customize any of the Bootstrap variables, you can do so via the
`client/assets/stylesheets/_pre-bootstrap.scss` partial.

2. Bootstrap via Webpack Dev Server

The webpack dev server does not go through Rails but instead loads bootstrap
via the `bootstrap-sass-loader` webpack loader. You can configure the loader
via the `client/bootstrap-sass-config.js` file.

3. Keeping Custom Bootstrap Configurations Synced

Because the webpack dev server and Rails each load Bootstrap via a different
file (explained in the two sections immediately above), any changes to
the way components are loaded in one file must also be made to the other
file in order to keep styling consistent between the two. For example,
if an import is excluded in _bootstrap-custom.scss, the same import should
be excluded in `bootstrap-sass-config.js` so that styling in the Rails
server and the webpack dev server will be the same.

4. Skip Bootstrap Integration

Bootstrap integration is enabled by default, but can be disabled by passing
the --skip-bootstrap flag (alias -b). When you don't need Bootstrap in your
existing project, just skip it as needed.

* JavaScript Linters

JavaScript linters are enabled by default, but can be disabled by passing the
--skip-js-linters flag (alias j), and those that run in Node have been add to
`client/package.json` under devDependencies.

* Ruby Linters

Ruby linters are disabled by default, but can be enabled by passing the
`--ruby-linters` flag when generating. These linters have been added to your
Gemfile in addition to the the appropriate Rake tasks.

We really love using all the linters! Give them a try.

More Details:

`https://github.com/shakacode/react_on_rails#generator`
16 changes: 9 additions & 7 deletions lib/generators/react_on_rails/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,44 @@
module ReactOnRails
module Generators
class InstallGenerator < Rails::Generators::Base
# fetch USAGE file for details generator description
source_root(File.expand_path("../", __FILE__))

# --redux
class_option :redux,
type: :boolean,
default: false,
desc: "Install Redux gems and Redux version of Hello World Example",
desc: "Install Redux gems and Redux version of Hello World Example. Default: false",
aliases: "-R"
# --server-rendering
class_option :server_rendering,
type: :boolean,
default: false,
desc: "Add necessary files and configurations for server-side rendering",
desc: "Add necessary files and configurations for server-side rendering. Default: false",
aliases: "-S"
# --skip-js-linters
class_option :skip_js_linters,
type: :boolean,
default: false,
desc: "Skip installing JavaScript linting files",
desc: "Skip installing JavaScript linting files. Default: false",
aliases: "-j"
# --ruby-linters
class_option :ruby_linters,
type: :boolean,
default: false,
desc: "Install ruby linting files, tasks, and configs",
desc: "Install ruby linting files, tasks, and configs. Default: false",
aliases: "-L"
# --ruby-linters
class_option :heroku_deployment,
type: :boolean,
default: false,
desc: "Install files necessary for deploying to Heroku",
desc: "Install files necessary for deploying to Heroku. Default: false",
aliases: "-H"

# --skip-bootstrap
class_option :skip_bootstrap,
type: :boolean,
default: false,
desc: "Skip integrating Bootstrap and don't initialize files and regarding configs",
desc: "Skip integrating Bootstrap and don't initialize files and regarding configs. Default: false",
aliases: "-b"

def run_generators # rubocop:disable Metrics/CyclomaticComplexity
Expand Down
34 changes: 18 additions & 16 deletions spec/dummy/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,24 @@ GEM
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
addressable (2.3.8)
addressable (2.4.0)
archive-zip (0.7.0)
io-like (~> 0.3.0)
arel (6.0.3)
ast (2.1.0)
astrolabe (1.3.1)
parser (~> 2.2)
autoprefixer-rails (6.1.0.1)
autoprefixer-rails (6.1.2)
execjs
json
awesome_print (1.6.1)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
bootstrap-sass (3.3.5.1)
autoprefixer-rails (>= 5.0.0.1)
sass (>= 3.3.0)
bootstrap-sass (3.3.6)
autoprefixer-rails (>= 5.2.1)
sass (>= 3.3.4)
builder (3.2.2)
byebug (8.2.0)
byebug (8.2.1)
capybara (2.5.0)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
Expand All @@ -84,11 +84,12 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.10.0)
concurrent-ruby (1.0.0)
connection_pool (2.2.0)
coveralls (0.8.9)
coveralls (0.8.10)
json (~> 1.8)
rest-client (>= 1.6.8, < 2)
simplecov (~> 0.10.0)
simplecov (~> 0.11.0)
term-ansicolor (~> 1.3)
thor (~> 0.19.1)
tins (~> 1.6.0)
Expand Down Expand Up @@ -127,12 +128,12 @@ GEM
mime-types (>= 1.16, < 3)
method_source (0.8.2)
mime-types (2.99)
mini_portile (0.6.2)
mini_portile2 (2.0.0)
minitest (5.8.3)
multi_json (1.11.2)
netrc (0.11.0)
nokogiri (1.6.6.4)
mini_portile (~> 0.6.0)
nokogiri (1.6.7)
mini_portile2 (~> 2.0.0.rc2)
parser (2.2.3.0)
ast (>= 1.1, < 3.0)
powerpack (0.1.1)
Expand Down Expand Up @@ -218,14 +219,14 @@ GEM
slop (~> 3.4, >= 3.4.7)
ruby-progressbar (1.7.5)
rubyzip (1.1.7)
sass (3.4.19)
sass (3.4.20)
sass-rails (5.0.4)
railties (>= 4.0.0, < 5.0)
sass (~> 3.1)
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)
scss_lint (0.43.0)
scss_lint (0.43.2)
rainbow (~> 2.0)
sass (~> 3.4.15)
sdoc (0.4.1)
Expand All @@ -236,14 +237,15 @@ GEM
multi_json (~> 1.0)
rubyzip (~> 1.0)
websocket (~> 1.0)
simplecov (0.10.0)
simplecov (0.11.1)
docile (~> 1.1.0)
json (~> 1.8)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.0)
slop (3.6.0)
spring (1.4.4)
sprockets (3.4.0)
spring (1.5.0)
sprockets (3.5.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (2.3.3)
actionpack (>= 3.0)
Expand Down

0 comments on commit a9b7d47

Please sign in to comment.