fix a major bug when updating template children which have the same parent + remove debug output + rspec tests pass
This commit is contained in:
parent
d7aba616f6
commit
335d7a1aac
8
Gemfile
8
Gemfile
@ -3,9 +3,10 @@ source 'http://rubygems.org'
|
||||
|
||||
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_acts_as_tree', '0.1.5'
|
||||
gem 'mongo_session_store', '2.0.0.pre'
|
||||
@ -42,7 +43,8 @@ group :test do
|
||||
gem 'growl-glue'
|
||||
gem 'rspec-rails', '2.0.0.beta.19'
|
||||
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 'capybara'
|
||||
|
||||
|
17
Gemfile.lock
17
Gemfile.lock
@ -13,16 +13,20 @@ GIT
|
||||
|
||||
GIT
|
||||
remote: git://github.com/locomotivecms/liquid.git
|
||||
revision: 7ce591f
|
||||
ref: 7ce591f38ab826875337
|
||||
revision: 9ec5709
|
||||
ref: 9ec570927f5281e1f397
|
||||
specs:
|
||||
liquid (2.1.3)
|
||||
|
||||
GIT
|
||||
remote: http://github.com/codegram/pickle.git
|
||||
revision: 2834204
|
||||
remote: http://github.com/ianwhite/pickle.git
|
||||
revision: 65ba8b7
|
||||
specs:
|
||||
pickle (0.3.0)
|
||||
pickle (0.4.2)
|
||||
cucumber (>= 0.8)
|
||||
rake
|
||||
rspec (>= 1.3)
|
||||
yard
|
||||
|
||||
GEM
|
||||
remote: http://rubygems.org/
|
||||
@ -226,6 +230,7 @@ GEM
|
||||
rack-test (>= 0.5.3)
|
||||
will_paginate (3.0.pre2)
|
||||
xml-simple (1.0.12)
|
||||
yard (0.6.0)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
@ -235,7 +240,7 @@ DEPENDENCIES
|
||||
actionmailer-with-request
|
||||
autotest
|
||||
aws
|
||||
bson_ext (>= 1.0.1)
|
||||
bson_ext (= 1.0.4)
|
||||
capybara
|
||||
carrierwave (= 0.5.0.beta2)
|
||||
cgi_multipart_eof_fix
|
||||
|
@ -60,17 +60,11 @@ module Models
|
||||
|
||||
context = default_context.merge(context)
|
||||
|
||||
# puts "*** [#{self.fullpath}] enter context = #{context.object_id} / #{context[:page].fullpath}"
|
||||
|
||||
@template = ::Liquid::Template.parse(self.raw_template, context)
|
||||
|
||||
# puts "*** exit context = #{context.object_id}"
|
||||
|
||||
self.template_dependencies = context[:templates]
|
||||
self.snippet_dependencies = context[:snippets]
|
||||
|
||||
# puts "*** [#{self.fullpath}] template_dependencies = #{self.template_dependencies.inspect}"
|
||||
|
||||
@template.root.context.clear
|
||||
end
|
||||
|
||||
@ -87,25 +81,17 @@ module Models
|
||||
# group them by fullpath for better performance
|
||||
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)
|
||||
|
||||
# finally save them all
|
||||
template_descendants.map(&:save)
|
||||
|
||||
# puts "** first descendant = #{descendants.first.object_id} / #{descendants.first.template.inspect}"
|
||||
end
|
||||
|
||||
def _update_direct_template_descendants(template_descendants, cached)
|
||||
# puts "*** [#{self.fullpath}] _update_direct_template_descendants"
|
||||
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
|
||||
end
|
||||
|
||||
# puts "*** [#{self.fullpath}] direct = #{direct_descendants.inspect}"
|
||||
|
||||
direct_descendants.each do |page|
|
||||
page.send(:_parse_and_serialize_template, { :cached_parent => self, :cached_pages => cached })
|
||||
|
||||
|
4
doc/TODO
4
doc/TODO
@ -7,13 +7,13 @@ x display liquid errors
|
||||
x theme assets selector in page editor
|
||||
x saving page in ajax
|
||||
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
|
||||
|
||||
- refactor slugify method (use parameterize + create a module)
|
||||
- [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:
|
||||
|
||||
|
@ -3,54 +3,18 @@ module Locomotive
|
||||
module Tags
|
||||
class Extends < ::Liquid::Extends
|
||||
|
||||
attr_accessor :page_id # parent page id
|
||||
|
||||
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])
|
||||
|
||||
def prepare_parsing
|
||||
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
|
||||
|
||||
private
|
||||
|
||||
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 @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?
|
||||
|
||||
# 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
|
||||
|
@ -3,31 +3,12 @@ module Locomotive
|
||||
module Tags
|
||||
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
|
||||
# puts "** InheritedBlock[end_tag] before super #{@name} / #{@context.object_id}/ #{@context[:page].fullpath}"
|
||||
|
||||
self.register_current_block
|
||||
super
|
||||
|
||||
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)
|
||||
end
|
||||
|
||||
# puts "** InheritedBlock[end_tag] after super #{@name} / #{@context.object_id}/ #{@context[:page].fullpath}"
|
||||
end
|
||||
|
||||
protected
|
||||
|
@ -12,7 +12,7 @@ module Locomotive
|
||||
|
||||
@slug = @template_name.gsub('\'', '')
|
||||
|
||||
@context[:snippets] << @slug
|
||||
(@context[:snippets] << @slug).uniq!
|
||||
|
||||
snippet = @context[:site].snippets.where(:slug => @slug).first
|
||||
|
||||
|
@ -1,12 +1,12 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Locomotive::Liquid::Tags::EditableShortText do
|
||||
describe Locomotive::Liquid::Tags::Editable::ShortText do
|
||||
|
||||
it 'should have a valid syntax' do
|
||||
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
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user