Skip to content

Commit

Permalink
Added support for new in rubyless (Post.new, Post.new(:title => 'foo')).
Browse files Browse the repository at this point in the history
  • Loading branch information
gaspard committed Jul 3, 2012
1 parent e2569b6 commit fd0a6ed
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions History.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* No need to use '>' or '<' in html params. \' escape works. Yeah !!
* Enabled "static" assets with symlink to skins in static bricks (/static/[brick]-[skin]/xxx.css => bricks/[brick]/skins/[skin]/static/xxx.css)
* No more strict scoping: "set" variables are rewritten if type matches.
* Added support for new in rubyless (Post.new, Post.new(:title => 'foo')).

* Minor changes
* Fixed label traduction for param.
Expand Down
17 changes: 15 additions & 2 deletions app/models/virtual_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,16 @@ class << self
safe_method [:relations, String] => {:class => ['RelationProxy'], :method => 'filtered_relations'}
# All columns defined for a VirtualClass (kpath based).
safe_method :all_columns => {:class => ['Column'], :method => 'safe_columns'}



# Methods on VirtualClass['Post'] instances, not nodes.
def self.safe_method_type(signature, receiver)
if signature.first == 'new'
{:method => 'zafu_new', :class => receiver.literal}
else
super
end
end

class Cache
def initialize
clear_cache!
Expand Down Expand Up @@ -474,6 +482,11 @@ def do_find(*args)
def new_instance(hash={})
real_class.new(hash, self)
end

# Build new nodes instances of this VirtualClass from zafu.
def zafu_new(hash={})
real_class.new(Node.transform_attributes(hash.stringify_keys), self)
end

# Create new nodes instances of this VirtualClass
def create_instance(*args)
Expand Down
12 changes: 11 additions & 1 deletion test/integration/zafu_compiler/rubyless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,14 @@ prop_in_list_context:
role_existing_class_name:
# Should understand 'Comment' as a Role.
src: "<r:Comment?>xx</r:Comment?>"
tem: "/<% if @node.has_role\?\(\d+\) %>xx<% end %>/"
tem: "/<% if @node.has_role\?\(\d+\) %>xx<% end %>/"

class_new:
src: "<div do='set' p='Post.new'><p do='p.klass'/>.<p do='p.title'/></div>"
tem: "/VirtualClass\[.Post.\].zafu_new.*_zp.klass.*_zp.prop\[.title.\]/"
res: "<div><p>Post</p>.<p></p></div>"

class_new_with_attr:
src: "<div do='set' p='Post.new(:title => \"yes\")'><p do='p.klass'/>.<p do='p.title'/></div>"
tem: "/VirtualClass\[.Post.\].zafu_new.*_zp.klass.*_zp.prop\[.title.\]/"
res: "<div><p>Post</p>.<p>yes</p></div>"

0 comments on commit fd0a6ed

Please sign in to comment.