haml_coffee_assets 1.5.1 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -6,6 +6,13 @@ a pure [Sprockets](https://github.com/sstephenson/sprockets) engine without Rail
6
6
 
7
7
  Tested on MRI Ruby 1.8.7, 1.9.2, 1.9.3, REE and the latest version of JRuby.
8
8
 
9
+ ## Features
10
+
11
+ * Seamless integration of [Haml-Coffee](https://github.com/netzpirat/haml-coffee) into the Rails asset pipeline or as
12
+ standalone Sprockets engine.
13
+ * Manifold options to configure Haml Coffee Assets to your needs.
14
+ * AMD support.
15
+
9
16
  ## Haml Coffee
10
17
 
11
18
  Haml Coffee allows you to write inline [CoffeeScript](http://jashkenas.github.com/coffee-script/) in your
@@ -13,24 +20,20 @@ Haml Coffee allows you to write inline [CoffeeScript](http://jashkenas.github.co
13
20
 
14
21
  ```haml
15
22
  #cart
16
- %h2= I18n.t('js.cart.title')
17
- - if @cart.length == 0
18
- %p.empty= I18n.t('js.cart.empty')
23
+ %h2 Cart
24
+ - if @cart.length is 0
25
+ %p.empty Your cart is empty
19
26
  - else
20
27
  %ul
21
28
  - for item in @cart
22
29
  %li
23
30
  .item
24
31
  = item.name
25
- %a{ :href => "/cart/item/remove/#{ item.id }" }
26
- = I18n.t('js.cart.item.remove')
32
+ %a{ :href => "/cart/item/remove/#{ item.id }" } Remove Item
27
33
  ```
28
34
 
29
35
  You can try Haml Coffee online by visiting [Haml Coffee Online](http://haml-coffee-online.herokuapp.com/).
30
36
 
31
- Please note that the `I18n` object in the above example is not part ot Haml Coffee Assets, the internationalization
32
- functions are provided by the [i18n.js](https://github.com/fnando/i18n-js) library.
33
-
34
37
  ## Installation
35
38
 
36
39
  The simplest way to install Haml Coffee Assets is to use [Bundler](http://gembundler.com/).
@@ -147,6 +150,17 @@ If you prefer another HTML format than HTML5, you can set it in your `config/app
147
150
  config.hamlcoffee.format = 'xhtml'
148
151
  ```
149
152
 
153
+ ### Template Placement
154
+
155
+ By default all Haml Coffee templates are placed under the configured template namespace. You can choose between the
156
+ following placements:
157
+
158
+ * global
159
+ * amd
160
+
161
+ By setting the placement option to `amd`, each template will be wrapped within a `define` function, enabling the usage
162
+ of a module loader.
163
+
150
164
  ### Template namespace
151
165
 
152
166
  By default all Haml Coffee templates are registered under the `JST` namespace. A template
@@ -20,10 +20,10 @@ module HamlCoffeeAssets
20
20
  #
21
21
  def compile(name, source, jst = true)
22
22
  config = HamlCoffeeAssets.config
23
-
23
+
24
24
  runtime.call('HamlCoffeeAssets.compile', name, source, jst,
25
25
  config.namespace, config.format, config.uglify, config.basename,
26
- config.escapeHtml, config.escapeAttributes, config.cleanValue,
26
+ config.escapeHtml, config.escapeAttributes, config.cleanValue, config.placement,
27
27
  config.customHtmlEscape, config.customCleanValue,
28
28
  config.customPreserve, config.customFindAndPreserve,
29
29
  config.customSurround, config.customSucceed, config.customPrecede,
@@ -7,7 +7,7 @@ module HamlCoffeeAssets
7
7
  def self.config
8
8
  @config ||= ::HamlCoffeeAssets::Configuration.new
9
9
  end
10
-
10
+
11
11
  # Haml Coffee configuration object that contains the default values.
12
12
  # It's a plain Ruby object so a Sinatra app doesn't have to depend
13
13
  # on ActiveSupport just because of the Rails engine configuration.
@@ -24,6 +24,7 @@ module HamlCoffeeAssets
24
24
  self.escapeHtml = true
25
25
  self.escapeAttributes = true
26
26
  self.cleanValue = true
27
+ self.placement = 'global'
27
28
  self.customHtmlEscape = 'window.HAML.escape'
28
29
  self.customCleanValue = 'window.HAML.cleanValue'
29
30
  self.customPreserve = 'window.HAML.preserve'
@@ -66,6 +67,10 @@ module HamlCoffeeAssets
66
67
  #
67
68
  attr_accessor :cleanValue
68
69
 
70
+ # Define the function placement, either `global` or `amd`
71
+ #
72
+ attr_accessor :placement
73
+
69
74
  # Custom global HTML escaping function
70
75
  #
71
76
  attr_accessor :customHtmlEscape
@@ -1,5 +1,5 @@
1
1
  # coding: UTF-8
2
2
 
3
3
  module HamlCoffeeAssets
4
- VERSION = '1.5.1' unless defined?(HamlCoffeeAssets::VERSION)
4
+ VERSION = '1.6.0' unless defined?(HamlCoffeeAssets::VERSION)
5
5
  end
@@ -19,6 +19,8 @@ var HamlCoffeeAssets = (function(){
19
19
  * @param basename [Boolean] ignore path when generate JST
20
20
  * @param escapeHtml [Boolean] whether to escape HTML output by default or not
21
21
  * @param escapeAttributes [Boolean] whether to escape HTML attributes output by default or not
22
+ * @param cleanValue [String] the name of the function to clean the values
23
+ * @param placement [String] where to place the function, either `global` or `amd`
22
24
  * @param customHtmlEscape [String] the name of the function to escape the output
23
25
  * @param customCleanValue [String] the name of the function to clean the code output
24
26
  * @param customSurround [String] the name of the function for the surround helper
@@ -30,7 +32,7 @@ var HamlCoffeeAssets = (function(){
30
32
  * @param extendScope [Boolean] extend the scope with the context
31
33
  */
32
34
  compile: function(name, source, jst, namespace, format, uglify, basename,
33
- escapeHtml, escapeAttributes, cleanValue,
35
+ escapeHtml, escapeAttributes, cleanValue, placement,
34
36
  customHtmlEscape, customCleanValue, customPreserve, customFindAndPreserve,
35
37
  customSurround, customSucceed, customPrecede,
36
38
  preserveTags, selfCloseTags,
@@ -43,6 +45,7 @@ var HamlCoffeeAssets = (function(){
43
45
  escapeHtml: escapeHtml,
44
46
  escapeAttributes: escapeAttributes,
45
47
  cleanValue: cleanValue,
48
+ placement: placement,
46
49
  customHtmlEscape: customHtmlEscape,
47
50
  customCleanValue: customCleanValue,
48
51
  customPreserve: customPreserve,
@@ -363,35 +363,38 @@ require.define("/haml-coffee.coffee", function (require, module, exports, __dirn
363
363
 
364
364
  module.exports = HamlCoffee = (function() {
365
365
 
366
- HamlCoffee.VERSION = '1.5.1';
366
+ HamlCoffee.VERSION = '1.6.0';
367
367
 
368
368
  function HamlCoffee(options) {
369
- var _base, _base2, _base3, _base4, _base5, _base6, _base7, _base8, _base9, _ref, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9;
369
+ var _base, _base10, _base2, _base3, _base4, _base5, _base6, _base7, _base8, _base9, _ref, _ref10, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9;
370
370
  this.options = options != null ? options : {};
371
- if ((_ref = (_base = this.options).escapeHtml) == null) {
372
- _base.escapeHtml = true;
371
+ if ((_ref = (_base = this.options).placement) == null) {
372
+ _base.placement = 'global';
373
373
  }
374
- if ((_ref2 = (_base2 = this.options).escapeAttributes) == null) {
375
- _base2.escapeAttributes = true;
374
+ if ((_ref2 = (_base2 = this.options).escapeHtml) == null) {
375
+ _base2.escapeHtml = true;
376
376
  }
377
- if ((_ref3 = (_base3 = this.options).cleanValue) == null) {
378
- _base3.cleanValue = true;
377
+ if ((_ref3 = (_base3 = this.options).escapeAttributes) == null) {
378
+ _base3.escapeAttributes = true;
379
379
  }
380
- if ((_ref4 = (_base4 = this.options).uglify) == null) _base4.uglify = false;
381
- if ((_ref5 = (_base5 = this.options).basename) == null) {
382
- _base5.basename = false;
380
+ if ((_ref4 = (_base4 = this.options).cleanValue) == null) {
381
+ _base4.cleanValue = true;
383
382
  }
384
- if ((_ref6 = (_base6 = this.options).extendScope) == null) {
385
- _base6.extendScope = false;
383
+ if ((_ref5 = (_base5 = this.options).uglify) == null) _base5.uglify = false;
384
+ if ((_ref6 = (_base6 = this.options).basename) == null) {
385
+ _base6.basename = false;
386
386
  }
387
- if ((_ref7 = (_base7 = this.options).format) == null) {
388
- _base7.format = 'html5';
387
+ if ((_ref7 = (_base7 = this.options).extendScope) == null) {
388
+ _base7.extendScope = false;
389
389
  }
390
- if ((_ref8 = (_base8 = this.options).preserveTags) == null) {
391
- _base8.preserveTags = 'pre,textarea';
390
+ if ((_ref8 = (_base8 = this.options).format) == null) {
391
+ _base8.format = 'html5';
392
392
  }
393
- if ((_ref9 = (_base9 = this.options).selfCloseTags) == null) {
394
- _base9.selfCloseTags = 'meta,img,link,br,hr,input,area,param,col,base';
393
+ if ((_ref9 = (_base9 = this.options).preserveTags) == null) {
394
+ _base9.preserveTags = 'pre,textarea';
395
+ }
396
+ if ((_ref10 = (_base10 = this.options).selfCloseTags) == null) {
397
+ _base10.selfCloseTags = 'meta,img,link,br,hr,input,area,param,col,base';
395
398
  }
396
399
  }
397
400
 
@@ -564,6 +567,20 @@ require.define("/haml-coffee.coffee", function (require, module, exports, __dirn
564
567
  };
565
568
 
566
569
  HamlCoffee.prototype.render = function(templateName, namespace) {
570
+ if (namespace == null) namespace = 'window.HAML';
571
+ switch (this.options.placement) {
572
+ case 'amd':
573
+ return this._render_amd();
574
+ default:
575
+ return this._render_global(templateName, namespace);
576
+ }
577
+ };
578
+
579
+ HamlCoffee.prototype._render_amd = function() {
580
+ return "define ->\n (context) ->\n render = ->\n \n" + (indent(this.precompile(), 4)) + "\n render.call(context)";
581
+ };
582
+
583
+ HamlCoffee.prototype._render_global = function(templateName, namespace) {
567
584
  var segment, segments, template, _i, _len;
568
585
  if (namespace == null) namespace = 'window.HAML';
569
586
  template = '';
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: 1.5.1
4
+ version: 1.6.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-09-24 00:00:00.000000000 Z
12
+ date: 2012-10-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: coffee-script
@@ -108,7 +108,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
108
108
  version: '0'
109
109
  segments:
110
110
  - 0
111
- hash: 591423817109157098
111
+ hash: 46178287923779691
112
112
  required_rubygems_version: !ruby/object:Gem::Requirement
113
113
  none: false
114
114
  requirements: