zafu 0.7.6 → 0.7.7

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,4 +1,10 @@
1
- == 0.7.6
1
+ == 0.7.7
2
+
3
+ * Enhancements
4
+ * Added to_s for Markup.
5
+ * Fixed a bug where markup wrapping would occur too often on ajax block.
6
+
7
+ == 0.7.6 2011-02-11
2
8
 
3
9
  * Enhancements
4
10
  * Enabled empty do (ignore method)
data/lib/zafu/info.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Zafu
2
- VERSION = '0.7.6'
2
+ VERSION = '0.7.7'
3
3
  end
4
4
 
data/lib/zafu/markup.rb CHANGED
@@ -4,7 +4,7 @@ module Zafu
4
4
  # A Markup object is used to hold information on the tag used (<li>), it's parameters (.. class='xxx') and
5
5
  # indentation.
6
6
  class Markup
7
- EMPTY_TAGS = %w{meta input link}
7
+ EMPTY_TAGS = %w{meta input link img}
8
8
  STEAL_PARAMS = {
9
9
  'link' => [:href, :charset, :rel, :type, :media, :rev, :target],
10
10
  'script' => [:type, :charset, :defer],
@@ -63,10 +63,14 @@ module Zafu
63
63
  end
64
64
  end
65
65
 
66
- def initialize(tag)
66
+ def initialize(tag, params = nil)
67
67
  @done = false
68
68
  @tag = tag
69
- @params = OrderedHash.new
69
+ if params
70
+ self.params = params
71
+ else
72
+ @params = OrderedHash.new
73
+ end
70
74
  @dyn_params = OrderedHash.new
71
75
  end
72
76
 
@@ -241,6 +245,10 @@ module Zafu
241
245
  (@space_before || '') + res + (@space_after || '')
242
246
  end
243
247
 
248
+ def to_s
249
+ wrap(nil)
250
+ end
251
+
244
252
  def steal_keys
245
253
  (STEAL_PARAMS[@tag] || []) + STEAL_PARAMS[:other]
246
254
  end
@@ -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}.#{finder[:class].first <= 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
 
@@ -55,12 +55,10 @@ module Zafu
55
55
  )
56
56
 
57
57
  # Render 'else' clauses
