haml_assets 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.rvmrc CHANGED
@@ -1 +1 @@
1
- rvm use default@handlebars_assets
1
+ rvm use default@haml_assets
@@ -0,0 +1,7 @@
1
+ ## v0.2.0
2
+
3
+ * Allow partials to render (@nicolai86, @libc)
4
+
5
+ ## v0.2.1
6
+
7
+ * Allow partials to trigger recompile (@libc)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- haml_assets (0.1.0)
4
+ haml_assets (0.2.1)
5
5
  haml
6
6
  tilt
7
7
 
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011-2012 Care Zone, Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,12 +1,9 @@
1
- **BREAKING CHANGE** `haml_assets` now works with the `haml` gem. Please update
2
- your gemfile.
3
-
4
- # Use `haml` to write your JavaScript templates in the asset pipeline
1
+ # Haml for JavaScript templates with the asset pipeline
5
2
 
6
3
  Writing JavaScript templates for Backbone.js (or other frameworks) in your app?
7
4
  Would you like to use `haml` in the asset pipeline?
8
5
 
9
- This gem adds `haml` support to the Rails 3.1 asset pipeline. You will also
6
+ This gem adds `haml` support to the Rails 3.1+ asset pipeline. You will also
10
7
  need a gem that creates a compiled JavaScript template like `hogan_assets` or
11
8
  `handlebars_assets` as well.
12
9
 
@@ -16,9 +13,14 @@ Add this to your `Gemfile`
16
13
 
17
14
  gem 'haml_assets'
18
15
 
19
- # Using `haml` for your JavaScript templates
16
+ ### Upgrading from 0.0.x
17
+
18
+ `haml_assets` now works with the `haml` gem. Please update your gemfile to only
19
+ require `haml_assets.`.
20
20
 
21
- ## Templates directory
21
+ ## Writing your JavaScript templates
22
+
23
+ ### Templates directory
22
24
 
23
25
  You should located your templates under `app/assets`; we suggest
