spine_paginator 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,4 +2,4 @@
2
2
  // version: 0.1.0
3
3
  // author: vkill
4
4
  // license: MIT
5
- (function(){var t,s,i,e;e=this.Spine||require("spine"),s=e.Model,i=function(){function t(t,s,i){var e;this._page=s,null==i&&(i={}),this._page=parseInt(this._page),(isNaN(this._page)||0>=this._page)&&(this._page=1),this._originalPage=this._page,this.perPage=i.perPage||this.constructor.DEFAULT_PER_PAGE,this.perPage=parseInt(this.perPage),(isNaN(this.perPage)||0>=this.perPage)&&(this.perPage=this.constructor.DEFAULT_PER_PAGE),this.maxPerPage=i.maxPerPage||this.constructor.MAX_PER_PAGE,this.window=i.window||i.inner_window||this.constructor.WINDOW,e=i.outer_window||this.constructor.OUTER_WINDOW,this.left=i.left||this.constructor.LEFT,0===this.left&&(this.left=e),this.right=i.right||this.constructor.RIGHT,0===this.right&&(this.right=e),this.originalRecords=this.cloneArray(t),this.totalCount=this.originalRecords.length,this.skipbuildButtonsAndLocals=i.skipbuildButtonsAndLocals,this.records=[],this.buttons=[],this.locals={},this.per()}return t.DEFAULT_PER_PAGE=25,t.MAX_PER_PAGE=null,t.WINDOW=4,t.OUTER_WINDOW=0,t.LEFT=0,t.RIGHT=0,t.prototype.per=function(t){var s,i,e;return i=parseInt(t),!isNaN(i)&&i>0&&(this.perPage=i,this._page=this._originalPage),s=this.offsetValue(),e=s+this.limitValue(),this.records=this.originalRecords.slice(s,e),null==this.skipbuildButtonsAndLocals&&this.buildButtonsAndLocals(),this},t.prototype.totalPages=function(){return Math.ceil(this.totalCount/this.limitValue())},t.prototype.currentPage=function(){return null==this.limitValue()?this.firstPage():this.offsetValue()/this.limitValue()+1},t.prototype.firstPage=function(){return 1},t.prototype.isFirstPage=function(){return this.currentPage()===this.firstPage()},t.prototype.lastPage=function(){return this.totalPages()},t.prototype.isLastPage=function(){return this.currentPage()>=this.lastPage()},t.prototype.pages=function(){var t,s,i,e,r,a,n,h;for(t=this.currentPage(),s=this.firstPage(),e=this.lastPage(),h=[],i=null,r=n=s;e>=s?e>=n:n>=e;r=e>=s?++n:--n)a=this.buildPage(r,i,t,s,e),i=a.isLeftOuter||a.isRightOuter||a.isInsideWindow?null:"gap",h.push(a);return h},t.prototype.curPage=function(){var t,s,i;return t=this.currentPage(),s=this.firstPage(),i=this.lastPage(),this.buildPage(t,null,t,s,i)},t.prototype.limitValue=function(){return this.perPage>this.totalCount&&(this.perPage=this.totalCount),null!=this.maxPerPage&&this.perPage>this.maxPerPage&&(this.perPage=this.maxPerPage),this.perPage},t.prototype.offsetValue=function(){var t;return t=this.totalPages(),this._page>t&&(this._page=t),(this._page-1)*this.limitValue()},t.prototype.buildPage=function(t,s,i,e,r){return{number:t,isCurrent:t===i,isFirst:t===e,isLast:t===r,isPrev:t===i-1,isNext:t===i+1,isLeftOuter:this.left>=t,isRightOuter:this.right>r-t,isInsideWindow:Math.abs(i-t)<=this.window,isWasTruncated:"gap"===s}},t.prototype.buildButtonsAndLocals=function(){var t,s,i,e,r,a,n;for(e=[],n={},t=this.curPage(),i=this.pages(),t.isFirst?n.hasFirst=!1:(e.push("first"),n.hasFirst=!0),t.isFirst?n.hasPrev=!1:(e.push("prev"),n.hasPrev=!0),n.pages=[],r=0,a=i.length;a>r;r++)s=i[r],s.isLeftOuter||s.isRightOuter||s.isInsideWindow?s.isCurrent?(e.push("current"),n.pages.push({number:s.number,current:!0})):(e.push(s.number),n.pages.push({number:s.number,current:!1})):s.isWasTruncated||(e.push("gap"),n.pages.push({number:s.number,gap:!0}));return t.isLast?n.hasNext=!1:(e.push("next"),n.hasNext=!0),t.isLast?n.hasLast=!1:(e.push("last"),n.hasLast=!0),n.first=this.firstPage(),n.current=this.currentPage(),n.last=this.lastPage(),n.numStart=0===this.records.length?0:this.offsetValue()+1,n.numEnd=this.offsetValue()+this.records.length,n.numTotal=this.totalCount,this.buttons=e,this.locals=n},t.prototype.cloneArray=function(t){var s,i,e,r;for(r=[],i=0,e=t.length;e>i;i++)s=t[i],r.push(s.clone());return r},t}(),t={_perPaginateRecords:function(){return this.records},page:function(t,s){return null==s&&(s={}),new i(this._perPaginateRecords(),t,s)}},s.Paginator={extended:function(){return this.extend(t)}},e.Paginator=i}).call(this);
5
+ (function(){var t,s,i;t=function(){function t(t,s,e){var r;this._page=s,null==e&&(e={}),i(t)||(t=[t]),this.originalRecords=t,this.totalCount=this.originalRecords.length,this._page=parseInt(this._page),(isNaN(this._page)||0>=this._page)&&(this._page=1),this._originalPage=this._page,this.perPage=e.perPage||this.constructor.DEFAULT_PER_PAGE,this.perPage=parseInt(this.perPage),(isNaN(this.perPage)||0>=this.perPage)&&(this.perPage=this.constructor.DEFAULT_PER_PAGE),this.maxPerPage=e.maxPerPage||this.constructor.MAX_PER_PAGE,this.window=e.window||e.inner_window||this.constructor.WINDOW,r=e.outer_window||this.constructor.OUTER_WINDOW,this.left=e.left||this.constructor.LEFT,0===this.left&&(this.left=r),this.right=e.right||this.constructor.RIGHT,0===this.right&&(this.right=r),this.skipbuildButtonsAndLocals=e.skipbuildButtonsAndLocals,this.records=[],this.buttons=[],this.locals={},this.per()}return t.DEFAULT_PER_PAGE=25,t.MAX_PER_PAGE=null,t.WINDOW=4,t.OUTER_WINDOW=0,t.LEFT=0,t.RIGHT=0,t.PAGE_TEXTS={first:"first",prev:"prev",current:"current",next:"next",last:"last",gap:"gap"},t.prototype.per=function(t){var s,i,e;return i=parseInt(t),!isNaN(i)&&i>0&&(this.perPage=i,this._page=this._originalPage),s=this.offsetValue(),e=s+this.limitValue(),this.records=this.originalRecords.slice(s,e),null==this.skipbuildButtonsAndLocals&&this.buildButtonsAndLocals(),this},t.prototype.totalPages=function(){return Math.ceil(this.totalCount/this.limitValue())},t.prototype.currentPage=function(){return null==this.limitValue()?this.firstPage():this.offsetValue()/this.limitValue()+1},t.prototype.firstPage=function(){return 1},t.prototype.isFirstPage=function(){return this.currentPage()===this.firstPage()},t.prototype.lastPage=function(){return this.totalPages()},t.prototype.isLastPage=function(){return this.currentPage()>=this.lastPage()},t.prototype.limitValue=function(){return this.perPage>this.totalCount&&(this.perPage=this.totalCount),null!=this.maxPerPage&&this.perPage>this.maxPerPage&&(this.perPage=this.maxPerPage),this.perPage},t.prototype.offsetValue=function(){var t;return t=this.totalPages(),this._page>t&&(this._page=t),(this._page-1)*this.limitValue()},t.prototype.buildPage=function(t,s,i,e,r){return{number:t,isCurrent:t===i,isFirst:t===e,isLast:t===r,isPrev:t===i-1,isNext:t===i+1,isLeftOuter:this.left>=t,isRightOuter:this.right>r-t,isInsideWindow:Math.abs(i-t)<=this.window,isWasTruncated:s===this.constructor.PAGE_TEXTS.gap}},t.prototype.curPage=function(){var t,s,i;return t=this.currentPage(),s=this.firstPage(),i=this.lastPage(),this.buildPage(t,null,t,s,i)},t.prototype.pages=function(){var t,s,i,e,r,n,a,h;for(t=this.currentPage(),s=this.firstPage(),e=this.lastPage(),h=[],i=null,r=a=s;e>=s?e>=a:a>=e;r=e>=s?++a:--a)n=this.buildPage(r,i,t,s,e),i=n.isLeftOuter||n.isRightOuter||n.isInsideWindow?null:this.constructor.PAGE_TEXTS.gap,h.push(n);return h},t.prototype.buildButtonsAndLocals=function(){var t,s,i,e,r,n,a;for(e=[],a={},t=this.curPage(),i=this.pages(),t.isFirst?a.hasFirst=!1:(e.push(this.constructor.PAGE_TEXTS.first),a.hasFirst=!0),t.isFirst?a.hasPrev=!1:(e.push(this.constructor.PAGE_TEXTS.prev),a.hasPrev=!0),a.pages=[],r=0,n=i.length;n>r;r++)s=i[r],s.isLeftOuter||s.isRightOuter||s.isInsideWindow?s.isCurrent?(e.push(this.constructor.PAGE_TEXTS.current),a.pages.push({number:s.number,current:!0})):(e.push(s.number),a.pages.push({number:s.number,current:!1})):s.isWasTruncated||(e.push(this.constructor.PAGE_TEXTS.gap),a.pages.push({number:s.number,gap:!0}));return t.isLast?a.hasNext=!1:(e.push(this.constructor.PAGE_TEXTS.next),a.hasNext=!0),t.isLast?a.hasLast=!1:(e.push(this.constructor.PAGE_TEXTS.last),a.hasLast=!0),a.first=this.firstPage(),a.current=this.currentPage(),a.last=this.lastPage(),a.numStart=0===this.records.length?0:this.offsetValue()+1,a.numEnd=this.offsetValue()+this.records.length,a.numTotal=this.totalCount,this.buttons=e,this.locals=a},t}(),i=function(t){return"[object Array]"===Object.prototype.toString.call(t)},t.isArray=i,null!=this.MyPaginatorName&&(this[this.MyPaginatorName]=t),null!=this.Spine&&(t.SpineModelExtend={page:function(s,i){return null==i&&(i={}),new t(this._perPaginateRecords(),s,i)},_perPaginateRecords:function(){return this.all()}},s=this.Spine,s.Paginator=t,s.Model.Paginator={extended:function(){return this.extend(t.SpineModelExtend)}})}).call(this);
@@ -0,0 +1,57 @@
1
+ window.App = App = {}
2
+
3
+ Spine = @Spine
4
+
5
+ class App.User extends Spine.Model
6
+ @configure 'User', 'name'
7
+ @extend Spine.Model.Paginator
8
+
9
+
10
+ User = App.User
11
+ App.UsersCtrl ||= {}
12
+ Ctrl = App.UsersCtrl
13
+
14
+ class Ctrl.IndexPagination extends Spine.PaginationController
15
+ @MODEL = User
16
+ @PER_PAGES = [5, 10, 20, 30]
17
+ @PAGINATE_EVENT = "paginate"
18
+
19
+ class Ctrl.IndexTbody extends Spine.Controller
20
+ constructor: ->
21
+ super
22
+ User.bind Ctrl.IndexPagination.PAGINATE_EVENT, @render
23
+
24
+ render: =>
25
+ @html @templateHtml()
26
+
27
+ templateHtml: =>
28
+ collection = Ctrl.IndexPagination.PAGINATION.records
29
+ source = """
30
+ {{#each collection}}
31
+ <tr data-id={{this.id}}>
32
+ <td>{{this.id}}</td>
33
+ <td>{{this.name}}</td>
34
+ </tr>
35
+ {{/each}}
36
+ """
37
+ Handlebars.compile(source)({collection: collection})
38
+
39
+ class Ctrl.Index extends Spine.Controller
40
+ constructor: ->
41
+ super
42
+ @tbody = new Ctrl.IndexTbody
43
+ el: @$('tbody')
44
+ @pagination = new Ctrl.IndexPagination
45
+ el: @$('#pagination')
46
+ User.bind 'refresh', @refreshPagination
47
+
48
+ refreshPagination: ->
49
+ Ctrl.IndexPagination.refresh()
50
+
51
+
52
+ $(document).ready ->
53
+ App.UsersCtrl.index = new App.UsersCtrl.Index
54
+ el: '#users'
55
+
56
+ data = ({name: String.fromCharCode(num)} for num in ['A'.charCodeAt(0)..'z'.charCodeAt(0)])
57
+ App.User.refresh(data)
@@ -0,0 +1,2 @@
1
+ .pagination ul .active a {
2
+ color: red; }
@@ -0,0 +1 @@
1
+ <!DOCTYPE html><html><head><title>Spine Pagination Demo</title><link href="http://twitter.github.io/bootstrap/assets/css/bootstrap.css" rel="stylesheet" /><link href="./spine_pagination.css" rel="stylesheet" /><script type="text/javascript">window.MyPaginationName = "Paginator"</script><script src="http://code.jquery.com/jquery-1.9.1.min.js"></script><script src="../spec/lib/spine.js"></script><script src="../spec/lib/handlebars.js"></script><script src="../dist/spine.paginator.js"></script><script src="../dist/spine.pagination_controller.js"></script><script src="./spine_pagination.js"></script></head><body><h1>Spine Pagination Demo</h1><div id="users"><table class="table table-hover"><thead><tr><td>ID</td><td>Name</td></tr></thead><tbody></tbody></table><div id="pagination"></div></div></body></html>
@@ -0,0 +1,120 @@
1
+ (function() {
2
+ var App, Ctrl, Spine, User, _ref, _ref1,
3
+ __hasProp = {}.hasOwnProperty,
4
+ __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; },
5
+ __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
6
+
7
+ window.App = App = {};
8
+
9
+ Spine = this.Spine;
10
+
11
+ App.User = (function(_super) {
12
+ __extends(User, _super);
13
+
14
+ function User() {
15
+ _ref = User.__super__.constructor.apply(this, arguments);
16
+ return _ref;
17
+ }
18
+
19
+ User.configure('User', 'name');
20
+
21
+ User.extend(Spine.Model.Paginator);
22
+
23
+ return User;
24
+
25
+ })(Spine.Model);
26
+
27
+ User = App.User;
28
+
29
+ App.UsersCtrl || (App.UsersCtrl = {});
30
+
31
+ Ctrl = App.UsersCtrl;
32
+
33
+ Ctrl.IndexPagination = (function(_super) {
34
+ __extends(IndexPagination, _super);
35
+
36
+ function IndexPagination() {
37
+ _ref1 = IndexPagination.__super__.constructor.apply(this, arguments);
38
+ return _ref1;
39
+ }
40
+
41
+ IndexPagination.MODEL = User;
42
+
43
+ IndexPagination.PER_PAGES = [5, 10, 20, 30];
44
+
45
+ IndexPagination.PAGINATE_EVENT = "paginate";
46
+
47
+ return IndexPagination;
48
+
49
+ })(Spine.PaginationController);
50
+
51
+ Ctrl.IndexTbody = (function(_super) {
52
+ __extends(IndexTbody, _super);
53
+
54
+ function IndexTbody() {
55
+ this.templateHtml = __bind(this.templateHtml, this);
56
+ this.render = __bind(this.render, this); IndexTbody.__super__.constructor.apply(this, arguments);
57
+ User.bind(Ctrl.IndexPagination.PAGINATE_EVENT, this.render);
58
+ }
59
+
60
+ IndexTbody.prototype.render = function() {
61
+ return this.html(this.templateHtml());
62
+ };
63
+
64
+ IndexTbody.prototype.templateHtml = function() {
65
+ var collection, source;
66
+
67
+ collection = Ctrl.IndexPagination.PAGINATION.records;
68
+ source = "{{#each collection}}\n <tr data-id={{this.id}}>\n <td>{{this.id}}</td>\n <td>{{this.name}}</td>\n </tr>\n{{/each}}";
69
+ return Handlebars.compile(source)({
70
+ collection: collection
71
+ });
72
+ };
73
+
74
+ return IndexTbody;
75
+
76
+ })(Spine.Controller);
77
+
78
+ Ctrl.Index = (function(_super) {
79
+ __extends(Index, _super);
80
+
81
+ function Index() {
82
+ Index.__super__.constructor.apply(this, arguments);
83
+ this.tbody = new Ctrl.IndexTbody({
84
+ el: this.$('tbody')
85
+ });
86
+ this.pagination = new Ctrl.IndexPagination({
87
+ el: this.$('#pagination')
88
+ });
89
+ User.bind('refresh', this.refreshPagination);
90
+ }
91
+
92
+ Index.prototype.refreshPagination = function() {
93
+ return Ctrl.IndexPagination.refresh();
94
+ };
95
+
96
+ return Index;
97
+
98
+ })(Spine.Controller);
99
+
100
+ $(document).ready(function() {
101
+ var data, num;
102
+
103
+ App.UsersCtrl.index = new App.UsersCtrl.Index({
104
+ el: '#users'
105
+ });
106
+ data = (function() {
107
+ var _i, _ref2, _ref3, _results;
108
+
109
+ _results = [];
110
+ for (num = _i = _ref2 = 'A'.charCodeAt(0), _ref3 = 'z'.charCodeAt(0); _ref2 <= _ref3 ? _i <= _ref3 : _i >= _ref3; num = _ref2 <= _ref3 ? ++_i : --_i) {
111
+ _results.push({
112
+ name: String.fromCharCode(num)
113
+ });
114
+ }
115
+ return _results;
116
+ })();
117
+ return App.User.refresh(data);
118
+ });
119
+
120
+ }).call(this);
@@ -0,0 +1,3 @@
1
+ .pagination ul .active a {
2
+ color: red;
3
+ }
@@ -0,0 +1,25 @@
1
+ doctype html
2
+ html
3
+ head
4
+ title Spine Pagination Demo
5
+ link href="http://twitter.github.io/bootstrap/assets/css/bootstrap.css" rel="stylesheet"
6
+ link href="./spine_pagination.css" rel="stylesheet"
7
+ javascript:
8
+ window.MyPaginationName = "Paginator"
9
+ script src="http://code.jquery.com/jquery-1.9.1.min.js"
10
+ script src="../spec/lib/spine.js"
11
+ script src="../spec/lib/handlebars.js"
12
+ script src="../dist/spine.paginator.js"
13
+ script src="../dist/spine.pagination_controller.js"
14
+ script src="./spine_pagination.js"
15
+
16
+ body
17
+ h1 Spine Pagination Demo
18
+ #users
19
+ table.table.table-hover
20
+ thead
21
+ tr
22
+ td ID
23
+ td Name
24
+ tbody
25
+ #pagination
@@ -1,3 +1,3 @@
1
1
  module SpinePaginator
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "spine.paginator",
3
3
  "description": "Paginator for Spine.",
