liquidizer 0.1.0 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +41 -22
- data/VERSION +1 -1
- data/lib/liquidizer/controller_extensions.rb +68 -77
- data/lib/liquidizer/file_system.rb +13 -0
- data/lib/liquidizer/liquid_template.rb +2 -2
- data/lib/liquidizer/support.rb +3 -10
- data/liquidizer.gemspec +9 -4
- data/test/controller_extensions_test.rb +90 -33
- data/test/file_system_test.rb +18 -0
- data/test/fixtures/layouts/layout.html.erb +1 -0
- data/test/fixtures/posts/show.html.erb +1 -0
- metadata +10 -5
- /data/test/fixtures/{ratings → comments}/_stuff.html.erb +0 -0
data/README.rdoc
CHANGED
@@ -29,28 +29,20 @@ And add this to your config/environment.rb:
|
|
29
29
|
First you have to specify which actions of which controllers should be liquified (rendered
|
30
30
|
with loadable liquid templates). To do that, use the +liquify+ controller macro:
|
31
31
|
|
32
|
-
class
|
32
|
+
class PostsController < ApplicationController
|
33
33
|
# This will apply the templates to all actions in this controller.
|
34
34
|
liquify
|
35
35
|
end
|
36
36
|
|
37
|
-
|
38
|
-
|
37
|
+
You can use the :only and :except options that work the same as for filters to limit the
|
38
|
+
set of actions to liquify:
|
39
39
|
|
40
|
-
class
|
41
|
-
|
42
|
-
liquify :show, :index
|
40
|
+
class PostsController < ApplicationController
|
41
|
+
liquify :only => [:show, :index]
|
43
42
|
end
|
44
43
|
|
45
|
-
|
46
|
-
|
47
|
-
template called "posts/index". Namespaced controllers work too: index in Blog::PostsController
|
48
|
-
will have template "blog/posts/index". This, however, can be overriden:
|
49
|
-
|
50
|
-
|
51
|
-
class PostController < ApplicationController
|
52
|
-
# This will liquify only show, but will use template called "awesome_show_template"
|
53
|
-
liquify :show, :as => 'awesome_show_template'
|
44
|
+
class CommentsController < ApplicationController
|
45
|
+
liquify :except => :edit
|
54
46
|
end
|
55
47
|
|
56
48
|
The +liquify+ macro is inherited, so if you want to apply liquid templates to all actions
|
@@ -62,18 +54,26 @@ controllers, if you want:
|
|
62
54
|
end
|
63
55
|
|
64
56
|
class PostsController < ApplicationController
|
65
|
-
liquify :
|
66
|
-
liquify :index, :as => 'hardcore_index'
|
57
|
+
liquify :only => :show
|
67
58
|
end
|
68
59
|
|
69
|
-
|
60
|
+
The layout is also liquified by default. You can disable it using the :layout => false options.
|
61
|
+
Note that this will disable layout rendering with liquid, not layout rendering in general.
|
70
62
|
|
71
63
|
class ApplicationController < ActionController::Base
|
72
|
-
|
73
|
-
|
64
|
+
liquify :layout => false
|
65
|
+
end
|
74
66
|
|
75
|
-
|
76
|
-
|
67
|
+
The Liqidizer uses the same naming convention for templates as Rails. So for the
|
68
|
+
Blog::PostsController's action :index, the looked up template will be "blog/posts/index". If
|
69
|
+
you want to override it, do it the standard Rails way:
|
70
|
+
|
71
|
+
class PostsController < ApplicationController
|
72
|
+
liquify
|
73
|
+
|
74
|
+
def index
|
75
|
+
render :template => 'more_awesome_index_template'
|
76
|
+
end
|
77
77
|
end
|
78
78
|
|
79
79
|
The last step is to tell Liquidizer where to load the liquid templates from. The way to implement
|
@@ -153,6 +153,25 @@ Then you can do this in your liquid template:
|
|
153
153
|
|
154
154
|
And the post.title will call PostDrop#title, filtering all nasty stuff.
|
155
155
|
|
156
|
+
If the instance variable is an array (also association collection, active record scope or
|
157
|
+
this kind of stuff), all it's elements will be dropified too:
|
158
|
+
|
159
|
+
class PostsController < ActiveRecord::Base
|
160
|
+
liquify
|
161
|
+
|
162
|
+
def index
|
163
|
+
@posts = current_blog.posts
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
Then in your liquid tempalte:
|
168
|
+
|
169
|
+
{% for post in posts %}
|
170
|
+
<h2>{{ post.title }}</h2>
|
171
|
+
|
172
|
+
<!-- more stuff -->
|
173
|
+
{% endfor %}
|
174
|
+
|
156
175
|
The way how variables are wrapped with drops can be completelly customized by overriding the
|
157
176
|
+dropify+ method.
|
158
177
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.2
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'liquid'
|
2
2
|
require 'liquidizer/support'
|
3
|
+
require 'liquidizer/file_system'
|
3
4
|
|
4
5
|
module Liquidizer
|
5
6
|
module ControllerExtensions
|
@@ -8,16 +9,18 @@ module Liquidizer
|
|
8
9
|
extend ClassMethods
|
9
10
|
alias_method_chain :render, :liquid
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
class_inheritable_hash :liquidizer_options
|
13
|
+
self.liquidizer_options ||= {}
|
14
|
+
|
15
|
+
before_filter :set_liquid_file_system
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
17
|
-
def render_with_liquid(options =
|
18
|
-
if
|
19
|
+
def render_with_liquid(options = nil, &block)
|
20
|
+
if view_template = liquid_template_for_view(options)
|
21
|
+
options ||= {}
|
19
22
|
assigns = assigns_for_liquify
|
20
|
-
content =
|
23
|
+
content = view_template.render!(assigns)
|
21
24
|
|
22
25
|
if layout_template = liquid_template_for_layout(options)
|
23
26
|
content = layout_template.render!(assigns.merge('content_for_layout' => content))
|
@@ -28,6 +31,7 @@ module Liquidizer
|
|
28
31
|
else
|
29
32
|
if layout_template = liquid_template_for_layout(options)
|
30
33
|
assigns = assigns_for_liquify
|
34
|
+
options ||= {}
|
31
35
|
|
32
36
|
content = render_to_string(options.merge(:layout => false))
|
33
37
|
content = layout_template.render!(assigns.merge('content_for_layout' => content))
|
@@ -41,38 +45,47 @@ module Liquidizer
|
|
41
45
|
|
42
46
|
private
|
43
47
|
|
44
|
-
def
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
48
|
+
def liquid_template_for_view(options)
|
49
|
+
name = options && options[:template]
|
50
|
+
|
51
|
+
unless name
|
52
|
+
action = extract_action_for_render(options)
|
53
|
+
|
54
|
+
if action && liquify?(action)
|
55
|
+
name = liquid_template_name_for_action(action)
|
56
|
+
end
|
52
57
|
end
|
58
|
+
|
59
|
+
name && find_and_parse_liquid_template(name)
|
53
60
|
end
|
54
61
|
|
55
62
|
def liquify?(action)
|
56
|
-
self.class.
|
57
|
-
|
58
|
-
|
63
|
+
options = self.class.liquidizer_options
|
64
|
+
|
65
|
+
return false unless options[:actions]
|
66
|
+
return false if options[:only] && !Array.wrap(options[:only]).include?(action.to_sym)
|
67
|
+
return false if options[:except] && Array.wrap(options[:except]).include?(action.to_sym)
|
68
|
+
|
69
|
+
true
|
59
70
|
end
|
60
71
|
|
61
72
|
def liquid_template_for_layout(options)
|
62
73
|
if liquify_layout?(options)
|
63
|
-
|
74
|
+
name = liquid_template_name_for_layout(options)
|
75
|
+
name && find_and_parse_liquid_template(name)
|
64
76
|
else
|
65
77
|
nil
|
66
78
|
end
|
67
79
|
end
|
68
80
|
|
69
81
|
def liquify_layout?(options)
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
82
|
+
options ||= {}
|
83
|
+
|
84
|
+
return false unless self.class.liquidizer_options[:layout]
|
85
|
+
return true if options[:layout].nil? && liquifiable_options?(options)
|
86
|
+
return true if options[:layout] == true
|
87
|
+
|
88
|
+
false
|
76
89
|
end
|
77
90
|
|
78
91
|
def extract_action_for_render(options)
|
@@ -84,7 +97,7 @@ module Liquidizer
|
|
84
97
|
action_name
|
85
98
|
else
|
86
99
|
nil
|
87
|
-
end
|
100
|
+
end
|
88
101
|
end
|
89
102
|
|
90
103
|
UNLIQUIFIABLE_OPTIONS = [:partial, :template, :file, :text, :xml, :json, :js, :inline]
|
@@ -105,11 +118,15 @@ module Liquidizer
|
|
105
118
|
end
|
106
119
|
|
107
120
|
def liquid_template_name_for_action(action)
|
108
|
-
|
121
|
+
"#{controller_path}/#{action}"
|
109
122
|
end
|
110
123
|
|
111
|
-
def
|
112
|
-
|
124
|
+
def liquid_template_name_for_layout(options)
|
125
|
+
case layout = self.class.read_inheritable_attribute(:layout)
|
126
|
+
when Symbol then __send__(layout)
|
127
|
+
when Proc then layout.call(self)
|
128
|
+
else layout
|
129
|
+
end
|
113
130
|
end
|
114
131
|
|
115
132
|
def find_liquid_template(name)
|
@@ -130,8 +147,7 @@ module Liquidizer
|
|
130
147
|
assign_name = name[/^@(.*)$/, 1] # strip @
|
131
148
|
next memo if assign_name.starts_with?('_') # skip "private" ivars
|
132
149
|
|
133
|
-
value = instance_variable_get(name)
|
134
|
-
value = dropify(value) unless value.respond_to?(:to_liquid)
|
150
|
+
value = dropify(instance_variable_get(name))
|
135
151
|
|
136
152
|
memo[assign_name] = value if value
|
137
153
|
memo
|
@@ -142,8 +158,16 @@ module Liquidizer
|
|
142
158
|
#
|
143
159
|
# Foo::Bar -> Foo::BarDrop
|
144
160
|
def dropify(value)
|
145
|
-
|
146
|
-
|
161
|
+
if value.respond_to?(:to_liquid)
|
162
|
+
if value.is_a?(Array)
|
163
|
+
value.map { |element| dropify(element) }
|
164
|
+
else
|
165
|
+
value
|
166
|
+
end
|
167
|
+
else
|
168
|
+
drop_class = infer_drop_class(value)
|
169
|
+
drop_class && drop_class.new(value)
|
170
|
+
end
|
147
171
|
end
|
148
172
|
|
149
173
|
def infer_drop_class(value)
|
@@ -153,62 +177,29 @@ module Liquidizer
|
|
153
177
|
Support.constant_defined?(name) ? name.constantize : nil
|
154
178
|
end
|
155
179
|
|
180
|
+
def set_liquid_file_system
|
181
|
+
Liquid::Template.file_system = FileSystem.new { current_liquid_templates }
|
182
|
+
end
|
183
|
+
|
156
184
|
module ClassMethods
|
157
|
-
#
|
185
|
+
# Enables liquid rendering.
|
158
186
|
#
|
159
187
|
# == Examples
|
160
188
|
#
|
161
189
|
# # liquify all actions
|
162
190
|
# liquify
|
163
191
|
#
|
164
|
-
# # also liquify all actions
|
165
|
-
# liquify :all
|
166
|
-
#
|
167
192
|
# # liquify only show and index
|
168
|
-
# liquify :show, :index
|
169
|
-
#
|
170
|
-
# # liquify only edit, but use template called awesome_edit
|
171
|
-
# liquify :edit, :as => 'awesome_edit'
|
172
|
-
#
|
173
|
-
# Unless you specify template name with the :as options, the name will be
|
174
|
-
# inferend from controller and action names thusly:
|
175
|
-
#
|
176
|
-
# controller Blog, action :index - blogs/index
|
177
|
-
# controller Blog, action :show - blogs/show
|
178
|
-
# controller Blog, action :edit - blogs/edit
|
179
|
-
#
|
180
|
-
# controller Blog::Post, action :index - blog/posts/index
|
181
|
-
# controller Blog::Post, action :show - blog/posts/show
|
182
|
-
# controller Blog::Post, action :edit - blog/posts/edit
|
183
|
-
#
|
184
|
-
# You've got the idea.
|
185
|
-
#
|
186
|
-
def liquify(*actions)
|
187
|
-
options = actions.extract_options!
|
188
|
-
actions = actions.map(&:to_sym)
|
189
|
-
|
190
|
-
self.liquify_actions = actions.empty? ? :all : actions
|
191
|
-
self.liquid_template_names_for_actions = {}
|
192
|
-
|
193
|
-
if options[:as]
|
194
|
-
actions.each do |action|
|
195
|
-
self.liquid_template_names_for_actions[action] = options[:as]
|
196
|
-
end
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
# Liquify the layout.
|
201
|
-
#
|
202
|
-
# == Examples
|
193
|
+
# liquify :only => [:show, :index]
|
203
194
|
#
|
204
|
-
# #
|
205
|
-
#
|
195
|
+
# # liquify all except show and index
|
196
|
+
# liquify :except => [:show, :index]
|
206
197
|
#
|
207
|
-
# #
|
208
|
-
#
|
198
|
+
# # liquify all, but do not liquify layout
|
199
|
+
# liquify :layout => false
|
209
200
|
#
|
210
|
-
def
|
211
|
-
self.
|
201
|
+
def liquify(options = {})
|
202
|
+
self.liquidizer_options = options.reverse_merge(:actions => true, :layout => true)
|
212
203
|
end
|
213
204
|
end
|
214
205
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Liquidizer
|
2
|
+
# File system for liquid that loads the templates from the database
|
3
|
+
class FileSystem
|
4
|
+
def initialize(&block)
|
5
|
+
@source = block
|
6
|
+
end
|
7
|
+
|
8
|
+
def read_template_file(template_path)
|
9
|
+
record = @source.call.find_by_name(template_path)
|
10
|
+
record && record.content
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -6,10 +6,10 @@ module Liquidizer
|
|
6
6
|
|
7
7
|
module ClassMethods
|
8
8
|
def find_by_name(name)
|
9
|
-
first(:conditions => {:name => name}) ||
|
9
|
+
first(:conditions => {:name => name}) || find_default_by_name(name)
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
12
|
+
def find_default_by_name(name)
|
13
13
|
file_name = File.join(Liquidizer.template_path, name) + '.liquid'
|
14
14
|
|
15
15
|
if File.exist?(file_name)
|
data/lib/liquidizer/support.rb
CHANGED
@@ -2,16 +2,9 @@ module Liquidizer
|
|
2
2
|
module Support
|
3
3
|
# This is like Object.const_defined?, but works with namespaced constants (Foo::Bar::Baz).
|
4
4
|
def self.constant_defined?(name)
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
base = base.const_get(name)
|
9
|
-
else
|
10
|
-
return false
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
true
|
5
|
+
name.constantize && true
|
6
|
+
rescue NameError
|
7
|
+
false
|
15
8
|
end
|
16
9
|
end
|
17
10
|
end
|
data/liquidizer.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{liquidizer}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Adam Cig\303\241nek"]
|
12
|
-
s.date = %q{2010-03-
|
12
|
+
s.date = %q{2010-03-09}
|
13
13
|
s.description = %q{WIth this gem, you can render your Ruby on Rails views with liquid templates that are loaded from database. This way, the look and feel of your site can be safely configured by it's users.
|
14
14
|
}
|
15
15
|
s.email = %q{adam.ciganek@gmail.com}
|
@@ -24,15 +24,19 @@ Gem::Specification.new do |s|
|
|
24
24
|
"app/models/liquid_template.rb",
|
25
25
|
"lib/liquidizer.rb",
|
26
26
|
"lib/liquidizer/controller_extensions.rb",
|
27
|
+
"lib/liquidizer/file_system.rb",
|
27
28
|
"lib/liquidizer/liquid_template.rb",
|
28
29
|
"lib/liquidizer/migration_extensions.rb",
|
29
30
|
"lib/liquidizer/support.rb",
|
30
31
|
"liquidizer.gemspec",
|
31
32
|
"rails/init.rb",
|
32
33
|
"test/controller_extensions_test.rb",
|
34
|
+
"test/file_system_test.rb",
|
35
|
+
"test/fixtures/comments/_stuff.html.erb",
|
33
36
|
"test/fixtures/comments/index.html.erb",
|
37
|
+
"test/fixtures/layouts/layout.html.erb",
|
34
38
|
"test/fixtures/posts/index.liquid",
|
35
|
-
"test/fixtures/
|
39
|
+
"test/fixtures/posts/show.html.erb",
|
36
40
|
"test/fixtures/ratings/edit.html.erb",
|
37
41
|
"test/fixtures/spams/index.html.erb",
|
38
42
|
"test/liquid_template_test.rb",
|
@@ -48,7 +52,8 @@ Gem::Specification.new do |s|
|
|
48
52
|
"test/support_test.rb",
|
49
53
|
"test/liquid_template_test.rb",
|
50
54
|
"test/controller_extensions_test.rb",
|
51
|
-
"test/test_helper.rb"
|
55
|
+
"test/test_helper.rb",
|
56
|
+
"test/file_system_test.rb"
|
52
57
|
]
|
53
58
|
|
54
59
|
if s.respond_to? :specification_version then
|
@@ -11,10 +11,12 @@ class BaseController < ActionController::Base
|
|
11
11
|
end
|
12
12
|
|
13
13
|
class PostsController < BaseController
|
14
|
+
layout 'layout'
|
14
15
|
liquify
|
15
16
|
|
16
17
|
def index
|
17
18
|
@title = 'Hello blog!'
|
19
|
+
@posts = [Post.new(:title => 'First post'), Post.new(:title => 'Second post')]
|
18
20
|
end
|
19
21
|
|
20
22
|
def show
|
@@ -28,32 +30,26 @@ class PostsController < BaseController
|
|
28
30
|
def create
|
29
31
|
render :status => :created
|
30
32
|
end
|
31
|
-
end
|
32
|
-
|
33
|
-
class CommentsController < BaseController
|
34
|
-
liquify :show
|
35
|
-
liquify :edit, :as => 'funky_comments_edit'
|
36
33
|
|
37
|
-
def
|
38
|
-
|
39
|
-
|
40
|
-
def show
|
34
|
+
def new
|
35
|
+
render :template => 'more_awesome_new'
|
41
36
|
end
|
42
37
|
|
43
38
|
def edit
|
39
|
+
render :layout => 'awesome_layout'
|
44
40
|
end
|
45
41
|
end
|
46
42
|
|
47
|
-
class
|
48
|
-
|
49
|
-
|
43
|
+
class CommentsController < BaseController
|
44
|
+
layout 'layout'
|
45
|
+
liquify :only => :show
|
50
46
|
|
51
|
-
def
|
47
|
+
def index
|
52
48
|
end
|
53
49
|
|
54
|
-
def
|
50
|
+
def show
|
55
51
|
end
|
56
|
-
|
52
|
+
|
57
53
|
def new
|
58
54
|
render :partial => 'stuff'
|
59
55
|
end
|
@@ -63,7 +59,16 @@ class RatingsController < BaseController
|
|
63
59
|
end
|
64
60
|
end
|
65
61
|
|
62
|
+
class RatingsController < BaseController
|
63
|
+
liquify :layout => false
|
64
|
+
|
65
|
+
def show
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
66
69
|
class SpamsController < BaseController
|
70
|
+
layout 'layout'
|
71
|
+
|
67
72
|
def index
|
68
73
|
end
|
69
74
|
end
|
@@ -130,13 +135,23 @@ class ControllerExtensionsTest < ActionController::TestCase
|
|
130
135
|
test 'renders with liquid template when explicit action specified' do
|
131
136
|
setup_controller(PostsController)
|
132
137
|
|
133
|
-
LiquidTemplate.create!(:name => 'posts/edit',
|
138
|
+
LiquidTemplate.create!(:name => 'posts/edit', :content => "<p>edit post</p>")
|
134
139
|
LiquidTemplate.create!(:name => 'posts/update', :content => "<p>update post</p>")
|
135
140
|
|
136
141
|
get :update
|
137
142
|
assert_select 'p', 'edit post'
|
138
143
|
end
|
139
144
|
|
145
|
+
test 'renders with liquid template when explicit template specified' do
|
146
|
+
setup_controller(PostsController)
|
147
|
+
|
148
|
+
LiquidTemplate.create!(:name => 'more_awesome_new', :content => "<p>more awesome new</p>")
|
149
|
+
LiquidTemplate.create!(:name => 'posts/new', :content => "<p>less awesome new</p>")
|
150
|
+
|
151
|
+
get :new
|
152
|
+
assert_select 'p', 'more awesome new'
|
153
|
+
end
|
154
|
+
|
140
155
|
test 'preserves additional render options' do
|
141
156
|
setup_controller(PostsController)
|
142
157
|
|
@@ -157,23 +172,13 @@ class ControllerExtensionsTest < ActionController::TestCase
|
|
157
172
|
setup_controller(SpamsController)
|
158
173
|
|
159
174
|
get :index
|
160
|
-
assert_select 'h1', 'This is not liquid template'
|
161
|
-
end
|
162
|
-
|
163
|
-
test 'renders with liquid template with custom name' do
|
164
|
-
setup_controller(CommentsController)
|
165
|
-
|
166
|
-
LiquidTemplate.create!(:name => 'comments/edit', :content => "<p>default edit</p>")
|
167
|
-
LiquidTemplate.create!(:name => 'funky_comments_edit', :content => "<p>funky edit</p>")
|
168
|
-
|
169
|
-
get :edit
|
170
|
-
assert_select 'p', 'funky edit'
|
175
|
+
assert_select '#layout h1', 'This is not liquid template'
|
171
176
|
end
|
172
177
|
|
173
178
|
test 'renders liquid template with liquid layout' do
|
174
|
-
setup_controller(
|
179
|
+
setup_controller(PostsController)
|
175
180
|
|
176
|
-
LiquidTemplate.create!(:name => '
|
181
|
+
LiquidTemplate.create!(:name => 'posts/show', :content => '<p>This is liquid template</p>')
|
177
182
|
LiquidTemplate.create!(:name => 'layout',
|
178
183
|
:content => '<div id="layout">{{ content_for_layout }}</div>')
|
179
184
|
|
@@ -182,17 +187,45 @@ class ControllerExtensionsTest < ActionController::TestCase
|
|
182
187
|
end
|
183
188
|
|
184
189
|
test 'renders solid template with liquid layout' do
|
185
|
-
setup_controller(
|
190
|
+
setup_controller(PostsController)
|
186
191
|
|
187
192
|
LiquidTemplate.create!(:name => 'layout',
|
188
193
|
:content => '<div id="layout">{{ content_for_layout }}</div>')
|
189
194
|
|
190
|
-
get :
|
195
|
+
get :show
|
191
196
|
assert_select '#layout p', 'This is not liquid template'
|
192
197
|
end
|
193
198
|
|
194
|
-
|
199
|
+
# TODO: make this pass
|
200
|
+
# test 'renders with overriden liquid layout' do
|
201
|
+
# setup_controller(PostsController)
|
202
|
+
|
203
|
+
# LiquidTemplate.create!(
|
204
|
+
# :name => 'awesome_layout',
|
205
|
+
# :content => '<div id="awesome_layout">{{ content_for_layout }}</div>')
|
206
|
+
|
207
|
+
# LiquidTemplate.create!(
|
208
|
+
# :name => 'layout',
|
209
|
+
# :content => '<div id="layout">{{ content_for_layout }}</div>')
|
210
|
+
|
211
|
+
# get :edit
|
212
|
+
# assert_select '#awesome_layout p'
|
213
|
+
# end
|
214
|
+
|
215
|
+
test 'does not render liquid layout if disabled' do
|
195
216
|
setup_controller(RatingsController)
|
217
|
+
|
218
|
+
LiquidTemplate.create!(:name => 'ratings/show', :content => '<p>This is liquid template</p>')
|
219
|
+
LiquidTemplate.create!(:name => 'layout',
|
220
|
+
:content => '<div id="layout">{{ content_for_layout }}</div>')
|
221
|
+
|
222
|
+
get :show
|
223
|
+
assert_select 'p', 'This is liquid template'
|
224
|
+
assert_select '#layout', false
|
225
|
+
end
|
226
|
+
|
227
|
+
test 'does not apply liquid layout to render :partial' do
|
228
|
+
setup_controller(CommentsController)
|
196
229
|
|
197
230
|
LiquidTemplate.create!(:name => 'layout',
|
198
231
|
:content => '<div id="layout">{{ content_for_layout }}</div>')
|
@@ -202,7 +235,7 @@ class ControllerExtensionsTest < ActionController::TestCase
|
|
202
235
|
end
|
203
236
|
|
204
237
|
test 'does not apply liquid layout to render :text' do
|
205
|
-
setup_controller(
|
238
|
+
setup_controller(CommentsController)
|
206
239
|
|
207
240
|
LiquidTemplate.create!(:name => 'layout',
|
208
241
|
:content => '<div id="layout">{{ content_for_layout }}</div>')
|
@@ -229,6 +262,30 @@ class ControllerExtensionsTest < ActionController::TestCase
|
|
229
262
|
get :show
|
230
263
|
assert_select 'h1 strong', 'Liquidizer is awesome!'
|
231
264
|
end
|
265
|
+
|
266
|
+
test 'dropifies array elements' do
|
267
|
+
setup_controller(PostsController)
|
268
|
+
|
269
|
+
LiquidTemplate.create!(:name => 'posts/index',
|
270
|
+
:content => '{% for post in posts %} {{ post.title }} {% endfor %}')
|
271
|
+
|
272
|
+
get :index
|
273
|
+
assert_select 'em', 'First post'
|
274
|
+
assert_select 'em', 'Second post'
|
275
|
+
end
|
276
|
+
|
277
|
+
test 'renders partials' do
|
278
|
+
setup_controller(PostsController)
|
279
|
+
|
280
|
+
LiquidTemplate.create!(:name => 'posts/show',
|
281
|
+
:content => '<p>This is a template</p> {% include "cool_partial" %}')
|
282
|
+
LiquidTemplate.create!(:name => 'cool_partial',
|
283
|
+
:content => '<p>This is a partial</p>')
|
284
|
+
|
285
|
+
get :show
|
286
|
+
assert_select 'p', 'This is a template'
|
287
|
+
assert_select 'p', 'This is a partial'
|
288
|
+
end
|
232
289
|
|
233
290
|
private
|
234
291
|
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
require 'liquidizer/file_system'
|
3
|
+
|
4
|
+
class FileSystemTest < ActiveSupport::TestCase
|
5
|
+
def setup
|
6
|
+
LiquidTemplate.destroy_all
|
7
|
+
end
|
8
|
+
|
9
|
+
test 'reads templates from the database' do
|
10
|
+
LiquidTemplate.create!(:name => 'posts/index', :content => 'These are posts')
|
11
|
+
LiquidTemplate.create!(:name => 'comments/show', :content => 'This is a comment')
|
12
|
+
|
13
|
+
file_system = Liquidizer::FileSystem.new { LiquidTemplate }
|
14
|
+
|
15
|
+
assert_equal 'These are posts', file_system.read_template_file('posts/index')
|
16
|
+
assert_equal 'This is a comment', file_system.read_template_file('comments/show')
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<div id="layout"><%= yield %></div>
|
@@ -0,0 +1 @@
|
|
1
|
+
<p>This is not liquid template</p>
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 4
|
8
|
+
- 2
|
9
|
+
version: 0.4.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- "Adam Cig\xC3\xA1nek"
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-03-
|
17
|
+
date: 2010-03-09 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -49,15 +49,19 @@ files:
|
|
49
49
|
- app/models/liquid_template.rb
|
50
50
|
- lib/liquidizer.rb
|
51
51
|
- lib/liquidizer/controller_extensions.rb
|
52
|
+
- lib/liquidizer/file_system.rb
|
52
53
|
- lib/liquidizer/liquid_template.rb
|
53
54
|
- lib/liquidizer/migration_extensions.rb
|
54
55
|
- lib/liquidizer/support.rb
|
55
56
|
- liquidizer.gemspec
|
56
57
|
- rails/init.rb
|
57
58
|
- test/controller_extensions_test.rb
|
59
|
+
- test/file_system_test.rb
|
60
|
+
- test/fixtures/comments/_stuff.html.erb
|
58
61
|
- test/fixtures/comments/index.html.erb
|
62
|
+
- test/fixtures/layouts/layout.html.erb
|
59
63
|
- test/fixtures/posts/index.liquid
|
60
|
-
- test/fixtures/
|
64
|
+
- test/fixtures/posts/show.html.erb
|
61
65
|
- test/fixtures/ratings/edit.html.erb
|
62
66
|
- test/fixtures/spams/index.html.erb
|
63
67
|
- test/liquid_template_test.rb
|
@@ -98,3 +102,4 @@ test_files:
|
|
98
102
|
- test/liquid_template_test.rb
|
99
103
|
- test/controller_extensions_test.rb
|
100
104
|
- test/test_helper.rb
|
105
|
+
- test/file_system_test.rb
|
File without changes
|