Skip to content

Commit

Permalink
Fixed the remaining bugs after the massive bug fixes and code changes…
Browse files Browse the repository at this point in the history
… from this week (old sites transition to 1.0).
  • Loading branch information
gaspard committed May 19, 2011
1 parent 208869b commit 49fd6ef
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 60 deletions.
4 changes: 3 additions & 1 deletion app/controllers/nodes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,11 @@ def destroy
respond_to do |format|
format.html do
if @node.destroy
# These flash messages tend to hang around stupidly
# flash[:notice] = _("Node destroyed.")
redirect_to params[:redir] || zen_path(@node.parent)
else
flash.now[:notice] = "Could not destroy node."
flash.now[:notice] = _("Could not destroy node.")
render :action => 'show'
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,7 @@ def create_nodes_from_folder(opts)
parent_id = opts[:parent_id] || opts[:parent][:id]
folder = opts[:folder]
defaults = (opts[:defaults] || {}).stringify_keys
# Initial object class
klass = opts[:class] || opts[:klass] || "Page"
res = {}

Expand Down Expand Up @@ -639,7 +640,6 @@ def create_nodes_from_folder(opts)
sub_folder = path
attrs = defaults.dup
attrs['v_lang'] ||= visitor.lang
attrs['klass'] = 'Page'
elsif filename =~ /^(.+?)(\.\w\w|)(\.\d+|)\.zml$/ # bird.jpg.en.zml
# node content in yaml
type = :node
Expand Down
71 changes: 34 additions & 37 deletions app/models/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Template < TextDocument
end

attr_protected :tkpath
before_validation :rebuild_tkpath
validate :validate_section, :validate_target_klass

# Class Methods
Expand All @@ -48,69 +49,64 @@ def filename
end

def skin
@skin ||= secure(Skin) { Skin.find(prop['skin_id']) }
@skin ||= secure(Skin) { Skin.find(skin_id) }
end

def rebuild_tkpath(target_klass = nil)
if prop['target_klass']
errors.add('format', "can't be blank") unless prop['format']


def rebuild_tkpath(rebuild_tklass = nil)
if target_klass
# this is a master template (found when choosing the template for rendering)
if target_klass
prop['target_klass'] = target_klass.name
prop['tkpath'] = target_klass.kpath
if klass = rebuild_tklass
# rebuilding index
self.target_klass = klass.name
self.tkpath = klass.kpath
self.title = title_from_mode_and_format
else
target_klass = Node.get_class(prop['target_klass'])
if target_klass
prop['tkpath'] = target_klass.kpath
else
errors.add('target_klass', 'invalid')
end
elsif klass = VirtualClass[target_klass]
self.tkpath = klass.kpath
end

else
self.tkpath = nil
end
end

private

def set_defaults
prop['mode'] = nil if prop['mode' ].blank?
prop['target_klass'] = nil if prop['target_klass'].blank?
self.mode = nil if mode.blank?
self.target_klass = nil if target_klass.blank?
super

# Force template extension to zafu
prop['ext'] = 'zafu'
self.ext = 'zafu'

# Force template content-type to 'text/zafu'
prop['content_type'] = 'text/zafu'
self.content_type = 'text/zafu'

if prop.title_changed?
if title =~ /^([A-Z][a-zA-Z]+?)(-(([a-zA-Z_\+]*)(-([a-zA-Z_]+)|))|)(\.|\Z)/
# title changed force update
prop['target_klass'] = $1 unless prop.target_klass_changed?
prop['mode'] = ($4 || '') unless prop.mode_changed?
prop['format'] = ($6 || 'html') unless prop.format_changed?
self.target_klass = $1 unless prop.target_klass_changed?
self.mode = ($4 || '') unless prop.mode_changed?
self.format = ($6 || 'html') unless prop.format_changed?
else
# title set but it is not a master template name
prop['target_klass'] = nil
prop['mode'] = nil
prop['format'] = nil
self.target_klass = nil
self.mode = nil
self.format = nil
end
end

if version.edited?
prop['mode'] = prop['mode'].gsub(/[^a-zA-Z\+]/, '') if prop['mode']
self.mode = mode.gsub(/[^a-zA-Z\+]/, '') if mode

if !prop['target_klass'].blank?
if !target_klass.blank?
# update title
prop['format'] = 'html' if prop['format'].blank?
self.format = 'html' if format.blank?
self.title = title_from_mode_and_format

if text.blank? && prop['format'] == 'html' && prop['mode'] != '+edit'
if text.blank? && format == 'html' && mode != '+edit'
# set a default text

if prop['target_klass'] == 'Node'
if target_klass == 'Node'
self.text = <<END_TXT
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
Expand Down Expand Up @@ -143,9 +139,9 @@ def set_defaults
end

def title_from_mode_and_format(opts={})
opts[:format] ||= prop['format']
opts[:mode ] ||= prop['mode']
opts[:target_klass ] ||= prop['target_klass']
opts[:format] ||= format
opts[:mode ] ||= mode
opts[:target_klass ] ||= target_klass
format = opts[:format] == 'html' ? '' : "-#{opts[:format]}"
mode = (!opts[:mode].blank? || format != '') ? "-#{opts[:mode]}" : ''
"#{opts[:target_klass]}#{mode}#{format}"
Expand All @@ -156,8 +152,9 @@ def validate_section
end

