hogan_assets 1.4.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,7 @@
1
+ ## 1.5.0 (2013-2-06)
2
+
3
+ * YAML configuration support - @apai4
4
+
1
5
  ## 1.4.0 (2013-1-02)
2
6
 
3
7
  * **slimstache** support, use `HoganAssets::Config.slim_options` to set options for `slim` - @sars
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hogan_assets (1.4.0)
4
+ hogan_assets (1.5.0)
5
5
  execjs (>= 1.2.9)
6
6
  sprockets (>= 2.0.3)
7
7
  tilt (>= 1.3.3)
@@ -9,6 +9,14 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
+ columnize (0.3.6)
13
+ debugger (1.3.0)
14
+ columnize (>= 0.3.1)
15
+ debugger-linecache (~> 1.1.1)
16
+ debugger-ruby_core_source (~> 1.1.7)
17
+ debugger-linecache (1.1.2)
18
+ debugger-ruby_core_source (>= 1.1.1)
19
+ debugger-ruby_core_source (1.1.7)
12
20
  execjs (1.4.0)
13
21
  multi_json (~> 1.0)
14
22
  haml (3.1.6)
@@ -30,6 +38,7 @@ PLATFORMS
30
38
  ruby
31
39
 
32
40
  DEPENDENCIES
41
+ debugger
33
42
  haml
34
43
  hogan_assets!
35
44
  slim
data/README.md CHANGED
@@ -69,6 +69,8 @@ _slimstache_ is the also popular combination of `slim` and `mustache`. Works jus
69
69
 
70
70
  ## Configuration
71
71
 
72
+ You can configure options using either an intializer or with a YAML file (`config/hogan_assets.yml`). See `lib/hogan_assets/config.rb` for details.
73
+
72
74
  ### Lambda Support
73
75
 
74
76
  **mustache** lambdas are off by default. (Not sure what that is? Read the [mustache](http://mustache.github.com/mustache.5.html) man page!) If you want them on, set the `lambda_support` option to true. This will include the raw template text as part of the compiled template; each template will be correspondingly larger. *TODO* Should this be on by default?
@@ -113,6 +115,7 @@ By default, templates are recognized if they have an extension of `.mustache` (a
113
115
  config.template_extensions = %w(mustache hamstache stache)
114
116
  end
115
117
 
118
+
116
119
  ## Usage
117
120
 
118
121
  Templates are compiled to a global JavaScript object named `HoganTemplates`. To render `pages/person`:
@@ -133,6 +136,7 @@ I made this because I <3 **mustache** and want to use it in Rails. Follow me on
133
136
  * @adamstrickland (Adam Strickland) : Custom template namespace
134
137
  * @lautis (Ville Lautanala) : haml_options configuration
135
138
  * @sars (Rodion) : slimstache support
139
+ * @apai4 : YAML configuration
136
140
 
137
141
  ## Contributing
138
142
 
@@ -19,6 +19,7 @@ Gem::Specification.new do |gem|
19
19
  gem.add_runtime_dependency "tilt", ">= 1.3.3"
20
20
  gem.add_runtime_dependency "sprockets", ">= 2.0.3"
21
21
 
22
+ gem.add_development_dependency "debugger"
22
23
  gem.add_development_dependency "haml"
23
24
  gem.add_development_dependency "slim"
24
25
  end
@@ -4,13 +4,14 @@ require 'hogan_assets/config'
4
4
  module HoganAssets
5
5
  extend Config
6
6
 
7
- autoload(:Hogan, 'hogan_assets/hogan')
8
- autoload(:Tilt, 'hogan_assets/tilt')
7
+ autoload :Hogan, 'hogan_assets/hogan'
8
+ autoload :Tilt, 'hogan_assets/tilt'
9
9
 
10
- if defined?(Rails)
10
+ if defined? Rails
11
11
  require 'hogan_assets/engine'
12
12
  else
13
13
  require 'sprockets'
14
+ Config.load_yml! if Config.yml_exists?
14
15
  Config.template_extensions.each do |ext|
15
16
  Sprockets.register_engine ".#{ext}", Tilt
16
17
  end
@@ -1,3 +1,5 @@
1
+ require 'yaml'
2
+
1
3
  module HoganAssets
2
4
  # Change config options in an initializer:
3
5
  #
@@ -13,31 +15,80 @@ module HoganAssets
13
15
  # config.slim_options[:pretty] = false
14
16
  # end
15
17
  #
18
+ # Or change config options in a YAML file (config/hogan_assets.yml):
19
+ #
20
+ # defaults: &defaults
21
+ # lambda_support: false
22
+ # path_prefix: 'templates'
23
+ # template_extensions:
24
+ # - 'hamstache'
25
+ # - 'slimstache'
26
+ # template_namespace: 'JST'
27
+ # haml_options:
28
+ # ugly: true
29
+ # slim_options:
30
+ # pretty: false
31
+ # development:
32
+ # <<: *defaults
33
+ # test:
34
+ # <<: *defaults
35
+ # production:
36
+ # <<: *defaults
37
+ #
16
38
  module Config
17
39
  extend self
18
40
 
19
- attr_writer :lambda_support, :path_prefix, :template_extensions, :template_namespace, :haml_options, :slim_options
41
+ attr_writer :env, :lambda_support, :path_prefix, :template_extensions, :template_namespace, :haml_options, :slim_options
20
42
 
21
43
  def configure
22
44
  yield self
23
45
  end
24
46
 
47
+ def env
48
+ @env ||= if defined? Rails
49
+ Rails.env
50
+ elsif ENV['RACK_ENV']
51
+ ENV['RACK_ENV']
52
+ else
53
+ 'development'
54
+ end
55
+ end
56
+
25
57
  def haml_available?
26
58
  defined? ::Haml::Engine
27
59
  end
28
60
 
29
- def slim_available?
30
- defined? ::Slim::Engine
61
+ def haml_options
62
+ @haml_options ||= {}
31
63
  end
32
64
 
33
65
  def lambda_support?
34
66
  @lambda_support
35
67
  end
36
68
 
69
+ def load_yml!
70
+ @lambda_support = yml['lambda_support'] if yml.has_key? 'lambda_support'
71
+ @path_prefix = yml['path_prefix'] if yml.has_key? 'path_prefix'
72
+ @template_extensions = yml['template_extensions'] if yml.has_key? 'template_extensions'
73
+ @template_namespace = yml['template_namespace'] if yml.has_key? 'template_namespace'
74
+ @haml_options = yml['haml_options'] if yml.has_key? 'haml_options'
75
+ @slim_options = yml['slim_options'] if yml.has_key? 'slim_options'
76
+ symbolize(@haml_options) if @haml_options
77
+ symbolize(@slim_options) if @slim_options
78
+ end
79
+
37
80
  def path_prefix
38
81
  @path_prefix ||= 'templates'
39
82
  end
40
83
 
84
+ def slim_available?
85
+ defined? ::Slim::Engine
86
+ end
87
+
88
+ def slim_options
89
+ @slim_options ||= {}
90
+ end
91
+
41
92
  def template_namespace
42
93
  @template_namespace ||= 'HoganTemplates'
43
94
  end
@@ -46,12 +97,32 @@ module HoganAssets
46
97
  @template_extensions ||= "mustache#{' hamstache' if haml_available?}#{' slimstache' if slim_available?}".split
47
98
  end
48
99
 
49
- def haml_options
50
- @haml_options ||= {}
100
+ def yml
101
+ begin
102
+ @yml ||= (YAML.load(IO.read yml_path)[env] rescue nil) || {}
103
+ rescue Psych::SyntaxError
104
+ @yml = {}
105
+ end
51
106
  end
52
107
 
53
- def slim_options
54
- @slim_options ||= {}
108
+ def yml_exists?
109
+ File.exists? yml_path
110
+ end
111
+
112
+ private
113
+
114
+ def symbolize(hash)
115
+ hash.keys.each do |key|
116
+ hash[(key.to_sym rescue key) || key] = hash.delete(key)
117
+ end
118
+ end
119
+
120
+ def yml_path
121
+ @yml_path ||= if defined? Rails
122
+ Rails.root.join 'config', 'hogan_assets.yml'
123
+ else
124
+ Pathname.new('.') + 'config/hogan_assets.yml'
125
+ end
55
126
  end
56
127
  end
57
128
  end
@@ -2,6 +2,7 @@ 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
+ HoganAssets::Config.load_yml! if HoganAssets::Config.yml_exists?
5
6
  HoganAssets::Config.template_extensions.each do |ext|
6
7
  app.assets.register_engine(".#{ext}", Tilt)
7
8
  end
@@ -1,3 +1,3 @@
1
1
  module HoganAssets
2
- VERSION = "1.4.0"
2
+ VERSION = "1.5.0"
3
3
  end
@@ -0,0 +1,5 @@
1
+ test:
2
+ template_extensions:
3
+ - 'custom'
4
+ haml_options:
5
+ ugly: true
@@ -0,0 +1,35 @@
1
+ require 'test_helper'
2
+
3
+ module HoganAssets
4
+ module Config
5
+ extend self
6
+
7
+ def yml_path=(yml_path)
8
+ @yml_path = yml_path
9
+ end
10
+ end
11
+
12
+ class ConfigTest < Test::Unit::TestCase
13
+ include TestSupport
14
+
15
+ def setup
16
+ HoganAssets::Config.env = 'test'
17
+ HoganAssets::Config.yml_path = Pathname.new('.') + 'test/config/hogan_assets.yml'
18
+ HoganAssets::Config.load_yml!
19
+ end
20
+
21
+ def teardown
22
+ HoganAssets::Config.env = nil
23
+ HoganAssets::Config.haml_options = nil
24
+ HoganAssets::Config.template_extensions = nil
25
+ HoganAssets::Config.yml_path = nil
26
+ end
27
+
28
+ def test_yaml_options
29
+ scope = make_scope '/myapp/app/assets/javascripts', 'path/to/template.custom'
30
+ template = HoganAssets::Tilt.new(scope.s_path) { "This is {{mustache}}" }
31
+ assert_match /This is/, template.render(scope, {})
32
+ assert_equal HoganAssets::Config.haml_options, ugly: true
33
+ end
34
+ end
35
+ end
@@ -2,18 +2,7 @@ require 'test_helper'
2
2
 
3
3
  module HoganAssets
4
4
  class TiltTest < Test::Unit::TestCase
5
- # Try to act like sprockets.
6
- def make_scope(root, file)
7
- Class.new do
8
- define_method(:logical_path) { pathname.to_s.gsub(root + '/', '').gsub(/\..*/, '') }
9
-
10
- define_method(:pathname) { Pathname.new(root) + file }
11
-
12
- define_method(:root_path) { root }
13
-
14
- define_method(:s_path) { pathname.to_s }
15
- end.new
16
- end
5
+ include TestSupport
17
6
 
18
7
  def teardown
19
8
  HoganAssets::Config.lambda_support = false
@@ -1,5 +1,18 @@
1
- require 'hogan_assets/tilt'
2
- require 'hogan_assets/hogan'
3
- require 'hogan_assets/config'
1
+ require 'hogan_assets'
4
2
 
5
3
  require 'test/unit'
4
+
5
+ module TestSupport
6
+ # Try to act like sprockets.
7
+ def make_scope(root, file)
8
+ Class.new do
9
+ define_method(:logical_path) { pathname.to_s.gsub(root + '/', '').gsub(/\..*/, '') }
10
+
11
+ define_method(:pathname) { Pathname.new(root) + file }
12
+
13
+ define_method(:root_path) { root }
14
+
15
+ define_method(:s_path) { pathname.to_s }
16
+ end.new
17
+ end
18
+ end
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.4.0
4
+ version: 1.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,88 +9,104 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-03 00:00:00.000000000 Z
12
+ date: 2013-02-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: execjs
16
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
17
18
  requirements:
18
19
  - - ! '>='
19
20
  - !ruby/object:Gem::Version
20
21
  version: 1.2.9
21
- none: false
22
- prerelease: false
23
22
  type: :runtime
23
+ prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
25
26
  requirements:
26
27
  - - ! '>='
27
28
  - !ruby/object:Gem::Version
28
29
  version: 1.2.9
29
- none: false
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: tilt
32
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
33
34
  requirements:
34
35
  - - ! '>='
35
36
  - !ruby/object:Gem::Version
36
37
  version: 1.3.3
37
- none: false
38
- prerelease: false
39
38
  type: :runtime
39
+ prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
41
42
  requirements:
42
43
  - - ! '>='
43
44
  - !ruby/object:Gem::Version
44
45
  version: 1.3.3
45
- none: false
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: sprockets
48
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
49
50
  requirements:
50
51
  - - ! '>='
51
52
  - !ruby/object:Gem::Version
52
53
  version: 2.0.3
53
- none: false
54
- prerelease: false
55
54
  type: :runtime
55
+ prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
57
58
  requirements:
58
59
  - - ! '>='
59
60
  - !ruby/object:Gem::Version
60
61
  version: 2.0.3
62
+ - !ruby/object:Gem::Dependency
63
+ name: debugger
64
+ requirement: !ruby/object:Gem::Requirement
61
65
  none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
62
78
  - !ruby/object:Gem::Dependency
63
79
  name: haml
64
80
  requirement: !ruby/object:Gem::Requirement
81
+ none: false
65
82
  requirements:
66
83
  - - ! '>='
67
84
  - !ruby/object:Gem::Version
68
85
  version: '0'
69
- none: false
70
- prerelease: false
71
86
  type: :development
87
+ prerelease: false
72
88
  version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
73
90
  requirements:
74
91
  - - ! '>='
75
92
  - !ruby/object:Gem::Version
76
93
  version: '0'
77
- none: false
78
94
  - !ruby/object:Gem::Dependency
79
95
  name: slim
80
96
  requirement: !ruby/object:Gem::Requirement
97
+ none: false
81
98
  requirements:
82
99
  - - ! '>='
83
100
  - !ruby/object:Gem::Version
84
101
  version: '0'
85
- none: false
86
- prerelease: false
87
102
  type: :development
103
+ prerelease: false
88
104
  version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
89
106
  requirements:
90
107
  - - ! '>='
91
108
  - !ruby/object:Gem::Version
92
109
  version: '0'
93
- none: false
94
110
  description: Use compiled hogan.js (mustache) JavaScript templates with sprockets
95
111
  and the Rails asset pipeline.
96
112
  email:
@@ -114,6 +130,8 @@ files:
114
130
  - lib/hogan_assets/hogan.rb
115
131
  - lib/hogan_assets/tilt.rb
116
132
  - lib/hogan_assets/version.rb
133
+ - test/config/hogan_assets.yml
134
+ - test/hogan_assets/config_test.rb
117
135
  - test/hogan_assets/tilt_test.rb
118
136
  - test/test_helper.rb
119
137
  - vendor/assets/javascripts/hogan.js
@@ -124,24 +142,26 @@ rdoc_options: []
124
142
  require_paths:
125
143
  - lib
126
144
  required_ruby_version: !ruby/object:Gem::Requirement
145
+ none: false
127
146
  requirements:
128
147
  - - ! '>='
129
148
  - !ruby/object:Gem::Version
130
149
  version: '0'
131
- none: false
132
150
  required_rubygems_version: !ruby/object:Gem::Requirement
151
+ none: false
133
152
  requirements:
134
153
  - - ! '>='
135
154
  - !ruby/object:Gem::Version
136
155
  version: '0'
137
- none: false
138
156
  requirements: []
139
157
  rubyforge_project:
140
- rubygems_version: 1.8.24
158
+ rubygems_version: 1.8.23
141
159
  signing_key:
142
160
  specification_version: 3
143
161
  summary: Use compiled hogan.js (mustache) JavaScript templates with sprockets and
144
162
  the Rails asset pipeline.
145
163
  test_files:
164
+ - test/config/hogan_assets.yml
165
+ - test/hogan_assets/config_test.rb
146
166
  - test/hogan_assets/tilt_test.rb
147
167
  - test/test_helper.rb