hogan_assets 1.0.3 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +6 -5
- data/README.md +20 -5
- data/lib/hogan_assets.rb +3 -1
- data/lib/hogan_assets/config.rb +18 -7
- data/lib/hogan_assets/engine.rb +3 -1
- data/lib/hogan_assets/hogan.rb +1 -1
- data/lib/hogan_assets/tilt.rb +13 -1
- data/lib/hogan_assets/version.rb +1 -1
- data/test/hogan_assets/tilt_test.rb +2 -0
- metadata +24 -10
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
hogan_assets (1.0
|
4
|
+
hogan_assets (1.1.0)
|
5
5
|
execjs (>= 1.2.9)
|
6
6
|
sprockets (>= 2.0.3)
|
7
7
|
tilt (>= 1.3.3)
|
@@ -9,13 +9,14 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
execjs (1.
|
12
|
+
execjs (1.4.0)
|
13
13
|
multi_json (~> 1.0)
|
14
14
|
hike (1.2.1)
|
15
|
-
multi_json (1.
|
16
|
-
rack (1.
|
17
|
-
sprockets (2.
|
15
|
+
multi_json (1.3.5)
|
16
|
+
rack (1.4.1)
|
17
|
+
sprockets (2.4.3)
|
18
18
|
hike (~> 1.2)
|
19
|
+
multi_json (~> 1.0)
|
19
20
|
rack (~> 1.0)
|
20
21
|
tilt (~> 1.1, != 1.3.0)
|
21
22
|
tilt (1.3.3)
|
data/README.md
CHANGED
@@ -24,12 +24,12 @@ Require `hogan.js` somewhere in your JavaScript manifest, for example in `applic
|
|
24
24
|
|
25
25
|
//= require hogan.js
|
26
26
|
|
27
|
-
Locate your `.mustache` templates with your other JavaScript assets, usually in `app/assets/
|
27
|
+
Locate your `.mustache` templates with your other JavaScript assets, usually in `app/assets/javascripts/templates`.
|
28
28
|
Require your templates with `require_tree`:
|
29
29
|
|
30
|
-
//= require_tree templates
|
30
|
+
//= require_tree ./templates
|
31
31
|
|
32
|
-
Templates are named for the sub-path
|
32
|
+
Templates are named for the sub-path from your manifest with `require_tree`. For example, the file `app/assets/javascripts/templates/pages/person.mustache` will be named `templates/pages/person`. _(TODO: make this nicer)_
|
33
33
|
|
34
34
|
### Installation with sprockets
|
35
35
|
|
@@ -45,6 +45,20 @@ Require `hogan.js` somewhere in your JavaScript.
|
|
45
45
|
|
46
46
|
*TODO* Templates?
|
47
47
|
|
48
|
+
## Hamstache!
|
49
|
+
|
50
|
+
_hamstache_ is the quite popular combination of `haml` and `mustache`, a more robust solution exists using [haml_assets](https://github.com/infbio/haml_assets), but if all you want is nicer markup, you need to take these two steps:
|
51
|
+
|
52
|
+
Add this line to your `Gemfile`:
|
53
|
+
|
54
|
+
group :assets do
|
55
|
+
gem 'hogan_assets'
|
56
|
+
end
|
57
|
+
|
58
|
+
And then execute:
|
59
|
+
|
60
|
+
$ bundle
|
61
|
+
|
48
62
|
## Usage
|
49
63
|
|
50
64
|
Templates are compiled to a global JavaScript object named `HoganTemplates`. To render `pages/person`:
|
@@ -57,8 +71,9 @@ I made this because I <3 **mustache** and want to use it in Rails. Follow me on
|
|
57
71
|
|
58
72
|
# Contributors
|
59
73
|
|
60
|
-
* Matthew Nelson
|
61
|
-
* Jack Lawson
|
74
|
+
* @mdavidn (Matthew Nelson) : Remove unnecessary template source
|
75
|
+
* @ajacksified (Jack Lawson) : Configurable file extension
|
76
|
+
* @mikesmullin (Mike Smullin) : hamstache support
|
62
77
|
|
63
78
|
## Contributing
|
64
79
|
|
data/lib/hogan_assets.rb
CHANGED
@@ -11,6 +11,8 @@ module HoganAssets
|
|
11
11
|
require 'hogan_assets/engine'
|
12
12
|
else
|
13
13
|
require 'sprockets'
|
14
|
-
|
14
|
+
Config.template_extensions.each do |ext|
|
15
|
+
Sprockets.register_engine ".#{ext}", Tilt
|
16
|
+
end
|
15
17
|
end
|
16
18
|
end
|
data/lib/hogan_assets/config.rb
CHANGED
@@ -1,24 +1,35 @@
|
|
1
1
|
module HoganAssets
|
2
2
|
# Change config options in an initializer:
|
3
3
|
#
|
4
|
-
# HoganAssets.
|
4
|
+
# HoganAssets::Config.template_extensions = ['mustache']
|
5
5
|
#
|
6
6
|
# Or in a block:
|
7
7
|
#
|
8
|
-
# HoganAssets.configure do |config|
|
9
|
-
# config.
|
8
|
+
# HoganAssets::Config.configure do |config|
|
9
|
+
# config.template_extensions = ['mustache']
|
10
10
|
# end
|
11
11
|
|
12
12
|
module Config
|
13
|
-
|
13
|
+
extend self
|
14
14
|
|
15
15
|
def configure
|
16
16
|
yield self
|
17
17
|
end
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
attr_accessor :allow_hamstache
|
20
|
+
|
21
|
+
attr_writer :template_extensions
|
22
|
+
|
23
|
+
def template_extensions
|
24
|
+
@template_extensions ||= if haml_available?
|
25
|
+
['mustache', 'hamstache']
|
26
|
+
else
|
27
|
+
['mustache']
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def haml_available?
|
32
|
+
defined? ::Haml::Engine
|
21
33
|
end
|
22
34
|
end
|
23
35
|
end
|
24
|
-
|
data/lib/hogan_assets/engine.rb
CHANGED
@@ -2,7 +2,9 @@ module HoganAssets
|
|
2
2
|
class Engine < ::Rails::Engine
|
3
3
|
initializer "sprockets.hogan", :after => "sprockets.environment", :group => :all do |app|
|
4
4
|
next unless app.assets
|
5
|
-
|
5
|
+
HoganAssets::Config.template_extensions.each do |ext|
|
6
|
+
app.assets.register_engine(".#{ext}", Tilt)
|
7
|
+
end
|
6
8
|
end
|
7
9
|
end
|
8
10
|
end
|
data/lib/hogan_assets/hogan.rb
CHANGED
data/lib/hogan_assets/tilt.rb
CHANGED
@@ -4,8 +4,20 @@ module HoganAssets
|
|
4
4
|
class Tilt < Tilt::Template
|
5
5
|
self.default_mime_type = 'application/javascript'
|
6
6
|
|
7
|
+
def initialize_engine
|
8
|
+
require_template_library 'haml'
|
9
|
+
rescue LoadError
|
10
|
+
# haml not available
|
11
|
+
end
|
12
|
+
|
7
13
|
def evaluate(scope, locals, &block)
|
8
|
-
|
14
|
+
if scope.pathname.extname == '.hamstache'
|
15
|
+
raise "Unable to complile #{scope.pathname} because haml is not available. Did you add the haml gem?" unless HoganAssets::Config.haml_available?
|
16
|
+
compiled_template = Haml::Engine.new(data, @options).render
|
17
|
+
compiled_template = Hogan.compile(compiled_template)
|
18
|
+
else
|
19
|
+
compiled_template = Hogan.compile(data)
|
20
|
+
end
|
9
21
|
template_name = scope.logical_path.inspect
|
10
22
|
<<-TEMPLATE
|
11
23
|
this.HoganTemplates || (this.HoganTemplates = {});
|
data/lib/hogan_assets/version.rb
CHANGED
@@ -9,6 +9,8 @@ module HoganAssets
|
|
9
9
|
def test_render
|
10
10
|
scope = Class.new do
|
11
11
|
def logical_path ; 'path/to/template' ; end
|
12
|
+
|
13
|
+
def pathname ; Pathname.new logical_path ; end
|
12
14
|
end.new
|
13
15
|
|
14
16
|
template = HoganAssets::Tilt.new('/myapp/app/assets/templates/path/to/template.mustache') { "This is {{mustache}}" }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hogan_assets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.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-
|
12
|
+
date: 2012-05-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: execjs
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: 1.2.9
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.2.9
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: tilt
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,10 +37,15 @@ dependencies:
|
|
32
37
|
version: 1.3.3
|
33
38
|
type: :runtime
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.3.3
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: sprockets
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ! '>='
|
@@ -43,7 +53,12 @@ dependencies:
|
|
43
53
|
version: 2.0.3
|
44
54
|
type: :runtime
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.0.3
|
47
62
|
description: Use compiled hogan.js (mustache) JavaScript templates with sprockets
|
48
63
|
and the Rails asset pipeline.
|
49
64
|
email:
|
@@ -89,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
104
|
version: '0'
|
90
105
|
requirements: []
|
91
106
|
rubyforge_project:
|
92
|
-
rubygems_version: 1.8.
|
107
|
+
rubygems_version: 1.8.24
|
93
108
|
signing_key:
|
94
109
|
specification_version: 3
|
95
110
|
summary: Use compiled hogan.js (mustache) JavaScript templates with sprockets and
|
@@ -97,4 +112,3 @@ summary: Use compiled hogan.js (mustache) JavaScript templates with sprockets an
|
|
97
112
|
test_files:
|
98
113
|
- test/hogan_assets/tilt_test.rb
|
99
114
|
- test/test_helper.rb
|
100
|
-
has_rdoc:
|