masterview 0.2.5 → 0.3.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 +31 -1
- data/README +70 -69
- data/RELEASE_NOTES +70 -64
- data/Rakefile +26 -27
- data/TODO +13 -29
- data/doc/about.html +246 -0
- data/doc/configuration.html +49 -36
- data/doc/developer.html +423 -41
- data/doc/directives.html +139 -51
- data/doc/guide.html +19 -9
- data/doc/index.html +90 -224
- data/doc/installation.html +36 -28
- data/doc/media_list.html +30 -20
- data/doc/simple_diagram.html +3 -5
- data/doc/stylesheets/masterview.css +16 -1
- data/examples/rails_app_config/masterview/settings.rb +2 -1
- data/init.rb +1 -1
- data/lib/#ChangeLog# +6 -0
- data/lib/masterview/analyzer.rb +48 -34
- data/lib/masterview/attr_string_parser.rb +5 -1
- data/lib/masterview/case_insensitive_hash.rb +69 -0
- data/lib/masterview/{pathname_extensions.rb → core_ext/pathname.rb} +0 -0
- data/lib/masterview/{string_extensions.rb → core_ext/string.rb} +0 -0
- data/lib/masterview/deprecated/directive_base.rb +362 -0
- data/lib/masterview/directive_base.rb +201 -179
- data/lib/masterview/directive_dsl.rb +457 -0
- data/lib/masterview/directive_helpers.rb +28 -141
- data/lib/masterview/directive_load_path.rb +388 -0
- data/lib/masterview/directive_metadata.rb +377 -0
- data/lib/masterview/directive_registry.rb +259 -69
- data/lib/masterview/directives/.metadata +16 -0
- data/lib/masterview/directives/attr.rb +9 -8
- data/lib/masterview/directives/block.rb +11 -14
- data/lib/masterview/directives/check_box.rb +13 -18
- data/lib/masterview/directives/collection_select.rb +15 -29
- data/lib/masterview/directives/content.rb +9 -3
- data/lib/masterview/directives/else.rb +15 -13
- data/lib/masterview/directives/elsif.rb +14 -13
- data/lib/masterview/directives/eval.rb +20 -0
- data/lib/masterview/directives/form.rb +56 -9
- data/lib/masterview/directives/form_remote.rb +26 -0
- data/lib/masterview/directives/global_inline_erb.rb +10 -14
- data/lib/masterview/directives/hidden_field.rb +11 -20
- data/lib/masterview/directives/if.rb +13 -12
- data/lib/masterview/directives/image_tag.rb +20 -28
- data/lib/masterview/directives/import.rb +5 -12
- data/lib/masterview/directives/import_render.rb +7 -19
- data/lib/masterview/directives/insert_generated_comment.rb +8 -11
- data/lib/masterview/directives/javascript_include.rb +21 -12
- data/lib/masterview/directives/link_to.rb +14 -8
- data/lib/masterview/directives/link_to_function.rb +22 -0
- data/lib/masterview/directives/link_to_if.rb +15 -13
- data/lib/masterview/directives/link_to_remote.rb +13 -8
- data/lib/masterview/directives/omit_tag.rb +32 -16
- data/lib/masterview/directives/password_field.rb +10 -22
- data/lib/masterview/directives/radio_button.rb +11 -22
- data/lib/masterview/directives/replace.rb +7 -8
- data/lib/masterview/directives/select.rb +11 -24
- data/lib/masterview/directives/stylesheet_link.rb +20 -12
- data/lib/masterview/directives/submit.rb +11 -5
- data/lib/masterview/directives/text_area.rb +10 -23
- data/lib/masterview/directives/text_field.rb +10 -22
- data/lib/masterview/exceptions.rb +21 -0
- data/lib/masterview/extras/app/controllers/masterview_controller.rb +102 -75
- data/lib/masterview/extras/app/views/layouts/masterview_admin.rhtml +24 -23
- data/lib/masterview/extras/app/views/layouts/masterview_admin_config.rhtml +81 -0
- data/lib/masterview/extras/app/views/masterview/admin/configuration.rhtml +5 -1
- data/lib/masterview/extras/app/views/masterview/admin/create.rhtml +2 -2
- data/lib/masterview/extras/app/views/masterview/admin/directives.rhtml +5 -0
- data/lib/masterview/extras/app/views/masterview/admin/features.rhtml +5 -79
- data/lib/masterview/extras/app/views/masterview/admin/interact.rhtml +5 -0
- data/lib/masterview/extras/app/views/masterview/admin/list.rhtml +3 -71
- data/lib/masterview/extras/init_mv_admin_pages.rb +42 -23
- data/lib/masterview/filter_helpers.rb +26 -0
- data/lib/masterview/initializer.rb +99 -53
- data/lib/masterview/io.rb +19 -15
- data/lib/masterview/keyword_expander.rb +7 -2
- data/lib/masterview/masterview_info.rb +229 -23
- data/lib/masterview/masterview_version.rb +2 -2
- data/lib/masterview/parser.rb +275 -105
- data/lib/masterview/parser_helpers.rb +54 -0
- data/lib/masterview/rails_ext/action_controller_erb_direct.rb +29 -0
- data/lib/masterview/rails_ext/action_controller_reparse_checking.rb +27 -0
- data/lib/masterview/{extras/init_rails_erb_mv_direct.rb → rails_ext/action_view_erb_direct.rb} +12 -59
- data/lib/masterview/template_spec.rb +3 -2
- data/lib/masterview.rb +21 -12
- data/lib/rexml/parsers/baseparser_with_doctype_fix.rb +473 -0
- data/lib/rexml/parsers/sax2parser_with_doctype_fix.rb +243 -0
- data/test/directive_test_helper.rb +135 -0
- data/test/fixtures/directives/id_check.rb +18 -0
- data/test/fixtures/directives/test_directive_events.rb +70 -0
- data/test/test_helper.rb +18 -5
- data/test/tmp/views/layouts/product.rhtml +10 -10
- data/test/tmp/views/product/_form.rhtml +4 -4
- data/test/tmp/views/product/_product.rhtml +3 -3
- data/test/tmp/views/product/destroy.rhtml +5 -5
- data/test/tmp/views/product/edit.rhtml +4 -4
- data/test/tmp/views/product/list.rhtml +3 -3
- data/test/tmp/views/product/new.rhtml +4 -4
- data/test/tmp/views/product/show.rhtml +2 -2
- data/test/unit/attr_string_parser_test.rb +105 -0
- data/test/unit/case_insensitive_hash_mod_test.rb +104 -0
- data/test/unit/config_settings_test.rb +13 -1
- data/test/unit/default_generate_mio_filter_test.rb +3 -3
- data/test/unit/deprecated_directive_base_test.rb +30 -0
- data/test/unit/directive_attr_test.rb +111 -35
- data/test/unit/directive_base_test.rb +520 -1
- data/test/unit/directive_block_test.rb +30 -22
- data/test/unit/directive_content_test.rb +24 -11
- data/test/unit/directive_else_test.rb +18 -15
- data/test/unit/directive_elsif_test.rb +17 -15
- data/test/unit/directive_form_remote_test.rb +59 -0
- data/test/unit/directive_form_test.rb +31 -39
- data/test/unit/directive_global_inline_erb_test.rb +28 -17
- data/test/unit/directive_grid_test_notready.rb +38 -0
- data/test/unit/directive_helpers_test.rb +39 -0
- data/test/unit/directive_hidden_field_test.rb +44 -29
- data/test/unit/directive_if_test.rb +10 -7
- data/test/unit/directive_image_tag_test.rb +69 -61
- data/test/unit/directive_import_render_test.rb +28 -38
- data/test/unit/directive_import_test.rb +16 -14
- data/test/unit/directive_insert_generated_comment_test.rb +32 -0
- data/test/unit/directive_javascript_include_test.rb +40 -43
- data/test/unit/directive_link_to_function_test.rb +40 -0
- data/test/unit/directive_link_to_if_test.rb +52 -12
- data/test/unit/directive_link_to_remote_test.rb +58 -0
- data/test/unit/directive_link_to_test.rb +46 -31
- data/test/unit/directive_load_path_test.rb +257 -0
- data/test/unit/directive_metadata_test.rb +313 -0
- data/test/unit/directive_omit_tag_test.rb +73 -21
- data/test/unit/directive_password_field_test.rb +44 -38
- data/test/unit/directive_registry_test.rb +44 -0
- data/test/unit/directive_replace_test.rb +28 -12
- data/test/unit/directive_stylesheet_link_test.rb +43 -36
- data/test/unit/directive_submit_test.rb +29 -30
- data/test/unit/directive_text_area_test.rb +40 -36
- data/test/unit/directive_text_field_test.rb +44 -38
- data/test/unit/example_directive_child_events_test.rb +41 -0
- data/test/unit/example_test.rb +31 -4
- data/test/unit/file_mio_test.rb +18 -13
- data/test/unit/filter_helpers_test.rb +10 -8
- data/test/unit/find_directive_parent_test.rb +174 -0
- data/test/unit/keyword_expander_test.rb +4 -2
- data/test/unit/mio_test.rb +18 -11
- data/test/unit/mtime_string_hash_mio_tree_test.rb +5 -1
- data/test/unit/parser_test.rb +41 -29
- data/test/unit/pathname_extensions_test.rb +1 -1
- data/test/unit/run_parser_test.rb +2 -2
- data/test/unit/simplified_directive_base_test.rb +256 -0
- data/test/unit/string_hash_mio_test.rb +5 -1
- data/test/unit/template_file_watcher_test.rb +2 -2
- data/test/unit/template_test.rb +221 -46
- metadata +86 -45
- data/lib/masterview/directives/testfilter.rb +0 -55
- data/lib/masterview/extras/init_rails_reparse_checking.rb +0 -62
data/test/unit/mio_test.rb
CHANGED
@@ -6,6 +6,13 @@ require File.join( currentPath, '../../lib/masterview/io' )
|
|
6
6
|
|
7
7
|
class TestMIO < Test::Unit::TestCase
|
8
8
|
|
9
|
+
# bring test subjects into the local name space
|
10
|
+
MIOTrees = MasterView::MIO::MIOTrees
|
11
|
+
FileMIOTree = MasterView::MIO::FileMIOTree
|
12
|
+
StringHashMIOTree = MasterView::MIO::StringHashMIOTree
|
13
|
+
MTimeStringHashMIOTree = MasterView::MIO::MTimeStringHashMIOTree
|
14
|
+
RailsErbCacheMIOTree = MasterView::MIO::RailsErbCacheMIOTree
|
15
|
+
|
9
16
|
MVTestDir = File.expand_path( File.join(File.dirname(__FILE__), '..' ) )
|
10
17
|
TemplateDir = "#{MVTestDir}/tmp/template"
|
11
18
|
TemplateErbDir = "#{MVTestDir}/tmp/erb"
|
@@ -23,20 +30,20 @@ class TestMIO < Test::Unit::TestCase
|
|
23
30
|
# TestWritePathname = Pathname.new(TestWriteFullPath)
|
24
31
|
|
25
32
|
def setup
|
26
|
-
@mio =
|
27
|
-
@mio.foo =
|
28
|
-
@mio.bar =
|
29
|
-
@mio.baz =
|
30
|
-
@mio.msh =
|
31
|
-
@mio.rec =
|
33
|
+
@mio = MIOTrees.new
|
34
|
+
@mio.foo = FileMIOTree.new(FileMIOTemplatePathname, ErbDefaultExtension) #??just use TemplateDir??
|
35
|
+
@mio.bar = FileMIOTree.new(ErbPathname, ErbDefaultExtension) #??just use TemplateErbDir??
|
36
|
+
@mio.baz = StringHashMIOTree.new
|
37
|
+
@mio.msh = MTimeStringHashMIOTree.new
|
38
|
+
@mio.rec = RailsErbCacheMIOTree.new
|
32
39
|
end
|
33
40
|
|
34
41
|
def test_mio_setup
|
35
|
-
assert_kind_of(
|
36
|
-
assert_kind_of(
|
37
|
-
assert_kind_of(
|
38
|
-
assert_kind_of(
|
39
|
-
assert_kind_of(
|
42
|
+
assert_kind_of(FileMIOTree, @mio.foo)
|
43
|
+
assert_kind_of(FileMIOTree, @mio.bar)
|
44
|
+
assert_kind_of(StringHashMIOTree, @mio.baz)
|
45
|
+
assert_kind_of(MTimeStringHashMIOTree, @mio.msh)
|
46
|
+
assert_kind_of(RailsErbCacheMIOTree, @mio.rec)
|
40
47
|
assert_nil(@mio.not_there)
|
41
48
|
assert_equal(FileMIOTemplatePathname.to_s, @mio.foo.to_s)
|
42
49
|
assert_equal(ErbPathname.to_s, @mio.bar.to_s)
|
@@ -5,7 +5,11 @@ currentPath = File.dirname(__FILE__)
|
|
5
5
|
require File.join( currentPath, '../../lib/masterview/io' )
|
6
6
|
|
7
7
|
class TestMTimeStringHashMIO < Test::Unit::TestCase
|
8
|
-
|
8
|
+
|
9
|
+
# bring test subjects into the local name space
|
10
|
+
MIOTrees = MasterView::MIO::MIOTrees
|
11
|
+
MTimeStringHashMIOTree = MasterView::MIO::MTimeStringHashMIOTree
|
12
|
+
MTimeStringMIO = MasterView::MIO::MTimeStringMIO
|
9
13
|
|
10
14
|
TestStringMIOTemplatePathname = Pathname.new('../tmp/template')
|
11
15
|
ErbPathname = Pathname.new('../tmp/erb')
|
data/test/unit/parser_test.rb
CHANGED
@@ -5,36 +5,48 @@ currentPath = File.dirname(__FILE__)
|
|
5
5
|
require File.join( currentPath, '../../lib/masterview' )
|
6
6
|
|
7
7
|
class TestParser < Test::Unit::TestCase
|
8
|
-
|
8
|
+
|
9
|
+
# map references to internal parser implementation classes inot the local name space
|
10
|
+
RenderLevel = MasterView::TemplateProcessing::RenderLevel
|
11
|
+
RenderMode = MasterView::TemplateProcessing::RenderMode
|
12
|
+
DirectiveSet = MasterView::TemplateProcessing::DirectiveSet
|
13
|
+
DirectiveCallStack = MasterView::TemplateProcessing::DirectiveCallStack
|
14
|
+
SimpleRenderHandler = MasterView::TemplateProcessing::SimpleRenderHandler
|
15
|
+
Renderer = MasterView::TemplateProcessing::Renderer
|
16
|
+
Tag = MasterView::TemplateProcessing::Tag
|
17
|
+
|
18
|
+
def setup
|
19
|
+
@renderer = Renderer.new(:output_mio_tree => MasterView::MIO::StringHashMIOTree.new({}, '.rhtml', :logging => true))
|
20
|
+
end
|
9
21
|
|
10
22
|
def test_render_level
|
11
|
-
rl =
|
23
|
+
rl = RenderLevel.new
|
12
24
|
assert_equal [], rl.render_modes
|
13
25
|
|
14
|
-
a =
|
15
|
-
b =
|
16
|
-
rl =
|
26
|
+
a = RenderMode.new
|
27
|
+
b = RenderMode.new
|
28
|
+
rl = RenderLevel.new [a,b]
|
17
29
|
assert_equal [a,b], rl.render_modes
|
18
30
|
|
19
|
-
c =
|
31
|
+
c = RenderMode.new
|
20
32
|
rl.push c
|
21
33
|
assert_equal [a,b,c], rl.render_modes
|
22
34
|
end
|
23
35
|
|
24
36
|
def test_render_mode
|
25
|
-
rm =
|
26
|
-
assert_equal nil, rm.output
|
37
|
+
rm = RenderMode.new
|
38
|
+
assert_equal nil, rm.output
|
27
39
|
assert_equal :normal, rm.mode_type
|
28
40
|
assert_equal [], rm.tags
|
29
41
|
|
30
42
|
a = '/foo/bar'
|
31
|
-
rm =
|
32
|
-
assert_equal a, rm.output
|
43
|
+
rm = RenderMode.new(a)
|
44
|
+
assert_equal a, rm.output
|
33
45
|
assert_equal :normal, rm.mode_type
|
34
46
|
assert_equal [], rm.tags
|
35
47
|
|
36
|
-
rm =
|
37
|
-
assert_equal a, rm.output
|
48
|
+
rm = RenderMode.new(a, :wide)
|
49
|
+
assert_equal a, rm.output
|
38
50
|
assert_equal :wide, rm.mode_type
|
39
51
|
assert_equal [], rm.tags
|
40
52
|
|
@@ -44,7 +56,7 @@ class TestParser < Test::Unit::TestCase
|
|
44
56
|
attributes = { 'bar' => 'baz', 'can' => 'dog' }
|
45
57
|
mode_type = :wide
|
46
58
|
parent = :parent
|
47
|
-
t2 =
|
59
|
+
t2 = Tag.new(directives, tag_name, attributes, mode_type, parent, nil, @renderer)
|
48
60
|
rm.tags << t1 << t2
|
49
61
|
assert_equal [t1,t2], rm.tags
|
50
62
|
assert_equal t2, rm.tag
|
@@ -58,30 +70,30 @@ class TestParser < Test::Unit::TestCase
|
|
58
70
|
end
|
59
71
|
|
60
72
|
def test_dcs
|
61
|
-
dcs =
|
73
|
+
dcs = DirectiveCallStack.new
|
62
74
|
dcs << :a
|
63
75
|
dcs << :b
|
64
76
|
dcs << [:c,:d]
|
65
77
|
assert_equal [:a,:b,:c,:d], dcs.directives_to_call
|
66
|
-
dcs2 =
|
78
|
+
dcs2 = DirectiveCallStack.new
|
67
79
|
dcs2 << :e
|
68
80
|
dcs2 << :f
|
69
81
|
assert_equal [:e,:f], dcs2.directives_to_call
|
70
82
|
dcs << dcs2
|
71
83
|
assert_equal [:a,:b,:c,:d,:e,:f], dcs.directives_to_call
|
72
84
|
|
73
|
-
assert_equal [],
|
85
|
+
assert_equal [], DirectiveCallStack.new.render
|
74
86
|
|
75
87
|
proc1 = lambda { |f| "1" }
|
76
88
|
proc2 = lambda { |f| "2" }
|
77
|
-
dcs3 =
|
89
|
+
dcs3 = DirectiveCallStack.new
|
78
90
|
dcs3 << proc1
|
79
91
|
dcs3 << proc2
|
80
|
-
assert_equal '1', dcs3.render
|
92
|
+
assert_equal '1', dcs3.render
|
81
93
|
end
|
82
94
|
|
83
95
|
def test_directives
|
84
|
-
fs =
|
96
|
+
fs = DirectiveSet.new
|
85
97
|
fs << :a
|
86
98
|
fs << :b
|
87
99
|
fs << [:c, :d]
|
@@ -97,21 +109,21 @@ class TestParser < Test::Unit::TestCase
|
|
97
109
|
end
|
98
110
|
|
99
111
|
def test_simple_render_handler
|
100
|
-
s =
|
101
|
-
dcs =
|
112
|
+
s = SimpleRenderHandler.new
|
113
|
+
dcs = DirectiveCallStack.new
|
102
114
|
directives = [:f1, :f2]
|
103
115
|
tag_name = 'foo'
|
104
116
|
attributes = { 'bar' => 'baz', 'can' => 'dog' }
|
105
117
|
mode_type = :wide
|
106
118
|
parent = :parent
|
107
|
-
t2 =
|
119
|
+
t2 = Tag.new(directives, tag_name, attributes, mode_type, parent, nil, @renderer)
|
108
120
|
dcs.context = { :tag => t2 }
|
109
121
|
ret = s.stag(dcs)
|
110
122
|
assert_equal "<foo", ret[0]
|
111
123
|
assert_equal " bar=\"baz\"", ret[1]
|
112
124
|
assert_equal " can=\"dog\"", ret[2]
|
113
125
|
assert_equal '>', ret[3]
|
114
|
-
|
126
|
+
|
115
127
|
dcs.context[:content_part] = 'hello'
|
116
128
|
assert_equal ['hello'], s.characters(dcs)
|
117
129
|
assert_equal ['<!-- ', 'hello', ' -->'], s.comment(dcs)
|
@@ -120,7 +132,7 @@ class TestParser < Test::Unit::TestCase
|
|
120
132
|
|
121
133
|
attributes = { :can => 'dog', :bar => 'baz' } # test that we can use symbols for keys
|
122
134
|
tag_name = :foo
|
123
|
-
t3 =
|
135
|
+
t3 = Tag.new(directives, tag_name, attributes, mode_type, parent, nil, @renderer)
|
124
136
|
dcs.context = { :tag => t3 }
|
125
137
|
ret = s.stag(dcs)
|
126
138
|
assert_equal "<foo", ret[0]
|
@@ -135,7 +147,7 @@ class TestParser < Test::Unit::TestCase
|
|
135
147
|
attributes = { 'bar' => 'baz', 'can' => 'dog' }
|
136
148
|
mode_type = :wide
|
137
149
|
parent = :parent
|
138
|
-
t =
|
150
|
+
t = Tag.new(directives, tag_name, attributes, mode_type, parent, nil, @renderer)
|
139
151
|
assert_equal [:f1, :f2], t.directives
|
140
152
|
assert_equal tag_name, t.tag_name
|
141
153
|
assert_equal attributes, t.attributes
|
@@ -161,9 +173,9 @@ class TestParser < Test::Unit::TestCase
|
|
161
173
|
assert_equal [[:a,:b], [:c,:d], [:e,:f]], t.data
|
162
174
|
end
|
163
175
|
|
164
|
-
# base, meta, link, hr, br, param, img, area, input, col
|
176
|
+
# base, meta, link, hr, br, param, img, area, input, col
|
165
177
|
def test_simplify_element_names
|
166
|
-
r =
|
178
|
+
r = Renderer.new(:output_mio_tree => MasterView::MIO::StringHashMIOTree.new )
|
167
179
|
assert_equal ['<base', ' />'], r.simplify_empty_elements( ['<base', '>', '</', 'base>'] )
|
168
180
|
assert_equal ['<meta', ' />'], r.simplify_empty_elements( ['<meta', '>', '</', 'meta>'] )
|
169
181
|
assert_equal ['<link', ' />'], r.simplify_empty_elements( ['<link', '>', '</', 'link>'] )
|
@@ -173,7 +185,7 @@ class TestParser < Test::Unit::TestCase
|
|
173
185
|
assert_equal ['<img', ' />'], r.simplify_empty_elements( ['<img', '>', '</', 'img>'] )
|
174
186
|
assert_equal ['<area', ' />'], r.simplify_empty_elements( ['<area', '>', '</', 'area>'] )
|
175
187
|
assert_equal ['<input', ' />'], r.simplify_empty_elements( ['<input', '>', '</', 'input>'] )
|
176
|
-
assert_equal ['<col', ' />'], r.simplify_empty_elements( ['<col', '>', '</', 'col>'] )
|
188
|
+
assert_equal ['<col', ' />'], r.simplify_empty_elements( ['<col', '>', '</', 'col>'] )
|
177
189
|
|
178
190
|
assert_equal ['<script', '>', '</', 'script>'], r.simplify_empty_elements( ['<script', '>', '</', 'script>'] )
|
179
191
|
assert_equal ['<title', '>', '</', 'title>'], r.simplify_empty_elements( ['<title', '>', '</', 'title>'] )
|
@@ -187,5 +199,5 @@ class TestParser < Test::Unit::TestCase
|
|
187
199
|
#todo
|
188
200
|
end
|
189
201
|
|
190
|
-
|
202
|
+
|
191
203
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'test/unit'
|
4
4
|
require 'pathname'
|
5
|
-
require File.join( File.dirname(__FILE__), '../../lib/masterview/
|
5
|
+
require File.join( File.dirname(__FILE__), '../../lib/masterview/core_ext/pathname' )
|
6
6
|
|
7
7
|
class TestPathnameExtensions < Test::Unit::TestCase
|
8
8
|
def test_for_path
|
@@ -15,9 +15,9 @@ class TestParser < Test::Unit::TestCase
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def test_parser_run
|
18
|
-
@template_mio_tree = MasterView::FileMIOTree.new(TestFixturesDir, '.html')
|
18
|
+
@template_mio_tree = MasterView::MIO::FileMIOTree.new(TestFixturesDir, '.html')
|
19
19
|
@template_mio = @template_mio_tree.path(MasterViewHTMLFile)
|
20
|
-
@erb_mio_tree = MasterView::FileMIOTree.new(TmpOutputDir, '.rhtml')
|
20
|
+
@erb_mio_tree = MasterView::MIO::FileMIOTree.new(TmpOutputDir, '.rhtml')
|
21
21
|
MasterView::Parser.parse_mio( @template_mio, @erb_mio_tree)
|
22
22
|
assert File.exist?(TmpOutputDir+'/layouts/product.rhtml')
|
23
23
|
assert File.exist?(TmpOutputDir+'/product/_form.rhtml')
|
@@ -0,0 +1,256 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
currentPath = File.dirname(__FILE__)
|
5
|
+
require File.join( currentPath, '../../lib/masterview' )
|
6
|
+
require File.join( currentPath, '../test_helper' )
|
7
|
+
|
8
|
+
class TestSimplifiedDirectiveBase < Test::Unit::TestCase
|
9
|
+
def test_nothing_yet
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
=begin comment out for now
|
14
|
+
|
15
|
+
class SimplifiedDirectiveExample < MasterView::SimplifiedDirectiveBase
|
16
|
+
end
|
17
|
+
|
18
|
+
class TestSimplifiedDirectiveBase < Test::Unit::TestCase
|
19
|
+
|
20
|
+
def setup
|
21
|
+
@sde = SimplifiedDirectiveExample.new('product, desc, {:foo => :bar}, :readonly => false')
|
22
|
+
@sde.save_directive_call_stack(MasterView::ParserMock.createMockDCS())
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_args
|
26
|
+
@sde.arg :obj
|
27
|
+
@sde.arg :method
|
28
|
+
@sde.arg :options
|
29
|
+
@sde.arg :html_options
|
30
|
+
@sde.arg :not_there
|
31
|
+
assert @sde.instance_variables.include?('@obj')
|
32
|
+
assert @sde.instance_variables.include?('@method')
|
33
|
+
assert @sde.instance_variables.include?('@options')
|
34
|
+
assert @sde.instance_variables.include?('@html_options')
|
35
|
+
assert @sde.instance_variables.include?('@not_there')
|
36
|
+
assert_equal 'product', @sde.instance_variable_get('@obj')
|
37
|
+
assert_equal 'desc', @sde.instance_variable_get('@method')
|
38
|
+
assert_equal '{:foo => :bar}', @sde.instance_variable_get('@options')
|
39
|
+
assert_equal ':readonly => false', @sde.instance_variable_get('@html_options')
|
40
|
+
assert_equal nil, @sde.instance_variable_get('@not_there')
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_arg_quote
|
44
|
+
@sde.arg :obj, :quote => true
|
45
|
+
@sde.arg :method, :quote => false
|
46
|
+
assert_equal '\'product\'', @sde.instance_variable_get('@obj')
|
47
|
+
assert_equal 'desc', @sde.instance_variable_get('@method')
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_prepare_output
|
51
|
+
@sde.arg :obj
|
52
|
+
@sde.arg :method
|
53
|
+
@sde.arg :options
|
54
|
+
@sde.arg :html_options
|
55
|
+
assert_equal 'test', @sde.prepare_output('test')
|
56
|
+
assert_equal 'test product', @sde.prepare_output('test', :obj)
|
57
|
+
assert_equal 'test product, desc', @sde.prepare_output('test', :obj, :method)
|
58
|
+
assert_equal 'test product, desc, {:foo => :bar}', @sde.prepare_output('test', :obj, :method, :options)
|
59
|
+
assert_equal 'test product, desc, {:foo => :bar}, :readonly => false', @sde.prepare_output('test', :obj, :method, :options, :html_options)
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_prepare_output_mixed
|
63
|
+
@sde.arg :obj
|
64
|
+
@sde.arg :method
|
65
|
+
@sde.arg :options
|
66
|
+
@sde.arg :html_options
|
67
|
+
assert_equal 'test product, :foo', @sde.prepare_output('test', :obj, :foo)
|
68
|
+
assert_equal 'test product, :foo, :bar', @sde.prepare_output('test', :obj, :foo, :bar)
|
69
|
+
assert_equal 'test product, desc, {:foo => :bar}, :hello', @sde.prepare_output('test', :obj, :method, :options, :hello)
|
70
|
+
assert_equal 'test product, desc, {:foo => :bar}, :hello, 1', @sde.prepare_output('test', :obj, :method, :options, :hello, 1)
|
71
|
+
assert_equal 'test product, desc, {:foo => :bar}, :hello, 1, [:a, :b]', @sde.prepare_output('test', :obj, :method, :options, :hello, 1, [:a, :b])
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_prepare_output_quote
|
75
|
+
@sde.arg :obj, :quote => true
|
76
|
+
@sde.arg :method, :quote => true
|
77
|
+
@sde.arg :options
|
78
|
+
@sde.arg :html_options
|
79
|
+
assert_equal 'test', @sde.prepare_output('test')
|
80
|
+
assert_equal 'test \'product\'', @sde.prepare_output('test', :obj)
|
81
|
+
assert_equal 'test \'product\', \'desc\'', @sde.prepare_output('test', :obj, :method)
|
82
|
+
assert_equal 'test \'product\', \'desc\', {:foo => :bar}', @sde.prepare_output('test', :obj, :method, :options)
|
83
|
+
assert_equal 'test \'product\', \'desc\', {:foo => :bar}, :readonly => false', @sde.prepare_output('test', :obj, :method, :options, :html_options)
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_prepare_output_middle_nil
|
87
|
+
@sde = SimplifiedDirectiveExample.new('product, desc, {:foo => :bar}, :readonly => false')
|
88
|
+
@sde.save_directive_call_stack(MasterView::ParserMock.createMockDCS())
|
89
|
+
@sde.arg :obj
|
90
|
+
@sde.arg :method
|
91
|
+
@sde.arg :options
|
92
|
+
@sde.arg :html_options
|
93
|
+
@sde.instance_variable_set("@options", nil)
|
94
|
+
assert_equal 'test product, desc', @sde.prepare_output('test', :obj, :method, :options)
|
95
|
+
assert_equal 'test product, desc, nil, :readonly => false', @sde.prepare_output('test', :obj, :method, :options, :html_options)
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_prepare_output_middle_needs_brackets
|
99
|
+
@sde = SimplifiedDirectiveExample.new('product, desc, :foo => :bar')
|
100
|
+
@sde.save_directive_call_stack(MasterView::ParserMock.createMockDCS())
|
101
|
+
@sde.arg :obj
|
102
|
+
@sde.arg :method
|
103
|
+
@sde.arg :options
|
104
|
+
@sde.arg :html_options
|
105
|
+
@sde.instance_variable_set("@html_options", ':hello => :world')
|
106
|
+
assert_equal 'test product, desc, :foo => :bar', @sde.prepare_output('test', :obj, :method, :options)
|
107
|
+
assert_equal 'test product, desc, { :foo => :bar }, :hello => :world', @sde.prepare_output('test', :obj, :method, :options, :html_options)
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_prepare_output_middle_empty_string
|
111
|
+
@sde = SimplifiedDirectiveExample.new('product, desc, :foo => :bar')
|
112
|
+
@sde.save_directive_call_stack(MasterView::ParserMock.createMockDCS())
|
113
|
+
@sde.arg :obj
|
114
|
+
@sde.arg :method
|
115
|
+
@sde.arg :options
|
116
|
+
@sde.arg :html_options
|
117
|
+
@sde.instance_variable_set("@options", '')
|
118
|
+
@sde.instance_variable_set("@html_options", ':hello => :world')
|
119
|
+
assert_equal 'test product, desc', @sde.prepare_output('test', :obj, :method, :options)
|
120
|
+
assert_equal 'test product, desc, nil, :hello => :world', @sde.prepare_output('test', :obj, :method, :options, :html_options)
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_prepare_output_middle_nil_opt_default_string
|
124
|
+
@sde = SimplifiedDirectiveExample.new('product, desc')
|
125
|
+
@sde.save_directive_call_stack(MasterView::ParserMock.createMockDCS())
|
126
|
+
@sde.arg :obj
|
127
|
+
@sde.arg :method
|
128
|
+
@sde.arg :options, :default => '{}'
|
129
|
+
@sde.arg :html_options
|
130
|
+
@sde.instance_variable_set("@html_options", ':readonly => true')
|
131
|
+
assert_equal 'test product, desc', @sde.prepare_output('test', :obj, :method, :options)
|
132
|
+
assert_equal 'test product, desc, {}, :readonly => true', @sde.prepare_output('test', :obj, :method, :options, :html_options)
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_prepare_output_middle_nil_opt_default_hash
|
136
|
+
@sde = SimplifiedDirectiveExample.new('product, desc')
|
137
|
+
@sde.save_directive_call_stack(MasterView::ParserMock.createMockDCS())
|
138
|
+
@sde.arg :obj
|
139
|
+
@sde.arg :method
|
140
|
+
@sde.arg :options, :default => {}
|
141
|
+
@sde.arg :html_options
|
142
|
+
@sde.instance_variable_set("@html_options", ':readonly => true')
|
143
|
+
assert_equal 'test product, desc', @sde.prepare_output('test', :obj, :method, :options)
|
144
|
+
assert_equal 'test product, desc, {}, :readonly => true', @sde.prepare_output('test', :obj, :method, :options, :html_options)
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_prepare_output_middle_nil_opt_default_array
|
148
|
+
@sde = SimplifiedDirectiveExample.new('product, desc')
|
149
|
+
@sde.save_directive_call_stack(MasterView::ParserMock.createMockDCS())
|
150
|
+
@sde.arg :obj
|
151
|
+
@sde.arg :method
|
152
|
+
@sde.arg :options, :default => []
|
153
|
+
@sde.arg :html_options
|
154
|
+
@sde.instance_variable_set("@html_options", ':readonly => true')
|
155
|
+
assert_equal 'test product, desc', @sde.prepare_output('test', :obj, :method, :options)
|
156
|
+
assert_equal 'test product, desc, [], :readonly => true', @sde.prepare_output('test', :obj, :method, :options, :html_options)
|
157
|
+
end
|
158
|
+
|
159
|
+
def test_prepare_output_middle_nil_opt_default_symbol
|
160
|
+
@sde = SimplifiedDirectiveExample.new('product, desc')
|
161
|
+
@sde.save_directive_call_stack(MasterView::ParserMock.createMockDCS())
|
162
|
+
@sde.arg :obj
|
163
|
+
@sde.arg :method
|
164
|
+
@sde.arg :options, :default => :foo
|
165
|
+
@sde.arg :html_options
|
166
|
+
@sde.instance_variable_set("@html_options", ':readonly => true')
|
167
|
+
assert_equal 'test product, desc', @sde.prepare_output('test', :obj, :method, :options)
|
168
|
+
assert_equal 'test product, desc, :foo, :readonly => true', @sde.prepare_output('test', :obj, :method, :options, :html_options)
|
169
|
+
end
|
170
|
+
|
171
|
+
def test_prepare_output_middle_nil_opt_default_fixnum
|
172
|
+
@sde = SimplifiedDirectiveExample.new('product, desc')
|
173
|
+
@sde.save_directive_call_stack(MasterView::ParserMock.createMockDCS())
|
174
|
+
@sde.arg :obj
|
175
|
+
@sde.arg :method
|
176
|
+
@sde.arg :options, :default => 123
|
177
|
+
@sde.arg :html_options
|
178
|
+
@sde.instance_variable_set("@html_options", ':readonly => true')
|
179
|
+
assert_equal 'test product, desc', @sde.prepare_output('test', :obj, :method, :options)
|
180
|
+
assert_equal 'test product, desc, 123, :readonly => true', @sde.prepare_output('test', :obj, :method, :options, :html_options)
|
181
|
+
end
|
182
|
+
|
183
|
+
def test_prepare_output_middle_nil_opt_default_hash_mixed
|
184
|
+
@sde = SimplifiedDirectiveExample.new('product, desc')
|
185
|
+
@sde.save_directive_call_stack(MasterView::ParserMock.createMockDCS())
|
186
|
+
@sde.arg :obj
|
187
|
+
@sde.arg :method
|
188
|
+
@sde.arg :options, :default => {}
|
189
|
+
assert_equal 'test product, desc', @sde.prepare_output('test', :obj, :method, :options)
|
190
|
+
assert_equal 'test product, desc, {}, 123', @sde.prepare_output('test', :obj, :method, :options, 123)
|
191
|
+
end
|
192
|
+
|
193
|
+
def test_merge_common_str
|
194
|
+
@sde.element_attrs['class'] = 'red'
|
195
|
+
@sde.element_attrs['id'] = 'id1'
|
196
|
+
@sde.arg :obj
|
197
|
+
@sde.arg :method
|
198
|
+
@sde.arg :options, :default => {}
|
199
|
+
@sde.arg :html_options, :append_element_attrs => [:common_html]
|
200
|
+
assert_equal ':readonly => false, :class => "red", :id => "id1"', @sde.instance_variable_get('@html_options')
|
201
|
+
end
|
202
|
+
|
203
|
+
def test_merge_common_array
|
204
|
+
@sde.element_attrs['class'] = 'red'
|
205
|
+
@sde.element_attrs['id'] = 'id1'
|
206
|
+
@sde.arg :obj
|
207
|
+
@sde.arg :method
|
208
|
+
@sde.arg :options, :default => {}
|
209
|
+
@sde.arg :html_options, :append_element_attrs => [:common_html]
|
210
|
+
assert_equal ':readonly => false, :class => "red", :id => "id1"', @sde.instance_variable_get('@html_options')
|
211
|
+
end
|
212
|
+
|
213
|
+
def test_render_nothing
|
214
|
+
@sde.arg :obj
|
215
|
+
assert_equal nil, @sde.render_nothing
|
216
|
+
end
|
217
|
+
|
218
|
+
def test_render
|
219
|
+
@sde.arg :obj
|
220
|
+
|
221
|
+
result = @sde.render @sde.prepare_output 'test', :obj
|
222
|
+
assert_equal ['test product'], result
|
223
|
+
|
224
|
+
result = @sde.render @sde.prepare_output 'hello', :obj
|
225
|
+
assert_equal ['test product', 'hello product'], result
|
226
|
+
end
|
227
|
+
|
228
|
+
def test_render_erb_content
|
229
|
+
@sde.arg :obj
|
230
|
+
|
231
|
+
result = @sde.render @sde.erb_content 'test', :obj
|
232
|
+
assert_equal ['<%= test product %>'], result
|
233
|
+
|
234
|
+
result = @sde.render @sde.erb_content 'hello', :obj
|
235
|
+
assert_equal ['<%= test product %>', '<%= hello product %>'], result
|
236
|
+
end
|
237
|
+
|
238
|
+
def test_merge_hash_into_str
|
239
|
+
assert_equal '', @sde.merge_hash_into_str({}, '')
|
240
|
+
assert_equal ':foo => :bar', @sde.merge_hash_into_str({}, ':foo => :bar')
|
241
|
+
assert_equal ':foo => :bar', @sde.merge_hash_into_str({:foo => :bar}, '')
|
242
|
+
assert_equal ':foo => :baz, :foo => :bar', @sde.merge_hash_into_str({:foo => :bar}, ':foo => :baz')
|
243
|
+
assert_equal ':foo => :baz, :foo => :bar, :goo => :hello', @sde.merge_hash_into_str({:goo => :hello, :foo => :bar}, ':foo => :baz')
|
244
|
+
assert_equal '"class" => "red"', @sde.merge_hash_into_str({'class' => 'red'}, '')
|
245
|
+
|
246
|
+
assert_equal '{}', @sde.merge_hash_into_str({}, '{}')
|
247
|
+
assert_equal '{:foo => :bar}', @sde.merge_hash_into_str({}, '{:foo => :bar}')
|
248
|
+
assert_equal '{:foo => :bar}', @sde.merge_hash_into_str({:foo => :bar}, '{ }')
|
249
|
+
assert_equal '{:foo => :baz, :foo => :bar}', @sde.merge_hash_into_str({:foo => :bar}, ' {:foo => :baz} ')
|
250
|
+
assert_equal '{:foo => :baz, :foo => :bar, :goo => :hello}', @sde.merge_hash_into_str({:goo => :hello, :foo => :bar}, '{:foo => :baz}')
|
251
|
+
assert_equal '{"class" => "red"}', @sde.merge_hash_into_str({'class' => 'red'}, '{}')
|
252
|
+
end
|
253
|
+
|
254
|
+
end
|
255
|
+
|
256
|
+
=end
|
@@ -5,7 +5,11 @@ currentPath = File.dirname(__FILE__)
|
|
5
5
|
require File.join( currentPath, '../../lib/masterview/io' )
|
6
6
|
|
7
7
|
class TestStringHashMIO < Test::Unit::TestCase
|
8
|
-
|
8
|
+
|
9
|
+
# bring test subjects into the local name space
|
10
|
+
MIOTrees = MasterView::MIO::MIOTrees
|
11
|
+
StringHashMIOTree = MasterView::MIO::StringHashMIOTree
|
12
|
+
StringMIO = MasterView::MIO::StringMIO
|
9
13
|
|
10
14
|
MVTestDir = File.expand_path( File.join(File.dirname(__FILE__), '..' ) )
|
11
15
|
TemplateDir = "#{MVTestDir}/tmp/template"
|
@@ -38,8 +38,8 @@ class TestTemplateWatcher < Test::Unit::TestCase
|
|
38
38
|
STDOUT.puts "...installed test fixture #{TestFixtureFile}" if DEBUG_TRACE
|
39
39
|
STDOUT.puts "...#{TestSubjectFileShortName} template timestamp=#{File.mtime(TestSubjectFile)}" if DEBUG_TRACE
|
40
40
|
end
|
41
|
-
@template_mio_tree = MasterView::FileMIOTree.new(TemplateSrcDir, '.html')
|
42
|
-
@output_mio_tree = MasterView::FileMIOTree.new(TemplateDstDir, '.rhtml')
|
41
|
+
@template_mio_tree = MasterView::MIO::FileMIOTree.new(TemplateSrcDir, '.html')
|
42
|
+
@output_mio_tree = MasterView::MIO::FileMIOTree.new(TemplateDstDir, '.rhtml')
|
43
43
|
end
|
44
44
|
|
45
45
|
def test_a_parse_template_on_startup
|