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
@@ -3,79 +3,83 @@
|
|
3
3
|
require 'test/unit'
|
4
4
|
currentPath = File.dirname(__FILE__)
|
5
5
|
require File.join( currentPath, '../../lib/masterview' )
|
6
|
-
require File.join( currentPath, '../../lib/masterview/directives/text_area')
|
6
|
+
#require File.join( currentPath, '../../lib/masterview/directives/text_area')
|
7
|
+
require File.join( currentPath, '../directive_test_helper' )
|
8
|
+
DirectiveTestHelpers.load_masterview_directive('text_area')
|
7
9
|
|
8
10
|
class TestTextArea < Test::Unit::TestCase
|
9
|
-
include
|
11
|
+
include DirectiveTestHelpers
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
+
TextArea = MasterView::Directives::TextArea # test subject
|
14
|
+
|
15
|
+
ELEMENT_TAG = 'input'
|
16
|
+
|
17
|
+
def test_metadata
|
18
|
+
assert_equal MasterView::ConfigSettings.namespace_prefix, TextArea.namespace_prefix
|
19
|
+
assert_equal 'text_area', TextArea.attribute_name
|
13
20
|
end
|
14
21
|
|
15
|
-
def
|
22
|
+
def create_element_with_text_area_directive(obj, method, other_attr_values, attributes)
|
23
|
+
|
16
24
|
attr_value = "#{obj}, #{method}"
|
17
|
-
attr_value << ', ' <<
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
dcs.context[:tag].content = "hello world"
|
25
|
-
dcs.render
|
26
|
-
end
|
25
|
+
attr_value << ', ' << other_attr_values unless other_attr_values.nil?
|
26
|
+
|
27
|
+
input_tag = create_template_element ELEMENT_TAG,
|
28
|
+
:attributes => attributes,
|
29
|
+
:content => 'hello world'
|
30
|
+
create_directive TextArea, attr_value
|
31
|
+
assert_equal '', render_element_event(:stag)
|
27
32
|
|
28
|
-
def test_normal
|
29
|
-
obj = ':product'
|
30
|
-
method = ':price'
|
31
|
-
ret = text_area_exec(obj, method, nil, {} )
|
32
|
-
assert_equal "<%= text_area #{obj}, #{method} %>", ret
|
33
33
|
end
|
34
34
|
|
35
|
-
def
|
35
|
+
def test_normal
|
36
36
|
obj = ':product'
|
37
37
|
method = ':price'
|
38
|
-
|
39
|
-
|
38
|
+
create_element_with_text_area_directive(obj, method, nil, {} )
|
39
|
+
expected_content = "<%= text_area( #{obj}, #{method} ) %>"
|
40
|
+
assert_equal expected_content, render_element_event(:etag)
|
40
41
|
end
|
41
42
|
|
42
43
|
def test_rows
|
43
44
|
obj = ':product'
|
44
45
|
method = ':price'
|
45
|
-
|
46
|
-
|
46
|
+
create_element_with_text_area_directive(obj, method, nil, { 'rows' => '4'} )
|
47
|
+
expected_content = "<%= text_area( #{obj}, #{method}, :rows => 4 ) %>"
|
48
|
+
assert_equal expected_content, render_element_event(:etag)
|
47
49
|
end
|
48
50
|
|
49
51
|
def test_cols
|
50
52
|
obj = ':product'
|
51
53
|
method = ':price'
|
52
|
-
|
53
|
-
|
54
|
+
create_element_with_text_area_directive(obj, method, nil, { 'cols' => 6 } )
|
55
|
+
expected_content = "<%= text_area( #{obj}, #{method}, :cols => 6 ) %>"
|
56
|
+
assert_equal expected_content, render_element_event(:etag)
|
54
57
|
end
|
55
58
|
|
56
59
|
def test_all
|
57
60
|
obj = ':product'
|
58
61
|
method = ':price'
|
59
|
-
|
60
|
-
{
|
61
|
-
'rows' => 4, 'cols' => 6, 'disabled' => 'disabled',
|
62
|
+
create_element_with_text_area_directive(obj, method, nil,
|
63
|
+
{
|
64
|
+
'rows' => 4, 'cols' => 6, 'disabled' => 'disabled',
|
62
65
|
'readonly' => 'readonly', 'class' => 'classfoo', 'style' => 'stylebar',
|
63
66
|
'tabindex' => 'tab1', 'accesskey' => 'ak2'
|
64
67
|
} )
|
65
|
-
|
68
|
+
expected_content = "<%= text_area( #{obj}, #{method}, :accesskey => \"ak2\", :class => \"classfoo\", :cols => 6, :disabled => true, :readonly => true, :rows => 4, :style => \"stylebar\", :tabindex => \"tab1\" ) %>"
|
69
|
+
assert_equal expected_content, render_element_event(:etag)
|
66
70
|
end
|
67
71
|
|
68
72
|
def test_all_uc
|
69
73
|
obj = ':product'
|
70
74
|
method = ':price'
|
71
|
-
|
72
|
-
{
|
73
|
-
'ROWS' => 4, 'COLS' => 6, 'DISABLED' => 'DISABLED',
|
75
|
+
create_element_with_text_area_directive(obj, method, nil,
|
76
|
+
{
|
77
|
+
'ROWS' => 4, 'COLS' => 6, 'DISABLED' => 'DISABLED',
|
74
78
|
'READONLY' => 'readonly', 'CLASS' => 'classfoo', 'STYLE' => 'stylebar',
|
75
79
|
'TABINDEX' => 'tab1', 'ACCESSKEY' => 'ak2'
|
76
80
|
} )
|
77
|
-
|
81
|
+
expected_content = "<%= text_area( #{obj}, #{method}, :accesskey => \"ak2\", :class => \"classfoo\", :cols => 6, :disabled => true, :readonly => true, :rows => 4, :style => \"stylebar\", :tabindex => \"tab1\" ) %>"
|
82
|
+
assert_equal expected_content, render_element_event(:etag)
|
78
83
|
end
|
79
84
|
|
80
|
-
|
81
85
|
end
|
@@ -3,87 +3,93 @@
|
|
3
3
|
require 'test/unit'
|
4
4
|
currentPath = File.dirname(__FILE__)
|
5
5
|
require File.join( currentPath, '../../lib/masterview' )
|
6
|
-
require File.join( currentPath, '../../lib/masterview/directives/text_field')
|
6
|
+
#require File.join( currentPath, '../../lib/masterview/directives/text_field')
|
7
|
+
require File.join( currentPath, '../directive_test_helper' )
|
8
|
+
DirectiveTestHelpers.load_masterview_directive('text_field')
|
7
9
|
|
8
10
|
class TestTextField < Test::Unit::TestCase
|
9
|
-
include
|
11
|
+
include DirectiveTestHelpers
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
+
TextField = MasterView::Directives::TextField # test subject
|
14
|
+
|
15
|
+
ELEMENT_TAG = 'input'
|
16
|
+
|
17
|
+
def test_metadata
|
18
|
+
assert_equal MasterView::ConfigSettings.namespace_prefix, TextField.namespace_prefix
|
19
|
+
assert_equal 'text_field', TextField.attribute_name
|
13
20
|
end
|
14
21
|
|
15
|
-
def
|
22
|
+
def create_element_with_text_field_directive(obj, method, other_attr_values, attributes)
|
23
|
+
|
16
24
|
attr_value = "#{obj}, #{method}"
|
17
|
-
attr_value << ', ' <<
|
18
|
-
tag = MasterView::Tag.new(@directives, 'input', options, :normal, nil)
|
19
|
-
@directives.directives = []
|
20
|
-
@directives << Text_field.new(attr_value)
|
21
|
-
assert_equal nil, @directives.determine_dcs(:stag).render
|
22
|
-
dcs = @directives.determine_dcs(:etag)
|
23
|
-
dcs.context = tag.create_context
|
24
|
-
dcs.context[:tag].content = "hello world"
|
25
|
-
dcs.render
|
26
|
-
end
|
25
|
+
attr_value << ', ' << other_attr_values unless other_attr_values.nil?
|
27
26
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
assert_equal
|
27
|
+
input_tag = create_template_element ELEMENT_TAG,
|
28
|
+
:attributes => attributes,
|
29
|
+
:content => 'hello world'
|
30
|
+
create_directive TextField, attr_value
|
31
|
+
assert_equal '', render_element_event(:stag)
|
32
|
+
#
|
33
33
|
end
|
34
34
|
|
35
|
-
def
|
35
|
+
def test_normal
|
36
36
|
obj = ':product'
|
37
37
|
method = ':price'
|
38
|
-
|
39
|
-
|
38
|
+
create_element_with_text_field_directive(obj, method, nil, { 'type' => 'text', 'value' => 'fake text' } )
|
39
|
+
expected_content = "<%= text_field( #{obj}, #{method} ) %>"
|
40
|
+
assert_equal expected_content, render_element_event(:etag)
|
40
41
|
end
|
41
42
|
|
42
43
|
def test_disabled
|
43
44
|
obj = ':product'
|
44
45
|
method = ':price'
|
45
|
-
|
46
|
-
|
46
|
+
create_element_with_text_field_directive(obj, method, nil, { 'type' => 'text', 'value' => 'fake text', 'disabled' => 'disabled'} )
|
47
|
+
expected_content = "<%= text_field( #{obj}, #{method}, :disabled => true ) %>"
|
48
|
+
assert_equal expected_content, render_element_event(:etag)
|
47
49
|
end
|
48
50
|
|
49
51
|
def test_size
|
50
52
|
obj = ':product'
|
51
53
|
method = ':price'
|
52
|
-
|
53
|
-
|
54
|
+
create_element_with_text_field_directive(obj, method, nil, { 'type' => 'text', 'value' => 'fake text', 'size' => '10' } )
|
55
|
+
expected_content = "<%= text_field( #{obj}, #{method}, :size => 10 ) %>"
|
56
|
+
assert_equal expected_content, render_element_event(:etag)
|
54
57
|
end
|
55
58
|
|
56
59
|
def test_maxlength
|
57
60
|
obj = ':product'
|
58
61
|
method = ':price'
|
59
|
-
|
60
|
-
|
62
|
+
create_element_with_text_field_directive(obj, method, nil, { 'type' => 'text', 'value' => 'fake text', 'maxlength' => '21' } )
|
63
|
+
expected_content = "<%= text_field( #{obj}, #{method}, :maxlength => 21 ) %>"
|
64
|
+
assert_equal expected_content, render_element_event(:etag)
|
61
65
|
end
|
62
66
|
|
63
67
|
def test_all
|
64
68
|
obj = ':product'
|
65
69
|
method = ':price'
|
66
|
-
|
67
|
-
{
|
68
|
-
'type' => 'text', 'value' => 'fake text', 'disabled' => 'disabled',
|
69
|
-
'size' => '10', 'maxlength' => '21',
|
70
|
+
create_element_with_text_field_directive(obj, method, nil,
|
71
|
+
{
|
72
|
+
'type' => 'text', 'value' => 'fake text', 'disabled' => 'disabled',
|
73
|
+
'size' => '10', 'maxlength' => '21',
|
70
74
|
'readonly' => 'readonly', 'class' => 'classfoo', 'style' => 'stylebar',
|
71
75
|
'tabindex' => 'tab1', 'accesskey' => 'ak2'
|
72
76
|
} )
|
73
|
-
|
77
|
+
expected_content = "<%= text_field( #{obj}, #{method}, :accesskey => \"ak2\", :class => \"classfoo\", :disabled => true, :maxlength => 21, :readonly => true, :size => 10, :style => \"stylebar\", :tabindex => \"tab1\" ) %>"
|
78
|
+
assert_equal expected_content, render_element_event(:etag)
|
74
79
|
end
|
75
80
|
|
76
81
|
def test_all_uc
|
77
82
|
obj = ':product'
|
78
83
|
method = ':price'
|
79
|
-
|
80
|
-
{
|
81
|
-
'type' => 'text', 'value' => 'fake text', 'DISABLED' => 'DISABLED',
|
84
|
+
create_element_with_text_field_directive(obj, method, nil,
|
85
|
+
{
|
86
|
+
'type' => 'text', 'value' => 'fake text', 'DISABLED' => 'DISABLED',
|
82
87
|
'SIZE' => '10', 'MAXLENGTH' => '21',
|
83
88
|
'READONLY' => 'readonly', 'CLASS' => 'classfoo', 'STYLE' => 'stylebar',
|
84
89
|
'TABINDEX' => 'tab1', 'ACCESSKEY' => 'ak2'
|
85
90
|
} )
|
86
|
-
|
91
|
+
expected_content = "<%= text_field( #{obj}, #{method}, :accesskey => \"ak2\", :class => \"classfoo\", :disabled => true, :maxlength => 21, :readonly => true, :size => 10, :style => \"stylebar\", :tabindex => \"tab1\" ) %>"
|
92
|
+
assert_equal expected_content, render_element_event(:etag)
|
87
93
|
end
|
88
94
|
|
89
95
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
currentPath = File.dirname(__FILE__)
|
5
|
+
testDirPath = File.join( currentPath, '..' )
|
6
|
+
require File.join( currentPath, '../../lib/masterview' )
|
7
|
+
require File.join( testDirPath, 'test_helper' )
|
8
|
+
require File.join( testDirPath, 'directive_test_helper' )
|
9
|
+
DirectiveTestHelpers.load_directive('test_directive_events', "#{testDirPath}/fixtures/directives")
|
10
|
+
|
11
|
+
class TestTestDirective < Test::Unit::TestCase
|
12
|
+
include DirectiveTestHelpers
|
13
|
+
|
14
|
+
TestEventsDirective = MasterView::DirectiveTests::TestEventsDirective # test subject
|
15
|
+
|
16
|
+
def setup
|
17
|
+
MasterView::IOMgr.erb = MasterView::MIO::StringHashMIOTree.new({}, '.rhtml', :logging => true)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_metadata
|
21
|
+
check_metadata_keys TestEventsDirective
|
22
|
+
check_metadata_values TestEventsDirective, 'mvtest', 'test_events'
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_test_directive
|
26
|
+
template = <<-END
|
27
|
+
<div mv:generate='foo/bar'>
|
28
|
+
<head mvtest:test_events="foo">
|
29
|
+
<!-- wow -->
|
30
|
+
<![CDATA[ mycdata ]]>
|
31
|
+
<title>hello</title>
|
32
|
+
</head>
|
33
|
+
</div>
|
34
|
+
END
|
35
|
+
expected = {
|
36
|
+
'foo/bar' => "<div>stag <head>stagend charsstart charsend commentstart <!-- wow -->commentend charsstart charsend cdatastart <![CDATA[ mycdata ]]>cdataend charsstart charsend before_child_title_stag <title>foo</title>charsstart charsend etag </head>etagend </div>"
|
37
|
+
}
|
38
|
+
assert_template_result expected, template
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
data/test/unit/example_test.rb
CHANGED
@@ -1,11 +1,38 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
+
# Example of the basic structure of a directive unit test
|
4
|
+
# The location of lib/masterview code base and the mv test directory
|
5
|
+
# depends on your development system configuration,
|
6
|
+
# as does the location of your directive implementation class.
|
7
|
+
|
8
|
+
# you need to customize these root dir references for your configuration
|
9
|
+
mv_installation_dir = File.expand_path(File.join( File.dirname(__FILE__), '../..' ))
|
10
|
+
directives_dir = File.join( mv_installation_dir, 'test/fixtures/directives' )
|
11
|
+
|
12
|
+
# standard imports for a directive unit test: Test::Unit, masterview, and
|
13
|
+
# # your directive class along with the DirectiveTestHelpers test framework.
|
3
14
|
require 'test/unit'
|
4
|
-
|
5
|
-
require File.join(
|
15
|
+
require File.join( mv_installation_dir, 'lib/masterview' ) # masterview engine
|
16
|
+
require File.join( mv_installation_dir, 'test/directive_test_helper' )
|
17
|
+
DirectiveTestHelpers.load_directive('id_check', directives_dir)
|
6
18
|
|
7
19
|
class TestExample < Test::Unit::TestCase
|
8
|
-
include
|
9
|
-
|
20
|
+
include DirectiveTestHelpers
|
21
|
+
|
22
|
+
IdCheck = MasterView::DirectiveTests::IdCheck # test subject
|
23
|
+
|
24
|
+
ELEMENT_TAG = 'div'
|
25
|
+
|
26
|
+
def test_metadata
|
27
|
+
# addon directives map to the mvx: namespace by default
|
28
|
+
assert_equal MasterView::ConfigSettings.namespace_prefix_extensions, IdCheck.namespace_prefix
|
29
|
+
assert_equal MasterView::ConfigSettings.namespace_prefix_extensions, IdCheck.namespace_name+':'
|
30
|
+
assert_equal 'id_check', IdCheck.attribute_name
|
31
|
+
assert_equal "#{MasterView::ConfigSettings.namespace_prefix_extensions}id_check", IdCheck.attribute_qname
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_something
|
35
|
+
#put a test case to exercise your directive's processing here
|
10
36
|
end
|
37
|
+
|
11
38
|
end
|
data/test/unit/file_mio_test.rb
CHANGED
@@ -5,7 +5,12 @@ currentPath = File.dirname(__FILE__)
|
|
5
5
|
require File.join( currentPath, '../../lib/masterview/io' )
|
6
6
|
|
7
7
|
class TestFileMIO < 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
|
+
FileMIO = MasterView::MIO::FileMIO
|
13
|
+
InvalidIOPathError = MasterView::InvalidIOPathError
|
9
14
|
|
10
15
|
MVTestDir = File.expand_path( File.join(File.dirname(__FILE__), '..' ) )
|
11
16
|
TemplateDir = "#{MVTestDir}/tmp/template"
|
@@ -39,18 +44,18 @@ class TestFileMIO < Test::Unit::TestCase
|
|
39
44
|
|
40
45
|
# ensure that sandbox limits writing to files outside of root path even if dot dot exists in path
|
41
46
|
def test_sandbox_dotdot
|
42
|
-
assert_raise(
|
43
|
-
assert_raise(
|
44
|
-
assert_raise(
|
45
|
-
assert_raise(
|
46
|
-
assert_raise(
|
47
|
-
assert_raise(
|
48
|
-
assert_raise(
|
49
|
-
assert_raise(
|
50
|
-
assert_raise(
|
51
|
-
assert_raise(
|
52
|
-
assert_raise(
|
53
|
-
assert_raise(
|
47
|
+
assert_raise(InvalidIOPathError){ f = IOMgr.template.path( '../bad') }
|
48
|
+
assert_raise(InvalidIOPathError){ f = IOMgr.template.path( 'bad/../dog/../../foo') }
|
49
|
+
assert_raise(InvalidIOPathError){ f = IOMgr.template.path( 'bad/../../foo') }
|
50
|
+
assert_raise(InvalidIOPathError){ f = IOMgr.template.path( 'bad/cat/../../../dog') }
|
51
|
+
assert_raise(InvalidIOPathError){ f = IOMgr.template.path( '/bad/foo') }
|
52
|
+
assert_raise(InvalidIOPathError){ f = IOMgr.template.path( '/bad') }
|
53
|
+
assert_raise(InvalidIOPathError){ f = IOMgr.template.path( '../bad.cat') }
|
54
|
+
assert_raise(InvalidIOPathError){ f = IOMgr.template.path( 'bad/../dot/../../foo.cat') }
|
55
|
+
assert_raise(InvalidIOPathError){ f = IOMgr.template.path( 'bad/../../foo.cat') }
|
56
|
+
assert_raise(InvalidIOPathError){ f = IOMgr.template.path( 'bad/cat/../../../dog.cat') }
|
57
|
+
assert_raise(InvalidIOPathError){ f = IOMgr.template.path( '/bad/foo.cat') }
|
58
|
+
assert_raise(InvalidIOPathError){ f = IOMgr.template.path( '/bad.cat') }
|
54
59
|
end
|
55
60
|
|
56
61
|
def test_create_foo
|
@@ -7,6 +7,7 @@ require File.join( currentPath, '../../lib/masterview' )
|
|
7
7
|
class TestDirectiveHelpers < Test::Unit::TestCase
|
8
8
|
include MasterView::Directives
|
9
9
|
include MasterView::DirectiveHelpers
|
10
|
+
include MasterView::ParserHelpers
|
10
11
|
|
11
12
|
def test_parse_eval_into_array_a
|
12
13
|
a = parse_eval_into_array("hello, world")
|
@@ -129,14 +130,15 @@ class TestDirectiveHelpers < Test::Unit::TestCase
|
|
129
130
|
assert_equal "foo/bar", find_string_val_in_string_hash("hello, :partial => 'foo/bar'", :partial)
|
130
131
|
end
|
131
132
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
133
|
+
#DEPRECATED
|
134
|
+
# def test_remove_prepended_strings
|
135
|
+
# assert_equal ":foo => 'bar', :baz => :cat", remove_prepended_strings( "hello, world, :foo => 'bar', :baz => :cat" )
|
136
|
+
# assert_equal ":foo => 'bar', :baz => :cat", remove_prepended_strings( "'hello', 'world', :foo => 'bar', :baz => :cat" )
|
137
|
+
# assert_equal ":foo => 'bar', :baz => :cat", remove_prepended_strings( "hello, 'world', :foo => 'bar', :baz => :cat" )
|
138
|
+
# assert_equal ":foo => 'bar', :baz => :cat", remove_prepended_strings( "hello, world, :foo => 'bar', :baz => :cat" )
|
139
|
+
# assert_equal "{:foo => 'bar', :baz => :cat}", remove_prepended_strings( "hello, world, {:foo => 'bar', :baz => :cat}" )
|
138
140
|
|
139
|
-
|
140
|
-
|
141
|
+
# assert_equal ':action => :add, :id => %Q[srcitem_#{srcitem.pkey}]', remove_prepended_strings( 'hello, world, :action => :add, :id => %Q[srcitem_#{srcitem.pkey}]' )
|
142
|
+
# end
|
141
143
|
|
142
144
|
end
|
@@ -0,0 +1,174 @@
|
|
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 Parent < MasterView::DirectiveBase
|
9
|
+
|
10
|
+
metadata :namespace => 'exa',
|
11
|
+
:priority => 'High',
|
12
|
+
:category => 'example',
|
13
|
+
:description => 'Example of a parent directive which takes input from its children'
|
14
|
+
|
15
|
+
def initialize(dcs)
|
16
|
+
super
|
17
|
+
@children_ids = []
|
18
|
+
end
|
19
|
+
|
20
|
+
def add_child_id(id)
|
21
|
+
@children_ids.push id
|
22
|
+
end
|
23
|
+
|
24
|
+
event :after_etag do
|
25
|
+
render @children_ids.inspect
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
class Child < MasterView::DirectiveBase
|
31
|
+
|
32
|
+
metadata :namespace => 'exa',
|
33
|
+
:category => 'example',
|
34
|
+
:description => 'Example of a child directive which communicates with the parent'
|
35
|
+
|
36
|
+
event :stag do
|
37
|
+
parent = find_parent_directive(Parent)
|
38
|
+
parent.add_child_id(attr_value) if parent
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
class ChildWithBlock < MasterView::DirectiveBase
|
44
|
+
|
45
|
+
metadata :namespace => 'exa',
|
46
|
+
:category => 'example',
|
47
|
+
:description => 'Example of a child directive which contains a filter block which communicates with the parent'
|
48
|
+
|
49
|
+
event :stag do
|
50
|
+
parent = find_parent_directive(Parent){ |d| d.attr_value=="hello" }
|
51
|
+
parent.add_child_id(attr_value) if parent
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
class TestFindDirectiveParent < Test::Unit::TestCase
|
58
|
+
|
59
|
+
def setup
|
60
|
+
MasterView::IOMgr.erb = MasterView::MIO::StringHashMIOTree.new({}, '.rhtml', :logging => true)
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
def test_find_multiple_levels
|
65
|
+
template = <<-END
|
66
|
+
<div mv:generate='foo/bar'>
|
67
|
+
<div exa:parent="hello">
|
68
|
+
<one exa:child="a">Hello</one>
|
69
|
+
<two>
|
70
|
+
<two1 exa:child="b">World</two1>
|
71
|
+
<two1 exa:child="c">World</two1>
|
72
|
+
</two>
|
73
|
+
</div>
|
74
|
+
</div>
|
75
|
+
END
|
76
|
+
expected = {
|
77
|
+
'foo/bar' => %q{<div><div><one>Hello</one><two><two1>World</two1><two1>World</two1></two></div>["a", "b", "c"] </div>}
|
78
|
+
}
|
79
|
+
assert_template_result expected, template
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_find_checking_dir_class
|
83
|
+
template = <<-END
|
84
|
+
<div mv:generate='foo/bar'>
|
85
|
+
<div exa:parent="hello">
|
86
|
+
<one exa:child="a">Hello</one>
|
87
|
+
<two mv:attr=":id => '1'">
|
88
|
+
<two1 exa:child="b">World</two1>
|
89
|
+
<two1 exa:child="c">World</two1>
|
90
|
+
</two>
|
91
|
+
</div>
|
92
|
+
</div>
|
93
|
+
END
|
94
|
+
expected = {
|
95
|
+
'foo/bar' => %q{<div><div><one>Hello</one><two id="1"><two1>World</two1><two1>World</two1></two></div>["a", "b", "c"] </div>}
|
96
|
+
}
|
97
|
+
assert_template_result expected, template
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
def test_find_multiple_parents
|
102
|
+
template = <<-END
|
103
|
+
<div mv:generate='foo/bar'>
|
104
|
+
<div exa:parent="hello">
|
105
|
+
<one exa:child="a">Hello</one>
|
106
|
+
<two exa:parent="wow">
|
107
|
+
<two1 exa:child="b">World</two1>
|
108
|
+
<two1 exa:child="c">World</two1>
|
109
|
+
</two>
|
110
|
+
</div>
|
111
|
+
</div>
|
112
|
+
END
|
113
|
+
expected = {
|
114
|
+
'foo/bar' => %q{<div><div><one>Hello</one><two><two1>World</two1><two1>World</two1></two>["b", "c"] </div>["a"] </div>}
|
115
|
+
}
|
116
|
+
assert_template_result expected, template
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
def test_find_parent_not_found
|
121
|
+
template = <<-END
|
122
|
+
<div mv:generate='foo/bar'>
|
123
|
+
<div>
|
124
|
+
<one exa:child="a">Hello</one>
|
125
|
+
<two>
|
126
|
+
<two1 exa:child="b">World</two1>
|
127
|
+
<two1 exa:child="c">World</two1>
|
128
|
+
</two>
|
129
|
+
</div>
|
130
|
+
</div>
|
131
|
+
END
|
132
|
+
expected = {
|
133
|
+
'foo/bar' => %q{<div><div><one>Hello</one><two><two1>World</two1><two1>World</two1></two></div></div>}
|
134
|
+
}
|
135
|
+
assert_template_result expected, template
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_find_multiple_parents_using_filter_block
|
139
|
+
template = <<-END
|
140
|
+
<div mv:generate='foo/bar'>
|
141
|
+
<div exa:parent="hello">
|
142
|
+
<one exa:child_with_block="a">Hello</one>
|
143
|
+
<two exa:parent="wow">
|
144
|
+
<two1 exa:child_with_block="b">World</two1>
|
145
|
+
<two1 exa:child_with_block="c">World</two1>
|
146
|
+
</two>
|
147
|
+
</div>
|
148
|
+
</div>
|
149
|
+
END
|
150
|
+
expected = {
|
151
|
+
'foo/bar' => %q{<div><div><one>Hello</one><two><two1>World</two1><two1>World</two1></two>[] </div>["a", "b", "c"] </div>}
|
152
|
+
}
|
153
|
+
assert_template_result expected, template
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_find_multiple_parents_using_filter_block_not_found
|
157
|
+
template = <<-END
|
158
|
+
<div mv:generate='foo/bar'>
|
159
|
+
<div exa:parent="notfound">
|
160
|
+
<one exa:child_with_block="a">Hello</one>
|
161
|
+
<two exa:parent="wow">
|
162
|
+
<two1 exa:child_with_block="b">World</two1>
|
163
|
+
<two1 exa:child_with_block="c">World</two1>
|
164
|
+
</two>
|
165
|
+
</div>
|
166
|
+
</div>
|
167
|
+
END
|
168
|
+
expected = {
|
169
|
+
'foo/bar' => %q{<div><div><one>Hello</one><two><two1>World</two1><two1>World</two1></two>[] </div>[] </div>}
|
170
|
+
}
|
171
|
+
assert_template_result expected, template
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|
@@ -3,11 +3,13 @@
|
|
3
3
|
require 'test/unit'
|
4
4
|
currentPath = File.dirname(__FILE__)
|
5
5
|
require File.join( currentPath, '../../lib/facets/core/string/starts_with' )
|
6
|
-
require File.join( currentPath, '../../lib/masterview/
|
6
|
+
require File.join( currentPath, '../../lib/masterview/core_ext/pathname' )
|
7
7
|
require File.join( currentPath, '../../lib/masterview/keyword_expander' )
|
8
8
|
|
9
9
|
class TestKeywordExpander < Test::Unit::TestCase
|
10
|
-
|
10
|
+
|
11
|
+
# bring test subjects into the local name space
|
12
|
+
KeywordExpander = MasterView::KeywordExpander
|
11
13
|
|
12
14
|
def test_ke
|
13
15
|
ke = KeywordExpander.new 'FOO' => 'bar', 'CAT' => 'dog'
|