Skip to content

Commit

Permalink
"data-" keys should stay with html tags, added [master_template] zafu…
Browse files Browse the repository at this point in the history
… tag.
  • Loading branch information
gaspard committed Jun 1, 2012
1 parent 28a53a8 commit bfc20b4
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 30 deletions.
1 change: 1 addition & 0 deletions History.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* Enable ajax response on Node destroy (use dummy update parameter).
* Added 'sum' method on array. <===== TODO: Document
* Added 'loading' option to [filter].
* Added 'master_template' zafu method to access the master template used for compilation.

== 1.2.0, 1.2.1 2012-05-01

Expand Down
10 changes: 7 additions & 3 deletions lib/zafu/markup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,13 @@ def dyn_params=(h)
# Steal html parameters from an existing hash (the stolen parameters are removed
# from the argument)
def steal_html_params_from(p)
steal_keys.each do |k|
next unless p[k]
@params[k] = p.delete(k)
p.delete_if do |k,v|
if steal_keys.include?(k) || k =~ /^data-/
@params[k] = v
true
else
false
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/zafu/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def new_with_url(path, opts={})
helper = opts[:helper] || Zafu::MockHelper.new
text, fullpath, base_path = self.get_template_text(path, helper)
return parser_error("template '#{path}' not found", 'include') unless text
self.new(text, :helper => helper, :base_path => base_path, :included_history => [fullpath], :root => path)
self.new(text, :helper => helper, :base_path => base_path, :included_history => [fullpath], :root => path, :master_template => opts[:master_template])
end

# Retrieve the template text in the current folder or as an absolute path.
Expand Down
8 changes: 8 additions & 0 deletions lib/zena/use/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,14 @@ def r_group
def r_each_group
r_each
end

def r_master_template
if template = @options[:master_template]
expand_if("#{var} = secure(Node) { Node.find_by_zip(#{template.zip}) }", node.move_to(var, template.vclass))
else
out ''
end
end
end # ZafuMethods
end # Context
end # Use
Expand Down
32 changes: 23 additions & 9 deletions lib/zena/use/forms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -453,24 +453,37 @@ def r_select
selected = "#{node}.prop[#{attribute.inspect}].to_s"
end
end

html_id = html_attributes[:id] ? " id='#{html_attributes[:id]}'" : ''

if @context[:in_filter] || @params[:param]
select_tag = "<select#{html_id} name='#{attribute}'>"
html_attributes[:name] = attribute
else
select_tag = "<select#{html_id} name='#{node.form_name}[#{attribute}]'>"
html_attributes[:name] = "#{node.form_name}[#{attribute}]"
end
html_attributes.delete(:value)
select_tag = Zafu::Markup.new('select', html_attributes)

res = if klass = @params[:root_class]
class_opts = ''
class_opts << ", :without => #{@params[:without].inspect}" if @params[:without]
tprefix = @params[:tprefix] || @params[:name] || @params[:param]
# do not use 'selected' if the node is not new
"#{select_tag}<%= options_for_select(Node.classes_for_form(:class => #{klass.inspect}#{class_opts}, :class_attr => #{(@params[:attr] || 'name').inspect}), (#{node}.new_record? ? #{selected} : #{node}.klass)) %></select>"
options_list = Node.classes_for_form(:class => klass, :without => @params[:without], :class_attr => @params[:attr] || 'name')

if !tprefix.blank? && tprefix != 'false'
options_list.map! do |e|
if e[0] =~ /^([^a-zA-Z]*)(.*)$/
[$1 + trans("#{tprefix}_#{$2}"), e[1]]
else
e
end
end
end
select_tag.wrap "<%= options_for_select(#{options_list.inspect}, (#{node}.new_record? ? #{selected} : #{node}.klass)) %>"
elsif @params[:type] == 'time_zone'
# <r:select name='d_tz' type='time_zone'/>
"#{select_tag}<%= options_for_select(TZInfo::Timezone.all_identifiers, #{selected}) %></select>"
select_tag.wrap "<%= options_for_select(TZInfo::Timezone.all_identifiers, #{selected}) %>"
elsif options_list = get_options_for_select
"#{select_tag}<%= options_for_select(#{options_list}, #{selected}) %></select>"
select_tag.wrap "<%= options_for_select(#{options_list}, #{selected}) %>"
else
parser_error("missing 'nodes', 'root_class' or 'values'")
end
Expand Down Expand Up @@ -707,8 +720,9 @@ def get_input_params(params = @params)
end

