perkins 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +5 -0
  3. data/.ruby-version +1 -0
  4. data/.vagrant/machines/default/virtualbox/action_provision +1 -0
  5. data/.vagrant/machines/default/virtualbox/action_set_name +1 -0
  6. data/.vagrant/machines/default/virtualbox/id +1 -0
  7. data/Gemfile +0 -1
  8. data/README.md +11 -4
  9. data/Rakefile +3 -2
  10. data/TODO.md +2 -2
  11. data/Vagrantfile +53 -0
  12. data/db/migrate/20150220143050_add_status_fields_to_repos.rb +11 -0
  13. data/db/schema.rb +3 -1
  14. data/examples/Gemfile +4 -0
  15. data/examples/Gemfile.lock +164 -0
  16. data/examples/Procfile +4 -0
  17. data/examples/boot.rb +15 -0
  18. data/examples/config.ru +22 -0
  19. data/examples/database.yml +2 -2
  20. data/examples/sidekiq.yml +9 -0
  21. data/lib/core_ext/string/color.rb +22 -0
  22. data/lib/perkins/application.rb +27 -3
  23. data/lib/perkins/assets/images/error.gif +0 -0
  24. data/lib/perkins/assets/images/working.gif +0 -0
  25. data/lib/perkins/assets/javascripts/app.js +17 -1
  26. data/lib/perkins/assets/javascripts/config.js.coffee +14 -0
  27. data/lib/perkins/assets/javascripts/log_view.js.coffee +1 -2
  28. data/lib/perkins/assets/javascripts/perkings.js.coffee +129 -20
  29. data/lib/perkins/assets/javascripts/perkins/helpers.js.coffee +21 -0
  30. data/lib/perkins/assets/javascripts/perkins/m/models.js.coffee +50 -0
  31. data/lib/perkins/assets/javascripts/perkins/router.js.coffee +10 -0
  32. data/lib/perkins/assets/javascripts/perkins/v/dashboard.js.coffee +17 -0
  33. data/lib/perkins/assets/javascripts/perkins/v/err.js.coffee +12 -0
  34. data/lib/perkins/assets/javascripts/perkins/v/menu.js.coffee +10 -0
  35. data/lib/perkins/assets/javascripts/perkins/v/my_repos.js.coffee +41 -0
  36. data/lib/perkins/assets/javascripts/perkins/v/orgs.js.coffee +39 -0
  37. data/lib/perkins/assets/javascripts/perkins/v/profile.js.coffee +20 -0
  38. data/lib/perkins/assets/javascripts/perkins/v/repo.js.coffee +192 -0
  39. data/lib/perkins/assets/javascripts/perkins/v/sidebar.js.coffee +33 -0
  40. data/lib/perkins/assets/javascripts/templates/dashboard.hamlc +11 -0
  41. data/lib/perkins/assets/javascripts/templates/error.hamlc +22 -0
  42. data/lib/perkins/assets/javascripts/templates/menu.hamlc +18 -0
  43. data/lib/perkins/assets/javascripts/templates/org.hamlc +77 -0
  44. data/lib/perkins/assets/javascripts/templates/profile.hamlc +28 -0
  45. data/lib/perkins/assets/javascripts/templates/repo.hamlc +37 -0
  46. data/lib/perkins/assets/javascripts/templates/repos/build_row.hamlc +19 -0
  47. data/lib/perkins/assets/javascripts/templates/repos/builds.hamlc +25 -0
  48. data/lib/perkins/assets/javascripts/templates/repos/config.hamlc +77 -0
  49. data/lib/perkins/assets/javascripts/templates/repos/gb_repo.hamlc +31 -0
  50. data/lib/perkins/assets/javascripts/templates/repos/github.hamlc +7 -0
  51. data/lib/perkins/assets/javascripts/templates/repos/menu.hamlc +17 -0
  52. data/lib/perkins/assets/javascripts/templates/repos/report_detail.hamlc +53 -0
  53. data/lib/perkins/assets/javascripts/templates/sidebar.hamlc +14 -0
  54. data/lib/perkins/assets/javascripts/templates/sidebar_repo.hamlc +4 -0
  55. data/lib/perkins/assets/javascripts/vendor/backbone-min.js +2 -0
  56. data/lib/perkins/assets/javascripts/vendor/backbone.marionette.js +2891 -0
  57. data/lib/perkins/assets/javascripts/vendor/hamlcoffee.js.coffee.erb +138 -0
  58. data/lib/perkins/assets/javascripts/vendor/livequery.jquery.js +8 -0
  59. data/lib/perkins/assets/javascripts/vendor/log.js +1 -1
  60. data/lib/perkins/assets/javascripts/vendor/md5.js +207 -0
  61. data/lib/perkins/assets/javascripts/vendor/nprogress.js +476 -0
  62. data/lib/perkins/assets/javascripts/vendor/underscore.js +6 -0
  63. data/lib/perkins/assets/stylesheets/app.css +3 -0
  64. data/lib/perkins/assets/stylesheets/bootstrap-overrides.css.scss +13 -0
  65. data/lib/perkins/assets/stylesheets/styles.css.scss +30 -3
  66. data/lib/perkins/assets/stylesheets/vendor/nprogress.css +74 -0
  67. data/lib/perkins/assets.rb +42 -0
  68. data/lib/perkins/build/script/ruby.rb +1 -1
  69. data/lib/perkins/build_report.rb +13 -0
  70. data/lib/perkins/{worker.rb → build_worker.rb} +9 -5
  71. data/lib/perkins/cli.rb +4 -2
  72. data/lib/perkins/commit.rb +8 -1
  73. data/lib/perkins/git_loader_worker.rb +29 -0
  74. data/lib/perkins/repo.rb +23 -9
  75. data/lib/perkins/runner.rb +16 -25
  76. data/lib/perkins/server.rb +121 -116
  77. data/lib/perkins/version.rb +1 -1
  78. data/lib/perkins/views/builds.haml +0 -3
  79. data/lib/perkins/views/layout.haml +25 -36
  80. data/lib/perkins/views/menu.haml +1 -1
  81. data/lib/perkins/views/repos/github.haml +0 -31
  82. data/lib/perkins/views/repos/repo.haml +1 -1
  83. data/lib/perkins.rb +4 -2
  84. data/perkins.gemspec +5 -2
  85. data/spec/lib/repo_spec.rb +27 -6
  86. data/spec/lib/runner_spec.rb +1 -0
  87. data/spec/lib/server_spec.rb +6 -23
  88. data/spec/spec_helper.rb +14 -3
  89. metadata +160 -70
  90. data/examples/config.rb +0 -12
  91. data/examples/mongo.yml +0 -13
  92. data/lib/perkins/listener.rb +0 -38
  93. data/spec/lib/listener_spec.rb +0 -30