def validate_target_klass
if prop.target_klass_changed?
rebuild_tkpath
if target_klass
errors.add('format', "can't be blank") unless format
errors.add('target_klass', 'invalid') unless VirtualClass[target_klass]
end
end
end
10 changes: 7 additions & 3 deletions app/models/virtual_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -569,9 +569,13 @@ def propagate_kpath_change
if templates = secure(Node) { Node.all(
:conditions => "id IN (#{idx_templates.map{|r| r.node_id}.join(',')})")}
templates.each do |t|
t.rebuild_tkpath(self)
# What if this fails ? Abort all ?
t.save!
t.visible_versions.each do |version|
t.version = version
t.instance_variable_set(:@properties, version.prop)
t.rebuild_tkpath(self)
Zena::Db.execute "UPDATE #{version.class.table_name} SET properties=#{Zena::Db.quote(version.class.encode_properties(version.prop))} WHERE id=#{version[:id]}"
end
t.rebuild_index!
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion lib/zena/use/image_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ module Zena
module Use
class ImageBuilder
DEFAULT_FORMATS = {
'tiny' => { :name=>'tiny', :size=>:force, :width=>16, :height=>16 , :gravity=>Magick::CenterGravity },
'tiny' => { :name=>'tiny', :size=>:force, :width=>16, :height=>16 , :gravity=>Magick::CenterGravity },
'tipop' => { :name=>'tipop', :size=>:force, :width=>16, :height=>16 , :gravity=>Magick::CenterGravity, :popup => 'std'},
'mini' => { :name=>'mini', :size=>:force, :width=>32, :height=>32 , :gravity=>Magick::CenterGravity },
'square' => { :name=>'square', :size=>:limit, :width=>180, :height=>180, :gravity=>Magick::CenterGravity },
'med' => { :name=>'med', :size=>:limit, :width=>280, :height=>186, :gravity=>Magick::CenterGravity },
Expand Down
10 changes: 6 additions & 4 deletions lib/zena/use/query_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -510,10 +510,12 @@ def context_relation(relation)
end

if CORE_CONTEXTS.include?(relation)
if %w{project section}.include?(relation)
set_main_class(VirtualClass[relation.capitalize])
else
set_main_class(VirtualClass['Node'])
unless class_name
if %w{project section}.include?(relation)
set_main_class(VirtualClass[relation.capitalize])
else
set_main_class(VirtualClass['Node'])
end
end

# PREVIOUS_GROUP.id = NEW_GROUP.project_id
Expand Down
2 changes: 1 addition & 1 deletion test/functional/iformats_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def test_index
assert_response :success
assert_template 'index'
iformats = assigns['iformats']
assert_equal 11, iformats.size
assert_equal 12, iformats.size
end

def test_show
Expand Down
17 changes: 9 additions & 8 deletions test/functional/nodes_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ class NodesControllerTest < Zena::Controller::TestCase
assert_redirected_to '/foo/bar/baz'
end
end # with a redir param

context 'by changing a link comment' do
subject do
{:action => 'update', :controller => 'nodes', :id => nodes_zip(:opening), :node => {:link_id => links_id(:opening_in_art), :l_comment => 'To be removed'}}
Expand All @@ -276,8 +276,8 @@ class NodesControllerTest < Zena::Controller::TestCase
assert_response :redirect
end
end # by changing a link comment


context 'by changing a link date' do
subject do
{:action => 'update', :controller => 'nodes', :id => nodes_zip(:opening), :node => {:link_id => links_id(:opening_in_art), :l_date => '2011-03-29 17:51'}}
Expand All @@ -293,7 +293,7 @@ class NodesControllerTest < Zena::Controller::TestCase
assert_response :redirect
end
end # by changing a date

context 'by changing skin' do
subject do
{:action => 'update', :controller => 'nodes', :id => nodes_zip(:people), :node => {:skin_zip => nodes_zip(:wikiSkin), :inherit => 0}}
Expand Down Expand Up @@ -478,10 +478,11 @@ class NodesControllerTest < Zena::Controller::TestCase
assert_response :redirect
end

should 'be noticed that the node is destroyed' do
delete_subject
assert_equal 'Node destroyed.', flash[:notice]
end
# No, flash removed
# should 'be noticed that the node is destroyed' do
# delete_subject
# assert_equal 'Node destroyed.', flash[:notice]
# end

should 'delete the node' do
assert_difference('Node.count', -1) do
Expand Down
4 changes: 2 additions & 2 deletions test/unit/iformat_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ def test_defined_format

def test_list
login(:lion)
assert_equal %w{tiny mini pv square low top med side edit std full}, Iformat.list.map{|h| h[:name]}
assert_equal %w{tiny tipop mini pv square low top med side edit std full}, Iformat.list.map{|h| h[:name]}

login(:whale)
assert_equal %w{tiny mini pv square low med top side header edit std full}, Iformat.list.map{|h| h[:name]}
assert_equal %w{tiny tipop mini pv square low med top side header edit std full}, Iformat.list.map{|h| h[:name]}
end

def test_mem_cached
Expand Down
2 changes: 1 addition & 1 deletion test/unit/template_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def self.should_set_target_class_mode_and_format

should 'destroy index if target_klass is removed' do
assert_difference('IdxTemplate.count', -1) do
assert subject.update_attributes(:target_klass => '')
assert subject.update_attributes(:target_klass => '', :v_status => Zena::Status[:pub])
end
end
end # with target_klass
Expand Down
2 changes: 1 addition & 1 deletion test/unit/text_document_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def test_parse_assets
#header { background:url('bird.jpg') }
#pv { background:url('bird_pv.jpg') }
#footer { background:url('/projects list/a wiki with Zena/flower.jpg') }
#back { background:url('../../projects list/a wiki with Zena/flower.jpg') }
#back { background:url('../../../projects list/a wiki with Zena/flower.jpg') }
#no_stamp { background:url('/en/image30_pv.jpg') }
END_CSS
node.text = start.dup
Expand Down

0 comments on commit 49fd6ef

Please sign in to comment.