Skip to content

Commit

Permalink
All tests pass with new 'on-the-fly' rendering of templates.
Browse files Browse the repository at this point in the history
  • Loading branch information
gaspard committed May 23, 2012
1 parent 0b3c80b commit 5db08f7
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 13 deletions.
9 changes: 4 additions & 5 deletions lib/zena/use/zafu_templates.rb
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,9 @@ def template_url(opts={})
if @skin
zafu_url, template = get_best_template(kpaths, format, mode, @skin)
return default_template_url(opts) unless zafu_url

rel_path = current_site.zafu_path + "/#{zafu_url}/#{lang_path}/_main.erb"
path = SITES_ROOT + rel_path

if !File.exists?(path) || params[:rebuild]
if @node && klass = VirtualClass.find_by_kpath(template.tkpath)
zafu_node('@node', klass)
Expand Down Expand Up @@ -324,8 +323,6 @@ def template_path_from_template_url(suffix='', template_url=params[:t_url], buil

main_fullpath = SITES_ROOT + (base_p + lang_p + ['_main.erb']).join('/')
if !File.exist?(main_fullpath) && build
# We cannot compile the template because we do not have the correct @node....
# ... too bad.
skin = template_url[0]
template_name = template_url[-2]
if template_name =~ ::Template::MODE_FORMAT_FROM_TITLE
Expand All @@ -338,7 +335,9 @@ def template_path_from_template_url(suffix='', template_url=params[:t_url], buil
# Find first node matching klass
vclass = VirtualClass[klass]
@node = Node.sfind("#{klass.underscore} in site", :first)
@node.skin = node_bak.skin
if @node.skin.title != skin
@node.skin = secure(Skin) { Skin.find_by_title(skin) }
end
template_url(:mode => mode, :format => format)
@node = node_bak
end
Expand Down
4 changes: 2 additions & 2 deletions test/integration/zafu_compiler/errors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ toggle_bad_finder_class:
map_join:
context:
node: 'cleanWater'
src: "<r:children do='map(:flobo).join(\",\")'/>"
tem: "/unknown method .*map\(:flobo\)/"
src: "<r:children do='map(\"flobo\").join(\",\")'/>"
tem: "/unknown method <span class='type'>flobo\(\)</span>/"

datebox_on_vclass:
src: "<r:Contact><r:input type='date' name='log_at'/></r:Contact>"
Expand Down
2 changes: 1 addition & 1 deletion test/integration/zafu_compiler/roles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ list_relations_filter_group:
res: "reference, reference_for, set_tag"

input_relation_name:
src: "<r:select name='rel' eval='Contact.relations(\"doc\").map(:name)'/>"
src: "<r:select name='rel' eval='Contact.relations(\"doc\").map(\"name\")'/>"
res: "<select name='node[rel]'><option value=\"reference\">reference</option>\n<option value=\"reference_for\">reference_for</option>\n<option value=\"set_tag\">set_tag</option></select>"

manual_select:
Expand Down
4 changes: 2 additions & 2 deletions test/integration/zafu_compiler/safe_definitions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ sum:
map_on_can_be_nil:
context:
node: 'cleanWater'
eval: "Contact.relations.map(:name).join('-')"
tem: "/VirtualClass\[\"Contact\"\] \? VirtualClass\[\"Contact\"\].all_relations.map\(&:other_role\).compact.join\(\"-\"\)/"
eval: "Contact.relations.map(\"name\").join('-')"
tem: "/VirtualClass\[\"Contact\"\] \? VirtualClass\[\"Contact\"\].all_relations.map\{\|_map_obj\| _map_obj.other_role\}.compact.join\(\"-\"\)/"
res: "/collaborator_for-favorite-favorite_for/"

min:
Expand Down
2 changes: 1 addition & 1 deletion test/integration/zafu_compiler/urls.yml
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ target_blank:

action_destroy:
src: "<r:link action='destroy'/>"
res: "<a data-confirm='Destroy ? \"status title\"' href='/nodes/22' onclick='return Zena.m(this,\"delete\")'>status title</a>"
res: "<a data-confirm='Destroy status title ?' href='/nodes/22' onclick='return Zena.m(this,\"delete\")'>status title</a>"

action_publish:
src: "<r:link action='publish'/>"
Expand Down
1 change: 1 addition & 0 deletions test/sites/zena/versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ wiki_page_changes_en:
prop:
comment: layout for wiki
summary: Layout for the wiki skin.
title: Page-changes
text: |
<r:include template='layout.html'>
<r:with part='body/content/main'>
Expand Down
14 changes: 12 additions & 2 deletions test/unit/zena/use/rendering_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,21 @@ class RenderingTest < Zena::View::TestCase
context 'resolving template_url' do

should 'append host and insert lang on template_path_from_template_url' do
assert_equal '/test.host/zafu/SKIN/TEMPLATE/en/DOM_ID', template_path_from_template_url('', 'SKIN/TEMPLATE/DOM_ID')
assert_equal '/test.host/zafu/SKIN/TEMPLATE/en/DOM_ID.erb', template_path_from_template_url('', 'SKIN/TEMPLATE/DOM_ID', false)
end

should 'build template on template_path_from_template_url' do
fullpath = fullpath_from_template_url('wiki skin/Page-changes/_main', false)
if File.exist?(fullpath)
FileUtils.rm(fullpath)
end
assert_equal '/test.host/zafu/wiki skin/Page-changes/en/foo.erb', template_path_from_template_url('', 'wiki skin/Page-changes/foo', true)
assert File.exist?(fullpath)
FileUtils.rm(fullpath)
end

should 'return a fullpath on fullpath_from_template_url' do
assert_equal "#{SITES_ROOT}/test.host/zafu/SKIN/TEMPLATE/en/DOM_ID", fullpath_from_template_url('', 'SKIN/TEMPLATE/DOM_ID')
assert_equal "#{SITES_ROOT}/test.host/zafu/SKIN/TEMPLATE/en/DOM_ID.erb", fullpath_from_template_url('SKIN/TEMPLATE/DOM_ID', false)
end

should 'return a relative path on admin_layout' do
Expand Down

0 comments on commit 5db08f7

Please sign in to comment.