24
26
  `app/assets/templates`. In your JavaScript manifest file (for example
@@ -26,7 +28,7 @@ You should located your templates under `app/assets`; we suggest
26
28
 
27
29
  //= require_tree ../templates
28
30
 
29
- ## The template file
31
+ ### The template file
30
32
 
31
33
  Inside your templates directory, add your template file. The file should be
32
34
  named as follows
@@ -52,11 +54,19 @@ if you are writing an *edit* template, for example
52
54
  = f.label :name, "Name"
53
55
  = f.text_field :name, class: 'text required', autofocus: true, value: '{{name}}'
54
56
 
55
- # TODO
57
+ ## Rendering partials
58
+
59
+ You can render partials within your views. Because this is hacked in, you can
60
+ nest your partials as normal, but they must have a recognized format such as
61
+ `html`. For example
56
62
 
57
- Make `render` available, so you can render a partial.
63
+ shared/_timestamps.html.haml
58
64
 
59
- # Contributing
65
+ A partial will become a part of whatever template you are rendering, so make
66
+ sure that you are generating the correct markup. For example, do not include an
67
+ embedded coffeescript partial inside an embedded javascript template.
68
+
69
+ ## Contributing
60
70
 
61
71
  Once you've made your great commits:
62
72
 
@@ -66,7 +76,12 @@ Once you've made your great commits:
66
76
  1. Create a Pull Request from your branch
67
77
  1. That's it!
68
78
 
69
- # Authors
79
+ ## Authors
80
+
81
+ * Les Hill : @leshill
82
+ * Wes Gibbs : @wgibbs
83
+
84
+ ## Contributors
70
85
 
71
- Les Hill : @leshill
72
- Wes Gibbs : @wgibbs
86
+ * Eugene Pimenov (@libc) : Rendering partials
87
+ * Raphael Randschau (@nicolai86) : Render partials
@@ -7,8 +7,33 @@ module HamlAssets
7
7
  'application/javascript'
8
8
  end
9
9
 
10
+ class LookupContext < ActionView::LookupContext
11
+ def initialize(haml_context, path)
12
+ super(path)
13
+ @view_context = haml_context
14
+ end
15
+
16
+ def find_template(*args)
17
+ super.tap do |r|
18
+ @view_context.depend_on(r.identifier)
19
+ end
20
+ end
21
+ end
22
+
10
23
  module ViewContext
11
- attr_accessor :output_buffer
24
+ attr_accessor :output_buffer, :_view_renderer, :_lookup_context
25
+
26
+ def view_renderer
27
+ @_view_renderer ||= ActionView::Renderer.new(lookup_context)
28
+ end
29
+
30
+ def environment_paths
31
+ environment.paths.to_a
32
+ end
33
+
34
+ def lookup_context
35
+ @_lookup_context ||= LookupContext.new(self, environment_paths)
36
+ end
12
37
 
13
38
  def output_buffer_with_haml
14
39
  return haml_buffer.buffer if is_haml?
@@ -65,14 +90,10 @@ module HamlAssets
65
90
  Haml::Engine.new(data, Haml::Template.options.merge(:escape_attrs => false)).render(context, locals)
66
91
  end
67
92
 
68
- # The Sprockets context is shared among all the processors, give haml its
69
- # own context
70
93
  def view_context(scope)
71
- @view_context ||=
72
- context_class(scope).new(
73
- scope.environment,
74
- scope.logical_path.to_s,
75
- scope.pathname).tap { |ctx| ctx.class.send(:include, ViewContext) }
94
+ @view_context ||= scope.tap do |s|
95
+ s.singleton_class.instance_eval { include HamlAssets::HamlSprocketsEngine::ViewContext }
96
+ end
76
97
  end
77
98
  end
78
99
  end
@@ -1,3 +1,3 @@
1
1
  module HamlAssets
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -1,7 +1,32 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe HamlAssets do
4
+
4
5
  it "should have the proper format" do
5
6
  RailsApp::Application.assets['link_to.jst.ejs.haml'].to_s.should == "(function() {\n this.JST || (this.JST = {});\n this.JST[\"link_to\"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('');}return __p.join('');};\n}).call(this);\n"
6
7
  end
8
+
9
+ context 'rendering' do
10
+ let(:path) { 'app/assets/templates/quotes.haml' }
11
+
12
+ it "quoted attributes" do
13
+ template = HamlAssets::HamlSprocketsEngine.new(path) { %Q(%div{data:{bind:'attr: { "data-something": someValue }'}}) }
14
+ template.send(:render_haml, Object.new, {}).strip.should eq(%Q(<div data-bind='attr: { "data-something": someValue }'></div>))
15
+ end
16
+
17
+ it "renders with a partial" do
18
+ template = HamlAssets::HamlSprocketsEngine.new('app/assets/templates/with_partial.haml') { %Q(%div= render 'partial') }
19
+ partial = stub(identifier: 'identifier', render: 'partial')
20
+
21
+ HamlAssets::HamlSprocketsEngine::LookupContext.any_instance.should_receive(:find_template).and_return(partial)
22
+
23
+ context = Class.new do
24
+ include HamlAssets::HamlSprocketsEngine::ViewContext
25
+ end.new
26
+
27
+ context.stub(environment_paths: [])
28
+
29
+ template.send(:render_haml, context, {}).strip.should eq(%Q(<div>partial</div>))
30
+ end
31
+ end
7
32
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haml_assets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-03-16 00:00:00.000000000Z
13
+ date: 2012-10-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: haml
17
- requirement: &70119385661380 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,15 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70119385661380
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
26
31
  - !ruby/object:Gem::Dependency
27
32
  name: tilt
28
- requirement: &70119385660240 !ruby/object:Gem::Requirement
33
+ requirement: !ruby/object:Gem::Requirement
29
34
  none: false
30
35
  requirements:
31
36
  - - ! '>='
@@ -33,10 +38,15 @@ dependencies:
33
38
  version: '0'
34
39
  type: :runtime
35
40
  prerelease: false
36
- version_requirements: *70119385660240
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
37
47
  - !ruby/object:Gem::Dependency
38
48
  name: rails
39
- requirement: &70119385659620 !ruby/object:Gem::Requirement
49
+ requirement: !ruby/object:Gem::Requirement
40
50
  none: false
41
51
  requirements:
42
52
  - - ~>
@@ -44,10 +54,15 @@ dependencies:
44
54
  version: 3.1.0
45
55
  type: :development
46
56
  prerelease: false
47
- version_requirements: *70119385659620
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: 3.1.0
48
63
  - !ruby/object:Gem::Dependency
49
64
  name: rspec
50
- requirement: &70119385659040 !ruby/object:Gem::Requirement
65
+ requirement: !ruby/object:Gem::Requirement
51
66
  none: false
52
67
  requirements:
53
68
  - - ! '>='
@@ -55,10 +70,15 @@ dependencies:
55
70
  version: '0'
56
71
  type: :development
57
72
  prerelease: false
58
- version_requirements: *70119385659040
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
59
79
  - !ruby/object:Gem::Dependency
60
80
  name: rspec-rails
61
- requirement: &70119385658500 !ruby/object:Gem::Requirement
81
+ requirement: !ruby/object:Gem::Requirement
62
82
  none: false
63
83
  requirements:
64
84
  - - ! '>='
@@ -66,10 +86,15 @@ dependencies:
66
86
  version: '0'
67
87
  type: :development
68
88
  prerelease: false
69
- version_requirements: *70119385658500
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
70
95
  - !ruby/object:Gem::Dependency
71
96
  name: ejs
72
- requirement: &70119385657720 !ruby/object:Gem::Requirement
97
+ requirement: !ruby/object:Gem::Requirement
73
98
  none: false
74
99
  requirements:
75
100
  - - ! '>='
@@ -77,7 +102,12 @@ dependencies:
77
102
  version: '0'
78
103
  type: :development
79
104
  prerelease: false
80
- version_requirements: *70119385657720
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
81
111
  description: Use Haml with Rails helpers in the asset pipeline
82
112
  email:
83
113
  - les@infbio.com
@@ -89,8 +119,10 @@ files:
89
119
  - .gitignore
90
120
  - .rspec
91
121
  - .rvmrc
122
+ - CHANGELOG.md
92
123
  - Gemfile
93
124
  - Gemfile.lock
125
+ - LICENSE
94
126
  - README.md
95
127
  - Rakefile
96
128
  - haml_assets.gemspec
@@ -135,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
167
  version: '0'
136
168
  requirements: []
137
169
  rubyforge_project: haml_assets
138
- rubygems_version: 1.8.17
170
+ rubygems_version: 1.8.24
139
171
  signing_key:
140
172
  specification_version: 3
141
173
  summary: Use Haml with Rails helpers in the asset pipeline
@@ -157,4 +189,3 @@ test_files:
157
189
  - spec/rails_app/script/rails
158
190
  - spec/render_spec.rb
159
191
  - spec/spec_helper.rb
160
- has_rdoc: