fix a major bug when updating template children which have the same parent + remove debug output + rspec tests pass

This commit is contained in:
dinedine 2010-08-31 01:56:54 +02:00
parent d7aba616f6
commit 335d7a1aac
8 changed files with 30 additions and 92 deletions

View File

@ -3,9 +3,10 @@ source 'http://rubygems.org'
gem 'rails', '3.0.0.rc' gem 'rails', '3.0.0.rc'
gem 'liquid', :git => 'git://github.com/locomotivecms/liquid.git', :ref => '7ce591f38ab826875337' # gem 'liquid', :path => '../gems/liquid' # local
gem 'liquid', :git => 'git://github.com/locomotivecms/liquid.git', :ref => '9ec570927f5281e1f397'
gem 'bson_ext', '>= 1.0.1' gem 'bson_ext', '1.0.4'
gem 'mongoid', '2.0.0.beta.16' gem 'mongoid', '2.0.0.beta.16'
gem 'mongoid_acts_as_tree', '0.1.5' gem 'mongoid_acts_as_tree', '0.1.5'
gem 'mongo_session_store', '2.0.0.pre' gem 'mongo_session_store', '2.0.0.pre'
@ -42,7 +43,8 @@ group :test do
gem 'growl-glue' gem 'growl-glue'
gem 'rspec-rails', '2.0.0.beta.19' gem 'rspec-rails', '2.0.0.beta.19'
gem 'factory_girl_rails' gem 'factory_girl_rails'
gem 'pickle', :git => 'http://github.com/codegram/pickle.git' # gem 'pickle', :git => 'http://github.com/codegram/pickle.git'
gem 'pickle', :git => 'http://github.com/ianwhite/pickle.git'
gem 'pickle-mongoid' gem 'pickle-mongoid'
gem 'capybara' gem 'capybara'

View File

@ -13,16 +13,20 @@ GIT
GIT GIT
remote: git://github.com/locomotivecms/liquid.git remote: git://github.com/locomotivecms/liquid.git
revision: 7ce591f revision: 9ec5709
ref: 7ce591f38ab826875337 ref: 9ec570927f5281e1f397
specs: specs:
liquid (2.1.3) liquid (2.1.3)
GIT GIT
remote: http://github.com/codegram/pickle.git remote: http://github.com/ianwhite/pickle.git
revision: 2834204 revision: 65ba8b7
specs: specs:
pickle (0.3.0) pickle (0.4.2)
cucumber (>= 0.8)
rake
rspec (>= 1.3)
yard
GEM GEM
remote: http://rubygems.org/ remote: http://rubygems.org/
@ -226,6 +230,7 @@ GEM
rack-test (>= 0.5.3) rack-test (>= 0.5.3)
will_paginate (3.0.pre2) will_paginate (3.0.pre2)
xml-simple (1.0.12) xml-simple (1.0.12)
yard (0.6.0)
PLATFORMS PLATFORMS
ruby ruby
@ -235,7 +240,7 @@ DEPENDENCIES
actionmailer-with-request actionmailer-with-request
autotest autotest
aws aws
bson_ext (>= 1.0.1) bson_ext (= 1.0.4)
capybara capybara
carrierwave (= 0.5.0.beta2) carrierwave (= 0.5.0.beta2)
cgi_multipart_eof_fix cgi_multipart_eof_fix

View File

@ -60,17 +60,11 @@ module Models
context = default_context.merge(context) context = default_context.merge(context)
# puts "*** [#{self.fullpath}] enter context = #{context.object_id} / #{context[:page].fullpath}"
@template = ::Liquid::Template.parse(self.raw_template, context) @template = ::Liquid::Template.parse(self.raw_template, context)
# puts "*** exit context = #{context.object_id}"
self.template_dependencies = context[:templates] self.template_dependencies = context[:templates]
self.snippet_dependencies = context[:snippets] self.snippet_dependencies = context[:snippets]
# puts "*** [#{self.fullpath}] template_dependencies = #{self.template_dependencies.inspect}"
@template.root.context.clear @template.root.context.clear
end end
@ -87,25 +81,17 @@ module Models
# group them by fullpath for better performance # group them by fullpath for better performance
cached = template_descendants.inject({}) { |memo, page| memo[page.fullpath] = page; memo } cached = template_descendants.inject({}) { |memo, page| memo[page.fullpath] = page; memo }
# puts "*** [#{self.fullpath}] #{template_descendants.collect(&:fullpath).inspect}"
self._update_direct_template_descendants(template_descendants, cached) self._update_direct_template_descendants(template_descendants, cached)
# finally save them all # finally save them all
template_descendants.map(&:save) template_descendants.map(&:save)
# puts "** first descendant = #{descendants.first.object_id} / #{descendants.first.template.inspect}"
end end
def _update_direct_template_descendants(template_descendants, cached) def _update_direct_template_descendants(template_descendants, cached)
# puts "*** [#{self.fullpath}] _update_direct_template_descendants"
direct_descendants = template_descendants.select do |page| direct_descendants = template_descendants.select do |page|
# puts "*** \t\t[#{self.fullpath}] _update_direct_template_descendants (#{page.template_dependencies.inspect})"
((page.template_dependencies || []) - (self.template_dependencies || [])).size == 1 ((page.template_dependencies || []) - (self.template_dependencies || [])).size == 1
end end
# puts "*** [#{self.fullpath}] direct = #{direct_descendants.inspect}"
direct_descendants.each do |page| direct_descendants.each do |page|
page.send(:_parse_and_serialize_template, { :cached_parent => self, :cached_pages => cached }) page.send(:_parse_and_serialize_template, { :cached_parent => self, :cached_pages => cached })

View File

@ -7,13 +7,13 @@ x display liquid errors
x theme assets selector in page editor x theme assets selector in page editor
x saving page in ajax x saving page in ajax
x editable_long_text tag x editable_long_text tag
- blocking issue when modifying the parent of 2 templates => one of the 2 children has reference of the first child x blocking issue when modifying the parent of 2 templates => one of the 2 children has reference of the first child
- editable_file tag - editable_file tag
- refactor slugify method (use parameterize + create a module) - refactor slugify method (use parameterize + create a module)
- [content types] the "display column" selector should not include file types - [content types] the "display column" selector should not include file types
- add dom_id and css_class fields in page (body structure ?) ! add dom_id and css_class fields in page (body structure ?)
BACKLOG: BACKLOG:

View File

@ -3,54 +3,18 @@ module Locomotive
module Tags module Tags
class Extends < ::Liquid::Extends class Extends < ::Liquid::Extends
attr_accessor :page_id # parent page id def prepare_parsing
def initialize(tag_name, markup, tokens, context)
if markup =~ Syntax
@template_name = $1.gsub('\'', '').strip
else
raise ::Liquid::SyntaxError.new("Error in tag 'extends' - Valid syntax: extends [template]")
end
# puts "** [Extends] #{context[:page].fullpath}"
@context = context
retrieve_parent_page
# before parsing the embedded tokens, get editable elements from parent page
@context[:page].merge_editable_elements_from_page(@context[:parent_page])
super super
# puts "** after extends, @context[:templates] = #{@context[:templates].inspect}" parent_page = @context[:parent_page]
@context[:snippets] = parent_page.snippet_dependencies
@context[:templates] = ([*parent_page.template_dependencies] + [parent_page.id]).compact
end end
private private
def parse_parent_template def parse_parent_template
page = @context[:parent_page]
template = page.template
# merge blocks ?
blocks = find_blocks(template.root.nodelist)
blocks.each_value do |block|
# puts "*** [Extends] merging #{block.name} / #{@context.object_id}"
block.send(:instance_variable_set, :"@context", @context)
block.send(:register_current_block)
end
@context[:snippets] = page.snippet_dependencies
@context[:templates] = ([*page.template_dependencies] + [@page_id]).compact
# puts "@context[:templates] = #{[*page.template_dependencies].inspect} + #{[@page_id].inspect} = #{@context[:templates].inspect}"
template
end
def retrieve_parent_page
if @template_name == 'parent' if @template_name == 'parent'
if @context[:cached_parent] if @context[:cached_parent]
@context[:parent_page] = @context[:cached_parent] @context[:parent_page] = @context[:cached_parent]
@ -65,9 +29,9 @@ module Locomotive
raise PageNotFound.new("Page with fullpath '#{@template_name}' was not found") if @context[:parent_page].nil? raise PageNotFound.new("Page with fullpath '#{@template_name}' was not found") if @context[:parent_page].nil?
# puts "** @page_id = #{@context[:parent_page].id}" @context[:page].merge_editable_elements_from_page(@context[:parent_page])
@page_id = @context[:parent_page].id @context[:parent_page].template
end end
end end

View File

@ -3,31 +3,12 @@ module Locomotive
module Tags module Tags
class InheritedBlock < ::Liquid::InheritedBlock class InheritedBlock < ::Liquid::InheritedBlock
def initialize(tag_name, markup, tokens, context)
if markup =~ Syntax
@name = $1
else
raise ::Liquid::SyntaxError.new("Error in tag 'block' - Valid syntax: block [name]")
end
context[:current_block] = self # for now, no need to push it in a stack
# puts "** InheritedBlock[begin] #{context.object_id} / #{@name} / #{context[:page].try(:fullpath)}"
super if tokens
end
def end_tag def end_tag
# puts "** InheritedBlock[end_tag] before super #{@name} / #{@context.object_id}/ #{@context[:page].fullpath}" super
self.register_current_block
if !self.contains_super?(@nodelist) # then disable all editable_elements coming from the parent block too and not used if !self.contains_super?(@nodelist) # then disable all editable_elements coming from the parent block too and not used
# puts "** InheritedBlock[end_tag] disabling_parent_editable_elements... #{@context.object_id}"
@context[:page].disable_parent_editable_elements(@name) @context[:page].disable_parent_editable_elements(@name)
end end
# puts "** InheritedBlock[end_tag] after super #{@name} / #{@context.object_id}/ #{@context[:page].fullpath}"
end end
protected protected

View File

@ -12,7 +12,7 @@ module Locomotive
@slug = @template_name.gsub('\'', '') @slug = @template_name.gsub('\'', '')
@context[:snippets] << @slug (@context[:snippets] << @slug).uniq!
snippet = @context[:site].snippets.where(:slug => @slug).first snippet = @context[:site].snippets.where(:slug => @slug).first

View File

@ -1,12 +1,12 @@
require 'spec_helper' require 'spec_helper'
describe Locomotive::Liquid::Tags::EditableShortText do describe Locomotive::Liquid::Tags::Editable::ShortText do
it 'should have a valid syntax' do it 'should have a valid syntax' do
markup = "'title', hint: 'Simple short text'" markup = "'title', hint: 'Simple short text'"
Locomotive::Liquid::Tags::EditableShortText.any_instance.stubs(:end_tag).returns(true) Locomotive::Liquid::Tags::Editable::ShortText.any_instance.stubs(:end_tag).returns(true)
lambda do lambda do
Locomotive::Liquid::Tags::EditableShortText.new('editable_short_text', markup, ["{% endeditable_short_text %}"], {}) Locomotive::Liquid::Tags::Editable::ShortText.new('editable_short_text', markup, ["{% endeditable_short_text %}"], {})
end.should_not raise_error end.should_not raise_error
end end