zafu 0.5.0 → 0.6.0
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 +11 -0
- data/Rakefile +2 -1
- data/lib/zafu/all.rb +6 -4
- data/lib/zafu/controller_methods.rb +27 -18
- data/lib/zafu/info.rb +1 -1
- data/lib/zafu/markup.rb +87 -25
- data/lib/zafu/node_context.rb +48 -4
- data/lib/zafu/ordered_hash.rb +47 -0
- data/lib/zafu/parser.rb +140 -55
- data/lib/zafu/parsing_rules.rb +49 -17
- data/lib/zafu/process/ajax.rb +344 -66
- data/lib/zafu/process/conditional.rb +36 -25
- data/lib/zafu/process/context.rb +101 -4
- data/lib/zafu/process/forms.rb +124 -0
- data/lib/zafu/process/html.rb +78 -83
- data/lib/zafu/process/ruby_less_processing.rb +248 -0
- data/lib/zafu/test_helper.rb +1 -1
- data/lib/zafu/view_methods.rb +6 -0
- data/test/markup_test.rb +150 -8
- data/test/mock/classes.rb +24 -0
- data/test/mock/core_ext.rb +9 -0
- data/test/mock/params.rb +4 -10
- data/test/mock/process.rb +7 -0
- data/test/mock/test_compiler.rb +9 -0
- data/test/node_context_test.rb +135 -46
- data/test/ordered_hash_test.rb +69 -0
- data/test/ruby_less_test.rb +29 -19
- data/test/test_helper.rb +4 -3
- data/test/zafu/ajax.yml +7 -0
- data/test/zafu/asset.yml +3 -0
- data/test/zafu/basic.yml +3 -0
- data/test/zafu/markup.yml +4 -0
- data/test/zafu/meta.yml +8 -0
- data/test/zafu/security.yml +19 -0
- data/test/zafu_test.rb +29 -12
- data/zafu.gemspec +28 -6
- metadata +41 -8
- data/lib/zafu/process/ruby_less.rb +0 -145
@@ -0,0 +1,24 @@
|
|
1
|
+
module Foo
|
2
|
+
end
|
3
|
+
|
4
|
+
unless defined?(ActiveRecord)
|
5
|
+
module ActiveRecord
|
6
|
+
class Base
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class Page < ActiveRecord::Base
|
12
|
+
include RubyLess
|
13
|
+
safe_context :root => Page
|
14
|
+
end
|
15
|
+
|
16
|
+
class SubPage < Page
|
17
|
+
include Foo
|
18
|
+
end
|
19
|
+
|
20
|
+
class SubSubPage < SubPage
|
21
|
+
end
|
22
|
+
|
23
|
+
class Comment
|
24
|
+
end
|
data/test/mock/params.rb
CHANGED
@@ -1,19 +1,13 @@
|
|
1
1
|
module Mock
|
2
2
|
module Params
|
3
3
|
def self.included(base)
|
4
|
-
base.before_process :
|
4
|
+
base.before_process :filter_post_string
|
5
5
|
end
|
6
6
|
|
7
|
-
def
|
8
|
-
if
|
9
|
-
|
10
|
-
res = RubyLess.translate("\"#{klass}\"", self)
|
11
|
-
@markup.append_dyn_param(:class, "<%= #{res} %>")
|
12
|
-
else
|
13
|
-
@markup.append_param(:class, klass)
|
14
|
-
end
|
7
|
+
def filter_post_string
|
8
|
+
if str = @params.delete(:post_string)
|
9
|
+
out_post str
|
15
10
|
end
|
16
|
-
true
|
17
11
|
end
|
18
12
|
end
|
19
13
|
end
|
data/test/node_context_test.rb
CHANGED
@@ -1,83 +1,145 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
+
class String
|
4
|
+
def underscore
|
5
|
+
gsub(/(^|.)([A-Z])/) {$1 == '' ? $2.downcase : "#{$1}_#{$2.downcase}"}
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
3
9
|
class NodeContextTest < Test::Unit::TestCase
|
4
|
-
class Page;end
|
5
|
-
class SubPage < Page; end
|
6
|
-
class Comment;end
|
7
10
|
NodeContext = Zafu::NodeContext
|
8
11
|
|
9
12
|
context 'In a blank context' do
|
10
|
-
|
11
|
-
|
13
|
+
subject do
|
14
|
+
NodeContext.new('@node', Page)
|
12
15
|
end
|
13
16
|
|
14
17
|
should 'return the current name' do
|
15
|
-
assert_equal '@node',
|
18
|
+
assert_equal '@node', subject.name
|
16
19
|
end
|
17
20
|
|
18
21
|
should 'return the current class' do
|
19
|
-
assert_equal Page,
|
22
|
+
assert_equal Page, subject.klass
|
20
23
|
end
|
21
|
-
|
24
|
+
|
22
25
|
should 'return true on will_be with the same class' do
|
23
|
-
assert
|
26
|
+
assert subject.will_be?(Page)
|
24
27
|
end
|
25
|
-
|
28
|
+
|
26
29
|
should 'return false on will_be with a sub class' do
|
27
|
-
assert
|
30
|
+
assert !subject.will_be?(SubPage)
|
28
31
|
end
|
29
|
-
|
32
|
+
|
30
33
|
should 'return false on will_be with a different class' do
|
31
|
-
assert
|
34
|
+
assert !subject.will_be?(String)
|
32
35
|
end
|
33
36
|
|
34
37
|
should 'return self on a get for the same class' do
|
35
|
-
assert_equal
|
38
|
+
assert_equal subject.object_id, subject.get(Page).object_id
|
36
39
|
end
|
37
40
|
|
38
41
|
should 'return nil on a get for another class' do
|
39
|
-
assert_nil
|
42
|
+
assert_nil subject.get(Comment)
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'calling as_main' do
|
46
|
+
should 'build the name from the class' do
|
47
|
+
assert_equal '@page', subject.as_main.name
|
48
|
+
end
|
49
|
+
|
50
|
+
should 'return same class' do
|
51
|
+
assert_equal subject.klass, subject.as_main.klass
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'calling form_name' do
|
56
|
+
should 'return underscore name of base class' do
|
57
|
+
assert_equal 'page', subject.form_name
|
58
|
+
end
|
40
59
|
end
|
41
|
-
|
60
|
+
|
42
61
|
context 'with a sub-class' do
|
43
|
-
|
44
|
-
|
62
|
+
subject do
|
63
|
+
NodeContext.new('@node', SubPage)
|
45
64
|
end
|
46
|
-
|
65
|
+
|
47
66
|
should 'return true on will_be with the same class' do
|
48
|
-
assert
|
67
|
+
assert subject.will_be?(SubPage)
|
49
68
|
end
|
50
69
|
|
51
70
|
should 'return true on will_be with a super class' do
|
52
|
-
assert
|
71
|
+
assert subject.will_be?(Page)
|
53
72
|
end
|
54
73
|
|
55
74
|
should 'return false on will_be with a different class' do
|
56
|
-
assert
|
75
|
+
assert !subject.will_be?(String)
|
57
76
|
end
|
58
|
-
|
77
|
+
|
78
|
+
context 'calling form_name' do
|
79
|
+
should 'return underscore name of base class' do
|
80
|
+
assert_equal 'page', subject.form_name
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context 'calling as_main' do
|
85
|
+
should 'build the name from the class' do
|
86
|
+
assert_equal '@sub_page', subject.as_main.name
|
87
|
+
end
|
88
|
+
|
89
|
+
should 'return same class' do
|
90
|
+
assert_equal subject.klass, subject.as_main.klass
|
91
|
+
end
|
92
|
+
|
93
|
+
should 'return an ancestor when using after_class argument' do
|
94
|
+
subject = NodeContext.new('@node', SubSubPage)
|
95
|
+
assert_equal SubPage, subject.as_main(Page).klass
|
96
|
+
end
|
97
|
+
|
98
|
+
should 'rebuild name from ancestor when using after_class argument' do
|
99
|
+
subject = NodeContext.new('@node', SubSubPage)
|
100
|
+
assert_equal '@sub_page', subject.as_main(Page).name
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
should 'return subclass on class_name' do
|
105
|
+
assert_equal 'SubPage', subject.class_name
|
106
|
+
end
|
107
|
+
end # with a sub-class
|
108
|
+
|
109
|
+
context 'with an anonymoys sub-class' do
|
110
|
+
subject do
|
111
|
+
NodeContext.new('@node', Class.new(Page))
|
112
|
+
end
|
113
|
+
|
114
|
+
should 'return class on class_name' do
|
115
|
+
assert_equal 'Page', subject.class_name
|
116
|
+
end
|
117
|
+
end # with an anonymoys sub-class
|
59
118
|
end
|
60
119
|
|
61
120
|
context 'In a sub-context' do
|
62
121
|
setup do
|
63
122
|
@parent = NodeContext.new('@node', Page)
|
64
|
-
|
123
|
+
end
|
124
|
+
|
125
|
+
subject do
|
126
|
+
@parent.move_to('comment1', Comment)
|
65
127
|
end
|
66
128
|
|
67
129
|
should 'return the current name' do
|
68
|
-
assert_equal 'comment1',
|
130
|
+
assert_equal 'comment1', subject.name
|
69
131
|
end
|
70
132
|
|
71
133
|
should 'return the current class' do
|
72
|
-
assert_equal Comment,
|
134
|
+
assert_equal Comment, subject.klass
|
73
135
|
end
|
74
136
|
|
75
137
|
should 'return self on a get for the same class' do
|
76
|
-
assert_equal
|
138
|
+
assert_equal subject.object_id, subject.get(Comment).object_id
|
77
139
|
end
|
78
140
|
|
79
141
|
should 'return the parent on a get for the class of the parent' do
|
80
|
-
assert_equal @parent.object_id,
|
142
|
+
assert_equal @parent.object_id, subject.get(Page).object_id
|
81
143
|
end
|
82
144
|
end
|
83
145
|
|
@@ -86,56 +148,80 @@ class NodeContextTest < Test::Unit::TestCase
|
|
86
148
|
@grandgrandma = NodeContext.new('@comment', Comment)
|
87
149
|
@grandma = @grandgrandma.move_to('page', Page)
|
88
150
|
@mother = @grandma.move_to('comment1', Comment)
|
89
|
-
|
151
|
+
end
|
152
|
+
|
153
|
+
subject do
|
154
|
+
@mother.move_to('var1', String)
|
90
155
|
end
|
91
156
|
|
92
157
|
should 'return the current name' do
|
93
|
-
assert_equal 'var1',
|
158
|
+
assert_equal 'var1', subject.name
|
94
159
|
end
|
95
160
|
|
96
161
|
should 'return the current class' do
|
97
|
-
assert_equal String,
|
162
|
+
assert_equal String, subject.klass
|
98
163
|
end
|
99
164
|
|
100
165
|
should 'return the first ancestor matching class on get' do
|
101
|
-
assert_equal @mother.object_id,
|
166
|
+
assert_equal @mother.object_id, subject.get(Comment).object_id
|
102
167
|
end
|
103
168
|
|
104
169
|
should 'return nil if no ancestor matches class on get' do
|
105
|
-
assert_nil
|
170
|
+
assert_nil subject.get(Fixnum)
|
171
|
+
end
|
172
|
+
|
173
|
+
should 'return the parent on up' do
|
174
|
+
assert_equal @mother, subject.up
|
106
175
|
end
|
107
176
|
end
|
108
177
|
|
109
178
|
context 'In a sub-classes context' do
|
110
|
-
|
111
|
-
|
179
|
+
subject do
|
180
|
+
NodeContext.new('super', SubPage)
|
112
181
|
end
|
113
182
|
|
114
183
|
should 'find the current context required class is an ancestor' do
|
115
|
-
assert_equal
|
184
|
+
assert_equal subject.object_id, subject.get(Page).object_id
|
116
185
|
end
|
117
186
|
end
|
118
187
|
|
119
188
|
context 'In a list context' do
|
120
189
|
setup do
|
121
|
-
@
|
190
|
+
@grandma = NodeContext.new('@page', Page)
|
191
|
+
@mother = @grandma.move_to('@comment', Comment)
|
192
|
+
end
|
193
|
+
|
194
|
+
subject do
|
195
|
+
@mother.move_to('list', [Page])
|
122
196
|
end
|
123
197
|
|
124
198
|
should 'find the context and resolve with first' do
|
125
|
-
assert context =
|
199
|
+
assert context = subject.get(Page)
|
126
200
|
assert_equal 'list.first', context.name
|
127
201
|
assert_equal Page, context.klass
|
128
202
|
end
|
203
|
+
|
204
|
+
should 'return parent on up with class' do
|
205
|
+
assert_equal @grandma, subject.up(Page)
|
206
|
+
end
|
207
|
+
|
208
|
+
should 'return true on will_be with the same class' do
|
209
|
+
assert subject.will_be?(Page)
|
210
|
+
end
|
211
|
+
|
212
|
+
should 'return class on master_class' do
|
213
|
+
assert_equal Page, subject.master_class(ActiveRecord::Base)
|
214
|
+
end
|
129
215
|
end
|
130
216
|
|
131
217
|
context 'Generating a dom id' do
|
132
218
|
context 'in a blank context' do
|
133
|
-
|
134
|
-
|
219
|
+
subject do
|
220
|
+
NodeContext.new('@foo', Page)
|
135
221
|
end
|
136
222
|
|
137
223
|
should 'return the node name in DOM id' do
|
138
|
-
assert_equal '<%= @foo.zip %>',
|
224
|
+
assert_equal '<%= @foo.zip %>', subject.dom_id
|
139
225
|
end
|
140
226
|
end
|
141
227
|
|
@@ -144,7 +230,10 @@ class NodeContextTest < Test::Unit::TestCase
|
|
144
230
|
@a = NodeContext.new('@node', Page)
|
145
231
|
@b = NodeContext.new('var1', [Page], @a)
|
146
232
|
@c = NodeContext.new('var2', Page, @b)
|
147
|
-
|
233
|
+
end
|
234
|
+
|
235
|
+
subject do
|
236
|
+
NodeContext.new('var3', Page, @c)
|
148
237
|
end
|
149
238
|
|
150
239
|
context 'with parents as dom_scopes' do
|
@@ -154,18 +243,18 @@ class NodeContextTest < Test::Unit::TestCase
|
|
154
243
|
end
|
155
244
|
|
156
245
|
should 'use dom_scopes' do
|
157
|
-
assert_equal '<%= var1.zip %>_<%= var2.zip %>_<%= var3.zip %>',
|
246
|
+
assert_equal '<%= var1.zip %>_<%= var2.zip %>_<%= var3.zip %>', subject.dom_id
|
158
247
|
end
|
159
248
|
end
|
160
249
|
|
161
250
|
context 'with ancestors and self as dom_scopes' do
|
162
251
|
setup do
|
163
252
|
@a.dom_scope!
|
164
|
-
|
253
|
+
subject.dom_scope!
|
165
254
|
end
|
166
255
|
|
167
256
|
should 'not use self twice' do
|
168
|
-
assert_equal '<%= @node.zip %>_<%= var3.zip %>',
|
257
|
+
assert_equal '<%= @node.zip %>_<%= var3.zip %>', subject.dom_id
|
169
258
|
end
|
170
259
|
end
|
171
260
|
|
@@ -175,7 +264,7 @@ class NodeContextTest < Test::Unit::TestCase
|
|
175
264
|
end
|
176
265
|
|
177
266
|
should 'use dom_prefix' do
|
178
|
-
assert_equal 'cart_<%= var3.zip %>',
|
267
|
+
assert_equal 'cart_<%= var3.zip %>', subject.dom_id
|
179
268
|
end
|
180
269
|
end
|
181
270
|
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class OrderedHashTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context 'An OrderedHash' do
|
6
|
+
setup do
|
7
|
+
@hash = Zafu::OrderedHash.new
|
8
|
+
@hash[:a] = 1
|
9
|
+
@hash[:c] = 2
|
10
|
+
@hash[:b] = 3
|
11
|
+
end
|
12
|
+
|
13
|
+
should 'keep keys in insertion order' do
|
14
|
+
assert_equal [:a, :c, :b], @hash.keys
|
15
|
+
end
|
16
|
+
|
17
|
+
should 'list each in insertion order' do
|
18
|
+
res = []
|
19
|
+
@hash.each do |k, v|
|
20
|
+
res << v
|
21
|
+
end
|
22
|
+
assert_equal [1, 2, 3], res
|
23
|
+
end
|
24
|
+
|
25
|
+
should 'remove entry on delete' do
|
26
|
+
@hash.delete(:c)
|
27
|
+
assert_equal [:a, :b], @hash.keys
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'running through keys' do
|
31
|
+
should 'allow key alteration' do
|
32
|
+
@hash.keys.each do |k|
|
33
|
+
assert k != :d
|
34
|
+
@hash[:d] = 'x'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'running each' do
|
40
|
+
should 'allow key alteration' do
|
41
|
+
@hash.each do |k, v|
|
42
|
+
assert k != :d
|
43
|
+
@hash[:d] = 'x'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'with a duplicate' do
|
49
|
+
setup do
|
50
|
+
@dup = @hash.dup
|
51
|
+
end
|
52
|
+
|
53
|
+
should 'not alter duplicate on set' do
|
54
|
+
@hash[:d] = 4
|
55
|
+
assert_equal [:a, :c, :b], @dup.keys
|
56
|
+
end
|
57
|
+
|
58
|
+
should 'not alter duplicate on change' do
|
59
|
+
@hash[:a] = 10
|
60
|
+
assert_equal 1, @dup[:a]
|
61
|
+
end
|
62
|
+
|
63
|
+
should 'not alter duplicate on delete' do
|
64
|
+
@hash.delete(:a)
|
65
|
+
assert_equal [:a, :c, :b], @dup.keys
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|