liquid_assets 0.1.1 → 0.3.2
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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +5 -12
- data/Gemfile.lock +40 -18
- data/LICENSE.txt +2 -0
- data/README.md +15 -146
- data/Rakefile +2 -16
- data/lib/liquid_assets/config.rb +36 -9
- data/lib/liquid_assets/engine.rb +4 -4
- data/lib/liquid_assets/eval.rb +20 -0
- data/lib/liquid_assets/{tilt_engine.rb → pipeline_template_engine.rb} +8 -12
- data/lib/liquid_assets/resolver.rb +68 -0
- data/lib/liquid_assets/template_handler.rb +6 -20
- data/lib/liquid_assets/tiny_liquid.rb +11 -7
- data/lib/liquid_assets/version.rb +1 -1
- data/lib/liquid_assets.rb +5 -2
- data/liquid_assets.gemspec +23 -71
- data/test/helper.rb +1 -1
- data/test/test_liquid_assets.rb +49 -6
- data/vendor/assets/javascripts/liquid_assets.js.erb +228 -0
- data/vendor/tinyliquid.js +9 -6
- metadata +53 -85
- data/.document +0 -5
- data/VERSION +0 -1
- data/vendor/assets/javascripts/liquid_assets.js +0 -57
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 05277be46cbe2e2d7d1cce109ca15d5e7ce156cf
|
4
|
+
data.tar.gz: 376327fb4e7fe7c2d6edeff878d530330d54d290
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 390677abed5cd524a34c634b8210a551ddfb0168a8ce8030d14cf315615e9db6d32d5acd8b211b01d7c788ad2185473cef2c45d95252d3ee78eb773cf94cd2f5
|
7
|
+
data.tar.gz: 52236d4d965716c356fd7246c8c64eee782a2758ff4336d5df6f9c1ab563ea97ffa214f4554d22c5aac7ea302b2596cfbb51ace171635d12c45716e2385186ec
|
data/.gitignore
ADDED
data/Gemfile
CHANGED
@@ -1,18 +1,11 @@
|
|
1
|
-
source
|
2
|
-
# Add dependencies required to use your gem here.
|
3
|
-
# Example:
|
4
|
-
# gem "activesupport", ">= 2.3.5"
|
5
|
-
|
6
|
-
gem 'liquid'
|
7
|
-
gem 'tilt'
|
8
|
-
gem 'sprockets'
|
9
|
-
gem 'execjs'
|
1
|
+
source 'https://rubygems.org'
|
10
2
|
|
3
|
+
# Specify your gem's dependencies in liquid_assets.gemspec
|
4
|
+
gemspec
|
11
5
|
|
12
6
|
# Add dependencies to develop your gem here.
|
13
7
|
# Include everything needed to run rake, tests, features, etc.
|
14
8
|
group :development do
|
15
|
-
|
16
|
-
|
17
|
-
gem "jeweler"
|
9
|
+
gem "rdoc"
|
10
|
+
gem "bundler"
|
18
11
|
end
|
data/Gemfile.lock
CHANGED
@@ -1,37 +1,59 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
liquid_assets (0.3.2)
|
5
|
+
actionpack (>= 3.2)
|
6
|
+
execjs
|
7
|
+
liquid
|
8
|
+
tilt
|
9
|
+
|
1
10
|
GEM
|
2
|
-
remote:
|
11
|
+
remote: https://rubygems.org/
|
3
12
|
specs:
|
13
|
+
actionpack (3.2.13)
|
14
|
+
activemodel (= 3.2.13)
|
15
|
+
activesupport (= 3.2.13)
|
16
|
+
builder (~> 3.0.0)
|
17
|
+
erubis (~> 2.7.0)
|
18
|
+
journey (~> 1.0.4)
|
19
|
+
rack (~> 1.4.5)
|
20
|
+
rack-cache (~> 1.2)
|
21
|
+
rack-test (~> 0.6.1)
|
22
|
+
sprockets (~> 2.2.1)
|
23
|
+
activemodel (3.2.13)
|
24
|
+
activesupport (= 3.2.13)
|
25
|
+
builder (~> 3.0.0)
|
26
|
+
activesupport (3.2.13)
|
27
|
+
i18n (= 0.6.1)
|
28
|
+
multi_json (~> 1.0)
|
29
|
+
builder (3.0.4)
|
30
|
+
erubis (2.7.0)
|
4
31
|
execjs (1.4.0)
|
5
32
|
multi_json (~> 1.0)
|
6
|
-
git (1.2.5)
|
7
33
|
hike (1.2.1)
|
8
|
-
|
9
|
-
|
10
|
-
git (>= 1.2.5)
|
11
|
-
rake
|
12
|
-
rdoc
|
13
|
-
json (1.7.7)
|
34
|
+
i18n (0.6.1)
|
35
|
+
journey (1.0.4)
|
14
36
|
liquid (2.5.0)
|
15
|
-
multi_json (1.
|
16
|
-
rack (1.5
|
17
|
-
|
37
|
+
multi_json (1.7.2)
|
38
|
+
rack (1.4.5)
|
39
|
+
rack-cache (1.2)
|
40
|
+
rack (>= 0.4)
|
41
|
+
rack-test (0.6.2)
|
42
|
+
rack (>= 1.0)
|
43
|
+
rake (10.0.4)
|
18
44
|
rdoc (4.0.0)
|
19
|
-
json (~> 1.4)
|
20
45
|
sprockets (2.2.2)
|
21
46
|
hike (~> 1.2)
|
22
47
|
multi_json (~> 1.0)
|
23
48
|
rack (~> 1.0)
|
24
49
|
tilt (~> 1.1, != 1.3.0)
|
25
|
-
tilt (1.3.
|
50
|
+
tilt (1.3.6)
|
26
51
|
|
27
52
|
PLATFORMS
|
28
53
|
ruby
|
29
54
|
|
30
55
|
DEPENDENCIES
|
31
56
|
bundler
|
32
|
-
|
33
|
-
|
34
|
-
liquid
|
57
|
+
liquid_assets!
|
58
|
+
rake
|
35
59
|
rdoc
|
36
|
-
sprockets
|
37
|
-
tilt
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,160 +1,29 @@
|
|
1
|
-
#
|
1
|
+
# LiquidAssets
|
2
2
|
|
3
|
-
|
3
|
+
TODO: Write a gem description
|
4
4
|
|
5
|
-
|
6
|
-
templates and as JavaScript via the asset_pipeline.
|
5
|
+
## Installation
|
7
6
|
|
8
|
-
|
9
|
-
0.1 really does mean 0.1 in this case!
|
7
|
+
Add this line to your application's Gemfile:
|
10
8
|
|
11
|
-
|
12
|
-
be a few as I discover bugs and/or better methods of implementing
|
13
|
-
features.
|
9
|
+
gem 'liquid_assets'
|
14
10
|
|
15
|
-
|
16
|
-
support and read template's from active_record. *(probably via a
|
17
|
-
supplied Proc)*
|
11
|
+
And then execute:
|
18
12
|
|
19
|
-
|
20
|
-
gem.
|
13
|
+
$ bundle
|
21
14
|
|
22
|
-
|
23
|
-
https://github.com/leizongmin/tinyliquid JavaScript library, which
|
24
|
-
execjs calls to compiles the templates to JavaScript. I did have to
|
25
|
-
perform a few small modifications to the library in order to get it to
|
26
|
-
support partials in the same manner as the Ruby library
|
27
|
-
|
28
|
-
## Rationale
|
29
|
-
I am currently developing a largish project that has a requirement for
|
30
|
-
user edited html that needs to be rendered both as a standard website
|
31
|
-
and as a single page Backbone application.
|
32
|
-
|
33
|
-
I'd originally attempted to use Mustache templates but discarded that
|
34
|
-
idea after not being able to do simple things like formatting numbers
|
35
|
-
in the views.
|
36
|
-
|
37
|
-
Liquid templates were ideal, but they lacked a suitable JS
|
38
|
-
environment. I then ran across the TinyLiquid project and decided to
|
39
|
-
create a gem to unite the two.
|
15
|
+
Or install it yourself as:
|
40
16
|
|
17
|
+
$ gem install liquid_assets
|
41
18
|
|
42
19
|
## Usage
|
43
20
|
|
44
|
-
|
45
|
-
The root defaults to app/assets/templates.
|
46
|
-
|
47
|
-
LiquidAssets::Config.configure do |config|
|
48
|
-
config.path_prefix = 'app/assets/templates'
|
49
|
-
config.filters = MyFilterModule
|
50
|
-
config.template_namespace = 'LQT'
|
51
|
-
end
|
52
|
-
|
53
|
-
|
54
|
-
### Use as Rails views
|
55
|
-
|
56
|
-
Create a view just like you would with erb, except with .liquid as the extension.
|
57
|
-
|
58
|
-
app/assets/templates/blog/post.liquid
|
59
|
-
|
60
|
-
Since the template is written in Liquid, it DOES NOT have access to
|
61
|
-
the normal rails helper methods.
|
62
|
-
|
63
|
-
It does have access to instance variables, but can only interact with
|
64
|
-
simple Strings, Numbers, Arrays, & Hashes. An additional restriction
|
65
|
-
is that Hashes must use strings for keys, not symbols.
|
66
|
-
|
67
|
-
I'm sure some of these limitations could be worked around, but my
|
68
|
-
needs do not include supporting them at this time. *Patches are welcomed*
|
69
|
-
|
70
|
-
|
71
|
-
By default the filters are set to the Liquid::StandardFilters
|
72
|
-
http://liquid.rubyforge.org/classes/Liquid/StandardFilters.html This
|
73
|
-
can be changed by including a liquid_filters method on the controller,
|
74
|
-
or in application_controller to set system-wide. *(assuming you are
|
75
|
-
inheriting from it)*
|
76
|
-
|
77
|
-
A short example:
|
78
|
-
|
79
|
-
blog_controller.rb:
|
80
|
-
|
81
|
-
def show
|
82
|
-
@ages={'bob'=>28,'joe'=>23}
|
83
|
-
render :template=>'blog/post'
|
84
|
-
end
|
85
|
-
|
86
|
-
app/assets/templates/blog/post.liquid :
|
87
|
-
|
88
|
-
Bob is {{ages.bob}}, older than Joe - who's only {{ages.joe}}.
|
89
|
-
|
90
|
-
But this will not since @bob is not a hash.
|
91
|
-
|
92
|
-
controller:
|
93
|
-
|
94
|
-
def show
|
95
|
-
@old=People.where({:name=>'bob',:age=>100}).first
|
96
|
-
render :template=>'blog/post'
|
97
|
-
end
|
98
|
-
|
99
|
-
(contrived) liquid view:
|
100
|
-
|
101
|
-
Bob's age is {{old.age}}
|
102
|
-
|
103
|
-
**Hint:** To get it to work, call as_json on your models:
|
104
|
-
|
105
|
-
@old=People.where({:name=>'bob',:age=>100}).first.as_json
|
106
|
-
|
107
|
-
|
108
|
-
### Use as AssetPipeline pre-compiled javascript
|
109
|
-
|
110
|
-
You can include your liquid templates in the asset_pipeline by
|
111
|
-
using the standard //= syntax in one of your existing JavaScript files
|
112
|
-
|
113
|
-
//=require liquid_assets
|
114
|
-
//=require templates/blog/post
|
115
|
-
|
116
|
-
Will compile post.liquid to JavaScript using TinyLiquid and include it like so
|
117
|
-
|
118
|
-
LQT['templates/blog/post'] = function(locals,filters){ ... }
|
119
|
-
|
120
|
-
It can be used similar to underscore's JST template.
|
121
|
-
|
122
|
-
With filters:
|
123
|
-
|
124
|
-
LQT['templates/blog/post']( { bob:{ age: 23 } }, {
|
125
|
-
plusTen: function(num){ return num+10; }
|
126
|
-
})
|
127
|
-
|
128
|
-
Template:
|
129
|
-
|
130
|
-
Bob will be {{bob.age | plusTen}} in ten years.
|
131
|
-
|
132
|
-
Renders to:
|
133
|
-
Bob will be 33 in ten years.
|
134
|
-
|
135
|
-
The LQT namespace is short for LiQuid Template, à la JST from underscore.
|
136
|
-
|
137
|
-
It can be modified by configuring:
|
138
|
-
|
139
|
-
LiquidAssets::Config.configure do |config|
|
140
|
-
config.template_namespace = 'FANCY_NAME'
|
141
|
-
end
|
142
|
-
|
143
|
-
## Thanks
|
144
|
-
|
145
|
-
[Shopify](http://www.shopify.com/)
|
146
|
-
for creating the liquid template language and Ruby implementation. [leizongmin](https://github.com/leizongmin/tinyliquid) for the
|
147
|
-
tinyliquid Javascript support.
|
148
|
-
|
149
|
-
I cribbed from [hogan_assets](https://github.com/leshill/hogan_assets/), [Poirot](https://github.com/olivernn/poirot) and [Stache](https://github.com/agoragames/stache/) in creating this gem. Good parts
|
150
|
-
are thanks to those projects, mistakes are mine.
|
151
|
-
|
21
|
+
TODO: Write usage instructions here
|
152
22
|
|
153
23
|
## Contributing
|
154
|
-
Fork on [github](https://github.com/nathanstitt/liquid_assets), implement your change, submit a pull request.
|
155
|
-
|
156
|
-
|
157
|
-
## Copyright
|
158
24
|
|
159
|
-
|
160
|
-
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'rubygems'
|
4
|
-
require 'bundler'
|
4
|
+
require 'bundler/gem_tasks'
|
5
|
+
|
5
6
|
begin
|
6
7
|
Bundler.setup(:default, :development)
|
7
8
|
rescue Bundler::BundlerError => e
|
@@ -11,21 +12,6 @@ rescue Bundler::BundlerError => e
|
|
11
12
|
end
|
12
13
|
require 'rake'
|
13
14
|
|
14
|
-
require 'jeweler'
|
15
|
-
Jeweler::Tasks.new do |gem|
|
16
|
-
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
-
gem.name = "liquid_assets"
|
18
|
-
gem.homepage = "http://github.com/nathanstitt/liquid_assets"
|
19
|
-
gem.license = "MIT"
|
20
|
-
gem.summary = %Q{Liquid formmated views and assets}
|
21
|
-
gem.description = %Q{Allows you to use Liquid format templates in Rails, both as
|
22
|
-
view templates and as compiled JavaScript via the asset_pipeline.}
|
23
|
-
gem.email = "nathan@stitt.org"
|
24
|
-
gem.authors = ["Nathan Stitt"]
|
25
|
-
# dependencies defined in Gemfile
|
26
|
-
end
|
27
|
-
Jeweler::RubygemsDotOrgTasks.new
|
28
|
-
|
29
15
|
require 'rake/testtask'
|
30
16
|
Rake::TestTask.new(:test) do |test|
|
31
17
|
test.libs << 'lib' << 'test'
|
data/lib/liquid_assets/config.rb
CHANGED
@@ -3,21 +3,23 @@ require 'yaml'
|
|
3
3
|
module LiquidAssets
|
4
4
|
# Change config options in an initializer:
|
5
5
|
#
|
6
|
-
# LiquidAssets::Config.
|
6
|
+
# LiquidAssets::Config.namespace = 'LT'
|
7
7
|
#
|
8
8
|
# Or in a block:
|
9
9
|
#
|
10
10
|
# LiquidAssets::Config.configure do |config|
|
11
11
|
# config.path_prefix = 'app/assets/templates'
|
12
12
|
# config.filters = MyFilterModule
|
13
|
-
# config.
|
13
|
+
# config.namespace = 'LQT'
|
14
14
|
# end
|
15
15
|
#
|
16
16
|
# Or change config options in a YAML file (config/liquid_assets.yml):
|
17
17
|
#
|
18
18
|
# defaults: &defaults
|
19
19
|
# path_prefix: 'templates'
|
20
|
-
#
|
20
|
+
# namespace: 'LQT'
|
21
|
+
# globals:
|
22
|
+
# company: 'BigCorp Inc'
|
21
23
|
# development:
|
22
24
|
# <<: *defaults
|
23
25
|
# test:
|
@@ -33,10 +35,23 @@ module LiquidAssets
|
|
33
35
|
# Directory to read templates from. Default = app/assets/templates
|
34
36
|
attr_writer :path_prefix
|
35
37
|
# The name of the global JS object that will contain the templates. Defaults = LQT
|
36
|
-
attr_writer :
|
38
|
+
attr_writer :namespace
|
37
39
|
# A Ruby module implementing the Liquid Filters that are accessible when templates are evaluated as views
|
38
|
-
# Javascript filters
|
40
|
+
# Javascript filters can be set by modifying the LQT.Filters object.
|
41
|
+
# A set of the standard Shopify filters are provided for both Ruby & Javascript.
|
42
|
+
# https://github.com/Shopify/liquid/wiki/Liquid-for-Designers
|
39
43
|
attr_writer :filters
|
44
|
+
# May be set to a Proc/Lambda which will be passed the path to a
|
45
|
+
# potential template
|
46
|
+
#
|
47
|
+
# The lambda should return the contents of a liquid template
|
48
|
+
# or false to indicate it is not found
|
49
|
+
attr_writer :content_provider
|
50
|
+
#
|
51
|
+
# A hash of 'global' variables that should always be available to
|
52
|
+
# templates. This will be merged into the template local variables
|
53
|
+
# when the template is rendered and may overwrite them
|
54
|
+
attr_writer :globals
|
40
55
|
|
41
56
|
def configure
|
42
57
|
yield self
|
@@ -53,8 +68,9 @@ module LiquidAssets
|
|
53
68
|
end
|
54
69
|
|
55
70
|
def load_yml!
|
56
|
-
|
57
|
-
|
71
|
+
%{path_prefix namespace globals}.each do | name |
|
72
|
+
self.instance_variable_set( "@#{name}", yml[name] ) if yaml.has_key?(name)
|
73
|
+
end
|
58
74
|
end
|
59
75
|
|
60
76
|
def path_prefix
|
@@ -68,11 +84,22 @@ module LiquidAssets
|
|
68
84
|
Pathname.new('.')
|
69
85
|
end
|
70
86
|
end
|
87
|
+
|
88
|
+
def content_provider
|
89
|
+
@content_provider ||= lambda{|path| false }
|
90
|
+
end
|
91
|
+
def globals
|
92
|
+
( @globals && @globals.is_a?(Proc) ) ? @globals.call : @globals ||= {}
|
93
|
+
end
|
94
|
+
def template_root_path
|
95
|
+
root_path.join( 'app','assets','templates' )
|
96
|
+
end
|
97
|
+
|
71
98
|
def filters
|
72
99
|
@filters ||= Liquid::StandardFilters
|
73
100
|
end
|
74
|
-
def
|
75
|
-
@
|
101
|
+
def namespace
|
102
|
+
@namespace ||= 'LQT'
|
76
103
|
end
|
77
104
|
|
78
105
|
def yml
|
data/lib/liquid_assets/engine.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'liquid_assets/
|
1
|
+
require 'liquid_assets/pipeline_template_engine'
|
2
2
|
|
3
3
|
module LiquidAssets
|
4
4
|
|
@@ -9,14 +9,14 @@ module LiquidAssets
|
|
9
9
|
|
10
10
|
LiquidAssets::Config.load_yml! if LiquidAssets::Config.yml_exists?
|
11
11
|
|
12
|
-
|
13
12
|
ActionView::Template.register_template_handler(:liquid, LiquidAssets::TemplateHandler )
|
14
13
|
|
15
|
-
app.assets.register_engine(".liquid", ::LiquidAssets::
|
14
|
+
app.assets.register_engine(".liquid", ::LiquidAssets::PipelineTemplateEngine )
|
16
15
|
|
17
16
|
app.config.to_prepare do
|
18
|
-
Liquid::Template.file_system = Liquid::LocalFileSystem.new( Config.
|
17
|
+
Liquid::Template.file_system = Liquid::LocalFileSystem.new( Config.template_root_path )
|
19
18
|
ApplicationController.send( :append_view_path, LiquidAssets::Config.path_prefix )
|
19
|
+
ApplicationController.send( :prepend_view_path, LiquidAssets::Resolver.instance )
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
module LiquidAssets
|
3
|
+
|
4
|
+
|
5
|
+
class LiquidWrapper < Struct.new(:template)
|
6
|
+
|
7
|
+
def render( variables={}, config={} )
|
8
|
+
assigns = Config.globals.dup
|
9
|
+
assigns.merge!( variables )
|
10
|
+
config[:filters] ||= ::LiquidAssets::Config.filters
|
11
|
+
template.render(assigns, config )
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.parse( source )
|
16
|
+
LiquidWrapper.new( ::Liquid::Template.parse( source ) )
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
end
|
@@ -2,7 +2,7 @@ require 'tilt'
|
|
2
2
|
|
3
3
|
module LiquidAssets
|
4
4
|
|
5
|
-
class
|
5
|
+
class PipelineTemplateEngine < Tilt::Template
|
6
6
|
|
7
7
|
self.default_mime_type = 'application/javascript'
|
8
8
|
|
@@ -10,16 +10,13 @@ module LiquidAssets
|
|
10
10
|
# end
|
11
11
|
|
12
12
|
def evaluate(scope, locals, &block)
|
13
|
-
|
14
13
|
template_path = TemplatePath.new scope
|
15
|
-
template_namespace = LiquidAssets::Config.template_namespace
|
16
|
-
|
17
|
-
compiled_template = TinyLiquid.compile(data)
|
18
14
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
15
|
+
source = Config.content_provider.call( template_path.name )
|
16
|
+
if false == source
|
17
|
+
source = data
|
18
|
+
end
|
19
|
+
"#{LiquidAssets::Config.namespace}.Templates[#{template_path.name.dump}] = #{ TinyLiquid.compile( source ) };"
|
23
20
|
end
|
24
21
|
|
25
22
|
protected
|
@@ -38,15 +35,14 @@ module LiquidAssets
|
|
38
35
|
end
|
39
36
|
|
40
37
|
def name
|
41
|
-
@name ||= relative_path
|
38
|
+
@name ||= relative_path
|
42
39
|
end
|
43
40
|
|
44
|
-
private
|
45
41
|
|
46
42
|
attr_accessor :template_path
|
47
43
|
|
48
44
|
def relative_path
|
49
|
-
@relative_path ||= template_path.
|
45
|
+
@relative_path ||= template_path.sub(/^#{LiquidAssets::Config.path_prefix}\/(.*)$/i, '\1' )
|
50
46
|
end
|
51
47
|
end
|
52
48
|
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
require 'action_view'
|
3
|
+
require 'action_view/template'
|
4
|
+
|
5
|
+
module LiquidAssets
|
6
|
+
class Resolver < ActionView::Resolver
|
7
|
+
|
8
|
+
include Singleton
|
9
|
+
|
10
|
+
def to_s
|
11
|
+
'LiquidAssets::Resolver'
|
12
|
+
end
|
13
|
+
|
14
|
+
def find_templates(name, prefix, partial, details)
|
15
|
+
|
16
|
+
source = Config.content_provider.call( name )
|
17
|
+
if false == source
|
18
|
+
return []
|
19
|
+
else
|
20
|
+
return [ make_template( source, normalize_path( prefix, name ), details, partial ) ]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def clear_cache_for( expired_path )
|
25
|
+
@cached.each do |context, prefix_hash |
|
26
|
+
prefix_hash.each do | prefix, name_hash |
|
27
|
+
name_hash.delete_if{ | name, partial_hash |
|
28
|
+
normalize_path( prefix, name ) == expired_path
|
29
|
+
}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def normalize_path( prefix, name )
|
37
|
+
if prefix.present? && name.present?
|
38
|
+
prefix + '/' + name
|
39
|
+
elsif prefix.present?
|
40
|
+
prefix
|
41
|
+
else
|
42
|
+
name
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def make_template( source, path, details, partial )
|
47
|
+
handler = ::ActionView::Template.registered_template_handler('.liquid')
|
48
|
+
details = {
|
49
|
+
:virtual_path => partial_path(path, partial ),
|
50
|
+
:locale => details[:locale].first.to_s,
|
51
|
+
:format => details[:formats].first.to_s,
|
52
|
+
:handler => details[:handlers].map(&:to_s),
|
53
|
+
:partial => partial || false
|
54
|
+
}
|
55
|
+
handler = ActionView::Template.registered_template_handler(:liquid)
|
56
|
+
return ActionView::Template.new(source, "LiquidTemplate - #{path}", handler, details)
|
57
|
+
end
|
58
|
+
|
59
|
+
def partial_path( path, partial )
|
60
|
+
return path if ! partial
|
61
|
+
if index.path.rindex('/') # had: gsub(/\/([^\/]+)$/,'/_\1')
|
62
|
+
path.insert(index+1,'_') # this is better
|
63
|
+
else
|
64
|
+
'_' + path
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -6,9 +6,6 @@ module LiquidAssets
|
|
6
6
|
class TemplateHandler
|
7
7
|
|
8
8
|
def self.call(template)
|
9
|
-
# view_path = "#{template.virtual_path}_view"
|
10
|
-
# abs_view_path = Rails.root.join('app/views', view_path)
|
11
|
-
# Rails.logger.warn "looking for: #{abs_view_path}"
|
12
9
|
return "LiquidAssets::TemplateHandler.new(self).render(#{template.source.inspect}, local_assigns)"
|
13
10
|
end
|
14
11
|
|
@@ -19,27 +16,16 @@ module LiquidAssets
|
|
19
16
|
def render(template, local_assigns = {})
|
20
17
|
@view.controller.headers["Content-Type"] ||= 'text/html; charset=utf-8'
|
21
18
|
|
22
|
-
assigns = @view.assigns
|
19
|
+
assigns = @view.assigns.dup
|
20
|
+
assigns.merge!( local_assigns.stringify_keys )
|
23
21
|
|
24
22
|
if content = @view.content_for?(:layout)
|
25
23
|
assigns["content_for_layout"] = content
|
26
24
|
end
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
controller.send(:liquid_filters)
|
32
|
-
else
|
33
|
-
Config.filters
|
34
|
-
end
|
35
|
-
|
36
|
-
liquid = ::Liquid::Template.parse(template)
|
37
|
-
liquid.render(assigns,
|
38
|
-
:filters => filters,
|
39
|
-
:registers => {
|
40
|
-
:action_view => @view,
|
41
|
-
:controller => @view.controller
|
42
|
-
} ).html_safe
|
25
|
+
LiquidAssets.parse(template).render( assigns, :registers=>{
|
26
|
+
:action_view => @view,
|
27
|
+
:controller => @view.controller
|
28
|
+
} ).html_safe
|
43
29
|
end
|
44
30
|
|
45
31
|
def compilable?
|
@@ -8,13 +8,17 @@ module LiquidAssets
|
|
8
8
|
|
9
9
|
class << self
|
10
10
|
def compile(source, options = {})
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
#{
|
16
|
-
|
17
|
-
}
|
11
|
+
ns = ::LiquidAssets::Config.namespace
|
12
|
+
js = context.eval("TinyLiquid.parse(#{source.inspect},{namespace:'#{Config.namespace}'}).code")
|
13
|
+
<<-TEMPLATE
|
14
|
+
function(locals,filters){
|
15
|
+
var $_tmpbuf, $_html = #{ns}._FNS.html, $_err = #{ns}._FNS.err,
|
16
|
+
$_rethrow=#{ns}._FNS.rethrow, $_merge=#{ns}._FNS.merge,
|
17
|
+
$_range=#{ns}._FNS.range, $_array=#{ns}._FNS.array;
|
18
|
+
#{js}
|
19
|
+
return $_buf;
|
20
|
+
}
|
21
|
+
TEMPLATE
|
18
22
|
end
|
19
23
|
|
20
24
|
private
|