Skip to content

Commit

Permalink
Fixed caching bug, removed 'h' from arguments to use in rubyless meth…
Browse files Browse the repository at this point in the history
…ods.
  • Loading branch information
gaspard committed Sep 6, 2012
1 parent fd832d9 commit 0836fe1
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 10 deletions.
7 changes: 7 additions & 0 deletions app/models/cached_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ def cached_page_after_save
else
File.open(filepath, "wb+") { |f| f.write(content_data) }
end

if path =~ %r{^#{current_site.public_path}/(\w\w)\.html$}
# Root cache: make sure we create directory to prevent
# Multiviews errors.
lang_path = "#{SITES_ROOT}#{current_site.public_path}/#{$1}"
Dir.mkdir(lang_path) unless File.exist?(lang_path)
end

# create join values from context for automatic expire
if (ids = @expire_with_ids || visitor.visited_node_ids) != []
Expand Down
2 changes: 2 additions & 0 deletions lib/zafu/process/ruby_less_processing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
module Zafu
module Process
module RubyLessProcessing
EXCLUDE_KEYS_IN_ARGS = [:h]
include RubyLess

def self.included(base)
Expand Down Expand Up @@ -211,6 +212,7 @@ def method_with_arguments(method, params)
hash_arguments = []
arguments = []
params.keys.sort {|a,b| a.to_s <=> b.to_s}.each do |k|
next if EXCLUDE_KEYS_IN_ARGS.include?(k)
if k =~ /\A_/
arguments << "%Q{#{params[k]}}"
else
Expand Down
6 changes: 1 addition & 5 deletions lib/zena/use/rendering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,7 @@ def cache_page(opts={})
if perform_caching && caching_allowed(:authenticated => opts.delete(:authenticated))

url = page_cache_file(opts.delete(:url))
if url =~ %r{^/(\w\w)\.html$}
# Root cache: make sure we create directory to prevent
# Multiviews errors.
Dir.mkdir(SITES_ROOT + current_site.public_path + "/#{$1}")
end

opts = {:expire_after => nil,
:path => (current_site.public_path + url),
:content_data => response.body,
Expand Down
2 changes: 1 addition & 1 deletion lib/zena/use/urls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ def make_href(remote_target = nil, opts = {})

def insert_ajax_args(target, hash_params, action)
hash_params << ":s => start_id"
hash_params << ":link_id => this.link_id" if @context[:has_link_id] && node.will_be?(Node)
hash_params << ":link_id => this.link_id" if @context[:has_link_id] && node.will_be?(Node) && !node.list_context?

# FIXME: when we have proper markup.dyn_params[:id] support,
# we should not need this crap anymore.
Expand Down
15 changes: 12 additions & 3 deletions test/integration/navigation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -420,12 +420,21 @@ def test_cache_root
root_path = "#{SITES_ROOT}#{visitor.site.public_path}/en.html"
lang_dir = "#{SITES_ROOT}#{visitor.site.public_path}/en"
assert !File.exists?(root_path), "No cached file yet"
assert !File.exists?(lang_dir), "No cached file yet"
assert !File.exists?(lang_dir), "No cached directory yet"
get 'http://test.host/en'
assert_response :success

# Both en.html and en directory exist
assert !File.exists?(root_path), "No cached file yet"
assert !File.exists?(lang_dir), "No cached file yet"
assert File.exists?(root_path), "Cached file created"
assert File.exists?(lang_dir), "Cached directory created"

FileUtils.rm root_path
# Only en directory exists
get 'http://test.host/en'
assert_response :success
# Both en.html and en directory exist
assert File.exists?(root_path), "Cached file created"
assert File.exists?(lang_dir), "Cached directory created"
end
end
end
Expand Down
5 changes: 5 additions & 0 deletions test/integration/zafu_compiler/display.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ show_title:
src: "<r:title/>"
tem: "<%=h @node.prop['title'] %>"
res: "status title"

show_title_h_false:
src: "<r:title h='false'/>"
tem: "<%= @node.prop['title'] %>"
res: "status title"

show_title_with_opts:
old_src: "<h1 do='title' class='s70' status='true' actions='all'>this is the title</h1>"
Expand Down
6 changes: 6 additions & 0 deletions test/integration/zafu_compiler/urls.yml
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,12 @@ link_page_next_with_block:
src: "<r:nodes in='site' limit='3' order='zip' paginate='pak'><r:link page='next' do='t'>next</r:link></r:nodes>"
res: "<a href='/oo/projects-list/Clean-Water-project/page22.html?pak=2'>next</a>"

link_page_next_relation:
context:
node: art
src: "<r:Tag?><div id='a' do='block' do='tagged order by l_status asc limit 1 paginate pak'><r:link page='next' update='a' do='t'>next</r:link></div></r:Tag?>"
res: "!/parser_error/"

link_page_list:
context:
pak: 2
Expand Down
2 changes: 1 addition & 1 deletion zena.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Gem::Specification.new do |s|

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Gaspard Bucher"]
s.date = %q{2012-09-05}
s.date = %q{2012-09-06}
s.default_executable = %q{zena}
s.description = %q{zena is a Ruby on Rails CMS (content managment system) with a focus on usability, ease of customization and web 2.0 goodness (application like behaviour).}
s.email = %q{gaspard@teti.ch}
Expand Down

0 comments on commit 0836fe1

Please sign in to comment.