diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6e26397 --- /dev/null +++ b/.gitignore @@ -0,0 +1,20 @@ +# See https://help.github.com/articles/ignoring-files for more about ignoring files. +# +# If you find yourself ignoring temporary files generated by your text editor +# or operating system, you probably want to add a global ignore instead: +# git config --global core.excludesfile '~/.gitignore_global' + +# Ignore bundler config. +/.bundle + +# Ignore the default SQLite database. +/db/*.sqlite3 +/db/*.sqlite3-journal + +# Ignore all logfiles and tempfiles. +/log/*.log +/tmp + +.DS_Store +public/assets +my-lineman-app/node_modules diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..3e8ce32 --- /dev/null +++ b/Gemfile @@ -0,0 +1,47 @@ +source 'https://rubygems.org' + +# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' +gem 'rails', '4.0.2' + +# Use sqlite3 as the database for Active Record +gem 'sqlite3' + +# Use SCSS for stylesheets +gem 'sass-rails', '~> 4.0.0' + +# Use Uglifier as compressor for JavaScript assets +gem 'uglifier', '>= 1.3.0' + +# Use CoffeeScript for .js.coffee assets and views +gem 'coffee-rails', '~> 4.0.0' + +# See https://github.com/sstephenson/execjs#readme for more supported runtimes +# gem 'therubyracer', platforms: :ruby + +# Use jquery as the JavaScript library +gem 'jquery-rails' + +# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks +gem 'turbolinks' + +# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder +gem 'jbuilder', '~> 1.2' + +group :doc do + # bundle exec rake doc:rails generates the API under doc/api. + gem 'sdoc', require: false +end + +# Use ActiveModel has_secure_password +# gem 'bcrypt-ruby', '~> 3.1.2' + +# Use unicorn as the app server +# gem 'unicorn' + +# Use Capistrano for deployment +# gem 'capistrano', group: :development + +# Use debugger +# gem 'debugger', group: [:development, :test] + +gem 'rails-lineman' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..c9273f0 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,122 @@ +GEM + remote: https://rubygems.org/ + specs: + actionmailer (4.0.2) + actionpack (= 4.0.2) + mail (~> 2.5.4) + actionpack (4.0.2) + activesupport (= 4.0.2) + builder (~> 3.1.0) + erubis (~> 2.7.0) + rack (~> 1.5.2) + rack-test (~> 0.6.2) + activemodel (4.0.2) + activesupport (= 4.0.2) + builder (~> 3.1.0) + activerecord (4.0.2) + activemodel (= 4.0.2) + activerecord-deprecated_finders (~> 1.0.2) + activesupport (= 4.0.2) + arel (~> 4.0.0) + activerecord-deprecated_finders (1.0.3) + activesupport (4.0.2) + i18n (~> 0.6, >= 0.6.4) + minitest (~> 4.2) + multi_json (~> 1.3) + thread_safe (~> 0.1) + tzinfo (~> 0.3.37) + arel (4.0.1) + atomic (1.1.14) + builder (3.1.4) + coffee-rails (4.0.1) + coffee-script (>= 2.2.0) + railties (>= 4.0.0, < 5.0) + coffee-script (2.2.0) + coffee-script-source + execjs + coffee-script-source (1.6.3) + erubis (2.7.0) + execjs (2.0.2) + hike (1.2.3) + i18n (0.6.9) + jbuilder (1.5.3) + activesupport (>= 3.0.0) + multi_json (>= 1.2.0) + jquery-rails (3.0.4) + railties (>= 3.0, < 5.0) + thor (>= 0.14, < 2.0) + json (1.8.1) + mail (2.5.4) + mime-types (~> 1.16) + treetop (~> 1.4.8) + mime-types (1.25.1) + minitest (4.7.5) + multi_json (1.8.2) + polyglot (0.3.3) + rack (1.5.2) + rack-test (0.6.2) + rack (>= 1.0) + rails (4.0.2) + actionmailer (= 4.0.2) + actionpack (= 4.0.2) + activerecord (= 4.0.2) + activesupport (= 4.0.2) + bundler (>= 1.3.0, < 2.0) + railties (= 4.0.2) + sprockets-rails (~> 2.0.0) + rails-lineman (0.0.1) + rake + railties (4.0.2) + actionpack (= 4.0.2) + activesupport (= 4.0.2) + rake (>= 0.8.7) + thor (>= 0.18.1, < 2.0) + rake (10.1.0) + rdoc (3.12.2) + json (~> 1.4) + sass (3.2.12) + sass-rails (4.0.1) + railties (>= 4.0.0, < 5.0) + sass (>= 3.1.10) + sprockets-rails (~> 2.0.0) + sdoc (0.3.20) + json (>= 1.1.3) + rdoc (~> 3.10) + sprockets (2.10.1) + hike (~> 1.2) + multi_json (~> 1.0) + rack (~> 1.0) + tilt (~> 1.1, != 1.3.0) + sprockets-rails (2.0.1) + actionpack (>= 3.0) + activesupport (>= 3.0) + sprockets (~> 2.8) + sqlite3 (1.3.8) + thor (0.18.1) + thread_safe (0.1.3) + atomic + tilt (1.4.1) + treetop (1.4.15) + polyglot + polyglot (>= 0.3.1) + turbolinks (2.1.0) + coffee-rails + tzinfo (0.3.38) + uglifier (2.3.3) + execjs (>= 0.3.0) + json (>= 1.8.0) + +PLATFORMS + ruby + +DEPENDENCIES + coffee-rails (~> 4.0.0) + jbuilder (~> 1.2) + jquery-rails + rails (= 4.0.2) + rails-lineman + sass-rails (~> 4.0.0) + sdoc + sqlite3 + turbolinks + uglifier (>= 1.3.0) diff --git a/README.rdoc b/README.rdoc new file mode 100644 index 0000000..dd4e97e --- /dev/null +++ b/README.rdoc @@ -0,0 +1,28 @@ +== README + +This README would normally document whatever steps are necessary to get the +application up and running. + +Things you may want to cover: + +* Ruby version + +* System dependencies + +* Configuration + +* Database creation + +* Database initialization + +* How to run the test suite + +* Services (job queues, cache servers, search engines, etc.) + +* Deployment instructions + +* ... + + +Please feel free to use a different markup language if you do not plan to run +rake doc:app. diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..74b4f43 --- /dev/null +++ b/Rakefile @@ -0,0 +1,6 @@ +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. + +require File.expand_path('../config/application', __FILE__) + +MyRailsApp::Application.load_tasks diff --git a/app/assets/images/.keep b/app/assets/images/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js new file mode 100644 index 0000000..d6925fa --- /dev/null +++ b/app/assets/javascripts/application.js @@ -0,0 +1,16 @@ +// This is a manifest file that'll be compiled into application.js, which will include all the files +// listed below. +// +// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, +// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. +// +// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the +// compiled file. +// +// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details +// about supported directives. +// +//= require jquery +//= require jquery_ujs +//= require turbolinks +//= require_tree . diff --git a/app/assets/javascripts/foo.coffee b/app/assets/javascripts/foo.coffee new file mode 100644 index 0000000..e69de29 diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css new file mode 100644 index 0000000..3192ec8 --- /dev/null +++ b/app/assets/stylesheets/application.css @@ -0,0 +1,13 @@ +/* + * This is a manifest file that'll be compiled into application.css, which will include all the files + * listed below. + * + * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, + * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. + * + * You're free to add application-wide styles to this file and they'll appear at the top of the + * compiled file, but it's generally better to create a new file per style scope. + * + *= require_self + *= require_tree . + */ diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb new file mode 100644 index 0000000..d83690e --- /dev/null +++ b/app/controllers/application_controller.rb @@ -0,0 +1,5 @@ +class ApplicationController < ActionController::Base + # Prevent CSRF attacks by raising an exception. + # For APIs, you may want to use :null_session instead. + protect_from_forgery with: :exception +end diff --git a/app/controllers/concerns/.keep b/app/controllers/concerns/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/controllers/widgets_controller.rb b/app/controllers/widgets_controller.rb new file mode 100644 index 0000000..828fee3 --- /dev/null +++ b/app/controllers/widgets_controller.rb @@ -0,0 +1,5 @@ +class WidgetsController < ApplicationController + def index + + end +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb new file mode 100644 index 0000000..de6be79 --- /dev/null +++ b/app/helpers/application_helper.rb @@ -0,0 +1,2 @@ +module ApplicationHelper +end diff --git a/app/mailers/.keep b/app/mailers/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/models/.keep b/app/models/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/models/concerns/.keep b/app/models/concerns/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb new file mode 100644 index 0000000..6c9c1cf --- /dev/null +++ b/app/views/layouts/application.html.erb @@ -0,0 +1,14 @@ + + + + MyRailsApp + <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %> + <%= javascript_include_tag "application", "data-turbolinks-track" => true %> + <%= csrf_meta_tags %> + + + +<%= yield %> + + + diff --git a/app/views/widgets/index.html.erb b/app/views/widgets/index.html.erb new file mode 100644 index 0000000..ce97fb6 --- /dev/null +++ b/app/views/widgets/index.html.erb @@ -0,0 +1,2 @@ +<%= stylesheet_link_tag "lineman/app" %> +<%= javascript_include_tag "lineman/app" %> diff --git a/bin/bundle b/bin/bundle new file mode 100755 index 0000000..66e9889 --- /dev/null +++ b/bin/bundle @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +load Gem.bin_path('bundler', 'bundle') diff --git a/bin/rails b/bin/rails new file mode 100755 index 0000000..728cd85 --- /dev/null +++ b/bin/rails @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +APP_PATH = File.expand_path('../../config/application', __FILE__) +require_relative '../config/boot' +require 'rails/commands' diff --git a/bin/rake b/bin/rake new file mode 100755 index 0000000..1724048 --- /dev/null +++ b/bin/rake @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +require_relative '../config/boot' +require 'rake' +Rake.application.run diff --git a/config.ru b/config.ru new file mode 100644 index 0000000..5bc2a61 --- /dev/null +++ b/config.ru @@ -0,0 +1,4 @@ +# This file is used by Rack-based servers to start the application. + +require ::File.expand_path('../config/environment', __FILE__) +run Rails.application diff --git a/config/application.rb b/config/application.rb new file mode 100644 index 0000000..79e9d76 --- /dev/null +++ b/config/application.rb @@ -0,0 +1,25 @@ +require File.expand_path('../boot', __FILE__) + +require 'rails/all' + +# Require the gems listed in Gemfile, including any gems +# you've limited to :test, :development, or :production. +Bundler.require(:default, Rails.env) + +module MyRailsApp + class Application < Rails::Application + # Settings in config/environments/* take precedence over those specified here. + # Application configuration should go into files in config/initializers + # -- all .rb files in that directory are automatically loaded. + + # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. + # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. + # config.time_zone = 'Central Time (US & Canada)' + + # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. + # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] + # config.i18n.default_locale = :de + + config.rails_lineman.lineman_project_location = "my-lineman-app" + end +end diff --git a/config/boot.rb b/config/boot.rb new file mode 100644 index 0000000..3596736 --- /dev/null +++ b/config/boot.rb @@ -0,0 +1,4 @@ +# Set up gems listed in the Gemfile. +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) + +require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) diff --git a/config/database.yml b/config/database.yml new file mode 100644 index 0000000..51a4dd4 --- /dev/null +++ b/config/database.yml @@ -0,0 +1,25 @@ +# SQLite version 3.x +# gem install sqlite3 +# +# Ensure the SQLite 3 gem is defined in your Gemfile +# gem 'sqlite3' +development: + adapter: sqlite3 + database: db/development.sqlite3 + pool: 5 + timeout: 5000 + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: + adapter: sqlite3 + database: db/test.sqlite3 + pool: 5 + timeout: 5000 + +production: + adapter: sqlite3 + database: db/production.sqlite3 + pool: 5 + timeout: 5000 diff --git a/config/environment.rb b/config/environment.rb new file mode 100644 index 0000000..13f18cc --- /dev/null +++ b/config/environment.rb @@ -0,0 +1,5 @@ +# Load the Rails application. +require File.expand_path('../application', __FILE__) + +# Initialize the Rails application. +MyRailsApp::Application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb new file mode 100644 index 0000000..fda9235 --- /dev/null +++ b/config/environments/development.rb @@ -0,0 +1,29 @@ +MyRailsApp::Application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # In the development environment your application's code is reloaded on + # every request. This slows down response time but is perfect for development + # since you don't have to restart the web server when you make code changes. + config.cache_classes = false + + # Do not eager load code on boot. + config.eager_load = false + + # Show full error reports and disable caching. + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # Don't care if the mailer can't send. + config.action_mailer.raise_delivery_errors = false + + # Print deprecation notices to the Rails logger. + config.active_support.deprecation = :log + + # Raise an error on page load if there are pending migrations + config.active_record.migration_error = :page_load + + # Debug mode disables concatenation and preprocessing of assets. + # This option may cause significant delays in view rendering with a large + # number of complex assets. + config.assets.debug = true +end diff --git a/config/environments/production.rb b/config/environments/production.rb new file mode 100644 index 0000000..3e47af9 --- /dev/null +++ b/config/environments/production.rb @@ -0,0 +1,80 @@ +MyRailsApp::Application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # Code is not reloaded between requests. + config.cache_classes = true + + # Eager load code on boot. This eager loads most of Rails and + # your application in memory, allowing both thread web servers + # and those relying on copy on write to perform better. + # Rake tasks automatically ignore this option for performance. + config.eager_load = true + + # Full error reports are disabled and caching is turned on. + config.consider_all_requests_local = false + config.action_controller.perform_caching = true + + # Enable Rack::Cache to put a simple HTTP cache in front of your application + # Add `rack-cache` to your Gemfile before enabling this. + # For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid. + # config.action_dispatch.rack_cache = true + + # Disable Rails's static asset server (Apache or nginx will already do this). + config.serve_static_assets = false + + # Compress JavaScripts and CSS. + config.assets.js_compressor = :uglifier + # config.assets.css_compressor = :sass + + # Do not fallback to assets pipeline if a precompiled asset is missed. + config.assets.compile = false + + # Generate digests for assets URLs. + config.assets.digest = true + + # Version of your assets, change this if you want to expire all your assets. + config.assets.version = '1.0' + + # Specifies the header that your server uses for sending files. + # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache + # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + # config.force_ssl = true + + # Set to :debug to see everything in the log. + config.log_level = :info + + # Prepend all log lines with the following tags. + # config.log_tags = [ :subdomain, :uuid ] + + # Use a different logger for distributed setups. + # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) + + # Use a different cache store in production. + # config.cache_store = :mem_cache_store + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.action_controller.asset_host = "http://assets.example.com" + + # Precompile additional assets. + # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. + # config.assets.precompile += %w( search.js ) + + # Ignore bad email addresses and do not raise email delivery errors. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. + # config.action_mailer.raise_delivery_errors = false + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation can not be found). + config.i18n.fallbacks = true + + # Send deprecation notices to registered listeners. + config.active_support.deprecation = :notify + + # Disable automatic flushing of the log to improve performance. + # config.autoflush_log = false + + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = ::Logger::Formatter.new +end diff --git a/config/environments/test.rb b/config/environments/test.rb new file mode 100644 index 0000000..3fd15e6 --- /dev/null +++ b/config/environments/test.rb @@ -0,0 +1,36 @@ +MyRailsApp::Application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # The test environment is used exclusively to run your application's + # test suite. You never need to work with it otherwise. Remember that + # your test database is "scratch space" for the test suite and is wiped + # and recreated between test runs. Don't rely on the data there! + config.cache_classes = true + + # Do not eager load code on boot. This avoids loading your whole application + # just for the purpose of running a single test. If you are using a tool that + # preloads Rails for running tests, you may have to set it to true. + config.eager_load = false + + # Configure static asset server for tests with Cache-Control for performance. + config.serve_static_assets = true + config.static_cache_control = "public, max-age=3600" + + # Show full error reports and disable caching. + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # Raise exceptions instead of rendering exception templates. + config.action_dispatch.show_exceptions = false + + # Disable request forgery protection in test environment. + config.action_controller.allow_forgery_protection = false + + # Tell Action Mailer not to deliver emails to the real world. + # The :test delivery method accumulates sent emails in the + # ActionMailer::Base.deliveries array. + config.action_mailer.delivery_method = :test + + # Print deprecation notices to the stderr. + config.active_support.deprecation = :stderr +end diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb new file mode 100644 index 0000000..59385cd --- /dev/null +++ b/config/initializers/backtrace_silencers.rb @@ -0,0 +1,7 @@ +# Be sure to restart your server when you modify this file. + +# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. +# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } + +# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. +# Rails.backtrace_cleaner.remove_silencers! diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb new file mode 100644 index 0000000..4a994e1 --- /dev/null +++ b/config/initializers/filter_parameter_logging.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Configure sensitive parameters which will be filtered from the log file. +Rails.application.config.filter_parameters += [:password] diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb new file mode 100644 index 0000000..ac033bf --- /dev/null +++ b/config/initializers/inflections.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Add new inflection rules using the following format. Inflections +# are locale specific, and you may define rules for as many different +# locales as you wish. All of these examples are active by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.plural /^(ox)$/i, '\1en' +# inflect.singular /^(ox)en/i, '\1' +# inflect.irregular 'person', 'people' +# inflect.uncountable %w( fish sheep ) +# end + +# These inflection rules are supported but not enabled by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.acronym 'RESTful' +# end diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb new file mode 100644 index 0000000..72aca7e --- /dev/null +++ b/config/initializers/mime_types.rb @@ -0,0 +1,5 @@ +# Be sure to restart your server when you modify this file. + +# Add new mime types for use in respond_to blocks: +# Mime::Type.register "text/richtext", :rtf +# Mime::Type.register_alias "text/html", :iphone diff --git a/config/initializers/secret_token.rb b/config/initializers/secret_token.rb new file mode 100644 index 0000000..c4d2e4c --- /dev/null +++ b/config/initializers/secret_token.rb @@ -0,0 +1,12 @@ +# Be sure to restart your server when you modify this file. + +# Your secret key is used for verifying the integrity of signed cookies. +# If you change this key, all old signed cookies will become invalid! + +# Make sure the secret is at least 30 characters and all random, +# no regular words or you'll be exposed to dictionary attacks. +# You can use `rake secret` to generate a secure secret key. + +# Make sure your secret_key_base is kept private +# if you're sharing your code publicly. +MyRailsApp::Application.config.secret_key_base = 'bbf070848331db5b55c94452483b7ae361b7ddf72f124251bdb1a26c22a9122bd5f0777df19eff403908a101ffc45e957e330e16d6e08bcab8ba3799f3392968' diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb new file mode 100644 index 0000000..efb086f --- /dev/null +++ b/config/initializers/session_store.rb @@ -0,0 +1,3 @@ +# Be sure to restart your server when you modify this file. + +MyRailsApp::Application.config.session_store :cookie_store, key: '_my-rails-app_session' diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb new file mode 100644 index 0000000..33725e9 --- /dev/null +++ b/config/initializers/wrap_parameters.rb @@ -0,0 +1,14 @@ +# Be sure to restart your server when you modify this file. + +# This file contains settings for ActionController::ParamsWrapper which +# is enabled by default. + +# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. +ActiveSupport.on_load(:action_controller) do + wrap_parameters format: [:json] if respond_to?(:wrap_parameters) +end + +# To enable root element in JSON for ActiveRecord objects. +# ActiveSupport.on_load(:active_record) do +# self.include_root_in_json = true +# end diff --git a/config/locales/en.yml b/config/locales/en.yml new file mode 100644 index 0000000..0653957 --- /dev/null +++ b/config/locales/en.yml @@ -0,0 +1,23 @@ +# Files in the config/locales directory are used for internationalization +# and are automatically loaded by Rails. If you want to use locales other +# than English, add the necessary files in this directory. +# +# To use the locales, use `I18n.t`: +# +# I18n.t 'hello' +# +# In views, this is aliased to just `t`: +# +# <%= t('hello') %> +# +# To use a different locale, set it with `I18n.locale`: +# +# I18n.locale = :es +# +# This would use the information in config/locales/es.yml. +# +# To learn more, please read the Rails Internationalization guide +# available at http://guides.rubyonrails.org/i18n.html. + +en: + hello: "Hello world" diff --git a/config/routes.rb b/config/routes.rb new file mode 100644 index 0000000..f9cf8ff --- /dev/null +++ b/config/routes.rb @@ -0,0 +1,58 @@ +MyRailsApp::Application.routes.draw do + # The priority is based upon order of creation: first created -> highest priority. + # See how all your routes lay out with "rake routes". + + # You can have the root of your site routed with "root" + # root 'welcome#index' + + # Example of regular route: + # get 'products/:id' => 'catalog#view' + + # Example of named route that can be invoked with purchase_url(id: product.id) + # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase + + # Example resource route (maps HTTP verbs to controller actions automatically): + # resources :products + + # Example resource route with options: + # resources :products do + # member do + # get 'short' + # post 'toggle' + # end + # + # collection do + # get 'sold' + # end + # end + + # Example resource route with sub-resources: + # resources :products do + # resources :comments, :sales + # resource :seller + # end + + # Example resource route with more complex sub-resources: + # resources :products do + # resources :comments + # resources :sales do + # get 'recent', on: :collection + # end + # end + + resources :widgets + + # Example resource route with concerns: + # concern :toggleable do + # post 'toggle' + # end + # resources :posts, concerns: :toggleable + # resources :photos, concerns: :toggleable + + # Example resource route within a namespace: + # namespace :admin do + # # Directs /admin/products/* to Admin::ProductsController + # # (app/controllers/admin/products_controller.rb) + # resources :products + # end +end diff --git a/db/seeds.rb b/db/seeds.rb new file mode 100644 index 0000000..4edb1e8 --- /dev/null +++ b/db/seeds.rb @@ -0,0 +1,7 @@ +# This file should contain all the record creation needed to seed the database with its default values. +# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). +# +# Examples: +# +# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) +# Mayor.create(name: 'Emanuel', city: cities.first) diff --git a/lib/assets/.keep b/lib/assets/.keep new file mode 100644 index 0000000..e69de29 diff --git a/lib/tasks/.keep b/lib/tasks/.keep new file mode 100644 index 0000000..e69de29 diff --git a/log/.keep b/log/.keep new file mode 100644 index 0000000..e69de29 diff --git a/my-lineman-app/.gitignore b/my-lineman-app/.gitignore new file mode 100644 index 0000000..50fd534 --- /dev/null +++ b/my-lineman-app/.gitignore @@ -0,0 +1,11 @@ +.DS_Store + +#ignore node_modules, as the node project is not "deployed" per se: http://www.mikealrogers.com/posts/nodemodules-in-git.html +/node_modules/* + +/dist +/generated + +.sass-cache + +!/node_modules/lineman-rails diff --git a/my-lineman-app/.npmignore b/my-lineman-app/.npmignore new file mode 100644 index 0000000..275ec00 --- /dev/null +++ b/my-lineman-app/.npmignore @@ -0,0 +1,9 @@ +.DS_Store + +#ignore node_modules, as the node project is not "deployed" per se: http://www.mikealrogers.com/posts/nodemodules-in-git.html +/node_modules + +/dist +/generated + +.sass-cache diff --git a/my-lineman-app/.travis.yml b/my-lineman-app/.travis.yml new file mode 100644 index 0000000..53ce7b2 --- /dev/null +++ b/my-lineman-app/.travis.yml @@ -0,0 +1,4 @@ +language: node_js +node_js: +- 0.10 +script: "lineman spec-ci" diff --git a/my-lineman-app/Gruntfile.js b/my-lineman-app/Gruntfile.js new file mode 100644 index 0000000..ed05645 --- /dev/null +++ b/my-lineman-app/Gruntfile.js @@ -0,0 +1,4 @@ +/*global module:false*/ +module.exports = function(grunt) { + require('./config/lineman').config.grunt.run(grunt); +}; diff --git a/my-lineman-app/README.md b/my-lineman-app/README.md new file mode 100644 index 0000000..debad91 --- /dev/null +++ b/my-lineman-app/README.md @@ -0,0 +1 @@ +# My Lineman Application \ No newline at end of file diff --git a/my-lineman-app/app/css/style.less b/my-lineman-app/app/css/style.less new file mode 100644 index 0000000..00b04ec --- /dev/null +++ b/my-lineman-app/app/css/style.less @@ -0,0 +1,7 @@ +@darkGray: #dedede; +@lightGray: #efefef; + +.hello { + background-color: @lightGray; + border: 1px solid @darkGray; +} \ No newline at end of file diff --git a/my-lineman-app/app/img/.gitkeep b/my-lineman-app/app/img/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/my-lineman-app/app/js/.gitkeep b/my-lineman-app/app/js/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/my-lineman-app/app/js/hello.coffee b/my-lineman-app/app/js/hello.coffee new file mode 100644 index 0000000..dc91fd2 --- /dev/null +++ b/my-lineman-app/app/js/hello.coffee @@ -0,0 +1,10 @@ +window.helloText = -> 'Hello, World!' + +window.hello = -> + html = JST['app/templates/hello.us'](text: helloText()) + document.body.innerHTML += html + +if window.addEventListener + window.addEventListener('DOMContentLoaded', hello, false) +else + window.attachEvent('onload', hello) \ No newline at end of file diff --git a/my-lineman-app/app/pages/index.us b/my-lineman-app/app/pages/index.us new file mode 100644 index 0000000..ee2bc1d --- /dev/null +++ b/my-lineman-app/app/pages/index.us @@ -0,0 +1,11 @@ + + + + <%= pkg.name %> + + + + + + + diff --git a/my-lineman-app/app/static/favicon.ico b/my-lineman-app/app/static/favicon.ico new file mode 100644 index 0000000..70de606 Binary files /dev/null and b/my-lineman-app/app/static/favicon.ico differ diff --git a/my-lineman-app/app/templates/hello.us b/my-lineman-app/app/templates/hello.us new file mode 100644 index 0000000..b17f363 --- /dev/null +++ b/my-lineman-app/app/templates/hello.us @@ -0,0 +1,3 @@ +
+ <%= text %> +
\ No newline at end of file diff --git a/my-lineman-app/config/application.js b/my-lineman-app/config/application.js new file mode 100644 index 0000000..6efc2ba --- /dev/null +++ b/my-lineman-app/config/application.js @@ -0,0 +1,50 @@ +/* Exports a function which returns an object that overrides the default & + * plugin grunt configuration object. + * + * You can familiarize yourself with Lineman's defaults by checking out: + * + * - https://github.com/testdouble/lineman/blob/master/config/application.coffee + * - https://github.com/testdouble/lineman/blob/master/config/plugins + * + * You can also ask Lineman's about config from the command line: + * + * $ lineman config #=> to print the entire config + * $ lineman config concat.js #=> to see the JS config for the concat task. + */ +module.exports = function(lineman) { + //Override application configuration here. Common examples follow in the comments. + return { + + // API Proxying + // + // During development, you'll likely want to make XHR (AJAX) requests to an API on the same + // port as your lineman development server. By enabling the API proxy and setting the port, all + // requests for paths that don't match a static asset in ./generated will be forwarded to + // whatever service might be running on the specified port. + // + // server: { + // apiProxy: { + // enabled: true, + // host: 'localhost', + // port: 3000 + // } + // } + + // Sass + // + // Lineman supports Sass via grunt-contrib-sass, which requires you first + // have Ruby installed as well as the `sass` gem. To enable it, comment out the + // following line: + // + // enableSass: false + + // Asset Fingerprints + // + // Lineman can fingerprint your static assets by appending a hash to the filename + // and logging a manifest of logical-to-hashed filenames in dist/assets.json + // via grunt-asset-fingerprint + // + // enableAssetFingerprint: false + + }; +}; diff --git a/my-lineman-app/config/files.js b/my-lineman-app/config/files.js new file mode 100644 index 0000000..0aeb48e --- /dev/null +++ b/my-lineman-app/config/files.js @@ -0,0 +1,23 @@ +/* Exports a function which returns an object that overrides the default & + * plugin file patterns (used widely through the app configuration) + * + * To see the default definitions for Lineman's file paths and globs, see: + * + * - https://github.com/testdouble/lineman/blob/master/config/files.coffee + */ +module.exports = function(lineman) { + //Override file patterns here + return { + + // As an example, to override the file patterns for + // the order in which to load third party JS libs: + // + // js: { + // vendor: [ + // "vendor/js/underscore.js", + // "vendor/js/**/*.js" + // ] + // } + + }; +}; diff --git a/my-lineman-app/config/lineman.js b/my-lineman-app/config/lineman.js new file mode 100644 index 0000000..0ce0689 --- /dev/null +++ b/my-lineman-app/config/lineman.js @@ -0,0 +1 @@ +module.exports = require(process.env['LINEMAN_MAIN']); diff --git a/my-lineman-app/config/server.js b/my-lineman-app/config/server.js new file mode 100644 index 0000000..1654dc1 --- /dev/null +++ b/my-lineman-app/config/server.js @@ -0,0 +1,21 @@ +/* Define custom server-side HTTP routes for lineman's development server + * These might be as simple as stubbing a little JSON to + * facilitate development of code that interacts with an HTTP service + * (presumably, mirroring one that will be reachable in a live environment). + * + * It's important to remember that any custom endpoints defined here + * will only be available in development, as lineman only builds + * static assets, it can't run server-side code. + * + * This file can be very useful for rapid prototyping or even organically + * defining a spec based on the needs of the client code that emerge. + * + */ + +module.exports = { + drawRoutes: function(app) { + // app.get('/api/greeting/:message', function(req, res){ + // res.json({ message: "OK, "+req.params.message }); + // }); + } +}; \ No newline at end of file diff --git a/my-lineman-app/config/spec.json b/my-lineman-app/config/spec.json new file mode 100644 index 0000000..b6258d5 --- /dev/null +++ b/my-lineman-app/config/spec.json @@ -0,0 +1,9 @@ +{ + "framework" : "jasmine", + "launch_in_dev" : ["Chrome"], + "launch_in_ci" : ["PhantomJS"], + "src_files" : [ + "generated/js/app.js", + "generated/js/spec.js" + ] +} \ No newline at end of file diff --git a/my-lineman-app/package.json b/my-lineman-app/package.json new file mode 100644 index 0000000..765fe1d --- /dev/null +++ b/my-lineman-app/package.json @@ -0,0 +1,18 @@ +{ + "name": "my-lineman-app", + "title": "An HTML/JS/CSS app", + "version": "0.0.1", + "private": true, + "author": { + "name": "John Doe", + "company": "ACME, Inc." + }, + "devDependencies": { + "lineman": "~0.21.2", + "lineman-rails": "~0.0.1" + }, + "scripts": { + "start": "lineman run", + "test": "lineman spec-ci" + } +} diff --git a/my-lineman-app/spec/hello-spec.coffee b/my-lineman-app/spec/hello-spec.coffee new file mode 100644 index 0000000..a371a11 --- /dev/null +++ b/my-lineman-app/spec/hello-spec.coffee @@ -0,0 +1,3 @@ +describe ".helloText", -> + When -> @result = helloText() + Then -> expect(@result).toEqual("Hello, World!") \ No newline at end of file diff --git a/my-lineman-app/spec/helpers/helper.js b/my-lineman-app/spec/helpers/helper.js new file mode 100644 index 0000000..c863cd3 --- /dev/null +++ b/my-lineman-app/spec/helpers/helper.js @@ -0,0 +1,4 @@ +var root = this; + +root.context = root.describe; +root.xcontext = root.xdescribe; \ No newline at end of file diff --git a/my-lineman-app/spec/helpers/jasmine-fixture.js b/my-lineman-app/spec/helpers/jasmine-fixture.js new file mode 100644 index 0000000..30f56dc --- /dev/null +++ b/my-lineman-app/spec/helpers/jasmine-fixture.js @@ -0,0 +1,491 @@ + +/* +jasmine-fixture 1.0.5 +Makes injecting HTML snippets into the DOM easy & clean! +site: https://github.com/searls/jasmine-fixture +*/ + + +(function() { + var createHTMLBlock; + + (function($) { + var jasmineFixture, originalAffix, originalInject, originalJasmineFixture, root, _; + root = this; + originalJasmineFixture = root.jasmineFixture; + originalInject = root.inject; + originalAffix = root.affix; + _ = function(list) { + return { + inject: function(iterator, memo) { + var item, _i, _len, _results; + _results = []; + for (_i = 0, _len = list.length; _i < _len; _i++) { + item = list[_i]; + _results.push(memo = iterator(memo, item)); + } + return _results; + } + }; + }; + root.jasmineFixture = function($) { + var $whatsTheRootOf, applyAttributes, defaultConfiguration, defaults, init, injectContents, isReady, isString, itLooksLikeHtml, rootId, tidyUp; + $.fn.affix = root.affix = function(selectorOptions) { + var $top; + $top = null; + _(selectorOptions.split(/[ ](?=[^\]]*?(?:\[|$))/)).inject(function($parent, elementSelector) { + var $el; + if (elementSelector === ">") { + return $parent; + } + $el = createHTMLBlock($, elementSelector).appendTo($parent); + $top || ($top = $el); + return $el; + }, $whatsTheRootOf(this)); + return $top; + }; + $whatsTheRootOf = function(that) { + if (that.jquery != null) { + return that; + } else if ($('#jasmine_content').length > 0) { + return $('#jasmine_content'); + } else { + return $('
').appendTo('body'); + } + }; + afterEach(function() { + return $('#jasmine_content').remove(); + }); + isReady = false; + rootId = "specContainer"; + defaultConfiguration = { + el: "div", + cssClass: "", + id: "", + text: "", + html: "", + defaultAttribute: "class", + attrs: {} + }; + defaults = $.extend({}, defaultConfiguration); + $.jasmine = { + inject: function(arg, context) { + var $toInject, config, parent; + if (isReady !== true) { + init(); + } + parent = (context ? context : $("#" + rootId)); + $toInject = void 0; + if (itLooksLikeHtml(arg)) { + $toInject = $(arg); + } else { + config = $.extend({}, defaults, arg, { + userString: arg + }); + $toInject = $("<" + config.el + ">"); + applyAttributes($toInject, config); + injectContents($toInject, config); + } + return $toInject.appendTo(parent); + }, + configure: function(config) { + return $.extend(defaults, config); + }, + restoreDefaults: function() { + return defaults = $.extend({}, defaultConfiguration); + }, + noConflict: function() { + root.jasmineFixture = originalJasmineFixture; + root.inject = originalInject; + root.affix = originalAffix; + return this; + } + }; + $.fn.inject = function(html) { + return $.jasmine.inject(html, $(this)); + }; + applyAttributes = function($html, config) { + var attrs, key, _results; + attrs = $.extend({}, { + id: config.id, + "class": config["class"] || config.cssClass + }, config.attrs); + if (isString(config.userString)) { + attrs[config.defaultAttribute] = config.userString; + } + _results = []; + for (key in attrs) { + if (attrs[key]) { + _results.push($html.attr(key, attrs[key])); + } else { + _results.push(void 0); + } + } + return _results; + }; + injectContents = function($el, config) { + if (config.text && config.html) { + throw "Error: because they conflict, you may only configure inject() to set `html` or `text`, not both! \n\nHTML was: " + config.html + " \n\n Text was: " + config.text; + } else if (config.text) { + return $el.text(config.text); + } else { + if (config.html) { + return $el.html(config.html); + } + } + }; + itLooksLikeHtml = function(arg) { + return isString(arg) && arg.indexOf("<") !== -1; + }; + isString = function(arg) { + return arg && arg.constructor === String; + }; + init = function() { + $("body").append("
"); + return isReady = true; + }; + tidyUp = function() { + $("#" + rootId).remove(); + return isReady = false; + }; + $(function($) { + return init(); + }); + afterEach(function() { + return tidyUp(); + }); + return $.jasmine; + }; + if ($) { + jasmineFixture = root.jasmineFixture($); + return root.inject = root.inject || jasmineFixture.inject; + } + })(window.jQuery); + + createHTMLBlock = (function() { + var bindData, bindEvents, parseAttributes, parseClasses, parseContents, parseEnclosure, parseReferences, parseVariableScope, regAttr, regAttrDfn, regAttrs, regCBrace, regClass, regClasses, regData, regDatas, regEvent, regEvents, regExclamation, regId, regReference, regTag, regTagNotContent, regZenTagDfn; + createHTMLBlock = function($, ZenObject, data, functions, indexes) { + var ZenCode, arr, block, blockAttrs, blockClasses, blockHTML, blockId, blockTag, blocks, el, el2, els, forScope, indexName, inner, len, obj, origZenCode, paren, result, ret, zc, zo; + if ($.isPlainObject(ZenObject)) { + ZenCode = ZenObject.main; + } else { + ZenCode = ZenObject; + ZenObject = { + main: ZenCode + }; + } + origZenCode = ZenCode; + if (indexes === undefined) { + indexes = {}; + } + if (ZenCode.charAt(0) === "!" || $.isArray(data)) { + if ($.isArray(data)) { + forScope = ZenCode; + } else { + obj = parseEnclosure(ZenCode, "!"); + obj = obj.substring(obj.indexOf(":") + 1, obj.length - 1); + forScope = parseVariableScope(ZenCode); + } + while (forScope.charAt(0) === "@") { + forScope = parseVariableScope("!for:!" + parseReferences(forScope, ZenObject)); + } + zo = ZenObject; + zo.main = forScope; + el = $(); + if (ZenCode.substring(0, 5) === "!for:" || $.isArray(data)) { + if (!$.isArray(data) && obj.indexOf(":") > 0) { + indexName = obj.substring(0, obj.indexOf(":")); + obj = obj.substr(obj.indexOf(":") + 1); + } + arr = ($.isArray(data) ? data : data[obj]); + zc = zo.main; + if ($.isArray(arr) || $.isPlainObject(arr)) { + $.map(arr, function(value, index) { + var next; + zo.main = zc; + if (indexName !== undefined) { + indexes[indexName] = index; + } + if (!$.isPlainObject(value)) { + value = { + value: value + }; + } + next = createHTMLBlock($, zo, value, functions, indexes); + if (el.length !== 0) { + return $.each(next, function(index, value) { + return el.push(value); + }); + } + }); + } + if (!$.isArray(data)) { + ZenCode = ZenCode.substr(obj.length + 6 + forScope.length); + } else { + ZenCode = ""; + } + } else if (ZenCode.substring(0, 4) === "!if:") { + result = parseContents("!" + obj + "!", data, indexes); + if (result !== "undefined" || result !== "false" || result !== "") { + el = createHTMLBlock($, zo, data, functions, indexes); + } + ZenCode = ZenCode.substr(obj.length + 5 + forScope.length); + } + ZenObject.main = ZenCode; + } else if (ZenCode.charAt(0) === "(") { + paren = parseEnclosure(ZenCode, "(", ")"); + inner = paren.substring(1, paren.length - 1); + ZenCode = ZenCode.substr(paren.length); + zo = ZenObject; + zo.main = inner; + el = createHTMLBlock($, zo, data, functions, indexes); + } else { + blocks = ZenCode.match(regZenTagDfn); + block = blocks[0]; + if (block.length === 0) { + return ""; + } + if (block.indexOf("@") >= 0) { + ZenCode = parseReferences(ZenCode, ZenObject); + zo = ZenObject; + zo.main = ZenCode; + return createHTMLBlock($, zo, data, functions, indexes); + } + block = parseContents(block, data, indexes); + blockClasses = parseClasses($, block); + if (regId.test(block)) { + blockId = regId.exec(block)[1]; + } + blockAttrs = parseAttributes(block, data); + blockTag = (block.charAt(0) === "{" ? "span" : "div"); + if (ZenCode.charAt(0) !== "#" && ZenCode.charAt(0) !== "." && ZenCode.charAt(0) !== "{") { + blockTag = regTag.exec(block)[1]; + } + if (block.search(regCBrace) !== -1) { + blockHTML = block.match(regCBrace)[1]; + } + blockAttrs = $.extend(blockAttrs, { + id: blockId, + "class": blockClasses, + html: blockHTML + }); + el = $("<" + blockTag + ">", blockAttrs); + el.attr(blockAttrs); + el = bindEvents(block, el, functions); + el = bindData(block, el, data); + ZenCode = ZenCode.substr(blocks[0].length); + ZenObject.main = ZenCode; + } + if (ZenCode.length > 0) { + if (ZenCode.charAt(0) === ">") { + if (ZenCode.charAt(1) === "(") { + zc = parseEnclosure(ZenCode.substr(1), "(", ")"); + ZenCode = ZenCode.substr(zc.length + 1); + } else if (ZenCode.charAt(1) === "!") { + obj = parseEnclosure(ZenCode.substr(1), "!"); + forScope = parseVariableScope(ZenCode.substr(1)); + zc = obj + forScope; + ZenCode = ZenCode.substr(zc.length + 1); + } else { + len = Math.max(ZenCode.indexOf("+"), ZenCode.length); + zc = ZenCode.substring(1, len); + ZenCode = ZenCode.substr(len); + } + zo = ZenObject; + zo.main = zc; + els = $(createHTMLBlock($, zo, data, functions, indexes)); + els.appendTo(el); + } + if (ZenCode.charAt(0) === "+") { + zo = ZenObject; + zo.main = ZenCode.substr(1); + el2 = createHTMLBlock($, zo, data, functions, indexes); + $.each(el2, function(index, value) { + return el.push(value); + }); + } + } + ret = el; + return ret; + }; + bindData = function(ZenCode, el, data) { + var datas, i, split; + if (ZenCode.search(regDatas) === 0) { + return el; + } + datas = ZenCode.match(regDatas); + if (datas === null) { + return el; + } + i = 0; + while (i < datas.length) { + split = regData.exec(datas[i]); + if (split[3] === undefined) { + $(el).data(split[1], data[split[1]]); + } else { + $(el).data(split[1], data[split[3]]); + } + i++; + } + return el; + }; + bindEvents = function(ZenCode, el, functions) { + var bindings, fn, i, split; + if (ZenCode.search(regEvents) === 0) { + return el; + } + bindings = ZenCode.match(regEvents); + if (bindings === null) { + return el; + } + i = 0; + while (i < bindings.length) { + split = regEvent.exec(bindings[i]); + if (split[2] === undefined) { + fn = functions[split[1]]; + } else { + fn = functions[split[2]]; + } + $(el).bind(split[1], fn); + i++; + } + return el; + }; + parseAttributes = function(ZenBlock, data) { + var attrStrs, attrs, i, parts; + if (ZenBlock.search(regAttrDfn) === -1) { + return undefined; + } + attrStrs = ZenBlock.match(regAttrDfn); + attrs = {}; + i = 0; + while (i < attrStrs.length) { + parts = regAttr.exec(attrStrs[i]); + attrs[parts[1]] = ""; + if (parts[3] !== undefined) { + attrs[parts[1]] = parseContents(parts[3], data); + } + i++; + } + return attrs; + }; + parseClasses = function($, ZenBlock) { + var classes, clsString, i; + ZenBlock = ZenBlock.match(regTagNotContent)[0]; + if (ZenBlock.search(regClasses) === -1) { + return undefined; + } + classes = ZenBlock.match(regClasses); + clsString = ""; + i = 0; + while (i < classes.length) { + clsString += " " + regClass.exec(classes[i])[1]; + i++; + } + return $.trim(clsString); + }; + parseContents = function(ZenBlock, data, indexes) { + var html; + if (indexes === undefined) { + indexes = {}; + } + html = ZenBlock; + if (data === undefined) { + return html; + } + while (regExclamation.test(html)) { + html = html.replace(regExclamation, function(str, str2) { + var begChar, fn, val; + begChar = ""; + if (str.indexOf("!for:") > 0 || str.indexOf("!if:") > 0) { + return str; + } + if (str.charAt(0) !== "!") { + begChar = str.charAt(0); + str = str.substring(2, str.length - 1); + } + fn = new Function("data", "indexes", "var r=undefined;" + "with(data){try{r=" + str + ";}catch(e){}}" + "with(indexes){try{if(r===undefined)r=" + str + ";}catch(e){}}" + "return r;"); + val = unescape(fn(data, indexes)); + return begChar + val; + }); + } + html = html.replace(/\\./g, function(str) { + return str.charAt(1); + }); + return unescape(html); + }; + parseEnclosure = function(ZenCode, open, close, count) { + var index, ret; + if (close === undefined) { + close = open; + } + index = 1; + if (count === undefined) { + count = (ZenCode.charAt(0) === open ? 1 : 0); + } + if (count === 0) { + return; + } + while (count > 0 && index < ZenCode.length) { + if (ZenCode.charAt(index) === close && ZenCode.charAt(index - 1) !== "\\") { + count--; + } else { + if (ZenCode.charAt(index) === open && ZenCode.charAt(index - 1) !== "\\") { + count++; + } + } + index++; + } + ret = ZenCode.substring(0, index); + return ret; + }; + parseReferences = function(ZenCode, ZenObject) { + ZenCode = ZenCode.replace(regReference, function(str) { + var fn; + str = str.substr(1); + fn = new Function("objs", "var r=\"\";" + "with(objs){try{" + "r=" + str + ";" + "}catch(e){}}" + "return r;"); + return fn(ZenObject, parseReferences); + }); + return ZenCode; + }; + parseVariableScope = function(ZenCode) { + var forCode, rest, tag; + if (ZenCode.substring(0, 5) !== "!for:" && ZenCode.substring(0, 4) !== "!if:") { + return undefined; + } + forCode = parseEnclosure(ZenCode, "!"); + ZenCode = ZenCode.substr(forCode.length); + if (ZenCode.charAt(0) === "(") { + return parseEnclosure(ZenCode, "(", ")"); + } + tag = ZenCode.match(regZenTagDfn)[0]; + ZenCode = ZenCode.substr(tag.length); + if (ZenCode.length === 0 || ZenCode.charAt(0) === "+") { + return tag; + } else if (ZenCode.charAt(0) === ">") { + rest = ""; + rest = parseEnclosure(ZenCode.substr(1), "(", ")", 1); + return tag + ">" + rest; + } + return undefined; + }; + regZenTagDfn = /([#\.\@]?[\w-]+|\[([\w-!?=:"']+(="([^"]|\\")+")? {0,})+\]|\~[\w$]+=[\w$]+|&[\w$]+(=[\w$]+)?|[#\.\@]?!([^!]|\\!)+!){0,}(\{([^\}]|\\\})+\})?/i; + regTag = /(\w+)/i; + regId = /#([\w-!]+)/i; + regTagNotContent = /((([#\.]?[\w-]+)?(\[([\w!]+(="([^"]|\\")+")? {0,})+\])?)+)/i; + regClasses = /(\.[\w-]+)/g; + regClass = /\.([\w-]+)/i; + regReference = /(@[\w$_][\w$_\d]+)/i; + regAttrDfn = /(\[([\w-!]+(="?([^"]|\\")+"?)? {0,})+\])/ig; + regAttrs = /([\w-!]+(="([^"]|\\")+")?)/g; + regAttr = /([\w-!]+)(="?(([^"\]]|\\")+)"?)?/i; + regCBrace = /\{(([^\}]|\\\})+)\}/i; + regExclamation = /(?:([^\\]|^))!([^!]|\\!)+!/g; + regEvents = /\~[\w$]+(=[\w$]+)?/g; + regEvent = /\~([\w$]+)=([\w$]+)/i; + regDatas = /&[\w$]+(=[\w$]+)?/g; + regData = /&([\w$]+)(=([\w$]+))?/i; + return createHTMLBlock; + })(); + +}).call(this); diff --git a/my-lineman-app/spec/helpers/jasmine-given.js b/my-lineman-app/spec/helpers/jasmine-given.js new file mode 100644 index 0000000..dede71a --- /dev/null +++ b/my-lineman-app/spec/helpers/jasmine-given.js @@ -0,0 +1,299 @@ +/* jasmine-given - 2.5.1 + * Adds a Given-When-Then DSL to jasmine as an alternative style for specs + * https://github.com/searls/jasmine-given + */ +(function() { + var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; + + (function(jasmine) { + var Waterfall, additionalInsightsForErrorMessage, apparentReferenceError, attemptedEquality, comparisonInsight, declareJasmineSpec, deepEqualsNotice, doneWrapperFor, evalInContextOfSpec, finalStatementFrom, getBlock, invariantList, mostRecentExpectations, mostRecentlyUsed, o, root, stringifyExpectation, wasComparison, whenList, wrapAsExpectations; + mostRecentlyUsed = null; + beforeEach(function() { + return this.addMatchers(jasmine._given.matchers); + }); + root = this; + root.Given = function() { + mostRecentlyUsed = root.Given; + return beforeEach(getBlock(arguments)); + }; + whenList = []; + root.When = function() { + var b; + mostRecentlyUsed = root.When; + b = getBlock(arguments); + beforeEach(function() { + return whenList.push(b); + }); + return afterEach(function() { + return whenList.pop(); + }); + }; + invariantList = []; + root.Invariant = function() { + var invariantBehavior; + mostRecentlyUsed = root.Invariant; + invariantBehavior = getBlock(arguments); + beforeEach(function() { + return invariantList.push(invariantBehavior); + }); + return afterEach(function() { + return invariantList.pop(); + }); + }; + getBlock = function(thing) { + var assignResultTo, setupFunction; + setupFunction = o(thing).firstThat(function(arg) { + return o(arg).isFunction(); + }); + assignResultTo = o(thing).firstThat(function(arg) { + return o(arg).isString(); + }); + return doneWrapperFor(setupFunction, function(done) { + var context, result; + context = jasmine.getEnv().currentSpec; + result = setupFunction.call(context, done); + if (assignResultTo) { + if (!context[assignResultTo]) { + return context[assignResultTo] = result; + } else { + throw new Error("Unfortunately, the variable '" + assignResultTo + "' is already assigned to: " + context[assignResultTo]); + } + } + }); + }; + mostRecentExpectations = null; + declareJasmineSpec = function(specArgs, itFunction) { + var expectationFunction, expectations, label; + if (itFunction == null) { + itFunction = it; + } + label = o(specArgs).firstThat(function(arg) { + return o(arg).isString(); + }); + expectationFunction = o(specArgs).firstThat(function(arg) { + return o(arg).isFunction(); + }); + mostRecentlyUsed = root.subsequentThen; + mostRecentExpectations = expectations = [expectationFunction]; + itFunction("then " + (label != null ? label : stringifyExpectation(expectations)), function(jasmineDone) { + var userCommands; + userCommands = [].concat(whenList, invariantList, wrapAsExpectations(expectations)); + return new Waterfall(userCommands, jasmineDone).flow(); + }); + return { + Then: subsequentThen, + And: subsequentThen + }; + }; + wrapAsExpectations = function(expectations) { + var expectation, i, _i, _len, _results; + _results = []; + for (i = _i = 0, _len = expectations.length; _i < _len; i = ++_i) { + expectation = expectations[i]; + _results.push((function(expectation, i) { + return doneWrapperFor(expectation, function(maybeDone) { + return expect(expectation).not.toHaveReturnedFalseFromThen(jasmine.getEnv().currentSpec, i + 1, maybeDone); + }); + })(expectation, i)); + } + return _results; + }; + doneWrapperFor = function(func, toWrap) { + if (func.length === 0) { + return function() { + return toWrap(); + }; + } else { + return function(done) { + return toWrap(done); + }; + } + }; + root.Then = function() { + return declareJasmineSpec(arguments); + }; + root.Then.only = function() { + return declareJasmineSpec(arguments, it.only); + }; + root.subsequentThen = function(additionalExpectation) { + mostRecentExpectations.push(additionalExpectation); + return this; + }; + mostRecentlyUsed = root.Given; + root.And = function() { + return mostRecentlyUsed.apply(this, jasmine.util.argsToArray(arguments)); + }; + o = function(thing) { + return { + isFunction: function() { + return Object.prototype.toString.call(thing) === "[object Function]"; + }, + isString: function() { + return Object.prototype.toString.call(thing) === "[object String]"; + }, + firstThat: function(test) { + var i; + i = 0; + while (i < thing.length) { + if (test(thing[i]) === true) { + return thing[i]; + } + i++; + } + return void 0; + } + }; + }; + jasmine._given = { + matchers: { + toHaveReturnedFalseFromThen: function(context, n, done) { + var e, exception, result; + result = false; + exception = void 0; + try { + result = this.actual.call(context, done); + } catch (_error) { + e = _error; + exception = e; + } + this.message = function() { + var msg, stringyExpectation; + stringyExpectation = stringifyExpectation(this.actual); + msg = "Then clause" + (n > 1 ? " #" + n : "") + " `" + stringyExpectation + "` failed by "; + if (exception) { + msg += "throwing: " + exception.toString(); + } else { + msg += "returning false"; + } + msg += additionalInsightsForErrorMessage(stringyExpectation); + return msg; + }; + return result === false; + } + } + }; + stringifyExpectation = function(expectation) { + var matches; + matches = expectation.toString().replace(/\n/g, '').match(/function\s?\(.*\)\s?{\s*(return\s+)?(.*?)(;)?\s*}/i); + if (matches && matches.length >= 3) { + return matches[2].replace(/\s+/g, ' '); + } else { + return ""; + } + }; + additionalInsightsForErrorMessage = function(expectationString) { + var comparison, expectation; + expectation = finalStatementFrom(expectationString); + if (comparison = wasComparison(expectation)) { + return comparisonInsight(expectation, comparison); + } else { + return ""; + } + }; + finalStatementFrom = function(expectationString) { + var multiStatement; + if (multiStatement = expectationString.match(/.*return (.*)/)) { + return multiStatement[multiStatement.length - 1]; + } else { + return expectationString; + } + }; + wasComparison = function(expectation) { + var comparator, comparison, left, right, s; + if (comparison = expectation.match(/(.*) (===|!==|==|!=|>|>=|<|<=) (.*)/)) { + s = comparison[0], left = comparison[1], comparator = comparison[2], right = comparison[3]; + return { + left: left, + comparator: comparator, + right: right + }; + } + }; + comparisonInsight = function(expectation, comparison) { + var left, msg, right; + left = evalInContextOfSpec(comparison.left); + right = evalInContextOfSpec(comparison.right); + if (apparentReferenceError(left) && apparentReferenceError(right)) { + return ""; + } + msg = "\n\nThis comparison was detected:\n " + expectation + "\n " + left + " " + comparison.comparator + " " + right; + if (attemptedEquality(left, right, comparison.comparator)) { + msg += "\n\n" + (deepEqualsNotice(comparison.left, comparison.right)); + } + return msg; + }; + apparentReferenceError = function(result) { + return /^"; + } + }; + attemptedEquality = function(left, right, comparator) { + return (comparator === "==" || comparator === "===") && jasmine.getEnv().equals_(left, right); + }; + deepEqualsNotice = function(left, right) { + return "However, these items are deeply equal! Try an expectation like this instead:\n expect(" + left + ").toEqual(" + right + ")"; + }; + return Waterfall = (function() { + function Waterfall(functions, finalCallback) { + var func, _i, _len, _ref; + if (functions == null) { + functions = []; + } + this.flow = __bind(this.flow, this); + this.invokeFinalCallbackIfNecessary = __bind(this.invokeFinalCallbackIfNecessary, this); + this.asyncTaskCompleted = __bind(this.asyncTaskCompleted, this); + this.functions = functions.slice(0); + this.finalCallback = finalCallback; + this.asyncCount = 0; + _ref = this.functions; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + func = _ref[_i]; + if (func.length > 0) { + this.asyncCount += 1; + } + } + } + + Waterfall.prototype.asyncTaskCompleted = function() { + this.asyncCount -= 1; + return this.flow(); + }; + + Waterfall.prototype.invokeFinalCallbackIfNecessary = function() { + if (this.asyncCount === 0) { + if (typeof this.finalCallback === "function") { + this.finalCallback(); + } + return this.finalCallback = void 0; + } + }; + + Waterfall.prototype.flow = function() { + var func; + if (this.functions.length === 0) { + return this.invokeFinalCallbackIfNecessary(); + } + func = this.functions.shift(); + if (func.length > 0) { + return func(this.asyncTaskCompleted); + } else { + func(); + return this.flow(); + } + }; + + return Waterfall; + + })(); + })(jasmine); + +}).call(this); diff --git a/my-lineman-app/spec/helpers/jasmine-only.js b/my-lineman-app/spec/helpers/jasmine-only.js new file mode 100644 index 0000000..01e2a67 --- /dev/null +++ b/my-lineman-app/spec/helpers/jasmine-only.js @@ -0,0 +1,103 @@ +/* jasmine-only - 0.1.0 + * Exclusivity spec helpers for jasmine: `describe.only` and `it.only` + * https://github.com/davemo/jasmine-only + */ +(function() { + var __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + + (function(jasmine) { + var describeOnly, env, itOnly, root; + + root = this; + env = jasmine.getEnv(); + describeOnly = function(description, specDefinitions) { + var suite; + + suite = new jasmine.Suite(this, description, null, this.currentSuite); + suite.exclusive_ = 1; + this.exclusive_ = Math.max(this.exclusive_, 1); + return this.describe_(suite, specDefinitions); + }; + itOnly = function(description, func) { + var spec; + + spec = this.it(description, func); + spec.exclusive_ = 2; + this.exclusive_ = 2; + return spec; + }; + env.exclusive_ = 0; + env.describe = function(description, specDefinitions) { + var suite; + + suite = new jasmine.Suite(this, description, null, this.currentSuite); + return this.describe_(suite, specDefinitions); + }; + env.describe_ = function(suite, specDefinitions) { + var declarationError, e, parentSuite; + + parentSuite = this.currentSuite; + if (parentSuite) { + parentSuite.add(suite); + } else { + this.currentRunner_.add(suite); + } + this.currentSuite = suite; + declarationError = null; + try { + specDefinitions.call(suite); + } catch (_error) { + e = _error; + declarationError = e; + } + if (declarationError) { + this.it("encountered a declaration exception", function() { + throw declarationError; + }); + } + this.currentSuite = parentSuite; + return suite; + }; + env.specFilter = function(spec) { + return this.exclusive_ <= spec.exclusive_; + }; + env.describe.only = function() { + return describeOnly.apply(env, arguments); + }; + env.it.only = function() { + return itOnly.apply(env, arguments); + }; + root.describe.only = function(description, specDefinitions) { + return env.describe.only(description, specDefinitions); + }; + root.it.only = function(description, func) { + return env.it.only(description, func); + }; + root.iit = root.it.only; + root.ddescribe = root.describe.only; + jasmine.Spec = (function(_super) { + __extends(Spec, _super); + + function Spec(env, suite, description) { + this.exclusive_ = suite.exclusive_; + Spec.__super__.constructor.call(this, env, suite, description); + } + + return Spec; + + })(jasmine.Spec); + return jasmine.Suite = (function(_super) { + __extends(Suite, _super); + + function Suite(env, suite, specDefinitions, parentSuite) { + this.exclusive_ = parentSuite && parentSuite.exclusive_ || 0; + Suite.__super__.constructor.call(this, env, suite, specDefinitions, parentSuite); + } + + return Suite; + + })(jasmine.Suite); + })(jasmine); + +}).call(this); diff --git a/my-lineman-app/spec/helpers/jasmine-stealth.js b/my-lineman-app/spec/helpers/jasmine-stealth.js new file mode 100644 index 0000000..5ccc0f3 --- /dev/null +++ b/my-lineman-app/spec/helpers/jasmine-stealth.js @@ -0,0 +1,232 @@ +/* jasmine-stealth - 0.0.13 + * Makes Jasmine spies a bit more robust + * https://github.com/searls/jasmine-stealth + */ +(function() { + var Captor, fake, root, stubChainer, unfakes, whatToDoWhenTheSpyGetsCalled, _, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + + root = this; + + _ = function(obj) { + return { + each: function(iterator) { + var item, _i, _len, _results; + _results = []; + for (_i = 0, _len = obj.length; _i < _len; _i++) { + item = obj[_i]; + _results.push(iterator(item)); + } + return _results; + }, + isFunction: function() { + return Object.prototype.toString.call(obj) === "[object Function]"; + }, + isString: function() { + return Object.prototype.toString.call(obj) === "[object String]"; + } + }; + }; + + root.spyOnConstructor = function(owner, classToFake, methodsToSpy) { + var fakeClass, spies; + if (methodsToSpy == null) { + methodsToSpy = []; + } + if (_(methodsToSpy).isString()) { + methodsToSpy = [methodsToSpy]; + } + spies = { + constructor: jasmine.createSpy("" + classToFake + "'s constructor") + }; + fakeClass = (function() { + function _Class() { + spies.constructor.apply(this, arguments); + } + + return _Class; + + })(); + _(methodsToSpy).each(function(methodName) { + spies[methodName] = jasmine.createSpy("" + classToFake + "#" + methodName); + return fakeClass.prototype[methodName] = function() { + return spies[methodName].apply(this, arguments); + }; + }); + fake(owner, classToFake, fakeClass); + return spies; + }; + + unfakes = []; + + afterEach(function() { + _(unfakes).each(function(u) { + return u(); + }); + return unfakes = []; + }); + + fake = function(owner, thingToFake, newThing) { + var originalThing; + originalThing = owner[thingToFake]; + owner[thingToFake] = newThing; + return unfakes.push(function() { + return owner[thingToFake] = originalThing; + }); + }; + + root.stubFor = root.spyOn; + + jasmine.createStub = jasmine.createSpy; + + jasmine.createStubObj = function(baseName, stubbings) { + var name, obj, stubbing; + if (stubbings.constructor === Array) { + return jasmine.createSpyObj(baseName, stubbings); + } else { + obj = {}; + for (name in stubbings) { + stubbing = stubbings[name]; + obj[name] = jasmine.createSpy(baseName + "." + name); + if (_(stubbing).isFunction()) { + obj[name].andCallFake(stubbing); + } else { + obj[name].andReturn(stubbing); + } + } + return obj; + } + }; + + whatToDoWhenTheSpyGetsCalled = function(spy) { + var matchesStub, priorStubbing; + matchesStub = function(stubbing, args, context) { + switch (stubbing.type) { + case "args": + return jasmine.getEnv().equals_(stubbing.ifThis, jasmine.util.argsToArray(args)); + case "context": + return jasmine.getEnv().equals_(stubbing.ifThis, context); + } + }; + priorStubbing = spy.plan(); + return spy.andCallFake(function() { + var i, stubbing; + i = 0; + while (i < spy._stealth_stubbings.length) { + stubbing = spy._stealth_stubbings[i]; + if (matchesStub(stubbing, arguments, this)) { + if (stubbing.satisfaction === "callFake") { + return stubbing.thenThat.apply(stubbing, arguments); + } else { + return stubbing.thenThat; + } + } + i++; + } + return priorStubbing; + }); + }; + + jasmine.Spy.prototype.whenContext = function(context) { + var spy; + spy = this; + spy._stealth_stubbings || (spy._stealth_stubbings = []); + whatToDoWhenTheSpyGetsCalled(spy); + return stubChainer(spy, "context", context); + }; + + jasmine.Spy.prototype.when = function() { + var ifThis, spy; + spy = this; + ifThis = jasmine.util.argsToArray(arguments); + spy._stealth_stubbings || (spy._stealth_stubbings = []); + whatToDoWhenTheSpyGetsCalled(spy); + return stubChainer(spy, "args", ifThis); + }; + + stubChainer = function(spy, type, ifThis) { + var addStubbing; + addStubbing = function(satisfaction) { + return function(thenThat) { + spy._stealth_stubbings.push({ + type: type, + ifThis: ifThis, + satisfaction: satisfaction, + thenThat: thenThat + }); + return spy; + }; + }; + return { + thenReturn: addStubbing("return"), + thenCallFake: addStubbing("callFake") + }; + }; + + jasmine.Spy.prototype.mostRecentCallThat = function(callThat, context) { + var i; + i = this.calls.length - 1; + while (i >= 0) { + if (callThat.call(context || this, this.calls[i]) === true) { + return this.calls[i]; + } + i--; + } + }; + + jasmine.Matchers.ArgThat = (function(_super) { + __extends(ArgThat, _super); + + function ArgThat(matcher) { + this.matcher = matcher; + } + + ArgThat.prototype.jasmineMatches = function(actual) { + return this.matcher(actual); + }; + + return ArgThat; + + })(jasmine.Matchers.Any); + + jasmine.Matchers.ArgThat.prototype.matches = jasmine.Matchers.ArgThat.prototype.jasmineMatches; + + jasmine.argThat = function(expected) { + return new jasmine.Matchers.ArgThat(expected); + }; + + jasmine.Matchers.Capture = (function(_super) { + __extends(Capture, _super); + + function Capture(captor) { + this.captor = captor; + } + + Capture.prototype.jasmineMatches = function(actual) { + this.captor.value = actual; + return true; + }; + + return Capture; + + })(jasmine.Matchers.Any); + + jasmine.Matchers.Capture.prototype.matches = jasmine.Matchers.Capture.prototype.jasmineMatches; + + Captor = (function() { + function Captor() {} + + Captor.prototype.capture = function() { + return new jasmine.Matchers.Capture(this); + }; + + return Captor; + + })(); + + jasmine.captor = function() { + return new Captor(); + }; + +}).call(this); diff --git a/my-lineman-app/tasks/.gitkeep b/my-lineman-app/tasks/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/my-lineman-app/vendor/css/.gitkeep b/my-lineman-app/vendor/css/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/my-lineman-app/vendor/img/.gitkeep b/my-lineman-app/vendor/img/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/my-lineman-app/vendor/js/underscore.js b/my-lineman-app/vendor/js/underscore.js new file mode 100644 index 0000000..32ca0c1 --- /dev/null +++ b/my-lineman-app/vendor/js/underscore.js @@ -0,0 +1,1227 @@ +// Underscore.js 1.4.4 +// =================== + +// > http://underscorejs.org +// > (c) 2009-2013 Jeremy Ashkenas, DocumentCloud Inc. +// > Underscore may be freely distributed under the MIT license. + +// Baseline setup +// -------------- +(function() { + + // Establish the root object, `window` in the browser, or `global` on the server. + var root = this; + + // Save the previous value of the `_` variable. + var previousUnderscore = root._; + + // Establish the object that gets returned to break out of a loop iteration. + var breaker = {}; + + // Save bytes in the minified (but not gzipped) version: + var ArrayProto = Array.prototype, ObjProto = Object.prototype, FuncProto = Function.prototype; + + // Create quick reference variables for speed access to core prototypes. + var push = ArrayProto.push, + slice = ArrayProto.slice, + concat = ArrayProto.concat, + toString = ObjProto.toString, + hasOwnProperty = ObjProto.hasOwnProperty; + + // All **ECMAScript 5** native function implementations that we hope to use + // are declared here. + var + nativeForEach = ArrayProto.forEach, + nativeMap = ArrayProto.map, + nativeReduce = ArrayProto.reduce, + nativeReduceRight = ArrayProto.reduceRight, + nativeFilter = ArrayProto.filter, + nativeEvery = ArrayProto.every, + nativeSome = ArrayProto.some, + nativeIndexOf = ArrayProto.indexOf, + nativeLastIndexOf = ArrayProto.lastIndexOf, + nativeIsArray = Array.isArray, + nativeKeys = Object.keys, + nativeBind = FuncProto.bind; + + // Create a safe reference to the Underscore object for use below. + var _ = function(obj) { + if (obj instanceof _) return obj; + if (!(this instanceof _)) return new _(obj); + this._wrapped = obj; + }; + + // Export the Underscore object for **Node.js**, with + // backwards-compatibility for the old `require()` API. If we're in + // the browser, add `_` as a global object via a string identifier, + // for Closure Compiler "advanced" mode. + if (typeof exports !== 'undefined') { + if (typeof module !== 'undefined' && module.exports) { + exports = module.exports = _; + } + exports._ = _; + } else { + root._ = _; + } + + // Current version. + _.VERSION = '1.4.4'; + + // Collection Functions + // -------------------- + + // The cornerstone, an `each` implementation, aka `forEach`. + // Handles objects with the built-in `forEach`, arrays, and raw objects. + // Delegates to **ECMAScript 5**'s native `forEach` if available. + var each = _.each = _.forEach = function(obj, iterator, context) { + if (obj == null) return; + if (nativeForEach && obj.forEach === nativeForEach) { + obj.forEach(iterator, context); + } else if (obj.length === +obj.length) { + for (var i = 0, l = obj.length; i < l; i++) { + if (iterator.call(context, obj[i], i, obj) === breaker) return; + } + } else { + for (var key in obj) { + if (_.has(obj, key)) { + if (iterator.call(context, obj[key], key, obj) === breaker) return; + } + } + } + }; + + // Return the results of applying the iterator to each element. + // Delegates to **ECMAScript 5**'s native `map` if available. + _.map = _.collect = function(obj, iterator, context) { + var results = []; + if (obj == null) return results; + if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context); + each(obj, function(value, index, list) { + results[results.length] = iterator.call(context, value, index, list); + }); + return results; + }; + + var reduceError = 'Reduce of empty array with no initial value'; + + // **Reduce** builds up a single result from a list of values, aka `inject`, + // or `foldl`. Delegates to **ECMAScript 5**'s native `reduce` if available. + _.reduce = _.foldl = _.inject = function(obj, iterator, memo, context) { + var initial = arguments.length > 2; + if (obj == null) obj = []; + if (nativeReduce && obj.reduce === nativeReduce) { + if (context) iterator = _.bind(iterator, context); + return initial ? obj.reduce(iterator, memo) : obj.reduce(iterator); + } + each(obj, function(value, index, list) { + if (!initial) { + memo = value; + initial = true; + } else { + memo = iterator.call(context, memo, value, index, list); + } + }); + if (!initial) throw new TypeError(reduceError); + return memo; + }; + + // The right-associative version of reduce, also known as `foldr`. + // Delegates to **ECMAScript 5**'s native `reduceRight` if available. + _.reduceRight = _.foldr = function(obj, iterator, memo, context) { + var initial = arguments.length > 2; + if (obj == null) obj = []; + if (nativeReduceRight && obj.reduceRight === nativeReduceRight) { + if (context) iterator = _.bind(iterator, context); + return initial ? obj.reduceRight(iterator, memo) : obj.reduceRight(iterator); + } + var length = obj.length; + if (length !== +length) { + var keys = _.keys(obj); + length = keys.length; + } + each(obj, function(value, index, list) { + index = keys ? keys[--length] : --length; + if (!initial) { + memo = obj[index]; + initial = true; + } else { + memo = iterator.call(context, memo, obj[index], index, list); + } + }); + if (!initial) throw new TypeError(reduceError); + return memo; + }; + + // Return the first value which passes a truth test. Aliased as `detect`. + _.find = _.detect = function(obj, iterator, context) { + var result; + any(obj, function(value, index, list) { + if (iterator.call(context, value, index, list)) { + result = value; + return true; + } + }); + return result; + }; + + // Return all the elements that pass a truth test. + // Delegates to **ECMAScript 5**'s native `filter` if available. + // Aliased as `select`. + _.filter = _.select = function(obj, iterator, context) { + var results = []; + if (obj == null) return results; + if (nativeFilter && obj.filter === nativeFilter) return obj.filter(iterator, context); + each(obj, function(value, index, list) { + if (iterator.call(context, value, index, list)) results[results.length] = value; + }); + return results; + }; + + // Return all the elements for which a truth test fails. + _.reject = function(obj, iterator, context) { + return _.filter(obj, function(value, index, list) { + return !iterator.call(context, value, index, list); + }, context); + }; + + // Determine whether all of the elements match a truth test. + // Delegates to **ECMAScript 5**'s native `every` if available. + // Aliased as `all`. + _.every = _.all = function(obj, iterator, context) { + iterator || (iterator = _.identity); + var result = true; + if (obj == null) return result; + if (nativeEvery && obj.every === nativeEvery) return obj.every(iterator, context); + each(obj, function(value, index, list) { + if (!(result = result && iterator.call(context, value, index, list))) return breaker; + }); + return !!result; + }; + + // Determine if at least one element in the object matches a truth test. + // Delegates to **ECMAScript 5**'s native `some` if available. + // Aliased as `any`. + var any = _.some = _.any = function(obj, iterator, context) { + iterator || (iterator = _.identity); + var result = false; + if (obj == null) return result; + if (nativeSome && obj.some === nativeSome) return obj.some(iterator, context); + each(obj, function(value, index, list) { + if (result || (result = iterator.call(context, value, index, list))) return breaker; + }); + return !!result; + }; + + // Determine if the array or object contains a given value (using `===`). + // Aliased as `include`. + _.contains = _.include = function(obj, target) { + if (obj == null) return false; + if (nativeIndexOf && obj.indexOf === nativeIndexOf) return obj.indexOf(target) != -1; + return any(obj, function(value) { + return value === target; + }); + }; + + // Invoke a method (with arguments) on every item in a collection. + _.invoke = function(obj, method) { + var args = slice.call(arguments, 2); + var isFunc = _.isFunction(method); + return _.map(obj, function(value) { + return (isFunc ? method : value[method]).apply(value, args); + }); + }; + + // Convenience version of a common use case of `map`: fetching a property. + _.pluck = function(obj, key) { + return _.map(obj, function(value){ return value[key]; }); + }; + + // Convenience version of a common use case of `filter`: selecting only objects + // containing specific `key:value` pairs. + _.where = function(obj, attrs, first) { + if (_.isEmpty(attrs)) return first ? null : []; + return _[first ? 'find' : 'filter'](obj, function(value) { + for (var key in attrs) { + if (attrs[key] !== value[key]) return false; + } + return true; + }); + }; + + // Convenience version of a common use case of `find`: getting the first object + // containing specific `key:value` pairs. + _.findWhere = function(obj, attrs) { + return _.where(obj, attrs, true); + }; + + // Return the maximum element or (element-based computation). + // Can't optimize arrays of integers longer than 65,535 elements. + // See: https://bugs.webkit.org/show_bug.cgi?id=80797 + _.max = function(obj, iterator, context) { + if (!iterator && _.isArray(obj) && obj[0] === +obj[0] && obj.length < 65535) { + return Math.max.apply(Math, obj); + } + if (!iterator && _.isEmpty(obj)) return -Infinity; + var result = {computed : -Infinity, value: -Infinity}; + each(obj, function(value, index, list) { + var computed = iterator ? iterator.call(context, value, index, list) : value; + computed >= result.computed && (result = {value : value, computed : computed}); + }); + return result.value; + }; + + // Return the minimum element (or element-based computation). + _.min = function(obj, iterator, context) { + if (!iterator && _.isArray(obj) && obj[0] === +obj[0] && obj.length < 65535) { + return Math.min.apply(Math, obj); + } + if (!iterator && _.isEmpty(obj)) return Infinity; + var result = {computed : Infinity, value: Infinity}; + each(obj, function(value, index, list) { + var computed = iterator ? iterator.call(context, value, index, list) : value; + computed < result.computed && (result = {value : value, computed : computed}); + }); + return result.value; + }; + + // Shuffle an array. + _.shuffle = function(obj) { + var rand; + var index = 0; + var shuffled = []; + each(obj, function(value) { + rand = _.random(index++); + shuffled[index - 1] = shuffled[rand]; + shuffled[rand] = value; + }); + return shuffled; + }; + + // An internal function to generate lookup iterators. + var lookupIterator = function(value) { + return _.isFunction(value) ? value : function(obj){ return obj[value]; }; + }; + + // Sort the object's values by a criterion produced by an iterator. + _.sortBy = function(obj, value, context) { + var iterator = lookupIterator(value); + return _.pluck(_.map(obj, function(value, index, list) { + return { + value : value, + index : index, + criteria : iterator.call(context, value, index, list) + }; + }).sort(function(left, right) { + var a = left.criteria; + var b = right.criteria; + if (a !== b) { + if (a > b || a === void 0) return 1; + if (a < b || b === void 0) return -1; + } + return left.index < right.index ? -1 : 1; + }), 'value'); + }; + + // An internal function used for aggregate "group by" operations. + var group = function(obj, value, context, behavior) { + var result = {}; + var iterator = lookupIterator(value || _.identity); + each(obj, function(value, index) { + var key = iterator.call(context, value, index, obj); + behavior(result, key, value); + }); + return result; + }; + + // Groups the object's values by a criterion. Pass either a string attribute + // to group by, or a function that returns the criterion. + _.groupBy = function(obj, value, context) { + return group(obj, value, context, function(result, key, value) { + (_.has(result, key) ? result[key] : (result[key] = [])).push(value); + }); + }; + + // Counts instances of an object that group by a certain criterion. Pass + // either a string attribute to count by, or a function that returns the + // criterion. + _.countBy = function(obj, value, context) { + return group(obj, value, context, function(result, key) { + if (!_.has(result, key)) result[key] = 0; + result[key]++; + }); + }; + + // Use a comparator function to figure out the smallest index at which + // an object should be inserted so as to maintain order. Uses binary search. + _.sortedIndex = function(array, obj, iterator, context) { + iterator = iterator == null ? _.identity : lookupIterator(iterator); + var value = iterator.call(context, obj); + var low = 0, high = array.length; + while (low < high) { + var mid = (low + high) >>> 1; + iterator.call(context, array[mid]) < value ? low = mid + 1 : high = mid; + } + return low; + }; + + // Safely convert anything iterable into a real, live array. + _.toArray = function(obj) { + if (!obj) return []; + if (_.isArray(obj)) return slice.call(obj); + if (obj.length === +obj.length) return _.map(obj, _.identity); + return _.values(obj); + }; + + // Return the number of elements in an object. + _.size = function(obj) { + if (obj == null) return 0; + return (obj.length === +obj.length) ? obj.length : _.keys(obj).length; + }; + + // Array Functions + // --------------- + + // Get the first element of an array. Passing **n** will return the first N + // values in the array. Aliased as `head` and `take`. The **guard** check + // allows it to work with `_.map`. + _.first = _.head = _.take = function(array, n, guard) { + if (array == null) return void 0; + return (n != null) && !guard ? slice.call(array, 0, n) : array[0]; + }; + + // Returns everything but the last entry of the array. Especially useful on + // the arguments object. Passing **n** will return all the values in + // the array, excluding the last N. The **guard** check allows it to work with + // `_.map`. + _.initial = function(array, n, guard) { + return slice.call(array, 0, array.length - ((n == null) || guard ? 1 : n)); + }; + + // Get the last element of an array. Passing **n** will return the last N + // values in the array. The **guard** check allows it to work with `_.map`. + _.last = function(array, n, guard) { + if (array == null) return void 0; + if ((n != null) && !guard) { + return slice.call(array, Math.max(array.length - n, 0)); + } else { + return array[array.length - 1]; + } + }; + + // Returns everything but the first entry of the array. Aliased as `tail` and `drop`. + // Especially useful on the arguments object. Passing an **n** will return + // the rest N values in the array. The **guard** + // check allows it to work with `_.map`. + _.rest = _.tail = _.drop = function(array, n, guard) { + return slice.call(array, (n == null) || guard ? 1 : n); + }; + + // Trim out all falsy values from an array. + _.compact = function(array) { + return _.filter(array, _.identity); + }; + + // Internal implementation of a recursive `flatten` function. + var flatten = function(input, shallow, output) { + each(input, function(value) { + if (_.isArray(value)) { + shallow ? push.apply(output, value) : flatten(value, shallow, output); + } else { + output.push(value); + } + }); + return output; + }; + + // Return a completely flattened version of an array. + _.flatten = function(array, shallow) { + return flatten(array, shallow, []); + }; + + // Return a version of the array that does not contain the specified value(s). + _.without = function(array) { + return _.difference(array, slice.call(arguments, 1)); + }; + + // Produce a duplicate-free version of the array. If the array has already + // been sorted, you have the option of using a faster algorithm. + // Aliased as `unique`. + _.uniq = _.unique = function(array, isSorted, iterator, context) { + if (_.isFunction(isSorted)) { + context = iterator; + iterator = isSorted; + isSorted = false; + } + var initial = iterator ? _.map(array, iterator, context) : array; + var results = []; + var seen = []; + each(initial, function(value, index) { + if (isSorted ? (!index || seen[seen.length - 1] !== value) : !_.contains(seen, value)) { + seen.push(value); + results.push(array[index]); + } + }); + return results; + }; + + // Produce an array that contains the union: each distinct element from all of + // the passed-in arrays. + _.union = function() { + return _.uniq(concat.apply(ArrayProto, arguments)); + }; + + // Produce an array that contains every item shared between all the + // passed-in arrays. + _.intersection = function(array) { + var rest = slice.call(arguments, 1); + return _.filter(_.uniq(array), function(item) { + return _.every(rest, function(other) { + return _.indexOf(other, item) >= 0; + }); + }); + }; + + // Take the difference between one array and a number of other arrays. + // Only the elements present in just the first array will remain. + _.difference = function(array) { + var rest = concat.apply(ArrayProto, slice.call(arguments, 1)); + return _.filter(array, function(value){ return !_.contains(rest, value); }); + }; + + // Zip together multiple lists into a single array -- elements that share + // an index go together. + _.zip = function() { + var args = slice.call(arguments); + var length = _.max(_.pluck(args, 'length')); + var results = new Array(length); + for (var i = 0; i < length; i++) { + results[i] = _.pluck(args, "" + i); + } + return results; + }; + + // Converts lists into objects. Pass either a single array of `[key, value]` + // pairs, or two parallel arrays of the same length -- one of keys, and one of + // the corresponding values. + _.object = function(list, values) { + if (list == null) return {}; + var result = {}; + for (var i = 0, l = list.length; i < l; i++) { + if (values) { + result[list[i]] = values[i]; + } else { + result[list[i][0]] = list[i][1]; + } + } + return result; + }; + + // If the browser doesn't supply us with indexOf (I'm looking at you, **MSIE**), + // we need this function. Return the position of the first occurrence of an + // item in an array, or -1 if the item is not included in the array. + // Delegates to **ECMAScript 5**'s native `indexOf` if available. + // If the array is large and already in sort order, pass `true` + // for **isSorted** to use binary search. + _.indexOf = function(array, item, isSorted) { + if (array == null) return -1; + var i = 0, l = array.length; + if (isSorted) { + if (typeof isSorted == 'number') { + i = (isSorted < 0 ? Math.max(0, l + isSorted) : isSorted); + } else { + i = _.sortedIndex(array, item); + return array[i] === item ? i : -1; + } + } + if (nativeIndexOf && array.indexOf === nativeIndexOf) return array.indexOf(item, isSorted); + for (; i < l; i++) if (array[i] === item) return i; + return -1; + }; + + // Delegates to **ECMAScript 5**'s native `lastIndexOf` if available. + _.lastIndexOf = function(array, item, from) { + if (array == null) return -1; + var hasIndex = from != null; + if (nativeLastIndexOf && array.lastIndexOf === nativeLastIndexOf) { + return hasIndex ? array.lastIndexOf(item, from) : array.lastIndexOf(item); + } + var i = (hasIndex ? from : array.length); + while (i--) if (array[i] === item) return i; + return -1; + }; + + // Generate an integer Array containing an arithmetic progression. A port of + // the native Python `range()` function. See + // [the Python documentation](http://docs.python.org/library/functions.html#range). + _.range = function(start, stop, step) { + if (arguments.length <= 1) { + stop = start || 0; + start = 0; + } + step = arguments[2] || 1; + + var len = Math.max(Math.ceil((stop - start) / step), 0); + var idx = 0; + var range = new Array(len); + + while(idx < len) { + range[idx++] = start; + start += step; + } + + return range; + }; + + // Function (ahem) Functions + // ------------------ + + // Create a function bound to a given object (assigning `this`, and arguments, + // optionally). Delegates to **ECMAScript 5**'s native `Function.bind` if + // available. + _.bind = function(func, context) { + if (func.bind === nativeBind && nativeBind) return nativeBind.apply(func, slice.call(arguments, 1)); + var args = slice.call(arguments, 2); + return function() { + return func.apply(context, args.concat(slice.call(arguments))); + }; + }; + + // Partially apply a function by creating a version that has had some of its + // arguments pre-filled, without changing its dynamic `this` context. + _.partial = function(func) { + var args = slice.call(arguments, 1); + return function() { + return func.apply(this, args.concat(slice.call(arguments))); + }; + }; + + // Bind all of an object's methods to that object. Useful for ensuring that + // all callbacks defined on an object belong to it. + _.bindAll = function(obj) { + var funcs = slice.call(arguments, 1); + if (funcs.length === 0) funcs = _.functions(obj); + each(funcs, function(f) { obj[f] = _.bind(obj[f], obj); }); + return obj; + }; + + // Memoize an expensive function by storing its results. + _.memoize = function(func, hasher) { + var memo = {}; + hasher || (hasher = _.identity); + return function() { + var key = hasher.apply(this, arguments); + return _.has(memo, key) ? memo[key] : (memo[key] = func.apply(this, arguments)); + }; + }; + + // Delays a function for the given number of milliseconds, and then calls + // it with the arguments supplied. + _.delay = function(func, wait) { + var args = slice.call(arguments, 2); + return setTimeout(function(){ return func.apply(null, args); }, wait); + }; + + // Defers a function, scheduling it to run after the current call stack has + // cleared. + _.defer = function(func) { + return _.delay.apply(_, [func, 1].concat(slice.call(arguments, 1))); + }; + + // Returns a function, that, when invoked, will only be triggered at most once + // during a given window of time. + _.throttle = function(func, wait) { + var context, args, timeout, result; + var previous = 0; + var later = function() { + previous = new Date; + timeout = null; + result = func.apply(context, args); + }; + return function() { + var now = new Date; + var remaining = wait - (now - previous); + context = this; + args = arguments; + if (remaining <= 0) { + clearTimeout(timeout); + timeout = null; + previous = now; + result = func.apply(context, args); + } else if (!timeout) { + timeout = setTimeout(later, remaining); + } + return result; + }; + }; + + // Returns a function, that, as long as it continues to be invoked, will not + // be triggered. The function will be called after it stops being called for + // N milliseconds. If `immediate` is passed, trigger the function on the + // leading edge, instead of the trailing. + _.debounce = function(func, wait, immediate) { + var timeout, result; + return function() { + var context = this, args = arguments; + var later = function() { + timeout = null; + if (!immediate) result = func.apply(context, args); + }; + var callNow = immediate && !timeout; + clearTimeout(timeout); + timeout = setTimeout(later, wait); + if (callNow) result = func.apply(context, args); + return result; + }; + }; + + // Returns a function that will be executed at most one time, no matter how + // often you call it. Useful for lazy initialization. + _.once = function(func) { + var ran = false, memo; + return function() { + if (ran) return memo; + ran = true; + memo = func.apply(this, arguments); + func = null; + return memo; + }; + }; + + // Returns the first function passed as an argument to the second, + // allowing you to adjust arguments, run code before and after, and + // conditionally execute the original function. + _.wrap = function(func, wrapper) { + return function() { + var args = [func]; + push.apply(args, arguments); + return wrapper.apply(this, args); + }; + }; + + // Returns a function that is the composition of a list of functions, each + // consuming the return value of the function that follows. + _.compose = function() { + var funcs = arguments; + return function() { + var args = arguments; + for (var i = funcs.length - 1; i >= 0; i--) { + args = [funcs[i].apply(this, args)]; + } + return args[0]; + }; + }; + + // Returns a function that will only be executed after being called N times. + _.after = function(times, func) { + if (times <= 0) return func(); + return function() { + if (--times < 1) { + return func.apply(this, arguments); + } + }; + }; + + // Object Functions + // ---------------- + + // Retrieve the names of an object's properties. + // Delegates to **ECMAScript 5**'s native `Object.keys` + _.keys = nativeKeys || function(obj) { + if (obj !== Object(obj)) throw new TypeError('Invalid object'); + var keys = []; + for (var key in obj) if (_.has(obj, key)) keys[keys.length] = key; + return keys; + }; + + // Retrieve the values of an object's properties. + _.values = function(obj) { + var values = []; + for (var key in obj) if (_.has(obj, key)) values.push(obj[key]); + return values; + }; + + // Convert an object into a list of `[key, value]` pairs. + _.pairs = function(obj) { + var pairs = []; + for (var key in obj) if (_.has(obj, key)) pairs.push([key, obj[key]]); + return pairs; + }; + + // Invert the keys and values of an object. The values must be serializable. + _.invert = function(obj) { + var result = {}; + for (var key in obj) if (_.has(obj, key)) result[obj[key]] = key; + return result; + }; + + // Return a sorted list of the function names available on the object. + // Aliased as `methods` + _.functions = _.methods = function(obj) { + var names = []; + for (var key in obj) { + if (_.isFunction(obj[key])) names.push(key); + } + return names.sort(); + }; + + // Extend a given object with all the properties in passed-in object(s). + _.extend = function(obj) { + each(slice.call(arguments, 1), function(source) { + if (source) { + for (var prop in source) { + obj[prop] = source[prop]; + } + } + }); + return obj; + }; + + // Return a copy of the object only containing the whitelisted properties. + _.pick = function(obj) { + var copy = {}; + var keys = concat.apply(ArrayProto, slice.call(arguments, 1)); + each(keys, function(key) { + if (key in obj) copy[key] = obj[key]; + }); + return copy; + }; + + // Return a copy of the object without the blacklisted properties. + _.omit = function(obj) { + var copy = {}; + var keys = concat.apply(ArrayProto, slice.call(arguments, 1)); + for (var key in obj) { + if (!_.contains(keys, key)) copy[key] = obj[key]; + } + return copy; + }; + + // Fill in a given object with default properties. + _.defaults = function(obj) { + each(slice.call(arguments, 1), function(source) { + if (source) { + for (var prop in source) { + if (obj[prop] == null) obj[prop] = source[prop]; + } + } + }); + return obj; + }; + + // Create a (shallow-cloned) duplicate of an object. + _.clone = function(obj) { + if (!_.isObject(obj)) return obj; + return _.isArray(obj) ? obj.slice() : _.extend({}, obj); + }; + + // Invokes interceptor with the obj, and then returns obj. + // The primary purpose of this method is to "tap into" a method chain, in + // order to perform operations on intermediate results within the chain. + _.tap = function(obj, interceptor) { + interceptor(obj); + return obj; + }; + + // Internal recursive comparison function for `isEqual`. + var eq = function(a, b, aStack, bStack) { + // Identical objects are equal. `0 === -0`, but they aren't identical. + // See the Harmony `egal` proposal: http://wiki.ecmascript.org/doku.php?id=harmony:egal. + if (a === b) return a !== 0 || 1 / a == 1 / b; + // A strict comparison is necessary because `null == undefined`. + if (a == null || b == null) return a === b; + // Unwrap any wrapped objects. + if (a instanceof _) a = a._wrapped; + if (b instanceof _) b = b._wrapped; + // Compare `[[Class]]` names. + var className = toString.call(a); + if (className != toString.call(b)) return false; + switch (className) { + // Strings, numbers, dates, and booleans are compared by value. + case '[object String]': + // Primitives and their corresponding object wrappers are equivalent; thus, `"5"` is + // equivalent to `new String("5")`. + return a == String(b); + case '[object Number]': + // `NaN`s are equivalent, but non-reflexive. An `egal` comparison is performed for + // other numeric values. + return a != +a ? b != +b : (a == 0 ? 1 / a == 1 / b : a == +b); + case '[object Date]': + case '[object Boolean]': + // Coerce dates and booleans to numeric primitive values. Dates are compared by their + // millisecond representations. Note that invalid dates with millisecond representations + // of `NaN` are not equivalent. + return +a == +b; + // RegExps are compared by their source patterns and flags. + case '[object RegExp]': + return a.source == b.source && + a.global == b.global && + a.multiline == b.multiline && + a.ignoreCase == b.ignoreCase; + } + if (typeof a != 'object' || typeof b != 'object') return false; + // Assume equality for cyclic structures. The algorithm for detecting cyclic + // structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`. + var length = aStack.length; + while (length--) { + // Linear search. Performance is inversely proportional to the number of + // unique nested structures. + if (aStack[length] == a) return bStack[length] == b; + } + // Add the first object to the stack of traversed objects. + aStack.push(a); + bStack.push(b); + var size = 0, result = true; + // Recursively compare objects and arrays. + if (className == '[object Array]') { + // Compare array lengths to determine if a deep comparison is necessary. + size = a.length; + result = size == b.length; + if (result) { + // Deep compare the contents, ignoring non-numeric properties. + while (size--) { + if (!(result = eq(a[size], b[size], aStack, bStack))) break; + } + } + } else { + // Objects with different constructors are not equivalent, but `Object`s + // from different frames are. + var aCtor = a.constructor, bCtor = b.constructor; + if (aCtor !== bCtor && !(_.isFunction(aCtor) && (aCtor instanceof aCtor) && + _.isFunction(bCtor) && (bCtor instanceof bCtor))) { + return false; + } + // Deep compare objects. + for (var key in a) { + if (_.has(a, key)) { + // Count the expected number of properties. + size++; + // Deep compare each member. + if (!(result = _.has(b, key) && eq(a[key], b[key], aStack, bStack))) break; + } + } + // Ensure that both objects contain the same number of properties. + if (result) { + for (key in b) { + if (_.has(b, key) && !(size--)) break; + } + result = !size; + } + } + // Remove the first object from the stack of traversed objects. + aStack.pop(); + bStack.pop(); + return result; + }; + + // Perform a deep comparison to check if two objects are equal. + _.isEqual = function(a, b) { + return eq(a, b, [], []); + }; + + // Is a given array, string, or object empty? + // An "empty" object has no enumerable own-properties. + _.isEmpty = function(obj) { + if (obj == null) return true; + if (_.isArray(obj) || _.isString(obj)) return obj.length === 0; + for (var key in obj) if (_.has(obj, key)) return false; + return true; + }; + + // Is a given value a DOM element? + _.isElement = function(obj) { + return !!(obj && obj.nodeType === 1); + }; + + // Is a given value an array? + // Delegates to ECMA5's native Array.isArray + _.isArray = nativeIsArray || function(obj) { + return toString.call(obj) == '[object Array]'; + }; + + // Is a given variable an object? + _.isObject = function(obj) { + return obj === Object(obj); + }; + + // Add some isType methods: isArguments, isFunction, isString, isNumber, isDate, isRegExp. + each(['Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp'], function(name) { + _['is' + name] = function(obj) { + return toString.call(obj) == '[object ' + name + ']'; + }; + }); + + // Define a fallback version of the method in browsers (ahem, IE), where + // there isn't any inspectable "Arguments" type. + if (!_.isArguments(arguments)) { + _.isArguments = function(obj) { + return !!(obj && _.has(obj, 'callee')); + }; + } + + // Optimize `isFunction` if appropriate. + if (typeof (/./) !== 'function') { + _.isFunction = function(obj) { + return typeof obj === 'function'; + }; + } + + // Is a given object a finite number? + _.isFinite = function(obj) { + return isFinite(obj) && !isNaN(parseFloat(obj)); + }; + + // Is the given value `NaN`? (NaN is the only number which does not equal itself). + _.isNaN = function(obj) { + return _.isNumber(obj) && obj != +obj; + }; + + // Is a given value a boolean? + _.isBoolean = function(obj) { + return obj === true || obj === false || toString.call(obj) == '[object Boolean]'; + }; + + // Is a given value equal to null? + _.isNull = function(obj) { + return obj === null; + }; + + // Is a given variable undefined? + _.isUndefined = function(obj) { + return obj === void 0; + }; + + // Shortcut function for checking if an object has a given property directly + // on itself (in other words, not on a prototype). + _.has = function(obj, key) { + return hasOwnProperty.call(obj, key); + }; + + // Utility Functions + // ----------------- + + // Run Underscore.js in *noConflict* mode, returning the `_` variable to its + // previous owner. Returns a reference to the Underscore object. + _.noConflict = function() { + root._ = previousUnderscore; + return this; + }; + + // Keep the identity function around for default iterators. + _.identity = function(value) { + return value; + }; + + // Run a function **n** times. + _.times = function(n, iterator, context) { + var accum = Array(n); + for (var i = 0; i < n; i++) accum[i] = iterator.call(context, i); + return accum; + }; + + // Return a random integer between min and max (inclusive). + _.random = function(min, max) { + if (max == null) { + max = min; + min = 0; + } + return min + Math.floor(Math.random() * (max - min + 1)); + }; + + // List of HTML entities for escaping. + var entityMap = { + escape: { + '&': '&', + '<': '<', + '>': '>', + '"': '"', + "'": ''', + '/': '/' + } + }; + entityMap.unescape = _.invert(entityMap.escape); + + // Regexes containing the keys and values listed immediately above. + var entityRegexes = { + escape: new RegExp('[' + _.keys(entityMap.escape).join('') + ']', 'g'), + unescape: new RegExp('(' + _.keys(entityMap.unescape).join('|') + ')', 'g') + }; + + // Functions for escaping and unescaping strings to/from HTML interpolation. + _.each(['escape', 'unescape'], function(method) { + _[method] = function(string) { + if (string == null) return ''; + return ('' + string).replace(entityRegexes[method], function(match) { + return entityMap[method][match]; + }); + }; + }); + + // If the value of the named property is a function then invoke it; + // otherwise, return it. + _.result = function(object, property) { + if (object == null) return null; + var value = object[property]; + return _.isFunction(value) ? value.call(object) : value; + }; + + // Add your own custom functions to the Underscore object. + _.mixin = function(obj) { + each(_.functions(obj), function(name){ + var func = _[name] = obj[name]; + _.prototype[name] = function() { + var args = [this._wrapped]; + push.apply(args, arguments); + return result.call(this, func.apply(_, args)); + }; + }); + }; + + // Generate a unique integer id (unique within the entire client session). + // Useful for temporary DOM ids. + var idCounter = 0; + _.uniqueId = function(prefix) { + var id = ++idCounter + ''; + return prefix ? prefix + id : id; + }; + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + // Add a "chain" function, which will delegate to the wrapper. + _.chain = function(obj) { + return _(obj).chain(); + }; + + // OOP + // --------------- + // If Underscore is called as a function, it returns a wrapped object that + // can be used OO-style. This wrapper holds altered versions of all the + // underscore functions. Wrapped objects may be chained. + + // Helper function to continue chaining intermediate results. + var result = function(obj) { + return this._chain ? _(obj).chain() : obj; + }; + + // Add all of the Underscore functions to the wrapper object. + _.mixin(_); + + // Add all mutator Array functions to the wrapper. + each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) { + var method = ArrayProto[name]; + _.prototype[name] = function() { + var obj = this._wrapped; + method.apply(obj, arguments); + if ((name == 'shift' || name == 'splice') && obj.length === 0) delete obj[0]; + return result.call(this, obj); + }; + }); + + // Add all accessor Array functions to the wrapper. + each(['concat', 'join', 'slice'], function(name) { + var method = ArrayProto[name]; + _.prototype[name] = function() { + return result.call(this, method.apply(this._wrapped, arguments)); + }; + }); + + _.extend(_.prototype, { + + // Start chaining a wrapped Underscore object. + chain: function() { + this._chain = true; + return this; + }, + + // Extracts the result from a wrapped and chained object. + value: function() { + return this._wrapped; + } + + }); + +}).call(this); diff --git a/public/404.html b/public/404.html new file mode 100644 index 0000000..a0daa0c --- /dev/null +++ b/public/404.html @@ -0,0 +1,58 @@ + + + + The page you were looking for doesn't exist (404) + + + + + +
+

The page you were looking for doesn't exist.

+

You may have mistyped the address or the page may have moved.

+
+

If you are the application owner check the logs for more information.

+ + diff --git a/public/422.html b/public/422.html new file mode 100644 index 0000000..fbb4b84 --- /dev/null +++ b/public/422.html @@ -0,0 +1,58 @@ + + + + The change you wanted was rejected (422) + + + + + +
+

The change you wanted was rejected.

+

Maybe you tried to change something you didn't have access to.

+
+

If you are the application owner check the logs for more information.

+ + diff --git a/public/500.html b/public/500.html new file mode 100644 index 0000000..e9052d3 --- /dev/null +++ b/public/500.html @@ -0,0 +1,57 @@ + + + + We're sorry, but something went wrong (500) + + + + + +
+

We're sorry, but something went wrong.

+
+

If you are the application owner check the logs for more information.

+ + diff --git a/public/favicon.ico b/public/favicon.ico new file mode 100644 index 0000000..e69de29 diff --git a/public/robots.txt b/public/robots.txt new file mode 100644 index 0000000..1a3a5e4 --- /dev/null +++ b/public/robots.txt @@ -0,0 +1,5 @@ +# See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file +# +# To ban all spiders from the entire site uncomment the next two lines: +# User-agent: * +# Disallow: / diff --git a/test/controllers/.keep b/test/controllers/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/fixtures/.keep b/test/fixtures/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/helpers/.keep b/test/helpers/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/integration/.keep b/test/integration/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/mailers/.keep b/test/mailers/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/models/.keep b/test/models/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 0000000..bc7e05d --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,15 @@ +ENV["RAILS_ENV"] ||= "test" +require File.expand_path('../../config/environment', __FILE__) +require 'rails/test_help' + +class ActiveSupport::TestCase + ActiveRecord::Migration.check_pending! + + # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. + # + # Note: You'll currently still have to declare fixtures explicitly in integration tests + # -- they do not yet inherit this setting + fixtures :all + + # Add more helper methods to be used by all tests here... +end diff --git a/vendor/assets/javascripts/.keep b/vendor/assets/javascripts/.keep new file mode 100644 index 0000000..e69de29 diff --git a/vendor/assets/stylesheets/.keep b/vendor/assets/stylesheets/.keep new file mode 100644 index 0000000..e69de29