4
- "version": "0.1.0",
4
+ "version": "0.1.1",
5
5
  "author": "vkill",
6
6
  "url": "https://github.com/vkill/spine_paginator",
7
7
  "main": "./dist/spine.paginator.js",
8
8
  "licenses": [
9
9
  {
10
10
  "type": "MIT",
11
- "url": "https://github.com/vkill/spina_paginator/blob/master/LICENSE-MIT"
11
+ "url": "https://github.com/vkill/spina_paginator/blob/master/LICENSE.txt"
12
12
  }
13
13
  ],
14
14
  "repository": {
@@ -24,7 +24,9 @@
24
24
  "grunt-contrib-concat": "~0.3.0",
25
25
  "grunt-contrib-uglify": "~0.2.0",
26
26
  "grunt-contrib-jasmine": "~0.4.2",
27
- "grunt-contrib-watch": "~0.3.1"
27
+ "grunt-contrib-watch": "~0.3.1",
28
+ "grunt-slim": "~0.1.0",
29
+ "grunt-contrib-sass": "~0.3.0"
28
30
  },
29
31
  "engines": {
30
32
  "node": ">= 0.8.0"
@@ -0,0 +1,2239 @@
1
+ /*
2
+
3
+ Copyright (C) 2011 by Yehuda Katz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
22
+
23
+ */
24
+
25
+ // lib/handlebars/browser-prefix.js
26
+ var Handlebars = {};
27
+
28
+ (function(Handlebars, undefined) {
29
+ ;
30
+ // lib/handlebars/base.js
31
+
32
+ Handlebars.VERSION = "1.0.0-rc.3";
33
+ Handlebars.COMPILER_REVISION = 3;
34
+
35
+ Handlebars.REVISION_CHANGES = {
36
+ 1: '<= 1.0.rc.2', // 1.0.rc.2 is actually rev2 but doesn't report it
37
+ 2: '== 1.0.0-rc.3',
38
+ 3: '>= 1.0.0-rc.4'
39
+ };
40
+
41
+ Handlebars.helpers = {};
42
+ Handlebars.partials = {};
43
+
44
+ var toString = Object.prototype.toString,
45
+ functionType = '[object Function]',
46
+ objectType = '[object Object]';
47
+
48
+ Handlebars.registerHelper = function(name, fn, inverse) {
49
+ if (toString.call(name) === objectType) {
50
+ if (inverse || fn) { throw new Handlebars.Exception('Arg not supported with multiple helpers'); }
51
+ Handlebars.Utils.extend(this.helpers, name);
52
+ } else {
53
+ if (inverse) { fn.not = inverse; }
54
+ this.helpers[name] = fn;
55
+ }
56
+ };
57
+
58
+ Handlebars.registerPartial = function(name, str) {
59
+ if (toString.call(name) === objectType) {
60
+ Handlebars.Utils.extend(this.partials, name);
61
+ } else {
62
+ this.partials[name] = str;
63
+ }
64
+ };
65
+
66
+ Handlebars.registerHelper('helperMissing', function(arg) {
67
+ if(arguments.length === 2) {
68
+ return undefined;
69
+ } else {
70
+ throw new Error("Could not find property '" + arg + "'");
71
+ }
72
+ });
73
+
74
+ Handlebars.registerHelper('blockHelperMissing', function(context, options) {
75
+ var inverse = options.inverse || function() {}, fn = options.fn;
76
+
77
+ var type = toString.call(context);
78
+
79
+ if(type === functionType) { context = context.call(this); }
80
+
81
+ if(context === true) {
82
+ return fn(this);
83
+ } else if(context === false || context == null) {
84
+ return inverse(this);
85
+ } else if(type === "[object Array]") {
86
+ if(context.length > 0) {
87
+ return Handlebars.helpers.each(context, options);
88
+ } else {
89
+ return inverse(this);
90
+ }
91
+ } else {
92
+ return fn(context);
93
+ }
94
+ });
95
+
96
+ Handlebars.K = function() {};
97
+
98
+ Handlebars.createFrame = Object.create || function(object) {
99
+ Handlebars.K.prototype = object;
100
+ var obj = new Handlebars.K();
101
+ Handlebars.K.prototype = null;
102
+ return obj;
103
+ };
104
+
105
+ Handlebars.logger = {
106
+ DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3, level: 3,
107
+
108
+ methodMap: {0: 'debug', 1: 'info', 2: 'warn', 3: 'error'},
109
+
110
+ // can be overridden in the host environment
111
+ log: function(level, obj) {
112
+ if (Handlebars.logger.level <= level) {
113
+ var method = Handlebars.logger.methodMap[level];
114
+ if (typeof console !== 'undefined' && console[method]) {
115
+ console[method].call(console, obj);
116
+ }
117
+ }
118
+ }
119
+ };
120
+
121
+ Handlebars.log = function(level, obj) { Handlebars.logger.log(level, obj); };
122
+
123
+ Handlebars.registerHelper('each', function(context, options) {
124
+ var fn = options.fn, inverse = options.inverse;
125
+ var i = 0, ret = "", data;
126
+
127
+ if (options.data) {
128
+ data = Handlebars.createFrame(options.data);
129
+ }
130
+
131
+ if(context && typeof context === 'object') {
132
+ if(context instanceof Array){
133
+ for(var j = context.length; i<j; i++) {
134
+ if (data) { data.index = i; }
135
+ ret = ret + fn(context[i], { data: data });
136
+ }
137
+ } else {
138
+ for(var key in context) {
139
+ if(context.hasOwnProperty(key)) {
140
+ if(data) { data.key = key; }
141
+ ret = ret + fn(context[key], {data: data});
142
+ i++;
143
+ }
144
+ }
145
+ }
146
+ }
147
+
148
+ if(i === 0){
149
+ ret = inverse(this);
150
+ }
151
+
152
+ return ret;
153
+ });
154
+
155
+ Handlebars.registerHelper('if', function(context, options) {
156
+ var type = toString.call(context);
157
+ if(type === functionType) { context = context.call(this); }
158
+
159
+ if(!context || Handlebars.Utils.isEmpty(context)) {
160
+ return options.inverse(this);
161
+ } else {
162
+ return options.fn(this);
163
+ }
164
+ });
165
+
166
+ Handlebars.registerHelper('unless', function(context, options) {
167
+ return Handlebars.helpers['if'].call(this, context, {fn: options.inverse, inverse: options.fn});
168
+ });
169
+
170
+ Handlebars.registerHelper('with', function(context, options) {
171
+ if (!Handlebars.Utils.isEmpty(context)) return options.fn(context);
172
+ });
173
+
174
+ Handlebars.registerHelper('log', function(context, options) {
175
+ var level = options.data && options.data.level != null ? parseInt(options.data.level, 10) : 1;
176
+ Handlebars.log(level, context);
177
+ });
178
+ ;
179
+ // lib/handlebars/compiler/parser.js
180
+ /* Jison generated parser */
181
+ var handlebars = (function(){
182
+ var parser = {trace: function trace() { },
183
+ yy: {},
184
+ symbols_: {"error":2,"root":3,"program":4,"EOF":5,"simpleInverse":6,"statements":7,"statement":8,"openInverse":9,"closeBlock":10,"openBlock":11,"mustache":12,"partial":13,"CONTENT":14,"COMMENT":15,"OPEN_BLOCK":16,"inMustache":17,"CLOSE":18,"OPEN_INVERSE":19,"OPEN_ENDBLOCK":20,"path":21,"OPEN":22,"OPEN_UNESCAPED":23,"OPEN_PARTIAL":24,"partialName":25,"params":26,"hash":27,"DATA":28,"param":29,"STRING":30,"INTEGER":31,"BOOLEAN":32,"hashSegments":33,"hashSegment":34,"ID":35,"EQUALS":36,"PARTIAL_NAME":37,"pathSegments":38,"SEP":39,"$accept":0,"$end":1},
185
+ terminals_: {2:"error",5:"EOF",14:"CONTENT",15:"COMMENT",16:"OPEN_BLOCK",18:"CLOSE",19:"OPEN_INVERSE",20:"OPEN_ENDBLOCK",22:"OPEN",23:"OPEN_UNESCAPED",24:"OPEN_PARTIAL",28:"DATA",30:"STRING",31:"INTEGER",32:"BOOLEAN",35:"ID",36:"EQUALS",37:"PARTIAL_NAME",39:"SEP"},
186
+ productions_: [0,[3,2],[4,2],[4,3],[4,2],[4,1],[4,1],[4,0],[7,1],[7,2],[8,3],[8,3],[8,1],[8,1],[8,1],[8,1],[11,3],[9,3],[10,3],[12,3],[12,3],[13,3],[13,4],[6,2],[17,3],[17,2],[17,2],[17,1],[17,1],[26,2],[26,1],[29,1],[29,1],[29,1],[29,1],[29,1],[27,1],[33,2],[33,1],[34,3],[34,3],[34,3],[34,3],[34,3],[25,1],[21,1],[38,3],[38,1]],
187
+ performAction: function anonymous(yytext,yyleng,yylineno,yy,yystate,$$,_$) {
188
+
189
+ var $0 = $$.length - 1;
190
+ switch (yystate) {
191
+ case 1: return $$[$0-1];
192
+ break;
193
+ case 2: this.$ = new yy.ProgramNode([], $$[$0]);
194
+ break;
195
+ case 3: this.$ = new yy.ProgramNode($$[$0-2], $$[$0]);
196
+ break;
197
+ case 4: this.$ = new yy.ProgramNode($$[$0-1], []);
198
+ break;
199
+ case 5: this.$ = new yy.ProgramNode($$[$0]);
200
+ break;
201
+ case 6: this.$ = new yy.ProgramNode([], []);
202
+ break;
203
+ case 7: this.$ = new yy.ProgramNode([]);
204
+ break;
205
+ case 8: this.$ = [$$[$0]];
206
+ break;
207
+ case 9: $$[$0-1].push($$[$0]); this.$ = $$[$0-1];
208
+ break;
209
+ case 10: this.$ = new yy.BlockNode($$[$0-2], $$[$0-1].inverse, $$[$0-1], $$[$0]);
210
+ break;
211
+ case 11: this.$ = new yy.BlockNode($$[$0-2], $$[$0-1], $$[$0-1].inverse, $$[$0]);
212
+ break;
213
+ case 12: this.$ = $$[$0];
214
+ break;
215
+ case 13: this.$ = $$[$0];
216
+ break;
217
+ case 14: this.$ = new yy.ContentNode($$[$0]);
218
+ break;
219
+ case 15: this.$ = new yy.CommentNode($$[$0]);
220
+ break;
221
+ case 16: this.$ = new yy.MustacheNode($$[$0-1][0], $$[$0-1][1]);
222
+ break;
223
+ case 17: this.$ = new yy.MustacheNode($$[$0-1][0], $$[$0-1][1]);
224
+ break;
225
+ case 18: this.$ = $$[$0-1];
226
+ break;
227
+ case 19: this.$ = new yy.MustacheNode($$[$0-1][0], $$[$0-1][1]);
228
+ break;
229
+ case 20: this.$ = new yy.MustacheNode($$[$0-1][0], $$[$0-1][1], true);
230
+ break;
231
+ case 21: this.$ = new yy.PartialNode($$[$0-1]);
232
+ break;
233
+ case 22: this.$ = new yy.PartialNode($$[$0-2], $$[$0-1]);
234
+ break;
235
+ case 23:
236
+ break;
237
+ case 24: this.$ = [[$$[$0-2]].concat($$[$0-1]), $$[$0]];
238
+ break;
239
+ case 25: this.$ = [[$$[$0-1]].concat($$[$0]), null];
240
+ break;
241
+ case 26: this.$ = [[$$[$0-1]], $$[$0]];
242
+ break;
243
+ case 27: this.$ = [[$$[$0]], null];
244
+ break;
245
+ case 28: this.$ = [[new yy.DataNode($$[$0])], null];
246
+ break;
247
+ case 29: $$[$0-1].push($$[$0]); this.$ = $$[$0-1];
248
+ break;
249
+ case 30: this.$ = [$$[$0]];
250
+ break;
251
+ case 31: this.$ = $$[$0];
252
+ break;
253
+ case 32: this.$ = new yy.StringNode($$[$0]);
254
+ break;
255
+ case 33: this.$ = new yy.IntegerNode($$[$0]);
256
+ break;
257
+ case 34: this.$ = new yy.BooleanNode($$[$0]);
258
+ break;
259
+ case 35: this.$ = new yy.DataNode($$[$0]);
260
+ break;
261
+ case 36: this.$ = new yy.HashNode($$[$0]);
262
+ break;
263
+ case 37: $$[$0-1].push($$[$0]); this.$ = $$[$0-1];
264
+ break;
265
+ case 38: this.$ = [$$[$0]];
266
+ break;
267
+ case 39: this.$ = [$$[$0-2], $$[$0]];
268
+ break;
269
+ case 40: this.$ = [$$[$0-2], new yy.StringNode($$[$0])];
270
+ break;
271
+ case 41: this.$ = [$$[$0-2], new yy.IntegerNode($$[$0])];
272
+ break;
273
+ case 42: this.$ = [$$[$0-2], new yy.BooleanNode($$[$0])];
274
+ break;
275
+ case 43: this.$ = [$$[$0-2], new yy.DataNode($$[$0])];
276
+ break;
277
+ case 44: this.$ = new yy.PartialNameNode($$[$0]);
278
+ break;
279
+ case 45: this.$ = new yy.IdNode($$[$0]);
280
+ break;
281
+ case 46: $$[$0-2].push($$[$0]); this.$ = $$[$0-2];
282
+ break;
283
+ case 47: this.$ = [$$[$0]];
284
+ break;
285
+ }
286
+ },
287
+ table: [{3:1,4:2,5:[2,7],6:3,7:4,8:6,9:7,11:8,12:9,13:10,14:[1,11],15:[1,12],16:[1,13],19:[1,5],22:[1,14],23:[1,15],24:[1,16]},{1:[3]},{5:[1,17]},{5:[2,6],7:18,8:6,9:7,11:8,12:9,13:10,14:[1,11],15:[1,12],16:[1,13],19:[1,19],20:[2,6],22:[1,14],23:[1,15],24:[1,16]},{5:[2,5],6:20,8:21,9:7,11:8,12:9,13:10,14:[1,11],15:[1,12],16:[1,13],19:[1,5],20:[2,5],22:[1,14],23:[1,15],24:[1,16]},{17:23,18:[1,22],21:24,28:[1,25],35:[1,27],38:26},{5:[2,8],14:[2,8],15:[2,8],16:[2,8],19:[2,8],20:[2,8],22:[2,8],23:[2,8],24:[2,8]},{4:28,6:3,7:4,8:6,9:7,11:8,12:9,13:10,14:[1,11],15:[1,12],16:[1,13],19:[1,5],20:[2,7],22:[1,14],23:[1,15],24:[1,16]},{4:29,6:3,7:4,8:6,9:7,11:8,12:9,13:10,14:[1,11],15:[1,12],16:[1,13],19:[1,5],20:[2,7],22:[1,14],23:[1,15],24:[1,16]},{5:[2,12],14:[2,12],15:[2,12],16:[2,12],19:[2,12],20:[2,12],22:[2,12],23:[2,12],24:[2,12]},{5:[2,13],14:[2,13],15:[2,13],16:[2,13],19:[2,13],20:[2,13],22:[2,13],23:[2,13],24:[2,13]},{5:[2,14],14:[2,14],15:[2,14],16:[2,14],19:[2,14],20:[2,14],22:[2,14],23:[2,14],24:[2,14]},{5:[2,15],14:[2,15],15:[2,15],16:[2,15],19:[2,15],20:[2,15],22:[2,15],23:[2,15],24:[2,15]},{17:30,21:24,28:[1,25],35:[1,27],38:26},{17:31,21:24,28:[1,25],35:[1,27],38:26},{17:32,21:24,28:[1,25],35:[1,27],38:26},{25:33,37:[1,34]},{1:[2,1]},{5:[2,2],8:21,9:7,11:8,12:9,13:10,14:[1,11],15:[1,12],16:[1,13],19:[1,19],20:[2,2],22:[1,14],23:[1,15],24:[1,16]},{17:23,21:24,28:[1,25],35:[1,27],38:26},{5:[2,4],7:35,8:6,9:7,11:8,12:9,13:10,14:[1,11],15:[1,12],16:[1,13],19:[1,19],20:[2,4],22:[1,14],23:[1,15],24:[1,16]},{5:[2,9],14:[2,9],15:[2,9],16:[2,9],19:[2,9],20:[2,9],22:[2,9],23:[2,9],24:[2,9]},{5:[2,23],14:[2,23],15:[2,23],16:[2,23],19:[2,23],20:[2,23],22:[2,23],23:[2,23],24:[2,23]},{18:[1,36]},{18:[2,27],21:41,26:37,27:38,28:[1,45],29:39,30:[1,42],31:[1,43],32:[1,44],33:40,34:46,35:[1,47],38:26},{18:[2,28]},{18:[2,45],28:[2,45],30:[2,45],31:[2,45],32:[2,45],35:[2,45],39:[1,48]},{18:[2,47],28:[2,47],30:[2,47],31:[2,47],32:[2,47],35:[2,47],39:[2,47]},{10:49,20:[1,50]},{10:51,20:[1,50]},{18:[1,52]},{18:[1,53]},{18:[1,54]},{18:[1,55],21:56,35:[1,27],38:26},{18:[2,44],35:[2,44]},{5:[2,3],8:21,9:7,11:8,12:9,13:10,14:[1,11],15:[1,12],16:[1,13],19:[1,19],20:[2,3],22:[1,14],23:[1,15],24:[1,16]},{14:[2,17],15:[2,17],16:[2,17],19:[2,17],20:[2,17],22:[2,17],23:[2,17],24:[2,17]},{18:[2,25],21:41,27:57,28:[1,45],29:58,30:[1,42],31:[1,43],32:[1,44],33:40,34:46,35:[1,47],38:26},{18:[2,26]},{18:[2,30],28:[2,30],30:[2,30],31:[2,30],32:[2,30],35:[2,30]},{18:[2,36],34:59,35:[1,60]},{18:[2,31],28:[2,31],30:[2,31],31:[2,31],32:[2,31],35:[2,31]},{18:[2,32],28:[2,32],30:[2,32],31:[2,32],32:[2,32],35:[2,32]},{18:[2,33],28:[2,33],30:[2,33],31:[2,33],32:[2,33],35:[2,33]},{18:[2,34],28:[2,34],30:[2,34],31:[2,34],32:[2,34],35:[2,34]},{18:[2,35],28:[2,35],30:[2,35],31:[2,35],32:[2,35],35:[2,35]},{18:[2,38],35:[2,38]},{18:[2,47],28:[2,47],30:[2,47],31:[2,47],32:[2,47],35:[2,47],36:[1,61],39:[2,47]},{35:[1,62]},{5:[2,10],14:[2,10],15:[2,10],16:[2,10],19:[2,10],20:[2,10],22:[2,10],23:[2,10],24:[2,10]},{21:63,35:[1,27],38:26},{5:[2,11],14:[2,11],15:[2,11],16:[2,11],19:[2,11],20:[2,11],22:[2,11],23:[2,11],24:[2,11]},{14:[2,16],15:[2,16],16:[2,16],19:[2,16],20:[2,16],22:[2,16],23:[2,16],24:[2,16]},{5:[2,19],14:[2,19],15:[2,19],16:[2,19],19:[2,19],20:[2,19],22:[2,19],23:[2,19],24:[2,19]},{5:[2,20],14:[2,20],15:[2,20],16:[2,20],19:[2,20],20:[2,20],22:[2,20],23:[2,20],24:[2,20]},{5:[2,21],14:[2,21],15:[2,21],16:[2,21],19:[2,21],20:[2,21],22:[2,21],23:[2,21],24:[2,21]},{18:[1,64]},{18:[2,24]},{18:[2,29],28:[2,29],30:[2,29],31:[2,29],32:[2,29],35:[2,29]},{18:[2,37],35:[2,37]},{36:[1,61]},{21:65,28:[1,69],30:[1,66],31:[1,67],32:[1,68],35:[1,27],38:26},{18:[2,46],28:[2,46],30:[2,46],31:[2,46],32:[2,46],35:[2,46],39:[2,46]},{18:[1,70]},{5:[2,22],14:[2,22],15:[2,22],16:[2,22],19:[2,22],20:[2,22],22:[2,22],23:[2,22],24:[2,22]},{18:[2,39],35:[2,39]},{18:[2,40],35:[2,40]},{18:[2,41],35:[2,41]},{18:[2,42],35:[2,42]},{18:[2,43],35:[2,43]},{5:[2,18],14:[2,18],15:[2,18],16:[2,18],19:[2,18],20:[2,18],22:[2,18],23:[2,18],24:[2,18]}],
288
+ defaultActions: {17:[2,1],25:[2,28],38:[2,26],57:[2,24]},
289
+ parseError: function parseError(str, hash) {
290
+ throw new Error(str);
291
+ },
292
+ parse: function parse(input) {
293
+ var self = this, stack = [0], vstack = [null], lstack = [], table = this.table, yytext = "", yylineno = 0, yyleng = 0, recovering = 0, TERROR = 2, EOF = 1;
294
+ this.lexer.setInput(input);
295
+ this.lexer.yy = this.yy;
296
+ this.yy.lexer = this.lexer;
297
+ this.yy.parser = this;
298
+ if (typeof this.lexer.yylloc == "undefined")
299
+ this.lexer.yylloc = {};
300
+ var yyloc = this.lexer.yylloc;
301
+ lstack.push(yyloc);
302
+ var ranges = this.lexer.options && this.lexer.options.ranges;
303
+ if (typeof this.yy.parseError === "function")
304
+ this.parseError = this.yy.parseError;
305
+ function popStack(n) {
306
+ stack.length = stack.length - 2 * n;
307
+ vstack.length = vstack.length - n;
308
+ lstack.length = lstack.length - n;
309
+ }
310
+ function lex() {
311
+ var token;
312
+ token = self.lexer.lex() || 1;
313
+ if (typeof token !== "number") {
314
+ token = self.symbols_[token] || token;
315
+ }
316
+ return token;
317
+ }
318
+ var symbol, preErrorSymbol, state, action, a, r, yyval = {}, p, len, newState, expected;
319
+ while (true) {
320
+ state = stack[stack.length - 1];
321
+ if (this.defaultActions[state]) {
322
+ action = this.defaultActions[state];
323
+ } else {
324
+ if (symbol === null || typeof symbol == "undefined") {
325
+ symbol = lex();
326
+ }
327
+ action = table[state] && table[state][symbol];
328
+ }
329
+ if (typeof action === "undefined" || !action.length || !action[0]) {
330
+ var errStr = "";
331
+ if (!recovering) {
332
+ expected = [];
333
+ for (p in table[state])
334
+ if (this.terminals_[p] && p > 2) {
335
+ expected.push("'" + this.terminals_[p] + "'");
336
+ }
337
+ if (this.lexer.showPosition) {
338
+ errStr = "Parse error on line " + (yylineno + 1) + ":\n" + this.lexer.showPosition() + "\nExpecting " + expected.join(", ") + ", got '" + (this.terminals_[symbol] || symbol) + "'";
339
+ } else {
340
+ errStr = "Parse error on line " + (yylineno + 1) + ": Unexpected " + (symbol == 1?"end of input":"'" + (this.terminals_[symbol] || symbol) + "'");
341
+ }
342
+ this.parseError(errStr, {text: this.lexer.match, token: this.terminals_[symbol] || symbol, line: this.lexer.yylineno, loc: yyloc, expected: expected});
343
+ }
344
+ }
345
+ if (action[0] instanceof Array && action.length > 1) {
346
+ throw new Error("Parse Error: multiple actions possible at state: " + state + ", token: " + symbol);
347
+ }
348
+ switch (action[0]) {
349
+ case 1:
350
+ stack.push(symbol);
351
+ vstack.push(this.lexer.yytext);
352
+ lstack.push(this.lexer.yylloc);
353
+ stack.push(action[1]);
354
+ symbol = null;
355
+ if (!preErrorSymbol) {
356
+ yyleng = this.lexer.yyleng;
357
+ yytext = this.lexer.yytext;
358
+ yylineno = this.lexer.yylineno;
359
+ yyloc = this.lexer.yylloc;
360
+ if (recovering > 0)
361
+ recovering--;
362
+ } else {
363
+ symbol = preErrorSymbol;
364
+ preErrorSymbol = null;
365
+ }
366
+ break;
367
+ case 2:
368
+ len = this.productions_[action[1]][1];
369
+ yyval.$ = vstack[vstack.length - len];
370
+ yyval._$ = {first_line: lstack[lstack.length - (len || 1)].first_line, last_line: lstack[lstack.length - 1].last_line, first_column: lstack[lstack.length - (len || 1)].first_column, last_column: lstack[lstack.length - 1].last_column};
371
+ if (ranges) {
372
+ yyval._$.range = [lstack[lstack.length - (len || 1)].range[0], lstack[lstack.length - 1].range[1]];
373
+ }
374
+ r = this.performAction.call(yyval, yytext, yyleng, yylineno, this.yy, action[1], vstack, lstack);
375
+ if (typeof r !== "undefined") {
376
+ return r;
377
+ }
378
+ if (len) {
379
+ stack = stack.slice(0, -1 * len * 2);
380
+ vstack = vstack.slice(0, -1 * len);
381
+ lstack = lstack.slice(0, -1 * len);
382
+ }
383
+ stack.push(this.productions_[action[1]][0]);
384
+ vstack.push(yyval.$);
385
+ lstack.push(yyval._$);
386
+ newState = table[stack[stack.length - 2]][stack[stack.length - 1]];
387
+ stack.push(newState);
388
+ break;
389
+ case 3:
390
+ return true;
391
+ }
392
+ }
393
+ return true;
394
+ }
395
+ };
396
+ /* Jison generated lexer */
397
+ var lexer = (function(){
398
+ var lexer = ({EOF:1,
399
+ parseError:function parseError(str, hash) {
400
+ if (this.yy.parser) {
401
+ this.yy.parser.parseError(str, hash);
402
+ } else {
403
+ throw new Error(str);
404
+ }
405
+ },
406
+ setInput:function (input) {
407
+ this._input = input;
408
+ this._more = this._less = this.done = false;
409
+ this.yylineno = this.yyleng = 0;
410
+ this.yytext = this.matched = this.match = '';
411
+ this.conditionStack = ['INITIAL'];
412
+ this.yylloc = {first_line:1,first_column:0,last_line:1,last_column:0};
413
+ if (this.options.ranges) this.yylloc.range = [0,0];
414
+ this.offset = 0;
415
+ return this;
416
+ },
417
+ input:function () {
418
+ var ch = this._input[0];
419
+ this.yytext += ch;
420
+ this.yyleng++;
421
+ this.offset++;
422
+ this.match += ch;
423
+ this.matched += ch;
424
+ var lines = ch.match(/(?:\r\n?|\n).*/g);
425
+ if (lines) {
426
+ this.yylineno++;
427
+ this.yylloc.last_line++;
428
+ } else {
429
+ this.yylloc.last_column++;
430
+ }
431
+ if (this.options.ranges) this.yylloc.range[1]++;
432
+
433
+ this._input = this._input.slice(1);
434
+ return ch;
435
+ },
436
+ unput:function (ch) {
437
+ var len = ch.length;
438
+ var lines = ch.split(/(?:\r\n?|\n)/g);
439
+
440
+ this._input = ch + this._input;
441
+ this.yytext = this.yytext.substr(0, this.yytext.length-len-1);
442
+ //this.yyleng -= len;
443
+ this.offset -= len;
444
+ var oldLines = this.match.split(/(?:\r\n?|\n)/g);
445
+ this.match = this.match.substr(0, this.match.length-1);
446
+ this.matched = this.matched.substr(0, this.matched.length-1);
447
+
448
+ if (lines.length-1) this.yylineno -= lines.length-1;
449
+ var r = this.yylloc.range;
450
+
451
+ this.yylloc = {first_line: this.yylloc.first_line,
452
+ last_line: this.yylineno+1,
453
+ first_column: this.yylloc.first_column,
454
+ last_column: lines ?
455
+ (lines.length === oldLines.length ? this.yylloc.first_column : 0) + oldLines[oldLines.length - lines.length].length - lines[0].length:
456
+ this.yylloc.first_column - len
457
+ };
458
+
459
+ if (this.options.ranges) {
460
+ this.yylloc.range = [r[0], r[0] + this.yyleng - len];
461
+ }
462
+ return this;
463
+ },
464
+ more:function () {
465
+ this._more = true;
466
+ return this;
467
+ },
468
+ less:function (n) {
469
+ this.unput(this.match.slice(n));
470
+ },
471
+ pastInput:function () {
472
+ var past = this.matched.substr(0, this.matched.length - this.match.length);
473
+ return (past.length > 20 ? '...':'') + past.substr(-20).replace(/\n/g, "");
474
+ },
475
+ upcomingInput:function () {
476
+ var next = this.match;
477
+ if (next.length < 20) {
478
+ next += this._input.substr(0, 20-next.length);
479
+ }
480
+ return (next.substr(0,20)+(next.length > 20 ? '...':'')).replace(/\n/g, "");
481
+ },
482
+ showPosition:function () {
483
+ var pre = this.pastInput();
484
+ var c = new Array(pre.length + 1).join("-");
485
+ return pre + this.upcomingInput() + "\n" + c+"^";
486
+ },
487
+ next:function () {
488
+ if (this.done) {
489
+ return this.EOF;
490
+ }
491
+ if (!this._input) this.done = true;
492
+
493
+ var token,
494
+ match,
495
+ tempMatch,
496
+ index,
497
+ col,
498
+ lines;
499
+ if (!this._more) {
500
+ this.yytext = '';
501
+ this.match = '';
502
+ }
503
+ var rules = this._currentRules();
504
+ for (var i=0;i < rules.length; i++) {
505
+ tempMatch = this._input.match(this.rules[rules[i]]);
506
+ if (tempMatch && (!match || tempMatch[0].length > match[0].length)) {
507
+ match = tempMatch;
508
+ index = i;
509
+ if (!this.options.flex) break;
510
+ }
511
+ }
512
+ if (match) {
513
+ lines = match[0].match(/(?:\r\n?|\n).*/g);
514
+ if (lines) this.yylineno += lines.length;
515
+ this.yylloc = {first_line: this.yylloc.last_line,
516
+ last_line: this.yylineno+1,
517
+ first_column: this.yylloc.last_column,
518
+ last_column: lines ? lines[lines.length-1].length-lines[lines.length-1].match(/\r?\n?/)[0].length : this.yylloc.last_column + match[0].length};
519
+ this.yytext += match[0];
520
+ this.match += match[0];
521
+ this.matches = match;
522
+ this.yyleng = this.yytext.length;
523
+ if (this.options.ranges) {
524
+ this.yylloc.range = [this.offset, this.offset += this.yyleng];
525
+ }
526
+ this._more = false;
527
+ this._input = this._input.slice(match[0].length);
528
+ this.matched += match[0];
529
+ token = this.performAction.call(this, this.yy, this, rules[index],this.conditionStack[this.conditionStack.length-1]);
530
+ if (this.done && this._input) this.done = false;
531
+ if (token) return token;
532
+ else return;
533
+ }
534
+ if (this._input === "") {
535
+ return this.EOF;
536
+ } else {
537
+ return this.parseError('Lexical error on line '+(this.yylineno+1)+'. Unrecognized text.\n'+this.showPosition(),
538
+ {text: "", token: null, line: this.yylineno});
539
+ }
540
+ },
541
+ lex:function lex() {
542
+ var r = this.next();
543
+ if (typeof r !== 'undefined') {
544
+ return r;
545
+ } else {
546
+ return this.lex();
547
+ }
548
+ },
549
+ begin:function begin(condition) {
550
+ this.conditionStack.push(condition);
551
+ },
552
+ popState:function popState() {
553
+ return this.conditionStack.pop();
554
+ },
555
+ _currentRules:function _currentRules() {
556
+ return this.conditions[this.conditionStack[this.conditionStack.length-1]].rules;
557
+ },
558
+ topState:function () {
559
+ return this.conditionStack[this.conditionStack.length-2];
560
+ },
561
+ pushState:function begin(condition) {
562
+ this.begin(condition);
563
+ }});
564
+ lexer.options = {};
565
+ lexer.performAction = function anonymous(yy,yy_,$avoiding_name_collisions,YY_START) {
566
+
567
+ var YYSTATE=YY_START
568
+ switch($avoiding_name_collisions) {
569
+ case 0: yy_.yytext = "\\"; return 14;
570
+ break;
571
+ case 1:
572
+ if(yy_.yytext.slice(-1) !== "\\") this.begin("mu");
573
+ if(yy_.yytext.slice(-1) === "\\") yy_.yytext = yy_.yytext.substr(0,yy_.yyleng-1), this.begin("emu");
574
+ if(yy_.yytext) return 14;
575
+
576
+ break;
577
+ case 2: return 14;
578
+ break;
579
+ case 3:
580
+ if(yy_.yytext.slice(-1) !== "\\") this.popState();
581
+ if(yy_.yytext.slice(-1) === "\\") yy_.yytext = yy_.yytext.substr(0,yy_.yyleng-1);
582
+ return 14;
583
+
584
+ break;
585
+ case 4: yy_.yytext = yy_.yytext.substr(0, yy_.yyleng-4); this.popState(); return 15;
586
+ break;
587
+ case 5: this.begin("par"); return 24;
588
+ break;
589
+ case 6: return 16;
590
+ break;
591
+ case 7: return 20;
592
+ break;
593
+ case 8: return 19;
594
+ break;
595
+ case 9: return 19;
596
+ break;
597
+ case 10: return 23;
598
+ break;
599
+ case 11: return 23;
600
+ break;
601
+ case 12: this.popState(); this.begin('com');
602
+ break;
603
+ case 13: yy_.yytext = yy_.yytext.substr(3,yy_.yyleng-5); this.popState(); return 15;
604
+ break;
605
+ case 14: return 22;
606
+ break;
607
+ case 15: return 36;
608
+ break;
609
+ case 16: return 35;
610
+ break;
611
+ case 17: return 35;
612
+ break;
613
+ case 18: return 39;
614
+ break;
615
+ case 19: /*ignore whitespace*/
616
+ break;
617
+ case 20: this.popState(); return 18;
618
+ break;
619
+ case 21: this.popState(); return 18;
620
+ break;
621
+ case 22: yy_.yytext = yy_.yytext.substr(1,yy_.yyleng-2).replace(/\\"/g,'"'); return 30;
622
+ break;
623
+ case 23: yy_.yytext = yy_.yytext.substr(1,yy_.yyleng-2).replace(/\\'/g,"'"); return 30;
624
+ break;
625
+ case 24: yy_.yytext = yy_.yytext.substr(1); return 28;
626
+ break;
627
+ case 25: return 32;
628
+ break;
629
+ case 26: return 32;
630
+ break;
631
+ case 27: return 31;
632
+ break;
633
+ case 28: return 35;
634
+ break;
635
+ case 29: yy_.yytext = yy_.yytext.substr(1, yy_.yyleng-2); return 35;
636
+ break;
637
+ case 30: return 'INVALID';
638
+ break;
639
+ case 31: /*ignore whitespace*/
640
+ break;
641
+ case 32: this.popState(); return 37;
642
+ break;
643
+ case 33: return 5;
644
+ break;
645
+ }
646
+ };
647
+ lexer.rules = [/^(?:\\\\(?=(\{\{)))/,/^(?:[^\x00]*?(?=(\{\{)))/,/^(?:[^\x00]+)/,/^(?:[^\x00]{2,}?(?=(\{\{|$)))/,/^(?:[\s\S]*?--\}\})/,/^(?:\{\{>)/,/^(?:\{\{#)/,/^(?:\{\{\/)/,/^(?:\{\{\^)/,/^(?:\{\{\s*else\b)/,/^(?:\{\{\{)/,/^(?:\{\{&)/,/^(?:\{\{!--)/,/^(?:\{\{![\s\S]*?\}\})/,/^(?:\{\{)/,/^(?:=)/,/^(?:\.(?=[}/ ]))/,/^(?:\.\.)/,/^(?:[\/.])/,/^(?:\s+)/,/^(?:\}\}\})/,/^(?:\}\})/,/^(?:"(\\["]|[^"])*")/,/^(?:'(\\[']|[^'])*')/,/^(?:@[a-zA-Z]+)/,/^(?:true(?=[}\s]))/,/^(?:false(?=[}\s]))/,/^(?:-?[0-9]+(?=[}\s]))/,/^(?:[a-zA-Z0-9_$:\-]+(?=[=}\s\/.]))/,/^(?:\[[^\]]*\])/,/^(?:.)/,/^(?:\s+)/,/^(?:[a-zA-Z0-9_$\-\/]+)/,/^(?:$)/];
648
+ lexer.conditions = {"mu":{"rules":[5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,33],"inclusive":false},"emu":{"rules":[3],"inclusive":false},"com":{"rules":[4],"inclusive":false},"par":{"rules":[31,32],"inclusive":false},"INITIAL":{"rules":[0,1,2,33],"inclusive":true}};
649
+ return lexer;})()
650
+ parser.lexer = lexer;
651
+ function Parser () { this.yy = {}; }Parser.prototype = parser;parser.Parser = Parser;
652
+ return new Parser;
653
+ })();;
654
+ // lib/handlebars/compiler/base.js
655
+
656
+ Handlebars.Parser = handlebars;
657
+
658
+ Handlebars.parse = function(input) {
659
+
660
+ // Just return if an already-compile AST was passed in.
661
+ if(input.constructor === Handlebars.AST.ProgramNode) { return input; }
662
+
663
+ Handlebars.Parser.yy = Handlebars.AST;
664
+ return Handlebars.Parser.parse(input);
665
+ };
666
+ ;
667
+ // lib/handlebars/compiler/ast.js
668
+ Handlebars.AST = {};
669
+
670
+ Handlebars.AST.ProgramNode = function(statements, inverse) {
671
+ this.type = "program";
672
+ this.statements = statements;
673
+ if(inverse) { this.inverse = new Handlebars.AST.ProgramNode(inverse); }
674
+ };
675
+
676
+ Handlebars.AST.MustacheNode = function(rawParams, hash, unescaped) {
677
+ this.type = "mustache";
678
+ this.escaped = !unescaped;
679
+ this.hash = hash;
680
+
681
+ var id = this.id = rawParams[0];
682
+ var params = this.params = rawParams.slice(1);
683
+
684
+ // a mustache is an eligible helper if:
685
+ // * its id is simple (a single part, not `this` or `..`)
686
+ var eligibleHelper = this.eligibleHelper = id.isSimple;
687
+
688
+ // a mustache is definitely a helper if:
689
+ // * it is an eligible helper, and
690
+ // * it has at least one parameter or hash segment
691
+ this.isHelper = eligibleHelper && (params.length || hash);
692
+
693
+ // if a mustache is an eligible helper but not a definite
694
+ // helper, it is ambiguous, and will be resolved in a later
695
+ // pass or at runtime.
696
+ };
697
+
698
+ Handlebars.AST.PartialNode = function(partialName, context) {
699
+ this.type = "partial";
700
+ this.partialName = partialName;
701
+ this.context = context;
702
+ };
703
+
704
+ Handlebars.AST.BlockNode = function(mustache, program, inverse, close) {
705
+ var verifyMatch = function(open, close) {
706
+ if(open.original !== close.original) {
707
+ throw new Handlebars.Exception(open.original + " doesn't match " + close.original);
708
+ }
709
+ };
710
+
711
+ verifyMatch(mustache.id, close);
712
+ this.type = "block";
713
+ this.mustache = mustache;
714
+ this.program = program;
715
+ this.inverse = inverse;
716
+
717
+ if (this.inverse && !this.program) {
718
+ this.isInverse = true;
719
+ }
720
+ };
721
+
722
+ Handlebars.AST.ContentNode = function(string) {
723
+ this.type = "content";
724
+ this.string = string;
725
+ };
726
+
727
+ Handlebars.AST.HashNode = function(pairs) {
728
+ this.type = "hash";
729
+ this.pairs = pairs;
730
+ };
731
+
732
+ Handlebars.AST.IdNode = function(parts) {
733
+ this.type = "ID";
734
+ this.original = parts.join(".");
735
+
736
+ var dig = [], depth = 0;
737
+
738
+ for(var i=0,l=parts.length; i<l; i++) {
739
+ var part = parts[i];
740
+
741
+ if (part === ".." || part === "." || part === "this") {
742
+ if (dig.length > 0) { throw new Handlebars.Exception("Invalid path: " + this.original); }
743
+ else if (part === "..") { depth++; }
744
+ else { this.isScoped = true; }
745
+ }
746
+ else { dig.push(part); }
747
+ }
748
+
749
+ this.parts = dig;
750
+ this.string = dig.join('.');
751
+ this.depth = depth;
752
+
753
+ // an ID is simple if it only has one part, and that part is not
754
+ // `..` or `this`.
755
+ this.isSimple = parts.length === 1 && !this.isScoped && depth === 0;
756
+
757
+ this.stringModeValue = this.string;
758
+ };
759
+
760
+ Handlebars.AST.PartialNameNode = function(name) {
761
+ this.type = "PARTIAL_NAME";
762
+ this.name = name;
763
+ };
764
+
765
+ Handlebars.AST.DataNode = function(id) {
766
+ this.type = "DATA";
767
+ this.id = id;
768
+ };
769
+
770
+ Handlebars.AST.StringNode = function(string) {
771
+ this.type = "STRING";
772
+ this.string = string;
773
+ this.stringModeValue = string;
774
+ };
775
+
776
+ Handlebars.AST.IntegerNode = function(integer) {
777
+ this.type = "INTEGER";
778
+ this.integer = integer;
779
+ this.stringModeValue = Number(integer);
780
+ };
781
+
782
+ Handlebars.AST.BooleanNode = function(bool) {
783
+ this.type = "BOOLEAN";
784
+ this.bool = bool;
785
+ this.stringModeValue = bool === "true";
786
+ };
787
+
788
+ Handlebars.AST.CommentNode = function(comment) {
789
+ this.type = "comment";
790
+ this.comment = comment;
791
+ };
792
+ ;
793
+ // lib/handlebars/utils.js
794
+
795
+ var errorProps = ['description', 'fileName', 'lineNumber', 'message', 'name', 'number', 'stack'];
796
+
797
+ Handlebars.Exception = function(message) {
798
+ var tmp = Error.prototype.constructor.apply(this, arguments);
799
+
800
+ // Unfortunately errors are not enumerable in Chrome (at least), so `for prop in tmp` doesn't work.
801
+ for (var idx = 0; idx < errorProps.length; idx++) {
802
+ this[errorProps[idx]] = tmp[errorProps[idx]];
803
+ }
804
+ };
805
+ Handlebars.Exception.prototype = new Error();
806
+
807
+ // Build out our basic SafeString type
808
+ Handlebars.SafeString = function(string) {
809
+ this.string = string;
810
+ };
811
+ Handlebars.SafeString.prototype.toString = function() {
812
+ return this.string.toString();
813
+ };
814
+
815
+ var escape = {
816
+ "&": "&amp;",
817
+ "<": "&lt;",
818
+ ">": "&gt;",
819
+ '"': "&quot;",
820
+ "'": "&#x27;",
821
+ "`": "&#x60;"
822
+ };
823
+
824
+ var badChars = /[&<>"'`]/g;
825
+ var possible = /[&<>"'`]/;
826
+
827
+ var escapeChar = function(chr) {
828
+ return escape[chr] || "&amp;";
829
+ };
830
+
831
+ Handlebars.Utils = {
832
+ extend: function(obj, value) {
833
+ for(var key in value) {
834
+ if(value.hasOwnProperty(key)) {
835
+ obj[key] = value[key];
836
+ }
837
+ }
838
+ },
839
+
840
+ escapeExpression: function(string) {
841
+ // don't escape SafeStrings, since they're already safe
842
+ if (string instanceof Handlebars.SafeString) {
843
+ return string.toString();
844
+ } else if (string == null || string === false) {
845
+ return "";
846
+ }
847
+
848
+ // Force a string conversion as this will be done by the append regardless and
849
+ // the regex test will do this transparently behind the scenes, causing issues if
850
+ // an object's to string has escaped characters in it.
851
+ string = string.toString();
852
+
853
+ if(!possible.test(string)) { return string; }
854
+ return string.replace(badChars, escapeChar);
855
+ },
856
+
857
+ isEmpty: function(value) {
858
+ if (!value && value !== 0) {
859
+ return true;
860
+ } else if(toString.call(value) === "[object Array]" && value.length === 0) {
861
+ return true;
862
+ } else {
863
+ return false;
864
+ }
865
+ }
866
+ };
867
+ ;
868
+ // lib/handlebars/compiler/compiler.js
869
+
870
+ /*jshint eqnull:true*/
871
+ var Compiler = Handlebars.Compiler = function() {};
872
+ var JavaScriptCompiler = Handlebars.JavaScriptCompiler = function() {};
873
+
874
+ // the foundHelper register will disambiguate helper lookup from finding a
875
+ // function in a context. This is necessary for mustache compatibility, which
876
+ // requires that context functions in blocks are evaluated by blockHelperMissing,
877
+ // and then proceed as if the resulting value was provided to blockHelperMissing.
878
+
879
+ Compiler.prototype = {
880
+ compiler: Compiler,
881
+
882
+ disassemble: function() {
883
+ var opcodes = this.opcodes, opcode, out = [], params, param;
884
+
885
+ for (var i=0, l=opcodes.length; i<l; i++) {
886
+ opcode = opcodes[i];
887
+
888
+ if (opcode.opcode === 'DECLARE') {
889
+ out.push("DECLARE " + opcode.name + "=" + opcode.value);
890
+ } else {
891
+ params = [];
892
+ for (var j=0; j<opcode.args.length; j++) {
893
+ param = opcode.args[j];
894
+ if (typeof param === "string") {
895
+ param = "\"" + param.replace("\n", "\\n") + "\"";
896
+ }
897
+ params.push(param);
898
+ }
899
+ out.push(opcode.opcode + " " + params.join(" "));
900
+ }
901
+ }
902
+
903
+ return out.join("\n");
904
+ },
905
+ equals: function(other) {
906
+ var len = this.opcodes.length;
907
+ if (other.opcodes.length !== len) {
908
+ return false;
909
+ }
910
+
911
+ for (var i = 0; i < len; i++) {
912
+ var opcode = this.opcodes[i],
913
+ otherOpcode = other.opcodes[i];
914
+ if (opcode.opcode !== otherOpcode.opcode || opcode.args.length !== otherOpcode.args.length) {
915
+ return false;
916
+ }
917
+ for (var j = 0; j < opcode.args.length; j++) {
918
+ if (opcode.args[j] !== otherOpcode.args[j]) {
919
+ return false;
920
+ }
921
+ }
922
+ }
923
+
924
+ len = this.children.length;
925
+ if (other.children.length !== len) {
926
+ return false;
927
+ }
928
+ for (i = 0; i < len; i++) {
929
+ if (!this.children[i].equals(other.children[i])) {
930
+ return false;
931
+ }
932
+ }
933
+
934
+ return true;
935
+ },
936
+
937
+ guid: 0,
938
+
939
+ compile: function(program, options) {
940
+ this.children = [];
941
+ this.depths = {list: []};
942
+ this.options = options;
943
+
944
+ // These changes will propagate to the other compiler components
945
+ var knownHelpers = this.options.knownHelpers;
946
+ this.options.knownHelpers = {
947
+ 'helperMissing': true,
948
+ 'blockHelperMissing': true,
949
+ 'each': true,
950
+ 'if': true,
951
+ 'unless': true,
952
+ 'with': true,
953
+ 'log': true
954
+ };
955
+ if (knownHelpers) {
956
+ for (var name in knownHelpers) {
957
+ this.options.knownHelpers[name] = knownHelpers[name];
958
+ }
959
+ }
960
+
961
+ return this.program(program);
962
+ },
963
+
964
+ accept: function(node) {
965
+ return this[node.type](node);
966
+ },
967
+
968
+ program: function(program) {
969
+ var statements = program.statements, statement;
970
+ this.opcodes = [];
971
+
972
+ for(var i=0, l=statements.length; i<l; i++) {
973
+ statement = statements[i];
974
+ this[statement.type](statement);
975
+ }
976
+ this.isSimple = l === 1;
977
+
978
+ this.depths.list = this.depths.list.sort(function(a, b) {
979
+ return a - b;
980
+ });
981
+
982
+ return this;
983
+ },
984
+
985
+ compileProgram: function(program) {
986
+ var result = new this.compiler().compile(program, this.options);
987
+ var guid = this.guid++, depth;
988
+
989
+ this.usePartial = this.usePartial || result.usePartial;
990
+
991
+ this.children[guid] = result;
992
+
993
+ for(var i=0, l=result.depths.list.length; i<l; i++) {
994
+ depth = result.depths.list[i];
995
+
996
+ if(depth < 2) { continue; }
997
+ else { this.addDepth(depth - 1); }
998
+ }
999
+
1000
+ return guid;
1001
+ },
1002
+
1003
+ block: function(block) {
1004
+ var mustache = block.mustache,
1005
+ program = block.program,
1006
+ inverse = block.inverse;
1007
+
1008
+ if (program) {
1009
+ program = this.compileProgram(program);
1010
+ }
1011
+
1012
+ if (inverse) {
1013
+ inverse = this.compileProgram(inverse);
1014
+ }
1015
+
1016
+ var type = this.classifyMustache(mustache);
1017
+
1018
+ if (type === "helper") {
1019
+ this.helperMustache(mustache, program, inverse);
1020
+ } else if (type === "simple") {
1021
+ this.simpleMustache(mustache);
1022
+
1023
+ // now that the simple mustache is resolved, we need to
1024
+ // evaluate it by executing `blockHelperMissing`
1025
+ this.opcode('pushProgram', program);
1026
+ this.opcode('pushProgram', inverse);
1027
+ this.opcode('emptyHash');
1028
+ this.opcode('blockValue');
1029
+ } else {
1030
+ this.ambiguousMustache(mustache, program, inverse);
1031
+
1032
+ // now that the simple mustache is resolved, we need to
1033
+ // evaluate it by executing `blockHelperMissing`
1034
+ this.opcode('pushProgram', program);
1035
+ this.opcode('pushProgram', inverse);
1036
+ this.opcode('emptyHash');
1037
+ this.opcode('ambiguousBlockValue');
1038
+ }
1039
+
1040
+ this.opcode('append');
1041
+ },
1042
+
1043
+ hash: function(hash) {
1044
+ var pairs = hash.pairs, pair, val;
1045
+
1046
+ this.opcode('pushHash');
1047
+
1048
+ for(var i=0, l=pairs.length; i<l; i++) {
1049
+ pair = pairs[i];
1050
+ val = pair[1];
1051
+
1052
+ if (this.options.stringParams) {
1053
+ if(val.depth) {
1054
+ this.addDepth(val.depth);
1055
+ }
1056
+ this.opcode('getContext', val.depth || 0);
1057
+ this.opcode('pushStringParam', val.stringModeValue, val.type);
1058
+ } else {
1059
+ this.accept(val);
1060
+ }
1061
+
1062
+ this.opcode('assignToHash', pair[0]);
1063
+ }
1064
+ this.opcode('popHash');
1065
+ },
1066
+
1067
+ partial: function(partial) {
1068
+ var partialName = partial.partialName;
1069
+ this.usePartial = true;
1070
+
1071
+ if(partial.context) {
1072
+ this.ID(partial.context);
1073
+ } else {
1074
+ this.opcode('push', 'depth0');
1075
+ }
1076
+
1077
+ this.opcode('invokePartial', partialName.name);
1078
+ this.opcode('append');
1079
+ },
1080
+
1081
+ content: function(content) {
1082
+ this.opcode('appendContent', content.string);
1083
+ },
1084
+
1085
+ mustache: function(mustache) {
1086
+ var options = this.options;
1087
+ var type = this.classifyMustache(mustache);
1088
+
1089
+ if (type === "simple") {
1090
+ this.simpleMustache(mustache);
1091
+ } else if (type === "helper") {
1092
+ this.helperMustache(mustache);
1093
+ } else {
1094
+ this.ambiguousMustache(mustache);
1095
+ }
1096
+
1097
+ if(mustache.escaped && !options.noEscape) {
1098
+ this.opcode('appendEscaped');
1099
+ } else {
1100
+ this.opcode('append');
1101
+ }
1102
+ },
1103
+
1104
+ ambiguousMustache: function(mustache, program, inverse) {
1105
+ var id = mustache.id,
1106
+ name = id.parts[0],
1107
+ isBlock = program != null || inverse != null;
1108
+
1109
+ this.opcode('getContext', id.depth);
1110
+
1111
+ this.opcode('pushProgram', program);
1112
+ this.opcode('pushProgram', inverse);
1113
+
1114
+ this.opcode('invokeAmbiguous', name, isBlock);
1115
+ },
1116
+
1117
+ simpleMustache: function(mustache) {
1118
+ var id = mustache.id;
1119
+
1120
+ if (id.type === 'DATA') {
1121
+ this.DATA(id);
1122
+ } else if (id.parts.length) {
1123
+ this.ID(id);
1124
+ } else {
1125
+ // Simplified ID for `this`
1126
+ this.addDepth(id.depth);
1127
+ this.opcode('getContext', id.depth);
1128
+ this.opcode('pushContext');
1129
+ }
1130
+
1131
+ this.opcode('resolvePossibleLambda');
1132
+ },
1133
+
1134
+ helperMustache: function(mustache, program, inverse) {
1135
+ var params = this.setupFullMustacheParams(mustache, program, inverse),
1136
+ name = mustache.id.parts[0];
1137
+
1138
+ if (this.options.knownHelpers[name]) {
1139
+ this.opcode('invokeKnownHelper', params.length, name);
1140
+ } else if (this.options.knownHelpersOnly) {
1141
+ throw new Error("You specified knownHelpersOnly, but used the unknown helper " + name);
1142
+ } else {
1143
+ this.opcode('invokeHelper', params.length, name);
1144
+ }
1145
+ },
1146
+
1147
+ ID: function(id) {
1148
+ this.addDepth(id.depth);
1149
+ this.opcode('getContext', id.depth);
1150
+
1151
+ var name = id.parts[0];
1152
+ if (!name) {
1153
+ this.opcode('pushContext');
1154
+ } else {
1155
+ this.opcode('lookupOnContext', id.parts[0]);
1156
+ }
1157
+
1158
+ for(var i=1, l=id.parts.length; i<l; i++) {
1159
+ this.opcode('lookup', id.parts[i]);
1160
+ }
1161
+ },
1162
+
1163
+ DATA: function(data) {
1164
+ this.options.data = true;
1165
+ this.opcode('lookupData', data.id);
1166
+ },
1167
+
1168
+ STRING: function(string) {
1169
+ this.opcode('pushString', string.string);
1170
+ },
1171
+
1172
+ INTEGER: function(integer) {
1173
+ this.opcode('pushLiteral', integer.integer);
1174
+ },
1175
+
1176
+ BOOLEAN: function(bool) {
1177
+ this.opcode('pushLiteral', bool.bool);
1178
+ },
1179
+
1180
+ comment: function() {},
1181
+
1182
+ // HELPERS
1183
+ opcode: function(name) {
1184
+ this.opcodes.push({ opcode: name, args: [].slice.call(arguments, 1) });
1185
+ },
1186
+
1187
+ declare: function(name, value) {
1188
+ this.opcodes.push({ opcode: 'DECLARE', name: name, value: value });
1189
+ },
1190
+
1191
+ addDepth: function(depth) {
1192
+ if(isNaN(depth)) { throw new Error("EWOT"); }
1193
+ if(depth === 0) { return; }
1194
+
1195
+ if(!this.depths[depth]) {
1196
+ this.depths[depth] = true;
1197
+ this.depths.list.push(depth);
1198
+ }
1199
+ },
1200
+
1201
+ classifyMustache: function(mustache) {
1202
+ var isHelper = mustache.isHelper;
1203
+ var isEligible = mustache.eligibleHelper;
1204
+ var options = this.options;
1205
+
1206
+ // if ambiguous, we can possibly resolve the ambiguity now
1207
+ if (isEligible && !isHelper) {
1208
+ var name = mustache.id.parts[0];
1209
+
1210
+ if (options.knownHelpers[name]) {
1211
+ isHelper = true;
1212
+ } else if (options.knownHelpersOnly) {
1213
+ isEligible = false;
1214
+ }
1215
+ }
1216
+
1217
+ if (isHelper) { return "helper"; }
1218
+ else if (isEligible) { return "ambiguous"; }
1219
+ else { return "simple"; }
1220
+ },
1221
+
1222
+ pushParams: function(params) {
1223
+ var i = params.length, param;
1224
+
1225
+ while(i--) {
1226
+ param = params[i];
1227
+
1228
+ if(this.options.stringParams) {
1229
+ if(param.depth) {
1230
+ this.addDepth(param.depth);
1231
+ }
1232
+
1233
+ this.opcode('getContext', param.depth || 0);
1234
+ this.opcode('pushStringParam', param.stringModeValue, param.type);
1235
+ } else {
1236
+ this[param.type](param);
1237
+ }
1238
+ }
1239
+ },
1240
+
1241
+ setupMustacheParams: function(mustache) {
1242
+ var params = mustache.params;
1243
+ this.pushParams(params);
1244
+
1245
+ if(mustache.hash) {
1246
+ this.hash(mustache.hash);
1247
+ } else {
1248
+ this.opcode('emptyHash');
1249
+ }
1250
+
1251
+ return params;
1252
+ },
1253
+
1254
+ // this will replace setupMustacheParams when we're done
1255
+ setupFullMustacheParams: function(mustache, program, inverse) {
1256
+ var params = mustache.params;
1257
+ this.pushParams(params);
1258
+
1259
+ this.opcode('pushProgram', program);
1260
+ this.opcode('pushProgram', inverse);
1261
+
1262
+ if(mustache.hash) {
1263
+ this.hash(mustache.hash);
1264
+ } else {
1265
+ this.opcode('emptyHash');
1266
+ }
1267
+
1268
+ return params;
1269
+ }
1270
+ };
1271
+
1272
+ var Literal = function(value) {
1273
+ this.value = value;
1274
+ };
1275
+
1276
+ JavaScriptCompiler.prototype = {
1277
+ // PUBLIC API: You can override these methods in a subclass to provide
1278
+ // alternative compiled forms for name lookup and buffering semantics
1279
+ nameLookup: function(parent, name /* , type*/) {
1280
+ if (/^[0-9]+$/.test(name)) {
1281
+ return parent + "[" + name + "]";
1282
+ } else if (JavaScriptCompiler.isValidJavaScriptVariableName(name)) {
1283
+ return parent + "." + name;
1284
+ }
1285
+ else {
1286
+ return parent + "['" + name + "']";
1287
+ }
1288
+ },
1289
+
1290
+ appendToBuffer: function(string) {
1291
+ if (this.environment.isSimple) {
1292
+ return "return " + string + ";";
1293
+ } else {
1294
+ return {
1295
+ appendToBuffer: true,
1296
+ content: string,
1297
+ toString: function() { return "buffer += " + string + ";"; }
1298
+ };
1299
+ }
1300
+ },
1301
+
1302
+ initializeBuffer: function() {
1303
+ return this.quotedString("");
1304
+ },
1305
+
1306
+ namespace: "Handlebars",
1307
+ // END PUBLIC API
1308
+
1309
+ compile: function(environment, options, context, asObject) {
1310
+ this.environment = environment;
1311
+ this.options = options || {};
1312
+
1313
+ Handlebars.log(Handlebars.logger.DEBUG, this.environment.disassemble() + "\n\n");
1314
+
1315
+ this.name = this.environment.name;
1316
+ this.isChild = !!context;
1317
+ this.context = context || {
1318
+ programs: [],
1319
+ environments: [],
1320
+ aliases: { }
1321
+ };
1322
+
1323
+ this.preamble();
1324
+
1325
+ this.stackSlot = 0;
1326
+ this.stackVars = [];
1327
+ this.registers = { list: [] };
1328
+ this.compileStack = [];
1329
+ this.inlineStack = [];
1330
+
1331
+ this.compileChildren(environment, options);
1332
+
1333
+ var opcodes = environment.opcodes, opcode;
1334
+
1335
+ this.i = 0;
1336
+
1337
+ for(l=opcodes.length; this.i<l; this.i++) {
1338
+ opcode = opcodes[this.i];
1339
+
1340
+ if(opcode.opcode === 'DECLARE') {
1341
+ this[opcode.name] = opcode.value;
1342
+ } else {
1343
+ this[opcode.opcode].apply(this, opcode.args);
1344
+ }
1345
+ }
1346
+
1347
+ return this.createFunctionContext(asObject);
1348
+ },
1349
+
1350
+ nextOpcode: function() {
1351
+ var opcodes = this.environment.opcodes;
1352
+ return opcodes[this.i + 1];
1353
+ },
1354
+
1355
+ eat: function() {
1356
+ this.i = this.i + 1;
1357
+ },
1358
+
1359
+ preamble: function() {
1360
+ var out = [];
1361
+
1362
+ if (!this.isChild) {
1363
+ var namespace = this.namespace;
1364
+ var copies = "helpers = helpers || " + namespace + ".helpers;";
1365
+ if (this.environment.usePartial) { copies = copies + " partials = partials || " + namespace + ".partials;"; }
1366
+ if (this.options.data) { copies = copies + " data = data || {};"; }
1367
+ out.push(copies);
1368
+ } else {
1369
+ out.push('');
1370
+ }
1371
+
1372
+ if (!this.environment.isSimple) {
1373
+ out.push(", buffer = " + this.initializeBuffer());
1374
+ } else {
1375
+ out.push("");
1376
+ }
1377
+
1378
+ // track the last context pushed into place to allow skipping the
1379
+ // getContext opcode when it would be a noop
1380
+ this.lastContext = 0;
1381
+ this.source = out;
1382
+ },
1383
+
1384
+ createFunctionContext: function(asObject) {
1385
+ var locals = this.stackVars.concat(this.registers.list);
1386
+
1387
+ if(locals.length > 0) {
1388
+ this.source[1] = this.source[1] + ", " + locals.join(", ");
1389
+ }
1390
+
1391
+ // Generate minimizer alias mappings
1392
+ if (!this.isChild) {
1393
+ for (var alias in this.context.aliases) {
1394
+ this.source[1] = this.source[1] + ', ' + alias + '=' + this.context.aliases[alias];
1395
+ }
1396
+ }
1397
+
1398
+ if (this.source[1]) {
1399
+ this.source[1] = "var " + this.source[1].substring(2) + ";";
1400
+ }
1401
+
1402
+ // Merge children
1403
+ if (!this.isChild) {
1404
+ this.source[1] += '\n' + this.context.programs.join('\n') + '\n';
1405
+ }
1406
+
1407
+ if (!this.environment.isSimple) {
1408
+ this.source.push("return buffer;");
1409
+ }
1410
+
1411
+ var params = this.isChild ? ["depth0", "data"] : ["Handlebars", "depth0", "helpers", "partials", "data"];
1412
+
1413
+ for(var i=0, l=this.environment.depths.list.length; i<l; i++) {
1414
+ params.push("depth" + this.environment.depths.list[i]);
1415
+ }
1416
+
1417
+ // Perform a second pass over the output to merge content when possible
1418
+ var source = this.mergeSource();
1419
+
1420
+ if (!this.isChild) {
1421
+ var revision = Handlebars.COMPILER_REVISION,
1422
+ versions = Handlebars.REVISION_CHANGES[revision];
1423
+ source = "this.compilerInfo = ["+revision+",'"+versions+"'];\n"+source;
1424
+ }
1425
+
1426
+ if (asObject) {
1427
+ params.push(source);
1428
+
1429
+ return Function.apply(this, params);
1430
+ } else {
1431
+ var functionSource = 'function ' + (this.name || '') + '(' + params.join(',') + ') {\n ' + source + '}';
1432
+ Handlebars.log(Handlebars.logger.DEBUG, functionSource + "\n\n");
1433
+ return functionSource;
1434
+ }
1435
+ },
1436
+ mergeSource: function() {
1437
+ // WARN: We are not handling the case where buffer is still populated as the source should
1438
+ // not have buffer append operations as their final action.
1439
+ var source = '',
1440
+ buffer;
1441
+ for (var i = 0, len = this.source.length; i < len; i++) {
1442
+ var line = this.source[i];
1443
+ if (line.appendToBuffer) {
1444
+ if (buffer) {
1445
+ buffer = buffer + '\n + ' + line.content;
1446
+ } else {
1447
+ buffer = line.content;
1448
+ }
1449
+ } else {
1450
+ if (buffer) {
1451
+ source += 'buffer += ' + buffer + ';\n ';
1452
+ buffer = undefined;
1453
+ }
1454
+ source += line + '\n ';
1455
+ }
1456
+ }
1457
+ return source;
1458
+ },
1459
+
1460
+ // [blockValue]
1461
+ //
1462
+ // On stack, before: hash, inverse, program, value
1463
+ // On stack, after: return value of blockHelperMissing
1464
+ //
1465
+ // The purpose of this opcode is to take a block of the form
1466
+ // `{{#foo}}...{{/foo}}`, resolve the value of `foo`, and
1467
+ // replace it on the stack with the result of properly
1468
+ // invoking blockHelperMissing.
1469
+ blockValue: function() {
1470
+ this.context.aliases.blockHelperMissing = 'helpers.blockHelperMissing';
1471
+
1472
+ var params = ["depth0"];
1473
+ this.setupParams(0, params);
1474
+
1475
+ this.replaceStack(function(current) {
1476
+ params.splice(1, 0, current);
1477
+ return "blockHelperMissing.call(" + params.join(", ") + ")";
1478
+ });
1479
+ },
1480
+
1481
+ // [ambiguousBlockValue]
1482
+ //
1483
+ // On stack, before: hash, inverse, program, value
1484
+ // Compiler value, before: lastHelper=value of last found helper, if any
1485
+ // On stack, after, if no lastHelper: same as [blockValue]
1486
+ // On stack, after, if lastHelper: value
1487
+ ambiguousBlockValue: function() {
1488
+ this.context.aliases.blockHelperMissing = 'helpers.blockHelperMissing';
1489
+
1490
+ var params = ["depth0"];
1491
+ this.setupParams(0, params);
1492
+
1493
+ var current = this.topStack();
1494
+ params.splice(1, 0, current);
1495
+
1496
+ // Use the options value generated from the invocation
1497
+ params[params.length-1] = 'options';
1498
+
1499
+ this.source.push("if (!" + this.lastHelper + ") { " + current + " = blockHelperMissing.call(" + params.join(", ") + "); }");
1500
+ },
1501
+
1502
+ // [appendContent]
1503
+ //
1504
+ // On stack, before: ...
1505
+ // On stack, after: ...
1506
+ //
1507
+ // Appends the string value of `content` to the current buffer
1508
+ appendContent: function(content) {
1509
+ this.source.push(this.appendToBuffer(this.quotedString(content)));
1510
+ },
1511
+
1512
+ // [append]
1513
+ //
1514
+ // On stack, before: value, ...
1515
+ // On stack, after: ...
1516
+ //
1517
+ // Coerces `value` to a String and appends it to the current buffer.
1518
+ //
1519
+ // If `value` is truthy, or 0, it is coerced into a string and appended
1520
+ // Otherwise, the empty string is appended
1521
+ append: function() {
1522
+ // Force anything that is inlined onto the stack so we don't have duplication
1523
+ // when we examine local
1524
+ this.flushInline();
1525
+ var local = this.popStack();
1526
+ this.source.push("if(" + local + " || " + local + " === 0) { " + this.appendToBuffer(local) + " }");
1527
+ if (this.environment.isSimple) {
1528
+ this.source.push("else { " + this.appendToBuffer("''") + " }");
1529
+ }
1530
+ },
1531
+
1532
+ // [appendEscaped]
1533
+ //
1534
+ // On stack, before: value, ...
1535
+ // On stack, after: ...
1536
+ //
1537
+ // Escape `value` and append it to the buffer
1538
+ appendEscaped: function() {
1539
+ this.context.aliases.escapeExpression = 'this.escapeExpression';
1540
+
1541
+ this.source.push(this.appendToBuffer("escapeExpression(" + this.popStack() + ")"));
1542
+ },
1543
+
1544
+ // [getContext]
1545
+ //
1546
+ // On stack, before: ...
1547
+ // On stack, after: ...
1548
+ // Compiler value, after: lastContext=depth
1549
+ //
1550
+ // Set the value of the `lastContext` compiler value to the depth
1551
+ getContext: function(depth) {
1552
+ if(this.lastContext !== depth) {
1553
+ this.lastContext = depth;
1554
+ }
1555
+ },
1556
+
1557
+ // [lookupOnContext]
1558
+ //
1559
+ // On stack, before: ...
1560
+ // On stack, after: currentContext[name], ...
1561
+ //
1562
+ // Looks up the value of `name` on the current context and pushes
1563
+ // it onto the stack.
1564
+ lookupOnContext: function(name) {
1565
+ this.push(this.nameLookup('depth' + this.lastContext, name, 'context'));
1566
+ },
1567
+
1568
+ // [pushContext]
1569
+ //
1570
+ // On stack, before: ...
1571
+ // On stack, after: currentContext, ...
1572
+ //
1573
+ // Pushes the value of the current context onto the stack.
1574
+ pushContext: function() {
1575
+ this.pushStackLiteral('depth' + this.lastContext);
1576
+ },
1577
+
1578
+ // [resolvePossibleLambda]
1579
+ //
1580
+ // On stack, before: value, ...
1581
+ // On stack, after: resolved value, ...
1582
+ //
1583
+ // If the `value` is a lambda, replace it on the stack by
1584
+ // the return value of the lambda
1585
+ resolvePossibleLambda: function() {
1586
+ this.context.aliases.functionType = '"function"';
1587
+
1588
+ this.replaceStack(function(current) {
1589
+ return "typeof " + current + " === functionType ? " + current + ".apply(depth0) : " + current;
1590
+ });
1591
+ },
1592
+
1593
+ // [lookup]
1594
+ //
1595
+ // On stack, before: value, ...
1596
+ // On stack, after: value[name], ...
1597
+ //
1598
+ // Replace the value on the stack with the result of looking
1599
+ // up `name` on `value`
1600
+ lookup: function(name) {
1601
+ this.replaceStack(function(current) {
1602
+ return current + " == null || " + current + " === false ? " + current + " : " + this.nameLookup(current, name, 'context');
1603
+ });
1604
+ },
1605
+
1606
+ // [lookupData]
1607
+ //
1608
+ // On stack, before: ...
1609
+ // On stack, after: data[id], ...
1610
+ //
1611
+ // Push the result of looking up `id` on the current data
1612
+ lookupData: function(id) {
1613
+ this.push(this.nameLookup('data', id, 'data'));
1614
+ },
1615
+
1616
+ // [pushStringParam]
1617
+ //
1618
+ // On stack, before: ...
1619
+ // On stack, after: string, currentContext, ...
1620
+ //
1621
+ // This opcode is designed for use in string mode, which
1622
+ // provides the string value of a parameter along with its
1623
+ // depth rather than resolving it immediately.
1624
+ pushStringParam: function(string, type) {
1625
+ this.pushStackLiteral('depth' + this.lastContext);
1626
+
1627
+ this.pushString(type);
1628
+
1629
+ if (typeof string === 'string') {
1630
+ this.pushString(string);
1631
+ } else {
1632
+ this.pushStackLiteral(string);
1633
+ }
1634
+ },
1635
+
1636
+ emptyHash: function() {
1637
+ this.pushStackLiteral('{}');
1638
+
1639
+ if (this.options.stringParams) {
1640
+ this.register('hashTypes', '{}');
1641
+ this.register('hashContexts', '{}');
1642
+ }
1643
+ },
1644
+ pushHash: function() {
1645
+ this.hash = {values: [], types: [], contexts: []};
1646
+ },
1647
+ popHash: function() {
1648
+ var hash = this.hash;
1649
+ this.hash = undefined;
1650
+
1651
+ if (this.options.stringParams) {
1652
+ this.register('hashContexts', '{' + hash.contexts.join(',') + '}');
1653
+ this.register('hashTypes', '{' + hash.types.join(',') + '}');
1654
+ }
1655
+ this.push('{\n ' + hash.values.join(',\n ') + '\n }');
1656
+ },
1657
+
1658
+ // [pushString]
1659
+ //
1660
+ // On stack, before: ...
1661
+ // On stack, after: quotedString(string), ...
1662
+ //
1663
+ // Push a quoted version of `string` onto the stack
1664
+ pushString: function(string) {
1665
+ this.pushStackLiteral(this.quotedString(string));
1666
+ },
1667
+
1668
+ // [push]
1669
+ //
1670
+ // On stack, before: ...
1671
+ // On stack, after: expr, ...
1672
+ //
1673
+ // Push an expression onto the stack
1674
+ push: function(expr) {
1675
+ this.inlineStack.push(expr);
1676
+ return expr;
1677
+ },
1678
+
1679
+ // [pushLiteral]
1680
+ //
1681
+ // On stack, before: ...
1682
+ // On stack, after: value, ...
1683
+ //
1684
+ // Pushes a value onto the stack. This operation prevents
1685
+ // the compiler from creating a temporary variable to hold
1686
+ // it.
1687
+ pushLiteral: function(value) {
1688
+ this.pushStackLiteral(value);
1689
+ },
1690
+
1691
+ // [pushProgram]
1692
+ //
1693
+ // On stack, before: ...
1694
+ // On stack, after: program(guid), ...
1695
+ //
1696
+ // Push a program expression onto the stack. This takes
1697
+ // a compile-time guid and converts it into a runtime-accessible
1698
+ // expression.
1699
+ pushProgram: function(guid) {
1700
+ if (guid != null) {
1701
+ this.pushStackLiteral(this.programExpression(guid));
1702
+ } else {
1703
+ this.pushStackLiteral(null);
1704
+ }
1705
+ },
1706
+
1707
+ // [invokeHelper]
1708
+ //
1709
+ // On stack, before: hash, inverse, program, params..., ...
1710
+ // On stack, after: result of helper invocation
1711
+ //
1712
+ // Pops off the helper's parameters, invokes the helper,
1713
+ // and pushes the helper's return value onto the stack.
1714
+ //
1715
+ // If the helper is not found, `helperMissing` is called.
1716
+ invokeHelper: function(paramSize, name) {
1717
+ this.context.aliases.helperMissing = 'helpers.helperMissing';
1718
+
1719
+ var helper = this.lastHelper = this.setupHelper(paramSize, name, true);
1720
+
1721
+ this.push(helper.name);
1722
+ this.replaceStack(function(name) {
1723
+ return name + ' ? ' + name + '.call(' +
1724
+ helper.callParams + ") " + ": helperMissing.call(" +
1725
+ helper.helperMissingParams + ")";
1726
+ });
1727
+ },
1728
+
1729
+ // [invokeKnownHelper]
1730
+ //
1731
+ // On stack, before: hash, inverse, program, params..., ...
1732
+ // On stack, after: result of helper invocation
1733
+ //
1734
+ // This operation is used when the helper is known to exist,
1735
+ // so a `helperMissing` fallback is not required.
1736
+ invokeKnownHelper: function(paramSize, name) {
1737
+ var helper = this.setupHelper(paramSize, name);
1738
+ this.push(helper.name + ".call(" + helper.callParams + ")");
1739
+ },
1740
+
1741
+ // [invokeAmbiguous]
1742
+ //
1743
+ // On stack, before: hash, inverse, program, params..., ...
1744
+ // On stack, after: result of disambiguation
1745
+ //
1746
+ // This operation is used when an expression like `{{foo}}`
1747
+ // is provided, but we don't know at compile-time whether it
1748
+ // is a helper or a path.
1749
+ //
1750
+ // This operation emits more code than the other options,
1751
+ // and can be avoided by passing the `knownHelpers` and
1752
+ // `knownHelpersOnly` flags at compile-time.
1753
+ invokeAmbiguous: function(name, helperCall) {
1754
+ this.context.aliases.functionType = '"function"';
1755
+
1756
+ this.pushStackLiteral('{}'); // Hash value
1757
+ var helper = this.setupHelper(0, name, helperCall);
1758
+
1759
+ var helperName = this.lastHelper = this.nameLookup('helpers', name, 'helper');
1760
+
1761
+ var nonHelper = this.nameLookup('depth' + this.lastContext, name, 'context');
1762
+ var nextStack = this.nextStack();
1763
+
1764
+ this.source.push('if (' + nextStack + ' = ' + helperName + ') { ' + nextStack + ' = ' + nextStack + '.call(' + helper.callParams + '); }');
1765
+ this.source.push('else { ' + nextStack + ' = ' + nonHelper + '; ' + nextStack + ' = typeof ' + nextStack + ' === functionType ? ' + nextStack + '.apply(depth0) : ' + nextStack + '; }');
1766
+ },
1767
+
1768
+ // [invokePartial]
1769
+ //
1770
+ // On stack, before: context, ...
1771
+ // On stack after: result of partial invocation
1772
+ //
1773
+ // This operation pops off a context, invokes a partial with that context,
1774
+ // and pushes the result of the invocation back.
1775
+ invokePartial: function(name) {
1776
+ var params = [this.nameLookup('partials', name, 'partial'), "'" + name + "'", this.popStack(), "helpers", "partials"];
1777
+
1778
+ if (this.options.data) {
1779
+ params.push("data");
1780
+ }
1781
+
1782
+ this.context.aliases.self = "this";
1783
+ this.push("self.invokePartial(" + params.join(", ") + ")");
1784
+ },
1785
+
1786
+ // [assignToHash]
1787
+ //
1788
+ // On stack, before: value, hash, ...
1789
+ // On stack, after: hash, ...
1790
+ //
1791
+ // Pops a value and hash off the stack, assigns `hash[key] = value`
1792
+ // and pushes the hash back onto the stack.
1793
+ assignToHash: function(key) {
1794
+ var value = this.popStack(),
1795
+ context,
1796
+ type;
1797
+
1798
+ if (this.options.stringParams) {
1799
+ type = this.popStack();
1800
+ context = this.popStack();
1801
+ }
1802
+
1803
+ var hash = this.hash;
1804
+ if (context) {
1805
+ hash.contexts.push("'" + key + "': " + context);
1806
+ }
1807
+ if (type) {
1808
+ hash.types.push("'" + key + "': " + type);
1809
+ }
1810
+ hash.values.push("'" + key + "': (" + value + ")");
1811
+ },
1812
+
1813
+ // HELPERS
1814
+
1815
+ compiler: JavaScriptCompiler,
1816
+
1817
+ compileChildren: function(environment, options) {
1818
+ var children = environment.children, child, compiler;
1819
+
1820
+ for(var i=0, l=children.length; i<l; i++) {
1821
+ child = children[i];
1822
+ compiler = new this.compiler();
1823
+
1824
+ var index = this.matchExistingProgram(child);
1825
+
1826
+ if (index == null) {
1827
+ this.context.programs.push(''); // Placeholder to prevent name conflicts for nested children
1828
+ index = this.context.programs.length;
1829
+ child.index = index;
1830
+ child.name = 'program' + index;
1831
+ this.context.programs[index] = compiler.compile(child, options, this.context);
1832
+ this.context.environments[index] = child;
1833
+ } else {
1834
+ child.index = index;
1835
+ child.name = 'program' + index;
1836
+ }
1837
+ }
1838
+ },
1839
+ matchExistingProgram: function(child) {
1840
+ for (var i = 0, len = this.context.environments.length; i < len; i++) {
1841
+ var environment = this.context.environments[i];
1842
+ if (environment && environment.equals(child)) {
1843
+ return i;
1844
+ }
1845
+ }
1846
+ },
1847
+
1848
+ programExpression: function(guid) {
1849
+ this.context.aliases.self = "this";
1850
+
1851
+ if(guid == null) {
1852
+ return "self.noop";
1853
+ }
1854
+
1855
+ var child = this.environment.children[guid],
1856
+ depths = child.depths.list, depth;
1857
+
1858
+ var programParams = [child.index, child.name, "data"];
1859
+
1860
+ for(var i=0, l = depths.length; i<l; i++) {
1861
+ depth = depths[i];
1862
+
1863
+ if(depth === 1) { programParams.push("depth0"); }
1864
+ else { programParams.push("depth" + (depth - 1)); }
1865
+ }
1866
+
1867
+ return (depths.length === 0 ? "self.program(" : "self.programWithDepth(") + programParams.join(", ") + ")";
1868
+ },
1869
+
1870
+ register: function(name, val) {
1871
+ this.useRegister(name);
1872
+ this.source.push(name + " = " + val + ";");
1873
+ },
1874
+
1875
+ useRegister: function(name) {
1876
+ if(!this.registers[name]) {
1877
+ this.registers[name] = true;
1878
+ this.registers.list.push(name);
1879
+ }
1880
+ },
1881
+
1882
+ pushStackLiteral: function(item) {
1883
+ return this.push(new Literal(item));
1884
+ },
1885
+
1886
+ pushStack: function(item) {
1887
+ this.flushInline();
1888
+
1889
+ var stack = this.incrStack();
1890
+ if (item) {
1891
+ this.source.push(stack + " = " + item + ";");
1892
+ }
1893
+ this.compileStack.push(stack);
1894
+ return stack;
1895
+ },
1896
+
1897
+ replaceStack: function(callback) {
1898
+ var prefix = '',
1899
+ inline = this.isInline(),
1900
+ stack;
1901
+
1902
+ // If we are currently inline then we want to merge the inline statement into the
1903
+ // replacement statement via ','
1904
+ if (inline) {
1905
+ var top = this.popStack(true);
1906
+
1907
+ if (top instanceof Literal) {
1908
+ // Literals do not need to be inlined
1909
+ stack = top.value;
1910
+ } else {
1911
+ // Get or create the current stack name for use by the inline
1912
+ var name = this.stackSlot ? this.topStackName() : this.incrStack();
1913
+
1914
+ prefix = '(' + this.push(name) + ' = ' + top + '),';
1915
+ stack = this.topStack();
1916
+ }
1917
+ } else {
1918
+ stack = this.topStack();
1919
+ }
1920
+
1921
+ var item = callback.call(this, stack);
1922
+
1923
+ if (inline) {
1924
+ if (this.inlineStack.length || this.compileStack.length) {
1925
+ this.popStack();
1926
+ }
1927
+ this.push('(' + prefix + item + ')');
1928
+ } else {
1929
+ // Prevent modification of the context depth variable. Through replaceStack
1930
+ if (!/^stack/.test(stack)) {
1931
+ stack = this.nextStack();
1932
+ }
1933
+
1934
+ this.source.push(stack + " = (" + prefix + item + ");");
1935
+ }
1936
+ return stack;
1937
+ },
1938
+
1939
+ nextStack: function() {
1940
+ return this.pushStack();
1941
+ },
1942
+
1943
+ incrStack: function() {
1944
+ this.stackSlot++;
1945
+ if(this.stackSlot > this.stackVars.length) { this.stackVars.push("stack" + this.stackSlot); }
1946
+ return this.topStackName();
1947
+ },
1948
+ topStackName: function() {
1949
+ return "stack" + this.stackSlot;
1950
+ },
1951
+ flushInline: function() {
1952
+ var inlineStack = this.inlineStack;
1953
+ if (inlineStack.length) {
1954
+ this.inlineStack = [];
1955
+ for (var i = 0, len = inlineStack.length; i < len; i++) {
1956
+ var entry = inlineStack[i];
1957
+ if (entry instanceof Literal) {
1958
+ this.compileStack.push(entry);
1959
+ } else {
1960
+ this.pushStack(entry);
1961
+ }
1962
+ }
1963
+ }
1964
+ },
1965
+ isInline: function() {
1966
+ return this.inlineStack.length;
1967
+ },
1968
+
1969
+ popStack: function(wrapped) {
1970
+ var inline = this.isInline(),
1971
+ item = (inline ? this.inlineStack : this.compileStack).pop();
1972
+
1973
+ if (!wrapped && (item instanceof Literal)) {
1974
+ return item.value;
1975
+ } else {
1976
+ if (!inline) {
1977
+ this.stackSlot--;
1978
+ }
1979
+ return item;
1980
+ }
1981
+ },
1982
+
1983
+ topStack: function(wrapped) {
1984
+ var stack = (this.isInline() ? this.inlineStack : this.compileStack),
1985
+ item = stack[stack.length - 1];
1986
+
1987
+ if (!wrapped && (item instanceof Literal)) {
1988
+ return item.value;
1989
+ } else {
1990
+ return item;
1991
+ }
1992
+ },
1993
+
1994
+ quotedString: function(str) {
1995
+ return '"' + str
1996
+ .replace(/\\/g, '\\\\')
1997
+ .replace(/"/g, '\\"')
1998
+ .replace(/\n/g, '\\n')
1999
+ .replace(/\r/g, '\\r')
2000
+ .replace(/\u2028/g, '\\u2028') // Per Ecma-262 7.3 + 7.8.4
2001
+ .replace(/\u2029/g, '\\u2029') + '"';
2002
+ },
2003
+
2004
+ setupHelper: function(paramSize, name, missingParams) {
2005
+ var params = [];
2006
+ this.setupParams(paramSize, params, missingParams);
2007
+ var foundHelper = this.nameLookup('helpers', name, 'helper');
2008
+
2009
+ return {
2010
+ params: params,
2011
+ name: foundHelper,
2012
+ callParams: ["depth0"].concat(params).join(", "),
2013
+ helperMissingParams: missingParams && ["depth0", this.quotedString(name)].concat(params).join(", ")
2014
+ };
2015
+ },
2016
+
2017
+ // the params and contexts arguments are passed in arrays
2018
+ // to fill in
2019
+ setupParams: function(paramSize, params, useRegister) {
2020
+ var options = [], contexts = [], types = [], param, inverse, program;
2021
+
2022
+ options.push("hash:" + this.popStack());
2023
+
2024
+ inverse = this.popStack();
2025
+ program = this.popStack();
2026
+
2027
+ // Avoid setting fn and inverse if neither are set. This allows
2028
+ // helpers to do a check for `if (options.fn)`
2029
+ if (program || inverse) {
2030
+ if (!program) {
2031
+ this.context.aliases.self = "this";
2032
+ program = "self.noop";
2033
+ }
2034
+
2035
+ if (!inverse) {
2036
+ this.context.aliases.self = "this";
2037
+ inverse = "self.noop";
2038
+ }
2039
+
2040
+ options.push("inverse:" + inverse);
2041
+ options.push("fn:" + program);
2042
+ }
2043
+
2044
+ for(var i=0; i<paramSize; i++) {
2045
+ param = this.popStack();
2046
+ params.push(param);
2047
+
2048
+ if(this.options.stringParams) {
2049
+ types.push(this.popStack());
2050
+ contexts.push(this.popStack());
2051
+ }
2052
+ }
2053
+
2054
+ if (this.options.stringParams) {
2055
+ options.push("contexts:[" + contexts.join(",") + "]");
2056
+ options.push("types:[" + types.join(",") + "]");
2057
+ options.push("hashContexts:hashContexts");
2058
+ options.push("hashTypes:hashTypes");
2059
+ }
2060
+
2061
+ if(this.options.data) {
2062
+ options.push("data:data");
2063
+ }
2064
+
2065
+ options = "{" + options.join(",") + "}";
2066
+ if (useRegister) {
2067
+ this.register('options', options);
2068
+ params.push('options');
2069
+ } else {
2070
+ params.push(options);
2071
+ }
2072
+ return params.join(", ");
2073
+ }
2074
+ };
2075
+
2076
+ var reservedWords = (
2077
+ "break else new var" +
2078
+ " case finally return void" +
2079
+ " catch for switch while" +
2080
+ " continue function this with" +
2081
+ " default if throw" +
2082
+ " delete in try" +
2083
+ " do instanceof typeof" +
2084
+ " abstract enum int short" +
2085
+ " boolean export interface static" +
2086
+ " byte extends long super" +
2087
+ " char final native synchronized" +
2088
+ " class float package throws" +
2089
+ " const goto private transient" +
2090
+ " debugger implements protected volatile" +
2091
+ " double import public let yield"
2092
+ ).split(" ");
2093
+
2094
+ var compilerWords = JavaScriptCompiler.RESERVED_WORDS = {};
2095
+
2096
+ for(var i=0, l=reservedWords.length; i<l; i++) {
2097
+ compilerWords[reservedWords[i]] = true;
2098
+ }
2099
+
2100
+ JavaScriptCompiler.isValidJavaScriptVariableName = function(name) {
2101
+ if(!JavaScriptCompiler.RESERVED_WORDS[name] && /^[a-zA-Z_$][0-9a-zA-Z_$]+$/.test(name)) {
2102
+ return true;
2103
+ }
2104
+ return false;
2105
+ };
2106
+
2107
+ Handlebars.precompile = function(input, options) {
2108
+ if (input == null || (typeof input !== 'string' && input.constructor !== Handlebars.AST.ProgramNode)) {
2109
+ throw new Handlebars.Exception("You must pass a string or Handlebars AST to Handlebars.precompile. You passed " + input);
2110
+ }
2111
+
2112
+ options = options || {};
2113
+ if (!('data' in options)) {
2114
+ options.data = true;
2115
+ }
2116
+ var ast = Handlebars.parse(input);
2117
+ var environment = new Compiler().compile(ast, options);
2118
+ return new JavaScriptCompiler().compile(environment, options);
2119
+ };
2120
+
2121
+ Handlebars.compile = function(input, options) {
2122
+ if (input == null || (typeof input !== 'string' && input.constructor !== Handlebars.AST.ProgramNode)) {
2123
+ throw new Handlebars.Exception("You must pass a string or Handlebars AST to Handlebars.compile. You passed " + input);
2124
+ }
2125
+
2126
+ options = options || {};
2127
+ if (!('data' in options)) {
2128
+ options.data = true;
2129
+ }
2130
+ var compiled;
2131
+ function compile() {
2132
+ var ast = Handlebars.parse(input);
2133
+ var environment = new Compiler().compile(ast, options);
2134
+ var templateSpec = new JavaScriptCompiler().compile(environment, options, undefined, true);
2135
+ return Handlebars.template(templateSpec);
2136
+ }
2137
+
2138
+ // Template is only compiled on first use and cached after that point.
2139
+ return function(context, options) {
2140
+ if (!compiled) {
2141
+ compiled = compile();
2142
+ }
2143
+ return compiled.call(this, context, options);
2144
+ };
2145
+ };
2146
+
2147
+ ;
2148
+ // lib/handlebars/runtime.js
2149
+
2150
+ Handlebars.VM = {
2151
+ template: function(templateSpec) {
2152
+ // Just add water
2153
+ var container = {
2154
+ escapeExpression: Handlebars.Utils.escapeExpression,
2155
+ invokePartial: Handlebars.VM.invokePartial,
2156
+ programs: [],
2157
+ program: function(i, fn, data) {
2158
+ var programWrapper = this.programs[i];
2159
+ if(data) {
2160
+ programWrapper = Handlebars.VM.program(i, fn, data);
2161
+ } else if (!programWrapper) {
2162
+ programWrapper = this.programs[i] = Handlebars.VM.program(i, fn);
2163
+ }
2164
+ return programWrapper;
2165
+ },
2166
+ programWithDepth: Handlebars.VM.programWithDepth,
2167
+ noop: Handlebars.VM.noop,
2168
+ compilerInfo: null
2169
+ };
2170
+
2171
+ return function(context, options) {
2172
+ options = options || {};
2173
+ var result = templateSpec.call(container, Handlebars, context, options.helpers, options.partials, options.data);
2174
+
2175
+ var compilerInfo = container.compilerInfo || [],
2176
+ compilerRevision = compilerInfo[0] || 1,
2177
+ currentRevision = Handlebars.COMPILER_REVISION;
2178
+
2179
+ if (compilerRevision !== currentRevision) {
2180
+ if (compilerRevision < currentRevision) {
2181
+ var runtimeVersions = Handlebars.REVISION_CHANGES[currentRevision],
2182
+ compilerVersions = Handlebars.REVISION_CHANGES[compilerRevision];
2183
+ throw "Template was precompiled with an older version of Handlebars than the current runtime. "+
2184
+ "Please update your precompiler to a newer version ("+runtimeVersions+") or downgrade your runtime to an older version ("+compilerVersions+").";
2185
+ } else {
2186
+ // Use the embedded version info since the runtime doesn't know about this revision yet
2187
+ throw "Template was precompiled with a newer version of Handlebars than the current runtime. "+
2188
+ "Please update your runtime to a newer version ("+compilerInfo[1]+").";
2189
+ }
2190
+ }
2191
+
2192
+ return result;
2193
+ };
2194
+ },
2195
+
2196
+ programWithDepth: function(i, fn, data /*, $depth */) {
2197
+ var args = Array.prototype.slice.call(arguments, 3);
2198
+
2199
+ var program = function(context, options) {
2200
+ options = options || {};
2201
+
2202
+ return fn.apply(this, [context, options.data || data].concat(args));
2203
+ };
2204
+ program.program = i;
2205
+ program.depth = args.length;
2206
+ return program;
2207
+ },
2208
+ program: function(i, fn, data) {
2209
+ var program = function(context, options) {
2210
+ options = options || {};
2211
+
2212
+ return fn(context, options.data || data);
2213
+ };
2214
+ program.program = i;
2215
+ program.depth = 0;
2216
+ return program;
2217
+ },
2218
+ noop: function() { return ""; },
2219
+ invokePartial: function(partial, name, context, helpers, partials, data) {
2220
+ var options = { helpers: helpers, partials: partials, data: data };
2221
+
2222
+ if(partial === undefined) {
2223
+ throw new Handlebars.Exception("The partial " + name + " could not be found");
2224
+ } else if(partial instanceof Function) {
2225
+ return partial(context, options);
2226
+ } else if (!Handlebars.compile) {
2227
+ throw new Handlebars.Exception("The partial " + name + " could not be compiled when running in runtime-only mode");
2228
+ } else {
2229
+ partials[name] = Handlebars.compile(partial, {data: data !== undefined});
2230
+ return partials[name](context, options);
2231
+ }
2232
+ }
2233
+ };
2234
+
2235
+ Handlebars.template = Handlebars.VM.template;
2236
+ ;
2237
+ // lib/handlebars/browser-suffix.js
2238
+ })(Handlebars);
2239
+ ;