Skip to content
Browse files

initial commit

  • Loading branch information...
0 parents commit 5f542adeb8666eef68d3206db0e4c2c81502bb9a James A. Rosen committed Sep 28, 2011
2 .gitignore
@@ -0,0 +1,2 @@
+lib/*.js
+spec/javascripts/*.js
4 Gemfile
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+gem 'jasmine-headless-webkit'
+gem 'jasmine'
49 Gemfile.lock
@@ -0,0 +1,49 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ childprocess (0.2.2)
+ ffi (~> 1.0.6)
+ coffee-script (2.2.0)
+ coffee-script-source
+ execjs
+ coffee-script-source (1.1.2)
+ diff-lcs (1.1.3)
+ execjs (1.2.4)
+ multi_json (~> 1.0)
+ ffi (1.0.9)
+ jasmine (1.0.2.1)
+ json_pure (>= 1.4.3)
+ rack (>= 1.1)
+ rspec (>= 1.3.1)
+ selenium-webdriver (>= 0.1.3)
+ jasmine-core (1.1.0.rc3)
+ jasmine-headless-webkit (0.6.3)
+ coffee-script (>= 2.2)
+ jasmine-core (~> 1.1.beta)
+ multi_json
+ rainbow
+ json_pure (1.5.3)
+ multi_json (1.0.3)
+ rack (1.3.2)
+ rainbow (1.1.1)
+ 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)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.6.0)
+ rubyzip (0.9.4)
+ selenium-webdriver (2.5.0)
+ childprocess (>= 0.2.1)
+ ffi (>= 1.0.7)
+ json_pure
+ rubyzip
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ jasmine
+ jasmine-headless-webkit
46 README.md
@@ -0,0 +1,46 @@
+## Sproutcore.I18n
+
+Internationalization for Sproutcore 2.0
+
+### Examples
+
+Given
+
+ I18n.translations = {
+ 'user.edit.title': 'Edit User',
+ 'user.followers.title': 'All {{count}} Followers',
+ 'button.add_user.title': 'Add a user',
+ 'button.add_user.text': 'Add'
+ };
+
+A simple translation:
+
+ <h2>{{t user.edit.title}}</h2>
+
+or perhaps
+
+ {{t user.edit.title tagName="h2"}}
+
+to avoid the inner `<span>`.
+
+A translation with an interpolation:
+
+ <h2>{{t user.followers.title count="2"}}</h2>
+
+A translation with a bound interpoloation:
+
+ <h2>{{t user.followers.title countBinding="user.followers.count"}}</h2>
+
+A translated attribute:
+
+ {{view SC.Button titleTranslation="button.add_user.title">
+ {{t button.add_user.text}}
+ </button>
+
+### Questions:
+
+ * What about an attribute with bound interpolations? Would that require a custom view class with an attribute bound to the translated string?
+ * How can we use `SC.Handlebars.compile` instead of `Handlebars.compile`? Trying the former yields an error on a missing `buffer`.
+ * Can we pull the required interpolations out of the template so we can set up bindings automatically in the current context?
+ * What about the case where you want the interpolation to be something generated by an `SC.View` or a helper?
+
79 Rakefile
@@ -0,0 +1,79 @@
+require 'bundler/setup'
+require 'pathname'
+Bundler.require
+project_dir = File.expand_path(File.dirname(__FILE__))
+
+def coffee(file)
+ `coffee -c #{file}`
+ puts "Compiled #{file}"
+end
+
+task :clean do
+ rm_f project_dir + '/lib/*.js'
+ rm_f project_dir + '/spec/javascripts/*.js'
+end
+
+task :compile do
+ coffee project_dir + '/lib/i18n.coffee'
+end
+
+namespace :spec do
+ task :compile do
+ coffee project_dir + '/spec/javascripts/i18nSpec.coffee'
+ end
+end
+
+namespace :jasmine do
+ task :require do
+ require 'jasmine'
+ end
+
+ desc "Run continuous integration tests"
+ task :ci => ["jasmine:require", 'spec:compile'] do
+ if Jasmine::rspec2?
+ require "rspec"
+ require "rspec/core/rake_task"
+ else
+ require "spec"
+ require 'spec/rake/spectask'
+ end
+
+ if Jasmine::rspec2?
+ RSpec::Core::RakeTask.new(:jasmine_continuous_integration_runner) do |t|
+ t.rspec_opts = ["--colour", "--format", "progress"]
+ t.verbose = true
+ t.pattern = ['spec/javascripts/support/jasmine_runner.rb']
+ end
+ else
+ Spec::Rake::SpecTask.new(:jasmine_continuous_integration_runner) do |t|
+ t.spec_opts = ["--color", "--format", "specdoc"]
+ t.verbose = true
+ t.spec_files = ['spec/javascripts/support/jasmine_runner.rb']
+ end
+ end
+ Rake::Task["jasmine_continuous_integration_runner"].invoke
+ end
+
+ task :server => "jasmine:require" do
+ jasmine_config_overrides = './spec/javascripts/support/jasmine_config.rb'
+ require jasmine_config_overrides if File.exist?(jasmine_config_overrides)
+
+ puts "your tests are here:"
+ puts " http://localhost:8888/"
+
+ Jasmine::Config.new.start_server
+ end
+end
+
+desc "Run specs via server"
+task :jasmine => ['spec:compile', 'jasmine:server']
+
+
+
+require 'jasmine/headless/task'
+
+Jasmine::Headless::Task.new('jasmine:headless') do |t|
+ t.colors = true
+end
+
+task :default => ['compile', 'spec:compile', 'jasmine:headless']
22 lib/i18n.coffee
@@ -0,0 +1,22 @@
+I18n = {
+ compile: Handlebars.compile
+
+ translations: {}
+
+ template: (key) ->
+ result = I18n.translations[key]
+ unless result
+ result = I18n.translations[key] = I18n.compile("Missing translation: " + key)
+ unless $.isFunction(result)
+ result = I18n.translations[key] = I18n.compile(result)
+ result
+
+ t: (key, context) ->
+ template = I18n.template(key)
+ return template(context)
+}
+
+SC.I18n = I18n
+
+Handlebars.registerHelper 't', (key, options) ->
+ # what goes here?
23 spec/javascripts/i18nSpec.coffee
@@ -0,0 +1,23 @@
+describe 'SC.I18n', ->
+
+ beforeEach ->
+ this.originalTranslations = SC.I18n.translations
+ SC.I18n.translations = {
+ 'foo.bar': 'A Foobar'
+ 'foo.count': 'All {{count}} Foos'
+ }
+
+ afterEach ->
+ SC.I18n.translations = this.originalTranslations
+
+ it 'should exist', ->
+ expect(SC.I18n).not.toBeUndefined()
+
+ it 'should translate simple strings', ->
+ expect(SC.I18n.t('foo.bar')).toEqual('A Foobar')
+
+ it 'should interpolate', ->
+ expect(SC.I18n.t('foo.count', {count: 12 })).toEqual('All 12 Foos')
+
+ it 'should warn about missing translations', ->
+ expect(SC.I18n.t('nothing.here')).toEqual('Missing translation: nothing.here')
77 spec/javascripts/support/jasmine.yml
@@ -0,0 +1,77 @@
+# src_files
+#
+# Return an array of filepaths relative to src_dir to include before jasmine specs.
+# Default: []
+#
+# EXAMPLE:
+#
+# src_files:
+# - lib/source1.js
+# - lib/source2.js
+# - dist/**/*.js
+#
+src_files:
+ - vendor/jquery-1.6.js
+ - vendor/sproutcore.js
+ - lib/i18n.js
+
+# stylesheets
+#
+# Return an array of stylesheet filepaths relative to src_dir to include before jasmine specs.
+# Default: []
+#
+# EXAMPLE:
+#
+# stylesheets:
+# - css/style.css
+# - stylesheets/*.css
+#
+stylesheets:
+
+# helpers
+#
+# Return an array of filepaths relative to spec_dir to include before jasmine specs.
+# Default: ["helpers/**/*.js"]
+#
+# EXAMPLE:
+#
+# helpers:
+# - helpers/**/*.js
+#
+helpers:
+ - helpers/**/*.js
+
+# spec_files
+#
+# Return an array of filepaths relative to spec_dir to include.
+# Default: ["**/*[sS]pec.js"]
+#
+# EXAMPLE:
+#
+# spec_files:
+# - **/*[sS]pec.js
+#
+spec_files:
+ - '**/*[sS]pec.js'
+
+# src_dir
+#
+# Source directory path. Your src_files must be returned relative to this path. Will use root if left blank.
+# Default: project root
+#
+# EXAMPLE:
+#
+# src_dir: public
+#
+src_dir:
+
+# spec_dir
+#
+# Spec directory path. Your spec_files must be returned relative to this path.
+# Default: spec/javascripts
+#
+# EXAMPLE:
+#
+# spec_dir: spec/javascripts
+#
+spec_dir: spec/javascripts
23 spec/javascripts/support/jasmine_config.rb
@@ -0,0 +1,23 @@
+module Jasmine
+ class Config
+
+ # Add your overrides or custom config code here
+
+ end
+end
+
+
+# Note - this is necessary for rspec2, which has removed the backtrace
+module Jasmine
+ class SpecBuilder
+ def declare_spec(parent, spec)
+ me = self
+ example_name = spec["name"]
+ @spec_ids << spec["id"]
+ backtrace = @example_locations[parent.description + " " + example_name]
+ parent.it example_name, {} do
+ me.report_spec(spec["id"])
+ end
+ end
+ end
+end
32 spec/javascripts/support/jasmine_runner.rb
@@ -0,0 +1,32 @@
+$:.unshift(ENV['JASMINE_GEM_PATH']) if ENV['JASMINE_GEM_PATH'] # for gem testing purposes
+
+require 'rubygems'
+require 'jasmine'
+jasmine_config_overrides = File.expand_path(File.join(File.dirname(__FILE__), 'jasmine_config.rb'))
+require jasmine_config_overrides if File.exist?(jasmine_config_overrides)
+if Jasmine::rspec2?
+ require 'rspec'
+else
+ require 'spec'
+end
+
+jasmine_config = Jasmine::Config.new
+spec_builder = Jasmine::SpecBuilder.new(jasmine_config)
+
+should_stop = false
+
+if Jasmine::rspec2?
+ RSpec.configuration.after(:suite) do
+ spec_builder.stop if should_stop
+ end
+else
+ Spec::Runner.configure do |config|
+ config.after(:suite) do
+ spec_builder.stop if should_stop
+ end
+ end
+end
+
+spec_builder.start
+should_stop = true
+spec_builder.declare_suites
8,865 vendor/jquery-1.6.js
8,865 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
13,866 vendor/sproutcore.js
13,866 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.

0 comments on commit 5f542ad

Please sign in to comment.
Something went wrong with that request. Please try again.