handlebars-rails 0.3.2 → 0.4.2

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: 6d8995def3a47bca84c0742b7037243faba037bc
4
- data.tar.gz: fc4c39725c7427b0665c6655c36ccf4ee484bd59
3
+ metadata.gz: c0724fd16c6efec8f6270a5ba575c6397338cd8d
4
+ data.tar.gz: 60824dad6a58bdf4fa88a0c158808640b005dcec
5
5
  SHA512:
6
- metadata.gz: 84893458ce6576d3e747a178e54b90891c20b2109bbb7b1ee298391aa2e6a9b2edb1370198ac04c8d8fc1475edda23eb4aca37dd67e0d6c444ef5aa610815afc
7
- data.tar.gz: b39c8235f3953ab2b6985b337a744bc6cccffc02a4179b36787345343bb99af96791013998d4d019f8a41ff1f941bed817cd61e52ace91c2ceaed4a803573967
6
+ metadata.gz: 18f8a43d3feb53336faee5fc89c9faddbc0558325a45ab36c25d836ffc07f0e90e10f97aca982b208d0725fcda33153d5adbe2b11b70a2e9a4bc607681005677
7
+ data.tar.gz: fa47ee77b6941c79a8d11e736f40d01958dddd086291cea63ba7ed0ac9f19357ee2d02b54958a7c523bb9cd56e2873b48dd03785f2ff854987b10c1127dbc083
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  .bundle
2
- Gemfile.lock
2
+ Gemfile.lock
3
+ /pkg/*.gem
@@ -19,6 +19,7 @@ Gem::Specification.new do |gem|
19
19
  gem.specification_version = 2
20
20
  gem.add_runtime_dependency 'rails', '>= 3.0'
21
21
  gem.add_runtime_dependency 'handlebars', '~> 0.5.0'
22
+ gem.add_runtime_dependency 'barber', '~> 0.4.2'
22
23
 
23
24
  gem.add_development_dependency 'rake'
24
25
  gem.add_development_dependency 'redgreen', '~> 1.2'
@@ -1,4 +1,5 @@
1
1
  require 'tilt'
2
+ require 'barber'
2
3
 
3
4
  module Handlebars
4
5
  class Tilt < ::Tilt::Template
@@ -11,53 +12,12 @@ module Handlebars
11
12
  end
12
13
 
13
14
  def evaluate(scope, locals, &block)
14
- scope.extend Scope
15
- hbsc = Handlebars::TemplateHandler.handlebars.precompile data
16
- if scope.partial?
17
- <<-JS
18
- // generated by handlebars-rails #{Handlebars::Rails::VERSION}
19
- ;(function() {
20
- var template = Handlebars.template
21
- var fucknet = true
22
- Handlebars.registerPartial('#{scope.partial_name}', template(#{hbsc}));
23
- })()
24
- JS
25
- else
26
- <<-JS
27
- //generated by handlebars-rails #{Handlebars::Rails::VERSION}
28
- ;(function() {
29
- var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};
30
- #{scope.template_path}
31
- namespace['#{scope.template_name}'] = template(#{hbsc});
32
- })()
33
- JS
34
- end
35
- end
36
-
37
- module Scope
38
- def partial?
39
- File.basename(logical_path).start_with?('_')
40
- end
41
-
42
- def partial_name
43
- "#{File.dirname(logical_path)}/#{File.basename(logical_path, '.hbs').gsub(/^_/,'')}".gsub(/^\.+/,'')
44
- end
45
-
46
- def template_path
47
- branches = File.dirname(logical_path).split('/').reject{|p| p == '.'}
48
- <<-ASSIGN
49
- var branches = #{branches.inspect}
50
- var namespace = templates
51
- for (var path = branches.shift(); path; path = branches.shift()) {
52
- namespace[path] = namespace[path] || {}
53
- namespace = namespace[path]
54
- }
55
- ASSIGN
56
- end
57
-
58
- def template_name
59
- File.basename(logical_path, '.hbs')
60
- end
15
+ source = Barber::InlinePrecompiler.call data
16
+ is_partial = File.basename(scope.logical_path).start_with?('_')
17
+ template_name = scope.logical_path.sub(%r~^templates/~, "")
18
+ template_name.gsub!(%r~/_~, '/') if is_partial
19
+ target = is_partial ? "partials" : "templates"
20
+ "if (!Handlebars.templates) Handlebars.templates = {};Handlebars.#{target}['#{template_name}']=#{source}"
61
21
  end
62
22
  end
63
23
  end
@@ -1,5 +1,5 @@
1
1
  module Handlebars
2
2
  module Rails
3
- VERSION = "0.3.2"
3
+ VERSION = "0.4.2"
4
4
  end
5
5
  end
@@ -19,7 +19,7 @@ describe "sprockets integration" do
19
19
  @context.runtime.eval(source).call(@context.handlebars)
20
20
  end
21
21
  it 'precompiles templates' do
22
- @context.handlebars.templates['foobars']['whole'].call('thing' => 'enchilada').should match 'whole enchilada'
22
+ @context.handlebars.templates['foobars/whole'].call('thing' => 'enchilada').should match 'whole enchilada'
23
23
  end
24
24
  it 'precompiles partials' do
25
25
  @context.compile('{{>foobars/partial}}').call(:thing => 'enchilada').should match 'partial enchilada'
@@ -4,9 +4,9 @@ require 'spec_helper'
4
4
  describe Handlebars::TemplateHandler do
5
5
 
6
6
  before do
7
- @lookup_context = mock('ActionView::LookupContext', :prefixes => [:one])
7
+ @lookup_context = double('ActionView::LookupContext', :prefixes => [:one])
8
8
  @assigns = {:name => 'World'}
9
- @view = mock('ActionView::Base', :lookup_context => @lookup_context, :assigns => @assigns)
9
+ @view = double('ActionView::Base', :lookup_context => @lookup_context, :assigns => @assigns)
10
10
  end
11
11
 
12
12
  it 'should be able to render a basic HTML template' do
@@ -19,7 +19,7 @@ describe Handlebars::TemplateHandler do
19
19
 
20
20
  describe 'an embedded handlebars partial' do
21
21
  before do
22
- @lookup_context.stub(:find).with("to/hbs", [:one, ''], true) {mock(:source => "{{name}}", :handler => Handlebars::TemplateHandler)}
22
+ @lookup_context.stub(:find).with("to/hbs", [:one, ''], true) {double(:source => "{{name}}", :handler => Handlebars::TemplateHandler)}
23
23
  end
24
24
 
25
25
  it 'renders' do
@@ -29,7 +29,7 @@ describe Handlebars::TemplateHandler do
29
29
 
30
30
  describe 'an embedded erb partial' do
31
31
  before do
32
- @lookup_context.stub(:find).with("to/erb", [:one, ''], true) {mock(:source => "<%= @name %>", :handler => mock(:ERB))}
32
+ @lookup_context.stub(:find).with("to/erb", [:one, ''], true) {double(:source => "<%= @name %>", :handler => double(:ERB))}
33
33
  @view.stub(:render).with(hash_including(:partial => 'to/erb')) {|options| options[:locals][:name]}
34
34
  end
35
35
  it 'renders' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: handlebars-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - James A. Rosen
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-11-04 00:00:00.000000000 Z
13
+ date: 2013-11-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -40,6 +40,20 @@ dependencies:
40
40
  - - ~>
41
41
  - !ruby/object:Gem::Version
42
42
  version: 0.5.0
43
+ - !ruby/object:Gem::Dependency
44
+ name: barber
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ~>
48
+ - !ruby/object:Gem::Version
49
+ version: 0.4.2
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ version: 0.4.2
43
57
  - !ruby/object:Gem::Dependency
44
58
  name: rake
45
59
  requirement: !ruby/object:Gem::Requirement