masterview 0.0.17 → 0.1.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.
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ currentPath = File.dirname(__FILE__)
5
+ require File.join( currentPath, '../lib/masterview' )
6
+ require File.join( currentPath, '../lib/masterview/directives/import')
7
+
8
+ class TestImport < Test::Unit::TestCase
9
+ include MasterView::Directives
10
+
11
+ def setup
12
+ @directives = MasterView::DirectiveSet.new
13
+ end
14
+
15
+ def test_import
16
+ import_tag = MasterView::Tag.new(@directives, 'bar', {}, :normal, nil)
17
+ @directives.directives = []
18
+ attr_value = 'foo/bar'
19
+ @directives << Import.new(attr_value)
20
+ dcs = @directives.determine_dcs(:stag)
21
+ dcs.context = import_tag.create_context
22
+ assert_equal nil, dcs.render
23
+
24
+ dcs = @directives.determine_dcs(:etag)
25
+ dcs.context = import_tag.create_context
26
+ assert_equal nil, dcs.render
27
+ end
28
+
29
+ end
@@ -11,7 +11,7 @@ class TestTemplateFileWatcher < Test::Unit::TestCase
11
11
  MVFilenamePattern = '*.html'
12
12
  TmpOutputDir = File.join(CurrentPath, '../tmp/views')
13
13
 
14
- MVProductFile = File.join(CurrentPath, '../examples/product.html')
14
+ MVProductFile = File.expand_path File.join(CurrentPath, '../examples/product.html')
15
15
 
16
16
  def setup
17
17
  FileUtils.remove_dir(TmpOutputDir, true)
