From 7703d72cc5ca0de88a3ca346621c6dd92ecc6ce4 Mon Sep 17 00:00:00 2001 From: Oliver Clarke Date: Sat, 5 Jun 2010 17:57:30 +1200 Subject: [PATCH 01/11] added ability to remove liquify from controller, and check liquify status --- lib/liquidizer/controller_extensions.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/liquidizer/controller_extensions.rb b/lib/liquidizer/controller_extensions.rb index 9fca4db..37c71dd 100644 --- a/lib/liquidizer/controller_extensions.rb +++ b/lib/liquidizer/controller_extensions.rb @@ -17,6 +17,9 @@ def self.included(base) end def render_with_liquid(options = nil, &block) + # use normal render if "liquify" has not been called in the controller + return render_without_liquid(options, &block) if !self.class.liquify_enabled? + if view_template = liquid_template_for_view(options) options ||= {} assigns = assigns_for_liquify @@ -206,6 +209,15 @@ module ClassMethods def liquify(options = {}) self.liquidizer_options = options.reverse_merge(:actions => true, :layout => true) end + + def remove_liquify + self.liquidizer_options.clear + end + + def liquify_enabled? + self.liquidizer_options != {} + end + end end end From d8121d59c8bbf1154fdc13f1b955250a3da3b779 Mon Sep 17 00:00:00 2001 From: Michal Cichra Date: Mon, 12 Sep 2011 19:12:20 +0200 Subject: [PATCH 02/11] Gemfile.lock shouldn't be in git repo (for gems) --- .gitignore | 1 + Gemfile.lock | 28 ---------------------------- 2 files changed, 1 insertion(+), 28 deletions(-) delete mode 100644 Gemfile.lock diff --git a/.gitignore b/.gitignore index 7b0db99..f29db7c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .bundle *.gem +Gemfile.lock diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index c1f208f..0000000 --- a/Gemfile.lock +++ /dev/null @@ -1,28 +0,0 @@ -PATH - remote: . - specs: - liquidizer (0.5.4) - actionpack (~> 2.3.5) - activerecord (~> 2.3.5) - liquid (>= 2.0.0) - -GEM - remote: http://rubygems.org/ - specs: - actionpack (2.3.8) - activesupport (= 2.3.8) - rack (~> 1.1.0) - activerecord (2.3.8) - activesupport (= 2.3.8) - activesupport (2.3.8) - liquid (2.2.2) - rack (1.1.0) - -PLATFORMS - ruby - -DEPENDENCIES - actionpack (~> 2.3.5) - activerecord (~> 2.3.5) - liquid (>= 2.0.0) - liquidizer! From 11165551fab08c76a30261752b9bd7e87481c64d Mon Sep 17 00:00:00 2001 From: Michal Cichra Date: Mon, 12 Sep 2011 19:13:04 +0200 Subject: [PATCH 03/11] added rake and sqlite3 to Gemfile, so can run tests with bundle exec --- Gemfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Gemfile b/Gemfile index 1aa98e4..8caa1b7 100644 --- a/Gemfile +++ b/Gemfile @@ -1,2 +1,4 @@ source "http://rubygems.org" +gem 'rake' +gem 'sqlite3' gemspec From fdd4f1827a5ead72ef15e967602604c938d8e8ea Mon Sep 17 00:00:00 2001 From: Michal Cichra Date: Mon, 12 Sep 2011 19:38:24 +0200 Subject: [PATCH 04/11] Made Liquidizer compatabile with "smart" render method. Now you can use 'render :edit' or 'render "shared/template"' and other stuff --- lib/liquidizer/controller_extensions.rb | 49 ++++++++++++++++++------- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/lib/liquidizer/controller_extensions.rb b/lib/liquidizer/controller_extensions.rb index df8e50b..78b1300 100644 --- a/lib/liquidizer/controller_extensions.rb +++ b/lib/liquidizer/controller_extensions.rb @@ -16,38 +16,61 @@ def self.included(base) end end - def render_with_liquid(options = nil, &block) + def render_with_liquid(options = nil, extra_options = {}, &block) # use normal render if "liquify" has not been called in the controller - return render_without_liquid(options, &block) if !self.class.liquify_enabled? - - if view_template = liquid_template_for_view(options) - options ||= {} + return render_without_liquid(options, extra_options, &block) unless self.class.liquify_enabled? + + liquid_options = handle_multiple_options(options, extra_options) || {} + + if view_template = liquid_template_for_view(liquid_options) assigns = assigns_for_liquify content = view_template.render!(assigns) - if layout_template = liquid_template_for_layout(options) + if layout_template = liquid_template_for_layout(liquid_options) content = layout_template.render!(assigns.merge('content_for_layout' => content)) - options[:layout] = false + liquid_options[:layout] = false end - render_without_liquid(options.merge(:text => content)) + render_without_liquid(liquid_options.merge(:text => content)) else - if layout_template = liquid_template_for_layout(options) + if layout_template = liquid_template_for_layout(liquid_options) assigns = assigns_for_liquify - options ||= {} - content = render_to_string(options.merge(:layout => false)) + content = render_to_string(liquid_options.merge(:layout => false)) content = layout_template.render!(assigns.merge('content_for_layout' => content)) - render_without_liquid(options.merge(:text => content, :layout => false)) + render_without_liquid(options, extra_options.merge(:text => content, :layout => false)) else - render_without_liquid(options, &block) + render_without_liquid(options, extra_options, &block) end end end private + # taken from Rails #render + def handle_multiple_options options, extra_options + if options.nil? + # Rails fetch default template, but that is not possible (there is no template) + elsif options.is_a?(String) || options.is_a?(Symbol) + case options.to_s.index('/') + when 0 + extra_options[:file] = options + when nil + extra_options[:action] = options + else + extra_options[:template] = options + end + + options = extra_options + elsif !options.is_a?(Hash) + extra_options[:partial] = options + options = extra_options + end + + options + end + def liquid_template_for_view(options) name = options && options[:template] From babe70d578f3f7c25a31329d2b9d1904c5a40385 Mon Sep 17 00:00:00 2001 From: Michal Cichra Date: Tue, 13 Sep 2011 10:45:58 +0200 Subject: [PATCH 05/11] little changes, addded tests --- lib/liquidizer/controller_extensions.rb | 9 ++++-- test/controller_extensions_test.rb | 38 +++++++++++++++++++++++++ test/fixtures/rails/edit.html.erb | 1 + test/fixtures/rails/update.html.erb | 1 + 4 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 test/fixtures/rails/edit.html.erb create mode 100644 test/fixtures/rails/update.html.erb diff --git a/lib/liquidizer/controller_extensions.rb b/lib/liquidizer/controller_extensions.rb index 78b1300..cf929df 100644 --- a/lib/liquidizer/controller_extensions.rb +++ b/lib/liquidizer/controller_extensions.rb @@ -20,7 +20,7 @@ def render_with_liquid(options = nil, extra_options = {}, &block) # use normal render if "liquify" has not been called in the controller return render_without_liquid(options, extra_options, &block) unless self.class.liquify_enabled? - liquid_options = handle_multiple_options(options, extra_options) || {} + liquid_options = handle_multiple_options(options, extra_options) if view_template = liquid_template_for_view(liquid_options) assigns = assigns_for_liquify @@ -50,8 +50,12 @@ def render_with_liquid(options = nil, extra_options = {}, &block) # taken from Rails #render def handle_multiple_options options, extra_options + extra_options = extra_options.dup + if options.nil? # Rails fetch default template, but that is not possible (there is no template) + options = extra_options + elsif options.is_a?(String) || options.is_a?(Symbol) case options.to_s.index('/') when 0 @@ -63,8 +67,10 @@ def handle_multiple_options options, extra_options end options = extra_options + elsif !options.is_a?(Hash) extra_options[:partial] = options + options = extra_options end @@ -96,7 +102,6 @@ def liquify?(action) end def liquid_template_for_layout(options) - options ||= {} if liquify_layout?(options) name = liquid_template_name_for_layout(options) diff --git a/test/controller_extensions_test.rb b/test/controller_extensions_test.rb index 7ceb7c3..3e5f509 100644 --- a/test/controller_extensions_test.rb +++ b/test/controller_extensions_test.rb @@ -10,6 +10,22 @@ def current_liquid_templates end end +class RailsController < BaseController + + def show + render :edit, :layout => false + end + + def edit + render 'posts/show' + end + + def update + render + end + +end + class PostsController < BaseController layout 'layout' liquify @@ -315,6 +331,28 @@ def teardown assert_select 'p', 'This is a partial' end + test 'call to render with symbol' do + setup_controller(RailsController) + + get :show + assert_select 'p', 'Rails edit action' + assert_select '#layout', false + end + + test 'call to render with template name' do + setup_controller(RailsController) + + get :edit + assert_select 'p', 'This is not liquid template' + end + + test 'call to render without anything' do + setup_controller(RailsController) + + get :update + assert_select 'p', 'Rails update action' + end + private def setup_controller(controller_class) diff --git a/test/fixtures/rails/edit.html.erb b/test/fixtures/rails/edit.html.erb new file mode 100644 index 0000000..79cd8d1 --- /dev/null +++ b/test/fixtures/rails/edit.html.erb @@ -0,0 +1 @@ +

