liquid_assets 0.3.3 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 70f04b8e8c2997831e781dffd05a95e80cadcbed
4
- data.tar.gz: 2fa71d8788f5174057b5fc2a402711d7e13c184f
3
+ metadata.gz: 50e6eb3911190f87a95427241a4f72f2f3c99b13
4
+ data.tar.gz: 917feafdbd36d8a8f9b48619e33efa4599e23c8b
5
5
  SHA512:
6
- metadata.gz: 35e41cccb938e6450ec78c107f7dbb0e63eef33f713cbb2790840890566df5329d63d38cb33be1ac5ba8b57d103708b4e2e5a976edee3f05a2b875bb19455710
7
- data.tar.gz: d370954a6795c57e15b0a40f5c8ae3c5318177658ecac41e0a5f02eb2c97869c4f70b0277043f16ea3a285e4a3dcc2e2ccf13552b478160505fe8e7fefad0d13
6
+ metadata.gz: 089c3243284ea3dacbe2cfc37b8ec520b3649883fb1e1bf75c43da9f0f9e9c45c8dc96a4f1ae4b7e5d3444a99317714d6c9111bd064d7d05e6c2331008f303da
7
+ data.tar.gz: 5ba19ade6130e6dd873c62aeed7e523cf13d037ded8ff747a480ffd3b7bb99c05f69b02f6e0c9c006fff866d1470b0775b95b109b272ed78c53fd40f80696dcb
data/Gemfile.lock CHANGED
@@ -1,53 +1,53 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- liquid_assets (0.3.3)
4
+ liquid_assets (0.4.2)
5
5
  actionpack (>= 3.2)
6
6
  execjs
7
7
  liquid
8
+ sprockets
8
9
  tilt
9
10
 
10
11
  GEM
11
12
  remote: https://rubygems.org/
12
13
  specs:
13
- actionpack (3.2.13)
14
- activemodel (= 3.2.13)
15
- activesupport (= 3.2.13)
16
- builder (~> 3.0.0)
14
+ actionpack (4.0.0)
15
+ activesupport (= 4.0.0)
16
+ builder (~> 3.1.0)
17
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)
18
+ rack (~> 1.5.2)
19
+ rack-test (~> 0.6.2)
20
+ activesupport (4.0.0)
21
+ i18n (~> 0.6, >= 0.6.4)
22
+ minitest (~> 4.2)
23
+ multi_json (~> 1.3)
24
+ thread_safe (~> 0.1)
25
+ tzinfo (~> 0.3.37)
26
+ atomic (1.1.13)
27
+ builder (3.1.4)
30
28
  erubis (2.7.0)
31
- execjs (1.4.0)
32
- multi_json (~> 1.0)
33
- hike (1.2.1)
34
- i18n (0.6.1)
35
- journey (1.0.4)
36
- liquid (2.5.0)
37
- multi_json (1.7.2)
38
- rack (1.4.5)
39
- rack-cache (1.2)
40
- rack (>= 0.4)
29
+ execjs (2.0.1)
30
+ hike (1.2.3)
31
+ i18n (0.6.5)
32
+ json (1.8.0)
33
+ liquid (2.5.2)
34
+ minitest (4.7.5)
35
+ multi_json (1.7.9)
36
+ rack (1.5.2)
41
37
  rack-test (0.6.2)
42
38
  rack (>= 1.0)
43
- rake (10.0.4)
44
- rdoc (4.0.0)
45
- sprockets (2.2.2)
39
+ rake (10.1.0)
40
+ rdoc (4.0.1)
41
+ json (~> 1.4)
42
+ sprockets (2.10.0)
46
43
  hike (~> 1.2)
47
44
  multi_json (~> 1.0)
48
45
  rack (~> 1.0)
49
46
  tilt (~> 1.1, != 1.3.0)
50
- tilt (1.3.6)
47
+ thread_safe (0.1.2)
48
+ atomic
49
+ tilt (1.4.1)
50
+ tzinfo (0.3.37)
51
51
 
52
52
  PLATFORMS
53
53
  ruby
data/README.md CHANGED
@@ -1,29 +1,201 @@
1
- # LiquidAssets
1
+ # liquid_assets
2
2
 
3
- TODO: Write a gem description
3
+ ## Description
4
4
 
5
- ## Installation
5
+ Allows you to use the Liquid template language in Rails, both as
6
+ templates and as JavaScript via the asset_pipeline.
6
7
 
7
- Add this line to your application's Gemfile:
8
+ The Ruby bits are via the standard Liquid http://liquidmarkup.org/
9
+ gem.
8
10
 
9
- gem 'liquid_assets'
11
+ The JavaScript support is possible through the TinyLiquid
12
+ https://github.com/leizongmin/tinyliquid JavaScript library, which
13
+ execjs calls to compiles the templates to JavaScript. I did have to
14
+ perform a few small modifications to the library in order to get it to
15
+ support partials in the same manner as the Ruby library
10
16
 
11
- And then execute:
17
+ Javascript version of templates may be rendered by calling
12
18
 
13
- $ bundle
19
+ LQT.Render( path, data );
14
20
 
15
- Or install it yourself as:
21
+ and partials by:
16
22
 
17
- $ gem install liquid_assets
23
+ LQT.RenderPartial( path, data );
18
24
 
19
- ## Usage
25
+ ## Rationale
26
+ I am currently developing a largish project that has a requirement for
27
+ user edited html that needs to be rendered both as a standard website
28
+ and as a single page Backbone application.
29
+
30
+ I'd originally attempted to use Mustache templates but discarded that
31
+ idea after not being able to do simple things like formatting numbers
32
+ in the views.
33
+
34
+ Liquid templates were ideal, but they lacked a suitable JS
35
+ environment. I then ran across the TinyLiquid project and created
36
+ this gem in order to cleanly unite the them.
37
+
38
+
39
+ ## Configuration
40
+
41
+ Set the root in an initializer, i.e. config/initializers/liquid_assets.rb
42
+ The root defaults to app/assets/templates.
43
+
44
+ LiquidAssets::Config.configure do |config|
45
+ config.path_prefix = 'app/assets/templates'
46
+ config.filters = MyFilterModule
47
+ config.namespace = 'LQT'
48
+ config.globals = lambda{ { 'website_name': 'A Website of Excellence!' } }
49
+ config.content_provider = lambda{ |path|
50
+ path == 'hello-world' ? LiquidAssets::Template.new( 'Hello World!', Time.now ) : false
51
+ }
52
+ end
53
+
54
+ By default the Ruby filters are set to Liquid::StandardFilters
55
+ http://liquid.rubyforge.org/classes/Liquid/StandardFilters.html. Javascript
56
+ versions are also included in the liquid_assets.js file under the
57
+ LQT.Filters namespace.
58
+
59
+ ### Content_provider config
60
+
61
+ A content provider option can be set on the configuration. It can be used to retrieve a template
62
+
63
+ Example
64
+ -----
65
+
66
+ ##### Simple rendering
67
+
68
+ tmpl = LiquidAssets.parse <<END_TEMPLATE
69
+ Hello {{visitor.name | capitalize }},
70
+ So long and thanks for all the fish!
71
+ END_TEMPLATE
72
+
73
+ tmpl.render({'visitor'=>{'name'=>'Bob'}})
74
+
75
+
76
+ Or with a file 'foo/bar.liquid', containing the content *(under Config.path_prefix)*:
77
+ tmpl = LiquidAssets.template( 'foo/bar' ) ``
78
+
79
+
80
+ ##### Rendering via rails engine
81
+
82
+ Given the below configuration:
83
+ LiquidAssets::Config.configure do |config|
84
+ config.globals = { copyright_holder: 'BigCorp Inc.' }
85
+ end
86
+
87
+ A liquid template with content:
88
+
89
+ Hello {{visitor.name | capitalize }},
90
+ Thanks for stopping by!
91
+
92
+ {{ author.name | capitalize }}'s age is {{author.age}}.
93
+
94
+ They will be {{ author.age| plus:10 }} in ten years.
95
+
96
+ {{ include 'blog/legalease' }}
97
+
98
+
99
+ stored at: app/assets/templates/blog/about.liquid
100
+
101
+ And a partial:
102
+
103
+ This post is copyright {{ copyright_holder }}
104
+
105
+ stored at: app/assets/templates/blog/_legalease.liquid
106
+
107
+
108
+ ### as Rails view
109
+
110
+
111
+ blog_controller.rb:
112
+
113
+ def show
114
+ @visitor = { 'name' => 'bob' }
115
+ @author = { 'name' => 'jimmy smith', 'age'=>23 }
116
+ render :template=>'blog/about'
117
+ end
118
+
119
+ **Note:** Since the template is written in Liquid, it DOES NOT have access to
120
+ the normal rails helper methods.
121
+
122
+ It does have access to instance variables, but can only interact with
123
+ simple Strings, Numbers, Arrays, & Hashes. An additional restriction
124
+ is that Hashes must use strings for keys, not symbols.
125
+
126
+ I'm sure some of these limitations could be worked around, but my
127
+ needs do not include supporting them at this time. *Patches are welcomed*
128
+
129
+
130
+ ### as AssetPipeline pre-compiled javascript
131
+
132
+ You can include your liquid templates in the asset_pipeline by
133
+ using the standard //= syntax in one of your existing JavaScript files
134
+
135
+ //=require liquid_assets
136
+ //=require blog/_welcome // Could also require_tree, or an index.js manifest file
137
+ //=require blog/post
138
+
139
+ Will compile post.liquid to JavaScript using TinyLiquid and include it at:
140
+
141
+ LQT.Templates['blog/post']
142
+
143
+ It can then be rendered by
144
+
145
+ LQT.Render('blog/post',{ author: { name: jimmy smith', age: 23}, visitor: {name: 'bob' } } )
146
+
147
+ A set of standard filters are included at LQT.Filters, which may be extended with
148
+ custom filter functions.
149
+
150
+ **Note:** The LQT namespace is short for LiQuid Template, à la JST from underscore.
151
+ It can be modified by configuring:
152
+
153
+ LiquidAssets::Config.configure do |config|
154
+ config.namespace = 'FANCY_NAME'
155
+ end
156
+
157
+ If you do modify the namespace, you *may* have to clean Rails asset
158
+ cache by running *'rake assets:clean'* In my experience, sometimes
159
+ Rails doesn't notice when vendor assets ERB variables change and may
160
+ not regenerate the template.
161
+
162
+ ## Result
163
+
164
+ The output from the template should be identical from both Ruby & Javascript:
165
+
166
+ Hello Bob,
167
+ Thanks for stopping by!
168
+
169
+ Jimmy Smith's age is 23.
170
+
171
+ They will be 33 in ten years.
172
+
173
+ This post is copyright BigCorp Inc.
174
+
175
+
176
+ ### evaluating liquid templates from string
177
+
178
+ template = LiquidAssets.parse( 'A {{name|upcase}} template' )
179
+ template.render({ :name=>'liquid' })
180
+
181
+ => 'A Liquid template'
182
+
183
+
184
+ ## Thanks
185
+
186
+ [Shopify](http://www.shopify.com/)
187
+ for creating the liquid template language and Ruby implementation. [leizongmin](https://github.com/leizongmin/tinyliquid) for the
188
+ tinyliquid Javascript support.
189
+
190
+ 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
191
+ are thanks to those projects, mistakes are mine.
20
192
 
21
- TODO: Write usage instructions here
22
193
 
23
194
  ## Contributing
195
+ Fork on [github](https://github.com/nathanstitt/liquid_assets), implement your change, submit a pull request.
196
+
197
+
198
+ ## Copyright
24
199
 
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
200
+ Copyright (c) 2013 Nathan Stitt. See LICENSE.txt for
201
+ further details, *it's MIT*
data/Rakefile CHANGED
@@ -16,7 +16,7 @@ require 'rake/testtask'
16
16
  Rake::TestTask.new(:test) do |test|
17
17
  test.libs << 'lib' << 'test'
18
18
  test.pattern = 'test/**/test_*.rb'
19
- test.verbose = true
19
+ test.verbose = false
20
20
  end
21
21
 
22
22
  task :default => :test
@@ -96,7 +96,7 @@ module LiquidAssets
96
96
  end
97
97
 
98
98
  def filters
99
- @filters ||= Liquid::StandardFilters
99
+ @filters ||= LiquidAssets::TemplateFilters
100
100
  end
101
101
  def namespace
102
102
  @namespace ||= 'LQT'
@@ -1,5 +1,3 @@
1
- require 'liquid_assets/pipeline_template_engine'
2
-
3
1
  module LiquidAssets
4
2
 
5
3
  class Engine < ::Rails::Engine
@@ -1,4 +1,3 @@
1
-
2
1
  module LiquidAssets
3
2
 
4
3
 
@@ -16,5 +15,19 @@ module LiquidAssets
16
15
  LiquidWrapper.new( ::Liquid::Template.parse( source ) )
17
16
  end
18
17
 
18
+ def self.template( path )
19
+ tmpl = Config.content_provider.call( path )
20
+ if tmpl && tmpl.present?
21
+ source = tmpl.source
22
+ else
23
+ full_path = Config.template_root_path.join( "#{path}.liquid" )
24
+ if full_path.exist?
25
+ source = File.read( full_path )
26
+ else
27
+ raise Liquid::FileSystemError, "No such template '#{path}' #{full_path}"
28
+ end
29
+ end
30
+ LiquidWrapper.new( ::Liquid::Template.parse( source ) )
31
+ end
19
32
 
20
33
  end
@@ -0,0 +1,12 @@
1
+ # -*- coding: utf-8 -*-
2
+ module LiquidAssets
3
+ module Filters
4
+
5
+ extend Liquid::StandardFilters
6
+
7
+ def titleize( input )
8
+ input.to_s.gsub(/\b([\S])/){ |m| m.upcase }
9
+ end
10
+
11
+ end
12
+ end
@@ -8,11 +8,11 @@ module LiquidAssets
8
8
 
9
9
 
10
10
  def read_template_file( template_path, context )
11
- source = Config.content_provider.call( Resolver.convert_path_to_partial( template_path.dup ) )
12
- if false == source
13
- return super
11
+ tmpl = Config.content_provider.call( Resolver.convert_path_to_partial( template_path.dup ) )
12
+ if tmpl && tmpl.present?
13
+ return tmpl.source
14
14
  else
15
- return source
15
+ return super
16
16
  end
17
17
  end
18
18
 
@@ -6,16 +6,14 @@ module LiquidAssets
6
6
 
7
7
  self.default_mime_type = 'application/javascript'
8
8
 
9
- # def initialize_engine
10
- # end
11
-
12
9
  def evaluate(scope, locals, &block)
13
- template_path = TemplatePath.new scope
14
-
15
- source = Config.content_provider.call( template_path.name )
16
- if false == source
17
- source = data
18
- end
10
+ template_path = TemplatePath.new( scope )
11
+ tmpl = Config.content_provider.call( template_path.name )
12
+ source = if tmpl && tmpl.present?
13
+ tmpl.source
14
+ else
15
+ data
16
+ end
19
17
  "#{LiquidAssets::Config.namespace}.Templates[#{template_path.name.dump}] = #{ TinyLiquid.compile( source ) };"
20
18
  end
21
19
 
@@ -12,22 +12,12 @@ module LiquidAssets
12
12
  end
13
13
 
14
14
  def find_templates(name, prefix, partial, details)
15
-
16
- source = Config.content_provider.call( name )
17
- if false == source
18
- return []
15
+ path = normalize_path( prefix, name )
16
+ tmpl = Config.content_provider.call( partial_path( path, partial ) )
17
+ if tmpl && tmpl.present?
18
+ return [ make_template( tmpl, path, details, partial ) ]
19
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
20
+ return []
31
21
  end
32
22
  end
33
23
 
@@ -43,17 +33,18 @@ module LiquidAssets
43
33
  end
44
34
  end
45
35
 
46
- def make_template( source, path, details, partial )
36
+ def make_template( tmpl, path, details, partial )
47
37
  handler = ::ActionView::Template.registered_template_handler('.liquid')
48
38
  details = {
49
39
  :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
40
+ :locale => details[:locale].first.to_s,
41
+ :format => details[:formats].first.to_s,
42
+ :handler => details[:handlers].map(&:to_s),
43
+ :updated_at => tmpl.mtime,
44
+ :partial => partial || false
54
45
  }
55
46
  handler = ActionView::Template.registered_template_handler(:liquid)
56
- return ActionView::Template.new(source, "LiquidTemplate - #{path}", handler, details)
47
+ return ActionView::Template.new( tmpl.source, "LiquidTemplate - #{path}", handler, details)
57
48
  end
58
49
 
59
50
  def partial_path( path, partial )
@@ -0,0 +1,18 @@
1
+ module LiquidAssets
2
+
3
+ class Template
4
+
5
+ attr_reader :mtime, :source
6
+
7
+ def initialize( source, mtime=Time.now )
8
+ @source = source
9
+ @mtime = mtime
10
+ end
11
+
12
+ def present?
13
+ ! @source.nil? && ! @source.empty?
14
+ end
15
+
16
+ end
17
+
18
+ end
@@ -6,33 +6,26 @@ module LiquidAssets
6
6
  class TemplateHandler
7
7
 
8
8
  def self.call(template)
9
- return "LiquidAssets::TemplateHandler.new(self).render(#{template.source.inspect}, local_assigns)"
9
+ dump = Marshal.dump( LiquidAssets.parse( template ) )
10
+ return "LiquidAssets::TemplateHandler.render(#{dump.inspect}, self, local_assigns)"
10
11
  end
11
12
 
12
- def initialize(view)
13
- @view = view
14
- end
15
-
16
- def render(template, local_assigns = {})
17
- @view.controller.headers["Content-Type"] ||= 'text/html; charset=utf-8'
13
+ def self.render( src, view, local_assigns )
14
+ view.controller.headers["Content-Type"] ||= 'text/html; charset=utf-8'
18
15
 
19
- assigns = @view.assigns.dup
16
+ assigns = view.assigns.dup
20
17
  assigns.merge!( local_assigns.stringify_keys )
21
18
 
22
- if content = @view.content_for?(:layout)
19
+ if content = view.content_for?(:layout)
23
20
  assigns["content_for_layout"] = content
24
21
  end
25
- LiquidAssets.parse(template).render( assigns, :registers=>{
26
- :action_view => @view,
27
- :controller => @view.controller
28
- } ).html_safe
29
- end
30
22
 
31
- def compilable?
32
- false
23
+ Marshal.load( src ).render( assigns, :registers=>{
24
+ :action_view => view,
25
+ :controller => view.controller
26
+ } ).html_safe
33
27
  end
34
28
 
35
-
36
29
  end
37
30
 
38
31
  end
@@ -1,3 +1,3 @@
1
1
  module LiquidAssets
2
- VERSION = "0.3.3"
2
+ VERSION = "0.4.2"
3
3
  end
data/lib/liquid_assets.rb CHANGED
@@ -4,21 +4,21 @@ require 'liquid_assets/config'
4
4
  require 'liquid_assets/template_handler'
5
5
  require 'liquid_assets/liquid_file_system'
6
6
  require 'liquid_assets/resolver'
7
+ require 'liquid_assets/filters'
8
+ require 'liquid_assets/pipeline_template_engine'
9
+ require 'liquid_assets/tiny_liquid'
10
+ require 'liquid_assets/template'
7
11
 
8
12
  module LiquidAssets
9
13
 
10
14
  extend Config
11
15
 
12
- autoload :TinyLiquid, 'liquid_assets/tiny_liquid'
13
- autoload :PipelineTemplateEngine, 'liquid_assets/pipeline_template_engine'
14
-
15
16
  if defined? Rails
16
17
  require 'liquid_assets/engine'
17
18
  else
18
19
  require 'sprockets'
19
20
  Config.load_yml! if Config.yml_exists?
20
-
21
21
  Sprockets.register_engine ".liquid", Tilt
22
-
23
22
  end
23
+
24
24
  end
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_dependency 'liquid'
22
22
  spec.add_dependency 'tilt'
23
23
  spec.add_dependency 'execjs'
24
+ spec.add_dependency 'sprockets'
24
25
  spec.add_dependency 'actionpack', '>=3.2'
25
26
 
26
27
  spec.add_development_dependency "bundler", "~> 1.3"
@@ -25,28 +25,29 @@ tmpl="LQT.Templates[\"path/to/template\"] = function(locals,fil
25
25
  def test_template_rendering
26
26
  locals = {foo:'bar'}
27
27
  source = 'foo={{foo}}'
28
- template = LiquidAssets::TemplateHandler.new(DummyView.new).render(source, locals)
28
+ compiled = LiquidAssets::TemplateHandler.call(DummyView.new)
29
+ p compiled
29
30
  assert_equal 'foo=bar', template
30
31
  end
31
32
 
32
33
 
33
34
  def test_resolver
34
35
  LiquidAssets::Config.content_provider = lambda do | path |
35
- 'good' == path ? 'Hello {{bob|upcase}}' : false
36
+ 'good' == path ? LiquidAssets::Template.new('Hello {{bob|upcase}}') : false
36
37
  end
37
38
 
38
39
  details = {:formats=>[:liquid], :locale=>[:en], :handlers=>[] }
39
40
  resolver = LiquidAssets::Resolver.instance
40
41
 
41
- assert_empty resolver.find_all('bad','',false, details )
42
- assert_not_empty resolver.find_all('good','',false, details )
42
+ assert_empty resolver.find_all('bad', '' ,false, details )
43
+ assert_not_empty resolver.find_all('good','', false, details )
43
44
  end
44
45
 
45
46
  def test_resolver_caches
46
47
  times_called = 0
47
48
  LiquidAssets::Config.content_provider = lambda do | path |
48
49
  times_called += 1
49
- 'foo/bar/good' == path ? 'Hello {{bob|upcase}}' : false
50
+ 'foo/bar/good' == path ? LiquidAssets::Template.new('Hello {{bob|upcase}}') : false
50
51
  end
51
52
 
52
53
  details = {:formats=>[:liquid], :locale=>[:en], :handlers=>[] }
@@ -59,18 +60,11 @@ tmpl="LQT.Templates[\"path/to/template\"] = function(locals,fil
59
60
 
60
61
  times_called = 0
61
62
 
62
- resolver.clear_cache_for( 'bad' ) # shouldn't clear cache for 'good'
63
-
64
- resolver.find_all('foo/bar/good',nil,false, details, key )
65
-
66
- assert_equal 0, times_called
67
-
68
- resolver.clear_cache_for( 'foo/bar/good' )
63
+ resolver.clear_cache
69
64
 
70
65
  resolver.find_all('foo/bar/good',nil,false, details, key )
71
66
 
72
67
  assert_equal 1, times_called
73
-
74
-
75
68
  end
69
+
76
70
  end
@@ -1,5 +1,9 @@
1
1
  (function( namespace, document, undefined) {
2
2
 
3
+ Array.isArray || (Array.isArray = function ( a ) {
4
+ return'' + a !== a && {}.toString.call( a ) == '[object Array]'
5
+ });
6
+
3
7
  namespace = namespace.<%= LiquidAssets::Config.namespace%> || (namespace.<%=LiquidAssets::Config.namespace%>={});
4
8
  namespace.Templates || ( namespace.Templates={} );
5
9
 
@@ -110,6 +114,14 @@ word-wrap:break-word; z-index:9999">' + msg + '</pre>';
110
114
  upcase: function(input) {
111
115
  return toString(input).toUpperCase();
112
116
  },
117
+ capitalize: function(input){
118
+ return string.charAt(0).toUpperCase() + string.slice(1);
119
+ },
120
+ titleize: function(input){
121
+ if (input == null) return '';
122
+ input = String(input).toLowerCase();
123
+ return input.replace(/(?:^|\s|-)\S/g, function(c){ return c.toUpperCase(); });
124
+ },
113
125
  append: function(input, other) {
114
126
  return [toString(input), toString(other)].join();
115
127
  },
@@ -188,12 +200,17 @@ word-wrap:break-word; z-index:9999">' + msg + '</pre>';
188
200
  }
189
201
  return input.split(pattern);
190
202
  },
203
+ escape: function(input) {
204
+ var chr = { '"': '&quot;', '&': '&amp;', '<': '&lt;', '>': '&gt;' };
205
+ return text ? text.replace(/[\"&<>]/g, function (a) { return chr[a]; }) : '';
206
+ },
191
207
  join: function(input, glue) {
192
208
  if (glue == null) {
193
209
  glue = ' ';
194
210
  }
195
211
  return _(input).flatten().join(glue);
196
212
  },
213
+
197
214
  first: function(array) {
198
215
  if (array.length > 0) {
199
216
  return array[0];
data/vendor/tinyliquid.js CHANGED
@@ -7,6 +7,10 @@
7
7
 
8
8
  var TinyLiquid = (function (exports) {
9
9
 
10
+ Array.isArray || (Array.isArray = function ( a ) {
11
+ return'' + a !== a && {}.toString.call( a ) == '[object Array]'
12
+ });
13
+
10
14
  var modules = {};
11
15
 
12
16
  /*--------------- ./lib/md5.js ----------------*/
@@ -373,7 +377,7 @@ exports.condition = function (cond, context) {
373
377
  return '(' + localsWrap(ca[0]) + ')';
374
378
  }
375
379
  if (ca.length === 3) {
376
- var op1 = localsWrap(ca[0]);
380
+ var op1 = localsWrap( ca[0].replace(/\.(size)$/,".length") );
377
381
  var op2 = localsWrap(ca[2]);
378
382
  ca[1] = ca[1].toLowerCase();
379
383
  if (ca[1] === 'contains') {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: liquid_assets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Stitt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-11 00:00:00.000000000 Z
11
+ date: 2013-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: liquid
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sprockets
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: actionpack
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -112,9 +126,11 @@ files:
112
126
  - lib/liquid_assets/config.rb
113
127
  - lib/liquid_assets/engine.rb
114
128
  - lib/liquid_assets/eval.rb
129
+ - lib/liquid_assets/filters.rb
115
130
  - lib/liquid_assets/liquid_file_system.rb
116
131
  - lib/liquid_assets/pipeline_template_engine.rb
117
132
  - lib/liquid_assets/resolver.rb
133
+ - lib/liquid_assets/template.rb
118
134
  - lib/liquid_assets/template_handler.rb
119
135
  - lib/liquid_assets/tiny_liquid.rb
120
136
  - lib/liquid_assets/version.rb