@@ -0,0 +1,344 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ currentPath = File.dirname(__FILE__)
5
+ require File.join( currentPath, '../lib/masterview' )
6
+
7
+ class TestTemplateSpec < Test::Unit::TestCase
8
+ CurrentPath = File.dirname(__FILE__)
9
+ MasterViewHTMLFile = File.join(CurrentPath, '../examples/product.html')
10
+ MasterViewHTMLImportFile = File.join(CurrentPath, '../examples/test.import')
11
+
12
+ def setup
13
+ end
14
+
15
+ def test_scan
16
+ content_hash = {}
17
+ template = <<-END
18
+ <html mv:generate="layout/foo.rhtml">
19
+ <body>
20
+ <div mv:generate="bar/baz.rhtml">
21
+ <div mv:gen_render=":partial => 'cat/foo'">
22
+ Hello
23
+ </div>
24
+ </div>
25
+ </body>
26
+ </html>
27
+ END
28
+ spec = MasterView::TemplateSpec.scan_template(template, 'hello', content_hash)
29
+ assert_equal MasterView::TemplateSpec::Status::OK, spec.status
30
+ assert_equal '', spec.message
31
+ assert_equal %w{ bar/baz.rhtml cat/_foo.rhtml layout/foo.rhtml }, spec.gen_parts
32
+ end
33
+
34
+ def test_badxhtml
35
+ content_hash = {}
36
+ template = <<-END
37
+ <html mv:generate="layout/foo.rhtml">
38
+ </breakthisxhtml>
39
+ <body>
40
+ <div mv:generate="bar/baz.rhtml">
41
+ <div mv:gen_render=":partial => 'cat/foo'">
42
+ Hello
43
+ </div>
44
+ </div>
45
+ </body>
46
+ </html>
47
+ END
48
+ spec = MasterView::TemplateSpec.scan_template(template, 'hello', content_hash)
49
+ assert_equal MasterView::TemplateSpec::Status::InvalidXHTML, spec.status
50
+ assert_not_equal '', spec.message
51
+ assert_equal [], spec.gen_parts
52
+ end
53
+
54
+ def test_conflicts
55
+ content_hash = {}
56
+ template = <<-END
57
+ <html mv:generate="layout/foo.rhtml">
58
+ <body>
59
+ <div mv:generate="bar/baz.rhtml">
60
+ <div mv:gen_render=":partial => 'cat/foo'">
61
+ Hello
62
+ </div>
63
+ </div>
64
+ </body>
65
+ </html>
66
+ END
67
+ spec1 = MasterView::TemplateSpec.scan_template(template, 'hello', content_hash)
68
+ template2 = <<-END
69
+ <html mv:generate="layout/foo.rhtml">
70
+ <body>
71
+ <div mv:import="bar/baz.rhtml">
72
+ <div mv:gen_render=":partial => 'cat/foo'">
73
+ Hello
74
+ </div>
75
+ </div>
76
+ </body>
77
+ </html>
78
+ END
79
+ spec = MasterView::TemplateSpec.scan_template(template2, 'world', content_hash)
80
+ assert_equal MasterView::TemplateSpec::Status::Conflicts, spec.status
81
+ assert_not_equal '', spec.message
82
+ assert_equal %w{ cat/_foo.rhtml layout/foo.rhtml }, spec.gen_parts
83
+ end
84
+
85
+ def test_imports_not_outdated
86
+ content_hash = {}
87
+ template1 = <<-END
88
+ <html mv:import="layout/foo.rhtml">
89
+ <body>
90
+ <div mv:import="bar/baz.rhtml">
91
+ <div mv:import_render=":partial => 'cat/foo'">
92
+ Hello
93
+ </div>
94
+ </div>
95
+ </body>
96
+ </html>
97
+ END
98
+ spec1 = MasterView::TemplateSpec.scan_template(template1, 'hello', content_hash)
99
+ template2 = <<-END
100
+ <html mv:generate="layout/foo.rhtml">
101
+ <body>
102
+ <div mv:generate="bar/baz.rhtml">
103
+ <div mv:gen_render=":partial => 'cat/foo'">
104
+ Hello
105
+ </div>
106
+ </div>
107
+ </body>
108
+ </html>
109
+ END
110
+ spec2 = MasterView::TemplateSpec.scan_template(template2, 'world', content_hash)
111
+
112
+ invalid_parts = MasterView::TemplateSpec.template_out_of_sync?(template1, content_hash)
113
+ spec1.update_status_from_invalid_parts(invalid_parts)
114
+ assert_equal [], invalid_parts
115
+ assert_equal MasterView::TemplateSpec::Status::OK, spec1.status
116
+ assert_equal '', spec1.message
117
+ assert_equal [], spec1.gen_parts
118
+
119
+ invalid_parts = MasterView::TemplateSpec.template_out_of_sync?(template2, content_hash)
120
+ spec2.update_status_from_invalid_parts(invalid_parts)
121
+ assert_equal [], invalid_parts
122
+ assert_equal MasterView::TemplateSpec::Status::OK, spec2.status
123
+ assert_equal '', spec2.message
124
+ assert_equal %w{ bar/baz.rhtml cat/_foo.rhtml layout/foo.rhtml }, spec2.gen_parts
125
+ end
126
+
127
+ def test_imports_outdated
128
+ content_hash = {}
129
+ template1 = <<-END
130
+ <html mv:import="layout/foo.rhtml">
131
+ <body>
132
+ This should make it outdated
133
+ <div mv:import="bar/baz.rhtml">
134
+ <div mv:import_render=":partial => 'cat/foo'">
135
+ Hello this will also make this outdated
136
+ </div>
137
+ </div>
138
+ </body>
139
+ </html>
140
+ END
141
+ spec1 = MasterView::TemplateSpec.scan_template(template1, 'hello', content_hash)
142
+ template2 = <<-END
143
+ <html mv:generate="layout/foo.rhtml">
144
+ <body>
145
+ <div mv:generate="bar/baz.rhtml">
146
+ <div mv:gen_render=":partial => 'cat/foo'">
147
+ Hello
148
+ </div>
149
+ </div>
150
+ </body>
151
+ </html>
152
+ END
153
+ spec2 = MasterView::TemplateSpec.scan_template(template2, 'world', content_hash)
154
+
155
+ invalid_parts = MasterView::TemplateSpec.template_out_of_sync?(template1, content_hash)
156
+ spec1.update_status_from_invalid_parts(invalid_parts)
157
+ assert_equal %w{ cat/_foo.rhtml layout/foo.rhtml }, invalid_parts
158
+ assert_equal MasterView::TemplateSpec::Status::ImportsOutdated, spec1.status
159
+ assert_equal 'Outdated parts: cat/_foo.rhtml, layout/foo.rhtml', spec1.message
160
+ assert_equal [], spec1.gen_parts
161
+
162
+ invalid_parts = MasterView::TemplateSpec.template_out_of_sync?(template2, content_hash)
163
+ spec2.update_status_from_invalid_parts(invalid_parts)
164
+ assert_equal [], invalid_parts
165
+ assert_equal MasterView::TemplateSpec::Status::OK, spec2.status
166
+ assert_equal '', spec2.message
167
+ assert_equal %w{ bar/baz.rhtml cat/_foo.rhtml layout/foo.rhtml }, spec2.gen_parts
168
+ end
169
+
170
+ def test_rebuild_template
171
+ content_hash = {}
172
+ template1 = <<-END
173
+ <html mv:import="layout/foo.rhtml">
174
+ <body>
175
+ This should make it outdated
176
+ <div mv:import="bar/baz.rhtml">
177
+ <div mv:import_render=":partial => 'cat/foo'">
178
+ Hello this will also make this outdated
179
+ </div>
180
+ </div>
181
+ </body>
182
+ </html>
183
+ END
184
+ spec1 = MasterView::TemplateSpec.scan_template(template1, 'hello', content_hash)
185
+ template2 = <<-END
186
+ <html mv:generate="layout/foo.rhtml">
187
+ <body>
188
+ <div mv:generate="bar/baz.rhtml">
189
+ <div mv:gen_render=":partial => 'cat/foo'">
190
+ Hello
191
+ </div>
192
+ </div>
193
+ </body>
194
+ </html>
195
+ END
196
+ spec2 = MasterView::TemplateSpec.scan_template(template2, 'world', content_hash)
197
+
198
+ invalid_parts = MasterView::TemplateSpec.template_out_of_sync?(template1, content_hash)
199
+ spec1.update_status_from_invalid_parts(invalid_parts)
200
+ assert_equal %w{ cat/_foo.rhtml layout/foo.rhtml }, invalid_parts
201
+ assert_equal MasterView::TemplateSpec::Status::ImportsOutdated, spec1.status
202
+ assert_equal 'Outdated parts: cat/_foo.rhtml, layout/foo.rhtml', spec1.message
203
+ assert_equal [], spec1.gen_parts
204
+
205
+ expected_rebuilt_template = <<-END
206
+ <html mv:import="layout/foo.rhtml">
207
+ <body>
208
+ <div mv:import="bar/baz.rhtml">
209
+ <div mv:import_render=":partial => 'cat/foo'">
210
+ Hello
211
+ </div>
212
+ </div>
213
+ </body>
214
+ </html>
215
+ END
216
+
217
+ rebuilt_template = spec1.rebuild_template(content_hash)
218
+ assert_equal expected_rebuilt_template.strip, rebuilt_template
219
+ end
220
+
221
+ # test the creation of an empty shell using simply the source and action inferring the rest
222
+ def test_create_empty_shell_for_action
223
+ source = <<-END
224
+ <html mv:generate="layout/foo.rhtml">
225
+ <body>
226
+ <div mv:generate="foo/bar.rhtml">
227
+ <div mv:gen_render=":partial => 'foo/messages'">
228
+ Hello
229
+ </div>
230
+ </div>
231
+ </body>
232
+ </html>
233
+ END
234
+ source.strip!
235
+
236
+ empty_erb = <<-END
237
+ <div id="<%= @controller_file_name %>_<%= @action_name %>" mv:generate="<%= @controller_view_dir_name %>/<%= @action_name %>.rhtml">
238
+ controller_file_name=<%= @controller_file_name %>
239
+ </div>
240
+ END
241
+ empty_erb.strip!
242
+
243
+ expected_result = <<-END
244
+ <html mv:import="layout/foo.rhtml">
245
+ <body>
246
+ <div id="foo_cat" mv:generate="foo/cat.rhtml">
247
+ controller_file_name=foo
248
+ </div>
249
+ </body>
250
+ </html>
251
+ END
252
+
253
+ src_path = 'foo_bar.html'
254
+ content_hash = {}
255
+ template_spec_to_copy_from = MasterView::TemplateSpec.scan_template(source, src_path, content_hash) # setup content_hash since not getting from dir
256
+ options = { :template_source => source, :content_hash => content_hash }
257
+ result = MasterView::TemplateSpec.create_empty_shell_for_action(src_path, 'cat', empty_erb, options)
258
+ assert_equal expected_result.strip, result
259
+ end
260
+
261
+ # test the creation of an empty shell using simply the source and action inferring the rest, src_path = app/views/masterview/foo_bar.html
262
+ def test_create_empty_shell_for_action_full_path
263
+ source = <<-END
264
+ <html mv:generate="layout/foo.rhtml">
265
+ <body>
266
+ <div mv:generate="foo/bar.rhtml">
267
+ <div mv:gen_render=":partial => 'foo/messages'">
268
+ Hello
269
+ </div>
270
+ </div>
271
+ </body>
272
+ </html>
273
+ END
274
+ source.strip!
275
+
276
+ empty_erb = <<-END
277
+ <div id="<%= @controller_file_name %>_<%= @action_name %>" mv:generate="<%= @controller_view_dir_name %>/<%= @action_name %>.rhtml">
278
+ controller_file_name=<%= @controller_file_name %>
279
+ </div>
280
+ END
281
+ empty_erb.strip!
282
+
283
+ expected_result = <<-END
284
+ <html mv:import="layout/foo.rhtml">
285
+ <body>
286
+ <div id="foo_cat" mv:generate="foo/cat.rhtml">
287
+ controller_file_name=foo
288
+ </div>
289
+ </body>
290
+ </html>
291
+ END
292
+
293
+ src_path = 'app/views/masterview/foo_bar.html'
294
+ content_hash = {}
295
+ template_spec_to_copy_from = MasterView::TemplateSpec.scan_template(source, src_path, content_hash) # setup content_hash since not getting from dir
296
+ options = { :template_source => source, :content_hash => content_hash }
297
+ result = MasterView::TemplateSpec.create_empty_shell_for_action(src_path, 'cat', empty_erb, options)
298
+ assert_equal expected_result.strip, result
299
+ end
300
+
301
+ # test the creation of an empty shell using simply the source and action inferring the rest, src_path = foo_bar
302
+ def test_create_empty_shell_for_action_no_ext
303
+ source = <<-END
304
+ <html mv:generate="layout/foo.rhtml">
305
+ <body>
306
+ <div mv:generate="foo/bar.rhtml">
307
+ <div mv:gen_render=":partial => 'foo/messages'">
308
+ Hello
309
+ </div>
310
+ </div>
311
+ </body>
312
+ </html>
313
+ END
314
+ source.strip!
315
+
316
+ empty_erb = <<-END
317
+ <div id="<%= @controller_file_name %>_<%= @action_name %>" mv:generate="<%= @controller_view_dir_name %>/<%= @action_name %>.rhtml">
318
+ controller_file_name=<%= @controller_file_name %>
319
+ </div>
320
+ END
321
+ empty_erb.strip!
322
+
323
+ expected_result = <<-END
324
+ <html mv:import="layout/foo.rhtml">
325
+ <body>
326
+ <div id="foo_cat" mv:generate="foo/cat.rhtml">
327
+ controller_file_name=foo
328
+ </div>
329
+ </body>
330
+ </html>
331
+ END
332
+
333
+ src_path = 'foo_bar'
334
+ content_hash = {}
335
+ template_spec_to_copy_from = MasterView::TemplateSpec.scan_template(source, src_path, content_hash) # setup content_hash since not getting from dir
336
+ options = { :template_source => source, :content_hash => content_hash }
337
+ result = MasterView::TemplateSpec.create_empty_shell_for_action(src_path, 'cat', empty_erb, options)
338
+ assert_equal expected_result.strip, result
339
+ end
340
+
341
+
342
+ end
343
+
344
+
@@ -59,6 +59,22 @@ class TestTemplate < Test::Unit::TestCase
59
59
  assert_template_result expected, template
