zafu 0.7.5 → 0.7.6
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 +6 -0
- data/lib/zafu/info.rb +1 -1
- data/lib/zafu/parser.rb +3 -3
- data/lib/zafu/parsing_rules.rb +9 -5
- data/lib/zafu/process/ajax.rb +13 -13
- data/lib/zafu/process/conditional.rb +4 -4
- data/lib/zafu/process/context.rb +5 -5
- data/lib/zafu/process/forms.rb +1 -1
- data/lib/zafu/process/html.rb +6 -0
- data/test/zafu/basic.yml +13 -1
- data/test/zafu/markup.yml +1 -1
- data/test/zafu_test.rb +5 -2
- data/zafu.gemspec +2 -2
- metadata +4 -4
data/History.txt
CHANGED
data/lib/zafu/info.rb
CHANGED
data/lib/zafu/parser.rb
CHANGED
@@ -13,9 +13,9 @@ module Zafu
|
|
13
13
|
# 'after_wrap' is called by the 'wrap' method from within the method handler, 'after_process' is called
|
14
14
|
# at the very end. Example:
|
15
15
|
#
|
16
|
-
# <% if var = Node.all
|
17
|
-
# <li>...</li>
|
18
|
-
# <% end
|
16
|
+
# <% if var = Node.all %> | <---
|
17
|
+
# <li>...</li> <--- content for after_wrap | <--- content for after_process
|
18
|
+
# <% end %> | <---
|
19
19
|
#
|
20
20
|
|
21
21
|
|
data/lib/zafu/parsing_rules.rb
CHANGED
@@ -50,13 +50,16 @@ module Zafu
|
|
50
50
|
if @params =~ /\A([^>]*?)do\s*=('|")([^\2]*?[^\\])\2([^>]*)\Z/
|
51
51
|
#puts $~.to_a.inspect
|
52
52
|
# we have a sub 'do'
|
53
|
+
params = $1
|
54
|
+
sub_params = $4
|
55
|
+
sub_method = $3.gsub("\\#{$2}", $2)
|
53
56
|
|
54
|
-
@params = Markup.parse_params(
|
57
|
+
@params = Markup.parse_params(params)
|
55
58
|
|
56
59
|
# We need this flag to detect cases cases like <r:with part='list' do='other list finder'/>
|
57
60
|
@sub_do = true
|
58
61
|
|
59
|
-
opts = {:method
|
62
|
+
opts = {:method => sub_method, :params => sub_params}
|
60
63
|
|
61
64
|
# the matching zafu tag will be parsed by the last 'do', we must inform it to halt properly :
|
62
65
|
opts[:end_tag] = @end_tag
|
@@ -193,11 +196,12 @@ module Zafu
|
|
193
196
|
opts.merge!(:text=>'') if $3 != ''
|
194
197
|
make(:void, opts)
|
195
198
|
#elsif @text =~ /\A<(\w+)([^>]*?)do\s*=('([^>]*?[^\\]|)'|"([^>]*?[^\\]|)")([^>]*?)(\/?)>/
|
196
|
-
elsif @text =~ /\A<(\w+)([^>]*?)do\s*=('|")([^\3]*?[^\\])\3([^>]*?)(\/?)>/
|
199
|
+
elsif @text =~ /\A<(\w+)([^>]*?)do\s*=('|")([^\3]*?[^\\]|)\3([^>]*?)(\/?)>/
|
197
200
|
#puts "DO:#{$~.to_a.inspect}" # do tag
|
198
201
|
eat $&
|
199
|
-
|
200
|
-
opts.merge!(:
|
202
|
+
reg = $~
|
203
|
+
opts.merge!(:method=> reg[4].gsub("\\#{reg[3]}", reg[3]), :html_tag=>reg[1], :html_tag_params=>reg[2], :params=>reg[5])
|
204
|
+
opts.merge!(:text=>'') if reg[6] != ''
|
201
205
|
make(:void, opts)
|
202
206
|
elsif @options[:form] && @text =~ /\A<(input|select|textarea|form)([^>]*?)(\/?)>/
|
203
207
|
eat $&
|
data/lib/zafu/process/ajax.rb
CHANGED
@@ -33,7 +33,7 @@ module Zafu
|
|
33
33
|
|
34
34
|
# 1. Render inline
|
35
35
|
# assign [] to var
|
36
|
-
out "<% if (#{var} = #{finder[:method]}) || (#{node}.#{node.will_be?(Comment) ? "can_comment?" : "can_write?"} && #{var}=[])
|
36
|
+
out "<% if (#{var} = #{finder[:method]}) || (#{node}.#{node.will_be?(Comment) ? "can_comment?" : "can_write?"} && #{var}=[]) %>"
|
37
37
|
# The list is not empty or we have enough rights to add new elements.
|
38
38
|
set_dom_prefix
|
39
39
|
|
@@ -76,7 +76,7 @@ module Zafu
|
|
76
76
|
|
77
77
|
store_block(form_block, cont)
|
78
78
|
end
|
79
|
-
out "<% end
|
79
|
+
out "<% end %>"
|
80
80
|
else
|
81
81
|
super
|
82
82
|
end
|
@@ -101,17 +101,17 @@ module Zafu
|
|
101
101
|
#else
|
102
102
|
# # no form, render, edit and add are not ajax
|
103
103
|
# if descendant('add') || descendant('add_document')
|
104
|
-
# out "<% if (#{list_var} = #{list_finder}) || (#{node}.#{node.will_be?(Comment) ? "can_comment?" : "can_write?"} && #{list_var}=[])
|
104
|
+
# out "<% if (#{list_var} = #{list_finder}) || (#{node}.#{node.will_be?(Comment) ? "can_comment?" : "can_write?"} && #{list_var}=[]) %>"
|
105
105
|
# elsif list_finder != 'nil'
|
106
|
-
# out "<% if #{list_var} = #{list_finder}
|
106
|
+
# out "<% if #{list_var} = #{list_finder} %>"
|
107
107
|
# else
|
108
|
-
# out "<% if nil
|
108
|
+
# out "<% if nil %>"
|
109
109
|
# end
|
110
110
|
#
|
111
111
|
#
|
112
112
|
# out render_html_tag(expand_with(:list=>list_var, :in_if => false))
|
113
113
|
# out expand_with(:in_if=>true, :only=>['elsif', 'else'], :html_tag => @html_tag, :html_tag_params => @html_tag_params)
|
114
|
-
# out "<% end
|
114
|
+
# out "<% end %>"
|
115
115
|
#end
|
116
116
|
end
|
117
117
|
|
@@ -159,7 +159,7 @@ module Zafu
|
|
159
159
|
|
160
160
|
link = wrap(make_link(:default_text => _('edit'), :update => each_block, :action => 'edit'))
|
161
161
|
|
162
|
-
out "<% if #{node}.can_write?
|
162
|
+
out "<% if #{node}.can_write? %>#{link}<% end %>"
|
163
163
|
end
|
164
164
|
|
165
165
|
#if @context[:template_url]
|
@@ -179,9 +179,9 @@ module Zafu
|
|
179
179
|
return '' if @context[:make_form]
|
180
180
|
|
181
181
|
if node.will_be?(Comment)
|
182
|
-
out "<% if #{node.up(Node)}.can_comment?
|
182
|
+
out "<% if #{node.up(Node)}.can_comment? %>"
|
183
183
|
else
|
184
|
-
out "<% if #{node.up(Node)}.can_write?
|
184
|
+
out "<% if #{node.up(Node)}.can_write? %>"
|
185
185
|
end
|
186
186
|
|
187
187
|
unless descendant('add_btn')
|
@@ -216,9 +216,9 @@ module Zafu
|
|
216
216
|
# FIXME: BUG if we set <r:form klass='Post'/> the user cannot select class with menu...
|
217
217
|
|
218
218
|
# FIXME: inspect '@context[:form]' to see if it contains v_klass ?
|
219
|
-
out "<% if #{new_node} = secure(Node) { Node.new_node('class' => '#{new_node.klass}') }
|
219
|
+
out "<% if #{new_node} = secure(Node) { Node.new_node('class' => '#{new_node.klass}') } %>"
|
220
220
|
else
|
221
|
-
out "<% if #{new_node} = #{new_node.class_name}.new
|
221
|
+
out "<% if #{new_node} = #{new_node.class_name}.new %>"
|
222
222
|
end
|
223
223
|
|
224
224
|
form_block = @context[:form]
|
@@ -236,13 +236,13 @@ module Zafu
|
|
236
236
|
# Node context = new node
|
237
237
|
:node => new_node
|
238
238
|
)
|
239
|
-
out "<% end
|
239
|
+
out "<% end %>"
|
240
240
|
else
|
241
241
|
# no ajax
|
242
242
|
@markup.append_param(:class, 'btn_add') if @markup.tag
|
243
243
|
out wrap(expand_with)
|
244
244
|
end
|
245
|
-
out "<% end
|
245
|
+
out "<% end %>"
|
246
246
|
end
|
247
247
|
|
248
248
|
def r_add_btn
|
@@ -41,10 +41,10 @@ module Zafu
|
|
41
41
|
@markup.set_dyn_param(k, v)
|
42
42
|
end
|
43
43
|
|
44
|
-
out "<% elsif #{cond}
|
44
|
+
out "<% elsif #{cond} %>#{wrap(res)}" # do not propagate
|
45
45
|
else
|
46
46
|
@markup.done = true # never wrap else/elsif clause
|
47
|
-
out "<% elsif #{cond}
|
47
|
+
out "<% elsif #{cond} %>#{res}" # do not propagate
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
@@ -57,7 +57,7 @@ module Zafu
|
|
57
57
|
# * +alt_markup+ - (optional) alternative markup to use for the 'else', 'elsif' clauses.
|
58
58
|
def expand_if(condition, new_node_context = self.node, alt_markup = @markup)
|
59
59
|
res = ""
|
60
|
-
res << "<% if #{condition}
|
60
|
+
res << "<% if #{condition} %>"
|
61
61
|
|
62
62
|
with_context(:node => new_node_context) do
|
63
63
|
res << wrap(expand_with)
|
@@ -65,7 +65,7 @@ module Zafu
|
|
65
65
|
|
66
66
|
only = method == 'case' ? %r{^[A-Z]|else|elsif|when} : %w{else elsif when}
|
67
67
|
res << expand_with(:in_if => true, :only => only, :markup => alt_markup)
|
68
|
-
res << "<% end
|
68
|
+
res << "<% end %>"
|
69
69
|
res
|
70
70
|
end
|
71
71
|
|
data/lib/zafu/process/context.rb
CHANGED
@@ -7,8 +7,8 @@ module Zafu
|
|
7
7
|
def r_each
|
8
8
|
if node.list_context?
|
9
9
|
if @params[:alt_class] || @params[:join]
|
10
|
-
out "<% #{var}_max_index = #{node}.size - 1
|
11
|
-
out "<% #{node}.each_with_index do |#{var},#{var}_index|
|
10
|
+
out "<% #{var}_max_index = #{node}.size - 1 %>" if @params[:alt_reverse]
|
11
|
+
out "<% #{node}.each_with_index do |#{var},#{var}_index| %>"
|
12
12
|
|
13
13
|
if join = @params[:join]
|
14
14
|
join = RubyLess.translate_string(self, join)
|
@@ -28,7 +28,7 @@ module Zafu
|
|
28
28
|
@markup.tag ||= 'div'
|
29
29
|
end
|
30
30
|
else
|
31
|
-
out "<% #{node}.each do |#{var}|
|
31
|
+
out "<% #{node}.each do |#{var}| %>"
|
32
32
|
end
|
33
33
|
|
34
34
|
|
@@ -49,7 +49,7 @@ module Zafu
|
|
49
49
|
|
50
50
|
out wrap(expand_with)
|
51
51
|
end
|
52
|
-
out "<% end
|
52
|
+
out "<% end %>"
|
53
53
|
else
|
54
54
|
out expand_with
|
55
55
|
end
|
@@ -104,7 +104,7 @@ module Zafu
|
|
104
104
|
end
|
105
105
|
else
|
106
106
|
res = ''
|
107
|
-
res << "<% #{var} = #{finder[:method]}
|
107
|
+
res << "<% #{var} = #{finder[:method]} %>"
|
108
108
|
open_node_context(finder, :node => node.move_to(var, finder[:class], finder), :form => nil) do
|
109
109
|
res << wrap(expand_with)
|
110
110
|
end
|
data/lib/zafu/process/forms.rb
CHANGED
data/lib/zafu/process/html.rb
CHANGED
@@ -116,6 +116,12 @@ module Zafu
|
|
116
116
|
expand_with
|
117
117
|
end
|
118
118
|
|
119
|
+
def steal_and_eval_html_params_for(markup, params)
|
120
|
+
markup.steal_keys.each do |key|
|
121
|
+
next unless value = params.delete(key)
|
122
|
+
append_markup_attr(markup, key, value)
|
123
|
+
end
|
124
|
+
end
|
119
125
|
#def r_form
|
120
126
|
# res = "<#{@markup.tag}#{params_to_html(@params)}"
|
121
127
|
# @markup.done = true
|
data/test/zafu/basic.yml
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
use_block_as_param:
|
2
|
+
src: "<r:raw>this and thatn</r:raw>"
|
3
|
+
tem: "<%= raw(\"this and thatn\") %>"
|
4
|
+
|
1
5
|
out_post:
|
2
6
|
src: "<r:link post_string='Monday'/>"
|
3
|
-
tem: "<%= make_link(@node) %>Monday"
|
7
|
+
tem: "<%= make_link(@node) %>Monday"
|
8
|
+
|
9
|
+
empty_do:
|
10
|
+
src: "this is <li do=''>not</li>good"
|
11
|
+
tem: "this is good"
|
12
|
+
|
13
|
+
do_with_escaped_quote:
|
14
|
+
src: "<li do='raw(\'blah\')'>blah</li>"
|
15
|
+
tem: "<li><%= raw(\"blah\") %></li>"
|
data/test/zafu/markup.yml
CHANGED
data/test/zafu_test.rb
CHANGED
@@ -15,9 +15,12 @@ class ZafuTest < Test::Unit::TestCase
|
|
15
15
|
include RubyLess
|
16
16
|
safe_method :hello => String
|
17
17
|
safe_method :one => {:class => String, :method => "dummy_one"}
|
18
|
+
safe_context :friend => Dummy
|
18
19
|
end
|
19
20
|
safe_method :dum => Dummy
|
21
|
+
safe_method :list => [Dummy]
|
20
22
|
safe_method :dum2 => {:class => Dummy, :nil => true}
|
23
|
+
safe_method [:raw, String] => String
|
21
24
|
|
22
25
|
context 'Compilation in a model' do
|
23
26
|
setup do
|
@@ -33,12 +36,12 @@ class ZafuTest < Test::Unit::TestCase
|
|
33
36
|
end
|
34
37
|
|
35
38
|
should 'change node context by following safe_method types' do
|
36
|
-
assert_equal '<% var1 = dum
|
39
|
+
assert_equal '<% var1 = dum %><%= var1.hello %>', zafu_erb("<r:dum do='hello'/>")
|
37
40
|
end
|
38
41
|
|
39
42
|
context 'that can be nil' do
|
40
43
|
should 'wrap context in if' do
|
41
|
-
assert_equal '<% if var1 = dum2
|
44
|
+
assert_equal '<% if var1 = dum2 %><%= var1.hello %><% end %>', zafu_erb("<r:dum2 do='hello'/>")
|
42
45
|
end
|
43
46
|
end
|
44
47
|
end
|
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.7.
|
8
|
+
s.version = "0.7.6"
|
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-02-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: 15
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 7
|
9
|
-
-
|
10
|
-
version: 0.7.
|
9
|
+
- 6
|
10
|
+
version: 0.7.6
|
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-02-11 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|