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,289 @@
|
|
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 TestMTimeStringHashMIO < Test::Unit::TestCase
|
8
|
+
include MasterView
|
9
|
+
|
10
|
+
TestStringMIOTemplatePathname = Pathname.new('../tmp/template')
|
11
|
+
ErbPathname = Pathname.new('../tmp/erb')
|
12
|
+
HelloWorldFullPath = '../tmp/template/hello_world.txt'
|
13
|
+
HelloWorldPath = 'hello_world.txt'
|
14
|
+
TestWritePath = 'foo.txt'
|
15
|
+
TestWritePathname = Pathname.new(TestWritePath)
|
16
|
+
|
17
|
+
IOMgr = MIOTrees.new
|
18
|
+
|
19
|
+
def setup
|
20
|
+
IOMgr.template = MTimeStringHashMIOTree.new('.html')
|
21
|
+
IOMgr.erb = MTimeStringHashMIOTree.new('.rhtml' )
|
22
|
+
IOMgr.file = MTimeStringHashMIOTree.new()
|
23
|
+
@template_hash = IOMgr.template.string_hash
|
24
|
+
@erb_hash = IOMgr.erb.string_hash
|
25
|
+
@file_hash = IOMgr.file.string_hash
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_create_foo
|
29
|
+
f = IOMgr.template.path( 'foo')
|
30
|
+
assert_equal MTimeStringMIO, f.class
|
31
|
+
assert_equal 'foo', f.pathname.to_s
|
32
|
+
assert_equal 'foo', f.full_pathname.to_s
|
33
|
+
assert_nil f.mtime
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_create_foo_with_useless_dots
|
37
|
+
f = IOMgr.template.path( 'foo/bar/../cat')
|
38
|
+
assert_equal MTimeStringMIO, f.class
|
39
|
+
assert_equal 'foo/cat', f.pathname.to_s
|
40
|
+
assert_equal 'foo/cat', f.full_pathname.to_s
|
41
|
+
f.write('hello')
|
42
|
+
assert @template_hash.has_key?('foo/cat')
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_create_foo_with_useless_dots2
|
46
|
+
f = IOMgr.template.path( 'foo/bar/../cat/../dog')
|
47
|
+
assert_equal MTimeStringMIO, f.class
|
48
|
+
assert_equal 'foo/dog', f.pathname.to_s
|
49
|
+
assert_equal 'foo/dog', f.full_pathname.to_s
|
50
|
+
f.write('hello')
|
51
|
+
assert @template_hash.has_key?('foo/dog')
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_create_useless_dots
|
55
|
+
f = IOMgr.template.path( '../../foo')
|
56
|
+
assert_equal MTimeStringMIO, f.class
|
57
|
+
assert_equal '../../foo', f.pathname.to_s
|
58
|
+
assert_equal '../../foo', f.full_pathname.to_s
|
59
|
+
f.write('hello')
|
60
|
+
assert @template_hash['../../foo']
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_create_bar
|
64
|
+
f = IOMgr.erb.path( 'bar')
|
65
|
+
assert_equal MTimeStringMIO, f.class
|
66
|
+
assert_equal 'bar', f.pathname.to_s
|
67
|
+
assert_equal 'bar', f.full_pathname.to_s
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_create_cat
|
71
|
+
f = IOMgr.file.path('cat')
|
72
|
+
assert_equal MTimeStringMIO, f.class
|
73
|
+
assert_equal 'cat', f.pathname.to_s
|
74
|
+
assert_equal 'cat', f.full_pathname.to_s
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_create_foo_w_ext
|
78
|
+
f = IOMgr.template.path( 'foo.txt')
|
79
|
+
assert_equal MTimeStringMIO, f.class
|
80
|
+
assert_equal 'foo.txt', f.pathname.to_s
|
81
|
+
assert_equal 'foo.txt', f.full_pathname.to_s
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_create_parts
|
85
|
+
f = IOMgr.template.path( 'sub/one/two/three/foo.txt')
|
86
|
+
assert_equal MTimeStringMIO, f.class
|
87
|
+
assert_equal 'sub/one/two/three/foo.txt', f.pathname.to_s
|
88
|
+
assert_equal 'sub/one/two/three/foo.txt', f.full_pathname.to_s
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_read
|
92
|
+
f = IOMgr.template.path( HelloWorldPath)
|
93
|
+
assert_nil f.read
|
94
|
+
assert_nil f.mtime
|
95
|
+
@template_hash[HelloWorldPath] = "hello\nworld"
|
96
|
+
assert_equal "hello\nworld", f.read
|
97
|
+
assert_kind_of Time, f.mtime
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_read_disable_cache
|
101
|
+
@template_hash[HelloWorldPath] = "hello\nworld"
|
102
|
+
f = IOMgr.template.path( HelloWorldPath)
|
103
|
+
assert_equal "hello\nworld", f.read
|
104
|
+
@template_hash[HelloWorldPath] = "foo\nbar"
|
105
|
+
#assert_equal "hello\nworld", f.read #still reading from cache, #todo enable when caching module is ready for testing
|
106
|
+
assert_equal "foo\nbar", f.read(:disable_cache => true)
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_write_string
|
110
|
+
f = IOMgr.template.path( TestWritePath)
|
111
|
+
assert_nil f.mtime
|
112
|
+
f.write("foo\nbar")
|
113
|
+
assert_equal "foo\nbar", @template_hash[TestWritePath]
|
114
|
+
assert_equal "foo\nbar", IOMgr.template.path( TestWritePath).read
|
115
|
+
assert_kind_of Time, f.mtime
|
116
|
+
m = f.mtime
|
117
|
+
assert_equal m, f.mtime
|
118
|
+
sleep 1 # wait noticeable time
|
119
|
+
f.write("updated")
|
120
|
+
assert_kind_of Time, f.mtime
|
121
|
+
assert f.mtime > m
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_write_block
|
125
|
+
@template_hash.delete(TestWritePath)
|
126
|
+
IOMgr.template.path( TestWritePath).write { |f| f.write('hello') }
|
127
|
+
assert_equal "hello", IOMgr.template.path( TestWritePath).read
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_write_multi_block
|
131
|
+
@template_hash.delete(TestWritePath)
|
132
|
+
IOMgr.template.path( TestWritePath).write do |f|
|
133
|
+
f.write('hello')
|
134
|
+
f.write('world')
|
135
|
+
end
|
136
|
+
assert_equal "helloworld", IOMgr.template.path( TestWritePath).read
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_write_mkpath
|
140
|
+
@template_hash.clear
|
141
|
+
IOMgr.template.path( TestWritePath).write("foo\nbar")
|
142
|
+
assert_equal "foo\nbar", IOMgr.template.path( TestWritePath).read
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_exist
|
146
|
+
@template_hash.clear
|
147
|
+
assert_equal false, IOMgr.template.path( TestWritePath ).exist?
|
148
|
+
assert @template_hash.empty?
|
149
|
+
IOMgr.template.path( TestWritePath).write("foo")
|
150
|
+
assert_equal true, IOMgr.template.path( TestWritePath).exist?
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_identical
|
154
|
+
@template_hash.clear
|
155
|
+
assert_equal false, IOMgr.template.path( TestWritePath).identical?("hello\nworld")
|
156
|
+
@template_hash[TestWritePath] = "hello\nworld"
|
157
|
+
assert_equal true, IOMgr.template.path( TestWritePath).identical?("hello\nworld")
|
158
|
+
assert_equal false, IOMgr.template.path( TestWritePath).identical?("foo")
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_findfiles_single_dir
|
162
|
+
@template_hash.clear
|
163
|
+
IOMgr.template.path( 'apple.txt').write('foo')
|
164
|
+
IOMgr.template.path( 'bar.txt').write('foo')
|
165
|
+
@template_hash[('baz.txt').to_s] = 'foo'
|
166
|
+
found = IOMgr.template.find
|
167
|
+
assert_equal 3, found.length
|
168
|
+
assert_equal MTimeStringMIO, found[0].class
|
169
|
+
assert_equal MTimeStringMIO, found[1].class
|
170
|
+
assert_equal MTimeStringMIO, found[2].class
|
171
|
+
assert_equal 'apple.txt', found[0].pathname.to_s
|
172
|
+
assert_equal 'bar.txt', found[1].pathname.to_s
|
173
|
+
assert_equal ('baz.txt').to_s, found[2].pathname.to_s
|
174
|
+
assert_equal ('baz.txt').to_s, found[2].full_pathname.to_s
|
175
|
+
end
|
176
|
+
|
177
|
+
def test_findfiles_single_sub_dir
|
178
|
+
@template_hash.clear
|
179
|
+
IOMgr.template.path( 'sub/apple.txt').write('foo')
|
180
|
+
IOMgr.template.path( 'sub/bar.txt').write('foo')
|
181
|
+
IOMgr.template.path( 'sub/baz.txt').write('foo')
|
182
|
+
found = IOMgr.template.find(:path => 'sub')
|
183
|
+
assert_equal 3, found.length
|
184
|
+
assert_equal MTimeStringMIO, found[0].class
|
185
|
+
assert_equal MTimeStringMIO, found[1].class
|
186
|
+
assert_equal MTimeStringMIO, found[2].class
|
187
|
+
assert_equal 'sub/apple.txt', found[0].pathname.to_s
|
188
|
+
assert_equal 'sub/bar.txt', found[1].pathname.to_s
|
189
|
+
assert_equal 'sub/baz.txt', found[2].pathname.to_s
|
190
|
+
end
|
191
|
+
|
192
|
+
def test_findfiles_single_sub2_dir_multi_arg
|
193
|
+
@template_hash.clear
|
194
|
+
IOMgr.template.path( 'sub/two/apple.txt').write('foo')
|
195
|
+
IOMgr.template.path( 'sub/two/bar.txt').write('foo')
|
196
|
+
IOMgr.template.path( 'sub/two/baz.txt').write { |f| f.write('foo') }
|
197
|
+
found = IOMgr.template.find(:path => 'sub/two')
|
198
|
+
assert_equal 3, found.length
|
199
|
+
assert_equal MTimeStringMIO, found[0].class
|
200
|
+
assert_equal MTimeStringMIO, found[1].class
|
201
|
+
assert_equal MTimeStringMIO, found[2].class
|
202
|
+
assert_equal 'sub/two/apple.txt', found[0].full_pathname.to_s
|
203
|
+
assert_equal 'sub/two/apple.txt', found[0].pathname.to_s
|
204
|
+
assert_equal 'sub/two/bar.txt', found[1].pathname.to_s
|
205
|
+
assert_equal 'sub/two/baz.txt', found[2].pathname.to_s
|
206
|
+
end
|
207
|
+
|
208
|
+
def test_findfiles_single_dir_pattern
|
209
|
+
@template_hash.clear
|
210
|
+
IOMgr.template.path( 'sub/two/apple.txt').write('foo')
|
211
|
+
IOMgr.template.path( 'sub/two/bar.log').write('foo')
|
212
|
+
@template_hash['sub/two/baz.txt'] = 'foo'
|
213
|
+
found = IOMgr.template.find(:path => 'sub/two', :pattern => '*.txt')
|
214
|
+
assert_equal 2, found.length
|
215
|
+
assert_equal MTimeStringMIO, found[0].class
|
216
|
+
assert_equal MTimeStringMIO, found[1].class
|
217
|
+
assert_equal 'sub/two/apple.txt', found[0].pathname.to_s
|
218
|
+
assert_equal 'sub/two/baz.txt', found[1].pathname.to_s
|
219
|
+
end
|
220
|
+
|
221
|
+
def test_findfiles_multi_dir_root
|
222
|
+
@template_hash.clear
|
223
|
+
IOMgr.template.path( 'one/two/three.txt').write('foo')
|
224
|
+
IOMgr.template.path( 'sub/two/apple.txt').write('foo')
|
225
|
+
IOMgr.template.path( 'sub/two/bar.log').write('foo')
|
226
|
+
IOMgr.template.path( 'sub/two/baz.txt').write { |f| f.write('foo') }
|
227
|
+
found = IOMgr.template.find
|
228
|
+
assert_equal 4, found.length
|
229
|
+
assert_equal MTimeStringMIO, found[0].class
|
230
|
+
assert_equal MTimeStringMIO, found[1].class
|
231
|
+
assert_equal MTimeStringMIO, found[2].class
|
232
|
+
assert_equal MTimeStringMIO, found[3].class
|
233
|
+
assert_equal 'one/two/three.txt', found[0].pathname.to_s
|
234
|
+
assert_equal 'sub/two/apple.txt', found[1].pathname.to_s
|
235
|
+
assert_equal 'sub/two/bar.log', found[2].pathname.to_s
|
236
|
+
assert_equal 'sub/two/baz.txt', found[3].pathname.to_s
|
237
|
+
end
|
238
|
+
|
239
|
+
def test_findfiles_multi_dir_pattern
|
240
|
+
@template_hash.clear
|
241
|
+
IOMgr.template.path( 'one/two/three.txt').write('foo')
|
242
|
+
IOMgr.template.path( 'sub/two/apple.txt').write('foo')
|
243
|
+
IOMgr.template.path( 'sub/two/bar.log').write('foo')
|
244
|
+
IOMgr.template.path( 'sub/two/baz.txt').write('foo')
|
245
|
+
found = IOMgr.template.find(:pattern => '*.txt')
|
246
|
+
assert_equal 3, found.length
|
247
|
+
assert_equal MTimeStringMIO, found[0].class
|
248
|
+
assert_equal MTimeStringMIO, found[1].class
|
249
|
+
assert_equal MTimeStringMIO, found[2].class
|
250
|
+
assert_equal 'one/two/three.txt', found[0].pathname.to_s
|
251
|
+
assert_equal 'sub/two/apple.txt', found[1].pathname.to_s
|
252
|
+
assert_equal 'sub/two/baz.txt', found[2].pathname.to_s
|
253
|
+
end
|
254
|
+
|
255
|
+
def test_findfiles_multi_dir_pattern_deep
|
256
|
+
@template_hash.clear
|
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
|
+
IOMgr.template.path( 'sub/two/baz.txt').write('foo')
|
261
|
+
found = IOMgr.template.find(:path => 'sub/two', :pattern => '*.txt')
|
262
|
+
assert_equal 2, found.length
|
263
|
+
assert_equal MTimeStringMIO, found[0].class
|
264
|
+
assert_equal MTimeStringMIO, found[1].class
|
265
|
+
assert_equal 'sub/two/apple.txt', found[0].pathname.to_s
|
266
|
+
assert_equal 'sub/two/baz.txt', found[1].pathname.to_s
|
267
|
+
end
|
268
|
+
|
269
|
+
def test_findfiles_multi_dir_pattern_deep_with_block
|
270
|
+
@template_hash.clear
|
271
|
+
IOMgr.template.path( 'one/two/three.txt').write('foo')
|
272
|
+
IOMgr.template.path( 'sub/two/apple.txt').write('foo')
|
273
|
+
IOMgr.template.path( 'sub/two/bar.log').write('foo')
|
274
|
+
IOMgr.template.path( 'sub/two/baz.txt').write('foo')
|
275
|
+
array_of_mio = []
|
276
|
+
found = IOMgr.template.find(:path => 'sub/two', :pattern => '*.txt'){ |mio| array_of_mio << mio }
|
277
|
+
assert_equal 2, found.length
|
278
|
+
assert_equal MTimeStringMIO, found[0].class
|
279
|
+
assert_equal MTimeStringMIO, found[1].class
|
280
|
+
assert_equal 'sub/two/apple.txt', found[0].pathname.to_s
|
281
|
+
assert_equal 'sub/two/baz.txt', found[1].pathname.to_s
|
282
|
+
assert_equal 2, array_of_mio.length
|
283
|
+
assert_kind_of MTimeStringMIO, array_of_mio[0]
|
284
|
+
assert_kind_of MTimeStringMIO, array_of_mio[1]
|
285
|
+
assert_equal 'sub/two/apple.txt', array_of_mio[0].pathname.to_s
|
286
|
+
assert_equal 'sub/two/baz.txt', array_of_mio[1].pathname.to_s
|
287
|
+
end
|
288
|
+
|
289
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'pathname'
|
5
|
+
require File.join( File.dirname(__FILE__), '../../lib/masterview/mtime_tracking_hash' )
|
6
|
+
|
7
|
+
class TestMTimeTrackingHash < Test::Unit::TestCase
|
8
|
+
|
9
|
+
def setup
|
10
|
+
@h = MasterView::MTimeTrackingHash.new
|
11
|
+
@h[1] = 'one'
|
12
|
+
@h[2] = :two
|
13
|
+
@h[:foo] = :bar
|
14
|
+
@h['cat'] = :dog
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_hash
|
18
|
+
assert_equal 'one', @h[1]
|
19
|
+
assert_equal :two, @h[2]
|
20
|
+
assert_equal :bar, @h[:foo]
|
21
|
+
assert_equal :dog, @h['cat']
|
22
|
+
assert_nil @h.mtime(:not_found)
|
23
|
+
assert_kind_of Time, @h.mtime(1)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_hash_changed
|
27
|
+
m1 = @h.mtime(1)
|
28
|
+
m2 = @h.mtime(2)
|
29
|
+
assert_equal m1, @h.mtime(1)
|
30
|
+
sleep 1 # make sure noticeable time passes
|
31
|
+
@h[2] = 'two updated'
|
32
|
+
assert_not_equal m2, @h.mtime(2)
|
33
|
+
assert_equal m1, @h.mtime(1)
|
34
|
+
assert_kind_of Time, @h.mtime(2)
|
35
|
+
assert(@h.mtime(2) > m2)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -2,7 +2,7 @@
|
|
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 TestParser < Test::Unit::TestCase
|
8
8
|
include MasterView::Directives
|
@@ -154,6 +154,24 @@ class TestParser < Test::Unit::TestCase
|
|
154
154
|
assert_equal [[:a,:b], [:c,:d], [:e,:f]], t.data
|
155
155
|
end
|
156
156
|
|
157
|
+
# base, meta, link, hr, br, param, img, area, input, col
|
158
|
+
def test_simplify_element_names
|
159
|
+
r = MasterView::Renderer.new(:output_mio_tree => MasterView::StringHashMIOTree.new )
|
160
|
+
assert_equal ['<base', ' />'], r.simplify_empty_elements( ['<base', '>', '</', 'base>'] )
|
161
|
+
assert_equal ['<meta', ' />'], r.simplify_empty_elements( ['<meta', '>', '</', 'meta>'] )
|
162
|
+
assert_equal ['<link', ' />'], r.simplify_empty_elements( ['<link', '>', '</', 'link>'] )
|
163
|
+
assert_equal ['<hr', ' />'], r.simplify_empty_elements( ['<hr', '>', '</', 'hr>'] )
|
164
|
+
assert_equal ['<br', ' />'], r.simplify_empty_elements( ['<br', '>', '</', 'br>'] )
|
165
|
+
assert_equal ['<param', ' />'], r.simplify_empty_elements( ['<param', '>', '</', 'param>'] )
|
166
|
+
assert_equal ['<img', ' />'], r.simplify_empty_elements( ['<img', '>', '</', 'img>'] )
|
167
|
+
assert_equal ['<area', ' />'], r.simplify_empty_elements( ['<area', '>', '</', 'area>'] )
|
168
|
+
assert_equal ['<input', ' />'], r.simplify_empty_elements( ['<input', '>', '</', 'input>'] )
|
169
|
+
assert_equal ['<col', ' />'], r.simplify_empty_elements( ['<col', '>', '</', 'col>'] )
|
170
|
+
|
171
|
+
assert_equal ['<script', '>', '</', 'script>'], r.simplify_empty_elements( ['<script', '>', '</', 'script>'] )
|
172
|
+
assert_equal ['<title', '>', '</', 'title>'], r.simplify_empty_elements( ['<title', '>', '</', 'title>'] )
|
173
|
+
end
|
174
|
+
|
157
175
|
def test_renderer
|
158
176
|
#todo
|
159
177
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'pathname'
|
5
|
+
require File.join( File.dirname(__FILE__), '../../lib/masterview/pathname_extensions' )
|
6
|
+
|
7
|
+
class TestPathnameExtensions < Test::Unit::TestCase
|
8
|
+
def test_for_path
|
9
|
+
assert_equal 'foo/bar/baz.txt', Pathname.for_path('foo/bar/baz.txt').to_s
|
10
|
+
assert_equal 'foo/bar/baz.txt', Pathname.for_path('foo\\bar\\baz.txt').to_s
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_join
|
14
|
+
assert_equal 'foo/bar/baz.txt', Pathname.join('foo', 'bar', 'baz.txt').to_s
|
15
|
+
assert_equal '/foo/bar/baz.txt', Pathname.join('/foo', 'bar', 'baz.txt').to_s
|
16
|
+
assert_equal 'foo/bar/baz.txt', Pathname.join('foo/bar', 'baz.txt').to_s
|
17
|
+
assert_equal 'foo/bar/baz.txt', Pathname.join('foo/bar/', 'baz.txt').to_s
|
18
|
+
assert_equal 'foo/bar/baz.txt', Pathname.join('foo/bar/baz.txt').to_s
|
19
|
+
assert_equal 'foo/bar/baz.txt', Pathname.join('foo', 'bar/', 'baz.txt').to_s
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_join_backspaces
|
24
|
+
assert_equal 'foo/bar/baz.txt', Pathname.join('foo\\bar\\', 'baz.txt').to_s
|
25
|
+
assert_equal 'foo/bar/baz.txt', Pathname.join('foo\\bar\\baz.txt').to_s
|
26
|
+
assert_equal 'foo/bar/baz/cat/dog.txt', Pathname.join('foo\\bar', 'baz\\cat','dog.txt').to_s
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_path_no_ext
|
30
|
+
assert_equal 'foo/bar/baz', Pathname.for_path('foo/bar/baz.txt').path_no_ext
|
31
|
+
assert_equal 'foo/bar/baz.', Pathname.for_path('foo/bar/baz.').path_no_ext
|
32
|
+
assert_equal 'foo/bar/baz', Pathname.for_path('foo/bar/baz').path_no_ext
|
33
|
+
assert_equal 'bar/baz', Pathname.for_path('bar/baz.txt').path_no_ext
|
34
|
+
assert_equal 'baz', Pathname.for_path('baz.txt').path_no_ext
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_safe_concat
|
38
|
+
assert_equal Pathname, Pathname.safe_concat(Pathname.new('foo'), Pathname.new('bar')).class
|
39
|
+
assert_equal 'foo/bar', Pathname.safe_concat(Pathname.new('foo'), Pathname.new('bar')).to_s
|
40
|
+
assert_equal nil, Pathname.safe_concat(nil, nil)
|
41
|
+
assert_equal 'foo', Pathname.safe_concat(nil, Pathname.new('foo')).to_s
|
42
|
+
assert_equal 'foo', Pathname.safe_concat(Pathname.new('foo'), nil).to_s
|
43
|
+
assert_equal 'foo', Pathname.safe_concat(Pathname.new(''), Pathname.new('foo')).to_s
|
44
|
+
assert_equal 'foo', Pathname.safe_concat(Pathname.new('foo'), Pathname.new('')).to_s
|
45
|
+
end
|
46
|
+
end
|
@@ -2,11 +2,12 @@
|
|
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 TestParser < Test::Unit::TestCase
|
8
8
|
CurrentPath = File.dirname(__FILE__)
|
9
|
-
|
9
|
+
TestFixturesDir = File.join(CurrentPath, '../fixtures/templates')
|
10
|
+
MasterViewHTMLFile = 'product.html'
|
10
11
|
TmpOutputDir = File.join(CurrentPath, '../tmp/views')
|
11
12
|
|
12
13
|
def setup
|
@@ -14,7 +15,10 @@ class TestParser < Test::Unit::TestCase
|
|
14
15
|
end
|
15
16
|
|
16
17
|
def test_parser_run
|
17
|
-
MasterView::
|
18
|
+
@template_mio_tree = MasterView::FileMIOTree.new(TestFixturesDir, '.html')
|
19
|
+
@template_mio = @template_mio_tree.path(MasterViewHTMLFile)
|
20
|
+
@erb_mio_tree = MasterView::FileMIOTree.new(TmpOutputDir, '.rhtml')
|
21
|
+
MasterView::Parser.parse_mio( @template_mio, @erb_mio_tree)
|
18
22
|
assert File.exist?(TmpOutputDir+'/layouts/product.rhtml')
|
19
23
|
assert File.exist?(TmpOutputDir+'/product/_form.rhtml')
|
20
24
|
assert File.exist?(TmpOutputDir+'/product/edit.rhtml')
|