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
@@ -2,7 +2,7 @@
2
2
  <div class="product_list sidebar">
3
3
  <h1>Tasks:</h1>
4
4
  <ul>
5
- <li><%= link_to 'Create new product', :action => 'new' %></li>
5
+ <li><%= link_to( 'Create new product', { :action => 'new' }, :class => "new_link" ) %></li>
6
6
  </ul>
7
7
  </div>
8
8
 
@@ -23,8 +23,8 @@
23
23
  <%= render( :partial => 'product/product', :collection => @products ) %>
24
24
  </table>
25
25
 
26
- <% if @product_pages.current.previous %><%= link_to 'Previous page', :page => @product_pages.current.previous %><% end %>
27
- <% if @product_pages.current.next %><%= link_to 'Next page', :page => @product_pages.current.next %><% end %>
26
+ <% if( @product_pages.current.previous ) -%><%= link_to( 'Previous page', { :page => @product_pages.current.previous }, :class => "previous_link" ) %><% end -%>
27
+ <% if( @product_pages.current.next ) -%><%= link_to( 'Next page', { :page => @product_pages.current.next }, :class => "next_link" ) %><% end -%>
28
28
 
29
29
  </div>
30
30
  </div>
@@ -2,14 +2,14 @@
2
2
  <div class="product_new sidebar">
3
3
  <h1>Tasks:</h1>
4
4
  <ul>
5
- <li><%= link_to 'Back to overview', :action => 'list' %></li>
5
+ <li><%= link_to( 'Back to overview', { :action => 'list' }, :class => "list_link" ) %></li>
6
6
  </ul>
7
7
  </div>
8
8
 
9
9
  <div class="product_new content">
10
10
  <h1>Products</h1>
11
11
 
12
- <%= form_tag :action => 'new' %>
12
+ <%= form_tag( :action => 'new' ) %>
13
13
 
14
14
  <div class="form">
15
15
  <h2>Creating product</h2>
@@ -20,10 +20,10 @@
20
20
 
21
21
  <br />
22
22
  <div class="product_new operations">
23
- <%= submit_tag 'OK' %>
23
+ <%= submit_tag( 'OK', :class => "primary save_button" ) %>
24
24
  <input class="cancel_button" onclick="window.location.href = '<%= url_for :action => %q{list} %>';" style="width: auto;" type="button" value="Cancel" />
25
25
  </div>
26
26
 
27
- <%= end_form_tag %>
27
+ </form>
28
28
  </div>
29
29
  </div>
@@ -2,8 +2,8 @@
2
2
  <div class="product_show sidebar">
3
3
  <h1>Tasks:</h1>
4
4
  <ul>
5
- <li><%= link_to 'Back to overview', :action => 'list' %></li>
6
- <li><%= link_to 'Edit this product', :action => 'edit', :id => @product.id %></li>
5
+ <li><%= link_to( 'Back to overview', { :action => 'list' }, :class => "list_link" ) %></li>
6
+ <li><%= link_to( 'Edit this product', { :action => 'edit', :id => @product.id }, :class => "edit_link" ) %></li>
7
7
  </ul>
8
8
  </div>
9
9
 
@@ -0,0 +1,105 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ currentPath = File.dirname(__FILE__)
5
+ require File.join( currentPath, '../../lib/masterview' )
6
+
7
+ class TestAttrStringParser < Test::Unit::TestCase
8
+
9
+ # test subject
10
+ AttrStringParser = MasterView::AttrStringParser
11
+
12
+ def verify_arg_parsing( attr_value, expected_args )
13
+ parsed_args = AttrStringParser.new(attr_value).parse
14
+ #assert_equal expected_args.size, parsed_args.size, "Wrong num args in parsed_args=#{parsed_args.inspect}"
15
+ assert_equal expected_args, parsed_args, "GOT: parsed_args=#{parsed_args.inspect}"
16
+ end
17
+
18
+ def test_one_arg_value
19
+ attr_value = 'foo'
20
+ expected_args = [ attr_value ] #just foo
21
+ verify_arg_parsing( attr_value, expected_args )
22
+ end
23
+
24
+ def test_multiple_arg_values
25
+ attr_value = 'foo, bar, wingding'
26
+ expected_args = attr_value.split(',').collect {|x| x.strip}
27
+ verify_arg_parsing( attr_value, expected_args )
28
+ end
29
+
30
+ def test_multi_word_value
31
+ attr_value = 'one, and a two, and a three lets go'
32
+ expected_args = attr_value.split(',').collect {|x| x.strip}
33
+ verify_arg_parsing( attr_value, expected_args )
34
+ end
35
+
36
+ def test_omitted_arg
37
+ attr_value = 'one, two, skip the one after this,, five'
38
+ expected_args = attr_value.split(',').collect {|x| x.strip}
39
+ assert_equal '', expected_args[3], 'Omitted arg is parsed as empty string (not nil)'
40
+ verify_arg_parsing( attr_value, expected_args )
41
+ end
42
+
43
+ # assoc of an unwrapped hash gets parsed as one entry (deliberate or accidental?!)
44
+ def test_single_assoc
45
+ attr_value = ':foo => :bar'
46
+ expected_args = [ attr_value ]
47
+ verify_arg_parsing( attr_value, expected_args )
48
+ end
49
+
50
+ # multiple assocs of an unwrapped hash get parsed as one entry (deliberate or accidental?!)
51
+ def test_multiple_assocs
52
+ attr_value = ':foo => :bar, :option => "bing", :default => 5'
53
+ #expected_args = [ ':foo => :bar', ':option => "bing"', ':default => 5' ]
54
+ expected_args = [ attr_value ]
55
+ verify_arg_parsing( attr_value, expected_args )
56
+ end
57
+
58
+ # wrapped hash gets parsed as a single hash literal string
59
+ def test_single_entry_hash
60
+ attr_value = '{ :foo => :bar }'
61
+ expected_args = [ attr_value ] # client has to eval the hash literal themselves
62
+ verify_arg_parsing( attr_value, expected_args )
63
+ end
64
+
65
+ # wrapped hash gets parsed as a single hash literal string
66
+ def test_multiple_entry_hash
67
+ attr_value = '{ :foo => :bar, :option => "bing" }'
68
+ expected_args = [ attr_value ] # client has to eval the hash literal themselves
69
+ verify_arg_parsing( attr_value, expected_args )
70
+ end
71
+
72
+ def test_positional_and_wrapped_hash_args
73
+ attr_value = 'arg1, arg2, { :foo => :bar, :option => "bing" }'
74
+ expected_args = [ 'arg1', 'arg2', '{ :foo => :bar, :option => "bing" }' ]
75
+ verify_arg_parsing( attr_value, expected_args )
76
+ end
77
+
78
+ # hash entries must be wrapped if any subsequent parms follow
79
+ def test_positional_and_embedded_wrapped_hash_args
80
+ attr_value = 'arg1, arg2, { :foo => :bar, :option => "bing" }, trailingArg1, trailingArg2'
81
+ expected_args = [ 'arg1', 'arg2', '{ :foo => :bar, :option => "bing" }', 'trailingArg1', 'trailingArg2' ]
82
+ verify_arg_parsing( attr_value, expected_args )
83
+ end
84
+
85
+ # unwrapped hash assocs gobble up any trailing positional args, so this shouldn't be used
86
+ def test_positional_and_unwrapped_hash_args
87
+ attr_value = 'arg1,, arg3, :foo => :bar, :option => "bing", trailingArg-MUNCHED!'
88
+ expected_args = [ 'arg1', '', 'arg3', ':foo => :bar, :option => "bing", trailingArg-MUNCHED!' ]
89
+ verify_arg_parsing( attr_value, expected_args )
90
+ assert_equal 4, expected_args.size, 'trailing arg gets captured by the hash lit, so no number 5'
91
+ end
92
+
93
+ def test_list_arg
94
+ attr_value = '[one, two, three]'
95
+ expected_args = [attr_value]
96
+ verify_arg_parsing( attr_value, expected_args )
97
+ end
98
+
99
+ def test_positional_and_list_arg
100
+ attr_value = 'arg1, arg2, [one, two, three], arg4'
101
+ expected_args = [ 'arg1', 'arg2', '[one, two, three]', 'arg4' ]
102
+ verify_arg_parsing( attr_value, expected_args )
103
+ end
104
+
105
+ end
@@ -0,0 +1,104 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ currentPath = File.dirname(__FILE__)
5
+ require File.join( currentPath, '../../lib/masterview' )
6
+
7
+ class TestCaseInsensitiveHashMod < Test::Unit::TestCase
8
+
9
+ def setup
10
+ @h = MasterView::CaseInsensitiveHash.new
11
+ @h.replace( { :a => :A, 'b' => :B, 'C' => :C, 0 => 0, 1 => 1, :z => [1,2], 'y' => { :foo => :bar}, :aa => :AA, 'bb' => :BB, 'CC' => :CC, 'dD' => :DD} )
12
+ end
13
+
14
+ def test_get
15
+ assert_equal 0, @h[0]
16
+ assert_equal 1, @h[1]
17
+
18
+ assert_equal :A, @h[:a]
19
+ assert_equal :B, @h[:b]
20
+ assert_equal :C, @h[:c]
21
+ assert_equal [1,2], @h[:z]
22
+ assert_equal( { :foo => :bar }, @h[:y] )
23
+ assert_equal :AA, @h[:aa]
24
+ assert_equal :BB, @h[:bb]
25
+ assert_equal :CC, @h[:cc]
26
+ assert_equal :DD, @h[:dd]
27
+
28
+ assert_equal :A, @h['a']
29
+ assert_equal :B, @h['b']
30
+ assert_equal :C, @h['c']
31
+ assert_equal [1,2], @h['z']
32
+ assert_equal( { :foo => :bar }, @h['y'] )
33
+ assert_equal :AA, @h['aa']
34
+ assert_equal :BB, @h['bb']
35
+ assert_equal :CC, @h['cc']
36
+ assert_equal :DD, @h['dd']
37
+
38
+ assert_equal :A, @h['A']
39
+ assert_equal :B, @h['B']
40
+ assert_equal :C, @h['C']
41
+ assert_equal [1,2], @h['Z']
42
+ assert_equal( { :foo => :bar }, @h['Y'] )
43
+ assert_equal :AA, @h['AA']
44
+ assert_equal :BB, @h['BB']
45
+ assert_equal :CC, @h['CC']
46
+ assert_equal :DD, @h['DD']
47
+
48
+ assert_equal :AA, @h['Aa']
49
+ assert_equal :BB, @h['Bb']
50
+ assert_equal :CC, @h['Cc']
51
+ assert_equal :DD, @h['Dd']
52
+
53
+ assert_equal :AA, @h['aA']
54
+ assert_equal :BB, @h['bB']
55
+ assert_equal :CC, @h['cC']
56
+ assert_equal :DD, @h['dD']
57
+
58
+ assert_equal :AA, @h[:aA]
59
+ assert_equal :BB, @h[:bB]
60
+ assert_equal :CC, @h[:cC]
61
+ assert_equal :DD, @h[:dD]
62
+ end
63
+
64
+ def test_set
65
+ @h[:b] = 'bbb'
66
+ @h['c'] = 'ccc'
67
+ @h['onClick'] = 'hello'
68
+ @h[:onMove] = 'moved'
69
+ @h.store(:aa, 'aaaa')
70
+ @h.store('bB', 'bbbb')
71
+ @h.store('Class', 'red')
72
+
73
+ assert_equal 'bbb', @h[:b]
74
+ assert_equal 'ccc', @h[:c]
75
+ assert_equal 'aaaa', @h[:aa]
76
+ assert_equal 'bbbb', @h[:bb]
77
+ assert_equal 'hello', @h[:onclick]
78
+ assert_equal 'moved', @h[:onmove]
79
+
80
+ assert_equal 'bbb', @h['b']
81
+ assert_equal 'ccc', @h['c']
82
+ assert_equal 'aaaa', @h['aA']
83
+ assert_equal 'bbbb', @h[:Bb]
84
+ assert_equal 'hello', @h['onclick']
85
+ assert_equal 'moved', @h['ONMOVE']
86
+
87
+ assert_equal [0,1,:a,:aa,"b","bb","C","CC","Class","dD","onClick",:onMove,"y",:z], @h.keys.sort { |a,b| a.to_s.downcase <=> b.to_s.downcase }
88
+ end
89
+
90
+ def test_get_lowercase_str_value
91
+ @h[:method] = 'POST'
92
+ @h[:upper_array] = [:HELLO, 'WORLD']
93
+ assert_equal 'a', @h.get_lowercase_str_value('a')
94
+ assert_equal 'b', @h.get_lowercase_str_value('b')
95
+ assert_equal 'c', @h.get_lowercase_str_value('c')
96
+ assert_equal '0', @h.get_lowercase_str_value('0')
97
+ assert_equal '[1, 2]', @h.get_lowercase_str_value('z')
98
+ assert_equal '{:foo=>:bar}', @h.get_lowercase_str_value('y')
99
+ assert_equal 'post', @h.get_lowercase_str_value('method')
100
+ assert_equal '[:hello, "world"]', @h.get_lowercase_str_value('upper_array')
101
+ end
102
+
103
+
104
+ end
@@ -6,7 +6,7 @@ require File.join( currentPath, '../../lib/masterview/initializer' )
6
6
 
7
7
  class TestConfiguration < Test::Unit::TestCase
8
8
  CurrentPath = File.dirname(__FILE__)
9
- #TestCasesDir = File.join(CurrentPath, '../..')
9
+ TestCasesDir = File.expand_path( File.join(CurrentPath, '..') )
10
10
  TestFixturesDir = File.join(CurrentPath, '../fixtures/configs')
11
11
 
12
12
  def setup
@@ -22,10 +22,22 @@ class TestConfiguration < Test::Unit::TestCase
22
22
  code_base_from_install_dir = "#{config.mv_installation_dir}/lib/masterview"
23
23
  assert File.directory?( code_base_from_install_dir ), "no lib/masterview code dir at mv_installation_dir='#{config.mv_installation_dir}'"
24
24
 
25
+ # MasterView::ConfigSettings.mv_code_base_dir is the lib/masterview directory
25
26
  assert_equal code_base_from_install_dir, config.mv_code_base_dir, "inconsistent mv_code_base_dir='#{config.mv_code_base_dir}'"
26
27
 
27
28
  end
28
29
 
30
+ # these are interesting for directive developers, who need DirectiveTestHelpers
31
+ def test_mv_install_test_dir_refs
32
+
33
+ # default settings for standalone operation
34
+ config = MasterView::Configuration.new
35
+
36
+ # "#{MasterView::ConfigSettings.mv_installation_dir}/test" is the test directory
37
+ mv_test_dir_from_config_settings_root = "#{config.mv_installation_dir}/test"
38
+ assert_equal TestCasesDir, mv_test_dir_from_config_settings_root
39
+
40
+ end
29
41
 
30
42
  def test_default_settings_standalone
31
43
 
@@ -6,11 +6,11 @@ require File.join( currentPath, '../../lib/masterview' )
6
6
  require File.join( currentPath, '../test_helper' )
7
7
 
8
8
  class TestDefaultGenerateMIOFilter < Test::Unit::TestCase
9
- include MasterView::DefaultGenerateMIOFilter
9
+ include MasterView::MIO::DefaultGenerateMIOFilter
10
10
 
11
11
  def setup
12
- MasterView::IOMgr.template = MasterView::StringHashMIOTree.new({}, '.rhtml', :logging => true, :default_generate => true )
13
- MasterView::IOMgr.erb = MasterView::StringHashMIOTree.new({}, '.rhtml', :logging => true)
12
+ MasterView::IOMgr.template = MasterView::MIO::StringHashMIOTree.new({}, '.rhtml', :logging => true, :default_generate => true )
13
+ MasterView::IOMgr.erb = MasterView::MIO::StringHashMIOTree.new({}, '.rhtml', :logging => true)
14
14
  end
15
15
 
16
16
 
@@ -0,0 +1,30 @@
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, '../../lib/masterview/deprecated/directive_base' )
7
+
8
+ class TestDirectiveBase < Test::Unit::TestCase
9
+ def setup
10
+ @base = MasterView::DirectiveBase.new('')
11
+ end
12
+
13
+ def test_quote
14
+ assert_equal '\'hello\'', @base.quote('hello')
15
+ end
16
+
17
+ def test_quote_if
18
+ assert_equal '\'helloWorld0123\'', @base.quote_if('helloWorld0123')
19
+ assert_equal 'hello world', @base.quote_if('hello world')
20
+ assert_equal 'hello,world', @base.quote_if('hello,world')
21
+ assert_equal 'hello(world)', @base.quote_if('hello(world)')
22
+ assert_equal ':hello', @base.quote_if(':hello')
23
+ assert_equal '\"hello world\"', @base.quote_if('\"hello world\"')
24
+ assert_equal '%q{helloworld}', @base.quote_if('%q{helloworld}')
25
+ assert_equal 'hello.world', @base.quote_if('hello.world')
26
+ assert_equal 'hel/lo.w_orld', @base.quote_if('hel/lo.w_orld')
27
+ assert_equal '\'\'', @base.quote_if('')
28
+ end
29
+
30
+ end
@@ -3,50 +3,126 @@
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/attr')
6
+ #require File.join( currentPath, '../../lib/masterview/directives/attr')
7
+ require File.join( currentPath, '../directive_test_helper' )
8
+ DirectiveTestHelpers.load_masterview_directive('attr')
7
9
 
8
10
  class TestAttr < Test::Unit::TestCase
9
- include MasterView::Directives
11
+ include DirectiveTestHelpers
12
+
13
+ Attr = MasterView::Directives::Attr # test subject
14
+
15
+ ELEMENT_TAG = 'div'
16
+ TEMPLATE_ELEMENT_ATTR_NAME = 'foo'
17
+ TEMPLATE_ELEMENT_ATTR_VALUE = 'bar'
18
+ TEMPLATE_ELEMENT_ATTRIBUTES = { TEMPLATE_ELEMENT_ATTR_NAME => TEMPLATE_ELEMENT_ATTR_VALUE }
10
19
 
11
20
  def setup
12
- @directives = MasterView::DirectiveSet.new
13
- @tag = MasterView::Tag.new(@directives, 'foo', {'bar' => 'cat'}, :normal, nil)
21
+ create_template_element ELEMENT_TAG, :attributes => TEMPLATE_ELEMENT_ATTRIBUTES
14
22
  end
15
23
 
16
- def test_hello
17
- @directives.directives = []
18
- attr_value = "{:hello => 'world'}"
19
- @directives << Attr.new(attr_value)
20
- dcs = @directives.determine_dcs(:stag)
21
- dcs.context = @tag.create_context
22
- assert_equal '', dcs.render.join
23
- assert_equal 'cat', dcs.context[:tag].attributes['bar']
24
- assert_equal 'world', dcs.context[:tag].attributes['hello']
24
+ def test_metadata
25
+ assert_equal MasterView::ConfigSettings.namespace_prefix, Attr.namespace_prefix
25
26
  end
26
27
 
27
- def test_hello_hi
28
- @directives.directives = []
28
+ def check_element_rendering(expected_unchanged_attributes, expected_changedAttributes, expected_added_attributes)
29
+
30
+ num_original_attrs = element_attrs.size() # original attributes on the template element before mv:attr applied
31
+ num_unchanged_attributes = expected_unchanged_attributes.size()
32
+ num_changed_attributes = expected_changedAttributes.size()
33
+ num_new_attributes = expected_added_attributes.size()
34
+
35
+ # mv:attr directive manipulates the element's attributes, but doesn't directly act on the output
36
+ # It thus has an effect when the normal element processing occurs
37
+ assert_equal '', render_element_event(:stag) ##err... when does the stag actually get emitted?
38
+
39
+ assert_equal num_original_attrs, num_unchanged_attributes + num_changed_attributes, 'Oops: programmer error'
40
+
41
+ expected_unchanged_attributes.each_pair { | attr_name, expected_value |
42
+ assert_equal expected_value, element_attr_value(attr_name), 'Original attribute is not affected'
43
+ }
44
+ expected_changedAttributes.each_pair { | attr_name, expected_value |
45
+ assert_equal expected_value, element_attr_value(attr_name), 'Original attribute should be changed'
46
+ }
47
+ expected_added_attributes.each_pair { | attr_name, expected_value |
48
+ assert_equal expected_value, element_attr_value(attr_name), 'New attribute specified in the directive should be added'
49
+ }
50
+
51
+ assert_equal element_attrs.size(), num_original_attrs + num_new_attributes, 'Should end up with exactly original attributes + new attributes'
52
+
53
+ end
54
+
55
+ # test adding an attribute to the element (wrapped hash arg)
56
+ def test_add_using_hash_notation
57
+
58
+ attr_value = "{ :hello => 'world' }"
59
+ create_directive Attr, attr_value
60
+
61
+ check_element_rendering(
62
+ TEMPLATE_ELEMENT_ATTRIBUTES, # original
63
+ {}, # no changes
64
+ eval(attr_value) # new
65
+ )
66
+
67
+ end
68
+
69
+ # test adding multiple attributes to the element (unwrapped hash assocs notation)
70
+ def test_add_using_bare_keywords_notation
71
+
29
72
  attr_value = ":hello => 'world', :hi => 'there'"
30
- @directives << Attr.new(attr_value)
31
- dcs = @directives.determine_dcs(:stag)
32
- dcs.context = @tag.create_context
33
- assert_equal '', dcs.render.join
34
- assert_equal 'cat', dcs.context[:tag].attributes['bar']
35
- assert_equal 'world', dcs.context[:tag].attributes['hello']
36
- assert_equal 'there', dcs.context[:tag].attributes['hi']
37
- end
38
-
39
- def test_hello_erb
40
- @directives.directives = []
41
- attr_value = %q":hello => 'world', :hi => 'there', :wow => #{h product.name}"
42
- @directives << Attr.new(attr_value)
43
- dcs = @directives.determine_dcs(:stag)
44
- dcs.context = @tag.create_context
45
- assert_equal '', dcs.render.join
46
- assert_equal 'cat', dcs.context[:tag].attributes['bar']
47
- assert_equal 'world', dcs.context[:tag].attributes['hello']
48
- assert_equal 'there', dcs.context[:tag].attributes['hi']
49
- assert_equal '{{{= h product.name }}}', dcs.context[:tag].attributes['wow']
73
+ create_directive Attr, attr_value
74
+
75
+ check_element_rendering(
76
+ TEMPLATE_ELEMENT_ATTRIBUTES, # original
77
+ {}, # no changes
78
+ eval( "{ #{attr_value} }" ) # new
79
+ )
80
+
81
+ end
82
+
83
+ def test_add_attribute_with_erb_subst
84
+
85
+ attr_value = %q":hello => 'world', :wow => #{product.name}"
86
+ erbized_attr_value = '{{{= product.name }}}'
87
+ create_directive Attr, attr_value
88
+
89
+ check_element_rendering(
90
+ TEMPLATE_ELEMENT_ATTRIBUTES, # original
91
+ {}, # no changes
92
+ { :hello => 'world', :wow => erbized_attr_value } # new
93
+ )
94
+
95
+ end
96
+
97
+ # test adding multiple attributes to the element with changes to original markup
98
+ def test_add_and_change_attributes
99
+
100
+ modified_template_attr_value = 'wingding'
101
+ attr_value = ":hello => 'world', :#{TEMPLATE_ELEMENT_ATTR_NAME} => '#{modified_template_attr_value}'"
102
+ create_directive Attr, attr_value
103
+
104
+ check_element_rendering(
105
+ {}, # no unchanged
106
+ { TEMPLATE_ELEMENT_ATTR_NAME => modified_template_attr_value }, # changed
107
+ eval( "{ #{attr_value.split(',')[0]} }" ) # new
108
+ )
109
+
110
+ end
111
+
112
+ # test adding multiple attributes to the element with changes to original markup
113
+ def test_add_and_change_attribute_with_erb_subst
114
+
115
+ modified_template_attr_value = '#{product.name}'
116
+ erbized_attr_value = '{{{= product.name }}}'
117
+ attr_value = ":hello => 'world', :#{TEMPLATE_ELEMENT_ATTR_NAME} => " << modified_template_attr_value
118
+ create_directive Attr, attr_value
119
+
120
+ check_element_rendering(
121
+ {}, # no unchanged
122
+ { TEMPLATE_ELEMENT_ATTR_NAME => erbized_attr_value }, # changed
123
+ eval( "{ #{attr_value.split(',')[0]} }" ) # new
124
+ )
125
+
50
126
  end
51
127
 
52
128
  end