Skip to content

Commit

Permalink
Added 'label', 'tlabel' and blank options to show method (label is a …
Browse files Browse the repository at this point in the history
…dyn string).
  • Loading branch information
gaspard committed Jan 16, 2011
1 parent 118606e commit 7df9a75
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 17 deletions.
2 changes: 1 addition & 1 deletion config/gems.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ will_paginate: '~> 2.3.12'
differ: '>= 0.1.1'
shoulda: '= 2.10.3'

querybuilder: '>= 0.9.4'
querybuilder: '>= 0.9.5'
yamltest: '>= 0.7.0'
rubyless: '>= 0.8.2'
property: '>= 2.1.2'
Expand Down
30 changes: 27 additions & 3 deletions lib/zena/use/display.rb
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,31 @@ def r_show(code = nil)
res = show_string(method)
end

res
if (label = @params[:label] || @params[:tlabel]) && (attribute = @params[:attr])
case label
when 'true'
res = "<label>#{attribute}</label> <span>#{res}</span>"
when 't'
res = "<label>#{trans(attribute)}</label> <span>#{res}</span>"
else
if @params[:tlabel]
code = ::RubyLess.translate(self, "t(%Q{#{label}})")
else
code = ::RubyLess.translate_string(self, label)
end
if code.literal
res = "<label>#{code.literal}</label> <span>#{res}</span>"
else
res = "<label><%= #{code} %></label> <span>#{res}</span>"
end
end
end

if @params[:blank] == 'hide'
"<% if !#{method}.blank? -%>#{@markup.wrap(res)}<% end -%>"
else
res
end
end

# Insert javascript asset tags
Expand Down Expand Up @@ -573,7 +597,7 @@ def r_zena
"<a class='zena' href='http://zenadmin.org' title='Zena <%= Zena::VERSION %>'>#{text}</a>"
end
end

def r_grid
return parser_error("not in a list context") unless node.list_context?
return parser_error("not a Node list") unless node.single_class <= Node
Expand All @@ -585,7 +609,7 @@ def r_grid
</table>})]
expand_with
end

private
def show_number(method)
if fmt = @params[:format]
Expand Down
8 changes: 7 additions & 1 deletion test/integration/query_node/errors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,11 @@ site:
err: "Unknown relation 'site'."

pages_from_site_or_images:
# should be 'in site'
src: '(project from site) or images'
err: "Unknown relation 'site'."
err: "Unknown relation 'site'."

pagination_without_limit:
src: "pages in site paginate p"
# qb processor.rb 571
err: 'Invalid paginate clause (used without limit).'
23 changes: 22 additions & 1 deletion test/integration/zafu_compiler/display.yml
Original file line number Diff line number Diff line change
Expand Up @@ -275,4 +275,25 @@ admin_links_for_anon:
string_limit:
src: "<div do=\"text.limit(10, %Q{<a href='#{url}'>read more</a>})\"/>"
tem: "<div><%= (@node.prop['text'] ? @node.prop['text'].limit(10, \"<a href='#{zen_url(@node)}'>read more</a>\") : nil) %></div>"
res: "<div>status tex<a href='http://test.host/oo/projects-list/Clean-Water-project/page22.html'>read more</a></div>"
res: "<div>status tex<a href='http://test.host/oo/projects-list/Clean-Water-project/page22.html'>read more</a></div>"

show_with_label_shortcut:
context:
lang: fr
src: "<li do='show' label='t' blank='hide' attr='title'/>"
tem: "<% if !@node.prop['title'].blank? -%><li><label>titre</label> <span><%= @node.prop['title'] %></span></li><% end -%>"
res: "<li><label>titre</label> <span>Etat des travaux</span></li>"

show_with_custom_label_shortcut:
context:
lang: fr
src: "<li do='show' label='#{t(\"en\")}' blank='hide' attr='title'/>"
tem: "/anglais/"
res: "<li><label>anglais</label> <span>Etat des travaux</span></li>"

show_with_custom_tlabel_shortcut:
context:
lang: fr
src: "<li do='show' tlabel='en' blank='hide' attr='title'/>"
tem: "/anglais/"
res: "<li><label>anglais</label> <span>Etat des travaux</span></li>"
12 changes: 11 additions & 1 deletion test/integration/zafu_compiler/errors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,14 @@ map_join:
context:
node: 'cleanWater'
src: "<r:children do='map(:flobo).join(\",\")'/>"
tem: "/unknown method .*map\(:flobo\)/"
tem: "/unknown method .*map\(:flobo\)/"

query_on_vclass:
# typical syntax error (should be Contact?)
src: "<r:Contact><div do='pages in site'>...</div></r:Contact>"
# should not crash
tem: "<% if var1 = VirtualClass[\"Contact\"] -%><span class='parser_error'><span class='method'>pages in site</span> <span class='message'>No query builder for class VirtualClass</span></span><% end -%>"

datebox_on_vclass:
src: "<r:Contact><p do='show' date='log_at'/></r:Contact>"
tem: "/unknown method 'log_at\(\)' for 'var1' of type VirtualClass./"
22 changes: 12 additions & 10 deletions 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("> 1.3.1") if s.respond_to? :required_rubygems_version=
s.authors = ["Gaspard Bucher"]
s.date = %q{2010-12-08}
s.date = %q{2011-01-16}
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 Expand Up @@ -447,6 +447,7 @@ Gem::Specification.new do |s|
"db/migrate/20101116103920_change_scope_index.rb",
"db/migrate/20101123125822_add_integer_idx.rb",
"db/migrate/20101130134522_add_index_field.rb",
"db/migrate/20101213133816_add_group_to_relation.rb",
"doc/README_FOR_APP",
"doc/fixtures.graffle",
"doc/fixtures.pdf",
Expand Down Expand Up @@ -561,6 +562,7 @@ Gem::Specification.new do |s|
"lib/zena/use/kpath.rb",
"lib/zena/use/ml_index.rb",
"lib/zena/use/nested_attributes_alias.rb",
"lib/zena/use/node_context.rb",
"lib/zena/use/prop_eval.rb",
"lib/zena/use/query_builder.rb",
"lib/zena/use/query_comment.rb",
Expand Down Expand Up @@ -2209,11 +2211,11 @@ Gem::Specification.new do |s|
s.add_runtime_dependency(%q<ruby-recaptcha>, ["= 1.0.0"])
s.add_runtime_dependency(%q<tzinfo>, [">= 0.3.12"])
s.add_runtime_dependency(%q<rails>, ["= 2.3.8"])
s.add_runtime_dependency(%q<rubyless>, [">= 0.8.1"])
s.add_runtime_dependency(%q<rubyless>, [">= 0.8.2"])
s.add_runtime_dependency(%q<property>, [">= 2.1.2"])
s.add_runtime_dependency(%q<uuidtools>, ["= 2.0.0"])
s.add_runtime_dependency(%q<authlogic>, ["= 2.1.3"])
s.add_runtime_dependency(%q<zafu>, [">= 0.7.5"])
s.add_runtime_dependency(%q<zafu>, [">= 0.7.6"])
s.add_runtime_dependency(%q<shoulda>, ["= 2.10.3"])
s.add_runtime_dependency(%q<fast_gettext>, ["~> 0.4.16"])
s.add_runtime_dependency(%q<syntax>, ["= 1.0.0"])
Expand All @@ -2226,16 +2228,16 @@ Gem::Specification.new do |s|
s.add_runtime_dependency(%q<hpricot>, [">= 0"])
s.add_runtime_dependency(%q<differ>, [">= 0.1.1"])
s.add_runtime_dependency(%q<RedCloth>, ["= 3.0.4"])
s.add_runtime_dependency(%q<querybuilder>, [">= 0.9.4"])
s.add_runtime_dependency(%q<querybuilder>, [">= 0.9.5"])
else
s.add_dependency(%q<ruby-recaptcha>, ["= 1.0.0"])
s.add_dependency(%q<tzinfo>, [">= 0.3.12"])
s.add_dependency(%q<rails>, ["= 2.3.8"])
s.add_dependency(%q<rubyless>, [">= 0.8.1"])
s.add_dependency(%q<rubyless>, [">= 0.8.2"])
s.add_dependency(%q<property>, [">= 2.1.2"])
s.add_dependency(%q<uuidtools>, ["= 2.0.0"])
s.add_dependency(%q<authlogic>, ["= 2.1.3"])
s.add_dependency(%q<zafu>, [">= 0.7.5"])
s.add_dependency(%q<zafu>, [">= 0.7.6"])
s.add_dependency(%q<shoulda>, ["= 2.10.3"])
s.add_dependency(%q<fast_gettext>, ["~> 0.4.16"])
s.add_dependency(%q<syntax>, ["= 1.0.0"])
Expand All @@ -2248,17 +2250,17 @@ Gem::Specification.new do |s|
s.add_dependency(%q<hpricot>, [">= 0"])
s.add_dependency(%q<differ>, [">= 0.1.1"])
s.add_dependency(%q<RedCloth>, ["= 3.0.4"])
s.add_dependency(%q<querybuilder>, [">= 0.9.4"])
s.add_dependency(%q<querybuilder>, [">= 0.9.5"])
end
else
s.add_dependency(%q<ruby-recaptcha>, ["= 1.0.0"])
s.add_dependency(%q<tzinfo>, [">= 0.3.12"])
s.add_dependency(%q<rails>, ["= 2.3.8"])
s.add_dependency(%q<rubyless>, [">= 0.8.1"])
s.add_dependency(%q<rubyless>, [">= 0.8.2"])
s.add_dependency(%q<property>, [">= 2.1.2"])
s.add_dependency(%q<uuidtools>, ["= 2.0.0"])
s.add_dependency(%q<authlogic>, ["= 2.1.3"])
s.add_dependency(%q<zafu>, [">= 0.7.5"])
s.add_dependency(%q<zafu>, [">= 0.7.6"])
s.add_dependency(%q<shoulda>, ["= 2.10.3"])
s.add_dependency(%q<fast_gettext>, ["~> 0.4.16"])
s.add_dependency(%q<syntax>, ["= 1.0.0"])
Expand All @@ -2271,7 +2273,7 @@ Gem::Specification.new do |s|
s.add_dependency(%q<hpricot>, [">= 0"])
s.add_dependency(%q<differ>, [">= 0.1.1"])
s.add_dependency(%q<RedCloth>, ["= 3.0.4"])
s.add_dependency(%q<querybuilder>, [">= 0.9.4"])
s.add_dependency(%q<querybuilder>, [">= 0.9.5"])
end
end

0 comments on commit 7df9a75

Please sign in to comment.