zafu 0.6.3 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +8 -0
- data/Rakefile +1 -1
- data/lib/zafu/info.rb +1 -1
- data/lib/zafu/markup.rb +2 -2
- data/lib/zafu/node_context.rb +8 -4
- data/lib/zafu/process/context.rb +7 -5
- data/lib/zafu/process/ruby_less_processing.rb +38 -25
- data/zafu.gemspec +5 -5
- metadata +6 -6
data/History.txt
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
== 0.7.0 2010-09-14
|
2
|
+
|
3
|
+
* Major enhancements
|
4
|
+
* Using latest API from RubyLess and better NodeContext parameter transparency.
|
5
|
+
* Added get_type_from_query_select to resolve RubyLess with QueryBuilder select.
|
6
|
+
* Added 'opts' attribute to pass information in the compiler.
|
7
|
+
* Removed bad '#{foo}' resolution to r_show (this is syntactically wrong Ruby). Using a fallback on r_show instead.
|
8
|
+
|
1
9
|
== 0.6.3 2010-08-25
|
2
10
|
|
3
11
|
* Minor enhancement
|
data/Rakefile
CHANGED
@@ -14,7 +14,7 @@ begin
|
|
14
14
|
gem.authors = ["Gaspard Bucher"]
|
15
15
|
gem.add_development_dependency "shoulda", ">= 0"
|
16
16
|
gem.add_development_dependency "yamltest", ">= 0.5.0"
|
17
|
-
gem.add_dependency "rubyless", ">= 0.
|
17
|
+
gem.add_dependency "rubyless", ">= 0.7.0"
|
18
18
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
19
19
|
end
|
20
20
|
Jeweler::GemcutterTasks.new
|
data/lib/zafu/info.rb
CHANGED
data/lib/zafu/markup.rb
CHANGED
@@ -100,9 +100,9 @@ module Zafu
|
|
100
100
|
if value =~ /^(.*)\#\{(.*)\}(.*)$/
|
101
101
|
@params.delete(key)
|
102
102
|
if $1 == '' && $3 == ''
|
103
|
-
append_dyn_param(key, "<%= #{RubyLess.translate($2
|
103
|
+
append_dyn_param(key, "<%= #{RubyLess.translate(helper, $2)} %>")
|
104
104
|
else
|
105
|
-
append_dyn_param(key, "<%= #{RubyLess.translate_string(
|
105
|
+
append_dyn_param(key, "<%= #{RubyLess.translate_string(helper, value)} %>")
|
106
106
|
end
|
107
107
|
end
|
108
108
|
end
|
data/lib/zafu/node_context.rb
CHANGED
@@ -13,12 +13,16 @@ module Zafu
|
|
13
13
|
# it has a name or dom id defined ('main', 'related', 'list', etc).
|
14
14
|
attr_writer :dom_prefix
|
15
15
|
|
16
|
-
|
17
|
-
|
16
|
+
# Any kind of information that the compiler might need to use (QueryBuilder query used
|
17
|
+
# to fetch the node for example).
|
18
|
+
attr_reader :opts
|
19
|
+
|
20
|
+
def initialize(name, klass, up = nil, opts = {})
|
21
|
+
@name, @klass, @up, @opts = name, klass, up, opts
|
18
22
|
end
|
19
23
|
|
20
|
-
def move_to(name, klass)
|
21
|
-
NodeContext.new(name, klass, self)
|
24
|
+
def move_to(name, klass, opts={})
|
25
|
+
NodeContext.new(name, klass, self, opts)
|
22
26
|
end
|
23
27
|
|
24
28
|
# Since the idiom to write the node context name is the main purpose of this class, it
|
data/lib/zafu/process/context.rb
CHANGED
@@ -11,7 +11,7 @@ module Zafu
|
|
11
11
|
out "<% #{node}.each_with_index do |#{var},#{var}_index| -%>"
|
12
12
|
|
13
13
|
if join = @params[:join]
|
14
|
-
join = RubyLess.translate_string(
|
14
|
+
join = RubyLess.translate_string(self, join)
|
15
15
|
#if join_clause = @params[:join_if]
|
16
16
|
# set_stored(Node, 'prev', "#{var}_prev")
|
17
17
|
# cond = get_test_condition(var, :test=>join_clause)
|
@@ -22,7 +22,7 @@ module Zafu
|
|
22
22
|
end
|
23
23
|
|
24
24
|
if alt_class = @params[:alt_class]
|
25
|
-
alt_class = RubyLess.translate_string(
|
25
|
+
alt_class = RubyLess.translate_string(self, alt_class)
|
26
26
|
alt_test = @params[:alt_reverse] == 'true' ? "(#{var}_max_index - #{var}_index) % 2 != 0" : "#{var}_index % 2 != 0"
|
27
27
|
@markup.append_dyn_param(:class, "<%= #{alt_test} ? #{alt_class} : '' %>")
|
28
28
|
@markup.tag ||= 'div'
|
@@ -32,7 +32,9 @@ module Zafu
|
|
32
32
|
end
|
33
33
|
|
34
34
|
|
35
|
-
with_context(:node => node.move_to(var, node.klass.first)) do
|
35
|
+
with_context(:node => node.move_to(var, node.klass.first, :query => node.opts[:query])) do
|
36
|
+
# We pass the :query option for RubyLess resolution by using the QueryBuilder finder
|
37
|
+
|
36
38
|
# The id set here should be used as prefix for sub-nodes to ensure uniqueness of generated DOM ids
|
37
39
|
if node.list_context?
|
38
40
|
# we are still in a list (example: previous context was [[Node]], current is [Node])
|
@@ -100,12 +102,12 @@ module Zafu
|
|
100
102
|
def expand_with_finder(finder)
|
101
103
|
if finder[:nil]
|
102
104
|
open_node_context(finder, :form => nil) do # do not propagate :form
|
103
|
-
expand_if("#{var} = #{finder[:method]}", node.move_to(var, finder[:class]))
|
105
|
+
expand_if("#{var} = #{finder[:method]}", node.move_to(var, finder[:class], finder.merge(:nil => false)))
|
104
106
|
end
|
105
107
|
else
|
106
108
|
res = ''
|
107
109
|
res << "<% #{var} = #{finder[:method]} -%>"
|
108
|
-
open_node_context(finder, :node => node.move_to(var, finder[:class]), :form => nil) do
|
110
|
+
open_node_context(finder, :node => node.move_to(var, finder[:class], finder), :form => nil) do
|
109
111
|
res << wrap(expand_with)
|
110
112
|
end
|
111
113
|
res
|
@@ -20,7 +20,7 @@ module Zafu
|
|
20
20
|
# Actual method resolution. The lookup first starts in the current helper. If nothing is found there, it
|
21
21
|
# searches inside a 'helpers' module and finally looks into the current node_context.
|
22
22
|
# If nothing is found at this stage, we prepend the method with the current node and start over again.
|
23
|
-
def safe_method_type(signature)
|
23
|
+
def safe_method_type(signature, receiver = nil)
|
24
24
|
#puts [node.name, node.klass, signature].inspect
|
25
25
|
super || get_method_type(signature, false)
|
26
26
|
end
|
@@ -32,12 +32,7 @@ module Zafu
|
|
32
32
|
return rubyless_class_scope(@method)
|
33
33
|
end
|
34
34
|
|
35
|
-
|
36
|
-
params[:eval] = $1
|
37
|
-
r_show
|
38
|
-
else
|
39
|
-
rubyless_render(@method, params)
|
40
|
-
end
|
35
|
+
rubyless_render(@method, params)
|
41
36
|
rescue RubyLess::NoMethodError => err
|
42
37
|
parser_continue("#{err.error_message} <span class='type'>#{err.method_with_arguments}</span> for #{err.receiver_with_class}")
|
43
38
|
rescue RubyLess::Error => err
|
@@ -73,15 +68,25 @@ module Zafu
|
|
73
68
|
def rubyless_render(method, params)
|
74
69
|
# We need to set this here because we cannot pass options to RubyLess or get them back
|
75
70
|
# when we evaluate the method to see if we can use blocks as arguments.
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
71
|
+
begin
|
72
|
+
@rendering_block_owner = true
|
73
|
+
code = method_with_arguments(method, params)
|
74
|
+
rubyless_expand RubyLess.translate(self, code)
|
75
|
+
rescue RubyLess::Error => err
|
76
|
+
if !@params.empty?
|
77
|
+
# try to use r_show without using params as arguments
|
78
|
+
params[:eval] = @method
|
79
|
+
r_show
|
80
|
+
else
|
81
|
+
raise err
|
82
|
+
end
|
83
|
+
ensure
|
84
|
+
@rendering_block_owner = false
|
85
|
+
end
|
81
86
|
end
|
82
87
|
|
83
88
|
def set_markup_attr(markup, key, value)
|
84
|
-
value = value.kind_of?(RubyLess::TypedString) ? value : RubyLess.translate_string(
|
89
|
+
value = value.kind_of?(RubyLess::TypedString) ? value : RubyLess.translate_string(self, value)
|
85
90
|
if value.literal
|
86
91
|
markup.set_param(key, value.literal)
|
87
92
|
else
|
@@ -90,7 +95,7 @@ module Zafu
|
|
90
95
|
end
|
91
96
|
|
92
97
|
def append_markup_attr(markup, key, value)
|
93
|
-
value = RubyLess.translate_string(
|
98
|
+
value = RubyLess.translate_string(self, value)
|
94
99
|
if value.literal
|
95
100
|
markup.append_param(key, value.literal)
|
96
101
|
else
|
@@ -110,7 +115,7 @@ module Zafu
|
|
110
115
|
return parser_continue("Missing attribute/eval parameter")
|
111
116
|
end
|
112
117
|
|
113
|
-
RubyLess.translate(
|
118
|
+
RubyLess.translate(self, code)
|
114
119
|
rescue RubyLess::Error => err
|
115
120
|
return parser_continue(err.message, code)
|
116
121
|
end
|
@@ -122,14 +127,21 @@ module Zafu
|
|
122
127
|
|
123
128
|
keys.each do |key|
|
124
129
|
next unless value = @params[key.to_sym]
|
125
|
-
res << ":#{key} => #{RubyLess.translate_string(
|
130
|
+
res << ":#{key} => #{RubyLess.translate_string(self, value)}"
|
126
131
|
end
|
127
132
|
|
128
133
|
res.empty? ? nil : res
|
129
134
|
end
|
130
135
|
|
131
|
-
#
|
136
|
+
# Method resolution. The first matching method is returned. Order of evaluation is
|
137
|
+
# 1. find node_context (@page, @image, self)
|
138
|
+
# 2. set var (set_xxx = '...')
|
139
|
+
# 3. template helper methods
|
140
|
+
# 4. contextual node methods (var1.xxx)
|
141
|
+
# 5. contextual first node of list method ([...].first.xxx)
|
142
|
+
# 6. append block as argument (restart 1-5 with xxx(block_string))
|
132
143
|
def get_method_type(signature, added_options = false)
|
144
|
+
node = self.node
|
133
145
|
raise "#{node.klass.class}" unless node.klass.kind_of?(Array) || node.klass.kind_of?(Class)
|
134
146
|
|
135
147
|
if type = node_context_from_signature(signature)
|
@@ -144,10 +156,11 @@ module Zafu
|
|
144
156
|
elsif helper.respond_to?(:helpers) && type = safe_method_from(helper.helpers, signature)
|
145
157
|
# Resolve by looking at the included helpers
|
146
158
|
type
|
147
|
-
elsif node && node.
|
159
|
+
elsif node && !node.list_context? && type = safe_method_from(node.klass, signature, node)
|
160
|
+
# not a list_contex
|
148
161
|
# Resolve node context methods: xxx.foo, xxx.bar
|
149
162
|
type.merge(:method => "#{node.name}.#{type[:method]}")
|
150
|
-
elsif node && node.
|
163
|
+
elsif node && node.list_context? && type = safe_method_from(node.klass.first, signature, node)
|
151
164
|
type.merge(:method => "#{node.name}.first.#{type[:method]}")
|
152
165
|
elsif @rendering_block_owner && @blocks.first.kind_of?(String) && !added_options
|
153
166
|
# Insert the block content into the method: <r:trans>blah</r:trans> becomes trans("blah")
|
@@ -248,11 +261,11 @@ module Zafu
|
|
248
261
|
if node.list_context?
|
249
262
|
raise RubyLess::Error.new("Cannot use 'this' in list_context.")
|
250
263
|
else
|
251
|
-
|
264
|
+
node.opts.merge(:class => node.klass, :method => node.name)
|
252
265
|
end
|
253
266
|
elsif ivar[0..0] == '@' && klass = get_class(ivar[1..-1].capitalize)
|
254
267
|
if node = self.node(klass)
|
255
|
-
|
268
|
+
node.opts.merge(:class => node.klass, :method => node.name)
|
256
269
|
else
|
257
270
|
nil
|
258
271
|
end
|
@@ -271,12 +284,12 @@ module Zafu
|
|
271
284
|
end
|
272
285
|
end
|
273
286
|
|
274
|
-
def safe_method_from(
|
287
|
+
def safe_method_from(solver, signature, receiver = nil)
|
275
288
|
|
276
|
-
if
|
277
|
-
|
289
|
+
if solver.respond_to?(:safe_method_type)
|
290
|
+
solver.safe_method_type(signature, receiver)
|
278
291
|
else
|
279
|
-
RubyLess::SafeClass.safe_method_type_for(
|
292
|
+
RubyLess::SafeClass.safe_method_type_for(solver, signature)
|
280
293
|
end
|
281
294
|
end
|
282
295
|
|
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
|
+
s.version = "0.7.0"
|
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{2010-
|
12
|
+
s.date = %q{2010-09-14}
|
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 = [
|
@@ -90,16 +90,16 @@ Gem::Specification.new do |s|
|
|
90
90
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
91
91
|
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
92
92
|
s.add_development_dependency(%q<yamltest>, [">= 0.5.0"])
|
93
|
-
s.add_runtime_dependency(%q<rubyless>, [">= 0.
|
93
|
+
s.add_runtime_dependency(%q<rubyless>, [">= 0.7.0"])
|
94
94
|
else
|
95
95
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
96
96
|
s.add_dependency(%q<yamltest>, [">= 0.5.0"])
|
97
|
-
s.add_dependency(%q<rubyless>, [">= 0.
|
97
|
+
s.add_dependency(%q<rubyless>, [">= 0.7.0"])
|
98
98
|
end
|
99
99
|
else
|
100
100
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
101
101
|
s.add_dependency(%q<yamltest>, [">= 0.5.0"])
|
102
|
-
s.add_dependency(%q<rubyless>, [">= 0.
|
102
|
+
s.add_dependency(%q<rubyless>, [">= 0.7.0"])
|
103
103
|
end
|
104
104
|
end
|
105
105
|
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 7
|
8
|
+
- 0
|
9
|
+
version: 0.7.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Gaspard Bucher
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-09-14 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -52,9 +52,9 @@ dependencies:
|
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
segments:
|
54
54
|
- 0
|
55
|
-
-
|
55
|
+
- 7
|
56
56
|
- 0
|
57
|
-
version: 0.
|
57
|
+
version: 0.7.0
|
58
58
|
type: :runtime
|
59
59
|
version_requirements: *id003
|
60
60
|
description: Provides a powerful templating language based on xhtml for rails
|