jader 0.0.4 → 0.0.5
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 +1 -1
- data/README.md +8 -18
- data/lib/jader/configuration.rb +4 -2
- data/lib/jader/engine.rb +10 -0
- data/lib/jader/version.rb +1 -1
- data/spec/dummy/app/assets/javascripts/application.js +1 -1
- data/spec/dummy/app/assets/javascripts/views/users/{index.jst.jade → dummy.jst.jade} +0 -0
- data/spec/dummy/app/{views → assets/javascripts/views}/users/index.jade +0 -0
- data/spec/dummy/config/initializers/jader.rb +1 -0
- data/spec/template_spec.rb +1 -1
- metadata +6 -6
data/Gemfile
CHANGED
@@ -2,10 +2,10 @@ source "http://rubygems.org"
|
|
2
2
|
|
3
3
|
# Specify your gem's dependencies in jade.gemspec
|
4
4
|
gemspec
|
5
|
+
gem 'therubyracer', :platform => :ruby
|
5
6
|
|
6
7
|
group :test do
|
7
8
|
gem 'johnson', :platform => :mri_18
|
8
|
-
gem 'therubyracer', :platform => :ruby
|
9
9
|
gem 'therubyrhino', :platform => :jruby
|
10
10
|
gem 'sqlite3'
|
11
11
|
end
|
data/README.md
CHANGED
@@ -56,28 +56,16 @@ and the call to `=yield` will render your Jade template above.
|
|
56
56
|
|
57
57
|
Since Rails doesn't expect server-side templates to live under `app/assets` we need to add our client-side views path to Rails views lookup path.
|
58
58
|
|
59
|
-
|
59
|
+
Assuming we have an initializer `app/config/initializers/jader.rb` we can add our client-side views directory like this:
|
60
60
|
|
61
61
|
```ruby
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
before_filter :prepend_view_paths
|
66
|
-
|
67
|
-
# .... application controller code
|
68
|
-
|
69
|
-
private
|
70
|
-
|
71
|
-
# Adds Client-Side views to render path
|
72
|
-
def prepend_view_paths
|
73
|
-
prepend_view_path Rails.root.join('app', 'assets', 'javascripts', , 'views')
|
74
|
-
end
|
75
|
-
|
62
|
+
Jader.configure do |config|
|
63
|
+
# make your client-side views directory discoverable to Rails
|
64
|
+
config.views_path = Rails.root.join('app','assets','javascripts','views')
|
76
65
|
end
|
77
|
-
|
78
66
|
```
|
79
67
|
|
80
|
-
|
68
|
+
Internally, this adds a `before_filter` to `ApplicationController::Base` that prepends the provided path to `ActionView::Context` .
|
81
69
|
|
82
70
|
### Client-side code
|
83
71
|
|
@@ -276,7 +264,7 @@ Jader.configure do |config|
|
|
276
264
|
end
|
277
265
|
```
|
278
266
|
|
279
|
-
`Jader
|
267
|
+
`Jader.configuration.includes` is an array that accepts raw Javascript strings that are, in turn, passed to the server-side template evaluation context.
|
280
268
|
|
281
269
|
To give a more pragmatic example of using Jader inclusions, lets try using `I18n.js` on both server and client.
|
282
270
|
|
@@ -314,6 +302,8 @@ Assuming we have an initializer `app/config/initializers/jader.rb` it should inc
|
|
314
302
|
```ruby
|
315
303
|
Jader.configure do |config|
|
316
304
|
config.mixins_path = Rails.root.join('app','assets','javascripts','mixins')
|
305
|
+
# make your client-side views directory discoverable to Rails
|
306
|
+
config.views_path = Rails.root.join('app','assets','javascripts','views')
|
317
307
|
# Use some javascript from a file that's not available in the asset pipeline
|
318
308
|
config.includes << IO.read(Rails.root.join('app','assets','javascripts','includes','util.js'))
|
319
309
|
# wait for assets to be ready
|
data/lib/jader/configuration.rb
CHANGED
@@ -7,7 +7,8 @@ module Jader
|
|
7
7
|
# @yield [config] Jader::Configuration instance
|
8
8
|
# @example
|
9
9
|
# Jader.configure do |config|
|
10
|
-
# config.mixins_path = Rails.root.join('app','assets','javascripts','
|
10
|
+
# config.mixins_path = Rails.root.join('app','assets','javascripts','mixins')
|
11
|
+
# config.views_path = Rails.root.join('app','assets','javascripts','views')
|
11
12
|
# config.includes << IO.read Rails.root.join('app','assets','javascripts','util.js')
|
12
13
|
# end
|
13
14
|
def self.configure
|
@@ -17,11 +18,12 @@ module Jader
|
|
17
18
|
|
18
19
|
# Jader configuration class
|
19
20
|
class Configuration
|
20
|
-
attr_accessor :mixins_path, :includes
|
21
|
+
attr_accessor :mixins_path, :views_path, :includes
|
21
22
|
|
22
23
|
# Initialize Jader::Configuration class with default values
|
23
24
|
def initialize
|
24
25
|
@mixins_path = nil
|
26
|
+
@views_path = nil
|
25
27
|
@includes = []
|
26
28
|
end
|
27
29
|
end
|
data/lib/jader/engine.rb
CHANGED
@@ -7,5 +7,15 @@ module Jader
|
|
7
7
|
next unless app.config.assets.enabled
|
8
8
|
Sprockets.register_engine '.jade', ::Jader::Template
|
9
9
|
end
|
10
|
+
|
11
|
+
initializer 'jader.prepend_views_path', :after => :add_view_paths do |app|
|
12
|
+
next if Jader::configuration.views_path.nil?
|
13
|
+
ActionController::Base.class_eval do
|
14
|
+
before_filter do |controller|
|
15
|
+
prepend_view_path Jader::configuration.views_path
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
10
20
|
end
|
11
21
|
end
|
data/lib/jader/version.rb
CHANGED
File without changes
|
File without changes
|
@@ -1,4 +1,5 @@
|
|
1
1
|
Jader.configure do |config|
|
2
2
|
config.mixins_path = Rails.root.join('app','assets','javascripts','mixins')
|
3
|
+
config.views_path = Rails.root.join('app','assets','javascripts','views')
|
3
4
|
config.includes << IO.read(Rails.root.join('app','assets','javascripts','includes','util.js'))
|
4
5
|
end
|
data/spec/template_spec.rb
CHANGED
@@ -34,7 +34,7 @@ describe Jader::Compiler do
|
|
34
34
|
context = V8::Context.new
|
35
35
|
context.eval %{
|
36
36
|
#{asset_for('application.js').to_s}
|
37
|
-
html = JST['views/users/
|
37
|
+
html = JST['views/users/dummy']({phrase: '#{phrase}'})
|
38
38
|
}
|
39
39
|
context.eval('html').should include(phrase.upcase)
|
40
40
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-08-
|
13
|
+
date: 2012-08-29 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: libv8
|
@@ -171,7 +171,8 @@ files:
|
|
171
171
|
- spec/dummy/app/assets/javascripts/mixins/application_mixins.jade
|
172
172
|
- spec/dummy/app/assets/javascripts/mixins/users_mixins.jade
|
173
173
|
- spec/dummy/app/assets/javascripts/sample.jst.jade
|
174
|
-
- spec/dummy/app/assets/javascripts/views/users/
|
174
|
+
- spec/dummy/app/assets/javascripts/views/users/dummy.jst.jade
|
175
|
+
- spec/dummy/app/assets/javascripts/views/users/index.jade
|
175
176
|
- spec/dummy/app/assets/stylesheets/application.css
|
176
177
|
- spec/dummy/app/controllers/application_controller.rb
|
177
178
|
- spec/dummy/app/controllers/users_controller.rb
|
@@ -180,7 +181,6 @@ files:
|
|
180
181
|
- spec/dummy/app/models/.gitkeep
|
181
182
|
- spec/dummy/app/models/user.rb
|
182
183
|
- spec/dummy/app/views/layouts/application.html.erb
|
183
|
-
- spec/dummy/app/views/users/index.jade
|
184
184
|
- spec/dummy/app/views/users/show.jade
|
185
185
|
- spec/dummy/config.ru
|
186
186
|
- spec/dummy/config/application.rb
|
@@ -249,7 +249,8 @@ test_files:
|
|
249
249
|
- spec/dummy/app/assets/javascripts/mixins/application_mixins.jade
|
250
250
|
- spec/dummy/app/assets/javascripts/mixins/users_mixins.jade
|
251
251
|
- spec/dummy/app/assets/javascripts/sample.jst.jade
|
252
|
-
- spec/dummy/app/assets/javascripts/views/users/
|
252
|
+
- spec/dummy/app/assets/javascripts/views/users/dummy.jst.jade
|
253
|
+
- spec/dummy/app/assets/javascripts/views/users/index.jade
|
253
254
|
- spec/dummy/app/assets/stylesheets/application.css
|
254
255
|
- spec/dummy/app/controllers/application_controller.rb
|
255
256
|
- spec/dummy/app/controllers/users_controller.rb
|
@@ -258,7 +259,6 @@ test_files:
|
|
258
259
|
- spec/dummy/app/models/.gitkeep
|
259
260
|
- spec/dummy/app/models/user.rb
|
260
261
|
- spec/dummy/app/views/layouts/application.html.erb
|
261
|
-
- spec/dummy/app/views/users/index.jade
|
262
262
|
- spec/dummy/app/views/users/show.jade
|
263
263
|
- spec/dummy/config.ru
|
264
264
|
- spec/dummy/config/application.rb
|