masterview 0.1.5 → 0.2.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.
Files changed (105) hide show
  1. data/CHANGELOG +17 -0
  2. data/README +36 -504
  3. data/RELEASE_NOTES +126 -45
  4. data/Rakefile +215 -86
  5. data/TODO +8 -3
  6. data/doc/configuration.html +485 -0
  7. data/doc/directives.html +1085 -0
  8. data/doc/guide.html +243 -0
  9. data/doc/index.html +287 -0
  10. data/doc/installation.html +376 -0
  11. data/doc/stylesheets/masterview.css +206 -0
  12. data/doc/stylesheets/mv-config.css +23 -0
  13. data/doc/stylesheets/mv-directives.css +18 -0
  14. data/doc/stylesheets/mv-installation.css +10 -0
  15. data/doc/troubleshooting.html +18 -0
  16. data/examples/product.html +256 -0
  17. data/examples/product.html.old +107 -0
  18. data/examples/rails_app_config/masterview/environment/development.rb +22 -0
  19. data/examples/rails_app_config/masterview/environment/production.rb +9 -0
  20. data/examples/rails_app_config/masterview/settings.rb +59 -0
  21. data/examples/test.import +80 -0
  22. data/init.rb +26 -12
  23. data/lib/masterview/analyzer.rb +25 -15
  24. data/lib/masterview/directive_base.rb +4 -0
  25. data/lib/masterview/directive_helpers.rb +7 -5
  26. data/lib/masterview/directives/import_render.rb +6 -0
  27. data/lib/masterview/directives/insert_generated_comment.rb +8 -8
  28. data/lib/masterview/extras/app/controllers/masterview_controller.rb +154 -2
  29. data/lib/masterview/extras/app/views/masterview/admin/create.rhtml +4 -4
  30. data/lib/masterview/extras/app/views/masterview/admin/empty.rhtml +1 -1
  31. data/lib/masterview/extras/app/views/masterview/admin/list.rhtml +14 -9
  32. data/lib/masterview/extras/app/views/masterview/admin/view_rhtml.rhtml +70 -0
  33. data/lib/masterview/extras/init_logger.rb +102 -0
  34. data/lib/masterview/extras/init_rails_erb_mv_direct.rb +117 -0
  35. data/lib/masterview/extras/init_rails_reparse_checking.rb +59 -0
  36. data/lib/masterview/extras/watcher.rb +17 -23
  37. data/lib/masterview/filter_helpers.rb +26 -0
  38. data/lib/masterview/initializer.rb +912 -0
  39. data/lib/masterview/io.rb +352 -0
  40. data/lib/masterview/keyword_expander.rb +116 -0
  41. data/lib/masterview/masterview_version.rb +2 -2
  42. data/lib/masterview/mtime_tracking_hash.rb +44 -0
  43. data/lib/masterview/parser.rb +64 -92
  44. data/lib/masterview/pathname_extensions.rb +33 -0
  45. data/lib/masterview/template_spec.rb +49 -56
  46. data/lib/masterview.rb +40 -85
  47. data/test/fixtures/configs/fake_rails_app_with_config/config/masterview/environments/development.rb +12 -0
  48. data/test/fixtures/configs/fake_rails_app_with_config/config/masterview/environments/production.rb +11 -0
  49. data/test/fixtures/configs/fake_rails_app_with_config/config/masterview/settings.rb +23 -0
  50. data/test/fixtures/templates/product.html +256 -0
  51. data/test/fixtures/templates/test.import +80 -0
  52. data/test/test_helper.rb +5 -3
  53. data/test/tmp/template/foo.txt +1 -0
  54. data/test/tmp/templates_src/product.html +256 -0
  55. data/test/tmp/views/layouts/product.rhtml +35 -0
  56. data/test/tmp/views/product/_form.rhtml +30 -0
  57. data/test/tmp/views/product/_product.rhtml +14 -0
  58. data/test/tmp/views/product/_show.rhtml +27 -0
  59. data/test/tmp/views/product/destroy.rhtml +27 -0
  60. data/test/tmp/views/product/edit.rhtml +26 -0
  61. data/test/tmp/views/product/list.rhtml +31 -0
  62. data/test/tmp/views/product/new.rhtml +29 -0
  63. data/test/tmp/views/product/show.rhtml +16 -0
  64. data/test/unit/config_settings_test.rb +172 -0
  65. data/test/{attr_test.rb → unit/directive_attr_test.rb} +2 -2
  66. data/test/{block_test.rb → unit/directive_block_test.rb} +2 -2
  67. data/test/{content_test.rb → unit/directive_content_test.rb} +2 -2
  68. data/test/{else_test.rb → unit/directive_else_test.rb} +2 -2
  69. data/test/{elsif_test.rb → unit/directive_elsif_test.rb} +2 -2
  70. data/test/{form_test.rb → unit/directive_form_test.rb} +2 -2
  71. data/test/{global_inline_erb_test.rb → unit/directive_global_inline_erb_test.rb} +2 -2
  72. data/test/{hidden_field_test.rb → unit/directive_hidden_field_test.rb} +2 -2
  73. data/test/{if_test.rb → unit/directive_if_test.rb} +2 -2
  74. data/test/unit/directive_import_render_test.rb +62 -0
  75. data/test/{import_test.rb → unit/directive_import_test.rb} +2 -2
  76. data/test/{javascript_include_test.rb → unit/directive_javascript_include_test.rb} +2 -2
  77. data/test/{link_to_if_test.rb → unit/directive_link_to_if_test.rb} +2 -2
  78. data/test/{link_to_test.rb → unit/directive_link_to_test.rb} +2 -2
  79. data/test/{omit_tag_test.rb → unit/directive_omit_tag_test.rb} +2 -2
  80. data/test/{password_field_test.rb → unit/directive_password_field_test.rb} +2 -2
  81. data/test/{replace_test.rb → unit/directive_replace_test.rb} +2 -2
  82. data/test/{stylesheet_link_test.rb → unit/directive_stylesheet_link_test.rb} +2 -2
  83. data/test/{submit_test.rb → unit/directive_submit_test.rb} +2 -2
  84. data/test/{text_area_test.rb → unit/directive_text_area_test.rb} +2 -2
  85. data/test/{text_field_test.rb → unit/directive_text_field_test.rb} +2 -2
  86. data/test/{example_test.rb → unit/example_test.rb} +1 -1
  87. data/test/unit/file_mio_test.rb +368 -0
  88. data/test/{filter_helpers_test.rb → unit/filter_helpers_test.rb} +1 -1
  89. data/test/unit/keyword_expander_test.rb +95 -0
  90. data/test/unit/mio_test.rb +110 -0
  91. data/test/unit/mtime_string_hash_mio_tree_test.rb +289 -0
  92. data/test/unit/mtime_tracking_hash_test.rb +38 -0
  93. data/test/{parser_test.rb → unit/parser_test.rb} +19 -1
  94. data/test/unit/pathname_extensions_test.rb +46 -0
  95. data/test/{run_parser_test.rb → unit/run_parser_test.rb} +7 -3
  96. data/test/unit/string_hash_mio_test.rb +320 -0
  97. data/test/unit/template_file_watcher_test.rb +107 -0
  98. data/test/{template_spec_test.rb → unit/template_spec_test.rb} +57 -21
  99. data/test/{template_test.rb → unit/template_test.rb} +123 -22
  100. data/test/xtras/config-mv-logger_config.rb +109 -0
  101. data/test/xtras/config_initialize_standalone.rb +53 -0
  102. metadata +111 -38
  103. data/lib/masterview/extras/rails_init.rb +0 -72
  104. data/test/import_render_test.rb +0 -30
  105. data/test/template_file_watcher_test.rb +0 -50