60
60
  end
61
61
 
62
+ def test_multi_gen_render
63
+ template = <<-END
64
+ <div mv:generate='foo/bar'>
65
+ <span mv:replace="h product[:price]">foo bar</span>
66
+ <div mv:gen_render=":partial => 'baz/caz'">
67
+ <span mv:content="h product[:name]">hello world</span>
68
+ </div>
69
+ </div>
70
+ END
71
+ expected = {
72
+ 'foo/bar' => "<div><%= h product[:price] %><%= render( :partial => 'baz/caz' ) %></div>",
73
+ 'baz/_caz.rhtml' => "<div><span><%= h product[:name] %></span></div>"
74
+ }
75
+ assert_template_result expected, template
76
+ end
77
+
62
78
  def test_multi_spec_dir
63
79
  template = <<-END
64
80
  <div mv:generate='foo/bar'>
@@ -215,4 +231,64 @@ class TestTemplate < Test::Unit::TestCase
215
231
  assert_template_result expected, template
216
232
  end
217
233
 
234
+ def test_import
235
+ template = <<-END
236
+ <div mv:import='foo/bar'>
237
+ <span mv:replace="h product[:price]">foo bar</span>
238
+ </div>
239
+ END
240
+ expected = { }
241
+ assert_template_result expected, template
242
+ end
243
+
244
+ def test_import2
245
+ template = <<-END
246
+ <div mv:import='foo/bar'>
247
+ <div mv:generate='cat/dog'>Hello World</div>
248
+ </div>
249
+ END
250
+ expected = {
251
+ 'cat/dog' => "<div>Hello World</div>"
252
+ }
253
+ assert_template_result expected, template
254
+ end
255
+
256
+ def test_import3
257
+ template = <<-END
258
+ <div mv:generate='foo/bar'>
259
+ Hello
260
+ <div mv:import='cat/dog'>
261
+ Clown
262
+ <div mv:generate='egg/flower'>
263
+ Wow
264
+ </div>
265
+ </div>
266
+ </div>
267
+ END
268
+ expected = {
269
+ 'egg/flower' => "<div>Wow </div>",
270
+ 'foo/bar' => "<div>Hello </div>"
271
+ }
272
+ assert_template_result expected, template
273
+ end
274
+
275
+ def test_import_render
276
+ template = <<-END
277
+ <div mv:generate='foo/bar'>
278
+ Hello
279
+ <div mv:import_render=":partial => 'cat/dog'">
280
+ Clown
281
+ <div mv:generate='egg/flower'>
282
+ Wow
283
+ </div>
284
+ </div>
285
+ </div>
286
+ END
287
+ expected = {
288
+ 'foo/bar' => "<div>Hello <%= render( :partial => 'cat/dog' ) %></div>",
289
+ 'egg/flower' => "<div>Wow </div>"
290
+ }
291
+ assert_template_result expected, template
292
+ end
293
+
218
294
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: masterview
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.17
7
- date: 2006-05-04 00:00:00 -05:00
6
+ version: 0.1.0
7
+ date: 2006-05-29 00:00:00 -05:00
8
8
  summary: A (x)html friendly template engine for rails with the power of layouts, and partials.
9
9
  require_paths:
10
10
  - lib
@@ -49,6 +49,8 @@ files:
49
49
  - lib/masterview/directive_base.rb
50
50
  - lib/masterview/masterview_version.rb
51
51
  - lib/masterview/parser.rb
52
+ - lib/masterview/template_spec.rb
53
+ - lib/masterview/analyzer.rb
52
54
  - lib/masterview/directives/global_inline_erb.rb
53
55
  - lib/masterview/directives/link_to_if.rb
54
56
  - lib/masterview/directives/preview.rb
@@ -63,6 +65,7 @@ files:
63
65
  - lib/masterview/directives/elsif.rb
64
66
  - lib/masterview/directives/form.rb
65
67
  - lib/masterview/directives/submit.rb
68
+ - lib/masterview/directives/import.rb
66
69
  - lib/masterview/directives/insert_generated_comment.rb
67
70
  - lib/masterview/directives/stylesheet_link.rb
68
71
  - lib/masterview/directives/javascript_include.rb
@@ -71,8 +74,18 @@ files:
71
74
  - lib/masterview/directives/replace.rb
72
75
  - lib/masterview/directives/text_area.rb
73
76
  - lib/masterview/directives/attr.rb
77
+ - lib/masterview/directives/import_render.rb
78
+ - lib/masterview/extras/app
74
79
  - lib/masterview/extras/rails_init.rb
75
80
  - lib/masterview/extras/watcher.rb
81
+ - lib/masterview/extras/app/controllers
82
+ - lib/masterview/extras/app/views
83
+ - lib/masterview/extras/app/controllers/masterview_controller.rb
84
+ - lib/masterview/extras/app/views/masterview
85
+ - lib/masterview/extras/app/views/masterview/admin
86
+ - lib/masterview/extras/app/views/masterview/admin/create.rhtml
87
+ - lib/masterview/extras/app/views/masterview/admin/empty.rhtml
88
+ - lib/masterview/extras/app/views/masterview/admin/list.rhtml
76
89
  - test/run_parser_test.rb
77
90
  - test/test_helper.rb
78
91
  - test/template_file_watcher_test.rb
@@ -96,8 +109,11 @@ files:
96
109
  - test/content_test.rb
97
110
  - test/replace_test.rb
98
111
  - test/template_test.rb
112
+ - test/template_spec_test.rb
99
113
  - test/link_to_if_test.rb
114
+ - test/import_test.rb
100
115
  - test/attr_test.rb
116
+ - test/import_render_test.rb
101
117
  - CHANGELOG
102
118
  - Rakefile
103
119
  - RELEASE_NOTES