Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Rails AngularJS Bower Heroku

Rails AngularJS Bower Heroku

Presentation for the Vienna.rb Meetup on November 14th, 2013.

Hannes Stiebitzhofer

November 14, 2013
Tweet

More Decks by Hannes Stiebitzhofer

Other Decks in Programming

Transcript

  1. Front-end resources in Ruby Bundler aren’t cool //. Gemfile…. gem

    "angularjs-rails", "~> 1.0.8“ gem "jquery-rails", "~> 3.0.4“ ! Gems and required packages not up-to-date Version conflicts, headaches,…. Shouldn’t we separate package management for front-end and back-end?
  2. Bower.io „Bower is a package manager for the web. It

    offers a generic, unopinionated solution to the problem of front-end package management.“
  3. Using Bower is simple Part 1 Install NodeJS and npm

    package manager Installation Bower npm install -g bower Setup Bower // .bowerrc
 {
 "directory": "vendor/assets/components"
 }
  4. Using Bower is simple Part 2 Install Packages bower install

    angular
 bower install angular-resource Running bower init creates bower.json defining all packages similar 
 to Gemfile Or write bower.json yourself…
  5. Using Bower is simple Part 3 Configure Rails // ./config/application.rb

    config.assets.paths << Rails.root.join('vendor', 'assets', ‚components') ! // ./config/environments/production.rb config.assets.compile = true
  6. Custom Heroku buildpack for installation with Bower Heroku supports custom

    buildpacks to install whatever wanted (except Windows only stuff). Custom buildpack supporting Ruby and Node.js executes bower which processes bower.json. heroku config:set BUILDPACK_URL=‚git:// github.com/qnyp/heroku-buildpack-ruby- bower.git#run-bower' Finally deploy with git push [email protected]…. master
  7. Karma fills in the missing piece - testing JavaScript Spectacular

    Test Runner for JavaScript Supports test execution on real growers, phones and headless on PhantomJS. Testing framework agnostic - Jasmine, Mocha or QUnit Developed by Google AngularJS team
  8. Install Bower and Karma with npm //. package.json { "name":

    "rails-angular-bower-heroku", "version": "0.0.0", "devDependencies": { "bower": "~1.2.6", "karma": "~0.10.4", "karma-jasmine": "~0.1.3", "karma-chrome-launcher": "~0.1.0", "karma-phantomjs-launcher":"~0.1.0" } }
  9. Karma Runner needs all JavaScripts explicit module.exports = function(config) {

    config.set({ basePath: '', frameworks: ['jasmine'], files: [ 'vendor/assets/components/angular/angular.js', 'vendor/assets/components/angular-resource/ angular-resource.js', 'app/assets/javascripts/application.js', 'app/assets/javascripts/app.js', ‚app/assets/javascripts/**/*.js', ….
  10. Continuous integration with Codeship.io Setup commands rvm use 2.0.0 bundle

    install export RAILS_ENV=test bundle exec rake db:schema:load npm install bower install Test commands bundle exec rspec karma start --single-run
  11. Personal taste might matter more than benefits Separation of concerns

    and responsibilities Front-end packages maintained front-end developer Back-end packages maintained by back-end developer Reduce cost by automating whatever possible! Improve quality by automating whatever possible!