Rails edit action

diff --git a/test/fixtures/rails/update.html.erb b/test/fixtures/rails/update.html.erb new file mode 100644 index 0000000..6b32361 --- /dev/null +++ b/test/fixtures/rails/update.html.erb @@ -0,0 +1 @@ +

Rails update action

From 08591ab2dfeccc64c5a3c2c406499092614dc27e Mon Sep 17 00:00:00 2001 From: Michal Cichra Date: Tue, 13 Sep 2011 12:17:09 +0200 Subject: [PATCH 06/11] added test and fixed liquid layout rendering --- lib/liquidizer/controller_extensions.rb | 5 ++--- test/controller_extensions_test.rb | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/liquidizer/controller_extensions.rb b/lib/liquidizer/controller_extensions.rb index cf929df..b321e3b 100644 --- a/lib/liquidizer/controller_extensions.rb +++ b/lib/liquidizer/controller_extensions.rb @@ -39,7 +39,7 @@ def render_with_liquid(options = nil, extra_options = {}, &block) content = render_to_string(liquid_options.merge(:layout => false)) content = layout_template.render!(assigns.merge('content_for_layout' => content)) - render_without_liquid(options, extra_options.merge(:text => content, :layout => false)) + render_without_liquid(liquid_options.merge(:text => content, :layout => false)) else render_without_liquid(options, extra_options, &block) end @@ -102,7 +102,6 @@ def liquify?(action) end def liquid_template_for_layout(options) - if liquify_layout?(options) name = liquid_template_name_for_layout(options) name && find_and_parse_liquid_template(name) @@ -243,7 +242,7 @@ def remove_liquify end def liquify_enabled? - self.liquidizer_options != {} + self.liquidizer_options.present? end end diff --git a/test/controller_extensions_test.rb b/test/controller_extensions_test.rb index 3e5f509..e7dfdda 100644 --- a/test/controller_extensions_test.rb +++ b/test/controller_extensions_test.rb @@ -12,6 +12,9 @@ def current_liquid_templates class RailsController < BaseController + layout 'login_layout', :only => [:login] + liquify :only => [:login] + def show render :edit, :layout => false end @@ -24,6 +27,12 @@ def update render end + def login + LiquidTemplate.create!(:name => 'login_layout', + :content => '
{{ content_for_layout }}
') + render 'posts/show' + end + end class PostsController < BaseController @@ -353,6 +362,16 @@ def teardown assert_select 'p', 'Rails update action' end + test 'call to render with template and liquid layout' do + setup_controller(RailsController) + + get :login + assert_select 'p', 'This is not liquid template' + + assert_select '#layout', false + assert_select '#login_layout', true + end + private def setup_controller(controller_class) From 03b674a74eb82e4a12a00cc6cfd91a36e02405b9 Mon Sep 17 00:00:00 2001 From: Michal Cichra Date: Tue, 13 Sep 2011 10:46:20 +0200 Subject: [PATCH 07/11] bumped version --- lib/liquidizer/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/liquidizer/version.rb b/lib/liquidizer/version.rb index 4cda24b..18c74fe 100644 --- a/lib/liquidizer/version.rb +++ b/lib/liquidizer/version.rb @@ -1,3 +1,3 @@ module Liquidizer - VERSION = '0.5.4' + VERSION = '0.6.0' end From 338faee91a32b9eb695e64d1e1774bfd4390f949 Mon Sep 17 00:00:00 2001 From: Michal Cichra Date: Thu, 28 Jun 2012 18:25:33 +0300 Subject: [PATCH 08/11] Allow setting liquid template in controller to instance variable. --- lib/liquidizer/controller_extensions.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/liquidizer/controller_extensions.rb b/lib/liquidizer/controller_extensions.rb index b321e3b..93f5b1e 100644 --- a/lib/liquidizer/controller_extensions.rb +++ b/lib/liquidizer/controller_extensions.rb @@ -157,7 +157,7 @@ def liquid_template_name_for_action(action) end def liquid_template_name_for_layout(options) - options[:layout] || case layout = self.class.read_inheritable_attribute(:layout) + options[:layout] || @_liquid_layout || case layout = self.class.read_inheritable_attribute(:layout) when Symbol then __send__(layout) when Proc then layout.call(self) else layout From 0ef65a5301519770f419d7645cb8d77e69778de8 Mon Sep 17 00:00:00 2001 From: Michal Cichra Date: Wed, 18 Jul 2012 15:48:16 +0300 Subject: [PATCH 09/11] Use class inheritable accessor instead of hash this will override stored has in every child class when liquify is called --- lib/liquidizer/controller_extensions.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/liquidizer/controller_extensions.rb b/lib/liquidizer/controller_extensions.rb index 93f5b1e..96e1b13 100644 --- a/lib/liquidizer/controller_extensions.rb +++ b/lib/liquidizer/controller_extensions.rb @@ -9,7 +9,7 @@ def self.included(base) extend ClassMethods alias_method_chain :render, :liquid - class_inheritable_hash :liquidizer_options + class_inheritable_accessor :liquidizer_options self.liquidizer_options ||= {} before_filter :set_liquid_file_system From a8ab19f9e287dfa18b1eac037482ae855796af0f Mon Sep 17 00:00:00 2001 From: Michal Cichra Date: Tue, 4 Sep 2012 17:37:45 +0200 Subject: [PATCH 10/11] loose rails dependency --- liquidizer.gemspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/liquidizer.gemspec b/liquidizer.gemspec index 5463d6e..7ed62f5 100644 --- a/liquidizer.gemspec +++ b/liquidizer.gemspec @@ -18,8 +18,8 @@ END s.required_rubygems_version = ">= 1.3.7" - s.add_dependency 'actionpack', '~> 2.3.5' - s.add_dependency 'activerecord', '~> 2.3.5' + s.add_dependency 'actionpack' + s.add_dependency 'activerecord' s.add_dependency 'liquid', '>= 2.0.0' s.files = Dir.glob('{lib,bin}/**/*') From 85b31dbcdfb0e7741f2f498100ece8e52c130e22 Mon Sep 17 00:00:00 2001 From: Michal Cichra Date: Wed, 6 Feb 2013 13:18:47 +0100 Subject: [PATCH 11/11] Update liquidizer.gemspec remove utf-8 chars --- liquidizer.gemspec | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/liquidizer.gemspec b/liquidizer.gemspec index 7ed62f5..c0ac50d 100644 --- a/liquidizer.gemspec +++ b/liquidizer.gemspec @@ -1,4 +1,3 @@ -# -*- encoding: utf-8 -*- lib = File.expand_path('../lib/', __FILE__) $:.unshift lib unless $:.include?(lib) @@ -8,7 +7,7 @@ Gem::Specification.new do |s| s.name = 'liquidizer' s.version = Liquidizer::VERSION s.platform = Gem::Platform::RUBY - s.authors = ["Adam Cigánek"] + s.authors = ["Adam Ciganek"] s.email = 'adam.ciganek@gmail.com' s.homepage = 'http://github.com/madadam/liquidizer' s.summary = 'Support for Ruby on Rails views powered by Liquid and loaded from database'