haml_coffee_assets 0.9.5 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -314,6 +314,22 @@ App.globalTemplateContext = (locals) -> HAML.extend({}, {
314
314
  Please have a look at the wiki for [further examples](https://github.com/netzpirat/haml_coffee_assets/wiki) on how to
315
315
  use the global context.
316
316
 
317
+ #### Extending the template scope with the context
318
+
319
+ Pure haml-coffee cannot extend the template scope with the context, since CoffeeScript doesn't have the `with`
320
+ statement. But when you're using Haml Coffee Assets, then you can have the scope to be extended
321
+ with the context by enable it in the configuration:
322
+
323
+ ```ruby
324
+ config.hamlcoffee.extendContext = true
325
+ ```
326
+
327
+ With this option enabled, you don't need to use `@` or `this` to reference context data:
328
+
329
+ ```Haml
330
+ %p= name
331
+ ```
332
+
317
333
  ### Customize the tag lists
318
334
 
319
335
  Haml Coffee contains two list of HTML tags that you can customize. In general you're fine with the defaults, but if
@@ -26,7 +26,7 @@ module HamlCoffeeAssets
26
26
  config.customPreserve, config.customFindAndPreserve,
27
27
  config.customSurround, config.customSucceed, config.customPrecede,
28
28
  config.preserveTags, config.selfCloseTags,
29
- config.context)
29
+ config.context, config.extendScope)
30
30
  end
31
31
 
32
32
  private
@@ -26,6 +26,7 @@ module HamlCoffeeAssets
26
26
  self.preserveTags = 'textarea,pre'
27
27
  self.selfCloseTags = 'meta,img,link,br,hr,input,area,param,col,base'
28
28
  self.context = 'window.HAML.context'
29
+ self.extendScope = false
29
30
  self.name_filter = lambda { |n| n.sub /^templates\//, '' }
30
31
  end
31
32
 
@@ -97,6 +98,10 @@ module HamlCoffeeAssets
97
98
  #
98
99
  attr_accessor :context
99
100
 
101
+ # Extend the template scope with the context
102
+ #
103
+ attr_accessor :extendScope
104
+
100
105
  # A proc that is called to modify the template name used as the
101
106
  # JST key. The proc is passed the name as an argument and should
102
107
  # return the modified name (or unmodified) name.
@@ -1,5 +1,5 @@
1
1
  # coding: UTF-8
2
2
 
3
3
  module HamlCoffeeAssets
4
- VERSION = '0.9.5' unless defined?(HamlCoffeeAssets::VERSION)
4
+ VERSION = '1.0.0' unless defined?(HamlCoffeeAssets::VERSION)
5
5
  end
@@ -36,14 +36,15 @@ var HamlCoffeeAssets = (function(){
36
36
  * @param preserveTags [String] comma separated list of tags to preserve whitespace
37
37
  * @param selfCloseTags [String] comma separated list of tags to self-closing tags
38
38
  * @param context [String] the name of the function to merge contexts
39
+ * @param extendScope [Boolean] extend the scope with the context
39
40
  */
40
41
  compile: function(name, source, jst, namespace, format, uglify, basename,
41
42
  escapeHtml, escapeAttributes, cleanValue,
42
43
  customHtmlEscape, customCleanValue, customPreserve, customFindAndPreserve,
43
44
  customSurround, customSucceed, customPrecede,
44
45
  preserveTags, selfCloseTags,
45
- context) {
46
-
46
+ context, extendScope) {
47
+
47
48
  var compiler = new Compiler({
48
49
  format: format,
49
50
  uglify: uglify,
@@ -59,7 +60,8 @@ var HamlCoffeeAssets = (function(){
59
60
  customSucceed: customSucceed,
60
61
  customPrecede: customPrecede,
61
62
  preserveTags: preserveTags,
62
- selfCloseTags: selfCloseTags
63
+ selfCloseTags: selfCloseTags,
64
+ extendScope: extendScope
63
65
  });
64
66
 
65
67
  compiler.parse(source);
@@ -68,9 +70,15 @@ var HamlCoffeeAssets = (function(){
68
70
 
69
71
  if (jst) {
70
72
  template = CoffeeScript.compile(compiler.render(name, namespace));
73
+
71
74
  } else {
72
75
  var hamlc = CoffeeScript.compile(compiler.precompile(), { bare: true });
73
- template = '(function(context) {\n return (function() {\n' + hamlc.replace(/^(.*)$/mg, ' $1') + '\n }).call(context);\n});';
76
+
77
+ if (extendScope) {
78
+ template = '(function(context) {\n with(context || {}) {\n return (function() {\n' + hamlc.replace(/^(.*)$/mg, ' $1') + '\n };\n }).call(context);\n});';
79
+ } else {
80
+ template = '(function(context) {\n return (function() {\n' + hamlc.replace(/^(.*)$/mg, ' $1') + '\n }).call(context);\n});';
81
+ }
74
82
  }
75
83
 
76
84
  if (context !== '' && context !== false) {
@@ -363,34 +363,35 @@ require.define("/haml-coffee.js", function (require, module, exports, __dirname,
363
363
 
364
364
  module.exports = HamlCoffee = (function() {
365
365
 
366
- HamlCoffee.name = 'HamlCoffee';
367
-
368
366
  function HamlCoffee(options) {
369
- var _base, _base1, _base2, _base3, _base4, _base5, _base6, _base7;
367
+ var _base, _base1, _base2, _base3, _base4, _base5, _base6, _base7, _base8, _ref, _ref1, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8;
370
368
  this.options = options != null ? options : {};
371
- if ((_base = this.options).escapeHtml == null) {
369
+ if ((_ref = (_base = this.options).escapeHtml) == null) {
372
370
  _base.escapeHtml = true;
373
371
  }
374
- if ((_base1 = this.options).escapeAttributes == null) {
372
+ if ((_ref1 = (_base1 = this.options).escapeAttributes) == null) {
375
373
  _base1.escapeAttributes = true;
376
374
  }
377
- if ((_base2 = this.options).cleanValue == null) {
375
+ if ((_ref2 = (_base2 = this.options).cleanValue) == null) {
378
376
  _base2.cleanValue = true;
379
377
  }
380
- if ((_base3 = this.options).uglify == null) {
378
+ if ((_ref3 = (_base3 = this.options).uglify) == null) {
381
379
  _base3.uglify = false;
382
380
  }
383
- if ((_base4 = this.options).basename == null) {
381
+ if ((_ref4 = (_base4 = this.options).basename) == null) {
384
382
  _base4.basename = false;
385
383
  }
386
- if ((_base5 = this.options).format == null) {
387
- _base5.format = 'html5';
384
+ if ((_ref5 = (_base5 = this.options).extendScope) == null) {
385
+ _base5.extendScope = false;
386
+ }
387
+ if ((_ref6 = (_base6 = this.options).format) == null) {
388
+ _base6.format = 'html5';
388
389
  }
389
- if ((_base6 = this.options).preserveTags == null) {
390
- _base6.preserveTags = 'pre,textarea';
390
+ if ((_ref7 = (_base7 = this.options).preserveTags) == null) {
391
+ _base7.preserveTags = 'pre,textarea';
391
392
  }
392
- if ((_base7 = this.options).selfCloseTags == null) {
393
- _base7.selfCloseTags = 'meta,img,link,br,hr,input,area,param,col,base';
393
+ if ((_ref8 = (_base8 = this.options).selfCloseTags) == null) {
394
+ _base8.selfCloseTags = 'meta,img,link,br,hr,input,area,param,col,base';
394
395
  }
395
396
  }
396
397
 
@@ -588,9 +589,17 @@ require.define("/haml-coffee.js", function (require, module, exports, __dirname,
588
589
  } else {
589
590
  template += "" + namespace + " ?= {}\n";
590
591
  }
591
- template += "" + namespace + "['" + templateName + "'] = (context) -> ( ->\n";
592
- template += "" + (indent(this.precompile(), 1));
593
- template += ").call(context)";
592
+ if (this.options.extendScope) {
593
+ template += "" + namespace + "['" + templateName + "'] = (context) -> ( ->\n";
594
+ template += " `with (context || {}) {`\n";
595
+ template += "" + (indent(this.precompile(), 1));
596
+ template += "`}`\n";
597
+ template += ").call(context)";
598
+ } else {
599
+ template += "" + namespace + "['" + templateName + "'] = (context) -> ( ->\n";
600
+ template += "" + (indent(this.precompile(), 1));
601
+ template += ").call(context)";
602
+ }
594
603
  return template;
595
604
  };
596
605
 
@@ -759,8 +768,6 @@ require.define("/nodes/node.js", function (require, module, exports, __dirname,
759
768
 
760
769
  module.exports = Node = (function() {
761
770
 
762
- Node.name = 'Node';
763
-
764
771
  Node.CLEAR_WHITESPACE_LEFT = '\u0091';
765
772
 
766
773
  Node.CLEAR_WHITESPACE_RIGHT = '\u0092';
@@ -989,7 +996,7 @@ require.define("/nodes/text.js", function (require, module, exports, __dirname,
989
996
  (function() {
990
997
  var Node, Text, escapeQuotes,
991
998
  __hasProp = {}.hasOwnProperty,
992
- __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; };
999
+ __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; };
993
1000
 
994
1001
  Node = require('./node');
995
1002
 
@@ -999,8 +1006,6 @@ require.define("/nodes/text.js", function (require, module, exports, __dirname,
999
1006
 
1000
1007
  __extends(Text, _super);
1001
1008
 
1002
- Text.name = 'Text';
1003
-
1004
1009
  function Text() {
1005
1010
  return Text.__super__.constructor.apply(this, arguments);
1006
1011
  }
@@ -1408,7 +1413,7 @@ require.define("/nodes/code.js", function (require, module, exports, __dirname,
1408
1413
  (function() {
1409
1414
  var Code, Node,
1410
1415
  __hasProp = {}.hasOwnProperty,
1411
- __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; };
1416
+ __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; };
1412
1417
 
1413
1418
  Node = require('./node');
1414
1419
 
@@ -1416,8 +1421,6 @@ require.define("/nodes/code.js", function (require, module, exports, __dirname,
1416
1421
 
1417
1422
  __extends(Code, _super);
1418
1423
 
1419
- Code.name = 'Code';
1420
-
1421
1424
  function Code() {
1422
1425
  return Code.__super__.constructor.apply(this, arguments);
1423
1426
  }
@@ -1463,7 +1466,7 @@ require.define("/nodes/comment.js", function (require, module, exports, __dirnam
1463
1466
  (function() {
1464
1467
  var Comment, Node,
1465
1468
  __hasProp = {}.hasOwnProperty,
1466
- __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; };
1469
+ __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; };
1467
1470
 
1468
1471
  Node = require('./node');
1469
1472
 
@@ -1471,8 +1474,6 @@ require.define("/nodes/comment.js", function (require, module, exports, __dirnam
1471
1474
 
1472
1475
  __extends(Comment, _super);
1473
1476
 
1474
- Comment.name = 'Comment';
1475
-
1476
1477
  function Comment() {
1477
1478
  return Comment.__super__.constructor.apply(this, arguments);
1478
1479
  }
@@ -1510,7 +1511,7 @@ require.define("/nodes/filter.js", function (require, module, exports, __dirname
1510
1511
  (function() {
1511
1512
  var Filter, Node, unescapeQuotes, whitespace,
1512
1513
  __hasProp = {}.hasOwnProperty,
1513
- __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; };
1514
+ __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; };
1514
1515
 
1515
1516
  Node = require('./node');
1516
1517
 
@@ -1522,8 +1523,6 @@ require.define("/nodes/filter.js", function (require, module, exports, __dirname
1522
1523
 
1523
1524
  __extends(Filter, _super);
1524
1525
 
1525
- Filter.name = 'Filter';
1526
-
1527
1526
  function Filter() {
1528
1527
  return Filter.__super__.constructor.apply(this, arguments);
1529
1528
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haml_coffee_assets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.5
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-08 00:00:00.000000000 Z
12
+ date: 2012-06-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: execjs
@@ -109,7 +109,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
109
109
  version: '0'
110
110
  segments:
111
111
  - 0
112
- hash: -189567978419904399
112
+ hash: -738589441708461623
113
113
  required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  none: false
115
115
  requirements: