haml_coffee_assets 1.12.0 → 1.13.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 93f2ccc92329ca9b444dfee07f4e9a41dbd4ae6c
4
- data.tar.gz: 801901d64e1274b52947117848a341821f715994
3
+ metadata.gz: f16bd71b0c4e027ca2945067b211a9c3475f01fc
4
+ data.tar.gz: d08c4a18c98bb10899d6a034a18969b1c0dfe26a
5
5
  SHA512:
6
- metadata.gz: 85cc9b88742800121bacf533bf23c3db55705300c53949af219045ab9ece3f682bd5619d6e009e47dd61ac64107173ca06dc09fe57c8706c9250b4b7c86079ad
7
- data.tar.gz: 18445a4f5229d2ec3bc7827701d7d860da37526d01f7670a3e5b81c9b960d6cc7c3284f95014183120344b37b03415e997f464ce078319d86bca3e5cc0309fae
6
+ metadata.gz: 6cda2dc44bc2fbbe5d7f95a0fd3848fb98c2b7b01339f4322c764a42c832d7320b5aca103a43c8cccb39a2d6496f845dbd8f2fb6adc8a93960f83376084d3b2c
7
+ data.tar.gz: 49bddad7bd2cf83626e817f2c488837f4afbbe44b00ab872b5bc2d89ab380a194aa1e0ecd81a0bb33ec74cbabec66a234c6db353dcb2f0afc28421f0a1128508
data/README.md CHANGED
@@ -49,7 +49,7 @@ group :assets do
49
49
  end
50
50
  ```
51
51
 
52
- And require the `hamlcoffee.js` in your `app/assets/javascripts/application.js.coffee`:
52
+ And require the `hamlcoffee.js` in your `app/assets/javascripts/templates/context.js.coffee`:
53
53
 
54
54
  ```coffeescript
55
55
  #= require hamlcoffee
@@ -126,15 +126,22 @@ Given a Haml Coffee template at `app/assets/javascripts/templates/books/_book.ha
126
126
  %dd= @author
127
127
  ```
128
128
 
129
- Rendering `books#index`:
129
+ And a Haml Coffee context at `app/assets/javascripts/templates/context.js`:
130
+
131
+ ```javascript
132
+ //= require hamlcoffee
133
+ ```
134
+
135
+ To render on server in `books#index`:
130
136
 
131
137
  ```haml
132
138
  = render "book", :name => "A Tale of Two Cities", :author => "Charles Dickens"
133
139
  ```
134
140
 
135
- Require and render the same file on the client using the asset pipeline:
141
+ To render and render the same file on the client using the asset pipeline:
136
142
 
137
143
  ```coffeescript
144
+ #= require hamlcoffee
138
145
  #= require templates/books/_book
139
146
 
140
147
  JST["books/book"](name: "A Tale of Two Cities", author: "Charles Dickens")
@@ -372,6 +379,14 @@ Now you can use the properties from the global context in every template:
372
379
  %p Please log into your account.
373
380
  ```
374
381
 
382
+ When rendering on the server, haml_coffee_assets will expect the global context to be overriden with the `global_context_asset`. Located by default at `templates/context`.
383
+
384
+ You can configure the path to this asset in your `config/application.rb`:
385
+
386
+ ```ruby
387
+ config.hamlcoffee.global_context_asset = 'templates/context'
388
+ ```
389
+
375
390
  If you like to use your own implementation, simply configure your context function in your `config/application.rb`:
376
391
 
377
392
  ```ruby
@@ -397,22 +412,6 @@ App.globalTemplateContext = (locals) -> HAML.extend({}, {
397
412
  Please have a look at the wiki for [further examples](https://github.com/netzpirat/haml_coffee_assets/wiki) on how to
398
413
  use the global context.
399
414
 
400
- #### Extending the template scope with the context
401
-
402
- Pure haml-coffee cannot extend the template scope with the context, since CoffeeScript doesn't have the `with`
403
- statement. But when you're using Haml Coffee Assets, then you can have the scope to be extended
404
- with the context by enable it in the configuration:
405
-
406
- ```ruby
407
- config.hamlcoffee.extendScope = true
408
- ```
409
-
410
- With this option enabled, you don't need to use `@` or `this` to reference context data:
411
-
412
- ```Haml
413
- %p= name
414
- ```
415
-
416
415
  ### Customize the tag lists
417
416
 
418
417
  Haml Coffee contains two list of HTML tags that you can customize. In general you're fine with the defaults, but if
@@ -462,13 +461,13 @@ You can see the [default implementation](https://github.com/netzpirat/haml_coffe
462
461
  and the [Haml Coffee documentation](https://github.com/netzpirat/haml-coffee#custom-helper-function-options)
463
462
  for more information about each helper function.
464
463
 
465
- ### Shared template path
464
+ ### Templates path
466
465
 
467
466
  Rails will look for templates in `app/assets/javascripts/templates` when rendering on the server side. If you store your
468
467
  templates in another directory, you can change this location:
469
468
 
470
469
  ```ruby
471
- config.hamlcoffee.shared_template_path = "custom/template/path"
470
+ config.hamlcoffee.templates_path = "custom/template/path"
472
471
  ```
473
472
 
474
473
  ## Partial rendering
@@ -538,6 +537,16 @@ Pull requests are very welcome! Please try to follow these simple rules if appli
538
537
 
539
538
  For questions please join `#haml` on irc.freenode.net
540
539
 
