hamlbars 1.1.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +77 -97
- data/lib/hamlbars/ext/compiler.rb +4 -8
- data/lib/hamlbars/ext.rb +1 -3
- data/lib/hamlbars/template.rb +4 -93
- data/lib/hamlbars/version.rb +1 -1
- metadata +53 -45
- data/lib/hamlbars/ext/closure.rb +0 -43
- data/lib/hamlbars/ext/precompiler.rb +0 -71
data/README.md
CHANGED
@@ -12,80 +12,48 @@ you to easily generate [Handlebars](http://handlebarsjs.com) templates using
|
|
12
12
|
Add the following line to your Gemfile (on Rails, inside the `:assets` group):
|
13
13
|
|
14
14
|
```ruby
|
15
|
-
gem 'hamlbars', '~>
|
15
|
+
gem 'hamlbars', '~> 2.0'
|
16
16
|
```
|
17
17
|
|
18
|
-
|
19
|
-
update to 1.1, be sure to add `'~> 1.1'` as the version spec and run `bundle
|
20
|
-
install`.
|
18
|
+
# DEPRECATION WARNING
|
21
19
|
|
22
|
-
|
23
|
-
|
24
|
-
If you're unsure how all the pieces fit together then take a quick look at the
|
25
|
-
[demo site](http://hamlbars-demo.herokuapp.com/).
|
26
|
-
|
27
|
-
# Attribute bindings
|
28
|
-
|
29
|
-
You can easily add attribute bindings by adding a `:bind` hash to the tag
|
30
|
-
attributes, like so:
|
31
|
-
|
32
|
-
```haml
|
33
|
-
%div{ :class => 'widget', :bind => { :title => 'App.widgetController.title' }
|
34
|
-
```
|
20
|
+
As of version 2.0 Hamlbars simply outputs raw Handlebars templates, and you will need to
|
21
|
+
use the precompiler of your choice to compile the assets for your usage.
|
35
22
|
|
36
|
-
|
23
|
+
If you're using [Ember.js](http://emberjs.com) then you will need the
|
24
|
+
[ember-rails](http://rubygems.org/gems/ember-rails) gem. If you're just using
|
25
|
+
Handlebars templates on their own then you need to use
|
26
|
+
[handlebars_assets](http://rubygems.org/gems/handlebars_assets) to precompile
|
27
|
+
for your framework.
|
37
28
|
|
38
|
-
|
39
|
-
|
40
|
-
|
29
|
+
Be sure to take a look at Hamlbars' sister project
|
30
|
+
[FlavourSaver](http://rubygems.org/gems/flavour_saver) for pure-ruby server-side
|
31
|
+
rendering of Handlebars templates.
|
41
32
|
|
42
|
-
#
|
33
|
+
# Chaining compilation using the Rails asset pipeline
|
43
34
|
|
44
|
-
|
35
|
+
When using the `handlebars_assets` or `ember-rails` gems you need to add an
|
36
|
+
extra file extension so that the asset pipeline knows to take the output of
|
37
|
+
Hamlbars and send it into the template compiler of your choice. Luckily
|
38
|
+
both gems register the `hbs` extension, so you can enable asset compilation
|
39
|
+
by setting `.js.hbs.hamlbars` as the file extension for your templates.
|
45
40
|
|
46
|
-
|
47
|
-
%a{ :_action => 'toggle' } Toggle
|
48
|
-
%a{ :_action => 'edit article on="doubleClick"' } Edit
|
49
|
-
```
|
50
|
-
|
51
|
-
This will generate:
|
52
|
-
|
53
|
-
```html
|
54
|
-
<a {{action toggle}}>Toggle</a>
|
55
|
-
<a {{action edit article on="doubleClick"}}>Edit</a>
|
56
|
-
```
|
57
|
-
|
58
|
-
Note that `:_action` has a leading underscore, to distinguish it from regular
|
59
|
-
HTML attributes (`<form action="...">`).
|
60
|
-
|
61
|
-
# Event bindings (old syntax)
|
62
|
-
|
63
|
-
You can also add one or more event actions by adding an event hash or array of
|
64
|
-
event hashes to the tag options. This syntax is being deprecated in favor of
|
65
|
-
the newer `:_action` syntax described above.
|
66
|
-
|
67
|
-
```haml
|
68
|
-
%a{ :event => { :on => 'click', :action => 'clicked' } } Click
|
69
|
-
```
|
70
|
-
|
71
|
-
or
|
41
|
+
# Demo Site
|
72
42
|
|
73
|
-
|
74
|
-
|
75
|
-
```
|
43
|
+
If you're unsure how all the pieces fit together then take a quick look at the
|
44
|
+
[demo site](http://hamlbars-demo.herokuapp.com/).
|
76
45
|
|
77
|
-
|
46
|
+
# Handlebars extensions to Haml.
|
78
47
|
|
79
|
-
|
80
|
-
|
81
|
-
```
|
48
|
+
Hamlbars adds a couple of extensions to Haml in order to allow you to create
|
49
|
+
handlebars expressions in your templates.
|
82
50
|
|
83
|
-
|
51
|
+
## Handlebars helper
|
84
52
|
|
85
53
|
You can use the `handlebars` helper (or just `hb` for short) to generate both
|
86
54
|
Handlebars blocks and expressions.
|
87
55
|
|
88
|
-
|
56
|
+
### Expressions
|
89
57
|
|
90
58
|
Generating Handlebars expressions is as simple as using the `handlebars` helper
|
91
59
|
and providing the expression as a string argument:
|
@@ -100,7 +68,7 @@ which will will generate:
|
|
100
68
|
{{App.widgetController.title}}
|
101
69
|
```
|
102
70
|
|
103
|
-
|
71
|
+
### Blocks
|
104
72
|
|
105
73
|
Whereas passing a block to the `handlebars` helper will create a Handlebars
|
106
74
|
block expression:
|
@@ -124,7 +92,7 @@ will result in the following markup:
|
|
124
92
|
</ul>
|
125
93
|
```
|
126
94
|
|
127
|
-
|
95
|
+
### Options
|
128
96
|
|
129
97
|
The `hb` helper can take an optional hash of options which will be rendered
|
130
98
|
inside the expression:
|
@@ -139,68 +107,78 @@ will result in:
|
|
139
107
|
{{view App.InfoView tagName="span"}}
|
140
108
|
```
|
141
109
|
|
142
|
-
|
110
|
+
### Tripple-stash
|
143
111
|
|
144
112
|
You can use the `handlebars!` or `hb!` variant of the `handlebars` helper to
|
145
113
|
output "tripple-stash" expressions within which Handlebars does not escape the
|
146
114
|
output.
|
147
115
|
|
148
|
-
|
116
|
+
### In-tag expressions
|
149
117
|
|
150
|
-
|
151
|
-
|
118
|
+
Unfortunately, (or fortunately) due to the nature of Haml, we can't put Handlebars
|
119
|
+
expressions in a tag definition, eg:
|
152
120
|
|
153
|
-
```
|
154
|
-
|
155
|
-
|
156
|
-
|
121
|
+
```handlebars
|
122
|
+
<{{tagName}}>
|
123
|
+
My content
|
124
|
+
</{{tagName}}>
|
157
125
|
```
|
158
126
|
|
159
|
-
|
160
|
-
|
161
|
-
Handlebars within it then you'll have to change these.
|
162
|
-
|
163
|
-
If you're using [Ember.js](http://www.emberjs.com) then you can use:
|
127
|
+
But we can allow you to put Handlebars expressions in to generate tag arguments by
|
128
|
+
adding a special `hb` attribute to your tags. For example:
|
164
129
|
|
165
|
-
```
|
166
|
-
|
130
|
+
```haml
|
131
|
+
%div{:hb => 'idHelper'}
|
167
132
|
```
|
168
133
|
|
169
|
-
Which
|
134
|
+
Which would render the following:
|
170
135
|
|
171
|
-
```
|
172
|
-
|
173
|
-
Hamlbars::Template.template_compiler = 'Ember.Handlebars.compile'
|
174
|
-
Hamlbars::Template.template_partial_method = 'Ember.Handlebars.registerPartial'
|
136
|
+
```handlebars
|
137
|
+
<div {{idHelper}}></div>
|
175
138
|
```
|
176
139
|
|
177
|
-
|
178
|
-
|
179
|
-
automatically detect hamlbars and change it for you. Magic!
|
140
|
+
If you need to place more than one expression inside your tag then you can pass an array
|
141
|
+
of expressions.
|
180
142
|
|
181
|
-
|
182
|
-
need to put this in a initializer.
|
143
|
+
## Ember.js specific extensions
|
183
144
|
|
184
|
-
|
145
|
+
A large portion of the audience for Hamlbars is using it to generate templates for sites
|
146
|
+
using the Ember.js javascript framework. We have added some special extra syntax to
|
147
|
+
cater for Ember's common idioms.
|
185
148
|
|
186
|
-
|
187
|
-
[ExecJS](http://rubygems.org/gems/execjs). To enable it, call
|
149
|
+
### Attribute bindings
|
188
150
|
|
189
|
-
|
190
|
-
|
151
|
+
You can easily add attribute bindings by adding a `:bind` hash to the tag
|
152
|
+
attributes, like so:
|
153
|
+
|
154
|
+
```haml
|
155
|
+
%div{ :class => 'widget', :bind => { :title => 'App.widgetController.title' }
|
191
156
|
```
|
192
157
|
|
193
|
-
|
158
|
+
Which will generate the following output:
|
194
159
|
|
195
|
-
```
|
196
|
-
|
160
|
+
```handlebars
|
161
|
+
<div class="widget" {{bindAttr title="App.widgetController.title"}}></div>
|
197
162
|
```
|
198
163
|
|
199
|
-
|
164
|
+
### Action handlers
|
165
|
+
|
166
|
+
To use Ember's `{{action}}` helper, set the `:_action` attribute, like so:
|
167
|
+
|
168
|
+
```haml
|
169
|
+
%a{ :_action => 'toggle' } Toggle
|
170
|
+
%a{ :_action => 'edit article on="doubleClick"' } Edit
|
171
|
+
```
|
200
172
|
|
201
|
-
|
202
|
-
|
203
|
-
|
173
|
+
This will generate:
|
174
|
+
|
175
|
+
```html
|
176
|
+
<a {{action toggle}}>Toggle</a>
|
177
|
+
<a {{action edit article on="doubleClick"}}>Edit</a>
|
178
|
+
```
|
179
|
+
|
180
|
+
Note that `:_action` has a leading underscore, to distinguish it from regular
|
181
|
+
HTML attributes (`<form action="...">`).
|
204
182
|
|
205
183
|
# Rails helpers
|
206
184
|
|
@@ -209,6 +187,8 @@ Probably the best way to do this is to create an initializer. This is
|
|
209
187
|
dangerous and possibly stupid as a large number of Rails' helpers require
|
210
188
|
access to the request object, which is not present when compiling assets.
|
211
189
|
|
190
|
+
That said, it can be pretty handy to have access to the route helpers.
|
191
|
+
|
212
192
|
**Use at your own risk. You have been warned.**
|
213
193
|
|
214
194
|
# License and Copyright.
|
@@ -36,14 +36,10 @@ module Hamlbars
|
|
36
36
|
handlebars_rendered_attributes << Hamlbars::Ext::Compiler.handlebars_attributes('bindAttr', bind)
|
37
37
|
end
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
events.each do |event|
|
44
|
-
event[:on] = event.delete('on') || event.delete(:on) || 'click'
|
45
|
-
action = event.delete('action') || event.delete(:action)
|
46
|
-
handlebars_rendered_attributes << Hamlbars::Ext::Compiler.handlebars_attributes("action \"#{action}\"", event)
|
39
|
+
if hb = attributes.delete('hb')
|
40
|
+
(hb.respond_to?(:each) ? hb : [hb]).each do |expression|
|
41
|
+
handlebars_rendered_attributes << " {{#{expression}}}"
|
42
|
+
end
|
47
43
|
end
|
48
44
|
|
49
45
|
# This could be generalized into /_.*/ catch-all syntax, if
|
data/lib/hamlbars/ext.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
module Hamlbars
|
2
2
|
module Ext
|
3
|
-
autoload :Compiler,
|
4
|
-
autoload :Precompiler, File.expand_path('../ext/precompiler.rb', __FILE__)
|
5
|
-
autoload :Closure, File.expand_path('../ext/closure.rb', __FILE__)
|
3
|
+
autoload :Compiler, File.expand_path('../ext/compiler.rb', __FILE__)
|
6
4
|
autoload :RailsHelper, File.expand_path('../ext/rails_helper.rb', __FILE__)
|
7
5
|
end
|
8
6
|
end
|
data/lib/hamlbars/template.rb
CHANGED
@@ -2,74 +2,11 @@ require 'tilt/template'
|
|
2
2
|
|
3
3
|
module Hamlbars
|
4
4
|
class Template < Tilt::Template
|
5
|
-
include Ext::Closure
|
6
|
-
enable_closures! # Enable closures by default.
|
7
|
-
include Ext::Precompiler
|
8
5
|
if defined? Rails
|
9
6
|
include Ext::RailsHelper
|
10
|
-
enable_precompiler! if Rails.env.production?
|
11
7
|
end
|
12
8
|
|
13
|
-
|
14
|
-
"\r\n" => '\n',
|
15
|
-
"\n" => '\n',
|
16
|
-
"\r" => '\n',
|
17
|
-
'"' => '\\"',
|
18
|
-
"'" => "\\'"
|
19
|
-
}
|
20
|
-
|
21
|
-
# Used to change the asset path into a string which is
|
22
|
-
# safe to use as a JavaScript object property.
|
23
|
-
def self.path_translator(path)
|
24
|
-
path.downcase.gsub(/[^a-z0-9\/]/, '_')
|
25
|
-
end
|
26
|
-
|
27
|
-
# Handy helper to preconfigure Hamlbars to render for
|
28
|
-
# either :handlebars (default) or :ember.
|
29
|
-
def self.render_templates_for(whom=:handlebars)
|
30
|
-
if whom == :handlebars
|
31
|
-
self.template_destination = 'Handlebars.templates'
|
32
|
-
self.template_compiler = 'Handlebars.compile'
|
33
|
-
self.template_partial_method = 'Handlebars.registerPartial'
|
34
|
-
elsif whom == :ember
|
35
|
-
self.template_destination = 'Ember.TEMPLATES'
|
36
|
-
self.template_compiler = 'Ember.Handlebars.compile'
|
37
|
-
self.template_partial_method = 'Ember.Handlebars.registerPartial'
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
# The target object where the rendered template will
|
42
|
-
# be stored on the client side.
|
43
|
-
# Defaults to 'Handlebars.templates'
|
44
|
-
def self.template_destination
|
45
|
-
@template_destination ||= 'Handlebars.templates'
|
46
|
-
end
|
47
|
-
|
48
|
-
def self.template_destination=(x)
|
49
|
-
@template_destination = x
|
50
|
-
end
|
51
|
-
|
52
|
-
# The JavaScript function used to compile the HTML
|
53
|
-
# string into a usable Handlebars template.
|
54
|
-
def self.template_compiler
|
55
|
-
@template_compiler ||= 'Handlebars.compile'
|
56
|
-
end
|
57
|
-
|
58
|
-
def self.template_compiler=(x)
|
59
|
-
@template_compiler = x
|
60
|
-
end
|
61
|
-
|
62
|
-
# The JavaScript function used on the compile side to
|
63
|
-
# register the template as a partial on the client side.
|
64
|
-
def self.template_partial_method
|
65
|
-
@template_partial_method ||= 'Handlebars.registerPartial'
|
66
|
-
end
|
67
|
-
|
68
|
-
def self.template_partial_method=(x)
|
69
|
-
@template_partial_method = x
|
70
|
-
end
|
71
|
-
|
72
|
-
self.default_mime_type = 'application/javascript'
|
9
|
+
self.default_mime_type = 'text/x-handlebars'
|
73
10
|
|
74
11
|
def self.engine_initialized?
|
75
12
|
defined? ::Haml::Engine
|
@@ -87,41 +24,15 @@ module Hamlbars
|
|
87
24
|
# Uses Haml to render the template into an HTML string, then
|
88
25
|
# wraps it in the neccessary JavaScript to serve to the client.
|
89
26
|
def evaluate(scope, locals, &block)
|
90
|
-
|
91
|
-
|
92
|
-
else
|
93
|
-
@engine.render(scope, locals, &block)
|
94
|
-
end
|
95
|
-
|
96
|
-
if scope.respond_to? :logical_path
|
97
|
-
path = scope.logical_path
|
98
|
-
else
|
99
|
-
path = basename
|
100
|
-
end
|
101
|
-
|
102
|
-
if basename =~ /^_/
|
103
|
-
name = partial_path_translator(path)
|
104
|
-
"#{self.class.template_partial_method}('#{name}', '#{template.strip.gsub(/(\r\n|[\n\r"'])/) { JS_ESCAPE_MAP[$1] }}');\n"
|
27
|
+
if @engine.respond_to?(:precompiled_method_return_value, true)
|
28
|
+
super(scope, locals, &block)
|
105
29
|
else
|
106
|
-
|
107
|
-
"#{self.class.template_destination}[\"#{name}\"] = #{self.class.template_compiler}(\"#{template.strip.gsub(/(\r\n|[\n\r"'])/) { JS_ESCAPE_MAP[$1] }}\");\n"
|
30
|
+
@engine.render(scope, locals, &block)
|
108
31
|
end
|
109
32
|
end
|
110
33
|
|
111
|
-
# Used to change the asset path into a string which is
|
112
|
-
# safe to use as a JavaScript object property. When
|
113
|
-
# the template is a partial (ie starts with a '_')
|
114
|
-
def partial_path_translator(path)
|
115
|
-
path = remove_underscore_from_partial_path(path)
|
116
|
-
self.class.path_translator(path).gsub(%r{/}, '.')
|
117
|
-
end
|
118
|
-
|
119
34
|
private
|
120
35
|
|
121
|
-
def remove_underscore_from_partial_path(path)
|
122
|
-
path.sub(/(.*)(\/|^)_(.+?)$/, '\1\2\3')
|
123
|
-
end
|
124
|
-
|
125
36
|
# Precompiled Haml source. Taken from the precompiled_with_ambles
|
126
37
|
# method in Haml::Precompiler:
|
127
38
|
# http://github.com/nex3/haml/blob/master/lib/haml/precompiler.rb#L111-126
|
data/lib/hamlbars/version.rb
CHANGED
metadata
CHANGED
@@ -1,128 +1,128 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hamlbars
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.0
|
5
4
|
prerelease:
|
5
|
+
version: 2.0.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- James Harton
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-12-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
+
version_requirements: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
none: false
|
21
|
+
prerelease: false
|
15
22
|
name: haml
|
16
23
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
24
|
requirements:
|
19
25
|
- - ! '>='
|
20
26
|
- !ruby/object:Gem::Version
|
21
27
|
version: '0'
|
28
|
+
none: false
|
22
29
|
type: :runtime
|
23
|
-
|
30
|
+
- !ruby/object:Gem::Dependency
|
24
31
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
32
|
requirements:
|
27
33
|
- - ! '>='
|
28
34
|
- !ruby/object:Gem::Version
|
29
35
|
version: '0'
|
30
|
-
|
36
|
+
none: false
|
37
|
+
prerelease: false
|
31
38
|
name: sprockets
|
32
39
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
40
|
requirements:
|
35
41
|
- - ! '>='
|
36
42
|
- !ruby/object:Gem::Version
|
37
43
|
version: '0'
|
44
|
+
none: false
|
38
45
|
type: :runtime
|
39
|
-
|
46
|
+
- !ruby/object:Gem::Dependency
|
40
47
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
48
|
requirements:
|
43
49
|
- - ! '>='
|
44
50
|
- !ruby/object:Gem::Version
|
45
51
|
version: '0'
|
46
|
-
|
52
|
+
none: false
|
53
|
+
prerelease: false
|
47
54
|
name: tilt
|
48
55
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
56
|
requirements:
|
51
57
|
- - ! '>='
|
52
58
|
- !ruby/object:Gem::Version
|
53
59
|
version: '0'
|
60
|
+
none: false
|
54
61
|
type: :runtime
|
55
|
-
|
62
|
+
- !ruby/object:Gem::Dependency
|
56
63
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
64
|
requirements:
|
59
65
|
- - ! '>='
|
60
66
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
62
|
-
|
67
|
+
version: '1.2'
|
68
|
+
none: false
|
69
|
+
prerelease: false
|
63
70
|
name: execjs
|
64
71
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
72
|
requirements:
|
67
73
|
- - ! '>='
|
68
74
|
- !ruby/object:Gem::Version
|
69
75
|
version: '1.2'
|
76
|
+
none: false
|
70
77
|
type: :runtime
|
71
|
-
|
78
|
+
- !ruby/object:Gem::Dependency
|
72
79
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
80
|
requirements:
|
75
81
|
- - ! '>='
|
76
82
|
- !ruby/object:Gem::Version
|
77
|
-
version: '
|
78
|
-
|
83
|
+
version: '0'
|
84
|
+
none: false
|
85
|
+
prerelease: false
|
79
86
|
name: rake
|
80
87
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
88
|
requirements:
|
83
89
|
- - ! '>='
|
84
90
|
- !ruby/object:Gem::Version
|
85
91
|
version: '0'
|
92
|
+
none: false
|
86
93
|
type: :development
|
87
|
-
|
94
|
+
- !ruby/object:Gem::Dependency
|
88
95
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
96
|
requirements:
|
91
97
|
- - ! '>='
|
92
98
|
- !ruby/object:Gem::Version
|
93
|
-
version:
|
94
|
-
|
99
|
+
version: 2.10.0
|
100
|
+
none: false
|
101
|
+
prerelease: false
|
95
102
|
name: rspec
|
96
103
|
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
104
|
requirements:
|
99
105
|
- - ! '>='
|
100
106
|
- !ruby/object:Gem::Version
|
101
107
|
version: 2.10.0
|
108
|
+
none: false
|
102
109
|
type: :development
|
103
|
-
|
110
|
+
- !ruby/object:Gem::Dependency
|
104
111
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
112
|
requirements:
|
107
113
|
- - ! '>='
|
108
114
|
- !ruby/object:Gem::Version
|
109
|
-
version:
|
110
|
-
|
115
|
+
version: '0'
|
116
|
+
none: false
|
117
|
+
prerelease: false
|
111
118
|
name: activesupport
|
112
119
|
requirement: !ruby/object:Gem::Requirement
|
113
|
-
none: false
|
114
120
|
requirements:
|
115
121
|
- - ! '>='
|
116
122
|
- !ruby/object:Gem::Version
|
117
123
|
version: '0'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
124
|
none: false
|
122
|
-
|
123
|
-
- - ! '>='
|
124
|
-
- !ruby/object:Gem::Version
|
125
|
-
version: '0'
|
125
|
+
type: :development
|
126
126
|
description: Hamlbars allows you to write handlebars templates using the familiar
|
127
127
|
Haml syntax.
|
128
128
|
email:
|
@@ -134,9 +134,7 @@ files:
|
|
134
134
|
- README.md
|
135
135
|
- History.md
|
136
136
|
- MIT-LICENSE
|
137
|
-
- lib/hamlbars/ext/closure.rb
|
138
137
|
- lib/hamlbars/ext/compiler.rb
|
139
|
-
- lib/hamlbars/ext/precompiler.rb
|
140
138
|
- lib/hamlbars/ext/rails_helper.rb
|
141
139
|
- lib/hamlbars/ext.rb
|
142
140
|
- lib/hamlbars/template.rb
|
@@ -146,28 +144,38 @@ files:
|
|
146
144
|
- vendor/javascripts/precompiler.js
|
147
145
|
homepage: https://github.com/jamesotron/hamlbars
|
148
146
|
licenses: []
|
149
|
-
post_install_message:
|
147
|
+
post_install_message: ! " DEPRECATION WARNING: Hamlbars 2.0 removes asset compilation!\n\n
|
148
|
+
\ Template compilation in Hamlbars was a major source of confusion and bugs\n since
|
149
|
+
roughly half of its users are using Handlebars.js in their apps and\n the other
|
150
|
+
half are using Handlebars as part of Ember.js.\n\n Hamlbars now simply outputs
|
151
|
+
the rendered HTML marked up with Handlebars\n sections. It is up to you to choose
|
152
|
+
the Handlebars compiler that works\n for you.\n\n If you're using Ember.js I would
|
153
|
+
suggest adding ember-rails to your\n Gemfile.\n\n If you're using Handlebars.js
|
154
|
+
then I would suggest adding handlebars_assets\n to your Gemfile.\n\n For both
|
155
|
+
of the above gems you may need to rename your templates to\n `mytemplate.js.hbs.hamlbars`
|
156
|
+
in order for the output of Hamlbars to be sent\n into the correct compiler.\n\n
|
157
|
+
\ Thanks for using Hamlbars. You're awesome.\n @jamesotron\n"
|
150
158
|
rdoc_options: []
|
151
159
|
require_paths:
|
152
160
|
- lib
|
153
161
|
required_ruby_version: !ruby/object:Gem::Requirement
|
154
|
-
none: false
|
155
162
|
requirements:
|
156
163
|
- - ! '>='
|
157
164
|
- !ruby/object:Gem::Version
|
158
165
|
version: '0'
|
159
166
|
segments:
|
160
167
|
- 0
|
161
|
-
hash:
|
162
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
168
|
+
hash: 2248097403162291800
|
163
169
|
none: false
|
170
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
164
171
|
requirements:
|
165
172
|
- - ! '>='
|
166
173
|
- !ruby/object:Gem::Version
|
167
174
|
version: '0'
|
168
175
|
segments:
|
169
176
|
- 0
|
170
|
-
hash:
|
177
|
+
hash: 2248097403162291800
|
178
|
+
none: false
|
171
179
|
requirements: []
|
172
180
|
rubyforge_project:
|
173
181
|
rubygems_version: 1.8.24
|
data/lib/hamlbars/ext/closure.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
module Hamlbars
|
2
|
-
module Ext
|
3
|
-
module Closure
|
4
|
-
|
5
|
-
def self.included(base)
|
6
|
-
base.extend ClassMethods
|
7
|
-
end
|
8
|
-
|
9
|
-
# Wraps the JavaScript generated by Haml::Template#evaluate
|
10
|
-
# in a JavaScript closure.
|
11
|
-
def evaluate_with_closure(scope, locals, &block)
|
12
|
-
self.class.closures_enabled? ? enclosify { evaluate_without_closure(scope,locals,&block) } : evaluate_without_closure(scope,locals,&block)
|
13
|
-
end
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
def enclosify
|
18
|
-
"(function() { #{yield} }).call(this)"
|
19
|
-
end
|
20
|
-
|
21
|
-
module ClassMethods
|
22
|
-
# Enables closure wrapping for rendered templates.
|
23
|
-
def enable_closures!
|
24
|
-
@enable_closures = true
|
25
|
-
unless public_method_defined? :evaluate_without_closure
|
26
|
-
alias_method :evaluate_without_closure, :evaluate
|
27
|
-
alias_method :evaluate, :evaluate_with_closure
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def closures_enabled?
|
32
|
-
!!@enable_closures
|
33
|
-
end
|
34
|
-
|
35
|
-
# Disables closure wrapping for rendered templates.
|
36
|
-
def disable_closures!
|
37
|
-
@enable_closures = false
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,71 +0,0 @@
|
|
1
|
-
require 'execjs'
|
2
|
-
|
3
|
-
module Hamlbars
|
4
|
-
module Ext
|
5
|
-
module Precompiler
|
6
|
-
|
7
|
-
def self.included(base)
|
8
|
-
base.extend ClassMethods
|
9
|
-
end
|
10
|
-
|
11
|
-
# Takes the rendered template and compiles it using the Handlebars
|
12
|
-
# compiler via ExecJS.
|
13
|
-
def evaluate_with_precompiler(scope, locals, &block)
|
14
|
-
if self.class.precompiler_enabled?
|
15
|
-
precompile { evaluate_without_precompiler(scope,locals,&block) }
|
16
|
-
else
|
17
|
-
evaluate_without_precompiler(scope,locals,&block)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
def precompile
|
24
|
-
str = yield
|
25
|
-
str.gsub(Regexp.new("(#{Hamlbars::Template.template_compiler})\((.+)\)")) do |match|
|
26
|
-
# No named groups. WAT!
|
27
|
-
compiler = $1
|
28
|
-
template = $2
|
29
|
-
if compiler =~ /\.compile$/
|
30
|
-
"#{compiler.gsub(/\.compile$/, '.template')}(#{runtime.call('Hamlbars.precompile', template)})"
|
31
|
-
else
|
32
|
-
# Unable to precompile.
|
33
|
-
match
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def runtime
|
39
|
-
Thread.current[:hamlbars_js_runtime] ||= ExecJS.compile(js)
|
40
|
-
end
|
41
|
-
|
42
|
-
def js
|
43
|
-
[ 'handlebars.js', 'precompiler.js' ].map do |name|
|
44
|
-
File.read(File.expand_path("../../../../vendor/javascripts/#{name}", __FILE__))
|
45
|
-
end.join("\n")
|
46
|
-
end
|
47
|
-
|
48
|
-
module ClassMethods
|
49
|
-
|
50
|
-
# Enables use of the Handlebars compiler when rendering
|
51
|
-
# templates.
|
52
|
-
def enable_precompiler!
|
53
|
-
@precompiler_enabled = true
|
54
|
-
unless public_method_defined? :evaluate_without_precompiler
|
55
|
-
alias_method :evaluate_without_precompiler, :evaluate
|
56
|
-
alias_method :evaluate, :evaluate_with_precompiler
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def precompiler_enabled?
|
61
|
-
!!@precompiler_enabled
|
62
|
-
end
|
63
|
-
|
64
|
-
def disable_precompiler!
|
65
|
-
@precompiler_enabled = false
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|