@@ -0,0 +1,77 @@
1
+
2
+ #repo-menu.pull-right
3
+ %ul.nav.nav-pills{:role => "tablist"}
4
+ -#
5
+ %li.dropdown
6
+ %a.dropdown-toggle{"aria-expanded" => "false", "data-toggle" => "dropdown", :href => "#", :role => "button"}
7
+ Orgs
8
+ %span.caret
9
+ %ul.dropdown-menu.dropdown-menu-right{:role => "menu"}
10
+ - orgs.each do |org|
11
+ %li
12
+ %a{:href => "/orgs/#{org[:login]}"}
13
+ = org[:login]
14
+
15
+
16
+ .title
17
+ %h1
18
+ %span#org-name
19
+ = @name
20
+
21
+ %h5
22
+ %strong= @url
23
+
24
+ .panel.panel-default
25
+ .panel-heading
26
+ Organization info:
27
+
28
+ .panel-body
29
+ .col-sm-3
30
+
31
+ %img.avatar{ src: Perkins.Helpers.gravatar_url(@avatar_url, 80) }
32
+
33
+ .col-sm-3
34
+
35
+ %strong id:
36
+ = @id
37
+ %br
38
+
39
+ %strong email:
40
+ = @email
41
+ %br
42
+
43
+ %strong public repos:
44
+ = @public_repos
45
+
46
+ .col-sm-3
47
+
48
+ %strong public gists:
49
+ = @public_gists
50
+ %br
51
+
52
+ %strong followers:
53
+ = @followers
54
+ %br
55
+
56
+ %strong following:
57
+ = @following
58
+
59
+ .col-sm-3
60
+
61
+ %strong total private repos:
62
+ = @total_private_repos
63
+ %br
64
+
65
+ %strong owned private repos:
66
+ = @owned_private_repos
67
+
68
+
69
+ - if @repos
70
+ %h2 Repositories:
71
+
72
+ %ul.list-group
73
+ - _.each @repos, (repo)->
74
+ != JST["repos/gb_repo"](repo: repo)
75
+
76
+
77
+
@@ -0,0 +1,28 @@
1
+ %h1 Profile Details
2
+
3
+ .panel.panel-default
4
+
5
+ .panel-body
6
+
7
+ .col-sm-5
8
+ %img{:src => @avatar_url, :alt => "avatar" , width: 300}
9
+
10
+ .col-sm-6
11
+ %h2
12
+ = @name
13
+
14
+ %h5
15
+ %strong= @company
16
+
17
+ %h4 Select repos:
18
+
19
+ %ul
20
+ %li
21
+ %a{:href => "/myrepos"} #{@name} repos
22
+ - _.each @orgs , (org)->
23
+ %li
24
+ %a{ href: "/orgs/#{org}" }
25
+ = org
26
+
27
+
28
+
@@ -0,0 +1,37 @@
1
+
2
+ %div{id: "repo-#{@id}" }
3
+
4
+ != JST["repos/menu"](repo: @, active: "current")
5
+
6
+ .title
7
+ %h2
8
+ %span#repo-name
9
+ = @name
10
+ -#= haml :"repos/spinner", locals: {repo: repo}
11
+
12
+ %h5
13
+ %strong
14
+ = @url
15
+ %span#badge-placeholder
16
+
17
+ #build-report-container
18
+
19
+
20
+ - if @download_status isnt "downloaded"
21
+ %hr
22
+ %div{style: "margin:0 auto;width:255px"}
23
+ %h3 we are cloning this repo
24
+ %hr
25
+ %img{:src => "/assets/working.gif", :alt => "downloading..."}
26
+ - else
27
+
28
+ #no-build-warning.alert.alert-warning
29
+ %p
30
+ %span.no-build No builds yet.
31
+
32
+ %a.run-commit{:href => "#"}
33
+ Run latest commit in master branch
34
+
35
+
36
+
37
+
@@ -0,0 +1,19 @@
1
+
2
+ %td
3
+ %a{href: "/repos/#{current_repo.get('name')}/builds/#{@.id}"}
4
+ %span{class: Perkins.Helpers.status_class(@status) }
5
+ -#= build['_id'].to_s[0..7]
6
+
7
+ %td
8
+ = @.commit.message.split("\n")[0]
9
+ %td
10
+ %a{href: Perkins.Helpers.commit_url(current_repo.toJSON(), @.commit.sha), target: "blank"}
11
+ #{@.commit.sha[0..7]}
12
+ - if @.branch.present?
13
+ %strong
14
+ = "(#{@.branch})"
15
+
16
+ %td
17
+ = "#{Perkins.Helpers.round(@.duration)} secs"
18
+ %td
19
+ %abbr.timeago{title:@.build_time}
@@ -0,0 +1,25 @@
1
+
2
+ %div{id: "repo-#{@repo.id}-builds" }
3
+
4
+ != JST["repos/menu"](repo: @repo, active: "builds")
5
+
6
+ .title
7
+ %h2#repo-name= @repo.name
8
+ %h5
9
+ %strong= @repo.url
10
+
11
+ .panel.panel-default
12
+ .panel-heading Builds
13
+ .panel-body
14
+
15
+ %table.table
16
+ %thead
17
+ %tr
18
+ %th Build
19
+ %th Message
20
+ %th Commit
21
+ %th Duration
22
+ %th Finished
23
+ %tbody#repo-builds
24
+
25
+
@@ -0,0 +1,77 @@
1
+ %div{id: "repo-#{@repo.id}-config" }
2
+
3
+ != JST["repos/menu"](repo: @repo, active: "config")
4
+
5
+ .title
6
+ %h2
7
+ %span#repo-name
8
+ = @repo.name
9
+ -#= haml :"repos/spinner", locals: {repo: repo}
10
+
11
+ %h5
12
+ %strong= @repo.url
13
+
14
+
15
+ .panel.panel-default
16
+ .panel-heading
17
+ Config Post Hook
18
+
19
+ .panel-body
20
+
21
+
22
+ - if @hook
23
+ .col-sm-12
24
+
25
+ .pull-right
26
+ .badge
27
+ = if @hook.active then "active" else "disabled"
28
+
29
+ %h2
30
+ %a{ href: @hook.url}
31
+ = @hook.name
32
+ \-
33
+ = @hook.id
34
+
35
+ %h4 Config:
36
+ %ul
37
+ - if @hook.config.secret
38
+ %li
39
+ %strong secret:
40
+ = @hook.config.secret
41
+ %li
42
+ %strong url:
43
+ = @hook.config.url
44
+ %li
45
+ %strong content type:
46
+ = @hook.config.content_type
47
+ %li
48
+ %strong ssl:
49
+ = @hook.config.insecure_ssl
50
+
51
+ %h4 Test url:
52
+ %p
53
+ = @hook.test_url
54
+
55
+ %h4 Last response:
56
+ %p
57
+
58
+ - if @hook.last_response
59
+ %strong Code:
60
+ = @hook.last_response.code
61
+ %strong Status:
62
+ = @hook.last_response.status
63
+ %strong Message:
64
+ = @hook.last_response.message
65
+
66
+ .col-sm-12
67
+
68
+ %h3
69
+ = if @hook then "Will update exiting (#{@hook.id}) hook." else "Will create new hook."
70
+ %form{:action => "/repos/#{@repo.name}/add_hook", method: "post"}
71
+ %input{:type => "text", name: "webhook_url", placeholder: "type the receive hook url...", style:"width:250px"}
72
+ %button Send
73
+
74
+ %p.small
75
+ we are going to send the hook to
76
+ %strong
77
+ = @repo.url
@@ -0,0 +1,31 @@
1
+
2
+ %li.list-group-item
3
+
4
+ .pull-right
5
+ %a.add-repo.btn.btn-default{ href: "#", data: {"gb-id": @repo.id } }
6
+ ADD REPO
7
+ %i.fa.fa-plus
8
+
9
+ .row
10
+ %span.col-sm-2
11
+ %a{src: @repo.owner.url }
12
+ %img{ src: @repo.owner.avatar_url, width: 120 }
13
+
14
+ %span.col-sm-7
15
+ %h3
16
+ = @repo.name
17
+
18
+ - if @repo.fork
19
+ %i.fa.fa-code-fork{title: "is a fork"}
20
+
21
+ - if @repo.private
22
+ %i.fa.fa-lock{title: "is private"}
23
+
24
+
25
+ %p.small
26
+ = @repo.description
27
+
28
+ %p.small
29
+ %a{href: @repo.url}
30
+ View on github
31
+ %i.fa.fa-external-link
@@ -0,0 +1,7 @@
1
+
2
+ - if @repos
3
+ %h2 Repositories from my Github profile:
4
+
5
+ %ul.list-group
6
+ - _.each @repos, (repo)->
7
+ != JST["repos/gb_repo"](repo: repo)
@@ -0,0 +1,17 @@
1
+ #repo-menu.pull-right
2
+ %ul.nav.nav-pills{:role => "tablist"}
3
+
4
+ %li#restart-build-btn.hide
5
+ %a.btn.refresh{href:"#", title: "Restart Build"}
6
+ %i.fa.fa-refresh{class: "#{'fa-refresh'}"}
7
+
8
+ %li{class: "#{'active' if @active is 'current'}"}
9
+ %a{:href => "/repos/#{@repo.name}"} Current
10
+
11
+ %li{class: "#{'active' if @active is 'builds'}"}
12
+ %a{:href => "/repos/#{@repo.name}/builds"} Build history
13
+
14
+ %li{class: "#{'active' if @active is 'config'}"}
15
+ %a{:href => "/repos/#{@repo.name}/config"} Config Hook
16
+
17
+
@@ -0,0 +1,53 @@
1
+
2
+ - if @build
3
+ .panel.panel-default
4
+ .panel-heading
5
+ Current Build
6
+
7
+ .panel-body
8
+
9
+ .col-sm-8
10
+
11
+ %strong= @build.branch
12
+ \-
13
+ = @build.commit.message
14
+
15
+ .pull-right.stats
16
+ %p
17
+ != Perkins.Helpers.status_label(@build.status)
18
+
19
+ %p.small
20
+ %abbr.timeago{title: @build.build_time}
21
+
22
+ %p.small
23
+ duration:
24
+ %strong
25
+ = "#{Perkins.Helpers.round(@build.duration)} secs"
26
+
27
+
28
+ .col-sm-12
29
+ %img.avatar{ src: Perkins.Helpers.gravatar_url( @build.commit.email, 35) }
30
+ %strong= @build.commit.author
31
+ = @build.commit.email
32
+
33
+ .pull-right
34
+ %a{href: Perkins.Helpers.commit_url(@, @build.sha), target: "blank"}
35
+ %img{src: "/assets/github.svg", width:"20px"}
36
+ = "commit ... #{@build.sha.substr(0, 6)}"
37
+
38
+ %strong
39
+ %abbr.timeago{title @build.commit.created_at}
40
+
41
+ %ul.list-group
42
+ %li.list-group-item.build-item
43
+
44
+ .build-response
45
+ %p
46
+ %pre#log.ansi= @build.response
47
+
48
+ - else
49
+ .alert.alert-warning
50
+ No builds yet.
51
+
52
+ %a{:href => "/repos/#{@name}/run_commit"}
53
+ Run last commit in master branch
@@ -0,0 +1,14 @@
1
+ #sidebar-header
2
+ .pull-right
3
+ %a.btn{href: "/me", title: "Add new repository"}
4
+ %span.glyphicon.glyphicon-plus
5
+
6
+ %h4.title Repos
7
+
8
+ %ul#sidebar-repos.nav.nav-stacked{style: "overflow:scroll;height:100%"}
9
+ -#
10
+ - Perkins::Repo.added.all.each do |repo|
11
+ %li
12
+ %a{:href => "/repos/#{repo.name}"}
13
+ = repo.name
14
+ = haml :"repos/spinner", locals: {repo: repo}
@@ -0,0 +1,4 @@
1
+
2
+ %a{:href => "/repos/#{@name}"}
3
+ = @name
4
+ //= haml :"repos/spinner", locals: {repo: repo}
@@ -0,0 +1,2 @@
1
+ (function(t,e){if(typeof define==="function"&&define.amd){define(["underscore","jquery","exports"],function(i,r,s){t.Backbone=e(t,s,i,r)})}else if(typeof exports!=="undefined"){var i=require("underscore");e(t,exports,i)}else{t.Backbone=e(t,{},t._,t.jQuery||t.Zepto||t.ender||t.$)}})(this,function(t,e,i,r){var s=t.Backbone;var n=[];var a=n.push;var o=n.slice;var h=n.splice;e.VERSION="1.1.2";e.$=r;e.noConflict=function(){t.Backbone=s;return this};e.emulateHTTP=false;e.emulateJSON=false;var u=e.Events={on:function(t,e,i){if(!c(this,"on",t,[e,i])||!e)return this;this._events||(this._events={});var r=this._events[t]||(this._events[t]=[]);r.push({callback:e,context:i,ctx:i||this});return this},once:function(t,e,r){if(!c(this,"once",t,[e,r])||!e)return this;var s=this;var n=i.once(function(){s.off(t,n);e.apply(this,arguments)});n._callback=e;return this.on(t,n,r)},off:function(t,e,r){var s,n,a,o,h,u,l,f;if(!this._events||!c(this,"off",t,[e,r]))return this;if(!t&&!e&&!r){this._events=void 0;return this}o=t?[t]:i.keys(this._events);for(h=0,u=o.length;h<u;h++){t=o[h];if(a=this._events[t]){this._events[t]=s=[];if(e||r){for(l=0,f=a.length;l<f;l++){n=a[l];if(e&&e!==n.callback&&e!==n.callback._callback||r&&r!==n.context){s.push(n)}}}if(!s.length)delete this._events[t]}}return this},trigger:function(t){if(!this._events)return this;var e=o.call(arguments,1);if(!c(this,"trigger",t,e))return this;var i=this._events[t];var r=this._events.all;if(i)f(i,e);if(r)f(r,arguments);return this},stopListening:function(t,e,r){var s=this._listeningTo;if(!s)return this;var n=!e&&!r;if(!r&&typeof e==="object")r=this;if(t)(s={})[t._listenId]=t;for(var a in s){t=s[a];t.off(e,r,this);if(n||i.isEmpty(t._events))delete this._listeningTo[a]}return this}};var l=/\s+/;var c=function(t,e,i,r){if(!i)return true;if(typeof i==="object"){for(var s in i){t[e].apply(t,[s,i[s]].concat(r))}return false}if(l.test(i)){var n=i.split(l);for(var a=0,o=n.length;a<o;a++){t[e].apply(t,[n[a]].concat(r))}return false}return true};var f=function(t,e){var i,r=-1,s=t.length,n=e[0],a=e[1],o=e[2];switch(e.length){case 0:while(++r<s)(i=t[r]).callback.call(i.ctx);return;case 1:while(++r<s)(i=t[r]).callback.call(i.ctx,n);return;case 2:while(++r<s)(i=t[r]).callback.call(i.ctx,n,a);return;case 3:while(++r<s)(i=t[r]).callback.call(i.ctx,n,a,o);return;default:while(++r<s)(i=t[r]).callback.apply(i.ctx,e);return}};var d={listenTo:"on",listenToOnce:"once"};i.each(d,function(t,e){u[e]=function(e,r,s){var n=this._listeningTo||(this._listeningTo={});var a=e._listenId||(e._listenId=i.uniqueId("l"));n[a]=e;if(!s&&typeof r==="object")s=this;e[t](r,s,this);return this}});u.bind=u.on;u.unbind=u.off;i.extend(e,u);var p=e.Model=function(t,e){var r=t||{};e||(e={});this.cid=i.uniqueId("c");this.attributes={};if(e.collection)this.collection=e.collection;if(e.parse)r=this.parse(r,e)||{};r=i.defaults({},r,i.result(this,"defaults"));this.set(r,e);this.changed={};this.initialize.apply(this,arguments)};i.extend(p.prototype,u,{changed:null,validationError:null,idAttribute:"id",initialize:function(){},toJSON:function(t){return i.clone(this.attributes)},sync:function(){return e.sync.apply(this,arguments)},get:function(t){return this.attributes[t]},escape:function(t){return i.escape(this.get(t))},has:function(t){return this.get(t)!=null},set:function(t,e,r){var s,n,a,o,h,u,l,c;if(t==null)return this;if(typeof t==="object"){n=t;r=e}else{(n={})[t]=e}r||(r={});if(!this._validate(n,r))return false;a=r.unset;h=r.silent;o=[];u=this._changing;this._changing=true;if(!u){this._previousAttributes=i.clone(this.attributes);this.changed={}}c=this.attributes,l=this._previousAttributes;if(this.idAttribute in n)this.id=n[this.idAttribute];for(s in n){e=n[s];if(!i.isEqual(c[s],e))o.push(s);if(!i.isEqual(l[s],e)){this.changed[s]=e}else{delete this.changed[s]}a?delete c[s]:c[s]=e}if(!h){if(o.length)this._pending=r;for(var f=0,d=o.length;f<d;f++){this.trigger("change:"+o[f],this,c[o[f]],r)}}if(u)return this;if(!h){while(this._pending){r=this._pending;this._pending=false;this.trigger("change",this,r)}}this._pending=false;this._changing=false;return this},unset:function(t,e){return this.set(t,void 0,i.extend({},e,{unset:true}))},clear:function(t){var e={};for(var r in this.attributes)e[r]=void 0;return this.set(e,i.extend({},t,{unset:true}))},hasChanged:function(t){if(t==null)return!i.isEmpty(this.changed);return i.has(this.changed,t)},changedAttributes:function(t){if(!t)return this.hasChanged()?i.clone(this.changed):false;var e,r=false;var s=this._changing?this._previousAttributes:this.attributes;for(var n in t){if(i.isEqual(s[n],e=t[n]))continue;(r||(r={}))[n]=e}return r},previous:function(t){if(t==null||!this._previousAttributes)return null;return this._previousAttributes[t]},previousAttributes:function(){return i.clone(this._previousAttributes)},fetch:function(t){t=t?i.clone(t):{};if(t.parse===void 0)t.parse=true;var e=this;var r=t.success;t.success=function(i){if(!e.set(e.parse(i,t),t))return false;if(r)r(e,i,t);e.trigger("sync",e,i,t)};q(this,t);return this.sync("read",this,t)},save:function(t,e,r){var s,n,a,o=this.attributes;if(t==null||typeof t==="object"){s=t;r=e}else{(s={})[t]=e}r=i.extend({validate:true},r);if(s&&!r.wait){if(!this.set(s,r))return false}else{if(!this._validate(s,r))return false}if(s&&r.wait){this.attributes=i.extend({},o,s)}if(r.parse===void 0)r.parse=true;var h=this;var u=r.success;r.success=function(t){h.attributes=o;var e=h.parse(t,r);if(r.wait)e=i.extend(s||{},e);if(i.isObject(e)&&!h.set(e,r)){return false}if(u)u(h,t,r);h.trigger("sync",h,t,r)};q(this,r);n=this.isNew()?"create":r.patch?"patch":"update";if(n==="patch")r.attrs=s;a=this.sync(n,this,r);if(s&&r.wait)this.attributes=o;return a},destroy:function(t){t=t?i.clone(t):{};var e=this;var r=t.success;var s=function(){e.trigger("destroy",e,e.collection,t)};t.success=function(i){if(t.wait||e.isNew())s();if(r)r(e,i,t);if(!e.isNew())e.trigger("sync",e,i,t)};if(this.isNew()){t.success();return false}q(this,t);var n=this.sync("delete",this,t);if(!t.wait)s();return n},url:function(){var t=i.result(this,"urlRoot")||i.result(this.collection,"url")||M();if(this.isNew())return t;return t.replace(/([^\/])$/,"$1/")+encodeURIComponent(this.id)},parse:function(t,e){return t},clone:function(){return new this.constructor(this.attributes)},isNew:function(){return!this.has(this.idAttribute)},isValid:function(t){return this._validate({},i.extend(t||{},{validate:true}))},_validate:function(t,e){if(!e.validate||!this.validate)return true;t=i.extend({},this.attributes,t);var r=this.validationError=this.validate(t,e)||null;if(!r)return true;this.trigger("invalid",this,r,i.extend(e,{validationError:r}));return false}});var v=["keys","values","pairs","invert","pick","omit"];i.each(v,function(t){p.prototype[t]=function(){var e=o.call(arguments);e.unshift(this.attributes);return i[t].apply(i,e)}});var g=e.Collection=function(t,e){e||(e={});if(e.model)this.model=e.model;if(e.comparator!==void 0)this.comparator=e.comparator;this._reset();this.initialize.apply(this,arguments);if(t)this.reset(t,i.extend({silent:true},e))};var m={add:true,remove:true,merge:true};var y={add:true,remove:false};i.extend(g.prototype,u,{model:p,initialize:function(){},toJSON:function(t){return this.map(function(e){return e.toJSON(t)})},sync:function(){return e.sync.apply(this,arguments)},add:function(t,e){return this.set(t,i.extend({merge:false},e,y))},remove:function(t,e){var r=!i.isArray(t);t=r?[t]:i.clone(t);e||(e={});var s,n,a,o;for(s=0,n=t.length;s<n;s++){o=t[s]=this.get(t[s]);if(!o)continue;delete this._byId[o.id];delete this._byId[o.cid];a=this.indexOf(o);this.models.splice(a,1);this.length--;if(!e.silent){e.index=a;o.trigger("remove",o,this,e)}this._removeReference(o,e)}return r?t[0]:t},set:function(t,e){e=i.defaults({},e,m);if(e.parse)t=this.parse(t,e);var r=!i.isArray(t);t=r?t?[t]:[]:i.clone(t);var s,n,a,o,h,u,l;var c=e.at;var f=this.model;var d=this.comparator&&c==null&&e.sort!==false;var v=i.isString(this.comparator)?this.comparator:null;var g=[],y=[],_={};var b=e.add,w=e.merge,x=e.remove;var E=!d&&b&&x?[]:false;for(s=0,n=t.length;s<n;s++){h=t[s]||{};if(h instanceof p){a=o=h}else{a=h[f.prototype.idAttribute||"id"]}if(u=this.get(a)){if(x)_[u.cid]=true;if(w){h=h===o?o.attributes:h;if(e.parse)h=u.parse(h,e);u.set(h,e);if(d&&!l&&u.hasChanged(v))l=true}t[s]=u}else if(b){o=t[s]=this._prepareModel(h,e);if(!o)continue;g.push(o);this._addReference(o,e)}o=u||o;if(E&&(o.isNew()||!_[o.id]))E.push(o);_[o.id]=true}if(x){for(s=0,n=this.length;s<n;++s){if(!_[(o=this.models[s]).cid])y.push(o)}if(y.length)this.remove(y,e)}if(g.length||E&&E.length){if(d)l=true;this.length+=g.length;if(c!=null){for(s=0,n=g.length;s<n;s++){this.models.splice(c+s,0,g[s])}}else{if(E)this.models.length=0;var k=E||g;for(s=0,n=k.length;s<n;s++){this.models.push(k[s])}}}if(l)this.sort({silent:true});if(!e.silent){for(s=0,n=g.length;s<n;s++){(o=g[s]).trigger("add",o,this,e)}if(l||E&&E.length)this.trigger("sort",this,e)}return r?t[0]:t},reset:function(t,e){e||(e={});for(var r=0,s=this.models.length;r<s;r++){this._removeReference(this.models[r],e)}e.previousModels=this.models;this._reset();t=this.add(t,i.extend({silent:true},e));if(!e.silent)this.trigger("reset",this,e);return t},push:function(t,e){return this.add(t,i.extend({at:this.length},e))},pop:function(t){var e=this.at(this.length-1);this.remove(e,t);return e},unshift:function(t,e){return this.add(t,i.extend({at:0},e))},shift:function(t){var e=this.at(0);this.remove(e,t);return e},slice:function(){return o.apply(this.models,arguments)},get:function(t){if(t==null)return void 0;return this._byId[t]||this._byId[t.id]||this._byId[t.cid]},at:function(t){return this.models[t]},where:function(t,e){if(i.isEmpty(t))return e?void 0:[];return this[e?"find":"filter"](function(e){for(var i in t){if(t[i]!==e.get(i))return false}return true})},findWhere:function(t){return this.where(t,true)},sort:function(t){if(!this.comparator)throw new Error("Cannot sort a set without a comparator");t||(t={});if(i.isString(this.comparator)||this.comparator.length===1){this.models=this.sortBy(this.comparator,this)}else{this.models.sort(i.bind(this.comparator,this))}if(!t.silent)this.trigger("sort",this,t);return this},pluck:function(t){return i.invoke(this.models,"get",t)},fetch:function(t){t=t?i.clone(t):{};if(t.parse===void 0)t.parse=true;var e=t.success;var r=this;t.success=function(i){var s=t.reset?"reset":"set";r[s](i,t);if(e)e(r,i,t);r.trigger("sync",r,i,t)};q(this,t);return this.sync("read",this,t)},create:function(t,e){e=e?i.clone(e):{};if(!(t=this._prepareModel(t,e)))return false;if(!e.wait)this.add(t,e);var r=this;var s=e.success;e.success=function(t,i){if(e.wait)r.add(t,e);if(s)s(t,i,e)};t.save(null,e);return t},parse:function(t,e){return t},clone:function(){return new this.constructor(this.models)},_reset:function(){this.length=0;this.models=[];this._byId={}},_prepareModel:function(t,e){if(t instanceof p)return t;e=e?i.clone(e):{};e.collection=this;var r=new this.model(t,e);if(!r.validationError)return r;this.trigger("invalid",this,r.validationError,e);return false},_addReference:function(t,e){this._byId[t.cid]=t;if(t.id!=null)this._byId[t.id]=t;if(!t.collection)t.collection=this;t.on("all",this._onModelEvent,this)},_removeReference:function(t,e){if(this===t.collection)delete t.collection;t.off("all",this._onModelEvent,this)},_onModelEvent:function(t,e,i,r){if((t==="add"||t==="remove")&&i!==this)return;if(t==="destroy")this.remove(e,r);if(e&&t==="change:"+e.idAttribute){delete this._byId[e.previous(e.idAttribute)];if(e.id!=null)this._byId[e.id]=e}this.trigger.apply(this,arguments)}});var _=["forEach","each","map","collect","reduce","foldl","inject","reduceRight","foldr","find","detect","filter","select","reject","every","all","some","any","include","contains","invoke","max","min","toArray","size","first","head","take","initial","rest","tail","drop","last","without","difference","indexOf","shuffle","lastIndexOf","isEmpty","chain","sample"];i.each(_,function(t){g.prototype[t]=function(){var e=o.call(arguments);e.unshift(this.models);return i[t].apply(i,e)}});var b=["groupBy","countBy","sortBy","indexBy"];i.each(b,function(t){g.prototype[t]=function(e,r){var s=i.isFunction(e)?e:function(t){return t.get(e)};return i[t](this.models,s,r)}});var w=e.View=function(t){this.cid=i.uniqueId("view");t||(t={});i.extend(this,i.pick(t,E));this._ensureElement();this.initialize.apply(this,arguments);this.delegateEvents()};var x=/^(\S+)\s*(.*)$/;var E=["model","collection","el","id","attributes","className","tagName","events"];i.extend(w.prototype,u,{tagName:"div",$:function(t){return this.$el.find(t)},initialize:function(){},render:function(){return this},remove:function(){this.$el.remove();this.stopListening();return this},setElement:function(t,i){if(this.$el)this.undelegateEvents();this.$el=t instanceof e.$?t:e.$(t);this.el=this.$el[0];if(i!==false)this.delegateEvents();return this},delegateEvents:function(t){if(!(t||(t=i.result(this,"events"))))return this;this.undelegateEvents();for(var e in t){var r=t[e];if(!i.isFunction(r))r=this[t[e]];if(!r)continue;var s=e.match(x);var n=s[1],a=s[2];r=i.bind(r,this);n+=".delegateEvents"+this.cid;if(a===""){this.$el.on(n,r)}else{this.$el.on(n,a,r)}}return this},undelegateEvents:function(){this.$el.off(".delegateEvents"+this.cid);return this},_ensureElement:function(){if(!this.el){var t=i.extend({},i.result(this,"attributes"));if(this.id)t.id=i.result(this,"id");if(this.className)t["class"]=i.result(this,"className");var r=e.$("<"+i.result(this,"tagName")+">").attr(t);this.setElement(r,false)}else{this.setElement(i.result(this,"el"),false)}}});e.sync=function(t,r,s){var n=T[t];i.defaults(s||(s={}),{emulateHTTP:e.emulateHTTP,emulateJSON:e.emulateJSON});var a={type:n,dataType:"json"};if(!s.url){a.url=i.result(r,"url")||M()}if(s.data==null&&r&&(t==="create"||t==="update"||t==="patch")){a.contentType="application/json";a.data=JSON.stringify(s.attrs||r.toJSON(s))}if(s.emulateJSON){a.contentType="application/x-www-form-urlencoded";a.data=a.data?{model:a.data}:{}}if(s.emulateHTTP&&(n==="PUT"||n==="DELETE"||n==="PATCH")){a.type="POST";if(s.emulateJSON)a.data._method=n;var o=s.beforeSend;s.beforeSend=function(t){t.setRequestHeader("X-HTTP-Method-Override",n);if(o)return o.apply(this,arguments)}}if(a.type!=="GET"&&!s.emulateJSON){a.processData=false}if(a.type==="PATCH"&&k){a.xhr=function(){return new ActiveXObject("Microsoft.XMLHTTP")}}var h=s.xhr=e.ajax(i.extend(a,s));r.trigger("request",r,h,s);return h};var k=typeof window!=="undefined"&&!!window.ActiveXObject&&!(window.XMLHttpRequest&&(new XMLHttpRequest).dispatchEvent);var T={create:"POST",update:"PUT",patch:"PATCH","delete":"DELETE",read:"GET"};e.ajax=function(){return e.$.ajax.apply(e.$,arguments)};var $=e.Router=function(t){t||(t={});if(t.routes)this.routes=t.routes;this._bindRoutes();this.initialize.apply(this,arguments)};var S=/\((.*?)\)/g;var H=/(\(\?)?:\w+/g;var A=/\*\w+/g;var I=/[\-{}\[\]+?.,\\\^$|#\s]/g;i.extend($.prototype,u,{initialize:function(){},route:function(t,r,s){if(!i.isRegExp(t))t=this._routeToRegExp(t);if(i.isFunction(r)){s=r;r=""}if(!s)s=this[r];var n=this;e.history.route(t,function(i){var a=n._extractParameters(t,i);n.execute(s,a);n.trigger.apply(n,["route:"+r].concat(a));n.trigger("route",r,a);e.history.trigger("route",n,r,a)});return this},execute:function(t,e){if(t)t.apply(this,e)},navigate:function(t,i){e.history.navigate(t,i);return this},_bindRoutes:function(){if(!this.routes)return;this.routes=i.result(this,"routes");var t,e=i.keys(this.routes);while((t=e.pop())!=null){this.route(t,this.routes[t])}},_routeToRegExp:function(t){t=t.replace(I,"\\$&").replace(S,"(?:$1)?").replace(H,function(t,e){return e?t:"([^/?]+)"}).replace(A,"([^?]*?)");return new RegExp("^"+t+"(?:\\?([\\s\\S]*))?$")},_extractParameters:function(t,e){var r=t.exec(e).slice(1);return i.map(r,function(t,e){if(e===r.length-1)return t||null;return t?decodeURIComponent(t):null})}});var N=e.History=function(){this.handlers=[];i.bindAll(this,"checkUrl");if(typeof window!=="undefined"){this.location=window.location;this.history=window.history}};var R=/^[#\/]|\s+$/g;var O=/^\/+|\/+$/g;var P=/msie [\w.]+/;var C=/\/$/;var j=/#.*$/;N.started=false;i.extend(N.prototype,u,{interval:50,atRoot:function(){return this.location.pathname.replace(/[^\/]$/,"$&/")===this.root},getHash:function(t){var e=(t||this).location.href.match(/#(.*)$/);return e?e[1]:""},getFragment:function(t,e){if(t==null){if(this._hasPushState||!this._wantsHashChange||e){t=decodeURI(this.location.pathname+this.location.search);var i=this.root.replace(C,"");if(!t.indexOf(i))t=t.slice(i.length)}else{t=this.getHash()}}return t.replace(R,"")},start:function(t){if(N.started)throw new Error("Backbone.history has already been started");N.started=true;this.options=i.extend({root:"/"},this.options,t);this.root=this.options.root;this._wantsHashChange=this.options.hashChange!==false;this._wantsPushState=!!this.options.pushState;this._hasPushState=!!(this.options.pushState&&this.history&&this.history.pushState);var r=this.getFragment();var s=document.documentMode;var n=P.exec(navigator.userAgent.toLowerCase())&&(!s||s<=7);this.root=("/"+this.root+"/").replace(O,"/");if(n&&this._wantsHashChange){var a=e.$('<iframe src="javascript:0" tabindex="-1">');this.iframe=a.hide().appendTo("body")[0].contentWindow;this.navigate(r)}if(this._hasPushState){e.$(window).on("popstate",this.checkUrl)}else if(this._wantsHashChange&&"onhashchange"in window&&!n){e.$(window).on("hashchange",this.checkUrl)}else if(this._wantsHashChange){this._checkUrlInterval=setInterval(this.checkUrl,this.interval)}this.fragment=r;var o=this.location;if(this._wantsHashChange&&this._wantsPushState){if(!this._hasPushState&&!this.atRoot()){this.fragment=this.getFragment(null,true);this.location.replace(this.root+"#"+this.fragment);return true}else if(this._hasPushState&&this.atRoot()&&o.hash){this.fragment=this.getHash().replace(R,"");this.history.replaceState({},document.title,this.root+this.fragment)}}if(!this.options.silent)return this.loadUrl()},stop:function(){e.$(window).off("popstate",this.checkUrl).off("hashchange",this.checkUrl);if(this._checkUrlInterval)clearInterval(this._checkUrlInterval);N.started=false},route:function(t,e){this.handlers.unshift({route:t,callback:e})},checkUrl:function(t){var e=this.getFragment();if(e===this.fragment&&this.iframe){e=this.getFragment(this.getHash(this.iframe))}if(e===this.fragment)return false;if(this.iframe)this.navigate(e);this.loadUrl()},loadUrl:function(t){t=this.fragment=this.getFragment(t);return i.any(this.handlers,function(e){if(e.route.test(t)){e.callback(t);return true}})},navigate:function(t,e){if(!N.started)return false;if(!e||e===true)e={trigger:!!e};var i=this.root+(t=this.getFragment(t||""));t=t.replace(j,"");if(this.fragment===t)return;this.fragment=t;if(t===""&&i!=="/")i=i.slice(0,-1);if(this._hasPushState){this.history[e.replace?"replaceState":"pushState"]({},document.title,i)}else if(this._wantsHashChange){this._updateHash(this.location,t,e.replace);if(this.iframe&&t!==this.getFragment(this.getHash(this.iframe))){if(!e.replace)this.iframe.document.open().close();this._updateHash(this.iframe.location,t,e.replace)}}else{return this.location.assign(i)}if(e.trigger)return this.loadUrl(t)},_updateHash:function(t,e,i){if(i){var r=t.href.replace(/(javascript:|#).*$/,"");t.replace(r+"#"+e)}else{t.hash="#"+e}}});e.history=new N;var U=function(t,e){var r=this;var s;if(t&&i.has(t,"constructor")){s=t.constructor}else{s=function(){return r.apply(this,arguments)}}i.extend(s,r,e);var n=function(){this.constructor=s};n.prototype=r.prototype;s.prototype=new n;if(t)i.extend(s.prototype,t);s.__super__=r.prototype;return s};p.extend=g.extend=$.extend=w.extend=N.extend=U;var M=function(){throw new Error('A "url" property or function must be specified')};var q=function(t,e){var i=e.error;e.error=function(r){if(i)i(t,r,e);t.trigger("error",t,r,e)}};return e});
2
+ //# sourceMappingURL=backbone-min.map