58
- @markup.done = false
59
- out wrap(
60
- expand_with(
58
+ else_clauses = expand_with(
61
59
  :in_if => true,
62
- :only => ['elsif', 'else']
63
- )
60
+ :only => ['elsif', 'else'],
61
+ :markup => @markup
64
62
  )
65
63
 
66
64
  # 2. Save 'each' template
@@ -270,7 +268,8 @@ module Zafu
270
268
  if ['context', 'each', 'block'].include?(method)
271
269
  # do not propagate 'form',etc up
272
270
  all.reject do |k,v|
273
- ['form','unlink'].include?(k)
271
+ # FIXME: Zena leakage
272
+ ['form','unlink', 'count'].include?(k)
274
273
  end
275
274
  elsif ['if', 'case'].include?(method) || (method =~ /^[A-Z]/)
276
275
  # conditional
@@ -338,6 +337,9 @@ module Zafu
338
337
  ['block', 'drop'].include?(each_block.single_child_method)
339
338
  end
340
339
 
340
+ def context_for_partial(cont)
341
+ context_without_vars.merge(cont)
342
+ end
341
343
  private
342
344
 
343
345
  # Find a block to update on the page
@@ -354,7 +356,7 @@ module Zafu
354
356
  end
355
357
 
356
358
  def store_block(block, cont = {})
357
- cont = context_without_vars.merge(cont)
359
+ cont, prefix = context_for_partial(cont)
358
360
 
359
361
  # Create new node context
360
362
  node = cont[:node].as_main(ActiveRecord::Base)
@@ -369,7 +371,7 @@ module Zafu
369
371
 
370
372
  # We overwrite all context: no merge.
371
373
  with_context(cont, false) do
372
- template = expand_block(block)
374
+ template = prefix.to_s + expand_block(block)
373
375
  end
374
376
 
375
377
  out helper.save_erb_to_url(template, cont[:saved_template])
@@ -29,6 +29,7 @@ module Zafu
29
29
 
30
30
  # We use 'elsif' just in case there are more then one 'else' clause
31
31
  if markup = @context[:markup]
32
+ # Copy markup tag
32
33
  @markup.tag ||= markup.tag
33
34
  @markup.steal_html_params_from(@params)
34
35
  markup.params.each do |k, v|
@@ -94,7 +94,9 @@ module Zafu
94
94
  end
95
95
 
96
96
  def get_attribute_or_eval(use_string_block = true)
97
- if attribute = @params[:attr] || @params[:date]
97
+ if attribute = @params[:date]
98
+ return parser_continue("'date' parameter is deprecated. Please use 'attr' or 'eval'.")
99
+ elsif attribute = @params[:attr]
98
100
  code = "this.#{attribute}"
99
101
  elsif code = @params[:eval] || @params[:test]
100
102
  elsif text = @params[:text]
@@ -110,19 +112,32 @@ module Zafu
110
112
  return parser_continue(err.message, code)
111
113
  end
112
114
 
115
+ # Pass default values as parameters in @context as :param_XXXX
116
+ def r_default
117
+ cont = {}
118
+ @params.each do |k, v|
119
+ cont[:"params_#{k}"] = v
120
+ end
121
+ expand_with cont
122
+ end
123
+
113
124
  private
114
125
  # Extract arguments from params
115
126
  def extract_from_params(*keys)
116
127
  res = []
117
128
 
118
129
  keys.each do |key|
119
- next unless value = @params[key.to_sym]
130
+ next unless value = param(key.to_sym)
120
131
  res << ":#{key} => #{RubyLess.translate_string(self, value)}"
121
132
  end
122
133
 
123
134
  res.empty? ? nil : res
124
135
  end
125
136
 
137
+ def param(key, default = nil)
138
+ @params[key] || @context[:"params_#{key}"] || default
139
+ end
140
+
126
141
  # Method resolution. The first matching method is returned. Order of evaluation is
127
142
  # 1. find node_context (@page, @image, self)
128
143
  # 2. set var (set_xxx = '...')
@@ -217,6 +232,8 @@ module Zafu
217
232
  else
218
233
  out "<%= #{res} %>"
219
234
  end
235
+ elsif res.klass == Boolean
236
+ expand_if(res)
220
237
  elsif @blocks.empty?
221
238
  out "<%= #{res} %>"
222
239
  elsif res.could_be_nil?
data/test/markup_test.rb CHANGED
@@ -296,6 +296,16 @@ class MarkupTest < Test::Unit::TestCase
296
296
  end
297
297
  end
298
298
  end
299
+
300
+ context 'To string' do
301
+ subject do
302
+ Markup.new('img', :src => '/foo/bar.png')
303
+ end
304
+
305
+ should 'render' do
306
+ assert_equal "<img src='/foo/bar.png'/>", subject.to_s
307
+ end
308
+ end
299
309
 
300
310
  context 'Wrapping some text' do
301
311
  setup do
data/test/zafu/meta.yml CHANGED
@@ -1,12 +1,17 @@
1
1
  some_template:
2
- src: "<div id='a'>a</div><div id='b'>b</div>"
3
- tem: "<div id='a'>a</div><div id='b'>b</div>"
2
+ src: "<div id='a'>a</div><div id='b' do='link'>b</div>"
3
+ tem: "<div id='a'>a</div><div id='b'><%= make_link(@node) %></div>"
4
4
 
5
5
  include_with_part:
6
6
  # part 'a' is moved around
7
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>"
8
8
  tem: "<div id='b'>new b:<div id='a'>a</div></div>"
9
9
 
10
+ include_with_part_change_class:
11
+ # part 'a' is moved around
12
+ src: "<r:include template='/some/template'><div class='foobar' do='with' part='b'>new b</div></r:include>"
13
+ tem: "<div id='a'>a</div><div id='b' class='foobar'><%= make_link(@node) %></div>"
14
+
10
15
  include_missing_part:
11
16
  # part 'a' is moved around
12
17
  src: "<r:include template='/some/template' part='bad'/>"
@@ -14,4 +19,8 @@ include_missing_part:
14
19
 
15
20
  missing_template:
16
21
  src: "<r:include template='Foo'/>"
17
- tem: "/template 'Foo' not found/"
22
+ tem: "/template 'Foo' not found/"
23
+
24
+ include_part:
25
+ src: "xxx <r:include template='/some/template' part='b'/>"
26
+ tem: "xxx <div id='b'><%= make_link(@node) %></div>"
data/zafu.gemspec CHANGED
@@ -1,91 +1,88 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{zafu}
8
- s.version = "0.7.6"
8
+ s.version = "0.7.7"
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-02-11}
12
+ s.date = %q{2011-04-15}
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 = [
16
16
  "README.rdoc"
17
17
  ]
