handlebars-rails 0.3.2 → 0.4.2
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.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/handlebars-rails.gemspec +1 -0
- data/lib/handlebars-rails/tilt.rb +7 -47
- data/lib/handlebars-rails/version.rb +1 -1
- data/spec/precompile_spec.rb +1 -1
- data/spec/render_spec.rb +4 -4
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0724fd16c6efec8f6270a5ba575c6397338cd8d
|
4
|
+
data.tar.gz: 60824dad6a58bdf4fa88a0c158808640b005dcec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18f8a43d3feb53336faee5fc89c9faddbc0558325a45ab36c25d836ffc07f0e90e10f97aca982b208d0725fcda33153d5adbe2b11b70a2e9a4bc607681005677
|
7
|
+
data.tar.gz: fa47ee77b6941c79a8d11e736f40d01958dddd086291cea63ba7ed0ac9f19357ee2d02b54958a7c523bb9cd56e2873b48dd03785f2ff854987b10c1127dbc083
|
data/.gitignore
CHANGED
data/handlebars-rails.gemspec
CHANGED
@@ -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
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
data/spec/precompile_spec.rb
CHANGED
@@ -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
|
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'
|
data/spec/render_spec.rb
CHANGED
@@ -4,9 +4,9 @@ require 'spec_helper'
|
|
4
4
|
describe Handlebars::TemplateHandler do
|
5
5
|
|
6
6
|
before do
|
7
|
-
@lookup_context =
|
7
|
+
@lookup_context = double('ActionView::LookupContext', :prefixes => [:one])
|
8
8
|
@assigns = {:name => 'World'}
|
9
|
-
@view =
|
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) {
|
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) {
|
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.
|
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-
|
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
|