540
+ ### Open Commit Bit
541
+
542
+ Guard has an open commit bit policy: Anyone with an accepted pull request gets added as a repository collaborator.
543
+ Please try to follow these simple rules:
544
+
545
+ * Commit directly onto the master branch only for typos, improvements to the readme and documentation (please add
546
+ `[ci skip]` to the commit message).
547
+ * Create a feature branch and open a pull-request early for any new features to get feedback.
548
+ * Make sure you adhere to the general pull request rules above.
549
+
541
550
  ## Contributors
542
551
 
543
552
  See the [CHANGELOG](https://github.com/netzpirat/haml_coffee_assets/blob/master/CHANGELOG.md) and the GitHub list of
@@ -0,0 +1,40 @@
1
+ # Monkey patches for rails to support our template engine.
2
+ # Hopefully these fixes will make it into rails or we find a
3
+ # better way to avoid this.
4
+ #
5
+ # TODO: Don't monkey patch rails
6
+
7
+ # See patch notes inline
8
+ class ::ActionView::Template
9
+
10
+ # Patch, it's almost exaclty the same with a small tweak
11
+ def handle_render_error(view, e) #:nodoc:
12
+ if e.is_a?(::ActionView::Template::Error)
13
+ e.sub_template_of(self)
14
+ raise e
15
+ else
16
+ assigns = view.respond_to?(:assigns) ? view.assigns : {}
17
+ template = self
18
+
19
+ # Here's the patch: if the javascript runtime throws an error
20
+ # during compilation, we get to this handler but our view
21
+ # doesn't have a lookup_context - thus throwing a very hard
22
+ # to debug error in Template#refresh. To circumvent, ensure the
23
+ # view responds to lookup_context before refreshing.
24
+ if view.respond_to?(:lookup_context) and template.source.nil?
25
+ template = refresh(view)
26
+ template.encode!
27
+ end
28
+ if ::ActionView::Template::Error.instance_method(:initialize).arity == 3
29
+ # Rails < 4.0 expects three arguments here
30
+ raise ::ActionView::Template::Error.new(template, assigns, e)
31
+ elsif ::ActionView::Template::Error.instance_method(:initialize).arity == 2
32
+ # and Rails >= 4.0 expects two arguments
33
+ raise ::ActionView::Template::Error.new(template, e)
34
+ else
35
+ # try and fail graciously if this changes in the future
36
+ raise e
37
+ end
38
+ end
39
+ end
40
+ end
@@ -9,6 +9,7 @@ module HamlCoffeeAssets
9
9
  class Resolver < ::ActionView::FileSystemResolver
10
10
  def find_templates(name, prefix, partial, details)
11
11
  if details[:formats].include?(:html)
12
+ clear_cache if ::Rails.env == "development"
12
13
  super
13
14
  else
14
15
  []
@@ -7,6 +7,10 @@ module HamlCoffeeAssets
7
7
  new(template).render
8
8
  end
9
9
 
10
+ def self.stale?(last_compile_time)
11
+ GlobalContext.mtime > last_compile_time
12
+ end
13
+
10
14
  def initialize(template, partial = false, dependencies = [])
11
15
  @template = template
12
16
  @partial = partial
@@ -48,7 +52,7 @@ module HamlCoffeeAssets
48
52
  end
49
53
 
50
54
  def helpers
51
- ::HamlCoffeeAssets.helpers
55
+ GlobalContext.to_s
52
56
  end
53
57
 
54
58
  def compiled_template
@@ -99,7 +103,7 @@ module HamlCoffeeAssets
99
103
 
100
104
  def partial_source(path)
101
105
  ::Rails.root.join(
102
- ::HamlCoffeeAssets.config.shared_template_path,
106
+ ::HamlCoffeeAssets.config.templates_path,
103
107
  partial_path(path) + '.hamlc'
104
108
  ).read
105
109
  end
@@ -28,7 +28,7 @@ module HamlCoffeeAssets
28
28
  config.customPreserve, config.customFindAndPreserve,
29
29
  config.customSurround, config.customSucceed, config.customPrecede, config.customReference,
30
30
  config.preserveTags, config.selfCloseTags,
31
- config.context, config.extendScope)
31
+ config.context, false)
32
32
  end
33
33
 
34
34
  private
@@ -37,8 +37,8 @@ module HamlCoffeeAssets
37
37
  self.preserveTags = 'textarea,pre'
38
38
  self.selfCloseTags = 'meta,img,link,br,hr,input,area,param,col,base'
39
39
  self.context = 'window.HAML.context'
