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.
Files changed (155) hide show
  1. data/CHANGELOG +31 -1
  2. data/README +70 -69
  3. data/RELEASE_NOTES +70 -64
  4. data/Rakefile +26 -27
  5. data/TODO +13 -29
  6. data/doc/about.html +246 -0
  7. data/doc/configuration.html +49 -36
  8. data/doc/developer.html +423 -41
  9. data/doc/directives.html +139 -51
  10. data/doc/guide.html +19 -9
  11. data/doc/index.html +90 -224
  12. data/doc/installation.html +36 -28
  13. data/doc/media_list.html +30 -20
  14. data/doc/simple_diagram.html +3 -5
  15. data/doc/stylesheets/masterview.css +16 -1
  16. data/examples/rails_app_config/masterview/settings.rb +2 -1
  17. data/init.rb +1 -1
  18. data/lib/#ChangeLog# +6 -0
  19. data/lib/masterview/analyzer.rb +48 -34
  20. data/lib/masterview/attr_string_parser.rb +5 -1
  21. data/lib/masterview/case_insensitive_hash.rb +69 -0
  22. data/lib/masterview/{pathname_extensions.rb → core_ext/pathname.rb} +0 -0
  23. data/lib/masterview/{string_extensions.rb → core_ext/string.rb} +0 -0
  24. data/lib/masterview/deprecated/directive_base.rb +362 -0
  25. data/lib/masterview/directive_base.rb +201 -179
  26. data/lib/masterview/directive_dsl.rb +457 -0
  27. data/lib/masterview/directive_helpers.rb +28 -141
  28. data/lib/masterview/directive_load_path.rb +388 -0
  29. data/lib/masterview/directive_metadata.rb +377 -0
  30. data/lib/masterview/directive_registry.rb +259 -69
  31. data/lib/masterview/directives/.metadata +16 -0
  32. data/lib/masterview/directives/attr.rb +9 -8
  33. data/lib/masterview/directives/block.rb +11 -14
  34. data/lib/masterview/directives/check_box.rb +13 -18
  35. data/lib/masterview/directives/collection_select.rb +15 -29
  36. data/lib/masterview/directives/content.rb +9 -3
  37. data/lib/masterview/directives/else.rb +15 -13
  38. data/lib/masterview/directives/elsif.rb +14 -13
  39. data/lib/masterview/directives/eval.rb +20 -0
  40. data/lib/masterview/directives/form.rb +56 -9
  41. data/lib/masterview/directives/form_remote.rb +26 -0
  42. data/lib/masterview/directives/global_inline_erb.rb +10 -14
  43. data/lib/masterview/directives/hidden_field.rb +11 -20
  44. data/lib/masterview/directives/if.rb +13 -12
  45. data/lib/masterview/directives/image_tag.rb +20 -28
  46. data/lib/masterview/directives/import.rb +5 -12
  47. data/lib/masterview/directives/import_render.rb +7 -19
  48. data/lib/masterview/directives/insert_generated_comment.rb +8 -11
  49. data/lib/masterview/directives/javascript_include.rb +21 -12
  50. data/lib/masterview/directives/link_to.rb +14 -8
  51. data/lib/masterview/directives/link_to_function.rb +22 -0
  52. data/lib/masterview/directives/link_to_if.rb +15 -13
  53. data/lib/masterview/directives/link_to_remote.rb +13 -8
  54. data/lib/masterview/directives/omit_tag.rb +32 -16
  55. data/lib/masterview/directives/password_field.rb +10 -22
  56. data/lib/masterview/directives/radio_button.rb +11 -22
  57. data/lib/masterview/directives/replace.rb +7 -8
  58. data/lib/masterview/directives/select.rb +11 -24
  59. data/lib/masterview/directives/stylesheet_link.rb +20 -12
  60. data/lib/masterview/directives/submit.rb +11 -5
  61. data/lib/masterview/directives/text_area.rb +10 -23
  62. data/lib/masterview/directives/text_field.rb +10 -22
  63. data/lib/masterview/exceptions.rb +21 -0
  64. data/lib/masterview/extras/app/controllers/masterview_controller.rb +102 -75
  65. data/lib/masterview/extras/app/views/layouts/masterview_admin.rhtml +24 -23
  66. data/lib/masterview/extras/app/views/layouts/masterview_admin_config.rhtml +81 -0
  67. data/lib/masterview/extras/app/views/masterview/admin/configuration.rhtml +5 -1
  68. data/lib/masterview/extras/app/views/masterview/admin/create.rhtml +2 -2
  69. data/lib/masterview/extras/app/views/masterview/admin/directives.rhtml +5 -0
  70. data/lib/masterview/extras/app/views/masterview/admin/features.rhtml +5 -79
  71. data/lib/masterview/extras/app/views/masterview/admin/interact.rhtml +5 -0
  72. data/lib/masterview/extras/app/views/masterview/admin/list.rhtml +3 -71
  73. data/lib/masterview/extras/init_mv_admin_pages.rb +42 -23
  74. data/lib/masterview/filter_helpers.rb +26 -0
  75. data/lib/masterview/initializer.rb +99 -53
  76. data/lib/masterview/io.rb +19 -15
  77. data/lib/masterview/keyword_expander.rb +7 -2
  78. data/lib/masterview/masterview_info.rb +229 -23
  79. data/lib/masterview/masterview_version.rb +2 -2
  80. data/lib/masterview/parser.rb +275 -105
  81. data/lib/masterview/parser_helpers.rb +54 -0
  82. data/lib/masterview/rails_ext/action_controller_erb_direct.rb +29 -0
  83. data/lib/masterview/rails_ext/action_controller_reparse_checking.rb +27 -0
  84. data/lib/masterview/{extras/init_rails_erb_mv_direct.rb → rails_ext/action_view_erb_direct.rb} +12 -59
  85. data/lib/masterview/template_spec.rb +3 -2
  86. data/lib/masterview.rb +21 -12
  87. data/lib/rexml/parsers/baseparser_with_doctype_fix.rb +473 -0
  88. data/lib/rexml/parsers/sax2parser_with_doctype_fix.rb +243 -0
  89. data/test/directive_test_helper.rb +135 -0
  90. data/test/fixtures/directives/id_check.rb +18 -0
  91. data/test/fixtures/directives/test_directive_events.rb +70 -0
  92. data/test/test_helper.rb +18 -5
  93. data/test/tmp/views/layouts/product.rhtml +10 -10
  94. data/test/tmp/views/product/_form.rhtml +4 -4
  95. data/test/tmp/views/product/_product.rhtml +3 -3
  96. data/test/tmp/views/product/destroy.rhtml +5 -5
  97. data/test/tmp/views/product/edit.rhtml +4 -4
  98. data/test/tmp/views/product/list.rhtml +3 -3
  99. data/test/tmp/views/product/new.rhtml +4 -4
  100. data/test/tmp/views/product/show.rhtml +2 -2
  101. data/test/unit/attr_string_parser_test.rb +105 -0
  102. data/test/unit/case_insensitive_hash_mod_test.rb +104 -0
  103. data/test/unit/config_settings_test.rb +13 -1
  104. data/test/unit/default_generate_mio_filter_test.rb +3 -3
  105. data/test/unit/deprecated_directive_base_test.rb +30 -0
  106. data/test/unit/directive_attr_test.rb +111 -35
  107. data/test/unit/directive_base_test.rb +520 -1
  108. data/test/unit/directive_block_test.rb +30 -22
  109. data/test/unit/directive_content_test.rb +24 -11
  110. data/test/unit/directive_else_test.rb +18 -15
  111. data/test/unit/directive_elsif_test.rb +17 -15
  112. data/test/unit/directive_form_remote_test.rb +59 -0
  113. data/test/unit/directive_form_test.rb +31 -39
  114. data/test/unit/directive_global_inline_erb_test.rb +28 -17
  115. data/test/unit/directive_grid_test_notready.rb +38 -0
  116. data/test/unit/directive_helpers_test.rb +39 -0
  117. data/test/unit/directive_hidden_field_test.rb +44 -29
  118. data/test/unit/directive_if_test.rb +10 -7
  119. data/test/unit/directive_image_tag_test.rb +69 -61
  120. data/test/unit/directive_import_render_test.rb +28 -38
  121. data/test/unit/directive_import_test.rb +16 -14
  122. data/test/unit/directive_insert_generated_comment_test.rb +32 -0
  123. data/test/unit/directive_javascript_include_test.rb +40 -43
  124. data/test/unit/directive_link_to_function_test.rb +40 -0
  125. data/test/unit/directive_link_to_if_test.rb +52 -12
  126. data/test/unit/directive_link_to_remote_test.rb +58 -0
  127. data/test/unit/directive_link_to_test.rb +46 -31
  128. data/test/unit/directive_load_path_test.rb +257 -0
  129. data/test/unit/directive_metadata_test.rb +313 -0
  130. data/test/unit/directive_omit_tag_test.rb +73 -21
  131. data/test/unit/directive_password_field_test.rb +44 -38
  132. data/test/unit/directive_registry_test.rb +44 -0
  133. data/test/unit/directive_replace_test.rb +28 -12
  134. data/test/unit/directive_stylesheet_link_test.rb +43 -36
  135. data/test/unit/directive_submit_test.rb +29 -30
  136. data/test/unit/directive_text_area_test.rb +40 -36
  137. data/test/unit/directive_text_field_test.rb +44 -38
  138. data/test/unit/example_directive_child_events_test.rb +41 -0
  139. data/test/unit/example_test.rb +31 -4
  140. data/test/unit/file_mio_test.rb +18 -13
  141. data/test/unit/filter_helpers_test.rb +10 -8
  142. data/test/unit/find_directive_parent_test.rb +174 -0
  143. data/test/unit/keyword_expander_test.rb +4 -2
  144. data/test/unit/mio_test.rb +18 -11
  145. data/test/unit/mtime_string_hash_mio_tree_test.rb +5 -1
  146. data/test/unit/parser_test.rb +41 -29
  147. data/test/unit/pathname_extensions_test.rb +1 -1
  148. data/test/unit/run_parser_test.rb +2 -2
  149. data/test/unit/simplified_directive_base_test.rb +256 -0
  150. data/test/unit/string_hash_mio_test.rb +5 -1
  151. data/test/unit/template_file_watcher_test.rb +2 -2
  152. data/test/unit/template_test.rb +221 -46
  153. metadata +86 -45
  154. data/lib/masterview/directives/testfilter.rb +0 -55
  155. 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 MasterView::Directives
11
+ include DirectiveTestHelpers
10
12
 
11
- def setup
12
- @directives = MasterView::DirectiveSet.new
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 text_area_exec(obj, method, other, options)
22
+ def create_element_with_text_area_directive(obj, method, other_attr_values, attributes)
23
+
16
24
  attr_value = "#{obj}, #{method}"
17
- attr_value << ', ' << other unless other.nil?
18
- tag = MasterView::Tag.new(@directives, 'input', options, :normal, nil)
19
- @directives.directives = []
20
- @directives << Text_area.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?
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 test_extra
35
+ def test_normal
36
36
  obj = ':product'
37
37
  method = ':price'
38
- ret = text_area_exec(obj, method, "'more', 'stuff'", { 'type' => 'text', 'value' => 'fake text' } )
39
- assert_equal "<%= text_area #{obj}, #{method} %>", ret
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
- ret = text_area_exec(obj, method, nil, { 'rows' => '4'} )
46
- assert_equal "<%= text_area #{obj}, #{method}, :rows => 4 %>", ret
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
- ret = text_area_exec(obj, method, nil, { 'cols' => 6 } )
53
- assert_equal "<%= text_area #{obj}, #{method}, :cols => 6 %>", ret
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
- ret = text_area_exec(obj, method, nil,
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
- assert_equal "<%= text_area #{obj}, #{method}, :accesskey => \"ak2\", :class => \"classfoo\", :cols => 6, :disabled => true, :readonly => true, :rows => 4, :style => \"stylebar\", :tabindex => \"tab1\" %>", ret
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
- ret = text_area_exec(obj, method, nil,
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
- assert_equal "<%= text_area #{obj}, #{method}, :accesskey => \"ak2\", :class => \"classfoo\", :cols => 6, :disabled => true, :readonly => true, :rows => 4, :style => \"stylebar\", :tabindex => \"tab1\" %>", ret
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 MasterView::Directives
11
+ include DirectiveTestHelpers
10
12
 
11
- def setup
12
- @directives = MasterView::DirectiveSet.new
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 text_field_exec(obj, method, other, options)
22
+ def create_element_with_text_field_directive(obj, method, other_attr_values, attributes)
23
+
16
24
  attr_value = "#{obj}, #{method}"
17
- attr_value << ', ' << other unless other.nil?
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
- def test_normal
29
- obj = ':product'
30
- method = ':price'
31
- ret = text_field_exec(obj, method, nil, { 'type' => 'text', 'value' => 'fake text' } )
32
- assert_equal "<%= text_field #{obj}, #{method} %>", ret
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 test_extra
35
+ def test_normal
36
36
  obj = ':product'
37
37
  method = ':price'
38
- ret = text_field_exec(obj, method, "'more', 'stuff'", { 'type' => 'text', 'value' => 'fake text' } )
39
- assert_equal "<%= text_field #{obj}, #{method} %>", ret
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
- ret = text_field_exec(obj, method, nil, { 'type' => 'text', 'value' => 'fake text', 'disabled' => 'disabled'} )
46
- assert_equal "<%= text_field #{obj}, #{method}, :disabled => true %>", ret
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
- ret = text_field_exec(obj, method, nil, { 'type' => 'text', 'value' => 'fake text', 'size' => '10' } )
53
- assert_equal "<%= text_field #{obj}, #{method}, :size => 10 %>", ret
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
- ret = text_field_exec(obj, method, nil, { 'type' => 'text', 'value' => 'fake text', 'maxlength' => '21' } )
60
- assert_equal "<%= text_field #{obj}, #{method}, :maxlength => 21 %>", ret
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
- ret = text_field_exec(obj, method, nil,
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
- assert_equal "<%= text_field #{obj}, #{method}, :accesskey => \"ak2\", :class => \"classfoo\", :disabled => true, :maxlength => 21, :readonly => true, :size => 10, :style => \"stylebar\", :tabindex => \"tab1\" %>", ret
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
- ret = text_field_exec(obj, method, nil,
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
- assert_equal "<%= text_field #{obj}, #{method}, :accesskey => \"ak2\", :class => \"classfoo\", :disabled => true, :maxlength => 21, :readonly => true, :size => 10, :style => \"stylebar\", :tabindex => \"tab1\" %>", ret
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
@@ -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
- currentPath = File.dirname(__FILE__)
5
- require File.join( currentPath, '../../lib/masterview' )
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 MasterView::Directives
9
- def test_nothing
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
@@ -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
- include MasterView
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(InvalidPathError){ f = IOMgr.template.path( '../bad') }
43
- assert_raise(InvalidPathError){ f = IOMgr.template.path( 'bad/../dog/../../foo') }
44
- assert_raise(InvalidPathError){ f = IOMgr.template.path( 'bad/../../foo') }
45
- assert_raise(InvalidPathError){ f = IOMgr.template.path( 'bad/cat/../../../dog') }
46
- assert_raise(InvalidPathError){ f = IOMgr.template.path( '/bad/foo') }
47
- assert_raise(InvalidPathError){ f = IOMgr.template.path( '/bad') }
48
- assert_raise(InvalidPathError){ f = IOMgr.template.path( '../bad.cat') }
49
- assert_raise(InvalidPathError){ f = IOMgr.template.path( 'bad/../dot/../../foo.cat') }
50
- assert_raise(InvalidPathError){ f = IOMgr.template.path( 'bad/../../foo.cat') }
51
- assert_raise(InvalidPathError){ f = IOMgr.template.path( 'bad/cat/../../../dog.cat') }
52
- assert_raise(InvalidPathError){ f = IOMgr.template.path( '/bad/foo.cat') }
53
- assert_raise(InvalidPathError){ f = IOMgr.template.path( '/bad.cat') }
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
- def test_remove_prepended_strings
133
- assert_equal ":foo => 'bar', :baz => :cat", remove_prepended_strings( "hello, world, :foo => 'bar', :baz => :cat" )
134
- assert_equal ":foo => 'bar', :baz => :cat", remove_prepended_strings( "'hello', 'world', :foo => 'bar', :baz => :cat" )
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}" )
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
- assert_equal ':action => :add, :id => %Q[srcitem_#{srcitem.pkey}]', remove_prepended_strings( 'hello, world, :action => :add, :id => %Q[srcitem_#{srcitem.pkey}]' )
140
- end
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/pathname_extensions' )
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
- include MasterView
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'