18
18
  s.files = [
19
- ".gitignore",
20
- "History.txt",
21
- "README.rdoc",
22
- "Rakefile",
23
- "lib/zafu.rb",
24
- "lib/zafu/all.rb",
25
- "lib/zafu/compiler.rb",
26
- "lib/zafu/controller_methods.rb",
27
- "lib/zafu/handler.rb",
28
- "lib/zafu/info.rb",
29
- "lib/zafu/markup.rb",
30
- "lib/zafu/mock_helper.rb",
31
- "lib/zafu/node_context.rb",
32
- "lib/zafu/ordered_hash.rb",
33
- "lib/zafu/parser.rb",
34
- "lib/zafu/parsing_rules.rb",
35
- "lib/zafu/process/ajax.rb",
36
- "lib/zafu/process/conditional.rb",
37
- "lib/zafu/process/context.rb",
38
- "lib/zafu/process/forms.rb",
39
- "lib/zafu/process/html.rb",
40
- "lib/zafu/process/ruby_less_processing.rb",
41
- "lib/zafu/security.rb",
42
- "lib/zafu/template.rb",
43
- "lib/zafu/test_helper.rb",
44
- "lib/zafu/view_methods.rb",
45
- "rails/init.rb",
46
- "script/console",
47
- "script/destroy",
48
- "script/generate",
49
- "test/markup_test.rb",
50
- "test/mock/classes.rb",
51
- "test/mock/core_ext.rb",
52
- "test/mock/params.rb",
53
- "test/mock/process.rb",
54
- "test/mock/test_compiler.rb",
55
- "test/node_context_test.rb",
56
- "test/ordered_hash_test.rb",
57
- "test/ruby_less_test.rb",
58
- "test/test_helper.rb",
59
- "test/zafu/ajax.yml",
60
- "test/zafu/asset.yml",
61
- "test/zafu/basic.yml",
62
- "test/zafu/markup.yml",
63
- "test/zafu/meta.yml",
64
- "test/zafu/security.yml",
65
- "test/zafu_test.rb",
66
- "zafu.gemspec"
19
+ "History.txt",
20
+ "README.rdoc",
21
+ "Rakefile",
22
+ "lib/zafu.rb",
23
+ "lib/zafu/all.rb",
24
+ "lib/zafu/compiler.rb",
25
+ "lib/zafu/controller_methods.rb",
26
+ "lib/zafu/handler.rb",
27
+ "lib/zafu/info.rb",
28
+ "lib/zafu/markup.rb",
29
+ "lib/zafu/mock_helper.rb",
30
+ "lib/zafu/node_context.rb",
31
+ "lib/zafu/ordered_hash.rb",
32
+ "lib/zafu/parser.rb",
33
+ "lib/zafu/parsing_rules.rb",
34
+ "lib/zafu/process/ajax.rb",
35
+ "lib/zafu/process/conditional.rb",
36
+ "lib/zafu/process/context.rb",
37
+ "lib/zafu/process/forms.rb",
38
+ "lib/zafu/process/html.rb",
39
+ "lib/zafu/process/ruby_less_processing.rb",
40
+ "lib/zafu/security.rb",
41
+ "lib/zafu/template.rb",
42
+ "lib/zafu/test_helper.rb",
43
+ "lib/zafu/view_methods.rb",
44
+ "rails/init.rb",
45
+ "script/console",
46
+ "script/destroy",
47
+ "script/generate",
48
+ "test/markup_test.rb",
49
+ "test/mock/classes.rb",
50
+ "test/mock/core_ext.rb",
51
+ "test/mock/params.rb",
52
+ "test/mock/process.rb",
53
+ "test/mock/test_compiler.rb",
54
+ "test/node_context_test.rb",
55
+ "test/ordered_hash_test.rb",
56
+ "test/ruby_less_test.rb",
57
+ "test/test_helper.rb",
58
+ "test/zafu/ajax.yml",
59
+ "test/zafu/asset.yml",
60
+ "test/zafu/basic.yml",
61
+ "test/zafu/markup.yml",
62
+ "test/zafu/meta.yml",
63
+ "test/zafu/security.yml",
64
+ "test/zafu_test.rb",
65
+ "zafu.gemspec"
67
66
  ]
