generator-rails-angular-require

Fast way to integrate angular.js and require.js with Ruby on Rails project

Homepage

Module License: MIT

Added by: Sam Deering

GitHub

Repository

hung-phan/generator-rails-angular-require

Stats

Stars: 16

Watchers: 16

Forks: 1

Author

Hung Phan
Hung Phan

Module Description

generator-rails-angular-require

Yeoman generator

NPM

Getting Started

To run this version of yeoman generator. First, make sure that you have already installed yeoman

$ npm install -g yo

To install generator-rails-angular-require from npm, run:

$ npm install -g generator-rails-angular-require

To be able to support template preprocessor, make sure you install the right gem first:

$ gem install slim # for slim
$ gem install haml # for haml

Other dependencies

  1. SASS (gem install sass)

  2. Compass (gem install compass)

Usage for Rails 4.*

Firstly, create Ruby on Rails project with normal rails command, but skip it bundle:

$ rails new app-name --skip-bundle

Finally, initiate the generator:

$ cd app-name
$ yo rails-angular-require

Answer 'Yes' to all 'Overwrite' actions. Then config the 'config/database.yml' if you use different database than sqlite3.

Assets compile

Compile your assets before deploying to production server

$ rake assets:precompile RAILS_ENV=production

Options

Name: mongoid (for mongodb)

add --skip-active-record option to your rails new app --skip-active-record command before selecting this option.

Template

I define all the templates with suffix .tpl.* to load those into $templateCache, which make them testable with directives that rely on partial template. However, this is configurable by setting in lib/jasmine_rails/spec_helper.rb.

Task

Live reload

For using livereload utility, firstly, install guard. Then, use rack-livereload or install LiveReload Safari/Chrome extension

$ bundle exec guard # to run the guard server and enjoy coding

Testing

Run:

$ rails server

For unit testing, access localhost:3000/specs

For e2e testing, run:

$ protractor protractor.config.js

Subgenerators

This also supports for subgenerator for controller, filter, service, and directive as well. Make sure you link them in your main.js

$ yo rails-angular-require:controller "name" #replace the name with your module name
$ yo rails-angular-require:service "name" #replace the name with your module name
$ yo rails-angular-require:directive "name" #replace the name with your module name
$ yo rails-angular-require:filter "name" #replace the name with your module name

Structure

application/
  |- app/
  |  |- apis/
  |  |  |- v1/
  |  |  |  |- base.rb
  |  |  |  |- person_api.rb
  |  |  |- base.rb
  |  |- assets/
  |  |  |- images/
  |  |  |- javascripts/
  |  |  |  |- <codeModule>/
  |  |  |  |  |- codeModule.tpl.html # also support other templates like haml, and slim
  |  |  |  |  |- codeModule.js.coffee
  |  |  |  |- application.js
  |  |  |  |- main.js.coffee # main file
  |  |  |- stylesheets/
  |  |  |  |- application.css
  |  |- controllers/
  |  |- helpers/
  |  |- mailers/
  |  |- models/
  |  |- views/
  |  |  |- application/
  |  |  |  |- index.html # default template navigation by angular-ui-router
  |  |  |- layouts/
  |  |  |  |- jasmine_rails/
  |  |  |  |  |- spec_runner.html.erb # jasmine spec runner template
  |  |  |  |- application.html.erb
  |- bin/
  |- config/
  |  |- initializers/
  |  |  |- angular_template_assets.rb # Add template support
  |  |  |- bower_rails.rb # bower rails config
  |  |- requirejs.yml # requirejs config file
  |- db/
  |- lib/
  |  |- jasmine_rails/
  |  |  |- spec_helper.rb # jasmine rails helper
  |- log/
  |- public/
  |- spec/
  |  |- javascripts/
  |  |  |- helpers/
  |  |  |- e2espec/
  |  |  |  |- codeSpec.{js, coffee} # suffix by _e2espec.{js, coffee}
  |  |  |- spec/
  |  |  |  |- codeSpec.{js, coffee} # suffix by _unitspec.{js, coffee}
  |  |  |- support/
  |  |  |  |- jasmine.yml # jasmine config
  |- test/
  |- tmp/
  |- vendor/
  |  |- assets/
  |  |  |- bower_components/
  |  |  |  |- third libararies/
  |- |  |- bower.json
  |- Bowerfile # define all bower_components here
  |- config.ru
  |- Gemfile
  |- Gemfile.lock
  |- Guardfile # Guard file for livereload
  |- Rakefile
  |- README.rdoc

Contribution

All contributions are welcomed.

License

MIT License

Module stats last updated: 2017-02-12 16:00:05

Disclaimer: Some data on this page may have been gathered from the authors GitHub respository. If you see any mistakes or outdated information please let us know. Thanks!