@@ -0,0 +1,368 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ currentPath = File.dirname(__FILE__)
5
+ require File.join( currentPath, '../../lib/masterview/io' )
6
+
7
+ class TestFileMIO < Test::Unit::TestCase
8
+ include MasterView
9
+
10
+ MVTestDir = File.expand_path( File.join(File.dirname(__FILE__), '..' ) )
11
+ TemplateDir = "#{MVTestDir}/tmp/template"
12
+ TemplateErbDir = "#{MVTestDir}/tmp/erb"
13
+
14
+ TestFileMIOTemplatePathname = Pathname.new(TemplateDir)
15
+ ErbPathname = Pathname.new(TemplateErbDir)
16
+
17
+ HelloWorldPath = 'hello_world.txt'
18
+ HelloWorldFullPath = "#{TemplateDir}/hello_world.txt"
19
+ TestWritePath = 'foo.txt'
20
+ TestWriteFullPath = "#{TemplateDir}/foo.txt"
21
+ TestWritePathname = Pathname.new(TestWriteFullPath)
22
+
23
+ IOMgr = MIOTrees.new
24
+
25
+ def setup
26
+ IOMgr.template = FileMIOTree.new(TemplateDir, '.html')
27
+ IOMgr.erb = FileMIOTree.new(TemplateErbDir, '.rhtml' )
28
+ IOMgr.file = FileMIOTree.new()
29
+
30
+ TestFileMIOTemplatePathname.rmtree if TestFileMIOTemplatePathname.exist?
31
+ ErbPathname.rmtree if ErbPathname.exist?
32
+ TestFileMIOTemplatePathname.mkpath
33
+ ErbPathname.mkpath
34
+ end
35
+
36
+ #------------------------------------------------------------------------------
37
+ # Test Cases
38
+ #------------------------------------------------------------------------------
39
+
40
+ # ensure that sandbox limits writing to files outside of root path even if dot dot exists in path
41
+ def test_sandbox_dotdot
42
+ assert_raise(InvalidPathError){ f = IOMgr.template.path( '../bad') }
43
+ assert_raise(InvalidPathError){ f = IOMgr.template.path( 'bad/../dog/../../foo') }
44
+ assert_raise(InvalidPathError){ f = IOMgr.template.path( 'bad/../../foo') }
45
+ assert_raise(InvalidPathError){ f = IOMgr.template.path( 'bad/cat/../../../dog') }
46
+ assert_raise(InvalidPathError){ f = IOMgr.template.path( '/bad/foo') }
47
+ assert_raise(InvalidPathError){ f = IOMgr.template.path( '/bad') }
48
+ assert_raise(InvalidPathError){ f = IOMgr.template.path( '../bad.cat') }
49
+ assert_raise(InvalidPathError){ f = IOMgr.template.path( 'bad/../dot/../../foo.cat') }
50
+ assert_raise(InvalidPathError){ f = IOMgr.template.path( 'bad/../../foo.cat') }
51
+ assert_raise(InvalidPathError){ f = IOMgr.template.path( 'bad/cat/../../../dog.cat') }
52
+ assert_raise(InvalidPathError){ f = IOMgr.template.path( '/bad/foo.cat') }
53
+ assert_raise(InvalidPathError){ f = IOMgr.template.path( '/bad.cat') }
54
+ end
55
+
56
+ def test_create_foo
57
+ verify_mio_handler_paths( 'foo', IOMgr.template, TemplateDir )
58
+ end
59
+
60
+ def test_create_bar
61
+ verify_mio_handler_paths( 'bar', IOMgr.erb, TemplateErbDir )
62
+ end
63
+
64
+ def test_create_cat
65
+ verify_mio_handler_paths( 'cat', IOMgr.file, Pathname.getwd.to_str )
66
+ end
67
+
68
+ def test_create_foo_w_ext
69
+ verify_mio_handler_paths( 'foo.txt', IOMgr.template, TemplateDir )
70
+ end
71
+
72
+ def test_create_parts
73
+ verify_mio_handler_paths( 'sub/one/two/three/foo.txt', IOMgr.template, TemplateDir )
74
+ end
75
+
76
+ def test_read
77
+ TestFileMIOTemplatePathname.mkpath unless TestFileMIOTemplatePathname.exist?
78
+
79
+ file_content = "hello\nworld"
80
+ # write to abs pathname, ensure handler resolves rel pathname properly
81
+ File.open( HelloWorldFullPath, 'w' ){ |file| file.write(file_content) }
82
+ verify_mio_handler_read( HelloWorldPath, HelloWorldFullPath, file_content, IOMgr.template )
83
+ end
84
+
85
+ def test_read_disable_cache
86
+ TestFileMIOTemplatePathname.mkpath unless TestFileMIOTemplatePathname.exist?
87
+
88
+ file_content = "hello\nworld"
89
+ # write to abs pathname, ensure handler resolves rel pathname properly
90
+ File.open( HelloWorldFullPath, 'w' ){ |file| file.write(file_content) }
91
+ verify_mio_handler_read( HelloWorldPath, HelloWorldFullPath, file_content, IOMgr.template )
92
+
93
+ file_content_changed = "foo\nbar"
94
+ File.open( HelloWorldFullPath, 'w' ){ |file| file.write(file_content_changed) }
95
+ #verify_mio_handler_read( HelloWorldPath, file_content, IOMgr.template ) # still hitting cache #todo turn this on when caching is ready for testing
96
+ verify_mio_handler_read_no_cache( HelloWorldPath, HelloWorldFullPath, file_content_changed, IOMgr.template )
97
+ end
98
+
99
+ def test_write_string
100
+ TestWritePathname.delete if TestWritePathname.exist?
101
+
102
+ file_content = "foo\nbar"
103
+ IOMgr.template.path( TestWritePath ).write(file_content)
104
+ verify_mio_handler_read( TestWritePath, TestWriteFullPath, file_content, IOMgr.template )
105
+ end
106
+
107
+ def test_write_strings
108
+ TestWritePathname.delete if TestWritePathname.exist?
109
+
110
+ file_content = "foo\nbar"
111
+ IOMgr.template.path( TestWritePath ).write(file_content)
112
+ verify_mio_handler_read( TestWritePath, TestWriteFullPath, file_content, IOMgr.template )
113
+ end
114
+
115
+ def test_write_block
116
+ TestWritePathname.delete if TestWritePathname.exist?
117
+
118
+ file_content = "hello"
119
+ IOMgr.template.path( TestWritePath ).write { |f| f.write(file_content) }
120
+ verify_mio_handler_read( TestWritePath, TestWriteFullPath, file_content, IOMgr.template )
121
+ end
122
+
123
+ def test_write_strings_and_block
124
+ TestWritePathname.delete if TestWritePathname.exist?
125
+
126
+ file_content_strings = [ 'hello', 'world']
127
+ file_content = file_content_strings.join('')
128
+ IOMgr.template.path( TestWritePath).write do |f|
129
+ file_content_strings.each { |str| f.write(str) }
130
+ end
131
+ verify_mio_handler_read( TestWritePath, TestWriteFullPath, file_content, IOMgr.template )
132
+ end
133
+
134
+ def test_write_mkpath
135
+ TestFileMIOTemplatePathname.rmtree if TestFileMIOTemplatePathname.exist?
136
+
137
+ file_content = "foo\nbar"
138
+ IOMgr.template.path( TestWritePath ).write(file_content)
139
+ verify_mio_handler_read( TestWritePath, TestWriteFullPath, file_content, IOMgr.template )
140
+ end
141
+
142
+ def test_exist
143
+ file_content = "foo"
144
+
145
+ TestFileMIOTemplatePathname.rmtree if TestFileMIOTemplatePathname.exist?
146
+ assert_equal false, IOMgr.template.path( TestWritePath).exist?
147
+ IOMgr.template.path( TestWritePath).write(file_content)
148
+ assert_equal true, IOMgr.template.path( TestWritePath).exist?
149
+
150
+ TestWritePathname.delete if TestWritePathname.exist?
151
+ assert_equal false, IOMgr.template.path( TestWritePath).exist?
152
+ IOMgr.template.path( TestWritePath).write(file_content)
153
+ assert_equal true, IOMgr.template.path( TestWritePath).exist?
154
+ end
155
+
156
+ def test_identical
157
+ file_content = "hello\nworld"
158
+ file_content_foo = "foo"
159
+
160
+ TestWritePathname.delete if TestWritePathname.exist?
161
+ assert_equal false, IOMgr.template.path( TestWritePath ).identical?(file_content)
162
+ TestFileMIOTemplatePathname.mkpath unless TestFileMIOTemplatePathname.exist?
163
+ File.open(TestWriteFullPath, 'w'){ |file| file.write(file_content) }
164
+ assert_equal true, IOMgr.template.path( TestWritePath).identical?(file_content)
165
+ assert_equal false, IOMgr.template.path( TestWritePath).identical?("foo")
166
+ end
167
+
168
+ def test_mtime
169
+ file_content = "hello\nworld"
170
+
171
+ TestWritePathname.delete if TestWritePathname.exist?
172
+ TestFileMIOTemplatePathname.mkpath unless TestFileMIOTemplatePathname.exist?
173
+ File.open(TestWriteFullPath, 'w'){ |file| file.write(file_content) }
174
+ assert_equal TestWritePathname.mtime, IOMgr.template.path( TestWritePath).mtime
175
+ end
176
+
177
+ def test_findfiles_single_dir
178
+ TestFileMIOTemplatePathname.rmtree if TestFileMIOTemplatePathname.exist?
179
+ IOMgr.template.path( 'apple.txt').write('foo')
180
+ IOMgr.template.path( 'bar.txt').write('foo')
181
+ File.open(TestFileMIOTemplatePathname+'baz.txt', 'w'){ |file| file.write('foo') }
182
+ found = IOMgr.template.find
183
+ assert_equal 3, found.length
184
+ assert_equal FileMIO, found[0].class
185
+ assert_equal FileMIO, found[1].class
186
+ assert_equal FileMIO, found[2].class
187
+ assert_equal (TestFileMIOTemplatePathname+'apple.txt').to_s, found[0].full_pathname.to_s
188
+ assert_equal 'apple.txt', found[0].pathname.to_s
189
+ assert_equal 'bar.txt', found[1].pathname.to_s
190
+ assert_equal 'baz.txt', found[2].pathname.to_s
191
+ end
192
+
193
+ def test_findfiles_single_sub_dir
194
+ TestFileMIOTemplatePathname.rmtree if TestFileMIOTemplatePathname.exist?
195
+ IOMgr.template.path( 'sub/apple.txt').write('foo')
196
+ IOMgr.template.path( 'sub/bar.txt').write('foo')
197
+ File.open(TestFileMIOTemplatePathname+'sub/baz.txt', 'w'){ |file| file.write('foo') }
198
+ found = IOMgr.template.find(:path => 'sub')
199
+ assert_equal 3, found.length
200
+ assert_equal FileMIO, found[0].class
201
+ assert_equal FileMIO, found[1].class
202
+ assert_equal FileMIO, found[2].class
203
+ assert_equal (TestFileMIOTemplatePathname+'sub/apple.txt').to_s, found[0].full_pathname.to_s
204
+ assert_equal 'sub/apple.txt', found[0].pathname.to_s
205
+ assert_equal 'sub/bar.txt', found[1].pathname.to_s
206
+ assert_equal 'sub/baz.txt', found[2].pathname.to_s
207
+ end
208
+
209
+ def test_findfiles_single_sub2_dir_multi_arg
210
+ TestFileMIOTemplatePathname.rmtree if TestFileMIOTemplatePathname.exist?
211
+ IOMgr.template.path( 'sub/two/apple.txt').write('foo')
212
+ IOMgr.template.path( 'sub/two/bar.txt').write('foo')
213
+ File.open(TestFileMIOTemplatePathname+'sub/two/baz.txt', 'w'){ |file| file.write('foo') }
214
+ found = IOMgr.template.find(:path => 'sub/two')
215
+ assert_equal 3, found.length
216
+ assert_equal FileMIO, found[0].class
217
+ assert_equal FileMIO, found[1].class
218
+ assert_equal FileMIO, found[2].class
219
+ assert_equal (TestFileMIOTemplatePathname+'sub/two/apple.txt').to_s, found[0].full_pathname.to_s
220
+ assert_equal 'sub/two/apple.txt', found[0].pathname.to_s
221
+ assert_equal 'sub/two/bar.txt', found[1].pathname.to_s
222
+ assert_equal 'sub/two/baz.txt', found[2].pathname.to_s
223
+ end
224
+
225
+ def test_findfiles_single_sub2_dir_single_arg
226
+ TestFileMIOTemplatePathname.rmtree if TestFileMIOTemplatePathname.exist?
227
+ IOMgr.template.path( 'sub/two/apple.txt').write('foo')
228
+ IOMgr.template.path( 'sub/two/bar.txt').write('foo')
229
+ File.open(TestFileMIOTemplatePathname+'sub/two/baz.txt', 'w'){ |file| file.write('foo') }
230
+ found = IOMgr.template.find(:path => 'sub/two')
231
+ assert_equal 3, found.length
232
+ assert_equal FileMIO, found[0].class
233
+ assert_equal FileMIO, found[1].class
234
+ assert_equal FileMIO, found[2].class
235
+ assert_equal (TestFileMIOTemplatePathname+'sub/two/apple.txt').to_s, found[0].full_pathname.to_s
236
+ assert_equal 'sub/two/apple.txt', found[0].pathname.to_s
237
+ assert_equal 'sub/two/bar.txt', found[1].pathname.to_s
238
+ assert_equal 'sub/two/baz.txt', found[2].pathname.to_s
239
+ end
240
+
241
+ def test_findfiles_single_dir_pattern
242
+ TestFileMIOTemplatePathname.rmtree if TestFileMIOTemplatePathname.exist?
243
+ IOMgr.template.path( 'sub/two/apple.txt').write('foo')
244
+ IOMgr.template.path( 'sub/two/bar.log').write('foo')
245
+ File.open(TestFileMIOTemplatePathname+'sub/two/baz.txt', 'w'){ |file| file.write('foo') }
246
+ found = IOMgr.template.find(:path => 'sub/two', :pattern => '*.txt')
247
+ assert_equal 2, found.length
248
+ assert_equal FileMIO, found[0].class
249
+ assert_equal FileMIO, found[1].class
250
+ assert_equal (TestFileMIOTemplatePathname+'sub/two/apple.txt').to_s, found[0].full_pathname.to_s
251
+ assert_equal 'sub/two/apple.txt', found[0].pathname.to_s
252
+ assert_equal 'sub/two/baz.txt', found[1].pathname.to_s
253
+ end
254
+
255
+ def test_findfiles_multi_dir_root
256
+ TestFileMIOTemplatePathname.rmtree if TestFileMIOTemplatePathname.exist?
257
+ IOMgr.template.path( 'one/two/three.txt').write('foo')
258
+ IOMgr.template.path( 'sub/two/apple.txt').write('foo')
259
+ IOMgr.template.path( 'sub/two/bar.log').write('foo')
260
+ File.open(TestFileMIOTemplatePathname+'sub/two/baz.txt', 'w'){ |file| file.write('foo') }
261
+ found = IOMgr.template.find
262
+ assert_equal 4, found.length
263
+ assert_equal FileMIO, found[0].class
264
+ assert_equal FileMIO, found[1].class
265
+ assert_equal FileMIO, found[2].class
266
+ assert_equal FileMIO, found[3].class
267
+ assert_equal (TestFileMIOTemplatePathname+'one/two/three.txt').to_s, found[0].full_pathname.to_s
268
+ assert_equal 'one/two/three.txt', found[0].pathname.to_s
269
+ assert_equal 'sub/two/apple.txt', found[1].pathname.to_s
270
+ assert_equal 'sub/two/bar.log', found[2].pathname.to_s
271
+ assert_equal 'sub/two/baz.txt', found[3].pathname.to_s
272
+ end
273
+
274
+ def test_findfiles_multi_dir_pattern
275
+ TestFileMIOTemplatePathname.rmtree if TestFileMIOTemplatePathname.exist?
276
+ IOMgr.template.path( 'one/two/three.txt').write('foo')
277
+ IOMgr.template.path( 'sub/two/apple.txt').write('foo')
278
+ IOMgr.template.path( 'sub/two/bar.log').write('foo')
279
+ File.open(TestFileMIOTemplatePathname+'sub/two/baz.txt', 'w'){ |file| file.write('foo') }
280
+ found = IOMgr.template.find(:pattern => '*.txt')
281
+ assert_equal 3, found.length
282
+ assert_equal FileMIO, found[0].class
283
+ assert_equal FileMIO, found[1].class
284
+ assert_equal FileMIO, found[2].class
285
+ assert_equal (TestFileMIOTemplatePathname+'one/two/three.txt').to_s, found[0].full_pathname.to_s
286
+ assert_equal 'one/two/three.txt', found[0].pathname.to_s
287
+ assert_equal 'sub/two/apple.txt', found[1].pathname.to_s
288
+ assert_equal 'sub/two/baz.txt', found[2].pathname.to_s
289
+ end
290
+
291
+ def test_findfiles_multi_dir_pattern_deep
292
+ TestFileMIOTemplatePathname.rmtree if TestFileMIOTemplatePathname.exist?
293
+ IOMgr.template.path( 'one/two/three.txt').write('foo')
294
+ IOMgr.template.path( 'sub/two/apple.txt').write('foo')
295
+ IOMgr.template.path( 'sub/two/bar.log').write('foo')
296
+ File.open(TestFileMIOTemplatePathname+'sub/two/baz.txt', 'w'){ |file| file.write('foo') }
297
+ found = IOMgr.template.find(:path => 'sub/two', :pattern => '*.txt')
298
+ assert_equal 2, found.length
299
+ assert_equal FileMIO, found[0].class
300
+ assert_equal FileMIO, found[1].class
301
+ assert_equal (TestFileMIOTemplatePathname+'sub/two/apple.txt').to_s, found[0].full_pathname.to_s
302
+ assert_equal 'sub/two/apple.txt', found[0].pathname.to_s
303
+ assert_equal 'sub/two/baz.txt', found[1].pathname.to_s
304
+ end
305
+
306
+ def test_findfiles_multi_dir_pattern_deep_with_block
307
+ TestFileMIOTemplatePathname.rmtree if TestFileMIOTemplatePathname.exist?
308
+ IOMgr.template.path( 'one/two/three.txt').write('foo')
309
+ IOMgr.template.path( 'sub/two/apple.txt').write('foo')
310
+ IOMgr.template.path( 'sub/two/bar.log').write('foo')
311
+ File.open(TestFileMIOTemplatePathname+'sub/two/baz.txt', 'w'){ |file| file.write('foo') }
312
+ array_of_mio = []
313
+ found = IOMgr.template.find(:path => 'sub/two', :pattern => '*.txt'){ |mio| array_of_mio << mio }
314
+ assert_equal 2, found.length
315
+ assert_equal FileMIO, found[0].class
316
+ assert_equal FileMIO, found[1].class
317
+ assert_equal (TestFileMIOTemplatePathname+'sub/two/apple.txt').to_s, found[0].full_pathname.to_s
318
+ assert_equal 'sub/two/apple.txt', found[0].pathname.to_s
319
+ assert_equal 'sub/two/baz.txt', found[1].pathname.to_s
320
+ assert_equal 2, array_of_mio.length
321
+ assert_kind_of FileMIO, array_of_mio[0]
322
+ assert_kind_of FileMIO, array_of_mio[1]
323
+ assert_equal 'sub/two/apple.txt', array_of_mio[0].pathname.to_s
324
+ assert_equal 'sub/two/baz.txt', array_of_mio[1].pathname.to_s
325
+ end
326
+
327
+ #------------------------------------------------------------------------------
328
+ # Test helpers
329
+ #------------------------------------------------------------------------------
330
+
331
+ # verify that an mio_handler for files anchored on a particular root_directory
332
+ # produces the expected file reference paths for a relative path within that space
333
+ def verify_mio_handler_paths( rel_path, mio_handler, root_directory )
334
+ assert_equal root_directory, mio_handler.to_str
335
+
336
+ file_path = mio_handler.path( rel_path )
337
+ assert_equal FileMIO, file_path.class
338
+ assert_equal rel_path, file_path.pathname.to_s
339
+ assert_equal "#{root_directory}/#{rel_path}", file_path.full_pathname.to_s
340
+ end
341
+
342
+ # verify that the file mio_handler reads the expected file content
343
+ def verify_mio_handler_read( rel_path, file_abs_path, file_content, mio_handler )
344
+
345
+ # verify the actual file contents are as expected
346
+ assert_equal file_abs_path, "#{mio_handler.to_str}/#{rel_path}"
347
+ assert_equal file_content, File.read( file_abs_path )
348
+
349
+ # verify that the file MIO handler obtains the expected content
350
+ file_path = mio_handler.path( rel_path )
351
+ assert_equal file_abs_path, file_path.to_str
352
+ assert_equal file_content, file_path.read
353
+ end
354
+
355
+ # verify that the file mio_handler reads the expected file content
356
+ def verify_mio_handler_read_no_cache( rel_path, file_abs_path, file_content, mio_handler )
357
+
358
+ # verify the actual file contents are as expected
359
+ assert_equal file_abs_path, "#{mio_handler.to_str}/#{rel_path}"
360
+ #???assert_equal file_content, File.read( file_abs_path )
361
+
362
+ # verify that the file MIO handler obtains the expected content
363
+ file_path = mio_handler.path( rel_path )
364
+ assert_equal file_abs_path, file_path.to_str
365
+ assert_equal file_content, file_path.read(:disable_cache => true)
366
+ end
367
+
368
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'test/unit'
4
4
  currentPath = File.dirname(__FILE__)
