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.
- data/CHANGELOG +17 -0
- data/README +36 -504
- data/RELEASE_NOTES +126 -45
- data/Rakefile +215 -86
- data/TODO +8 -3
- data/doc/configuration.html +485 -0
- data/doc/directives.html +1085 -0
- data/doc/guide.html +243 -0
- data/doc/index.html +287 -0
- data/doc/installation.html +376 -0
- data/doc/stylesheets/masterview.css +206 -0
- data/doc/stylesheets/mv-config.css +23 -0
- data/doc/stylesheets/mv-directives.css +18 -0
- data/doc/stylesheets/mv-installation.css +10 -0
- data/doc/troubleshooting.html +18 -0
- data/examples/product.html +256 -0
- data/examples/product.html.old +107 -0
- data/examples/rails_app_config/masterview/environment/development.rb +22 -0
- data/examples/rails_app_config/masterview/environment/production.rb +9 -0
- data/examples/rails_app_config/masterview/settings.rb +59 -0
- data/examples/test.import +80 -0
- data/init.rb +26 -12
- data/lib/masterview/analyzer.rb +25 -15
- data/lib/masterview/directive_base.rb +4 -0
- data/lib/masterview/directive_helpers.rb +7 -5
- data/lib/masterview/directives/import_render.rb +6 -0
- data/lib/masterview/directives/insert_generated_comment.rb +8 -8
- data/lib/masterview/extras/app/controllers/masterview_controller.rb +154 -2
- data/lib/masterview/extras/app/views/masterview/admin/create.rhtml +4 -4
- data/lib/masterview/extras/app/views/masterview/admin/empty.rhtml +1 -1
- data/lib/masterview/extras/app/views/masterview/admin/list.rhtml +14 -9
- data/lib/masterview/extras/app/views/masterview/admin/view_rhtml.rhtml +70 -0
- data/lib/masterview/extras/init_logger.rb +102 -0
- data/lib/masterview/extras/init_rails_erb_mv_direct.rb +117 -0
- data/lib/masterview/extras/init_rails_reparse_checking.rb +59 -0
- data/lib/masterview/extras/watcher.rb +17 -23
- data/lib/masterview/filter_helpers.rb +26 -0
- data/lib/masterview/initializer.rb +912 -0
- data/lib/masterview/io.rb +352 -0
- data/lib/masterview/keyword_expander.rb +116 -0
- data/lib/masterview/masterview_version.rb +2 -2
- data/lib/masterview/mtime_tracking_hash.rb +44 -0
- data/lib/masterview/parser.rb +64 -92
- data/lib/masterview/pathname_extensions.rb +33 -0
- data/lib/masterview/template_spec.rb +49 -56
- data/lib/masterview.rb +40 -85
- data/test/fixtures/configs/fake_rails_app_with_config/config/masterview/environments/development.rb +12 -0
- data/test/fixtures/configs/fake_rails_app_with_config/config/masterview/environments/production.rb +11 -0
- data/test/fixtures/configs/fake_rails_app_with_config/config/masterview/settings.rb +23 -0
- data/test/fixtures/templates/product.html +256 -0
- data/test/fixtures/templates/test.import +80 -0
- data/test/test_helper.rb +5 -3
- data/test/tmp/template/foo.txt +1 -0
- data/test/tmp/templates_src/product.html +256 -0
- data/test/tmp/views/layouts/product.rhtml +35 -0
- data/test/tmp/views/product/_form.rhtml +30 -0
- data/test/tmp/views/product/_product.rhtml +14 -0
- data/test/tmp/views/product/_show.rhtml +27 -0
- data/test/tmp/views/product/destroy.rhtml +27 -0
- data/test/tmp/views/product/edit.rhtml +26 -0
- data/test/tmp/views/product/list.rhtml +31 -0
- data/test/tmp/views/product/new.rhtml +29 -0
- data/test/tmp/views/product/show.rhtml +16 -0
- data/test/unit/config_settings_test.rb +172 -0
- data/test/{attr_test.rb → unit/directive_attr_test.rb} +2 -2
- data/test/{block_test.rb → unit/directive_block_test.rb} +2 -2
- data/test/{content_test.rb → unit/directive_content_test.rb} +2 -2
- data/test/{else_test.rb → unit/directive_else_test.rb} +2 -2
- data/test/{elsif_test.rb → unit/directive_elsif_test.rb} +2 -2
- data/test/{form_test.rb → unit/directive_form_test.rb} +2 -2
- data/test/{global_inline_erb_test.rb → unit/directive_global_inline_erb_test.rb} +2 -2
- data/test/{hidden_field_test.rb → unit/directive_hidden_field_test.rb} +2 -2
- data/test/{if_test.rb → unit/directive_if_test.rb} +2 -2
- data/test/unit/directive_import_render_test.rb +62 -0
- data/test/{import_test.rb → unit/directive_import_test.rb} +2 -2
- data/test/{javascript_include_test.rb → unit/directive_javascript_include_test.rb} +2 -2
- data/test/{link_to_if_test.rb → unit/directive_link_to_if_test.rb} +2 -2
- data/test/{link_to_test.rb → unit/directive_link_to_test.rb} +2 -2
- data/test/{omit_tag_test.rb → unit/directive_omit_tag_test.rb} +2 -2
- data/test/{password_field_test.rb → unit/directive_password_field_test.rb} +2 -2
- data/test/{replace_test.rb → unit/directive_replace_test.rb} +2 -2
- data/test/{stylesheet_link_test.rb → unit/directive_stylesheet_link_test.rb} +2 -2
- data/test/{submit_test.rb → unit/directive_submit_test.rb} +2 -2
- data/test/{text_area_test.rb → unit/directive_text_area_test.rb} +2 -2
- data/test/{text_field_test.rb → unit/directive_text_field_test.rb} +2 -2
- data/test/{example_test.rb → unit/example_test.rb} +1 -1
- data/test/unit/file_mio_test.rb +368 -0
- data/test/{filter_helpers_test.rb → unit/filter_helpers_test.rb} +1 -1
- data/test/unit/keyword_expander_test.rb +95 -0
- data/test/unit/mio_test.rb +110 -0
- data/test/unit/mtime_string_hash_mio_tree_test.rb +289 -0
- data/test/unit/mtime_tracking_hash_test.rb +38 -0
- data/test/{parser_test.rb → unit/parser_test.rb} +19 -1
- data/test/unit/pathname_extensions_test.rb +46 -0
- data/test/{run_parser_test.rb → unit/run_parser_test.rb} +7 -3
- data/test/unit/string_hash_mio_test.rb +320 -0
- data/test/unit/template_file_watcher_test.rb +107 -0
- data/test/{template_spec_test.rb → unit/template_spec_test.rb} +57 -21
- data/test/{template_test.rb → unit/template_test.rb} +123 -22
- data/test/xtras/config-mv-logger_config.rb +109 -0
- data/test/xtras/config_initialize_standalone.rb +53 -0
- metadata +111 -38
- data/lib/masterview/extras/rails_init.rb +0 -72
- data/test/import_render_test.rb +0 -30
- data/test/template_file_watcher_test.rb +0 -50
@@ -0,0 +1,320 @@
|
|
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 TestStringHashMIO < 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
|
+
HelloWorldPath = 'hello_world.txt'
|
15
|
+
#HelloWorldFullPath = "#{TemplateDir}/hello_world.txt"
|
16
|
+
TestWritePath = 'foo.txt'
|
17
|
+
#TestWriteFullPath = "#{TemplateDir}/foo.txt"
|
18
|
+
#TestWritePathname = Pathname.new(TestWriteFullPath)
|
19
|
+
|
20
|
+
IOMgr = MIOTrees.new
|
21
|
+
|
22
|
+
def setup
|
23
|
+
@template_hash = {}
|
24
|
+
@erb_hash = {}
|
25
|
+
@file_hash = {}
|
26
|
+
IOMgr.template = StringHashMIOTree.new(@template_hash, '.html')
|
27
|
+
IOMgr.erb = StringHashMIOTree.new(@erb_hash, '.rhtml' )
|
28
|
+
IOMgr.file = StringHashMIOTree.new(@file_hash)
|
29
|
+
end
|
30
|
+
|
31
|
+
#------------------------------------------------------------------------------
|
32
|
+
# Test Cases
|
33
|
+
#------------------------------------------------------------------------------
|
34
|
+
|
35
|
+
def test_create_foo
|
36
|
+
verify_mio_handler_paths( 'foo', IOMgr.template )
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_create_foo_with_useless_dots
|
40
|
+
f = IOMgr.template.path( 'foo/bar/../cat')
|
41
|
+
assert_equal StringMIO, f.class
|
42
|
+
assert_equal 'foo/cat', f.pathname.to_s
|
43
|
+
assert_equal 'foo/cat', f.full_pathname.to_s
|
44
|
+
f.write('hello')
|
45
|
+
assert @template_hash.has_key?('foo/cat')
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_create_foo_with_useless_dots2
|
49
|
+
f = IOMgr.template.path( 'foo/bar/../cat/../dog')
|
50
|
+
assert_equal StringMIO, f.class
|
51
|
+
assert_equal 'foo/dog', f.pathname.to_s
|
52
|
+
assert_equal 'foo/dog', f.full_pathname.to_s
|
53
|
+
f.write('hello')
|
54
|
+
assert @template_hash.has_key?('foo/dog')
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_create_useless_dots
|
58
|
+
f = IOMgr.template.path( '../../foo')
|
59
|
+
assert_equal StringMIO, f.class
|
60
|
+
assert_equal '../../foo', f.pathname.to_s
|
61
|
+
assert_equal '../../foo', f.full_pathname.to_s
|
62
|
+
f.write('hello')
|
63
|
+
assert @template_hash['../../foo']
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_create_bar
|
67
|
+
verify_mio_handler_paths( 'bar', IOMgr.erb )
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_create_cat
|
71
|
+
verify_mio_handler_paths( 'cat', IOMgr.file )
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_create_foo_w_ext
|
75
|
+
verify_mio_handler_paths( 'foo.txt', IOMgr.template )
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_create_parts
|
79
|
+
verify_mio_handler_paths( 'sub/one/two/three/foo.txt', IOMgr.template )
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_read
|
83
|
+
file_content = "hello\nworld"
|
84
|
+
@template_hash[HelloWorldPath] = file_content # stuff into IOMgr.template
|
85
|
+
verify_mio_handler_read( HelloWorldPath, file_content, IOMgr.template, @template_hash )
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_read_disable_cache
|
89
|
+
file_content = "hello\nworld"
|
90
|
+
@template_hash[HelloWorldPath] = file_content # stuff into IOMgr.template
|
91
|
+
verify_mio_handler_read( HelloWorldPath, file_content, IOMgr.template, @template_hash )
|
92
|
+
|
93
|
+
file_content_changed = "foo\nbar"
|
94
|
+
@template_hash[HelloWorldPath] = file_content_changed # stuff into IOMgr.template
|
95
|
+
#verify_mio_handler_read( HelloWorldPath, file_content, IOMgr.template ) #still reading from cache, #todo enable when caching module is ready for testing
|
96
|
+
verify_mio_handler_read_no_cache( HelloWorldPath, file_content_changed, IOMgr.template, @template_hash )
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_write_string
|
100
|
+
@template_hash.delete(TestWritePath)
|
101
|
+
|
102
|
+
file_content = "foo\nbar"
|
103
|
+
IOMgr.template.path( TestWritePath).write(file_content)
|
104
|
+
verify_mio_handler_read( TestWritePath, file_content, IOMgr.template, @template_hash )
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_write_block
|
108
|
+
@template_hash.delete(TestWritePath)
|
109
|
+
|
110
|
+
file_content = "hello"
|
111
|
+
IOMgr.template.path( TestWritePath).write { |f| f.write(file_content) }
|
112
|
+
verify_mio_handler_read( TestWritePath, file_content, IOMgr.template, @template_hash )
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_write_multi_block
|
116
|
+
@template_hash.delete(TestWritePath)
|
117
|
+
|
118
|
+
file_content_strings = [ 'hello', 'world']
|
119
|
+
file_content = file_content_strings.join('')
|
120
|
+
IOMgr.template.path( TestWritePath).write do |f|
|
121
|
+
file_content_strings.each { |str| f.write(str) }
|
122
|
+
end
|
123
|
+
verify_mio_handler_read( TestWritePath, file_content, IOMgr.template, @template_hash )
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_write_mkpath
|
127
|
+
@template_hash.clear
|
128
|
+
|
129
|
+
file_content = "foo\nbar"
|
130
|
+
IOMgr.template.path( TestWritePath).write(file_content)
|
131
|
+
verify_mio_handler_read( TestWritePath, file_content, IOMgr.template, @template_hash )
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_exist
|
135
|
+
@template_hash.clear
|
136
|
+
assert_equal false, IOMgr.template.path( TestWritePath ).exist?
|
137
|
+
assert @template_hash.empty?
|
138
|
+
IOMgr.template.path( TestWritePath).write("foo")
|
139
|
+
assert_equal true, IOMgr.template.path( TestWritePath).exist?
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_identical
|
143
|
+
@template_hash.clear
|
144
|
+
assert_equal false, IOMgr.template.path( TestWritePath).identical?("hello\nworld")
|
145
|
+
@template_hash[TestWritePath] = "hello\nworld"
|
146
|
+
assert_equal true, IOMgr.template.path( TestWritePath).identical?("hello\nworld")
|
147
|
+
assert_equal false, IOMgr.template.path( TestWritePath).identical?("foo")
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_findfiles_single_dir
|
151
|
+
@template_hash.clear
|
152
|
+
IOMgr.template.path( 'apple.txt').write('foo')
|
153
|
+
IOMgr.template.path( 'bar.txt').write('foo')
|
154
|
+
@template_hash[('baz.txt').to_s] = 'foo'
|
155
|
+
found = IOMgr.template.find
|
156
|
+
assert_equal 3, found.length
|
157
|
+
assert_equal StringMIO, found[0].class
|
158
|
+
assert_equal StringMIO, found[1].class
|
159
|
+
assert_equal StringMIO, found[2].class
|
160
|
+
assert_equal 'apple.txt', found[0].pathname.to_s
|
161
|
+
assert_equal 'bar.txt', found[1].pathname.to_s
|
162
|
+
assert_equal ('baz.txt').to_s, found[2].pathname.to_s
|
163
|
+
assert_equal ('baz.txt').to_s, found[2].full_pathname.to_s
|
164
|
+
end
|
165
|
+
|
166
|
+
def test_findfiles_single_sub_dir
|
167
|
+
@template_hash.clear
|
168
|
+
IOMgr.template.path( 'sub/apple.txt').write('foo')
|
169
|
+
IOMgr.template.path( 'sub/bar.txt').write('foo')
|
170
|
+
IOMgr.template.path( 'sub/baz.txt').write('foo')
|
171
|
+
found = IOMgr.template.find(:path => 'sub')
|
172
|
+
assert_equal 3, found.length
|
173
|
+
assert_equal StringMIO, found[0].class
|
174
|
+
assert_equal StringMIO, found[1].class
|
175
|
+
assert_equal StringMIO, found[2].class
|
176
|
+
assert_equal 'sub/apple.txt', found[0].pathname.to_s
|
177
|
+
assert_equal 'sub/bar.txt', found[1].pathname.to_s
|
178
|
+
assert_equal 'sub/baz.txt', found[2].pathname.to_s
|
179
|
+
end
|
180
|
+
|
181
|
+
def test_findfiles_single_sub2_dir_multi_arg
|
182
|
+
@template_hash.clear
|
183
|
+
IOMgr.template.path( 'sub/two/apple.txt').write('foo')
|
184
|
+
IOMgr.template.path( 'sub/two/bar.txt').write('foo')
|
185
|
+
IOMgr.template.path( 'sub/two/baz.txt').write { |f| f.write('foo') }
|
186
|
+
found = IOMgr.template.find(:path => 'sub/two')
|
187
|
+
assert_equal 3, found.length
|
188
|
+
assert_equal StringMIO, found[0].class
|
189
|
+
assert_equal StringMIO, found[1].class
|
190
|
+
assert_equal StringMIO, found[2].class
|
191
|
+
assert_equal 'sub/two/apple.txt', found[0].full_pathname.to_s
|
192
|
+
assert_equal 'sub/two/apple.txt', found[0].pathname.to_s
|
193
|
+
assert_equal 'sub/two/bar.txt', found[1].pathname.to_s
|
194
|
+
assert_equal 'sub/two/baz.txt', found[2].pathname.to_s
|
195
|
+
end
|
196
|
+
|
197
|
+
def test_findfiles_single_dir_pattern
|
198
|
+
@template_hash.clear
|
199
|
+
IOMgr.template.path( 'sub/two/apple.txt').write('foo')
|
200
|
+
IOMgr.template.path( 'sub/two/bar.log').write('foo')
|
201
|
+
@template_hash['sub/two/baz.txt'] = 'foo'
|
202
|
+
found = IOMgr.template.find(:path => 'sub/two', :pattern => '*.txt')
|
203
|
+
assert_equal 2, found.length
|
204
|
+
assert_equal StringMIO, found[0].class
|
205
|
+
assert_equal StringMIO, found[1].class
|
206
|
+
assert_equal 'sub/two/apple.txt', found[0].pathname.to_s
|
207
|
+
assert_equal 'sub/two/baz.txt', found[1].pathname.to_s
|
208
|
+
end
|
209
|
+
|
210
|
+
def test_findfiles_multi_dir_root
|
211
|
+
@template_hash.clear
|
212
|
+
IOMgr.template.path( 'one/two/three.txt').write('foo')
|
213
|
+
IOMgr.template.path( 'sub/two/apple.txt').write('foo')
|
214
|
+
IOMgr.template.path( 'sub/two/bar.log').write('foo')
|
215
|
+
IOMgr.template.path( 'sub/two/baz.txt').write { |f| f.write('foo') }
|
216
|
+
found = IOMgr.template.find
|
217
|
+
assert_equal 4, found.length
|
218
|
+
assert_equal StringMIO, found[0].class
|
219
|
+
assert_equal StringMIO, found[1].class
|
220
|
+
assert_equal StringMIO, found[2].class
|
221
|
+
assert_equal StringMIO, found[3].class
|
222
|
+
assert_equal 'one/two/three.txt', found[0].pathname.to_s
|
223
|
+
assert_equal 'sub/two/apple.txt', found[1].pathname.to_s
|
224
|
+
assert_equal 'sub/two/bar.log', found[2].pathname.to_s
|
225
|
+
assert_equal 'sub/two/baz.txt', found[3].pathname.to_s
|
226
|
+
end
|
227
|
+
|
228
|
+
def test_findfiles_multi_dir_pattern
|
229
|
+
@template_hash.clear
|
230
|
+
IOMgr.template.path( 'one/two/three.txt').write('foo')
|
231
|
+
IOMgr.template.path( 'sub/two/apple.txt').write('foo')
|
232
|
+
IOMgr.template.path( 'sub/two/bar.log').write('foo')
|
233
|
+
IOMgr.template.path( 'sub/two/baz.txt').write('foo')
|
234
|
+
found = IOMgr.template.find(:pattern => '*.txt')
|
235
|
+
assert_equal 3, found.length
|
236
|
+
assert_equal StringMIO, found[0].class
|
237
|
+
assert_equal StringMIO, found[1].class
|
238
|
+
assert_equal StringMIO, found[2].class
|
239
|
+
assert_equal 'one/two/three.txt', found[0].pathname.to_s
|
240
|
+
assert_equal 'sub/two/apple.txt', found[1].pathname.to_s
|
241
|
+
assert_equal 'sub/two/baz.txt', found[2].pathname.to_s
|
242
|
+
end
|
243
|
+
|
244
|
+
def test_findfiles_multi_dir_pattern_deep
|
245
|
+
@template_hash.clear
|
246
|
+
IOMgr.template.path( 'one/two/three.txt').write('foo')
|
247
|
+
IOMgr.template.path( 'sub/two/apple.txt').write('foo')
|
248
|
+
IOMgr.template.path( 'sub/two/bar.log').write('foo')
|
249
|
+
IOMgr.template.path( 'sub/two/baz.txt').write('foo')
|
250
|
+
found = IOMgr.template.find(:path => 'sub/two', :pattern => '*.txt')
|
251
|
+
assert_equal 2, found.length
|
252
|
+
assert_equal StringMIO, found[0].class
|
253
|
+
assert_equal StringMIO, found[1].class
|
254
|
+
assert_equal 'sub/two/apple.txt', found[0].pathname.to_s
|
255
|
+
assert_equal 'sub/two/baz.txt', found[1].pathname.to_s
|
256
|
+
end
|
257
|
+
|
258
|
+
def test_findfiles_multi_dir_pattern_deep_with_block
|
259
|
+
@template_hash.clear
|
260
|
+
IOMgr.template.path( 'one/two/three.txt').write('foo')
|
261
|
+
IOMgr.template.path( 'sub/two/apple.txt').write('foo')
|
262
|
+
IOMgr.template.path( 'sub/two/bar.log').write('foo')
|
263
|
+
IOMgr.template.path( 'sub/two/baz.txt').write('foo')
|
264
|
+
array_of_mio = []
|
265
|
+
found = IOMgr.template.find(:path => 'sub/two', :pattern => '*.txt'){ |mio| array_of_mio << mio }
|
266
|
+
assert_equal 2, found.length
|
267
|
+
assert_equal StringMIO, found[0].class
|
268
|
+
assert_equal StringMIO, found[1].class
|
269
|
+
assert_equal 'sub/two/apple.txt', found[0].pathname.to_s
|
270
|
+
assert_equal 'sub/two/baz.txt', found[1].pathname.to_s
|
271
|
+
assert_equal 2, array_of_mio.length
|
272
|
+
assert_kind_of StringMIO, array_of_mio[0]
|
273
|
+
assert_kind_of StringMIO, array_of_mio[1]
|
274
|
+
assert_equal 'sub/two/apple.txt', array_of_mio[0].pathname.to_s
|
275
|
+
assert_equal 'sub/two/baz.txt', array_of_mio[1].pathname.to_s
|
276
|
+
end
|
277
|
+
|
278
|
+
#------------------------------------------------------------------------------
|
279
|
+
# Test helpers
|
280
|
+
#------------------------------------------------------------------------------
|
281
|
+
|
282
|
+
# verify that a string-hash mio_handler produces the expected file reference paths
|
283
|
+
def verify_mio_handler_paths( rel_path, mio_handler )
|
284
|
+
#ISSUE: should consider supporting symmetric protocol with FileMIO (pathname)
|
285
|
+
#assert_equal '', mio_handler.to_s # this is just std object impl right now
|
286
|
+
assert_equal true, mio_handler.respond_to?(:to_s)
|
287
|
+
assert_equal false, mio_handler.respond_to?(:to_str)
|
288
|
+
|
289
|
+
file_path = mio_handler.path( rel_path )
|
290
|
+
assert_equal StringMIO, file_path.class
|
291
|
+
assert_equal rel_path, file_path.pathname.to_s
|
292
|
+
assert_equal rel_path, file_path.full_pathname.to_s
|
293
|
+
end
|
294
|
+
|
295
|
+
# verify that the string-hash mio_handler reads the expected content
|
296
|
+
def verify_mio_handler_read( rel_path, file_content, mio_handler, hash_storage )
|
297
|
+
|
298
|
+
# verify the actual hash contents are as expected
|
299
|
+
assert_equal file_content, hash_storage[rel_path]
|
300
|
+
|
301
|
+
# verify that the MIO handler obtains the expected content
|
302
|
+
file_path = mio_handler.path( rel_path )
|
303
|
+
#n/a: assert_equal rel_path, file_path.to_str
|
304
|
+
assert_equal file_content, file_path.read
|
305
|
+
assert_equal file_content, hash_storage[rel_path]
|
306
|
+
end
|
307
|
+
|
308
|
+
# verify that the string-hash mio_handler reads the expected content
|
309
|
+
def verify_mio_handler_read_no_cache( rel_path, file_content, mio_handler, hash_storage )
|
310
|
+
|
311
|
+
# verify the actual hash contents are as expected
|
312
|
+
assert_equal file_content, hash_storage[rel_path]
|
313
|
+
|
314
|
+
# verify that the MIO handler obtains the expected content
|
315
|
+
file_path = mio_handler.path( rel_path )
|
316
|
+
#n/a: assert_equal rel_path, file_path.to_str
|
317
|
+
assert_equal file_content, file_path.read(:disable_cache => true)
|
318
|
+
end
|
319
|
+
|
320
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
currentPath = File.dirname(__FILE__)
|
5
|
+
require File.join( currentPath, '../../lib/masterview' )
|
6
|
+
require 'masterview/extras/watcher.rb'
|
7
|
+
|
8
|
+
class TestTemplateWatcher < Test::Unit::TestCase
|
9
|
+
|
10
|
+
MVTestDir = File.expand_path( File.join(File.dirname(__FILE__), '..' ) )
|
11
|
+
TestFixturesDir = "#{MVTestDir}/fixtures/templates"
|
12
|
+
TemplateSrcDir = "#{MVTestDir}/tmp/templates_src"
|
13
|
+
TemplateFilenamePattern = '*.html'
|
14
|
+
TemplateDstDir = "#{MVTestDir}/tmp/views"
|
15
|
+
|
16
|
+
DEBUG_TRACE = false
|
17
|
+
if DEBUG_TRACE
|
18
|
+
STDOUT.puts "\nTEST TEMPLATE CHANGE-DETECTION"
|
19
|
+
STDOUT.puts "\nTest case root directories:"
|
20
|
+
STDOUT.puts "...MvTestDir=#{MVTestDir}"
|
21
|
+
STDOUT.puts "...TestFixturesDir=#{TestFixturesDir}"
|
22
|
+
STDOUT.puts "...TemplateSrcDir=#{TemplateSrcDir}"
|
23
|
+
STDOUT.puts "...TemplateDstDir=#{TemplateDstDir}"
|
24
|
+
end
|
25
|
+
|
26
|
+
# a template file that we'll monitor to verify change detection
|
27
|
+
TestSubjectFileShortName = 'product.html'
|
28
|
+
TestFixtureFile = "#{TestFixturesDir}/product.html"
|
29
|
+
TestSubjectFile = "#{TemplateSrcDir}/#{TestSubjectFileShortName}"
|
30
|
+
|
31
|
+
def setup
|
32
|
+
unless File.exists?(TestSubjectFile)
|
33
|
+
# isolate a copy of the observed template file in our templates source test dir
|
34
|
+
# so we can bash its file timestamp to test changed-file detection
|
35
|
+
FileUtils.mkdir_p TemplateSrcDir unless File.directory?(TemplateSrcDir)
|
36
|
+
FileUtils.copy TestFixtureFile, TestSubjectFile, :preserve => false #WAS: true
|
37
|
+
STDOUT.puts "\n========== test setup ==================" if DEBUG_TRACE
|
38
|
+
STDOUT.puts "...installed test fixture #{TestFixtureFile}" if DEBUG_TRACE
|
39
|
+
STDOUT.puts "...#{TestSubjectFileShortName} template timestamp=#{File.mtime(TestSubjectFile)}" if DEBUG_TRACE
|
40
|
+
end
|
41
|
+
@template_mio_tree = MasterView::FileMIOTree.new(TemplateSrcDir, '.html')
|
42
|
+
@output_mio_tree = MasterView::FileMIOTree.new(TemplateDstDir, '.rhtml')
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_a_parse_template_on_startup
|
46
|
+
STDOUT.puts "\n========== test_a_parse_template_on_startup ==========" if DEBUG_TRACE
|
47
|
+
STDOUT.puts "...#{TestSubjectFileShortName} template timestamp=#{File.mtime(TestSubjectFile)}" if DEBUG_TRACE
|
48
|
+
STDOUT.puts "...clearing dir #{TemplateDstDir}" if DEBUG_TRACE && File.exists?(TemplateDstDir)
|
49
|
+
|
50
|
+
FileUtils.remove_dir(TemplateDstDir, true)
|
51
|
+
files_processed = MasterView::TemplateWatcher.check_updated(@template_mio_tree, TemplateFilenamePattern) do |mio|
|
52
|
+
MasterView::Parser.parse_mio( mio, @output_mio_tree )
|
53
|
+
end
|
54
|
+
|
55
|
+
assert_equal [ TestSubjectFileShortName ], files_processed
|
56
|
+
assert File.exist?(TemplateDstDir+'/layouts/product.rhtml')
|
57
|
+
assert File.exist?(TemplateDstDir+'/product/_form.rhtml')
|
58
|
+
assert File.exist?(TemplateDstDir+'/product/edit.rhtml')
|
59
|
+
assert File.exist?(TemplateDstDir+'/product/list.rhtml')
|
60
|
+
assert File.exist?(TemplateDstDir+'/product/new.rhtml')
|
61
|
+
assert File.exist?(TemplateDstDir+'/product/show.rhtml')
|
62
|
+
|
63
|
+
STDOUT.puts "...files_processed [ #{files_processed.join(', ')} ]" if DEBUG_TRACE
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_b_check_template_no_change
|
67
|
+
STDOUT.puts "\n========== test_b_check_template_no_change =============" if DEBUG_TRACE
|
68
|
+
STDOUT.puts "...#{TestSubjectFileShortName} template timestamp=#{File.mtime(TestSubjectFile)}" if DEBUG_TRACE
|
69
|
+
|
70
|
+
assert_equal true, File.directory?(TemplateDstDir)
|
71
|
+
files_processed = parse_changed_templates
|
72
|
+
|
73
|
+
assert_equal [], files_processed
|
74
|
+
STDOUT.puts "...files_processed [ #{files_processed.join(', ')} ]" if DEBUG_TRACE
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_c_reparse_changed_template
|
78
|
+
STDOUT.puts "\n========== test_c_reparse_changed_template =============" if DEBUG_TRACE
|
79
|
+
STDOUT.puts "...#{TestSubjectFileShortName} template timestamp=#{File.mtime(TestSubjectFile)}" if DEBUG_TRACE
|
80
|
+
|
81
|
+
# touch gets permission-denied error on Win32, so work around
|
82
|
+
sleep 1 # make sure noticeable time passes
|
83
|
+
if RUBY_PLATFORM =~ /mswin32/
|
84
|
+
# re-copy the test fixture to get a new timestamp
|
85
|
+
STDOUT.puts "...forcing update of template #{TestSubjectFileShortName}" if DEBUG_TRACE
|
86
|
+
#FileUtils.copy TestFixtureFile, TestSubjectFile, :preserve => false
|
87
|
+
File.open( TestSubjectFile, 'a' ){ |file| file.write("\n ") }
|
88
|
+
else
|
89
|
+
FileUtils.touch TestSubjectFile
|
90
|
+
end
|
91
|
+
STDOUT.puts "...#{TestSubjectFileShortName} template timestamp=#{File.mtime(TestSubjectFile)}" if DEBUG_TRACE
|
92
|
+
|
93
|
+
files_processed = parse_changed_templates
|
94
|
+
assert_equal [ TestSubjectFileShortName ], files_processed
|
95
|
+
STDOUT.puts "...files_processed [ #{files_processed.join(', ')} ]" if DEBUG_TRACE
|
96
|
+
end
|
97
|
+
|
98
|
+
def parse_changed_templates
|
99
|
+
files_processed = MasterView::TemplateWatcher.check_updated(@template_mio_tree, TemplateFilenamePattern) do |mio|
|
100
|
+
MasterView::Parser.parse_mio( mio, @output_mio_tree )
|
101
|
+
end
|
102
|
+
files_processed
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
|
@@ -2,12 +2,13 @@
|
|
2
2
|
|
3
3
|
require 'test/unit'
|
4
4
|
currentPath = File.dirname(__FILE__)
|
5
|
-
require File.join( currentPath, '
|
5
|
+
require File.join( currentPath, '../../lib/masterview' )
|
6
6
|
|
7
7
|
class TestTemplateSpec < Test::Unit::TestCase
|
8
8
|
CurrentPath = File.dirname(__FILE__)
|
9
|
-
|
10
|
-
|
9
|
+
TestFixturesDir = File.join(CurrentPath, '../fixtures/templates')
|
10
|
+
MasterViewHTMLFile = File.join(TestFixturesDir, 'product.html')
|
11
|
+
MasterViewHTMLImportFile = File.join(TestFixturesDir, 'test.import')
|
11
12
|
|
12
13
|
def setup
|
13
14
|
end
|
@@ -18,7 +19,7 @@ class TestTemplateSpec < Test::Unit::TestCase
|
|
18
19
|
<html mv:generate="layout/foo.rhtml">
|
19
20
|
<body>
|
20
21
|
<div mv:generate="bar/baz.rhtml">
|
21
|
-
<div mv:
|
22
|
+
<div mv:gen_partial=":partial => 'cat/foo'">
|
22
23
|
Hello
|
23
24
|
</div>
|
24
25
|
</div>
|
@@ -38,7 +39,7 @@ class TestTemplateSpec < Test::Unit::TestCase
|
|
38
39
|
</breakthisxhtml>
|
39
40
|
<body>
|
40
41
|
<div mv:generate="bar/baz.rhtml">
|
41
|
-
<div mv:
|
42
|
+
<div mv:gen_partial=":partial => 'cat/foo'">
|
42
43
|
Hello
|
43
44
|
</div>
|
44
45
|
</div>
|
@@ -57,7 +58,7 @@ class TestTemplateSpec < Test::Unit::TestCase
|
|
57
58
|
<html mv:generate="layout/foo.rhtml">
|
58
59
|
<body>
|
59
60
|
<div mv:generate="bar/baz.rhtml">
|
60
|
-
<div mv:
|
61
|
+
<div mv:gen_partial=":partial => 'cat/foo'">
|
61
62
|
Hello
|
62
63
|
</div>
|
63
64
|
</div>
|
@@ -69,7 +70,7 @@ class TestTemplateSpec < Test::Unit::TestCase
|
|
69
70
|
<html mv:generate="layout/foo.rhtml">
|
70
71
|
<body>
|
71
72
|
<div mv:import="bar/baz.rhtml">
|
72
|
-
<div mv:
|
73
|
+
<div mv:gen_partial=":partial => 'cat/foo'">
|
73
74
|
Hello
|
74
75
|
</div>
|
75
76
|
</div>
|
@@ -100,7 +101,7 @@ class TestTemplateSpec < Test::Unit::TestCase
|
|
100
101
|
<html mv:generate="layout/foo.rhtml">
|
101
102
|
<body>
|
102
103
|
<div mv:generate="bar/baz.rhtml">
|
103
|
-
<div mv:
|
104
|
+
<div mv:gen_partial=":partial => 'cat/foo'">
|
104
105
|
Hello
|
105
106
|
</div>
|
106
107
|
</div>
|
@@ -109,14 +110,14 @@ class TestTemplateSpec < Test::Unit::TestCase
|
|
109
110
|
END
|
110
111
|
spec2 = MasterView::TemplateSpec.scan_template(template2, 'world', content_hash)
|
111
112
|
|
112
|
-
invalid_parts = MasterView::TemplateSpec.template_out_of_sync?(template1, content_hash)
|
113
|
+
invalid_parts = MasterView::TemplateSpec.template_out_of_sync?(template1, 'hello', content_hash)
|
113
114
|
spec1.update_status_from_invalid_parts(invalid_parts)
|
114
115
|
assert_equal [], invalid_parts
|
115
116
|
assert_equal MasterView::TemplateSpec::Status::OK, spec1.status
|
116
117
|
assert_equal '', spec1.message
|
117
118
|
assert_equal [], spec1.gen_parts
|
118
119
|
|
119
|
-
invalid_parts = MasterView::TemplateSpec.template_out_of_sync?(template2, content_hash)
|
120
|
+
invalid_parts = MasterView::TemplateSpec.template_out_of_sync?(template2, 'world', content_hash)
|
120
121
|
spec2.update_status_from_invalid_parts(invalid_parts)
|
121
122
|
assert_equal [], invalid_parts
|
122
123
|
assert_equal MasterView::TemplateSpec::Status::OK, spec2.status
|
@@ -143,7 +144,7 @@ class TestTemplateSpec < Test::Unit::TestCase
|
|
143
144
|
<html mv:generate="layout/foo.rhtml">
|
144
145
|
<body>
|
145
146
|
<div mv:generate="bar/baz.rhtml">
|
146
|
-
<div mv:
|
147
|
+
<div mv:gen_partial=":partial => 'cat/foo'">
|
147
148
|
Hello
|
148
149
|
</div>
|
149
150
|
</div>
|
@@ -152,14 +153,14 @@ class TestTemplateSpec < Test::Unit::TestCase
|
|
152
153
|
END
|
153
154
|
spec2 = MasterView::TemplateSpec.scan_template(template2, 'world', content_hash)
|
154
155
|
|
155
|
-
invalid_parts = MasterView::TemplateSpec.template_out_of_sync?(template1, content_hash)
|
156
|
+
invalid_parts = MasterView::TemplateSpec.template_out_of_sync?(template1, 'hello', content_hash)
|
156
157
|
spec1.update_status_from_invalid_parts(invalid_parts)
|
157
158
|
assert_equal %w{ cat/_foo.rhtml layout/foo.rhtml }, invalid_parts
|
158
159
|
assert_equal MasterView::TemplateSpec::Status::ImportsOutdated, spec1.status
|
159
160
|
assert_equal 'Outdated parts: cat/_foo.rhtml, layout/foo.rhtml', spec1.message
|
160
161
|
assert_equal [], spec1.gen_parts
|
161
162
|
|
162
|
-
invalid_parts = MasterView::TemplateSpec.template_out_of_sync?(template2, content_hash)
|
163
|
+
invalid_parts = MasterView::TemplateSpec.template_out_of_sync?(template2, 'world', content_hash)
|
163
164
|
spec2.update_status_from_invalid_parts(invalid_parts)
|
164
165
|
assert_equal [], invalid_parts
|
165
166
|
assert_equal MasterView::TemplateSpec::Status::OK, spec2.status
|
@@ -186,7 +187,7 @@ END
|
|
186
187
|
<html mv:generate="layout/foo.rhtml">
|
187
188
|
<body>
|
188
189
|
<div mv:generate="bar/baz.rhtml">
|
189
|
-
<div mv:
|
190
|
+
<div mv:gen_partial=":partial => 'cat/foo'">
|
190
191
|
Hello
|
191
192
|
</div>
|
192
193
|
</div>
|
@@ -195,7 +196,7 @@ END
|
|
195
196
|
END
|
196
197
|
spec2 = MasterView::TemplateSpec.scan_template(template2, 'world', content_hash)
|
197
198
|
|
198
|
-
invalid_parts = MasterView::TemplateSpec.template_out_of_sync?(template1, content_hash)
|
199
|
+
invalid_parts = MasterView::TemplateSpec.template_out_of_sync?(template1, 'hello', content_hash)
|
199
200
|
spec1.update_status_from_invalid_parts(invalid_parts)
|
200
201
|
assert_equal %w{ cat/_foo.rhtml layout/foo.rhtml }, invalid_parts
|
201
202
|
assert_equal MasterView::TemplateSpec::Status::ImportsOutdated, spec1.status
|
@@ -224,7 +225,7 @@ END
|
|
224
225
|
<html mv:generate="layout/foo.rhtml">
|
225
226
|
<body>
|
226
227
|
<div mv:generate="foo/bar.rhtml">
|
227
|
-
<div mv:
|
228
|
+
<div mv:gen_partial=":partial => 'foo/messages'">
|
228
229
|
Hello
|
229
230
|
</div>
|
230
231
|
</div>
|
@@ -250,7 +251,7 @@ END
|
|
250
251
|
</html>
|
251
252
|
END
|
252
253
|
|
253
|
-
src_path = '
|
254
|
+
src_path = 'foo/bar.html'
|
254
255
|
content_hash = {}
|
255
256
|
template_spec_to_copy_from = MasterView::TemplateSpec.scan_template(source, src_path, content_hash) # setup content_hash since not getting from dir
|
256
257
|
options = { :template_source => source, :content_hash => content_hash }
|
@@ -264,7 +265,7 @@ END
|
|
264
265
|
<html mv:generate="layout/foo.rhtml">
|
265
266
|
<body>
|
266
267
|
<div mv:generate="foo/bar.rhtml">
|
267
|
-
<div mv:
|
268
|
+
<div mv:gen_partial=":partial => 'foo/messages'">
|
268
269
|
Hello
|
269
270
|
</div>
|
270
271
|
</div>
|
@@ -290,7 +291,7 @@ END
|
|
290
291
|
</html>
|
291
292
|
END
|
292
293
|
|
293
|
-
src_path = '
|
294
|
+
src_path = 'foo/bar.html'
|
294
295
|
content_hash = {}
|
295
296
|
template_spec_to_copy_from = MasterView::TemplateSpec.scan_template(source, src_path, content_hash) # setup content_hash since not getting from dir
|
296
297
|
options = { :template_source => source, :content_hash => content_hash }
|
@@ -304,7 +305,7 @@ END
|
|
304
305
|
<html mv:generate="layout/foo.rhtml">
|
305
306
|
<body>
|
306
307
|
<div mv:generate="foo/bar.rhtml">
|
307
|
-
<div mv:
|
308
|
+
<div mv:gen_partial=":partial => 'foo/messages'">
|
308
309
|
Hello
|
309
310
|
</div>
|
310
311
|
</div>
|
@@ -330,7 +331,7 @@ END
|
|
330
331
|
</html>
|
331
332
|
END
|
332
333
|
|
333
|
-
src_path = '
|
334
|
+
src_path = 'foo/bar'
|
334
335
|
content_hash = {}
|
335
336
|
template_spec_to_copy_from = MasterView::TemplateSpec.scan_template(source, src_path, content_hash) # setup content_hash since not getting from dir
|
336
337
|
options = { :template_source => source, :content_hash => content_hash }
|
@@ -338,6 +339,41 @@ END
|
|
338
339
|
assert_equal expected_result.strip, result
|
339
340
|
end
|
340
341
|
|
342
|
+
def test_simple_html_no_mv_directives
|
343
|
+
source = <<-END
|
344
|
+
<html>
|
345
|
+
<body>
|
346
|
+
Hello
|
347
|
+
</body>
|
348
|
+
</html>
|
349
|
+
END
|
350
|
+
source.strip!
|
351
|
+
content_hash = {}
|
352
|
+
src_path = 'foo/bar'
|
353
|
+
template_spec = MasterView::TemplateSpec.scan_template(source, src_path, content_hash) # setup content_hash since not getting from dir
|
354
|
+
assert_equal MasterView::TemplateSpec::Status::OK, template_spec.status
|
355
|
+
assert_equal [], template_spec.build_list
|
356
|
+
end
|
357
|
+
|
358
|
+
|
359
|
+
def test_simple_html_one_mv_directive
|
360
|
+
source = <<-END
|
361
|
+
<html>
|
362
|
+
<body>
|
363
|
+
<div mv:generate="one/two.rhtml">
|
364
|
+
<two>world</two>
|
365
|
+
</div>
|
366
|
+
</body>
|
367
|
+
</html>
|
368
|
+
END
|
369
|
+
source.strip!
|
370
|
+
content_hash = {}
|
371
|
+
src_path = 'foo/bar'
|
372
|
+
template_spec = MasterView::TemplateSpec.scan_template(source, src_path, content_hash) # setup content_hash since not getting from dir
|
373
|
+
assert_equal MasterView::TemplateSpec::Status::OK, template_spec.status
|
374
|
+
assert_equal 1, template_spec.build_list.length
|
375
|
+
assert_equal 'one/two.rhtml', template_spec.build_list[0].name
|
376
|
+
end
|
341
377
|
|
342
378
|
end
|
343
379
|
|