haml_coffee_assets 0.7.1 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +64 -21
- data/lib/haml_coffee_assets/haml_coffee_template.rb +12 -1
- data/lib/haml_coffee_assets/version.rb +1 -1
- metadata +24 -24
data/README.md
CHANGED
@@ -49,15 +49,12 @@ And require the `hamlcoffee.js` in your `app/assets/javascripts/application.js.c
|
|
49
49
|
This provides the default escaping and the global context functions. Read more about it in the configuration section
|
50
50
|
below.
|
51
51
|
|
52
|
+
Please have a look at the [CHANGELOG](https://github.com/netzpirat/haml_coffee_assets/blob/master/CHANGELOG.md) when
|
53
|
+
upgrading to a newer Haml Coffee Assets version.
|
54
|
+
|
52
55
|
## Usage
|
53
56
|
|
54
|
-
|
55
|
-
your `app/assets/javascripts/application.js.coffee`:
|
56
|
-
|
57
|
-
```coffeescript
|
58
|
-
#= require_tree ../templates
|
59
|
-
```
|
60
|
-
Now you can start to add your Haml Coffee templates to your template directory.
|
57
|
+
Haml Coffee Assets allows two different ways of generating your JavaScript templates:
|
61
58
|
|
62
59
|
### Sprocket JST processor template generation
|
63
60
|
|
@@ -65,18 +62,43 @@ Now you can start to add your Haml Coffee templates to your template directory.
|
|
65
62
|
|
66
63
|
When you give your templates the extension `.jst.hamlc`, Haml Coffee Assets will only generate the template function,
|
67
64
|
which then in turn will be further processed by the
|
68
|
-
[Sprocket JST processor](https://github.com/sstephenson/sprockets/blob/master/lib/sprockets/jst_processor.rb).
|
69
|
-
|
65
|
+
[Sprocket JST processor](https://github.com/sstephenson/sprockets/blob/master/lib/sprockets/jst_processor.rb). Because
|
66
|
+
Haml Coffee Assets will not generate the template, you can't use the template name filter and the JST namespace
|
67
|
+
definition is more cumbersome compared to the Haml Coffee template generation.
|
68
|
+
|
69
|
+
With this approach you should place all your Haml Coffee templates in the `app/assets/templates` directory and include
|
70
|
+
all templates from your `app/assets/javascripts/application.js.coffee`:
|
71
|
+
|
72
|
+
```coffeescript
|
73
|
+
#= require_tree ../templates
|
74
|
+
```
|
75
|
+
|
76
|
+
If you would place your templates into `app/assets/javascripts/templates`, then all your JST template names would begin
|
77
|
+
with `templates/`, which may be not what you want.
|
70
78
|
|
71
79
|
### Haml Coffee template generation
|
72
80
|
|
73
81
|
* Extension: `.hamlc`
|
74
82
|
|
75
83
|
If you omit the `.jst` and give your templates only a `.hamlc` extension, then Haml Coffee Assets will handle the
|
76
|
-
JavaScript template generation. With this approach you can easily define your own namespace with a simple configuration
|
84
|
+
JavaScript template generation. With this approach you can easily define your own namespace with a simple configuration
|
85
|
+
and you can use the template name filter.
|
86
|
+
|
87
|
+
You can place all your Haml Coffee templates in the `app/assets/javascripts/templates` directory and include all
|
88
|
+
templates from your `app/assets/javascripts/application.js.coffee`:
|
89
|
+
|
90
|
+
```coffeescript
|
91
|
+
#= require_tree ./templates
|
92
|
+
```
|
93
|
+
|
94
|
+
Because Haml Coffee Assets provides a default template name filter, the `templates/` prefix will be automatically
|
95
|
+
removed.
|
77
96
|
|
78
97
|
## Configuration
|
79
98
|
|
99
|
+
_Please note that all configuration examples will use the paths of the Haml Coffee template generation and not the
|
100
|
+
Sprocket JST processor template generation._
|
101
|
+
|
80
102
|
### Document format
|
81
103
|
|
82
104
|
By default all Haml Coffee templates are rendered to a HTML5 document. You can choose between the following output
|
@@ -95,7 +117,7 @@ config.hamlcoffee.format = 'xhtml'
|
|
95
117
|
### Template namespace
|
96
118
|
|
97
119
|
By default all Haml Coffee templates are registered under the `JST` namespace. A template
|
98
|
-
`app/assets/templates/header.hamlc` with the given content:
|
120
|
+
`app/assets/javascripts/templates/header.hamlc` with the given content:
|
99
121
|
|
100
122
|
```haml
|
101
123
|
%header
|
@@ -133,17 +155,30 @@ Foo::Application.assets.register_engine '.jst', MyJstProcessor
|
|
133
155
|
|
134
156
|
And you must make sure `MyApp` exists before any template is loaded.
|
135
157
|
|
136
|
-
|
158
|
+
### Template name
|
137
159
|
|
138
160
|
The name under which the template can be addressed in the namespace depends not only from the filename, but also on
|
139
161
|
the directory name by default.
|
140
162
|
|
141
163
|
The following examples assumes a configured namespace `window.JST` and the asset template directory
|
142
|
-
`app/assets/templates`:
|
164
|
+
`app/assets/javascripts/templates`:
|
143
165
|
|
144
|
-
* `app/assets/templates/login.hamlc` will become `JST['login']`
|
145
|
-
* `app/assets/templates/users/new.hamlc` will become `JST['users/new']`
|
146
|
-
* `app/assets/templates/shared/form/address.hamlc` will become `JST['shared/form/address']`
|
166
|
+
* `app/assets/javascripts/templates/login.hamlc` will become `JST['login']`
|
167
|
+
* `app/assets/javascripts/templates/users/new.hamlc` will become `JST['users/new']`
|
168
|
+
* `app/assets/javascripts/templates/shared/form/address.hamlc` will become `JST['shared/form/address']`
|
169
|
+
|
170
|
+
#### Template name filter
|
171
|
+
|
172
|
+
If you wish to put the templates in a different location, you may want to modify `name_filter` in an initializer.
|
173
|
+
|
174
|
+
```ruby
|
175
|
+
HamlCoffeeAssets::HamlCoffeeTemplate.name_filter = lambda { |n| n.sub /^templates\//, '' }
|
176
|
+
```
|
177
|
+
|
178
|
+
By default, `name_filter` strips the leading `templates/` directory off of the name. Please note, `name_filter` is only
|
179
|
+
applicable if you use the `.hamlc` extension and let Haml Coffee Assets handle the JST generation. If you use the
|
180
|
+
`.jst.hamlc` extension, then Sprockets JST processor will name things accordingly (e.g., with `templates/` intact in
|
181
|
+
this case).
|
147
182
|
|
148
183
|
### Basename
|
149
184
|
|
@@ -157,9 +192,9 @@ config.hamlcoffee.basename = true
|
|
157
192
|
|
158
193
|
With this setting enabled the following naming rule applies:
|
159
194
|
|
160
|
-
* `app/assets/templates/login.hamlc` will become `JST['login']`
|
161
|
-
* `app/assets/templates/users/new.hamlc` will become `JST['new']`
|
162
|
-
* `app/assets/templates/shared/form/address.hamlc` will become `JST['address']`
|
195
|
+
* `app/assets/javascripts/templates/login.hamlc` will become `JST['login']`
|
196
|
+
* `app/assets/javascripts/templates/users/new.hamlc` will become `JST['new']`
|
197
|
+
* `app/assets/javascripts/templates/shared/form/address.hamlc` will become `JST['address']`
|
163
198
|
|
164
199
|
This setting has only an effect when you're using Haml Coffee to generate the JST and not when using the Sprockets
|
165
200
|
JST processor.
|
@@ -309,6 +344,13 @@ You can see the [default implementation](https://github.com/netzpirat/haml_coffe
|
|
309
344
|
and the [Haml Coffee documentation](https://github.com/9elements/haml-coffee#custom-helper-function-compiler-options)
|
310
345
|
for more information about each helper function.
|
311
346
|
|
347
|
+
## Shameless self promotion
|
348
|
+
|
349
|
+
Developed by Michael Kessler, sponsored by [mksoft.ch](https://mksoft.ch).
|
350
|
+
|
351
|
+
If you like Haml Coffee Assets, you can watch the repository at [GitHub](https://github.com/netzpirat/haml_coffee_assets) and
|
352
|
+
follow [@netzpirat](https://twitter.com/#!/netzpirat) on Twitter for project updates.
|
353
|
+
|
312
354
|
## Development
|
313
355
|
|
314
356
|
* Issues and feature request hosted at [GitHub Issues](https://github.com/netzpirat/haml_coffee_assets/issues).
|
@@ -321,14 +363,15 @@ Pull requests are very welcome! Please try to follow these simple rules if appli
|
|
321
363
|
* Make sure your patches are well tested. All specs must pass.
|
322
364
|
* Update the [Yard](http://yardoc.org/) documentation.
|
323
365
|
* Update the README.
|
366
|
+
* Update the CHANGELOG for noteworthy changes.
|
324
367
|
* Please **do not change** the version number.
|
325
368
|
|
326
369
|
For questions please join `#haml` on irc.freenode.net
|
327
370
|
|
328
371
|
## Contributors
|
329
372
|
|
330
|
-
|
331
|
-
|
373
|
+
See the [CHANGELOG](https://github.com/netzpirat/haml_coffee_assets/blob/master/CHANGELOG.md) and the GitHub list of
|
374
|
+
[contributors](https://github.com/netzpirat/haml_coffee_assets/contributors).
|
332
375
|
|
333
376
|
## Acknowledgement
|
334
377
|
|
@@ -7,7 +7,16 @@ module HamlCoffeeAssets
|
|
7
7
|
# Haml CoffeeScript template implementation for Tilt.
|
8
8
|
#
|
9
9
|
class HamlCoffeeTemplate < Tilt::Template
|
10
|
+
|
11
|
+
class << self
|
12
|
+
# A proc that is called to modify the template name used as the
|
13
|
+
# JST key. The proc is passed the name as an argument and should
|
14
|
+
# return the modified name (or unmodified) name.
|
15
|
+
attr_accessor :name_filter
|
16
|
+
end
|
10
17
|
|
18
|
+
# By default, remove any leading templates/ in the name
|
19
|
+
self.name_filter = lambda { |n| n.sub /^templates\//, '' }
|
11
20
|
self.default_mime_type = 'application/javascript'
|
12
21
|
|
13
22
|
# Test if the compiler is initialized.
|
@@ -33,7 +42,9 @@ module HamlCoffeeAssets
|
|
33
42
|
#
|
34
43
|
def evaluate(scope, locals = { }, &block)
|
35
44
|
jst = scope.pathname.to_s =~ /\.jst\.hamlc(?:\.|$)/ ? false : true
|
36
|
-
|
45
|
+
name = scope.logical_path
|
46
|
+
name = self.class.name_filter.call(name) if self.class.name_filter && jst
|
47
|
+
@output ||= HamlCoffee.compile(name, data, jst)
|
37
48
|
end
|
38
49
|
|
39
50
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: haml_coffee_assets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-01-
|
12
|
+
date: 2012-01-31 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: execjs
|
16
|
-
requirement: &
|
16
|
+
requirement: &70339113280060 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 1.2.9
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70339113280060
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: tilt
|
27
|
-
requirement: &
|
27
|
+
requirement: &70339113279600 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 1.3.3
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70339113279600
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: sprockets
|
38
|
-
requirement: &
|
38
|
+
requirement: &70339113279140 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 2.0.3
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70339113279140
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: bundler
|
49
|
-
requirement: &
|
49
|
+
requirement: &70339113278760 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70339113278760
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: railties
|
60
|
-
requirement: &
|
60
|
+
requirement: &70339113278220 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '3.1'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70339113278220
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
|
-
requirement: &
|
71
|
+
requirement: &70339113312080 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70339113312080
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: guard-rspec
|
82
|
-
requirement: &
|
82
|
+
requirement: &70339113311620 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70339113311620
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: yard
|
93
|
-
requirement: &
|
93
|
+
requirement: &70339113311200 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: '0'
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70339113311200
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: redcarpet
|
104
|
-
requirement: &
|
104
|
+
requirement: &70339113310780 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
@@ -109,10 +109,10 @@ dependencies:
|
|
109
109
|
version: '0'
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *70339113310780
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: pry
|
115
|
-
requirement: &
|
115
|
+
requirement: &70339113310360 !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|
118
118
|
- - ! '>='
|
@@ -120,10 +120,10 @@ dependencies:
|
|
120
120
|
version: '0'
|
121
121
|
type: :development
|
122
122
|
prerelease: false
|
123
|
-
version_requirements: *
|
123
|
+
version_requirements: *70339113310360
|
124
124
|
- !ruby/object:Gem::Dependency
|
125
125
|
name: rake
|
126
|
-
requirement: &
|
126
|
+
requirement: &70339113309940 !ruby/object:Gem::Requirement
|
127
127
|
none: false
|
128
128
|
requirements:
|
129
129
|
- - ! '>='
|
@@ -131,7 +131,7 @@ dependencies:
|
|
131
131
|
version: '0'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
|
-
version_requirements: *
|
134
|
+
version_requirements: *70339113309940
|
135
135
|
description: Compile Haml CoffeeScript templates in the Rails asset pipeline.
|
136
136
|
email:
|
137
137
|
- michi@netzpiraten.ch
|