Skip to content

Commit

Permalink
Added 'column("name")' for VirtualClasses, fixed default input field …
Browse files Browse the repository at this point in the history
…rendering for column.
  • Loading branch information
gaspard committed Jan 24, 2012
1 parent 3934f4f commit 80e75d7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
16 changes: 16 additions & 0 deletions app/models/role.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Role < ActiveRecord::Base
include RubyLess
# Columns defined in the role.
safe_method :columns => {:class => ['Column'], :method => 'defined_safe_columns'}
safe_method [:column, String] => {:class => 'Column', :nil => true, :method => 'defined_safe_column'}

safe_method :name => String

Expand Down Expand Up @@ -191,6 +192,21 @@ def defined_safe_columns
@safe_column ||= defined_columns.values.sort {|a,b| a.name <=> b.name}
end

# By default, all defined columns are safe (see )
def defined_safe_column(name)
if real_class?
# Get columns from the 'native' schema of the real class (this schema is a Property::Role,
# not a VirtualClass or ::Role).
#
# Only columns explicitly declared safe are safe here
if real_class.safe_method_type(name)
real_class.schema.defined_columns[name]
end
else
defined_columns[name]
end
end

def export
res = Zafu::OrderedHash.new
res['type'] = real_class? ? 'Class' : type
Expand Down
2 changes: 2 additions & 0 deletions lib/zena/use/forms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ def r_input(skip_col = false)
@markup.set_param(:type, @params[:type])
@markup.set_param(:text, @params[:text]) if @params[:text]
@markup.set_params(html_attributes)
@markup.done = false
wrap('')
else
# 'text', 'hidden', ...
Expand All @@ -531,6 +532,7 @@ def r_input(skip_col = false)
checked = html_attributes.delete(:checked)
@markup.set_dyn_params(html_attributes)
@markup.append_attribute checked if checked
@markup.done = false
wrap('')
end

Expand Down
13 changes: 12 additions & 1 deletion test/integration/zafu_compiler/forms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -268,4 +268,15 @@ hidden_fields_in_form_tag:

hidden_fields_in_form_tag_dynamic:
src: "<r:form node[log]='title'></r:form>"
tem: "/<input type='hidden' name='node\[log\]' value='<%= @node.prop\['title'\] %>/"
tem: "/<input type='hidden' name='node\[log\]' value='<%= @node.prop\['title'\] %>/"

should_show_column:
src: "<r:Document do='column(\"size\")' do='name'/>"
res: "size"

should_show_fields_for_columns:
context:
node: 'forest_pdf'
src: "<r:form><r:Document do='column(\"size\")' do='input'/></r:form>"
tem: "/input type='text' name='node\\[<%= var2.name %>\\]/"
res: "/<input type='text' name='node\\[size\\]' value='63569'/>/"

0 comments on commit 80e75d7

Please sign in to comment.