sinatra-template 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ require "sinatra/template/version"
2
+
3
+ module Sinatra
4
+ module Template
5
+ # Your code goes here...
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module Sinatra
2
+ module Template
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sinatra/template/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "sinatra-template"
8
+ gem.version = Sinatra::Template::VERSION
9
+ gem.authors = ["Mark Bates"]
10
+ gem.email = ["mark@markbates.com"]
11
+ gem.description = %q{A starter template and generators for Sinatra}
12
+ gem.summary = %q{A starter template and generators for Sinatra}
13
+ gem.homepage = ""
14
+ gem.license = "MIT"
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+
21
+ gem.add_development_dependency "rake"
22
+ end
@@ -0,0 +1,9 @@
1
+ describe Sinatra::Template do
2
+ it 'should have a version number' do
3
+ Sinatra::Template::VERSION.should_not be_nil
4
+ end
5
+
6
+ it 'should do something useful' do
7
+ false.should be_true
8
+ end
9
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'sinatra/template'
@@ -0,0 +1,21 @@
1
+ *.log
2
+ .DS_Store
3
+ doc
4
+ tmp
5
+ pkg
6
+ *.gem
7
+ *.pid
8
+ coverage
9
+ coverage.data
10
+ build/*
11
+ *.pbxuser
12
+ *.mode1v3
13
+ .svn
14
+ profile
15
+ .console_history
16
+ .sass-cache/*
17
+ .rake_tasks~
18
+ *.log.lck
19
+ solr/
20
+ .jhw-cache/
21
+ jhw.*
data/template/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ gem 'thin'
2
+ gem 'sass'
3
+ gem 'coffee-script'
4
+ gem 'sinatra'
5
+ gem "sinatra-twitter-bootstrap", github: "mifo/sinatra-twitter-bootstrap"
6
+ gem 'sprockets'
7
+ gem 'shotgun'
8
+ gem 'foreman'
9
+ gem 'mongoid'
10
+ gem 'activesupport'
11
+
12
+ group :development, :test do
13
+ gem 'rack-test'
14
+ gem 'rspec'
15
+ gem 'pry'
16
+ end
@@ -0,0 +1,85 @@
1
+ GIT
2
+ remote: git://github.com/mifo/sinatra-twitter-bootstrap.git
3
+ revision: 6433f8c6cb429ee1f2d3ed5d17617b99201632ca
4
+ specs:
5
+ sinatra-twitter-bootstrap (2.2.2)
6
+
7
+ GEM
8
+ specs:
9
+ activemodel (3.2.9)
10
+ activesupport (= 3.2.9)
11
+ builder (~> 3.0.0)
12
+ activesupport (3.2.9)
13
+ i18n (~> 0.6)
14
+ multi_json (~> 1.0)
15
+ builder (3.0.4)
16
+ coffee-script (2.2.0)
17
+ coffee-script-source
18
+ execjs
19
+ coffee-script-source (1.4.0)
20
+ daemons (1.1.9)
21
+ diff-lcs (1.1.3)
22
+ eventmachine (1.0.0)
23
+ execjs (1.4.0)
24
+ multi_json (~> 1.0)
25
+ foreman (0.60.2)
26
+ thor (>= 0.13.6)
27
+ hike (1.2.1)
28
+ i18n (0.6.1)
29
+ mongoid (3.0.15)
30
+ activemodel (~> 3.1)
31
+ moped (~> 1.1)
32
+ origin (~> 1.0)
33
+ tzinfo (~> 0.3.22)
34
+ moped (1.3.1)
35
+ multi_json (1.5.0)
36
+ origin (1.0.11)
37
+ rack (1.4.1)
38
+ rack-protection (1.3.2)
39
+ rack
40
+ rack-test (0.6.2)
41
+ rack (>= 1.0)
42
+ rspec (2.12.0)
43
+ rspec-core (~> 2.12.0)
44
+ rspec-expectations (~> 2.12.0)
45
+ rspec-mocks (~> 2.12.0)
46
+ rspec-core (2.12.2)
47
+ rspec-expectations (2.12.1)
48
+ diff-lcs (~> 1.1.3)
49
+ rspec-mocks (2.12.1)
50
+ sass (3.2.4)
51
+ shotgun (0.9)
52
+ rack (>= 1.0)
53
+ sinatra (1.3.3)
54
+ rack (~> 1.3, >= 1.3.6)
55
+ rack-protection (~> 1.2)
56
+ tilt (~> 1.3, >= 1.3.3)
57
+ sprockets (2.2.2)
58
+ hike (~> 1.2)
59
+ multi_json (~> 1.0)
60
+ rack (~> 1.0)
61
+ tilt (~> 1.1, != 1.3.0)
62
+ thin (1.5.0)
63
+ daemons (>= 1.0.9)
64
+ eventmachine (>= 0.12.6)
65
+ rack (>= 1.0.0)
66
+ thor (0.16.0)
67
+ tilt (1.3.3)
68
+ tzinfo (0.3.35)
69
+
70
+ PLATFORMS
71
+ ruby
72
+
73
+ DEPENDENCIES
74
+ activesupport
75
+ coffee-script
76
+ foreman
77
+ mongoid
78
+ rack-test
79
+ rspec
80
+ sass
81
+ shotgun
82
+ sinatra
83
+ sinatra-twitter-bootstrap!
84
+ sprockets
85
+ thin
data/template/Procfile ADDED
@@ -0,0 +1 @@
1
+ web: bundle exec rackup config.ru
@@ -0,0 +1 @@
1
+ web: bundle exec shotgun config.ru -p 9292
@@ -0,0 +1,38 @@
1
+ # Sinatra Template
2
+
3
+ This is my starter for building Sinatra applications. Take it for what it is.
4
+
5
+ ## Generate a New Application
6
+
7
+ First download the repo locally:
8
+
9
+ ```bash
10
+ $ git clone git://github.com/markbates/sinatra-template.git
11
+ ```
12
+
13
+ Second run the generate command against the directory you want to create:
14
+
15
+ ```bash
16
+ $ ruby PATH/TO/generate.rb awesome_app
17
+ ```
18
+
19
+ ```bash
20
+ $ cd awesome_app
21
+ $ bundle
22
+ ```
23
+
24
+ That's it! You're new application should be generated.
25
+
26
+ ## Run the Application
27
+
28
+ ```bash
29
+ $ cd awesome_app
30
+ $ foreman start
31
+ ```
32
+
33
+ ## Tests
34
+
35
+ ```bash
36
+ $ cd awesome_app
37
+ $ rake
38
+ ```
data/template/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ task :default do
2
+ system "bundle exec rspec"
3
+ end
@@ -0,0 +1,10 @@
1
+ class MyApp < Sinatra::Base
2
+ register Sinatra::Twitter::Bootstrap::Assets
3
+
4
+ set :views, File.join(settings.views, "my_app")
5
+
6
+ get "/" do
7
+ erb :index
8
+ end
9
+
10
+ end
@@ -0,0 +1 @@
1
+ MyApp!
@@ -0,0 +1,49 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>MyApp</title>
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <meta name="description" content="">
8
+ <meta name="author" content="">
9
+
10
+ <script src='/assets/application.js'></script>
11
+ <%= bootstrap_assets %>
12
+ <link href="/assets/application.css" rel="stylesheet">
13
+
14
+ <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
15
+ <!--[if lt IE 9]>
16
+ <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
17
+ <![endif]-->
18
+ </head>
19
+
20
+ <body>
21
+
22
+ <div class="navbar navbar-inverse navbar-fixed-top">
23
+ <div class="navbar-inner">
24
+ <!-- <div class="container">
25
+ <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
26
+ <span class="icon-bar"></span>
27
+ <span class="icon-bar"></span>
28
+ <span class="icon-bar"></span>
29
+ </a>
30
+ <a class="brand" href="#">Project name</a>
31
+ <div class="nav-collapse collapse">
32
+ <ul class="nav">
33
+ <li class="active"><a href="#">Home</a></li>
34
+ <li><a href="#about">About</a></li>
35
+ <li><a href="#contact">Contact</a></li>
36
+ </ul>
37
+ </div>
38
+ </div> -->
39
+ </div>
40
+ </div>
41
+
42
+ <div class="container" id='main'>
43
+
44
+ <%= yield %>
45
+
46
+ </div> <!-- /container -->
47
+
48
+ </body>
49
+ </html>
@@ -0,0 +1,7 @@
1
+ #= require jquery
2
+ #= require json2
3
+ #= require underscore
4
+ #= require backbone
5
+
6
+ $ ->
7
+ $("#main").append("jQuery works!")
@@ -0,0 +1,3 @@
1
+ body {
2
+ padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
3
+ }
File without changes
@@ -0,0 +1,19 @@
1
+ $stdout.sync = true
2
+
3
+ require './setup'
4
+
5
+ map '/assets' do
6
+ environment = Sprockets::Environment.new
7
+ %w{javascripts stylesheets images templates}.each do |path|
8
+ environment.append_path "./assets/#{path}"
9
+ environment.append_path "./vendor/assets/#{path}"
10
+ end
11
+ run environment
12
+ end
13
+
14
+ use Rack::MethodOverride
15
+
16
+ map "/" do
17
+ run MyApp
18
+ end
19
+
File without changes
@@ -0,0 +1,28 @@
1
+ development:
2
+ sessions:
3
+ default:
4
+ database: my_app_development
5
+ hosts:
6
+ - localhost:27017
7
+ test:
8
+ sessions:
9
+ default:
10
+ database: my_app_test
11
+ hosts:
12
+ - localhost:27017
13
+
14
+ production:
15
+ sessions:
16
+ default:
17
+ uri: <%= ENV['MONGOHQ_URL'] %>
18
+ options:
19
+ skip_version_check: true
20
+ use_utc: true
21
+
22
+ staging:
23
+ sessions:
24
+ default:
25
+ uri: <%= ENV['MONGOHQ_URL'] %>
26
+ options:
27
+ skip_version_check: true
28
+ use_utc: true
File without changes
data/template/setup.rb ADDED
@@ -0,0 +1,19 @@
1
+ require 'bundler'
2
+ Bundler.setup
3
+
4
+ require 'active_support/core_ext'
5
+ require 'sinatra/base'
6
+ require 'sinatra/twitter-bootstrap'
7
+ require 'sprockets'
8
+ require 'mongoid'
9
+ require 'json'
10
+
11
+ env = ENV["RACK_ENV"] ? ENV["RACK_ENV"] : "development"
12
+
13
+ Mongoid.load!(File.join(File.dirname(__FILE__), "mongoid.yml"), env.to_sym)
14
+
15
+ %w{apps models}.each do |dir|
16
+ Dir[File.expand_path(File.join(dir, "**", "*.rb"), File.dirname(__FILE__))].each do |file|
17
+ require file
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe MyApp do
4
+
5
+ def app
6
+ MyApp
7
+ end
8
+
9
+ it "says hello" do
10
+ get '/'
11
+ last_response.should be_ok
12
+ last_response.body.should match("MyApp!")
13
+ end
14
+
15
+ end
@@ -0,0 +1,10 @@
1
+ require 'rspec'
2
+ require 'rack/test'
3
+
4
+ ENV['RACK_ENV'] = 'test'
5
+
6
+ require File.expand_path(File.join("..", "setup.rb"), File.dirname(__FILE__))
7
+
8
+ RSpec.configure do |conf|
9
+ conf.include Rack::Test::Methods
10
+ end
@@ -0,0 +1,42 @@
1
+ // Backbone.js 0.9.9
2
+
3
+ // (c) 2010-2012 Jeremy Ashkenas, DocumentCloud Inc.
4
+ // Backbone may be freely distributed under the MIT license.
5
+ // For all details and documentation:
6
+ // http://backbonejs.org
7
+ (function(){var k=this,y=k.Backbone,h=[],z=h.push,r=h.slice,A=h.splice,g;g="undefined"!==typeof exports?exports:k.Backbone={};g.VERSION="0.9.9";var e=k._;!e&&"undefined"!==typeof require&&(e=require("underscore"));g.$=k.jQuery||k.Zepto||k.ender;g.noConflict=function(){k.Backbone=y;return this};g.emulateHTTP=!1;g.emulateJSON=!1;var s=/\s+/,n=function(a,b,c,d){if(!c)return!0;if("object"===typeof c)for(var f in c)a[b].apply(a,[f,c[f]].concat(d));else if(s.test(c)){c=c.split(s);f=0;for(var e=c.length;f<
8
+ e;f++)a[b].apply(a,[c[f]].concat(d))}else return!0},t=function(a,b,c){var d,a=-1,f=b.length;switch(c.length){case 0:for(;++a<f;)(d=b[a]).callback.call(d.ctx);break;case 1:for(;++a<f;)(d=b[a]).callback.call(d.ctx,c[0]);break;case 2:for(;++a<f;)(d=b[a]).callback.call(d.ctx,c[0],c[1]);break;case 3:for(;++a<f;)(d=b[a]).callback.call(d.ctx,c[0],c[1],c[2]);break;default:for(;++a<f;)(d=b[a]).callback.apply(d.ctx,c)}},h=g.Events={on:function(a,b,c){if(!n(this,"on",a,[b,c])||!b)return this;this._events||(this._events=
9
+ {});(this._events[a]||(this._events[a]=[])).push({callback:b,context:c,ctx:c||this});return this},once:function(a,b,c){if(!n(this,"once",a,[b,c])||!b)return this;var d=this,f=e.once(function(){d.off(a,f);b.apply(this,arguments)});f._callback=b;this.on(a,f,c);return this},off:function(a,b,c){var d,f,l,g,i,m,h,j;if(!this._events||!n(this,"off",a,[b,c]))return this;if(!a&&!b&&!c)return this._events={},this;g=a?[a]:e.keys(this._events);i=0;for(m=g.length;i<m;i++)if(a=g[i],d=this._events[a]){l=[];if(b||
10
+ c){h=0;for(j=d.length;h<j;h++)f=d[h],(b&&b!==(f.callback._callback||f.callback)||c&&c!==f.context)&&l.push(f)}this._events[a]=l}return this},trigger:function(a){if(!this._events)return this;var b=r.call(arguments,1);if(!n(this,"trigger",a,b))return this;var c=this._events[a],d=this._events.all;c&&t(this,c,b);d&&t(this,d,arguments);return this},listenTo:function(a,b,c){var d=this._listeners||(this._listeners={}),f=a._listenerId||(a._listenerId=e.uniqueId("l"));d[f]=a;a.on(b,c||this,this);return this},
11
+ stopListening:function(a,b,c){var d=this._listeners;if(d){if(a)a.off(b,c,this),!b&&!c&&delete d[a._listenerId];else{for(var f in d)d[f].off(null,null,this);this._listeners={}}return this}}};h.bind=h.on;h.unbind=h.off;e.extend(g,h);var o=g.Model=function(a,b){var c,d=a||{};this.cid=e.uniqueId("c");this.changed={};this.attributes={};this._changes=[];b&&b.collection&&(this.collection=b.collection);b&&b.parse&&(d=this.parse(d));(c=e.result(this,"defaults"))&&e.defaults(d,c);this.set(d,{silent:!0});this._currentAttributes=
12
+ e.clone(this.attributes);this._previousAttributes=e.clone(this.attributes);this.initialize.apply(this,arguments)};e.extend(o.prototype,h,{changed:null,idAttribute:"id",initialize:function(){},toJSON:function(){return e.clone(this.attributes)},sync:function(){return g.sync.apply(this,arguments)},get:function(a){return this.attributes[a]},escape:function(a){return e.escape(this.get(a))},has:function(a){return null!=this.get(a)},set:function(a,b,c){var d,f;if(null==a)return this;e.isObject(a)?(f=a,c=
13
+ b):(f={})[a]=b;var a=c&&c.silent,l=c&&c.unset;if(!this._validate(f,c))return!1;this.idAttribute in f&&(this.id=f[this.idAttribute]);var g=this.attributes;for(d in f)b=f[d],l?delete g[d]:g[d]=b,this._changes.push(d,b);this._hasComputed=!1;a||this.change(c);return this},unset:function(a,b){return this.set(a,void 0,e.extend({},b,{unset:!0}))},clear:function(a){var b={},c;for(c in this.attributes)b[c]=void 0;return this.set(b,e.extend({},a,{unset:!0}))},fetch:function(a){a=a?e.clone(a):{};void 0===a.parse&&
14
+ (a.parse=!0);var b=this,c=a.success;a.success=function(d){if(!b.set(b.parse(d),a))return false;c&&c(b,d,a)};return this.sync("read",this,a)},save:function(a,b,c){var d,f,g;null==a||e.isObject(a)?(d=a,c=b):null!=a&&((d={})[a]=b);c=c?e.clone(c):{};if(c.wait){if(d&&!this._validate(d,c))return!1;f=e.clone(this.attributes)}a=e.extend({},c,{silent:!0});if(d&&!this.set(d,c.wait?a:c)||!d&&!this._validate(null,c))return!1;var q=this,i=c.success;c.success=function(a){g=true;var b=q.parse(a);c.wait&&(b=e.extend(d||
15
+ {},b));if(!q.set(b,c))return false;i&&i(q,a,c)};b=this.isNew()?"create":c.patch?"patch":"update";"patch"==b&&(c.attrs=d);b=this.sync(b,this,c);!g&&c.wait&&(this.clear(a),this.set(f,a));return b},destroy:function(a){var a=a?e.clone(a):{},b=this,c=a.success,d=function(){b.trigger("destroy",b,b.collection,a)};a.success=function(f){(a.wait||b.isNew())&&d();c&&c(b,f,a)};if(this.isNew())return a.success(),!1;var f=this.sync("delete",this,a);a.wait||d();return f},url:function(){var a=e.result(this,"urlRoot")||
16
+ e.result(this.collection,"url")||u();return this.isNew()?a:a+("/"===a.charAt(a.length-1)?"":"/")+encodeURIComponent(this.id)},parse:function(a){return a},clone:function(){return new this.constructor(this.attributes)},isNew:function(){return null==this.id},change:function(a){var b=this._changing;this._changing=!0;var c=this._computeChanges(!0);this._pending=!!c.length;for(var d=c.length-2;0<=d;d-=2)this.trigger("change:"+c[d],this,c[d+1],a);if(b)return this;for(;this._pending;)this._pending=!1,this.trigger("change",
17
+ this,a),this._previousAttributes=e.clone(this.attributes);this._changing=!1;return this},hasChanged:function(a){this._hasComputed||this._computeChanges();return null==a?!e.isEmpty(this.changed):e.has(this.changed,a)},changedAttributes:function(a){if(!a)return this.hasChanged()?e.clone(this.changed):!1;var b,c=!1,d=this._previousAttributes,f;for(f in a)if(!e.isEqual(d[f],b=a[f]))(c||(c={}))[f]=b;return c},_computeChanges:function(a){this.changed={};for(var b={},c=[],d=this._currentAttributes,f=this._changes,
18
+ e=f.length-2;0<=e;e-=2){var g=f[e],i=f[e+1];b[g]||(b[g]=!0,d[g]!==i&&(this.changed[g]=i,a&&(c.push(g,i),d[g]=i)))}a&&(this._changes=[]);this._hasComputed=!0;return c},previous:function(a){return null==a||!this._previousAttributes?null:this._previousAttributes[a]},previousAttributes:function(){return e.clone(this._previousAttributes)},_validate:function(a,b){if(!this.validate)return!0;var a=e.extend({},this.attributes,a),c=this.validate(a,b);if(!c)return!0;b&&b.error&&b.error(this,c,b);this.trigger("error",
19
+ this,c,b);return!1}});var p=g.Collection=function(a,b){b||(b={});b.model&&(this.model=b.model);void 0!==b.comparator&&(this.comparator=b.comparator);this._reset();this.initialize.apply(this,arguments);a&&this.reset(a,e.extend({silent:!0},b))};e.extend(p.prototype,h,{model:o,initialize:function(){},toJSON:function(a){return this.map(function(b){return b.toJSON(a)})},sync:function(){return g.sync.apply(this,arguments)},add:function(a,b){var c,d,f,g,h=b&&b.at,i=null==(b&&b.sort)?!0:b.sort,a=e.isArray(a)?
20
+ a.slice():[a];for(c=a.length-1;0<=c;c--)(d=this._prepareModel(a[c],b))?(a[c]=d,(f=null!=d.id&&this._byId[d.id])||this._byCid[d.cid]?(b&&(b.merge&&f)&&(f.set(d.attributes,b),g=i),a.splice(c,1)):(d.on("all",this._onModelEvent,this),this._byCid[d.cid]=d,null!=d.id&&(this._byId[d.id]=d))):(this.trigger("error",this,a[c],b),a.splice(c,1));a.length&&(g=i);this.length+=a.length;c=[null!=h?h:this.models.length,0];z.apply(c,a);A.apply(this.models,c);g&&(this.comparator&&null==h)&&this.sort({silent:!0});if(b&&
21
+ b.silent)return this;for(;d=a.shift();)d.trigger("add",d,this,b);return this},remove:function(a,b){var c,d,f,g;b||(b={});a=e.isArray(a)?a.slice():[a];c=0;for(d=a.length;c<d;c++)if(g=this.get(a[c]))delete this._byId[g.id],delete this._byCid[g.cid],f=this.indexOf(g),this.models.splice(f,1),this.length--,b.silent||(b.index=f,g.trigger("remove",g,this,b)),this._removeReference(g);return this},push:function(a,b){a=this._prepareModel(a,b);this.add(a,e.extend({at:this.length},b));return a},pop:function(a){var b=
22
+ this.at(this.length-1);this.remove(b,a);return b},unshift:function(a,b){a=this._prepareModel(a,b);this.add(a,e.extend({at:0},b));return a},shift:function(a){var b=this.at(0);this.remove(b,a);return b},slice:function(a,b){return this.models.slice(a,b)},get:function(a){return null==a?void 0:this._byId[null!=a.id?a.id:a]||this._byCid[a.cid||a]},at:function(a){return this.models[a]},where:function(a){return e.isEmpty(a)?[]:this.filter(function(b){for(var c in a)if(a[c]!==b.get(c))return!1;return!0})},
23
+ sort:function(a){if(!this.comparator)throw Error("Cannot sort a set without a comparator");e.isString(this.comparator)||1===this.comparator.length?this.models=this.sortBy(this.comparator,this):this.models.sort(e.bind(this.comparator,this));(!a||!a.silent)&&this.trigger("sort",this,a);return this},pluck:function(a){return e.invoke(this.models,"get",a)},update:function(a,b){var c,d,f,g,h=[],i=[],m={},j=this.model.prototype.idAttribute,b=e.extend({add:!0,merge:!0,remove:!0},b);b.parse&&(a=this.parse(a));
24
+ e.isArray(a)||(a=a?[a]:[]);if(b.add&&!b.remove)return this.add(a,b);d=0;for(f=a.length;d<f;d++)c=a[d],g=this.get(c.id||c.cid||c[j]),b.remove&&g&&(m[g.cid]=!0),(b.add&&!g||b.merge&&g)&&h.push(c);if(b.remove){d=0;for(f=this.models.length;d<f;d++)c=this.models[d],m[c.cid]||i.push(c)}i.length&&this.remove(i,b);h.length&&this.add(h,b);return this},reset:function(a,b){b||(b={});b.parse&&(a=this.parse(a));for(var c=0,d=this.models.length;c<d;c++)this._removeReference(this.models[c]);b.previousModels=this.models;
25
+ this._reset();a&&this.add(a,e.extend({silent:!0},b));b.silent||this.trigger("reset",this,b);return this},fetch:function(a){a=a?e.clone(a):{};void 0===a.parse&&(a.parse=!0);var b=this,c=a.success;a.success=function(d){b[a.update?"update":"reset"](d,a);c&&c(b,d,a)};return this.sync("read",this,a)},create:function(a,b){var c=this,b=b?e.clone(b):{},a=this._prepareModel(a,b);if(!a)return!1;b.wait||c.add(a,b);var d=b.success;b.success=function(a,b,e){e.wait&&c.add(a,e);d&&d(a,b,e)};a.save(null,b);return a},
26
+ parse:function(a){return a},clone:function(){return new this.constructor(this.models)},chain:function(){return e(this.models).chain()},_reset:function(){this.length=0;this.models=[];this._byId={};this._byCid={}},_prepareModel:function(a,b){if(a instanceof o)return a.collection||(a.collection=this),a;b||(b={});b.collection=this;var c=new this.model(a,b);return!c._validate(a,b)?!1:c},_removeReference:function(a){this===a.collection&&delete a.collection;a.off("all",this._onModelEvent,this)},_onModelEvent:function(a,
27
+ b,c,d){("add"===a||"remove"===a)&&c!==this||("destroy"===a&&this.remove(b,d),b&&a==="change:"+b.idAttribute&&(delete this._byId[b.previous(b.idAttribute)],null!=b.id&&(this._byId[b.id]=b)),this.trigger.apply(this,arguments))}});e.each("forEach each map collect reduce foldl inject reduceRight foldr find detect filter select reject every all some any include contains invoke max min sortedIndex toArray size first head take initial rest tail last without indexOf shuffle lastIndexOf isEmpty".split(" "),
28
+ function(a){p.prototype[a]=function(){var b=r.call(arguments);b.unshift(this.models);return e[a].apply(e,b)}});e.each(["groupBy","countBy","sortBy"],function(a){p.prototype[a]=function(b,c){var d=e.isFunction(b)?b:function(a){return a.get(b)};return e[a](this.models,d,c)}});var v=g.Router=function(a){a||(a={});a.routes&&(this.routes=a.routes);this._bindRoutes();this.initialize.apply(this,arguments)},B=/\((.*?)\)/g,C=/:\w+/g,D=/\*\w+/g,E=/[\-{}\[\]+?.,\\\^$|#\s]/g;e.extend(v.prototype,h,{initialize:function(){},
29
+ route:function(a,b,c){e.isRegExp(a)||(a=this._routeToRegExp(a));c||(c=this[b]);g.history.route(a,e.bind(function(d){d=this._extractParameters(a,d);c&&c.apply(this,d);this.trigger.apply(this,["route:"+b].concat(d));g.history.trigger("route",this,b,d)},this));return this},navigate:function(a,b){g.history.navigate(a,b);return this},_bindRoutes:function(){if(this.routes)for(var a,b=e.keys(this.routes);null!=(a=b.pop());)this.route(a,this.routes[a])},_routeToRegExp:function(a){a=a.replace(E,"\\$&").replace(B,
30
+ "(?:$1)?").replace(C,"([^/]+)").replace(D,"(.*?)");return RegExp("^"+a+"$")},_extractParameters:function(a,b){return a.exec(b).slice(1)}});var j=g.History=function(){this.handlers=[];e.bindAll(this,"checkUrl");"undefined"!==typeof window&&(this.location=window.location,this.history=window.history)},w=/^[#\/]|\s+$/g,F=/^\/+|\/+$/g,G=/msie [\w.]+/,H=/\/$/;j.started=!1;e.extend(j.prototype,h,{interval:50,getHash:function(a){return(a=(a||this).location.href.match(/#(.*)$/))?a[1]:""},getFragment:function(a,
31
+ b){if(null==a)if(this._hasPushState||!this._wantsHashChange||b){var a=this.location.pathname,c=this.root.replace(H,"");a.indexOf(c)||(a=a.substr(c.length))}else a=this.getHash();return a.replace(w,"")},start:function(a){if(j.started)throw Error("Backbone.history has already been started");j.started=!0;this.options=e.extend({},{root:"/"},this.options,a);this.root=this.options.root;this._wantsHashChange=!1!==this.options.hashChange;this._wantsPushState=!!this.options.pushState;this._hasPushState=!(!this.options.pushState||
32
+ !this.history||!this.history.pushState);var a=this.getFragment(),b=document.documentMode,b=G.exec(navigator.userAgent.toLowerCase())&&(!b||7>=b);this.root=("/"+this.root+"/").replace(F,"/");b&&this._wantsHashChange&&(this.iframe=g.$('<iframe src="javascript:0" tabindex="-1" />').hide().appendTo("body")[0].contentWindow,this.navigate(a));this._hasPushState?g.$(window).bind("popstate",this.checkUrl):this._wantsHashChange&&"onhashchange"in window&&!b?g.$(window).bind("hashchange",this.checkUrl):this._wantsHashChange&&
33
+ (this._checkUrlInterval=setInterval(this.checkUrl,this.interval));this.fragment=a;a=this.location;b=a.pathname.replace(/[^\/]$/,"$&/")===this.root;if(this._wantsHashChange&&this._wantsPushState&&!this._hasPushState&&!b)return this.fragment=this.getFragment(null,!0),this.location.replace(this.root+this.location.search+"#"+this.fragment),!0;this._wantsPushState&&(this._hasPushState&&b&&a.hash)&&(this.fragment=this.getHash().replace(w,""),this.history.replaceState({},document.title,this.root+this.fragment+
34
+ a.search));if(!this.options.silent)return this.loadUrl()},stop:function(){g.$(window).unbind("popstate",this.checkUrl).unbind("hashchange",this.checkUrl);clearInterval(this._checkUrlInterval);j.started=!1},route:function(a,b){this.handlers.unshift({route:a,callback:b})},checkUrl:function(){var a=this.getFragment();a===this.fragment&&this.iframe&&(a=this.getFragment(this.getHash(this.iframe)));if(a===this.fragment)return!1;this.iframe&&this.navigate(a);this.loadUrl()||this.loadUrl(this.getHash())},
35
+ loadUrl:function(a){var b=this.fragment=this.getFragment(a);return e.any(this.handlers,function(a){if(a.route.test(b))return a.callback(b),!0})},navigate:function(a,b){if(!j.started)return!1;if(!b||!0===b)b={trigger:b};a=this.getFragment(a||"");if(this.fragment!==a){this.fragment=a;var c=this.root+a;if(this._hasPushState)this.history[b.replace?"replaceState":"pushState"]({},document.title,c);else if(this._wantsHashChange)this._updateHash(this.location,a,b.replace),this.iframe&&a!==this.getFragment(this.getHash(this.iframe))&&
36
+ (b.replace||this.iframe.document.open().close(),this._updateHash(this.iframe.location,a,b.replace));else return this.location.assign(c);b.trigger&&this.loadUrl(a)}},_updateHash:function(a,b,c){c?(c=a.href.replace(/(javascript:|#).*$/,""),a.replace(c+"#"+b)):a.hash="#"+b}});g.history=new j;var x=g.View=function(a){this.cid=e.uniqueId("view");this._configure(a||{});this._ensureElement();this.initialize.apply(this,arguments);this.delegateEvents()},I=/^(\S+)\s*(.*)$/,J="model collection el id attributes className tagName events".split(" ");
37
+ e.extend(x.prototype,h,{tagName:"div",$:function(a){return this.$el.find(a)},initialize:function(){},render:function(){return this},remove:function(){this.$el.remove();this.stopListening();return this},make:function(a,b,c){a=document.createElement(a);b&&g.$(a).attr(b);null!=c&&g.$(a).html(c);return a},setElement:function(a,b){this.$el&&this.undelegateEvents();this.$el=a instanceof g.$?a:g.$(a);this.el=this.$el[0];!1!==b&&this.delegateEvents();return this},delegateEvents:function(a){if(a||(a=e.result(this,
38
+ "events"))){this.undelegateEvents();for(var b in a){var c=a[b];e.isFunction(c)||(c=this[a[b]]);if(!c)throw Error('Method "'+a[b]+'" does not exist');var d=b.match(I),f=d[1],d=d[2],c=e.bind(c,this),f=f+(".delegateEvents"+this.cid);""===d?this.$el.bind(f,c):this.$el.delegate(d,f,c)}}},undelegateEvents:function(){this.$el.unbind(".delegateEvents"+this.cid)},_configure:function(a){this.options&&(a=e.extend({},e.result(this,"options"),a));e.extend(this,e.pick(a,J));this.options=a},_ensureElement:function(){if(this.el)this.setElement(e.result(this,
39
+ "el"),!1);else{var a=e.extend({},e.result(this,"attributes"));this.id&&(a.id=e.result(this,"id"));this.className&&(a["class"]=e.result(this,"className"));this.setElement(this.make(e.result(this,"tagName"),a),!1)}}});var K={create:"POST",update:"PUT",patch:"PATCH","delete":"DELETE",read:"GET"};g.sync=function(a,b,c){var d=K[a];e.defaults(c||(c={}),{emulateHTTP:g.emulateHTTP,emulateJSON:g.emulateJSON});var f={type:d,dataType:"json"};c.url||(f.url=e.result(b,"url")||u());if(null==c.data&&b&&("create"===
40
+ a||"update"===a||"patch"===a))f.contentType="application/json",f.data=JSON.stringify(c.attrs||b.toJSON(c));c.emulateJSON&&(f.contentType="application/x-www-form-urlencoded",f.data=f.data?{model:f.data}:{});if(c.emulateHTTP&&("PUT"===d||"DELETE"===d||"PATCH"===d)){f.type="POST";c.emulateJSON&&(f.data._method=d);var h=c.beforeSend;c.beforeSend=function(a){a.setRequestHeader("X-HTTP-Method-Override",d);if(h)return h.apply(this,arguments)}}"GET"!==f.type&&!c.emulateJSON&&(f.processData=!1);var j=c.success;
41
+ c.success=function(a,d,e){j&&j(a,d,e);b.trigger("sync",b,a,c)};var i=c.error;c.error=function(a){i&&i(b,a,c);b.trigger("error",b,a,c)};a=g.ajax(e.extend(f,c));b.trigger("request",b,a,c);return a};g.ajax=function(){return g.$.ajax.apply(g.$,arguments)};o.extend=p.extend=v.extend=x.extend=j.extend=function(a,b){var c=this,d;d=a&&e.has(a,"constructor")?a.constructor:function(){c.apply(this,arguments)};e.extend(d,c,b);var f=function(){this.constructor=d};f.prototype=c.prototype;d.prototype=new f;a&&e.extend(d.prototype,
42
+ a);d.__super__=c.prototype;return d};var u=function(){throw Error('A "url" property or function must be specified');}}).call(this);