params.each do |k, v|
next unless [:size, :style, :class].include?(k)
res[k] = params[k]
if [:size, :style, :class].include?(k) || k.to_s =~ /^data-/
res[k] = params[k]
end
end

return [res, attribute]
Expand Down
3 changes: 2 additions & 1 deletion lib/zena/use/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ def search_index(params, options = {})

# Execute a fulltext search using default fulltext support from the database (MyISAM on MySQL).
def search_text(query, options = {})
options[:order] ||= 'zip desc'
if offset = options[:offset]
limit = options[:limit] || 20
Node.find(:all, match_query(query).merge(:offset => offset, :limit => limit))
Node.find(:all, match_query(query).merge(:offset => offset, :limit => limit, :order => options[:order]))
else
# :default argument not used here
options.delete(:default)
Expand Down
2 changes: 1 addition & 1 deletion lib/zena/use/zafu_templates.rb
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ def rebuild_template(template, opts = {})
end
end

res = ZafuCompiler.new_with_url(zafu_url, :helper => zafu_helper).to_erb(:dev => dev_mode?, :node => get_node_context)
res = ZafuCompiler.new_with_url(zafu_url, :helper => zafu_helper, :master_template => template ).to_erb(:dev => dev_mode?, :node => get_node_context)

unless valid_template?(res, opts)
# problem during rendering, use default zafu
Expand Down
24 changes: 15 additions & 9 deletions public/javascripts/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ Grid.buildObj = function(grid, row) {

Grid.closeCell = function(e) {
if (Grid.in_paste) return
var cell = e.tagName == 'TD' ? e : e.findElement('td')
var cell = e.tagName ? e : e.element().up()
var table = cell.up('table')
var val = Grid.getValue(cell)
var old = cell.prev_value
var val = Grid.getValue(cell)
var prev = cell.prev_value
cell.removeClassName('input')
Grid.changed(cell, val, old)
Grid.changed(cell, val, prev)

if (table.grid.input) {
// single attribute table, serialize in input field
Expand Down Expand Up @@ -330,7 +330,7 @@ Grid.openCell = function(cell) {

if (!input) {
// default input field
cell.innerHTML = Grid.default_input
cell.update(Grid.default_input)
input = cell.childElements()[0]
input.value = value
}
Expand Down Expand Up @@ -407,7 +407,7 @@ Grid.copy = function(cell) {
var c = rows[i].childElements()[pos]
if (!Grid.isReadOnly(c)) {
var prev = Grid.getValue(c)
if (c.value != val.value) Grid.changed(c, val, prev)
if (prev.value != val.value) Grid.changed(c, val, prev)
}
}
table.grid.changes.push('end')
Expand Down Expand Up @@ -547,7 +547,9 @@ Grid.makeAttrPos = function(table) {
}
// get default values
helpers.select('input,textarea,select').each(function(e) {
defaults[e.name] = Grid.valueFromInput(e)
if (e.getAttribute('data-d') == 'true') {
defaults[e.name] = Grid.valueFromInput(e)
}
})
}
table.grid.defaults = $H(defaults)
Expand Down Expand Up @@ -619,8 +621,12 @@ Grid.addButtons = function(table) {

for (var i = 0; i < rows.length; i++) {
var buttons
if (i == 0 && grid.add) {
buttons = "<td class='action'><span class='add'>&nbsp;</span></td>"
if (i == 0) {
if (grid.add) {
buttons = "<td class='action'><span class='add'>&nbsp;</span></td>"
} else {
buttons = "<td class='action'></td>"
}
} else {
buttons = Grid.Buttons(grid)
}
Expand Down
5 changes: 5 additions & 0 deletions test/integration/zafu_compiler/context.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@ list_else:
node: status
src: "<ul do='posts'><li do='each' do='link'/><li do='else'>hop</li></ul>"
res: "<ul><li>hop</li></ul>"

master_template_on_static_render:
src: "<r:master_template><r:title/></r:master_template>"
tem: ''
# Master template on template rendering is tested in 'find master template', rendering_test.rb
15 changes: 12 additions & 3 deletions test/integration/zafu_compiler/forms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,24 @@ select_class_existing_node:
context:
node: 'letter'
src: "<r:form><r:select name='klass' root_class='Note' selected='Post'/></r:form>"
res: "/<select name=.node\[klass\].><option value=\"Note\">Note<\/option>\n<option value=\"Letter\" selected=\"selected\">  Letter<\/option>\n<option value=\"Post\">  Post<\/option><\/select>/"
res: "/<select name=.node\[klass\].><option value=\"Note\">klass_Note<\/option>\n<option value=\"Letter\" selected=\"selected\">  klass_Letter<\/option>\n<option value=\"Post\">  klass_Post<\/option><\/select>/"

select_class_new_node:
src: "<r:pages><r:each/><r:add/><r:form><r:select name='klass' root_class='Note' selected='Post'/></r:form>"
res: "/<select.*name=.node\[klass\].*Note.*Letter.*Post. selected=.selected./"
res: "/<select.*name=.node\[klass\].*klass_Note.*klass_Letter.*Post. selected=.selected./"

select_class_kpath:
src: "<r:select param='k' root_class='Note' attr='kpath'/>"
res: "/<select.*name=.k.*NN.*Note.*NNL.*Letter.*NNP.*Post/"
res: "/<select.*name=.k.*NN.*k_Note.*NNL.*k_Letter.*NNP.*k_Post/"

select_class_tprefix:
src: "<r:select tprefix='foo' param='k' root_class='Note'/>"
tem: '/\["foo_Note", "Note"\]/'
res: "/foo_Note.*foo_Letter/"

select_data:
src: "<r:select data-d='foo' param='k' root_class='Note' attr='kpath'/>"
res: "/<select data-d='foo' .*name=.k.*NN.*Note.*NNL.*Letter.*NNP.*Post/"

select_nodes:
src: "<r:form><r:select nodes='images in site' name='foo'></select></r:form>"
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 @@ -481,6 +481,7 @@ wiki_project_changes_xml_en:
node: wiki_Project_changes_xml_zafu
user: tiger
prop:
title: Project-changes-xml
comment: layout for wiki
summary: Layout for the wiki skin.
text: |
Expand Down
2 changes: 1 addition & 1 deletion test/unit/node_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1399,7 +1399,7 @@ def assert_transforms(result, src)
end

should 'parse pseudo ids' do
assert_transforms "Hi, this is just a simple \"test\":49 or \"\":43_life.rss. OK ?\n\n!24_pv!",
assert_transforms "Hi, this is just a simple \"test\":43 or \"\":31_life.rss. OK ?\n\n!24_pv!",
"Hi, this is just a simple \"test\"::w or \"\"::w++_life.rss. OK ?\n\n!:lake_pv!"
end

Expand Down
11 changes: 9 additions & 2 deletions test/unit/zena/use/rendering_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,12 @@ def render_to_xml(opts)
subject do
login(:lion)
# create template for 'special' mode
t = secure(Template) { Template.create(:parent_id => nodes_id(:default), :title => 'Node-bar.zafu', :text => @zafu, :v_status => Zena::Status::Pub) }
@template = secure(Template) { Template.create(:parent_id => nodes_id(:default), :title => 'Node-bar.zafu', :text => @zafu, :v_status => Zena::Status::Pub) }
login(:anon)
{:action => 'show', :controller => 'nodes', :path => ["section#{nodes_zip(:people)}_bar.html"], :prefix => 'en'}
end

should 'type and disposition headers' do
should 'set type and disposition headers' do
@zafu = %q{<r:headers X-Foobar='my thing' Content-Type='text/css' Content-Disposition='attachment; filename=special_#{title}.csv'/>}
get_subject
assert_response :success
Expand All @@ -206,6 +206,13 @@ def render_to_xml(opts)
assert_equal v, @response.headers[k]
end
end

should 'find master template' do
@zafu = %q{MASTER_TEMPLATE[<r:master_template do='id'/>]}
get_subject
assert_response :success
assert_equal "MASTER_TEMPLATE[#{@template.zip}]", @response.body
end
end # Custom rendering options

end

0 comments on commit bfc20b4

Please sign in to comment.