68
67
  s.homepage = %q{http://zenadmin.org/zafu}
69
- s.rdoc_options = ["--charset=UTF-8"]
70
68
  s.require_paths = ["lib"]
71
- s.rubygems_version = %q{1.3.7}
69
+ s.rubygems_version = %q{1.6.1}
72
70
  s.summary = %q{Provides a powerful templating language based on xhtml for rails}
73
71
  s.test_files = [
74
72
  "test/markup_test.rb",
75
- "test/mock/classes.rb",
76
- "test/mock/core_ext.rb",
77
- "test/mock/params.rb",
78
- "test/mock/process.rb",
79
- "test/mock/test_compiler.rb",
80
- "test/node_context_test.rb",
81
- "test/ordered_hash_test.rb",
82
- "test/ruby_less_test.rb",
83
- "test/test_helper.rb",
84
- "test/zafu_test.rb"
73
+ "test/mock/classes.rb",
74
+ "test/mock/core_ext.rb",
75
+ "test/mock/params.rb",
76
+ "test/mock/process.rb",
77
+ "test/mock/test_compiler.rb",
78
+ "test/node_context_test.rb",
79
+ "test/ordered_hash_test.rb",
80
+ "test/ruby_less_test.rb",
81
+ "test/test_helper.rb",
82
+ "test/zafu_test.rb"
85
83
  ]
86
84
 
87
85
  if s.respond_to? :specification_version then
88
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
89
86
  s.specification_version = 3
90
87
 
91
88
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
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: 15
5
- prerelease: false
4
+ hash: 13
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
- - 6
10
- version: 0.7.6
9
+ - 7
10
+ version: 0.7.7
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-02-11 00:00:00 +01:00
18
+ date: 2011-04-15 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -73,7 +73,6 @@ extensions: []
73
73
  extra_rdoc_files:
74
74
  - README.rdoc
75
75
  files:
76
- - .gitignore
77
76
  - History.txt
78
77
  - README.rdoc
79
78
  - Rakefile
@@ -126,8 +125,8 @@ homepage: http://zenadmin.org/zafu
126
125
  licenses: []
127
126
 
128
127
  post_install_message:
129
- rdoc_options:
130
- - --charset=UTF-8
128
+ rdoc_options: []
129
+
131
130
  require_paths:
132
131
  - lib
133
132
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -151,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
150
  requirements: []
152
151
 
153
152
  rubyforge_project:
154
- rubygems_version: 1.3.7
153
+ rubygems_version: 1.6.1
155
154
  signing_key:
156
155
  specification_version: 3
157
156
  summary: Provides a powerful templating language based on xhtml for rails
data/.gitignore DELETED
@@ -1,2 +0,0 @@
1
- *.gem
2
- .DS_Store