40
- self.extendScope = false
41
- self.shared_template_path = 'app/assets/javascripts/templates'
40
+ self.templates_path = 'app/assets/javascripts/templates'
41
+ self.global_context_asset = 'templates/context'
42
42
  self.name_filter = lambda { |n|
43
43
  parts = n.sub(/^templates\//, '').split('/')
44
44
  parts.last.sub!(/^_/, '')
@@ -126,10 +126,6 @@ module HamlCoffeeAssets
126
126
  #
127
127
  attr_accessor :context
128
128
 
129
- # Extend the template scope with the context
130
- #
131
- attr_accessor :extendScope
132
-
133
129
  # A proc that is called to modify the template name used as the
134
130
  # JST key. The proc is passed the name as an argument and should
135
131
  # return the modified name (or unmodified) name.
@@ -138,7 +134,11 @@ module HamlCoffeeAssets
138
134
 
139
135
  # Path to templates shared by Rails and JS.
140
136
  #
141
- attr_accessor :shared_template_path
137
+ attr_accessor :templates_path
138
+
139
+ # Path to custom helpers shared by Rails and JS.
140
+ #
141
+ attr_accessor :global_context_asset
142
142
 
143
143
  end
144
144
 
@@ -0,0 +1,38 @@
1
+ module HamlCoffeeAssets
2
+ class GlobalContext
3
+ def self.asset
4
+ find_asset(asset_path)
5
+ end
6
+
7
+ def self.asset_path
8
+ ::HamlCoffeeAssets.config.global_context_asset
9
+ end
10
+
11
+ def self.mtime
12
+ return nil unless asset.respond_to?(:mtime)
13
+ asset.mtime
14
+ end
15
+
16
+ def self.body
17
+ return "" if asset.blank?
18
+ asset.body
19
+ end
20
+
21
+ def self.to_s
22
+ return "" if asset.blank?
23
+ asset.to_s
24
+ end
25
+
26
+ private
27
+
28
+ def self.env
29
+ ::Rails.application.assets
30
+ end
31
+
32
+ def self.find_asset(name)
33
+ return "" unless ::Rails.respond_to?(:application)
34
+ return "" unless ::Rails.application.respond_to?(:assets)
35
+ env.find_asset(name)
36
+ end
37
+ end
38
+ end
@@ -27,12 +27,56 @@ module HamlCoffeeAssets
27
27
 
28
28
  # Add template path to ActionController's view paths.
29
29
  ActiveSupport.on_load(:action_controller) do
30
- path = ::HamlCoffeeAssets.config.shared_template_path
30
+ path = ::HamlCoffeeAssets.config.templates_path
31
31
  resolver = ::HamlCoffeeAssets::ActionView::Resolver.new(path)
32
32
  ::ActionController::Base.append_view_path(resolver)
33
33
  end
34
34
  end
35
35
 
36
+ if ::Rails.env == "development"
37
+ # Monkey patch rails so it busts the server cache for templates
38
+ # depending on the global_context_asset.
39
+ #
40
+ # Currently, the only way to force rails to recompile a server template is to
41
+ # touch it. This is problematic because when the global_context_asset
42
+ # changes we need to manually touch every template that uses the congtext
43
+ # in some way.
44
+ #
45
+ # To ease development, make rails 'touch' and recompile hamlc templates
46
+ # when the global context has changed.
47
+ #
48
+ # Do this ONLY in development.
49
+ #
50
+ # TODO: Don't monkey patch rails.
51
+ module ::ActionView
52
+ class Template
53
+ def stale?
54
+ return false unless ::Rails.env == "development"
55
+ return false unless handler.respond_to?(:stale?)
56
+ handler.stale?(updated_at)
57
+ end
58
+
59
+ alias_method :old_render, :render
60
+
61
+ # by default, rails will only compile a template once
62
+ # path render so it recompiles the template if 'stale'
63
+ def render(view, locals, buffer=nil, &block)
64
+ if @compiled and stale?
65
+ now = Time.now
66
+ File.utime(now, now, identifier) # touch file
67
+ ::Rails.logger.info "Busted cache for #{identifier} by touching it"
68
+
69
+ view = refresh(view)
70
+ @source = view.source
71
+ @compiled = false
72
+ end
73
+ old_render(view, locals, buffer, &block)
74
+ end
75
+
76
+ end
77
+ end
78
+ end
79
+
36
80
  next unless app.assets
37
81
 
38
82
  # Register Tilt template (for Sprockets)
@@ -1,5 +1,5 @@
1
1
  # coding: UTF-8
2
2
 
3
3
  module HamlCoffeeAssets
4
- VERSION = '1.12.0' unless defined?(HamlCoffeeAssets::VERSION)
4
+ VERSION = '1.13.0' unless defined?(HamlCoffeeAssets::VERSION)
5
5
  end
@@ -6,15 +6,17 @@ require 'tilt'
6
6
  require 'sprockets'
7
7
  require 'execjs'
8
8
 
9
- require 'haml_coffee_assets/version'
9
+ require 'haml_coffee_assets/global_context'
10
10
  require 'haml_coffee_assets/configuration'
11
11
  require 'haml_coffee_assets/compiler'
12
+ require 'haml_coffee_assets/version'
12
13
 
13
14
  require 'haml_coffee_assets/tilt/template_handler'
14
15
 
15
- if defined?(Rails)
16
+ if defined?(Rails) && Rails.version >= '3.0.0'
16
17
  require 'rails'
17
18
  require 'haml_coffee_assets/rails/engine'
19
+ require 'haml_coffee_assets/action_view/patches'
18
20
  else
19
21
  require 'sprockets/engines'
20
22
  Sprockets.register_engine '.hamlc', ::HamlCoffeeAssets::Tilt::TemplateHandler
@@ -24,32 +26,4 @@ end
24
26
  # its configuration settings.
25
27
  #
26
28
  module HamlCoffeeAssets
27
-
28
- # Get the path to the `hamlcoffee.js.coffee.erb` helper file.
29
- #
30
- # @return [String] the absolute path to the helpers file
31
- #
32
- def self.helpers_path
33
- File.expand_path(File.join(File.dirname(__FILE__), '..', 'vendor', 'assets', 'javascripts', 'hamlcoffee.js.coffee.erb'))
34
- end
35
-
36
- # Get the Haml Coffee Assets helper file
37
- #
38
- # @param [Boolean] compile whether to compile the CS helpers or not
39
- # @return [String] the helpers content
40
- #
41
- def self.helpers(compile=true)
42
- require 'erb'
43
-
44
- content = File.read(HamlCoffeeAssets.helpers_path)
45
- script = ERB.new(content).result(binding)
46
-
47
- if compile
48
- require 'coffee-script'
49
- script = CoffeeScript.compile(script)
50
- end
51
-
52
- script
53
- end
54
-
55
29
  end
data/lib/js/hamlcoffee.js CHANGED
@@ -454,55 +454,54 @@ require.define("/haml-coffee.coffee",function(require,module,exports,__dirname,_
454
454
  indent = require('./util/text').indent;
455
455
 
456
456
  module.exports = HamlCoffee = (function() {
457
- HamlCoffee.VERSION = '1.11.0';
457
+ HamlCoffee.VERSION = '1.11.3';
458
458
 
459
459
  function HamlCoffee(options) {
460
- var segment, segments, _base, _base1, _base10, _base11, _base12, _base13, _base2, _base3, _base4, _base5, _base6, _base7, _base8, _base9, _i, _len, _ref, _ref1, _ref10, _ref11, _ref12, _ref13, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9;
461
-
460
+ var segment, segments, _base, _base1, _base10, _base11, _base12, _base13, _base2, _base3, _base4, _base5, _base6, _base7, _base8, _base9, _i, _len;
462
461
  this.options = options != null ? options : {};
463
- if ((_ref = (_base = this.options).placement) == null) {
462
+ if ((_base = this.options).placement == null) {
464
463
  _base.placement = 'global';
465
464
  }
466
- if ((_ref1 = (_base1 = this.options).dependencies) == null) {
465
+ if ((_base1 = this.options).dependencies == null) {
467
466
  _base1.dependencies = {
468
467
  hc: 'hamlcoffee'
469
468
  };
470
469
  }
471
- if ((_ref2 = (_base2 = this.options).escapeHtml) == null) {
470
+ if ((_base2 = this.options).escapeHtml == null) {
472
471
  _base2.escapeHtml = true;
473
472
  }
474
- if ((_ref3 = (_base3 = this.options).escapeAttributes) == null) {
473
+ if ((_base3 = this.options).escapeAttributes == null) {
475
474
  _base3.escapeAttributes = true;
476
475
  }
477
- if ((_ref4 = (_base4 = this.options).cleanValue) == null) {
476
+ if ((_base4 = this.options).cleanValue == null) {
478
477
  _base4.cleanValue = true;
479
478
  }
480
- if ((_ref5 = (_base5 = this.options).uglify) == null) {
479
+ if ((_base5 = this.options).uglify == null) {
481
480
  _base5.uglify = false;
482
481
  }
483
- if ((_ref6 = (_base6 = this.options).basename) == null) {
482
+ if ((_base6 = this.options).basename == null) {
484
483
  _base6.basename = false;
485
484
  }
486
- if ((_ref7 = (_base7 = this.options).extendScope) == null) {
485
+ if ((_base7 = this.options).extendScope == null) {
487
486
  _base7.extendScope = false;
488
487
  }
489
- if ((_ref8 = (_base8 = this.options).format) == null) {
488
+ if ((_base8 = this.options).format == null) {
490
489
  _base8.format = 'html5';
491
490
  }
492
- if ((_ref9 = (_base9 = this.options).hyphenateDataAttrs) == null) {
491
+ if ((_base9 = this.options).hyphenateDataAttrs == null) {
493
492
  _base9.hyphenateDataAttrs = true;
494
493
  }
495
- if ((_ref10 = (_base10 = this.options).preserveTags) == null) {
494
+ if ((_base10 = this.options).preserveTags == null) {
496
495
  _base10.preserveTags = 'pre,textarea';
497
496
  }
498
- if ((_ref11 = (_base11 = this.options).selfCloseTags) == null) {
497
+ if ((_base11 = this.options).selfCloseTags == null) {
499
498
  _base11.selfCloseTags = 'meta,img,link,br,hr,input,area,param,col,base';
500
499
  }
501
500
  if (this.options.placement === 'global') {
502
- if ((_ref12 = (_base12 = this.options).name) == null) {
501
+ if ((_base12 = this.options).name == null) {
503
502
  _base12.name = 'test';
504
503
  }
505
- if ((_ref13 = (_base13 = this.options).namespace) == null) {
504
+ if ((_base13 = this.options).namespace == null) {
506
505
  _base13.namespace = 'window.HAML';
507
506
  }
508
507
  segments = ("" + this.options.namespace + "." + this.options.name).replace(/(\s|-)+/g, '_').split(/\./);
@@ -537,11 +536,11 @@ require.define("/haml-coffee.coffee",function(require,module,exports,__dirname,_
537
536
 
538
537
  HamlCoffee.prototype.updateBlockLevel = function() {
539
538
  this.currentBlockLevel = this.currentIndent / this.tabSize;
540
- if (this.currentBlockLevel - Math.floor(this.currentBlockLevel) > 0) {
541
- throw "Indentation error in line " + this.lineNumber;
542
- }
543
- if ((this.currentIndent - this.previousIndent) / this.tabSize > 1) {
544
- if (!this.node.isCommented()) {
539
+ if (!this.node.isCommented()) {
540
+ if (this.currentBlockLevel - Math.floor(this.currentBlockLevel) > 0) {
541
+ throw "Indentation error in line " + this.lineNumber;
542
+ }
543
+ if ((this.currentIndent - this.previousIndent) / this.tabSize > 1) {
545
544
  throw "Block level too deep in line " + this.lineNumber;
546
545
  }
547
546
  }
@@ -571,7 +570,6 @@ require.define("/haml-coffee.coffee",function(require,module,exports,__dirname,_
571
570
 
572
571
  HamlCoffee.prototype.popParent = function() {
573
572
  var i, _i, _ref, _results;
574
-
575
573
  _results = [];
576
574
  for (i = _i = 0, _ref = this.delta - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) {
577
575
  _results.push(this.parentNode = this.stack.pop());
@@ -603,7 +601,6 @@ require.define("/haml-coffee.coffee",function(require,module,exports,__dirname,_
603
601
 
604
602
  HamlCoffee.prototype.nodeFactory = function(expression) {
605
603
  var node, options, _ref;
606
-
607
604
  if (expression == null) {
608
605
  expression = '';
609
606
  }
@@ -628,8 +625,7 @@ require.define("/haml-coffee.coffee",function(require,module,exports,__dirname,_
628
625
  };
629
626
 
630
627
  HamlCoffee.prototype.parse = function(source) {
631
- var attributes, expression, line, lines, result, text, ws, _ref;
632
-
628
+ var attributes, expression, line, lines, range, result, tabsize, text, ws, _i, _j, _len, _ref, _ref1, _results;
633
629
  if (source == null) {
634
630
  source = '';
635
631
  }
@@ -638,7 +634,7 @@ require.define("/haml-coffee.coffee",function(require,module,exports,__dirname,_
638
634
  this.node = null;
639
635
  this.stack = [];
640
636
  this.root = this.parentNode = new Node('', this.getNodeOptions());
641
- lines = source.split("\n");
637
+ lines = source.replace(/\r/g, '').split("\n");
642
638
  while ((line = lines.shift()) !== void 0) {
643
639
  if ((this.node instanceof Filter) && !this.exitFilter) {
644
640
  if (/^(\s)*$/.test(line)) {
@@ -654,11 +650,20 @@ require.define("/haml-coffee.coffee",function(require,module,exports,__dirname,_
654
650
  lines.unshift(line);
655
651
  continue;
656
652
  }
657
- text = line.match(RegExp("^\\s{" + ((this.node.blockLevel * 2) + 2) + "}(.*)"));
658
- if (text) {
659
- this.node.addChild(new Text(text[1], this.getNodeOptions({
660
- parentNode: this.node
661
- })));
653
+ range = this.tabSize > 2 ? (function() {
654
+ _results = [];
655
+ for (var _i = _ref = this.tabSize; _ref <= 1 ? _i <= 1 : _i >= 1; _ref <= 1 ? _i++ : _i--){ _results.push(_i); }
656
+ return _results;
657
+ }).apply(this) : [2, 1];
658
+ for (_j = 0, _len = range.length; _j < _len; _j++) {
659
+ tabsize = range[_j];
660
+ text = line.match(RegExp("^\\s{" + ((this.node.blockLevel * tabsize) + tabsize) + "}(.*)"));
661
+ if (text) {
662
+ this.node.addChild(new Text(text[1], this.getNodeOptions({
663
+ parentNode: this.node
664
+ })));
665
+ break;
666
+ }
662
667
  }
663
668
  }
664
669
  } else {
@@ -675,9 +680,13 @@ require.define("/haml-coffee.coffee",function(require,module,exports,__dirname,_
675
680
  expression += ' ' + attributes.match(/^\s*(.*?)(\s+\|\s*)?$/)[1];
676
681
  this.lineNumber++;
677
682
  }
683
+ while (/^-#/.test(expression) && !/^(\s*)[-=&!~.%#</]/.test(lines[0]) && lines.length > 0) {
684
+ lines.shift();
685
+ this.lineNumber++;
686
+ }
678
687
  if (expression.match(/(\s)+\|\s*$/)) {
679
688
  expression = expression.replace(/(\s)+\|\s*$/, ' ');
680
- while ((_ref = lines[0]) != null ? _ref.match(/(\s)+\|$/) : void 0) {
689
+ while ((_ref1 = lines[0]) != null ? _ref1.match(/(\s)+\|$/) : void 0) {
681
690
  expression += lines.shift().match(/^(\s*)(.*)/)[2].replace(/(\s)+\|\s*$/, '');
682
691
  this.lineNumber++;
683
692
  }
@@ -700,7 +709,6 @@ require.define("/haml-coffee.coffee",function(require,module,exports,__dirname,_
700
709
 
701
710
  HamlCoffee.prototype.evaluate = function(node) {
702
711
  var child, _i, _len, _ref;
703
-
704
712
  _ref = node.children;
705
713
  for (_i = 0, _len = _ref.length; _i < _len; _i++) {
706
714
  child = _ref[_i];
@@ -722,13 +730,11 @@ require.define("/haml-coffee.coffee",function(require,module,exports,__dirname,_
722
730
 
723
731
  HamlCoffee.prototype.renderStandalone = function() {
724
732
  var template;
725
-
726
733
  return template = "return (context) ->\n (->\n" + (indent(this.precompile(), 2)) + "\n ).call(context)";
727
734
  };
728
735
 
729
736
  HamlCoffee.prototype.renderAmd = function() {
730
737
  var m, module, modules, param, params, template, _ref, _ref1;
731
-
732
738
  if (/^hamlcoffee/.test(this.options.dependencies['hc'])) {
733
739
  this.options.customHtmlEscape = 'hc.escape';
734
740
  this.options.customCleanValue = 'hc.cleanValue';
@@ -757,7 +763,6 @@ require.define("/haml-coffee.coffee",function(require,module,exports,__dirname,_
757
763
  if (modules.length !== 0) {
758
764
  modules = (function() {
759
765
  var _i, _len, _results;
760
-
761
766
  _results = [];
762
767
  for (_i = 0, _len = modules.length; _i < _len; _i++) {
763
768
  m = modules[_i];
@@ -774,7 +779,6 @@ require.define("/haml-coffee.coffee",function(require,module,exports,__dirname,_
774
779
 
775
780
  HamlCoffee.prototype.renderGlobal = function() {
776
781
  var template;
777
-
778
782
  template = this.intro;
779
783
  if (this.options.extendScope) {
780
784
  template += "" + this.options.namespace + "['" + this.options.name + "'] = (context) -> ( ->\n";
@@ -792,7 +796,6 @@ require.define("/haml-coffee.coffee",function(require,module,exports,__dirname,_
792
796
 
793
797
  HamlCoffee.prototype.precompile = function() {
794
798
  var code, fn;
795
-
796
799
  fn = '';
797
800
  code = this.createCode();
798
801
  if (code.indexOf('$e') !== -1) {
@@ -862,7 +865,6 @@ require.define("/haml-coffee.coffee",function(require,module,exports,__dirname,_
862
865
 
863
866
  HamlCoffee.prototype.createCode = function() {
864
867
  var child, code, line, processors, _i, _j, _len, _len1, _ref, _ref1;
865
-
866
868
  code = [];
867
869
  this.lines = [];
868
870
  _ref = this.root.children;
@@ -923,7 +925,6 @@ require.define("/haml-coffee.coffee",function(require,module,exports,__dirname,_
923
925
 
924
926
  HamlCoffee.prototype.combineText = function(lines) {
925
927
  var combined, line, nextLine;
926
-
927
928
  combined = [];
928
929
  while ((line = lines.shift()) !== void 0) {
929
930
  if (line.type === 'text') {
@@ -967,7 +968,6 @@ require.define("/haml-coffee.coffee",function(require,module,exports,__dirname,_
967
968
 
968
969
  HamlCoffee.prototype.findDependencies = function(code) {
969
970
  var dependencies, match, module, name, requireRegexp;
970
-
971
971
  requireRegexp = /require(?:\s+|\()(['"])(.+?)(\1)\)?/gm;
972
972
  dependencies = {};
973
973
  while (match = requireRegexp.exec(code)) {
@@ -1117,7 +1117,6 @@ require.define("/nodes/node.coffee",function(require,module,exports,__dirname,__
1117
1117
 
1118
1118
  Node.prototype.render = function() {
1119
1119
  var child, output, rendered, tag, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _m, _ref, _ref1, _ref2, _ref3, _ref4;
1120
-
1121
1120
  output = [];
1122
1121
  if (this.silent) {
1123
1122
  return output;
@@ -1189,7 +1188,6 @@ require.define("/util/text.coffee",function(require,module,exports,__dirname,__f
1189
1188
  module.exports = {
1190
1189
  whitespace: function(n) {
1191
1190
  var a;
1192
-
1193
1191
  n = n * 2;
1194
1192
  a = [];
1195
1193
  while (a.length < n) {
@@ -1217,6 +1215,7 @@ require.define("/util/text.coffee",function(require,module,exports,__dirname,__f
1217
1215
  },
1218
1216
  preserve: function(code) {
1219
1217
  if (code) {
1218
+ code.replace(/\r/g, '');
1220
1219
  return code.replace(/<(pre|textarea)>(.*?)<\/\1>/g, function(text) {
1221
1220
  return text.replace('\\n', '\&\#x000A;');
1222
1221
  });
@@ -1279,7 +1278,6 @@ require.define("/nodes/haml.coffee",function(require,module,exports,__dirname,__
1279
1278
 
1280
1279
  Haml.prototype.evaluate = function() {
1281
1280
  var assignment, code, identifier, match, prefix, tokens;
1282
-
1283
1281
  tokens = this.parseExpression(this.expression);
1284
1282
  if (tokens.doctype) {
1285
1283
  return this.opener = this.markText("" + (escapeQuotes(this.buildDocType(tokens.doctype))));
@@ -1340,7 +1338,6 @@ require.define("/nodes/haml.coffee",function(require,module,exports,__dirname,__
1340
1338
 
1341
1339
  Haml.prototype.parseExpression = function(exp) {
1342
1340
  var attributes, classes, id, key, tag, value, _ref1, _ref2;
1343
-
1344
1341
  tag = this.parseTag(exp);
1345
1342
  if (this.preserveTags.indexOf(tag.tag) !== -1) {
1346
1343
  this.preserve = true;
@@ -1380,7 +1377,6 @@ require.define("/nodes/haml.coffee",function(require,module,exports,__dirname,__
1380
1377
 
1381
1378
  Haml.prototype.parseTag = function(exp) {
1382
1379
  var assignment, attr, attributes, ch, classes, doctype, end, error, haml, htmlAttributes, id, ids, key, klass, level, pos, reference, rest, rubyAttributes, start, tag, text, val, whitespace, _i, _j, _k, _len, _len1, _ref1, _ref2, _ref3, _ref4, _ref5;
1383
-
1384
1380
  try {
1385
1381
  doctype = (_ref1 = exp.match(/^(\!{3}.*)/)) != null ? _ref1[1] : void 0;
1386
1382
  if (doctype) {
@@ -1479,7 +1475,6 @@ require.define("/nodes/haml.coffee",function(require,module,exports,__dirname,__
1479
1475
  tag: tag ? tag[1] : 'div',
1480
1476
  ids: ids ? (function() {
1481
1477
  var _l, _len2, _results;
1482
-
1483
1478
  _results = [];
1484
1479
  for (_l = 0, _len2 = ids.length; _l < _len2; _l++) {
1485
1480
  id = ids[_l];
@@ -1489,7 +1484,6 @@ require.define("/nodes/haml.coffee",function(require,module,exports,__dirname,__
1489
1484
  })() : void 0,
1490
1485
  classes: classes ? (function() {
1491
1486
  var _l, _len2, _results;
1492
-
1493
1487
  _results = [];
1494
1488
  for (_l = 0, _len2 = classes.length; _l < _len2; _l++) {
1495
1489
  klass = classes[_l];
@@ -1510,7 +1504,6 @@ require.define("/nodes/haml.coffee",function(require,module,exports,__dirname,__
1510
1504
 
1511
1505
  Haml.prototype.parseAttributes = function(exp) {
1512
1506
  var attr, attributes, ch, endPos, hasDataAttribute, inDataAttribute, key, keyValue, keys, level, marker, markers, pairs, pos, quote, quoted, start, startPos, type, value, _i, _j, _k, _len, _len1, _ref1, _ref2, _ref3, _ref4, _ref5;
1513
-
1514
1507
  attributes = {};
1515
1508
  if (exp === void 0) {
1516
1509
  return attributes;
@@ -1617,13 +1610,11 @@ require.define("/nodes/haml.coffee",function(require,module,exports,__dirname,__
1617
1610
 
1618
1611
  Haml.prototype.buildHtmlTagPrefix = function(tokens) {
1619
1612
  var classList, classes, hasDynamicClass, key, klass, name, tagParts, value, _i, _len, _ref1;
1620
-
1621
1613
  tagParts = ["<" + tokens.tag];
1622
1614
  if (tokens.classes) {
1623
1615
  hasDynamicClass = false;
1624
1616
  classList = (function() {
1625
1617
  var _i, _len, _ref1, _results;
1626
-
1627
1618
  _ref1 = tokens.classes;
1628
1619
  _results = [];
1629
1620
  for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
@@ -1680,7 +1671,6 @@ require.define("/nodes/haml.coffee",function(require,module,exports,__dirname,__
1680
1671
 
1681
1672
  Haml.prototype.interpolateCodeAttribute = function(text, unwrap) {
1682
1673
  var quoted;
1683
-
1684
1674
  if (unwrap == null) {
1685
1675
  unwrap = false;
1686
1676
  }
@@ -1712,7 +1702,6 @@ require.define("/nodes/haml.coffee",function(require,module,exports,__dirname,__
1712
1702
 
1713
1703
  Haml.prototype.quoteAndEscapeAttributeValue = function(value, code) {
1714
1704
  var escaped, hasDoubleQuotes, hasInterpolation, hasSingleQuotes, quoted, result, token, tokens;
1715
-
1716
1705
  if (code == null) {
1717
1706
  code = false;
1718
1707
  }
@@ -1728,7 +1717,6 @@ require.define("/nodes/haml.coffee",function(require,module,exports,__dirname,__
1728
1717
  hasInterpolation = false;
1729
1718
  tokens = (function() {
1730
1719
  var _i, _len, _results;
1731
-
1732
1720
  _results = [];
1733
1721
  for (_i = 0, _len = tokens.length; _i < _len; _i++) {
1734
1722
  token = tokens[_i];
@@ -1775,7 +1763,6 @@ require.define("/nodes/haml.coffee",function(require,module,exports,__dirname,__
1775
1763
  if (hasDoubleQuotes && !hasSingleQuotes) {
1776
1764
  escaped = (function() {
1777
1765
  var _i, _len, _results;
1778
-
1779
1766
  _results = [];
1780
1767
  for (_i = 0, _len = tokens.length; _i < _len; _i++) {
1781
1768
  token = tokens[_i];
@@ -1788,7 +1775,6 @@ require.define("/nodes/haml.coffee",function(require,module,exports,__dirname,__
1788
1775
  if (hasSingleQuotes && hasDoubleQuotes) {
1789
1776
  escaped = (function() {
1790
1777
  var _i, _len, _results;
1791
-
1792
1778
  _results = [];
1793
1779
  for (_i = 0, _len = tokens.length; _i < _len; _i++) {
1794
1780
  token = tokens[_i];
@@ -1804,7 +1790,6 @@ require.define("/nodes/haml.coffee",function(require,module,exports,__dirname,__
1804
1790
 
1805
1791
  Haml.prototype.splitInterpolations = function(value) {
1806
1792
  var ch, ch2, level, pos, start, tokens, _i, _ref1;
1807
-
1808
1793
  level = 0;
1809
1794
  start = 0;
1810
1795
  tokens = [];
@@ -1888,7 +1873,6 @@ require.define("/nodes/code.coffee",function(require,module,exports,__dirname,__
1888
1873
 
1889
1874
  Code.prototype.evaluate = function() {
1890
1875
  var code, codeBlock, escape, identifier;
1891
-
1892
1876
  codeBlock = this.expression.match(/(-|!=|\&=|=|~)\s?(.*)?/);
1893
1877
  identifier = codeBlock[1];
1894
1878
  code = codeBlock[2];
@@ -1943,7 +1927,6 @@ require.define("/nodes/comment.coffee",function(require,module,exports,__dirname
1943
1927
 
1944
1928
  Comment.prototype.evaluate = function() {
1945
1929
  var comment, expression, identifier, _ref1;
1946
-
1947
1930
  _ref1 = this.expression.match(/(-#|\/\[|\/)\s?(.*)?/), expression = _ref1[0], identifier = _ref1[1], comment = _ref1[2];
1948
1931
  switch (identifier) {
1949
1932
  case '-#':
@@ -1992,13 +1975,11 @@ require.define("/nodes/filter.coffee",function(require,module,exports,__dirname,
1992
1975
 
1993
1976
  Filter.prototype.evaluate = function() {
1994
1977
  var _ref1;
1995
-
1996
1978
  return this.filter = (_ref1 = this.expression.match(/:(escaped|preserve|css|javascript|coffeescript|plain|cdata|coffeescript)(.*)?/)) != null ? _ref1[1] : void 0;
1997
1979
  };
1998
1980
 
1999
1981
  Filter.prototype.render = function() {
2000
1982
  var child, indent, output, preserve, _i, _j, _len, _len1, _ref1, _ref2;
2001
-
2002
1983
  output = [];
2003
1984
  switch (this.filter) {
2004
1985
  case 'escaped':
@@ -2066,7 +2047,6 @@ require.define("/nodes/filter.coffee",function(require,module,exports,__dirname,
2066
2047
 
2067
2048
  Filter.prototype.renderFilterContent = function(indent, output, type) {
2068
2049
  var child, content, e, empty, line, _i, _j, _k, _len, _len1, _ref1, _results;
2069
-
2070
2050
  if (type == null) {
2071
2051
  type = 'text';
2072
2052
  }
@@ -2127,9 +2107,8 @@ require.define("/nodes/directive.coffee",function(require,module,exports,__dirna
2127
2107
  Directive.prototype.directives = {
2128
2108
  include: function(expression) {
2129
2109
  var context, e, name, statement, _ref1;
2130
-
2131
2110
  try {
2132
- _ref1 = expression.match(/\s*['"](.*)['"](?:,\s*(.*))?\s*/), _ref1[0], name = _ref1[1], context = _ref1[2];
2111
+ _ref1 = expression.match(/\s*['"](.*?)['"](?:,\s*(.*))?\s*/), _ref1[0], name = _ref1[1], context = _ref1[2];
2133
2112
  } catch (_error) {
2134
2113
  e = _error;
2135
2114
  throw new Error("Failed to parse the include directive from " + expression);
@@ -2153,7 +2132,6 @@ require.define("/nodes/directive.coffee",function(require,module,exports,__dirna
2153
2132
 
2154
2133
  Directive.prototype.evaluate = function() {
2155
2134
  var directives, e, name, rest, _ref1;
2156
-
2157
2135
  directives = Object.keys(this.directives).join('|');
2158
2136
  try {
2159
2137
  _ref1 = this.expression.match(RegExp("\\+(" + directives + ")(.*)")), _ref1[0], name = _ref1[1], rest = _ref1[2];
@@ -2190,7 +2168,6 @@ require.define("/hamlc.coffee",function(require,module,exports,__dirname,__filen
2190
2168
  module.exports = {
2191
2169
  compile: function(source, options) {
2192
2170
  var compiler, template;
2193
-
2194
2171
  if (options == null) {
2195
2172
  options = {};
2196
2173
  }
@@ -2205,7 +2182,6 @@ require.define("/hamlc.coffee",function(require,module,exports,__dirname,__filen
2205
2182
  },
2206
2183
  template: function(source, name, namespace, options) {
2207
2184
  var compiler;
2208
-
2209
2185
  if (options == null) {
2210
2186
  options = {};
2211
2187
  }
@@ -2217,7 +2193,6 @@ require.define("/hamlc.coffee",function(require,module,exports,__dirname,__filen
2217
2193
  },
2218
2194
  __express: function(filename, options, callback) {
2219
2195
  var err, source;
2220
-
2221
2196
  if (!!(options && options.constructor && options.call && options.apply)) {
2222
2197
  callback = options;
2223
2198
  options = {};
@@ -75,7 +75,7 @@ class window.HAML
75
75
  #
76
76
  @findAndPreserve: (text) ->
77
77
  tags = '<%= ::HamlCoffeeAssets.config.preserveTags %>'.split(',').join('|')
78
- text = text.replace ///<(#{ tags })>([^]*?)<\/\1>///g, (str, tag, content) ->
78
+ text = text.replace(/\r/g, '').replace ///<(#{ tags })>([^]*?)<\/\1>///g, (str, tag, content) ->
79
79
  "<#{ tag }>#{ <%= ::HamlCoffeeAssets.config.customPreserve %>(content) }</#{ tag }>"
80
80
 
81
81
  # The surround helper surrounds the function output
@@ -48,7 +48,7 @@ define ->
48
48
  #
49
49
  findAndPreserve: (text) ->
50
50
  tags = '<%= ::HamlCoffeeAssets.config.preserveTags %>'.split(',').join('|')
51
- text = text.replace ///<(#{ tags })>([^]*?)<\/\1>/// g, (str, tag, content) ->
51
+ text = text.replace(/\r/g, '').replace ///<(#{ tags })>([^]*?)<\/\1>/// g, (str, tag, content) ->
52
52
  "<#{ tag }>#{ <%= ::HamlCoffeeAssets.config.customPreserve %>(content) }</#{ tag }>"
53
53
 
54
54
  # The surround helper surrounds the function output
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haml_coffee_assets
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.12.0
4
+ version: 1.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Kessler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-08 00:00:00.000000000 Z
11
+ date: 2013-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: coffee-script
@@ -73,10 +73,12 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
+ - lib/haml_coffee_assets/action_view/patches.rb
76
77
  - lib/haml_coffee_assets/action_view/resolver.rb
77
78
  - lib/haml_coffee_assets/action_view/template_handler.rb
78
79
  - lib/haml_coffee_assets/compiler.rb
79
80
  - lib/haml_coffee_assets/configuration.rb
81
+ - lib/haml_coffee_assets/global_context.rb
80
82
  - lib/haml_coffee_assets/rails/engine.rb
81
83
  - lib/haml_coffee_assets/tilt/template_handler.rb
82
84
  - lib/haml_coffee_assets/version.rb
@@ -107,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
109
  version: 1.3.6
108
110
  requirements: []
109
111
  rubyforge_project: haml_coffee_assets
110
- rubygems_version: 2.0.3
112
+ rubygems_version: 2.0.2
111
113
  signing_key:
112
114
  specification_version: 4
113
115
  summary: Haml CoffeeScript templates