liquidizer 0.5.3 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,8 @@
1
1
  require 'liquidizer/controller_extensions'
2
2
  require 'liquidizer/migration_extensions'
3
3
  require 'liquidizer/liquid_template'
4
-
4
+ require 'liquidizer/version'
5
+
5
6
  module Liquidizer
6
7
  # The path the default liquid templates are stored.
7
8
  mattr_accessor :template_paths
@@ -37,7 +37,7 @@ module Liquidizer
37
37
  content = layout_template.render!(assigns.merge('content_for_layout' => content))
38
38
 
39
39
  render_without_liquid(options.merge(:text => content, :layout => false))
40
- else
40
+ else
41
41
  render_without_liquid(options, &block)
42
42
  end
43
43
  end
@@ -50,15 +50,15 @@ module Liquidizer
50
50
 
51
51
  unless name
52
52
  action = extract_action_for_render(options)
53
-
53
+
54
54
  if action && liquify?(action)
55
- name = liquid_template_name_for_action(action)
55
+ name = liquid_template_name_for_action(action)
56
56
  end
57
57
  end
58
58
 
59
59
  name && find_and_parse_liquid_template(name)
60
60
  end
61
-
61
+
62
62
  def liquify?(action)
63
63
  options = self.class.liquidizer_options
64
64
 
@@ -79,7 +79,7 @@ module Liquidizer
79
79
  nil
80
80
  end
81
81
  end
82
-
82
+
83
83
  def liquify_layout?(options)
84
84
  if self.class.liquidizer_options[:layout]
85
85
  case options[:layout]
@@ -92,7 +92,7 @@ module Liquidizer
92
92
  false
93
93
  end
94
94
  end
95
-
95
+
96
96
  def extract_action_for_render(options)
97
97
  if options.nil?
98
98
  action_name
@@ -105,12 +105,12 @@ module Liquidizer
105
105
  end
106
106
  end
107
107
 
108
- UNLIQUIFIABLE_OPTIONS = [:partial, :file, :text, :xml, :json, :js, :inline]
108
+ UNLIQUIFIABLE_OPTIONS = [:partial, :file, :text, :xml, :json, :js, :inline, :nothing]
109
109
 
110
110
  def liquifiable_options?(options)
111
111
  (options.keys.map(&:to_sym) & UNLIQUIFIABLE_OPTIONS).empty?
112
112
  end
113
-
113
+
114
114
  def find_and_parse_liquid_template(name)
115
115
  if template_record = find_liquid_template(name)
116
116
  template = Liquid::Template.parse(template_record.content)
@@ -147,7 +147,7 @@ module Liquidizer
147
147
  def assigns_for_liquify
148
148
  variable_names = instance_variable_names
149
149
  variable_names -= protected_instance_variables
150
-
150
+
151
151
  variable_names.inject({}) do |memo, name|
152
152
  assign_name = name[/^@(.*)$/, 1] # strip @
153
153
  next memo if assign_name.starts_with?('_') # skip "private" ivars
@@ -0,0 +1,3 @@
1
+ module Liquidizer
2
+ VERSION = '0.5.4'
3
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 5
8
- - 3
9
- version: 0.5.3
8
+ - 4
9
+ version: 0.5.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - "Adam Cig\xC3\xA1nek"
@@ -14,13 +14,41 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-06-01 00:00:00 +02:00
17
+ date: 2010-12-14 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: liquid
21
+ name: actionpack
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 2
29
+ - 3
30
+ - 5
31
+ version: 2.3.5
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: activerecord
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 2
43
+ - 3
44
+ - 5
45
+ version: 2.3.5
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: liquid
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
24
52
  requirements:
25
53
  - - ">="
26
54
  - !ruby/object:Gem::Version
@@ -30,7 +58,7 @@ dependencies:
30
58
  - 0
31
59
  version: 2.0.0
32
60
  type: :runtime
33
- version_requirements: *id001
61
+ version_requirements: *id003
34
62
  description: |
35
63
  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.
36
64
 
@@ -39,44 +67,23 @@ executables: []
39
67
 
40
68
  extensions: []
41
69
 
42
- extra_rdoc_files:
43
- - README.rdoc
70
+ extra_rdoc_files: []
71
+
44
72
  files:
45
- - .gitignore
46
- - README.rdoc
47
- - Rakefile
48
- - VERSION
49
- - app/models/liquid_template.rb
50
- - lib/liquidizer.rb
51
73
  - lib/liquidizer/controller_extensions.rb
52
- - lib/liquidizer/file_system.rb
53
74
  - lib/liquidizer/liquid_template.rb
54
75
  - lib/liquidizer/migration_extensions.rb
76
+ - lib/liquidizer/file_system.rb
55
77
  - lib/liquidizer/support.rb
56
- - liquidizer.gemspec
57
- - rails/init.rb
58
- - test/controller_extensions_test.rb
59
- - test/file_system_test.rb
60
- - test/fixtures/comments/_stuff.html.erb
61
- - test/fixtures/comments/index.html.erb
62
- - test/fixtures/layouts/layout.html.erb
63
- - test/fixtures/path_one/template_one.liquid
64
- - test/fixtures/path_two/template_one.liquid
65
- - test/fixtures/path_two/template_two.liquid
66
- - test/fixtures/posts/index.liquid
67
- - test/fixtures/posts/show.html.erb
68
- - test/fixtures/ratings/edit.html.erb
69
- - test/fixtures/spams/index.html.erb
70
- - test/liquid_template_test.rb
71
- - test/support_test.rb
72
- - test/test_helper.rb
78
+ - lib/liquidizer/version.rb
79
+ - lib/liquidizer.rb
73
80
  has_rdoc: true
74
81
  homepage: http://github.com/madadam/liquidizer
75
82
  licenses: []
76
83
 
77
84
  post_install_message:
78
- rdoc_options:
79
- - --charset=UTF-8
85
+ rdoc_options: []
86
+
80
87
  require_paths:
81
88
  - lib
82
89
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -91,18 +98,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
98
  - - ">="
92
99
  - !ruby/object:Gem::Version
93
100
  segments:
94
- - 0
95
- version: "0"
101
+ - 1
102
+ - 3
103
+ - 7
104
+ version: 1.3.7
96
105
  requirements: []
97
106
 
98
107
  rubyforge_project:
99
- rubygems_version: 1.3.6
108
+ rubygems_version: 1.3.7
100
109
  signing_key:
101
110
  specification_version: 3
102
111
  summary: Support for Ruby on Rails views powered by Liquid and loaded from database
103
- test_files:
104
- - test/support_test.rb
105
- - test/liquid_template_test.rb
106
- - test/controller_extensions_test.rb
107
- - test/test_helper.rb
108
- - test/file_system_test.rb
112
+ test_files: []
113
+
data/.gitignore DELETED
@@ -1 +0,0 @@
1
- pkg
@@ -1,206 +0,0 @@
1
- = Liquidizer
2
-
3
- Liquidizer is a gem for Ruby on Rails that allows to render pages using templates stored in the
4
- database. It uses liquid (http://www.liquidmarkup.org/) templating system (thus the name),
5
- because it's easy to use, extend and it's safe to edit by users.
6
-
7
- One example of when you might want to use it is this: Let's say you want to have a blogging
8
- system where people can create their blogs about kittens, ninjas or vampires. Using this gem,
9
- you can allow them to edit the look and feel of their blog using just their browser. Every
10
- blog can have it's own set of templates.
11
-
12
-
13
- == Installation
14
-
15
- It's hosted on http://gemcutter.org. Add it to your source list if you don't have it already:
16
-
17
- sudo gem source --add http://gemcutter.org
18
-
19
- Then install:
20
-
21
- sudo gem install liquidizer
22
-
23
- And add this to your config/environment.rb:
24
-
25
- config.gem 'liquidizer'
26
-
27
- == How to use
28
-
29
- First you have to specify which actions of which controllers should be liquified (rendered
30
- with loadable liquid templates). To do that, use the +liquify+ controller macro:
31
-
32
- class PostsController < ApplicationController
33
- # This will apply the templates to all actions in this controller.
34
- liquify
35
- end
36
-
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
-
40
- class PostsController < ApplicationController
41
- liquify :only => [:show, :index]
42
- end
43
-
44
- class CommentsController < ApplicationController
45
- liquify :except => :edit
46
- end
47
-
48
- The +liquify+ macro is inherited, so if you want to apply liquid templates to all actions
49
- in all controller, put it into ApplicationController. You can fine-tune it in derived
50
- controllers, if you want:
51
-
52
- class ApplicationController < ActionController::Base
53
- liquify
54
- end
55
-
56
- class PostsController < ApplicationController
57
- liquify :only => :show
58
- end
59
-
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.
62
-
63
- class ApplicationController < ActionController::Base
64
- liquify :layout => false
65
- end
66
-
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
- end
78
-
79
- The last step is to tell Liquidizer where to load the liquid templates from. The way to implement
80
- this is completely up to you. For example, you can associate the templates with the Blog model
81
- (to follow the blog example) and have something like current_blog, which is loaded by the
82
- current subdomain.
83
-
84
- In any case, you need to provide a +current_liquid_templates+ method,
85
- which should return collection of liquid templates to use. This method should return something
86
- that responds at least to +find_by_name+ which returns an object that responds to +content+
87
- which returns a string containing the liquid template.
88
-
89
- The easies way to do this, is to have a +LiquidTemplate+ model and return a collections of
90
- those in the +current_liquid_templates+. Liquidizer provides one such model for you,
91
- but you will probably want to use your own. To make your life easier, there is a module
92
- Liquidizer::LiquidTemplate which you can include into your template model to extend it with
93
- some helpful methods (see the docs for more info):
94
-
95
- class Blog < ActiveRecord::Base
96
- has_many :liquid_templates
97
- end
98
-
99
- # The
100
- class LiquidTemplate < ActiveRecord::Base
101
- include Liquidizer::LiquidTemplate
102
- belongs_to :blog
103
- end
104
-
105
- class ApplicationController < ActionController::Base
106
- private
107
-
108
- def current_liquid_templates
109
- current_blog.liquid_templates
110
- end
111
- end
112
-
113
- And that's it. You are now ready to kick asses!
114
-
115
- == Instance variables
116
-
117
- All instance variables that you assign in the controller are automatically available in the
118
- liquid templates. The variable will be automatically wrapped in a "drop", if necessary
119
- (please check the liquid docs for more details about what types can be passed directly to
120
- liquid templates and what are drops). For a class +Foo+, a +FooDrop+ will be used if it
121
- exists. If variable is not compatible with liquid and there is no corresponding drop class, it
122
- won't be passed to the template.
123
-
124
- Example:
125
-
126
- A controller:
127
-
128
- class PostsController < ActiveRecord::Base
129
- liquify
130
-
131
- def show
132
- @post = current_blog.posts.find(params[:id])
133
- end
134
- end
135
-
136
- A drop:
137
-
138
- class PostDrop < Liquid::Drop
139
- def initialize(post)
140
- @post = post
141
- end
142
-
143
- def title
144
- filter_nasty_stuff(@post.title)
145
- end
146
- end
147
-
148
- Then you can do this in your liquid template:
149
-
150
- <h1>{{ post.title }}</h1>
151
-
152
- <!-- more stuff ... -->
153
-
154
- And the post.title will call PostDrop#title, filtering all nasty stuff.
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
-
175
- The way how variables are wrapped with drops can be completelly customized by overriding the
176
- +dropify+ method.
177
-
178
- == Default templates
179
-
180
- The Liquidizer::LiquidTemplate module gives your model capability to fallback to a default
181
- template, if one is not found in the database. The default templates are stored in
182
- db/liquid_templates. You can configure this location by setting the Liquidizer.template_path:
183
-
184
- Liqduidizer.template_path = Rails.root.join('app', 'views', 'liquid_templates')
185
-
186
- == TODO
187
-
188
- There are several possible improvements to this gem:
189
-
190
- - Extend it so it can handle different template systems in addition (unlikely, since I don't
191
- need it and can't be bothered :) )
192
-
193
- - The Rails 3 has improved ActionView API and as far as I understand, abstracts away the
194
- concept of template storage. Taking advantage of this could potentialy simplify this gem.
195
- Also, support Rails 3 in general would be nice.
196
-
197
- - This does some nasty hacks into the ActionController::Base's render method. That method
198
- originaly has quite liberal API, allowing to specify it's parameters in many ways. To make
199
- this gem simple, some of those ways were sacrificed. Would be nice to support them too.
200
-
201
- Potentialy many more. In any case, it's open source project (MIT), so no fear, fork me and
202
- hack away!
203
-
204
- == Legal stuff
205
-
206
- Copyright (c) 2010 Adam Cigánek <adam.ciganek@gmail.com>. Released under the MIT License: www.opensource.org/licenses/mit-license.php
data/Rakefile DELETED
@@ -1,35 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'rake'
4
- require 'rake/testtask'
5
-
6
- desc 'Default: run unit tests.'
7
- task :default => :test
8
-
9
- desc 'Run unit tests.'
10
- Rake::TestTask.new(:test) do |t|
11
- t.pattern = 'test/**/*_test.rb'
12
- t.verbose = true
13
- end
14
-
15
- begin
16
- require 'jeweler'
17
-
18
- Jeweler::Tasks.new do |gemspec|
19
- gemspec.name = 'liquidizer'
20
- gemspec.summary = 'Support for Ruby on Rails views powered by Liquid and loaded from database'
21
- gemspec.description = <<END
22
- 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.
23
- END
24
-
25
- gemspec.email = 'adam.ciganek@gmail.com'
26
- gemspec.homepage = 'http://github.com/madadam/liquidizer'
27
- gemspec.authors = ['Adam Cigánek']
28
-
29
- gemspec.add_dependency 'liquid', '>= 2.0.0'
30
- end
31
-
32
- Jeweler::GemcutterTasks.new
33
- rescue LoadError
34
- puts "Jeweler not available. Install it with: gem install jeweler"
35
- end
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.5.3
@@ -1,3 +0,0 @@
1
- class LiquidTemplate < ActiveRecord::Base
2
- include Liquidizer::LiquidTemplate
3
- end
@@ -1,75 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{liquidizer}
8
- s.version = "0.5.3"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Adam Cigánek"]
12
- s.date = %q{2010-06-01}
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
- }
15
- s.email = %q{adam.ciganek@gmail.com}
16
- s.extra_rdoc_files = [
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".gitignore",
21
- "README.rdoc",
22
- "Rakefile",
23
- "VERSION",
24
- "app/models/liquid_template.rb",
25
- "lib/liquidizer.rb",
26
- "lib/liquidizer/controller_extensions.rb",
27
- "lib/liquidizer/file_system.rb",
28
- "lib/liquidizer/liquid_template.rb",
29
- "lib/liquidizer/migration_extensions.rb",
30
- "lib/liquidizer/support.rb",
31
- "liquidizer.gemspec",
32
- "rails/init.rb",
33
- "test/controller_extensions_test.rb",
34
- "test/file_system_test.rb",
35
- "test/fixtures/comments/_stuff.html.erb",
36
- "test/fixtures/comments/index.html.erb",
37
- "test/fixtures/layouts/layout.html.erb",
38
- "test/fixtures/path_one/template_one.liquid",
39
- "test/fixtures/path_two/template_one.liquid",
40
- "test/fixtures/path_two/template_two.liquid",
41
- "test/fixtures/posts/index.liquid",
42
- "test/fixtures/posts/show.html.erb",
43
- "test/fixtures/ratings/edit.html.erb",
44
- "test/fixtures/spams/index.html.erb",
45
- "test/liquid_template_test.rb",
46
- "test/support_test.rb",
47
- "test/test_helper.rb"
48
- ]
49
- s.homepage = %q{http://github.com/madadam/liquidizer}
50
- s.rdoc_options = ["--charset=UTF-8"]
51
- s.require_paths = ["lib"]
52
- s.rubygems_version = %q{1.3.6}
53
- s.summary = %q{Support for Ruby on Rails views powered by Liquid and loaded from database}
54
- s.test_files = [
55
- "test/support_test.rb",
56
- "test/liquid_template_test.rb",
57
- "test/controller_extensions_test.rb",
58
- "test/test_helper.rb",
59
- "test/file_system_test.rb"
60
- ]
61
-
62
- if s.respond_to? :specification_version then
63
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
64
- s.specification_version = 3
65
-
66
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
67
- s.add_runtime_dependency(%q<liquid>, [">= 2.0.0"])
68
- else
69
- s.add_dependency(%q<liquid>, [">= 2.0.0"])
70
- end
71
- else
72
- s.add_dependency(%q<liquid>, [">= 2.0.0"])
73
- end
74
- end
75
-
@@ -1 +0,0 @@
1
- require 'liquidizer'
@@ -1,315 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper'
2
-
3
- class BaseController < ActionController::Base
4
- append_view_path File.dirname(__FILE__) + '/fixtures'
5
-
6
- private
7
-
8
- def current_liquid_templates
9
- LiquidTemplate
10
- end
11
- end
12
-
13
- class PostsController < BaseController
14
- layout 'layout'
15
- liquify
16
-
17
- def index
18
- @title = 'Hello blog!'
19
- @posts = [Post.new(:title => 'First post'), Post.new(:title => 'Second post')]
20
- end
21
-
22
- def show
23
- @post = Post.new(:title => 'Liquidizer is awesome!')
24
- end
25
-
26
- def update
27
- render :action => 'edit'
28
- end
29
-
30
- def create
31
- render :status => :created
32
- end
33
-
34
- def new
35
- render :template => 'more_awesome_new'
36
- end
37
-
38
- def edit
39
- render :layout => 'awesome_layout'
40
- end
41
- end
42
-
43
- class CommentsController < BaseController
44
- layout 'layout'
45
- liquify :only => :show
46
-
47
- def index
48
- end
49
-
50
- def show
51
- end
52
-
53
- def new
54
- render :partial => 'stuff'
55
- end
56
-
57
- def create
58
- render :text => 'create'
59
- end
60
- end
61
-
62
- class RatingsController < BaseController
63
- liquify :layout => false
64
-
65
- def show
66
- end
67
- end
68
-
69
- class SpamsController < BaseController
70
- layout 'layout'
71
-
72
- def index
73
- end
74
- end
75
-
76
- class Post
77
- def initialize(attributes = {})
78
- self.title = attributes[:title]
79
- end
80
-
81
- attr_accessor :title
82
- end
83
-
84
- class PostDrop < Liquid::Drop
85
- def initialize(post)
86
- @post = post
87
- end
88
-
89
- def title
90
- "<em>#{@post.title}</em>"
91
- end
92
- end
93
-
94
- module CoolDrops
95
- class PostDrop < Liquid::Drop
96
- def initialize(post)
97
- @post = post
98
- end
99
-
100
- def title
101
- "<strong>#{@post.title}</strong>"
102
- end
103
- end
104
- end
105
-
106
- class ControllerExtensionsTest < ActionController::TestCase
107
- self.controller_class = nil
108
-
109
- def setup
110
- LiquidTemplate.destroy_all
111
- end
112
-
113
- def teardown
114
- Liquidizer.drop_module = nil
115
- end
116
-
117
- test 'renders with liquid template' do
118
- setup_controller(PostsController)
119
-
120
- LiquidTemplate.create!(:name => 'posts/index', :content => "<p>This is liquid template</p>")
121
-
122
- get :index
123
- assert_select 'p', 'This is liquid template'
124
- end
125
-
126
- test 'passes instance variables to liquid template' do
127
- setup_controller(PostsController)
128
-
129
- LiquidTemplate.create!(:name => 'posts/index', :content => "<h1>{{ title }}</h1>")
130
-
131
- get :index
132
- assert_select 'h1', /Hello blog!/
133
- end
134
-
135
- test 'renders with liquid template when explicit action specified' do
136
- setup_controller(PostsController)
137
-
138
- LiquidTemplate.create!(:name => 'posts/edit', :content => "<p>edit post</p>")
139
- LiquidTemplate.create!(:name => 'posts/update', :content => "<p>update post</p>")
140
-
141
- get :update
142
- assert_select 'p', 'edit post'
143
- end
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
-
155
- test 'preserves additional render options' do
156
- setup_controller(PostsController)
157
-
158
- LiquidTemplate.create!(:name => 'posts/create', :content => "<p>create post</p>")
159
-
160
- get :create
161
- assert_response :created
162
- end
163
-
164
- test 'does not render with liquid template actions that were not liquified' do
165
- setup_controller(CommentsController)
166
-
167
- get :index
168
- assert_select 'h1', 'This is not liquid template'
169
- end
170
-
171
- test 'does not render with liquid if liquify macro not called at all' do
172
- setup_controller(SpamsController)
173
-
174
- get :index
175
- assert_select '#layout h1', 'This is not liquid template'
176
- end
177
-
178
- test 'renders liquid template with liquid layout' do
179
- setup_controller(PostsController)
180
-
181
- LiquidTemplate.create!(:name => 'posts/show', :content => '<p>This is liquid template</p>')
182
- LiquidTemplate.create!(:name => 'layout',
183
- :content => '<div id="layout">{{ content_for_layout }}</div>')
184
-
185
- get :show
186
- assert_select '#layout p', 'This is liquid template'
187
- end
188
-
189
- test 'renders solid template with liquid layout' do
190
- setup_controller(PostsController)
191
-
192
- LiquidTemplate.create!(:name => 'layout',
193
- :content => '<div id="layout">{{ content_for_layout }}</div>')
194
-
195
- get :show
196
- assert_select '#layout p', 'This is not liquid template'
197
- end
198
-
199
- test 'renders with overriden liquid layout' do
200
- setup_controller(PostsController)
201
-
202
- LiquidTemplate.create!(
203
- :name => 'awesome_layout',
204
- :content => '<div id="awesome_layout">{{ content_for_layout }}</div>')
205
-
206
- LiquidTemplate.create!(
207
- :name => 'layout',
208
- :content => '<div id="layout">{{ content_for_layout }}</div>')
209
-
210
- LiquidTemplate.create!(
211
- :name => 'posts/edit',
212
- :content => '<p>Awesome liquid template</p>')
213
-
214
- get :edit
215
- assert_select '#awesome_layout p'
216
- end
217
-
218
- test 'does not render liquid layout if disabled' do
219
- setup_controller(RatingsController)
220
-
221
- LiquidTemplate.create!(:name => 'ratings/show', :content => '<p>This is liquid template</p>')
222
- LiquidTemplate.create!(:name => 'layout',
223
- :content => '<div id="layout">{{ content_for_layout }}</div>')
224
-
225
- get :show
226
- assert_select 'p', 'This is liquid template'
227
- assert_select '#layout', false
228
- end
229
-
230
- test 'does not apply liquid layout to render :partial' do
231
- setup_controller(CommentsController)
232
-
233
- LiquidTemplate.create!(:name => 'layout',
234
- :content => '<div id="layout">{{ content_for_layout }}</div>')
235
-
236
- get :new
237
- assert_select '#layout', false
238
- end
239
-
240
- test 'does not apply liquid layout to render :text' do
241
- setup_controller(CommentsController)
242
-
243
- LiquidTemplate.create!(:name => 'layout',
244
- :content => '<div id="layout">{{ content_for_layout }}</div>')
245
-
246
- get :create
247
- assert_select '#layout', false
248
- end
249
-
250
- test 'applies liquid layout to render :template' do
251
- setup_controller(PostsController)
252
-
253
- LiquidTemplate.create!(:name => 'more_awesome_new', :content => "<p>more awesome new</p>")
254
- LiquidTemplate.create!(:name => 'layout',
255
- :content => '<div id="layout">{{ content_for_layout }}</div>')
256
-
257
- get :new
258
- assert_select '#layout p', 'more awesome new'
259
- end
260
-
261
- test 'dropifies instance variables' do
262
- setup_controller(PostsController)
263
-
264
- LiquidTemplate.create!(:name => 'posts/show', :content => '<h1>{{ post.title }}</h1>')
265
-
266
- get :show
267
- assert_select 'h1 em', 'Liquidizer is awesome!'
268
- end
269
-
270
- test 'dropifies instance variables using namespaced drop' do
271
- setup_controller(PostsController)
272
- Liquidizer.drop_module = CoolDrops
273
-
274
- LiquidTemplate.create!(:name => 'posts/show', :content => '<h1>{{ post.title }}</h1>')
275
-
276
- get :show
277
- assert_select 'h1 strong', 'Liquidizer is awesome!'
278
- end
279
-
280
- test 'dropifies array elements' do
281
- setup_controller(PostsController)
282
-
283
- LiquidTemplate.create!(:name => 'posts/index',
284
- :content => '{% for post in posts %} {{ post.title }} {% endfor %}')
285
-
286
- get :index
287
- assert_select 'em', 'First post'
288
- assert_select 'em', 'Second post'
289
- end
290
-
291
- test 'renders partials' do
292
- setup_controller(PostsController)
293
-
294
- LiquidTemplate.create!(:name => 'posts/show',
295
- :content => '<p>This is a template</p> {% include "cool_partial" %}')
296
- LiquidTemplate.create!(:name => 'cool_partial',
297
- :content => '<p>This is a partial</p>')
298
-
299
- get :show
300
- assert_select 'p', 'This is a template'
301
- assert_select 'p', 'This is a partial'
302
- end
303
-
304
- private
305
-
306
- def setup_controller(controller_class)
307
- self.class.prepare_controller_class(controller_class)
308
-
309
- # This is copied over from ActionController::TestCase.setup_controller_request_and_response
310
- @controller = controller_class.new
311
- @controller.request = @request
312
- @controller.params = {}
313
- @controller.send(:initialize_current_url)
314
- end
315
- end
@@ -1,18 +0,0 @@
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
@@ -1 +0,0 @@
1
- Stuff
@@ -1 +0,0 @@
1
- <h1>This is not liquid template</h1>
@@ -1 +0,0 @@
1
- <div id="layout"><%= yield %></div>
@@ -1 +0,0 @@
1
- Default template one in path one
@@ -1 +0,0 @@
1
- Default template one in path two
@@ -1 +0,0 @@
1
- Default template two in path two
@@ -1,3 +0,0 @@
1
- <h1>Hello world</h1>
2
-
3
- <p>This is a liquid template.</p>
@@ -1 +0,0 @@
1
- <p>This is not liquid template</p>
@@ -1 +0,0 @@
1
- <p>This is not liquid template</p>
@@ -1 +0,0 @@
1
- <h1>This is not liquid template</h1>
@@ -1,41 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper'
2
-
3
- class LiquidTemplateTest < ActiveSupport::TestCase
4
- def setup
5
- LiquidTemplate.delete_all
6
- @old_template_paths = Liquidizer.template_paths
7
- end
8
-
9
- def teardown
10
- Liquidizer.template_paths = @old_template_paths
11
- end
12
-
13
- test 'find_by_name finds template by name if it exists' do
14
- one = LiquidTemplate.create!(:name => 'posts/index')
15
- two = LiquidTemplate.create!(:name => 'posts/show')
16
-
17
- assert_equal one, LiquidTemplate.find_by_name('posts/index')
18
- end
19
-
20
- test 'find_by_name fallbacks to default template' do
21
- expected_content = File.read(File.dirname(__FILE__) + '/fixtures/posts/index.liquid')
22
- found = LiquidTemplate.find_by_name('posts/index')
23
-
24
- assert_equal expected_content, found.content
25
- end
26
-
27
- test 'find_by_name searches template in all template paths' do
28
- Liquidizer.template_paths = [File.dirname(__FILE__) + '/fixtures/path_one',
29
- File.dirname(__FILE__) + '/fixtures/path_two']
30
-
31
- expected_one = File.read(File.dirname(__FILE__) + '/fixtures/path_one/template_one.liquid')
32
- expected_two = File.read(File.dirname(__FILE__) + '/fixtures/path_two/template_two.liquid')
33
-
34
- assert_equal expected_one, LiquidTemplate.find_by_name('template_one').content
35
- assert_equal expected_two, LiquidTemplate.find_by_name('template_two').content
36
- end
37
-
38
- test 'find_by_name returns nil if not even default template exists' do
39
- assert_nil LiquidTemplate.find_by_name('ninjas!')
40
- end
41
- end
@@ -1,24 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper'
2
-
3
- module Foo
4
- class Bar
5
- end
6
-
7
- class Awesomeness
8
- end
9
- end
10
-
11
- class Bar
12
- end
13
-
14
- class SupportTest < ActiveSupport::TestCase
15
- test 'constant_defined? with non-namespaced constant' do
16
- assert Liquidizer::Support.constant_defined?('Bar')
17
- assert !Liquidizer::Support.constant_defined?('Baz')
18
- end
19
-
20
- test 'constant_defined? with namespaced constant' do
21
- assert Liquidizer::Support.constant_defined?('Foo::Bar')
22
- assert !Liquidizer::Support.constant_defined?('Foo::Baz')
23
- end
24
- end
@@ -1,24 +0,0 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
- require 'action_controller'
4
- require 'active_record'
5
- require 'active_support/test_case'
6
-
7
- $: << File.dirname(__FILE__) + '/../lib'
8
- $: << File.dirname(__FILE__) + '/../app/models'
9
-
10
- require 'liquidizer'
11
- require 'liquid_template'
12
-
13
- Liquidizer.template_paths = [File.dirname(__FILE__) + '/fixtures']
14
-
15
- # Establish a temporary sqlite3 db for testing.
16
- ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
17
- ActiveRecord::Base.logger # instantiate logger
18
- ActiveRecord::Schema.define(:version => 1) do
19
- create_liquid_templates_table
20
- end
21
-
22
- ActionController::Routing::Routes.draw do |map|
23
- map.connect ':controller/:action/:id'
24
- end