zafu 0.8.0 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +12 -0
- data/lib/zafu/info.rb +1 -1
- data/lib/zafu/node_context.rb +17 -11
- data/lib/zafu/parser.rb +10 -27
- data/lib/zafu/process/ajax.rb +31 -3
- data/lib/zafu/process/forms.rb +18 -4
- data/lib/zafu/process/ruby_less_processing.rb +7 -2
- data/test/mock/params.rb +12 -1
- data/test/node_context_test.rb +6 -6
- data/test/zafu/basic.yml +5 -1
- data/zafu.gemspec +2 -2
- metadata +4 -4
data/History.txt
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
== 0.8.2 2011-07-11
|
2
|
+
|
3
|
+
* Enhancements
|
4
|
+
* Fixed forms in ajax context (was not passing parent_id).
|
5
|
+
* Changed resolution of 'this' in list context (going up, not using first).
|
6
|
+
* Fixed forms in "table" (should wrap around table, not inside).
|
7
|
+
|
8
|
+
== 0.8.1
|
9
|
+
|
10
|
+
* Enhancements
|
11
|
+
* Added support to pass elements in sibling's context.
|
12
|
+
|
1
13
|
== 0.8.0 2011-06-15
|
2
14
|
|
3
15
|
* Enhancements
|
data/lib/zafu/info.rb
CHANGED
data/lib/zafu/node_context.rb
CHANGED
@@ -51,7 +51,7 @@ module Zafu
|
|
51
51
|
# ivar name (see #master_class).
|
52
52
|
def as_main(after_class = nil)
|
53
53
|
klass = after_class ? master_class(after_class) : single_class
|
54
|
-
res = self.class.new("@#{klass.to_s.underscore}", single_class, nil
|
54
|
+
res = self.class.new("@#{klass.to_s.underscore}", single_class, nil) #, :new_record => @opts[:new_record])
|
55
55
|
res.dom_prefix = self.dom_prefix
|
56
56
|
res
|
57
57
|
end
|
@@ -114,17 +114,23 @@ module Zafu
|
|
114
114
|
@dom_scope = true
|
115
115
|
end
|
116
116
|
|
117
|
+
# Returns the first occurence of the klass up in the hierachy
|
118
|
+
# This does not resolve [Node] as [Node].first.
|
117
119
|
def get(klass)
|
118
|
-
if
|
119
|
-
return
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
120
|
+
if list_context?
|
121
|
+
return @up ? @up.get(klass) : nil
|
122
|
+
end
|
123
|
+
if self.klass <= klass
|
124
|
+
self
|
125
|
+
# return self unless list_context?
|
126
|
+
#
|
127
|
+
# res_class = self.klass
|
128
|
+
# method = self.name
|
129
|
+
# while res_class.kind_of?(Array)
|
130
|
+
# method = "#{method}.first"
|
131
|
+
# res_class = res_class.first
|
132
|
+
# end
|
133
|
+
# move_to(method, res_class)
|
128
134
|
elsif @up
|
129
135
|
@up.get(klass)
|
130
136
|
else
|
data/lib/zafu/parser.rb
CHANGED
@@ -210,6 +210,13 @@ module Zafu
|
|
210
210
|
enter(mode)
|
211
211
|
end
|
212
212
|
|
213
|
+
# Pass some contextual information to siblings
|
214
|
+
def pass(elems = nil)
|
215
|
+
return @pass unless elems
|
216
|
+
(@pass ||= {}).merge!(elems)
|
217
|
+
@pass
|
218
|
+
end
|
219
|
+
|
213
220
|
# Hook called when replacing part of an included template with '<r:with part='main'>...</r:with>'
|
214
221
|
# This replaces the current object 'self' which is in the original included template, with the custom version 'obj'.
|
215
222
|
def replace_with(obj)
|
@@ -241,11 +248,10 @@ module Zafu
|
|
241
248
|
# FIXME: replace with array and join (faster)
|
242
249
|
@result = ""
|
243
250
|
@out_post = ""
|
251
|
+
@pass = nil
|
244
252
|
|
245
253
|
before_process
|
246
254
|
|
247
|
-
@pass = {} # used to pass information to the parent (is this used ?)
|
248
|
-
|
249
255
|
res = wrap(expander || default_expander)
|
250
256
|
|
251
257
|
res = after_process(res)
|
@@ -270,7 +276,7 @@ module Zafu
|
|
270
276
|
if res.kind_of?(String)
|
271
277
|
@result << res
|
272
278
|
elsif @result.blank?
|
273
|
-
@result << (@errors.
|
279
|
+
@result << (@errors.empty? ? '' : show_errors)
|
274
280
|
end
|
275
281
|
@result
|
276
282
|
end
|
@@ -284,7 +290,6 @@ module Zafu
|
|
284
290
|
def r_inspect
|
285
291
|
expand_with(:preflight=>true)
|
286
292
|
@blocks = []
|
287
|
-
@pass.merge!(@parts||{})
|
288
293
|
self.inspect
|
289
294
|
end
|
290
295
|
|
@@ -594,10 +599,6 @@ module Zafu
|
|
594
599
|
blocks = acontext.delete(:blocks) || @blocks
|
595
600
|
res = ""
|
596
601
|
|
597
|
-
# FIXME: I think we can delete @pass and @parts stuff now (test first).
|
598
|
-
|
599
|
-
@pass = {} # current object sees some information from it's direct descendants
|
600
|
-
@parts = {}
|
601
602
|
only = acontext[:only]
|
602
603
|
new_context = @context.merge(acontext)
|
603
604
|
|
@@ -619,11 +620,7 @@ module Zafu
|
|
619
620
|
elsif (!only || (only.kind_of?(Array) && only.include?(b.method)) || only =~ b.method) && (!ignore || !ignore.include?(b.method))
|
620
621
|
res << b.process(new_context.dup)
|
621
622
|
if pass = b.pass
|
622
|
-
|
623
|
-
@parts.merge!(pass[:part])
|
624
|
-
pass.delete(:part)
|
625
|
-
end
|
626
|
-
@pass.merge!(pass)
|
623
|
+
new_context.merge!(pass)
|
627
624
|
end
|
628
625
|
end
|
629
626
|
end
|
@@ -648,20 +645,6 @@ module Zafu
|
|
648
645
|
end
|
649
646
|
attributes << " {> #{context.sort.join(', ')}}" unless context == []
|
650
647
|
|
651
|
-
pass = []
|
652
|
-
(@pass || {}).each do |k,v|
|
653
|
-
unless v.nil?
|
654
|
-
if v.kind_of?(Array)
|
655
|
-
pass << "#{k.inspect.gsub('"', "'")}=>#{v.inspect.gsub('"', "'")}"
|
656
|
-
elsif v.kind_of?(Parser)
|
657
|
-
pass << "#{k.inspect.gsub('"', "'")}=>['#{v}']"
|
658
|
-
else
|
659
|
-
pass << "#{k.inspect.gsub('"', "'")}=>#{v.inspect.gsub('"', "'")}"
|
660
|
-
end
|
661
|
-
end
|
662
|
-
end
|
663
|
-
attributes << " {< #{pass.sort.join(', ')}}" unless pass == []
|
664
|
-
|
665
648
|
res = []
|
666
649
|
@blocks.each do |b|
|
667
650
|
if b.kind_of?(String)
|
data/lib/zafu/process/ajax.rb
CHANGED
@@ -82,7 +82,7 @@ module Zafu
|
|
82
82
|
# Used to get parameters like 'publish', 'done', 'after'
|
83
83
|
:add => add_block,
|
84
84
|
:publish_after_save => publish_after_save,
|
85
|
-
:
|
85
|
+
:new_keys => {:parent_id => '@node.parent_zip'}
|
86
86
|
}
|
87
87
|
|
88
88
|
store_block(form_block, cont)
|
@@ -238,13 +238,40 @@ module Zafu
|
|
238
238
|
klass = @context[:klass] || node.single_class
|
239
239
|
|
240
240
|
# New object to render form.
|
241
|
-
new_node = node.move_to("#{var}_new", klass,
|
241
|
+
new_node = node.move_to("#{var}_new", klass,
|
242
|
+
:new_keys => {})
|
243
|
+
|
242
244
|
|
243
245
|
if new_node.will_be?(Node)
|
244
246
|
# FIXME: BUG if we set <r:form klass='Post'/> the user cannot select class with menu...
|
245
247
|
|
248
|
+
if @context[:saved_template]
|
249
|
+
parent_id = "#{node}.parent_zip"
|
250
|
+
else
|
251
|
+
parent_id = "#{node(Node)}.zip"
|
252
|
+
end
|
253
|
+
|
254
|
+
new_node.opts[:new_keys]['parent_id'] = parent_id
|
255
|
+
|
246
256
|
# FIXME: inspect '@context[:form]' to see if it contains v_klass ?
|
247
|
-
out "<% if #{new_node} = secure(Node) { Node.new_node('class' => '#{new_node.klass}') } %>"
|
257
|
+
out "<% if #{new_node} = secure(Node) { Node.new_node('class' => '#{new_node.klass}', 'parent_id' => #{parent_id}) } %>"
|
258
|
+
# if node.will_be?(Node)
|
259
|
+
# # Nested contexts:
|
260
|
+
# # 1. @node
|
261
|
+
# # 2. var1 = @node.children
|
262
|
+
# # 3. var1_new = Node.new
|
263
|
+
# if node.opts[:new_record] || @context[:saved_template]
|
264
|
+
# if @context[:saved_template] || !@context[:in_add]
|
265
|
+
# # TODO: we should not add parent_id on every saved_template. Why is this needed ?
|
266
|
+
# parent_id = "#{node}.parent_zip"
|
267
|
+
# else
|
268
|
+
# # We are in var2_new
|
269
|
+
# parent_id = "#{node.up(Node)}.zip"
|
270
|
+
# end
|
271
|
+
#
|
272
|
+
# hidden_fields['node[parent_id]'] = "<%= #{parent_id} %>"
|
273
|
+
# end
|
274
|
+
# els
|
248
275
|
else
|
249
276
|
out "<% if #{new_node} = #{new_node.class_name}.new %>"
|
250
277
|
end
|
@@ -395,6 +422,7 @@ module Zafu
|
|
395
422
|
|
396
423
|
# Create new node context
|
397
424
|
node = cont[:node].as_main(ActiveRecord::Base)
|
425
|
+
node.opts[:new_keys] = cont.delete(:new_keys)
|
398
426
|
|
399
427
|
# The dom_id will be calculated from the Ajax params in the view.
|
400
428
|
node.saved_dom_id = "\#{ndom_id(#{node})}"
|
data/lib/zafu/process/forms.rb
CHANGED
@@ -35,6 +35,7 @@ module Zafu
|
|
35
35
|
|
36
36
|
# Render hidden fields (these must go after normal elements so that focusFirstElement works)
|
37
37
|
hidden_fields = form_hidden_fields(options)
|
38
|
+
|
38
39
|
out "<div class='hidden'>"
|
39
40
|
hidden_fields.each do |k,v|
|
40
41
|
if v.kind_of?(String)
|
@@ -68,15 +69,20 @@ module Zafu
|
|
68
69
|
# opts[:klass] = node.master_class(ActiveRecord::Base).to_s
|
69
70
|
|
70
71
|
if @context[:in_add]
|
71
|
-
opts[:id] = "#{node.dom_prefix}
|
72
|
+
opts[:id] = "#{node.dom_prefix}_add"
|
72
73
|
opts[:style] = 'display:none;'
|
74
|
+
elsif @markup.tag == 'table'
|
75
|
+
# the normal id goes to the form wrapping the table
|
76
|
+
opts[:id] = "#{node.dom_prefix}_tbl"
|
77
|
+
form_id = node.dom_prefix
|
73
78
|
end
|
74
79
|
|
80
|
+
form_id ||= "#{node.dom_prefix}_form_t"
|
75
81
|
if @context[:template_url]
|
76
|
-
opts[:form_tag] = "<% remote_form_for(:#{node.form_name}, #{node}, :html => {:id =>
|
82
|
+
opts[:form_tag] = "<% remote_form_for(:#{node.form_name}, #{node}, :html => {:id => #{form_id.inspect}}) do |f| %>"
|
77
83
|
opts[:form_helper] = 'f'
|
78
84
|
else
|
79
|
-
opts[:form_tag] = "<% form_for(:#{node.form_name}, #{node}, :html => {:id =>
|
85
|
+
opts[:form_tag] = "<% form_for(:#{node.form_name}, #{node}, :html => {:id => #{form_id.inspect}}) do |f| %>"
|
80
86
|
opts[:form_helper] = 'f'
|
81
87
|
end
|
82
88
|
|
@@ -106,7 +112,15 @@ module Zafu
|
|
106
112
|
# form_for ... do |f|
|
107
113
|
out opts.delete(:form_tag)
|
108
114
|
# f.xxx
|
109
|
-
|
115
|
+
if markup.tag == 'table'
|
116
|
+
# Avoid <table><form> (invalid HTML)
|
117
|
+
bak = @result
|
118
|
+
@result = ''
|
119
|
+
yield(opts.merge(:in_form => true))
|
120
|
+
@result = bak + markup.wrap(@result)
|
121
|
+
else
|
122
|
+
yield(opts.merge(:in_form => true))
|
123
|
+
end
|
110
124
|
# close form
|
111
125
|
out opts[:form_helper] ? "<% end %>" : '</form>'
|
112
126
|
end
|
@@ -284,8 +284,13 @@ module Zafu
|
|
284
284
|
ivar = signature.first
|
285
285
|
if ivar == 'this'
|
286
286
|
if node.list_context?
|
287
|
-
#
|
288
|
-
|
287
|
+
# Find single element up
|
288
|
+
if single_node = node(node.klass.first)
|
289
|
+
single_node.opts.merge(:class => single_node.klass, :method => single_node.to_s)
|
290
|
+
else
|
291
|
+
out parser_error("In [#{node.klass.first}], could resolve 'this'.")
|
292
|
+
nil
|
293
|
+
end
|
289
294
|
else
|
290
295
|
node.opts.merge(:class => node.klass, :method => node.name)
|
291
296
|
end
|
data/test/mock/params.rb
CHANGED
@@ -12,7 +12,18 @@ module Mock
|
|
12
12
|
|
13
13
|
|
14
14
|
def r_inspect
|
15
|
-
out "#{@params.inspect}"
|
15
|
+
out "#{@params.inspect} xxxx"
|
16
|
+
end
|
17
|
+
|
18
|
+
# Test passing information to siblings
|
19
|
+
def r_pass
|
20
|
+
pass(@params)
|
21
|
+
true
|
22
|
+
end
|
23
|
+
|
24
|
+
def r_view_passed
|
25
|
+
key = @params[:key]
|
26
|
+
out @context[@params[:key].to_sym].to_s
|
16
27
|
end
|
17
28
|
end
|
18
29
|
end
|
data/test/node_context_test.rb
CHANGED
@@ -210,10 +210,10 @@ class NodeContextTest < Test::Unit::TestCase
|
|
210
210
|
@mother.move_to('list', [Page])
|
211
211
|
end
|
212
212
|
|
213
|
-
should 'find the context and resolve
|
213
|
+
should 'find the context and resolve without using first' do
|
214
214
|
assert context = subject.get(Page)
|
215
|
-
assert_equal '
|
216
|
-
assert_equal
|
215
|
+
assert_equal '@page', context.name
|
216
|
+
assert_equal SubPage, context.klass
|
217
217
|
end
|
218
218
|
|
219
219
|
should 'return parent on up with class' do
|
@@ -239,10 +239,10 @@ class NodeContextTest < Test::Unit::TestCase
|
|
239
239
|
@mother.move_to('list', [[[Page]]])
|
240
240
|
end
|
241
241
|
|
242
|
-
should 'find the context
|
242
|
+
should 'find the context without using first' do
|
243
243
|
assert context = subject.get(Page)
|
244
|
-
assert_equal '
|
245
|
-
assert_equal
|
244
|
+
assert_equal '@page', context.name
|
245
|
+
assert_equal SubPage, context.klass
|
246
246
|
end
|
247
247
|
|
248
248
|
should 'return parent on up with class' do
|
data/test/zafu/basic.yml
CHANGED
@@ -28,4 +28,8 @@ line_comment:
|
|
28
28
|
|
29
29
|
do_not_touch_js_comment:
|
30
30
|
src: "<r:raw>hello</r:raw> // This is a comment that will not be removed"
|
31
|
-
tem: "<%= raw(\"hello\") %> // This is a comment that will not be removed"
|
31
|
+
tem: "<%= raw(\"hello\") %> // This is a comment that will not be removed"
|
32
|
+
|
33
|
+
pass:
|
34
|
+
src: "<r:pass foo='hello'/><r:view_passed key='foo'/>"
|
35
|
+
tem: "hello"
|
data/zafu.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{zafu}
|
8
|
-
s.version = "0.8.
|
8
|
+
s.version = "0.8.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Gaspard Bucher"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-07-11}
|
13
13
|
s.description = %q{Provides a powerful templating language based on xhtml for rails}
|
14
14
|
s.email = %q{gaspard@teti.ch}
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zafu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 59
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 8
|
9
|
-
-
|
10
|
-
version: 0.8.
|
9
|
+
- 2
|
10
|
+
version: 0.8.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Gaspard Bucher
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-07-11 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|