5
- require File.join( currentPath, '../lib/masterview' )
5
+ require File.join( currentPath, '../../lib/masterview' )
6
6
 
7
7
  class TestDirectiveHelpers < Test::Unit::TestCase
8
8
  include MasterView::Directives
@@ -0,0 +1,95 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ currentPath = File.dirname(__FILE__)
5
+ require File.join( currentPath, '../../lib/facets/core/string/starts_with' )
6
+ require File.join( currentPath, '../../lib/masterview/pathname_extensions' )
7
+ require File.join( currentPath, '../../lib/masterview/keyword_expander' )
8
+
9
+ class TestKeywordExpander < Test::Unit::TestCase
10
+ include MasterView
11
+
12
+ def test_ke
13
+ ke = KeywordExpander.new 'FOO' => 'bar', 'CAT' => 'dog'
14
+ ke.set('HELLO', 'world')
15
+ ke.set('FOO_MAN', 'foo_man')
16
+ ke.set('FOO_MAN_CHU', 'fmc')
17
+ ke.set('FOO_HELLO', 'foo_hello')
18
+ ke.set('ONE_HELLO', 'one_hello')
19
+ assert_equal 'bar', ke['FOO']
20
+ assert_equal 'dog', ke['CAT']
21
+ assert_equal 'nosub', ke.resolveAttrAndDelete( {:a => 'nosub'}, :a)
22
+ assert_equal 'world', ke.resolveAttrAndDelete( {:a => 'HELLO'}, :a)
23
+ assert_equal 'world', ke.resolveAttrAndDelete( {'a' => 'HELLO'}, 'a')
24
+ assert_equal 'bar this', ke.resolveAttrAndDelete( {:a => 'FOO this'}, :a)
25
+ assert_equal 'bar/this.rhtml', ke.resolveAttrAndDelete( {:a => 'FOO/this.rhtml'}, :a)
26
+ assert_equal 'foo/bar.rhtml', ke.resolveAttrAndDelete( {:a => 'foo/FOO.rhtml'}, :a)
27
+ assert_equal 'bar', ke.resolveAttrAndDelete( {:a => 'FOO'}, :a)
28
+ assert_equal 'dog', ke.resolveAttrAndDelete( {:a => 'CAT'}, :a)
29
+ assert_equal 'bar/dog.rhtml', ke.resolveAttrAndDelete( {:a => 'FOO/CAT.rhtml'}, :a)
30
+ assert_equal 'bar/dog/foo_man.rhtml', ke.resolveAttrAndDelete( {:a => 'FOO/CAT/FOO_MAN.rhtml'}, :a)
31
+ assert_equal 'one_hello/dog/foo_man/world.rhtml', ke.resolveAttrAndDelete( {:a => 'ONE_HELLO/CAT/FOO_MAN/HELLO.rhtml'}, :a)
32
+ assert_equal 'barbarbar', ke.resolveAttrAndDelete( {:a => 'FOOFOOFOO'}, :a)
33
+ assert_equal 'bar_bar_bar', ke.resolveAttrAndDelete( {:a => 'FOO_FOO_FOO'}, :a)
34
+ assert_equal nil, ke.resolveAttrAndDelete( {:a => 'HELLO'}, :not_found)
35
+ end
36
+
37
+ def test_ke_expand_keywords
38
+ ke = KeywordExpander.new 'FOO' => 'bar', 'CAT' => 'dog'
39
+ assert_equal nil, ke.expand_keywords(nil)
40
+ assert_equal 'bar', ke.expand_keywords('FOO')
41
+ assert_equal 'barbarbar', ke.expand_keywords('FOOFOOFOO')
42
+ assert_equal 'bardogbar', ke.expand_keywords('FOOCATFOO')
43
+ assert_equal 'one/bardogbar/dog.html', ke.expand_keywords('one/FOOCATFOO/CAT.html')
44
+ end
45
+
46
+ def test_template_path
47
+ ke = KeywordExpander.new
48
+ ke.set_template_pathname('foo/bar/controller/action.html', '.rhtml')
49
+ assert_equal 'foo/bar/controller/action', ke['{template_path}']
50
+ assert_equal 'foo/bar/controller', ke['{template_dir_path}']
51
+ assert_equal 'action', ke['{template_basename}']
52
+ assert_equal '.html', ke['{extension}']
53
+ # mv:generate="{template_path}" expands to include default output extension
54
+ assert_equal 'foo/bar/controller/action.rhtml', ke.expand_keywords('{template_path}')
55
+ # mv:generate="{template_path}.xxx" expands to respect explicitly-specified output extension
56
+ assert_equal 'foo/bar/controller/action.xxx', ke.expand_keywords('{template_path}.xxx')
57
+ end
58
+
59
+ def test_template_path_baseonly
60
+ ke = KeywordExpander.new
61
+ ke.set_template_pathname('foo_bar', '.rhtml')
62
+ assert_equal 'foo_bar', ke['{template_path}']
63
+ assert_equal '', ke['{template_dir_path}']
64
+ assert_equal 'foo_bar', ke['{template_basename}']
65
+ assert_equal '', ke['{extension}']
66
+ # mv:generate="{template_path}" vs. mv:generate="{template_path}.xxx"
67
+ assert_equal 'foo_bar.rhtml', ke.expand_keywords('{template_path}')
68
+ assert_equal 'foo_bar.xxx', ke.expand_keywords('{template_path}.xxx')
69
+ end
70
+
71
+ def test_template_path_cont_action
72
+ ke = KeywordExpander.new
73
+ ke.set_template_pathname('controller/action', '.rhtml')
74
+ assert_equal 'controller/action', ke['{template_path}']
75
+ assert_equal 'controller', ke['{template_dir_path}']
76
+ assert_equal 'action', ke['{template_basename}']
77
+ assert_equal '', ke['{extension}']
78
+ # mv:generate="{template_path}" vs. mv:generate="{template_path}.xxx"
79
+ assert_equal 'controller/action.rhtml', ke.expand_keywords('{template_path}')
80
+ assert_equal 'controller/action.xxx', ke.expand_keywords('{template_path}.xxx')
81
+ end
82
+
83
+ def test_template_path_action_only
84
+ ke = KeywordExpander.new
85
+ ke.set_template_pathname('action', '.rhtml')
86
+ assert_equal 'action', ke['{template_path}']
87
+ assert_equal '', ke['{template_dir_path}']
88
+ assert_equal 'action', ke['{template_basename}']
89
+ assert_equal '', ke['{extension}']
90
+ # mv:generate="{template_path}" vs. mv:generate="{template_path}.xxx"
91
+ assert_equal 'action.rhtml', ke.expand_keywords('{template_path}')
92
+ assert_equal 'action.xxx', ke.expand_keywords('{template_path}.xxx')
93
+ end
94
+
95
+ end
@@ -0,0 +1,110 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ currentPath = File.dirname(__FILE__)
5
+ require File.join( currentPath, '../../lib/masterview/io' )
6
+
7
+ class TestMIO < Test::Unit::TestCase
8
+
9
+ MVTestDir = File.expand_path( File.join(File.dirname(__FILE__), '..' ) )
10
+ TemplateDir = "#{MVTestDir}/tmp/template"
11
+ TemplateErbDir = "#{MVTestDir}/tmp/erb"
12
+
13
+ FileMIOTemplatePathname = Pathname.new(TemplateDir)
14
+ FileMIOTemplateDefaultExtension = '.html'
15
+ ErbPathname = Pathname.new(TemplateErbDir)
16
+ ErbDefaultExtension = '.rhtml'
17
+
18
+ CatDogPath = 'cat/dog.html'
19
+ # HelloWorldFullPath = "#{TemplateDir}/hello_world.txt"
20
+ HelloWorldPath = 'hello_world.txt'
21
+ # TestWritePath = 'foo.txt'
22
+ # TestWriteFullPath = "#{TemplateDir}/foo.txt"
23
+ # TestWritePathname = Pathname.new(TestWriteFullPath)
24
+
25
+ def setup
26
+ @mio = MasterView::MIOTrees.new
27
+ @mio.foo = MasterView::FileMIOTree.new(FileMIOTemplatePathname, ErbDefaultExtension) #??just use TemplateDir??
28
+ @mio.bar = MasterView::FileMIOTree.new(ErbPathname, ErbDefaultExtension) #??just use TemplateErbDir??
29
+ @mio.baz = MasterView::StringHashMIOTree.new
30
+ @mio.msh = MasterView::MTimeStringHashMIOTree.new
31
+ @mio.rec = MasterView::RailsErbCacheMIOTree.new
32
+ end
33
+
34
+ def test_mio_setup
35
+ assert_kind_of(MasterView::FileMIOTree, @mio.foo)
36
+ assert_kind_of(MasterView::FileMIOTree, @mio.bar)
37
+ assert_kind_of(MasterView::StringHashMIOTree, @mio.baz)
38
+ assert_kind_of(MasterView::MTimeStringHashMIOTree, @mio.msh)
39
+ assert_kind_of(MasterView::RailsErbCacheMIOTree, @mio.rec)
40
+ assert_nil(@mio.not_there)
41
+ assert_equal(FileMIOTemplatePathname.to_s, @mio.foo.to_s)
42
+ assert_equal(ErbPathname.to_s, @mio.bar.to_s)
43
+ end
44
+
45
+ def test_mio_filemiotree_interface
46
+ assert(@mio.foo.respond_to?(:path))
47
+ assert(@mio.foo.respond_to?(:find))
48
+ assert(@mio.foo.respond_to?(:cleanup_path_get_relative_pathname))
49
+ end
50
+
51
+ def test_mio_stringmiotree_interface
52
+ assert(@mio.baz.respond_to?(:path))
53
+ assert(@mio.baz.respond_to?(:find))
54
+ assert(@mio.baz.respond_to?(:cleanup_path_get_relative_pathname))
55
+ end
56
+
57
+ def test_mio_mtime_stringmiotree_interface
58
+ assert(@mio.msh.respond_to?(:path))
59
+ assert(@mio.msh.respond_to?(:find))
60
+ assert(@mio.msh.respond_to?(:cleanup_path_get_relative_pathname))
61
+ end
62
+
63
+ def test_mio_rec_miotree_interface
64
+ assert(@mio.rec.respond_to?(:path))
65
+ assert(@mio.rec.respond_to?(:find))
66
+ assert(@mio.rec.respond_to?(:cleanup_path_get_relative_pathname))
67
+ end
68
+
69
+ def test_mio_filemio_interface
70
+ assert(@mio.foo.path(CatDogPath).respond_to?(:pathname))
71
+ assert(@mio.foo.path(CatDogPath).respond_to?(:full_pathname))
72
+ assert(@mio.foo.path(CatDogPath).respond_to?(:read))
73
+ assert(@mio.foo.path(CatDogPath).respond_to?(:write))
74
+ assert(@mio.foo.path(CatDogPath).respond_to?(:exist?))
75
+ assert(@mio.foo.path(CatDogPath).respond_to?(:identical?))
76
+ assert(@mio.foo.path(CatDogPath).respond_to?(:mtime))
77
+ end
78
+
79
+ def test_mio_stringmio_interface
80
+ assert(@mio.baz.path(CatDogPath).respond_to?(:pathname))
81
+ assert(@mio.baz.path(CatDogPath).respond_to?(:full_pathname))
82
+ assert(@mio.baz.path(CatDogPath).respond_to?(:read))
83
+ assert(@mio.baz.path(CatDogPath).respond_to?(:write))
84
+ assert(@mio.baz.path(CatDogPath).respond_to?(:exist?))
85
+ assert(@mio.baz.path(CatDogPath).respond_to?(:identical?))
86
+ assert(@mio.baz.path(CatDogPath).respond_to?(:mtime))
87
+ end
88
+
89
+ def test_mio_mtime_stringmio_interface
90
+ assert(@mio.msh.path(CatDogPath).respond_to?(:pathname))
91
+ assert(@mio.msh.path(CatDogPath).respond_to?(:full_pathname))
92
+ assert(@mio.msh.path(CatDogPath).respond_to?(:read))
93
+ assert(@mio.msh.path(CatDogPath).respond_to?(:write))
94
+ assert(@mio.msh.path(CatDogPath).respond_to?(:exist?))
95
+ assert(@mio.msh.path(CatDogPath).respond_to?(:identical?))
96
+ assert(@mio.msh.path(CatDogPath).respond_to?(:mtime))
97
+ end
98
+
99
+ def test_mio_rec_mio_interface
100
+ assert(@mio.rec.path(CatDogPath).respond_to?(:pathname))
101
+ assert(@mio.rec.path(CatDogPath).respond_to?(:full_pathname))
102
+ assert(@mio.rec.path(CatDogPath).respond_to?(:read))
103
+ assert(@mio.rec.path(CatDogPath).respond_to?(:write))
104
+ assert(@mio.rec.path(CatDogPath).respond_to?(:exist?))
105
+ assert(@mio.rec.path(CatDogPath).respond_to?(:identical?))
106
+ assert(@mio.rec.path(CatDogPath).respond_to?(:mtime))
107
+ end
108
+
109
+ end
110
+