hogan_assets 1.0.3 → 1.1.0

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.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hogan_assets (1.0.3)
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.2.13)
12
+ execjs (1.4.0)
13
13
  multi_json (~> 1.0)
14
14
  hike (1.2.1)
15
- multi_json (1.0.4)
16
- rack (1.3.5)
17
- sprockets (2.1.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/templates` or `app/assets/javascripts/templates`.
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 below `require_tree`. For example, the file `app/assets/javascripts/templates/pages/person.mustache` will be named `pages/person`.
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 (@mdavidn) : Remove unnecessary template source
61
- * Jack Lawson (@ajacksified) : Configurable file extension
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
- Sprockets.register_engine ".#{HoganAssets.template_extension}", Tilt
14
+ Config.template_extensions.each do |ext|
15
+ Sprockets.register_engine ".#{ext}", Tilt
16
+ end
15
17
  end
16
18
  end
@@ -1,24 +1,35 @@
1
1
  module HoganAssets
2
2
  # Change config options in an initializer:
3
3
  #
4
- # HoganAssets.template_extension = 'mustache'
4
+ # HoganAssets::Config.template_extensions = ['mustache']
5
5
  #
6
6
  # Or in a block:
7
7
  #
8
- # HoganAssets.configure do |config|
9
- # config.template_extension = 'mustache'
8
+ # HoganAssets::Config.configure do |config|
9
+ # config.template_extensions = ['mustache']
10
10
  # end
11
11
 
12
12
  module Config
13
- attr_accessor :template_base_path, :template_extension
13
+ extend self
14
14
 
15
15
  def configure
16
16
  yield self
17
17
  end
18
18
 
19
- def template_extension
20
- @template_extension ||= 'mustache'
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
-
@@ -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
- app.assets.register_engine(".#{HoganAssets.template_extension}", Tilt)
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
@@ -5,7 +5,7 @@ require 'pathname'
5
5
  module HoganAssets
6
6
  class Hogan
7
7
  class << self
8
- def compile(source)
8
+ def compile(source, options = {})
9
9
  context.eval("Hogan.compile(#{source.inspect}, {asString: true})")
10
10
  end
11
11
 
@@ -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
- compiled_template = Hogan.compile(data)
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 = {});
@@ -1,3 +1,3 @@
1
1
  module HoganAssets
2
- VERSION = "1.0.3"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -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.3
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-03-09 00:00:00.000000000Z
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: &70347106413740 !ruby/object:Gem::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: *70347106413740
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: &70347106413260 !ruby/object:Gem::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: *70347106413260
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: &70347106412800 !ruby/object:Gem::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: *70347106412800
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.17
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: