From 9913ee3359fc44f3a686aa8ce9ab14b143b6084d Mon Sep 17 00:00:00 2001 From: Derek Kastner Date: Thu, 10 Nov 2011 13:44:04 -0500 Subject: [PATCH] Finish Node.js conversion --- Cakefile | 13 + Gemfile.lock | 238 +- .../controllers/hoot-bar-controller.js | 2 +- app/assets/javascripts/views/route-view.js | 10 +- app/views/home/index.html.erb | 2 +- package.json | 14 +- public/javascripts/application.js | 19945 ++++++++++++++++ .../controllers/index-controller.spec.js | 3 - spec/javascripts/helper.js | 28 - spec/javascripts/lib/spi.spec.js | 56 - spec/javascripts/views/route-view.spec.js | 43 - test/helper.js | 19 + .../helpers/google-maps.js | 0 test/lib/spi-test.js | 57 + test/views/route-view-test.js | 45 + 15 files changed, 20204 insertions(+), 271 deletions(-) create mode 100644 public/javascripts/application.js delete mode 100644 spec/javascripts/controllers/index-controller.spec.js delete mode 100644 spec/javascripts/helper.js delete mode 100644 spec/javascripts/lib/spi.spec.js delete mode 100644 spec/javascripts/views/route-view.spec.js create mode 100644 test/helper.js rename {spec/javascripts => test}/helpers/google-maps.js (100%) create mode 100644 test/lib/spi-test.js create mode 100644 test/views/route-view-test.js diff --git a/Cakefile b/Cakefile index 3ae519b..fa545d5 100644 --- a/Cakefile +++ b/Cakefile @@ -1,4 +1,5 @@ path = require 'path' +fs = require 'fs' rails_root = __dirname @@ -8,6 +9,18 @@ node_paths = [ path.resolve(rails_root, 'vendor', 'assets', 'javascripts') ].join(':') +task 'build', -> + console.log 'Browserifying...' + browserify = require 'dkastner-browserify' + b = browserify() + b.require('jquery-browserify') + b.require('dkastner-http-browserify') + b.alias('jquery', 'jquery-browserify') + b.alias('http', 'dkastner-http-browserify') + b.addEntry('app/assets/javascripts/application.js') + fs.writeFileSync('public/javascripts/application.js', b.bundle()) + console.log 'Done' + task 'examples', 'Run Jasmine examples', -> child = require 'child_process' child_env = process.env diff --git a/Gemfile.lock b/Gemfile.lock index f6e8291..da1e4c1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,160 +1,144 @@ GEM remote: http://rubygems.org/ specs: - aaronh-chronic (0.3.9) - abstract (1.0.0) - actionmailer (3.0.5) - actionpack (= 3.0.5) - mail (~> 2.2.15) - actionpack (3.0.5) - activemodel (= 3.0.5) - activesupport (= 3.0.5) - builder (~> 2.1.2) - erubis (~> 2.6.6) - i18n (~> 0.4) - rack (~> 1.2.1) - rack-mount (~> 0.6.13) - rack-test (~> 0.5.7) - tzinfo (~> 0.3.23) - activemodel (3.0.5) - activesupport (= 3.0.5) - builder (~> 2.1.2) - i18n (~> 0.4) - activerecord (3.0.5) - activemodel (= 3.0.5) - activesupport (= 3.0.5) - arel (~> 2.0.2) - tzinfo (~> 0.3.23) - activeresource (3.0.5) - activemodel (= 3.0.5) - activesupport (= 3.0.5) - activesupport (3.0.5) - arel (2.0.10) - bson_ext (1.3.1) - builder (2.1.2) - capybara (1.0.0.beta1) - mime-types (>= 1.16) - nokogiri (>= 1.3.3) - rack (>= 1.0.0) - rack-test (>= 0.5.4) - selenium-webdriver (>= 0.0.27) - xpath (~> 0.1.4) - childprocess (0.1.9) + actionmailer (3.1.0.rc8) + actionpack (= 3.1.0.rc8) + mail (~> 2.3.0) + actionpack (3.1.0.rc8) + activemodel (= 3.1.0.rc8) + activesupport (= 3.1.0.rc8) + builder (~> 3.0.0) + erubis (~> 2.7.0) + i18n (~> 0.6) + rack (~> 1.3.2) + rack-cache (~> 1.0.3) + rack-mount (~> 0.8.2) + rack-test (~> 0.6.1) + sprockets (~> 2.0.0.beta.15) + activemodel (3.1.0.rc8) + activesupport (= 3.1.0.rc8) + bcrypt-ruby (~> 3.0.0) + builder (~> 3.0.0) + i18n (~> 0.6) + activerecord (3.1.0.rc8) + activemodel (= 3.1.0.rc8) + activesupport (= 3.1.0.rc8) + arel (~> 2.2.1) + tzinfo (~> 0.3.29) + activeresource (3.1.0.rc8) + activemodel (= 3.1.0.rc8) + activesupport (= 3.1.0.rc8) + activesupport (3.1.0.rc8) + multi_json (~> 1.0) + ansi (1.4.0) + arel (2.2.1) + bcrypt-ruby (3.0.1) + builder (3.0.0) + childprocess (0.2.2) ffi (~> 1.0.6) - configuration (1.2.0) - crack (0.1.8) - cucumber (0.10.5) - builder (>= 2.1.2) - diff-lcs (>= 1.1.2) - gherkin (~> 2.4.0) - json (>= 1.4.6) - term-ansicolor (>= 1.0.5) - cucumber-rails (0.5.1) - capybara (>= 1.0.0.beta1) - cucumber (>= 0.10.3) - nokogiri (>= 1.4.4) - rack-test (>= 0.5.7) - diff-lcs (1.1.2) - erubis (2.6.6) - abstract (>= 1.0.0) - fakeweb (1.3.0) + diff-lcs (1.1.3) + erubis (2.7.0) + execjs (1.2.9) + multi_json (~> 1.0) ffi (1.0.9) - gherkin (2.4.0) - json (>= 1.4.6) - heroku (2.2.4) - launchy (>= 0.3.2) - rest-client (~> 1.6.1) - term-ansicolor (~> 1.0.5) + hike (1.2.1) hoptoad_notifier (2.4.11) activesupport builder - httparty (0.7.7) - crack (= 0.1.8) i18n (0.6.0) - jasmine (1.0.2.1) - json_pure (>= 1.4.3) + jasmine (1.1.2) + jasmine-core (>= 1.1.0) rack (>= 1.1) rspec (>= 1.3.1) selenium-webdriver (>= 0.1.3) - json (1.5.1) - json_pure (1.5.1) - launchy (0.4.0) - configuration (>= 0.0.5) - rake (>= 0.8.1) - mail (2.2.19) - activesupport (>= 2.3.6) + jasmine-core (1.1.0) + json (1.6.1) + json_pure (1.6.1) + mail (2.3.0) i18n (>= 0.4.0) mime-types (~> 1.16) treetop (~> 1.4.8) - mime-types (1.16) - nokogiri (1.4.4) - polyglot (0.3.1) - rack (1.2.3) - rack-mount (0.6.14) + mime-types (1.17.2) + multi_json (1.0.3) + nodeify (0.0.1) + execjs + rails (~> 3.1.0.rc8) + sandbox + sprockets + polyglot (0.3.3) + rack (1.3.5) + rack-cache (1.0.3) + rack (>= 0.4) + rack-mount (0.8.3) rack (>= 1.0.0) - rack-test (0.5.7) + rack-ssl (1.3.2) + rack + rack-test (0.6.1) rack (>= 1.0) - rails (3.0.5) - actionmailer (= 3.0.5) - actionpack (= 3.0.5) - activerecord (= 3.0.5) - activeresource (= 3.0.5) - activesupport (= 3.0.5) + rails (3.1.0.rc8) + actionmailer (= 3.1.0.rc8) + actionpack (= 3.1.0.rc8) + activerecord (= 3.1.0.rc8) + activeresource (= 3.1.0.rc8) + activesupport (= 3.1.0.rc8) bundler (~> 1.0) - railties (= 3.0.5) - railties (3.0.5) - actionpack (= 3.0.5) - activesupport (= 3.0.5) + railties (= 3.1.0.rc8) + railties (3.1.0.rc8) + actionpack (= 3.1.0.rc8) + activesupport (= 3.1.0.rc8) + rack-ssl (~> 1.3.2) rake (>= 0.8.7) - thor (~> 0.14.4) + rdoc (~> 3.4) + thor (~> 0.14.6) rake (0.9.2.2) - rest-client (1.6.3) - mime-types (>= 1.16) - rspec (2.6.0) - rspec-core (~> 2.6.0) - rspec-expectations (~> 2.6.0) - rspec-mocks (~> 2.6.0) - rspec-core (2.6.4) - rspec-expectations (2.6.0) + rdoc (3.11) + json (~> 1.4) + rspec (2.7.0) + rspec-core (~> 2.7.0) + rspec-expectations (~> 2.7.0) + rspec-mocks (~> 2.7.0) + rspec-core (2.7.1) + rspec-expectations (2.7.0) diff-lcs (~> 1.1.2) - rspec-mocks (2.6.0) - rspec-rails (2.6.1) - actionpack (~> 3.0) - activesupport (~> 3.0) - railties (~> 3.0) - rspec (~> 2.6.0) + rspec-mocks (2.7.0) rubyzip (0.9.4) - selenium-webdriver (0.2.1) - childprocess (>= 0.1.7) - ffi (>= 1.0.7) + sandbox (0.1.1) + sass (3.1.10) + sass-rails (3.1.0.rc.7) + actionpack (~> 3.1.0.rc6) + railties (~> 3.1.0.rc6) + sass (>= 3.1.4) + selenium-webdriver (2.10.0) + childprocess (>= 0.2.1) + ffi (= 1.0.9) json_pure rubyzip - term-ansicolor (1.0.5) + sprockets (2.0.3) + hike (~> 1.2) + rack (~> 1.0) + tilt (~> 1.1, != 1.3.0) + sqlite3 (1.3.4) thor (0.14.6) - timecop (0.3.5) - treetop (1.4.9) + tilt (1.3.3) + treetop (1.4.10) + polyglot polyglot (>= 0.3.1) - tzinfo (0.3.27) - watchr (0.7) - xpath (0.1.4) - nokogiri (~> 1.3) + turn (0.8.3) + ansi + tzinfo (0.3.31) + uglifier (1.0.4) + execjs (>= 0.3.0) + multi_json (>= 1.0.2) PLATFORMS ruby DEPENDENCIES - aaronh-chronic - bson_ext (>= 1.0.9) - capybara - cucumber - cucumber-rails - fakeweb - heroku hoptoad_notifier - httparty jasmine - rails (= 3.0.5) - rspec - rspec-rails - timecop - watchr + nodeify + rails (= 3.1.0.rc8) + sass-rails (~> 3.1.0.rc) + sqlite3 + turn + uglifier diff --git a/app/assets/javascripts/controllers/hoot-bar-controller.js b/app/assets/javascripts/controllers/hoot-bar-controller.js index 924e8e8..ec8fc2f 100644 --- a/app/assets/javascripts/controllers/hoot-bar-controller.js +++ b/app/assets/javascripts/controllers/hoot-bar-controller.js @@ -1,4 +1,4 @@ -var $ = require('jquery-browserify'); +var $ = require('jquery'); var HootBarController = module.exports = function(indexController) { this.indexController = indexController; diff --git a/app/assets/javascripts/views/route-view.js b/app/assets/javascripts/views/route-view.js index 65ffd9c..236620a 100644 --- a/app/assets/javascripts/views/route-view.js +++ b/app/assets/javascripts/views/route-view.js @@ -38,16 +38,16 @@ RouteView.prototype.toggleDirections = function() { $('#routing').toggle(); }; -RouteView.prototype.updateSegmentEmissions = function(emissionEstimate) { +RouteView.prototype.updateSegmentEmissions = function(impacts) { var output; - var value = NumberFormatter.kilogramsToPounds(emissionEstimate.value(), 4); - if(emissionEstimate.methodology) { - output = '' + value + ' lbs CO₂'; + var value = NumberFormatter.kilogramsToPounds(impacts.carbon, 4); + if(impacts.methodology) { + output = '' + value + ' lbs CO₂'; } else { output = value.toString() + ' lbs CO₂'; } - $('#' + this.mode + '_segment_' + emissionEstimate.emitter.index + ' span.emissions').html(output); + $('#' + this.mode + '_segment_' + impacts.subject.index + ' span.emissions').html(output); }; RouteView.prototype.updateTotalEmissions = function() { diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index 0464128..a962aaa 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -7,7 +7,7 @@ - <%= javascript_include_tag :application %> + <%= hoptoad_javascript_notifier %>