zafu 0.7.7 → 0.7.8

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,4 +1,12 @@
1
- == 0.7.7
1
+ == 0.7.8 2011-05-10
2
+
3
+ * Enhancements
4
+ * Added 'to_s' method to ease debugging.
5
+ * Added support for an array of keys in "ancestor".
6
+ * Added 'on' option to form (ajax actions).
7
+ * Should steal 'title' attribute on 'a' Markup.
8
+
9
+ == 0.7.7 2011-04-14
2
10
 
3
11
  * Enhancements
4
12
  * Added to_s for Markup.
data/lib/zafu/info.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Zafu
2
- VERSION = '0.7.7'
2
+ VERSION = '0.7.8'
3
3
  end
4
4
 
data/lib/zafu/markup.rb CHANGED
@@ -7,6 +7,7 @@ module Zafu
7
7
  EMPTY_TAGS = %w{meta input link img}
8
8
  STEAL_PARAMS = {
9
9
  'link' => [:href, :charset, :rel, :type, :media, :rev, :target],
10
+ 'a' => [:title, :onclick],
10
11
  'script' => [:type, :charset, :defer],
11
12
  :other => [:class, :id, :style],
12
13
  }
@@ -23,6 +24,8 @@ module Zafu
23
24
  attr_accessor :space_before
24
25
  # Space to insert after tag
25
26
  attr_accessor :space_after
27
+ # Keys to remove from zafu and use for the tag itself
28
+ attr_writer :steal_keys
26
29
 
27
30
  class << self
28
31
 
@@ -250,7 +253,7 @@ module Zafu
250
253
  end
251
254
 
252
255
  def steal_keys
253
- (STEAL_PARAMS[@tag] || []) + STEAL_PARAMS[:other]
256
+ @steal_keys || (STEAL_PARAMS[@tag] || []) + STEAL_PARAMS[:other]
254
257
  end
255
258
 
256
259
  private
data/lib/zafu/parser.rb CHANGED
@@ -427,16 +427,15 @@ module Zafu
427
427
 
428
428
  alias public_descendants all_descendants
429
429
 
430
- # Return the last defined parent for the given key.
431
- def ancestor(key)
432
- res = nil
430
+ # Return the last defined parent for the given keys.
431
+ def ancestor(keys)
432
+ keys = Array(keys)
433
433
  ancestors.reverse_each do |a|
434
- if key == a.method
435
- res = a
436
- break
434
+ if keys.include?(a.method)
435
+ return a
437
436
  end
438
437
  end
439
- res
438
+ nil
440
439
  end
441
440
 
442
441
  # Return the last defined descendant for the given key.
@@ -71,7 +71,7 @@ module Zafu
71
71
  @params = Markup.parse_params(@params)
72
72
  end
73
73
 
74
- # set name used for include/replace from html_tag if not allready set by superclass
74
+ # set name used for include/replace from html_tag if not already set by superclass
75
75
  @name = extract_name
76
76
 
77
77
  if !@markup.tag && (@markup.tag = @params.delete(:tag))
@@ -88,6 +88,11 @@ module Zafu
88
88
  end
89
89
  end
90
90
 
91
+ # Used to debug parser.
92
+ def to_s
93
+ "[#{@method}#{@name.blank? ? '' : " '#{@name}'"}#{@params.empty? ? '' : " #{@params.map{|k,v| ":#{k}=>#{v.inspect}"}.join(', ')}"}]" + (@blocks||[]).join('') + "[/#{@method}]"
94
+ end
95
+
91
96
  def extract_name
92
97
  super ||
93
98
  (%w{input select textarea}.include?(@method) ? nil : @params[:name]) ||
@@ -291,5 +296,25 @@ module Zafu
291
296
  flush
292
297
  end
293
298
  end
299
+
300
+ # Helper during compilation to make a block
301
+ def add_block(text_or_opts, at_start = false)
302
+ # avoid wrapping objects in [void][/void]
303
+ bak = @blocks
304
+ @blocks = []
305
+ if text_or_opts.kind_of?(String)
306
+ new_blocks = make(:void, :method => 'void', :text => text_or_opts).blocks
307
+ else
308
+ new_blocks = [make(:void, text_or_opts)]
309
+ end
310
+ if at_start
311
+ bak = new_blocks + bak
312
+ else
313
+ bak += new_blocks
314
+ end
315
+ @blocks = bak
316
+ # Force descendants rebuild
317
+ @all_descendants = nil
318
+ end
294
319
  end # ParsingRules
295
320
  end # Zafu
@@ -41,6 +41,8 @@ module Zafu
41
41
  open_node_context(finder, :node => self.node.move_to(var, finder[:class])) do
42
42
  # Pagination count and other contextual variables exist here.
43
43
 
44
+ # TODO: DRY with r_block...
45
+
44
46
  # INLINE ==========
45
47
  out wrap(
46
48
  expand_with(
@@ -134,9 +136,26 @@ module Zafu
134
136
  else
135
137
  # 1. store template
136
138
  # will wrap with @markup
137
- store_block(self)
139
+ store_block(self, :ajax_action => 'show')
140
+
141
+ if edit_block = descendant('edit')
142
+ form_block = descendant('form') || self
143
+
144
+ publish_after_save = form_block.params[:publish] ||
145
+ (edit_block && edit_block.params[:publish])
146
+
147
+ # 2. store form
148
+ cont = {
149
+ :saved_template => form_url(node.dom_prefix),
150
+ :make_form => self == form_block,
151
+ :publish_after_save => publish_after_save,
152
+ :ajax_action => 'edit',
153
+ }
138
154
 
139
- # 2. render
155
+ store_block(form_block, cont)
156
+ end
157
+
158
+ # 3. render
140
159
  # Set id with the current node context (<%= var1.zip %>).
141
160
  @markup.set_id(node.dom_id(:list => false))
142
161
  out expand_with
@@ -146,29 +165,28 @@ module Zafu
146
165
 
147
166
  def r_edit
148
167
  # ajax
149
- if @context[:form_cancel]
168
+ if cancel = @context[:form_cancel]
150
169
  # cancel button
151
- @context[:form_cancel]
170
+ out cancel
152
171
  else
153
172
  # edit button
154
173
 
155
174
  # TODO: show 'reply' instead of 'edit' in comments if visitor != author
156
- each_block = ancestor('each')
175
+ block = ancestor(%w{each block})
176
+
177
+ # 'publish' is detected by r_block and set in form.
178
+ # removed so it does not polute link
179
+ @params.delete('publish')
180
+ @params.delete('cancel')
157
181
 
158
- link = wrap(make_link(:default_text => _('edit'), :update => each_block, :action => 'edit'))
182
+ link = wrap(make_link(:default_text => _('edit'), :update => block, :action => 'edit'))
159
183
 
160
184
  out "<% if #{node}.can_write? %>#{link}<% end %>"
161
185
  end
162
-
163
- #if @context[:template_url]
164
- #else
165
- # # FIXME: we could link to some html page to edit the item.
166
- # ""
167
- #end
168
186
  end
169
187
 
170
188
  def r_cancel
171
- (@context[:form_options] || {})[:form_cancel]
189
+ r_edit
172
190
  end
173
191
 
174
192
  def r_add
@@ -188,7 +206,7 @@ module Zafu
188
206
  @blocks = []
189
207
  add_btn = make(:void, :method => 'add_btn', :params => @params.dup, :text => '')
190
208
  add_btn.blocks = blocks
191
- remove_instance_variable(:@all_descendants)
209
+ @all_descendants = nil
192
210
  end
193
211
 
194
212
  if @context[:form]
@@ -205,10 +223,14 @@ module Zafu
205
223
  # Expand 'add' block
206
224
  out wrap("#{expand_with(:onclick=>"[\"#{node.dom_prefix}_add\", \"#{node.dom_prefix}_form\"].each(Element.toggle);#{focus}return false;")}")
207
225
 
208
- # New object to render form.
226
+ if klass = @context[:klass]
227
+ return parser_error("Invalid class '#{klass}'") unless klass = get_class(klass)
228
+ else
229
+ klass = Array(node.klass).first
230
+ end
209
231
 
210
- # FIXME: use 'klass' param in r_add or r_form instead of current list content.
211
- new_node = node.move_to("#{var}_new", [node.klass].flatten.first, :new_record => true)
232
+ # New object to render form.
233
+ new_node = node.move_to("#{var}_new", klass, :new_record => true)
212
234
 
213
235
  if new_node.will_be?(Node)
214
236
  # FIXME: BUG if we set <r:form klass='Post'/> the user cannot select class with menu...
@@ -59,7 +59,6 @@ module Zafu
59
59
  def expand_if(condition, new_node_context = self.node, alt_markup = @markup)
60
60
  res = ""
61
61
  res << "<% if #{condition} %>"
62
-
63
62
  with_context(:node => new_node_context) do
64
63
  res << wrap(expand_with)
65
64
  end
@@ -6,6 +6,10 @@ module Zafu
6
6
  end
7
7
 
8
8
  def r_form
9
+ unless @params[:on].nil? || @params[:on].split(',').include?(@context[:ajax_action])
10
+ return ''
11
+ end
12
+
9
13
  options = form_options
10
14
 
11
15
  @markup.set_id(options[:id]) if options[:id]
@@ -59,7 +63,7 @@ module Zafu
59
63
  def make_form
60
64
  return nil unless @context[:make_form]
61
65
 
62
- if method == 'each'
66
+ if method == 'each' || method == 'block'
63
67
  r_form
64
68
  else
65
69
  nil
@@ -101,9 +105,8 @@ module Zafu
101
105
  # Render the 'form' tag and set expansion context.
102
106
  def form_tag(options)
103
107
  opts = options.dup
104
- form = @context[:form]
105
108
 
106
- if form && (form.descendant('cancel') || form.descendant('edit'))
109
+ if descendant('cancel') || descendant('edit')
107
110
  # Pass 'form_cancel' content to expand_with (already in options).
108
111
  else
109
112
  # Insert cancel before form
@@ -84,7 +84,9 @@ module Zafu
84
84
  case @markup.tag
85
85
  when 'link'
86
86
  key = :href
87
- if @params[:rel].downcase == 'stylesheet'
87
+ return parser_error("Missing 'rel' parameter.") unless rel = @params[:rel]
88
+ return parser_error("Missing 'href' parameter.") unless @params[:href]
89
+ if rel.downcase == 'stylesheet'
88
90
  type = :stylesheet
89
91
  else
90
92
  type = :link
@@ -21,7 +21,6 @@ module Zafu
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
23
  def safe_method_type(signature, receiver = nil)
24
- #puts [node.name, node.klass, signature].inspect
25
24
  super || get_method_type(signature, false)
26
25
  end
27
26
 
@@ -94,13 +93,15 @@ module Zafu
94
93
  end
95
94
 
96
95
  def get_attribute_or_eval(use_string_block = true)
97
- if attribute = @params[:date]
96
+ if @params[:date] && method != 'link'
98
97
  return parser_continue("'date' parameter is deprecated. Please use 'attr' or 'eval'.")
99
98
  elsif attribute = @params[:attr]
100
99
  code = "this.#{attribute}"
101
100
  elsif code = @params[:eval] || @params[:test]
102
101
  elsif text = @params[:text]
103
102
  code = "%Q{#{text}}"
103
+ elsif text = @params[:t]
104
+ code = "t(%Q{#{text}})"
104
105
  elsif use_string_block && @blocks.size == 1 && @blocks.first.kind_of?(String)
105
106
  return RubyLess::TypedString.new(@blocks.first.inspect, :class => String, :literal => @blocks.first)
106
107
  else
@@ -273,7 +274,8 @@ module Zafu
273
274
  ivar = signature.first
274
275
  if ivar == 'this'
275
276
  if node.list_context?
276
- raise RubyLess::Error.new("Cannot use 'this' in list_context.")
277
+ # Return first element
278
+ node.opts.merge(:class => node.klass.first, :method => "#{node}.first")
277
279
  else
278
280
  node.opts.merge(:class => node.klass, :method => node.name)
279
281
  end
data/test/zafu/meta.yml CHANGED
@@ -4,7 +4,8 @@ some_template:
4
4
 
5
5
  include_with_part:
6
6
  # part 'a' is moved around
7
- src: "<r:include template='/some/template'><r:with part='a'/><r:with part='b'>new b:<r:include template='/some/template' part='a'/></r:with></r:include>"
7
+ # and we overwrite 'link' method with 'void'
8
+ src: "<r:include template='/some/template'><r:with part='a'/><r:with part='b' do='void'>new b:<r:include template='/some/template' part='a'/></r:with></r:include>"
8
9
  tem: "<div id='b'>new b:<div id='a'>a</div></div>"
9
10
 
10
11
  include_with_part_change_class:
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.7"
8
+ s.version = "0.7.8"
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-04-15}
12
+ s.date = %q{2011-05-10}
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: 13
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
- - 7
10
- version: 0.7.7
9
+ - 8
10
+ version: 0.7.8
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-04-15 00:00:00 +02:00
18
+ date: 2011-05-10 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency