masterview 0.0.6 → 0.0.7

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 (66) hide show
  1. data/Rakefile +8 -5
  2. data/init.rb +43 -0
  3. data/lib/facets/AUTHORS +36 -0
  4. data/lib/facets/CHANGELOG +266 -0
  5. data/lib/facets/COPYING +403 -0
  6. data/lib/facets/ProjectInfo +74 -0
  7. data/lib/facets/README +252 -0
  8. data/lib/facets/core/string/blank.rb +36 -0
  9. data/lib/facets/core/string/indent.rb +68 -0
  10. data/lib/facets/core/string/starts_with.rb +24 -0
  11. data/lib/masterview/directive_base.rb +163 -0
  12. data/lib/masterview/directive_helpers.rb +176 -0
  13. data/lib/masterview/directives/block.rb +30 -0
  14. data/lib/masterview/directives/content.rb +10 -0
  15. data/lib/masterview/directives/else.rb +25 -0
  16. data/lib/masterview/directives/elsif.rb +26 -0
  17. data/lib/masterview/directives/form.rb +19 -0
  18. data/lib/masterview/directives/global_inline_erb.rb +39 -0
  19. data/lib/masterview/directives/hidden_field.rb +31 -0
  20. data/lib/masterview/directives/if.rb +24 -0
  21. data/lib/masterview/directives/insert_generated_comment.rb +30 -0
  22. data/lib/masterview/directives/javascript_include.rb +15 -0
  23. data/lib/masterview/directives/link_to.rb +17 -0
  24. data/lib/masterview/directives/link_to_if.rb +21 -0
  25. data/lib/masterview/directives/link_to_remote.rb +17 -0
  26. data/lib/masterview/directives/password_field.rb +33 -0
  27. data/lib/masterview/directives/preview.rb +10 -0
  28. data/lib/masterview/directives/replace.rb +18 -0
  29. data/lib/masterview/directives/stylesheet_link.rb +14 -0
  30. data/lib/masterview/directives/submit.rb +14 -0
  31. data/lib/masterview/directives/testfilter.rb +55 -0
  32. data/lib/masterview/directives/text_area.rb +34 -0
  33. data/lib/masterview/directives/text_field.rb +33 -0
  34. data/lib/masterview/extras/rails_init.rb +67 -0
  35. data/lib/masterview/extras/watcher.rb +30 -0
  36. data/lib/masterview/masterview_version.rb +9 -0
  37. data/lib/masterview/parser.rb +585 -0
  38. data/lib/masterview/plugin_load_tracking.rb +41 -0
  39. data/lib/masterview/runtime_helpers.rb +9 -0
  40. data/lib/masterview/string_extensions.rb +15 -0
  41. data/lib/masterview.rb +129 -0
  42. data/test/block_test.rb +47 -0
  43. data/test/content_test.rb +26 -0
  44. data/test/else_test.rb +31 -0
  45. data/test/elsif_test.rb +31 -0
  46. data/test/example_test.rb +11 -0
  47. data/test/filter_helpers_test.rb +142 -0
  48. data/test/form_test.rb +66 -0
  49. data/test/global_inline_erb_test.rb +30 -0
  50. data/test/hidden_field_test.rb +62 -0
  51. data/test/if_test.rb +23 -0
  52. data/test/javascript_include_test.rb +26 -0
  53. data/test/link_to_if_test.rb +27 -0
  54. data/test/link_to_test.rb +52 -0
  55. data/test/parser_test.rb +166 -0
  56. data/test/password_field_test.rb +89 -0
  57. data/test/replace_test.rb +27 -0
  58. data/test/run_parser_test.rb +27 -0
  59. data/test/stylesheet_link_test.rb +26 -0
  60. data/test/submit_test.rb +54 -0
  61. data/test/template_file_watcher_test.rb +50 -0
  62. data/test/template_test.rb +181 -0
  63. data/test/test_helper.rb +24 -0
  64. data/test/text_area_test.rb +81 -0
  65. data/test/text_field_test.rb +89 -0
  66. metadata +71 -11
data/lib/masterview.rb ADDED
@@ -0,0 +1,129 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #--
4
+ # Copyright (c) 2006 Jeff Barczewski
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining
7
+ # a copy of this software and associated documentation files (the
8
+ # "Software"), to deal in the Software without restriction, including
9
+ # without limitation the rights to use, copy, modify, merge, publish,
10
+ # distribute, sublicense, and/or sell copies of the Software, and to
11
+ # permit persons to whom the Software is furnished to do so, subject to
12
+ # the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be
15
+ # included in all copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ #++
25
+ #
26
+ # = MasterView - Rails-optimized (x)html friendly template engine
27
+ #
28
+ # MasterView is a ruby/rails optimized HTML/XHTML friendly template engine.
29
+ # It is designed to use the full power and productivity of rails including
30
+ # layouts, partials, and rails html helpers while still being editable/styleable
31
+ # in a WYSIWYG HTML editor.
32
+
33
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
34
+
35
+ module MasterView
36
+ # set to true to have exceptions rescued
37
+ RescueExceptions = false
38
+
39
+ # :tidy - run tidy before parsing (set TidyPath), :escape_erb - escapes <% %> before parsing
40
+ DefaultParserOptions = { :tidy => false, :escape_erb => true }
41
+
42
+ # paths to load directives from, append your own paths to load custom directives
43
+ DefaultDirectiveLoadPaths = [ File.join( File.dirname(__FILE__), 'masterview/directives') ]
44
+
45
+ # prefix attributes in html with this value
46
+ NamespacePrefix = 'mv:'
47
+
48
+ # relative path under RAILS_ROOT/app/views where masterview templates are loaded
49
+ TemplateSrcRelativePath = 'masterview'
50
+
51
+ # masterview template filename pattern
52
+ TemplateFilenamePattern = '*.html'
53
+
54
+ # relative path to RAILS_ROOT/app/views where erb (rhtml) will be generated
55
+ TemplateDestRelativePath = ''
56
+
57
+ # boolean which determines whether warning comments will be ommitted (not generated) in rhtml indicating
58
+ # the generated file should not be manually edited, false = generate the warning comments
59
+ OmitGeneratedComments = false
60
+
61
+ # boolean which determines whether masterview files will be parsed during rails load and watched on requests.
62
+ # If true then masterview files will be parsed on rails loading. Additionally if
63
+ # this is true and the ActionController::Base.perform_caching is false (normally in development mode)
64
+ # then the masterview files will again be checked (using modified time) to see if any files need to
65
+ # be re-parsed. In production mode ActionController::Base.perform_caching is normally true and thus
66
+ # masterview files will only be parsed on first load.
67
+ # If this constant is set to false then no automatic watching or parsing occurs, it would be assumed
68
+ # that the parsing would have been manually triggered prior.
69
+ AutoParseMasterViewFiles = true
70
+
71
+ # xhtml safe substitution for '<%', make sure to update InlineErbSubstitutionRegex if changed
72
+ InlineErbStart = '{{{'
73
+
74
+ # xhtml safe substitution for '%>', make sure to update InlineErbSubstitutionRegex if changed
75
+ InlineErbEnd = '}}}'
76
+
77
+ # regex used to find escaped InlineErb, needs to match InlineErbStart and InlineErbEnd
78
+ InlineErbSubstitutionRegex = /\{\{\{(([^}]|\}[^}]|\}\}[^}])*)\}\}\}/
79
+
80
+ # sets path to tidy library on this system so masterview templates will be first run through tidy before parsing,
81
+ # required if DefaultParserOptions :tidy => true
82
+ # This allows invalid xhtml to be corrected before parsing
83
+ TidyPath = '/usr/lib/libtidy.so'
84
+ end
85
+
86
+ #external requires
87
+ require 'rexml/parsers/sax2parser'
88
+ require 'rexml/sax2listener'
89
+ require 'cgi'
90
+ require 'fileutils'
91
+ require 'strscan'
92
+
93
+ #external gem requires
94
+ require 'facets/core/string/blank'
95
+ require 'facets/core/string/indent'
96
+ require 'facets/core/string/starts_with'
97
+
98
+ #optional external gem requires, added functionality when available
99
+ require 'log4r'
100
+ require 'tidy'
101
+
102
+ #internal requires
103
+ require 'masterview/masterview_version'
104
+ require 'masterview/string_extensions'
105
+ require 'masterview/plugin_load_tracking'
106
+ require 'masterview/directive_helpers'
107
+ require 'masterview/directive_base'
108
+ require 'masterview/runtime_helpers'
109
+ require 'masterview/parser'
110
+ include MasterView::RuntimeHelpers
111
+
112
+ # set these constants after everything has been required
113
+ module MasterView
114
+ DefaultSerializer = FileSerializer
115
+
116
+ # setup logger
117
+ begin
118
+ include Log4r # will use log4r if available, otherwise default to logger
119
+
120
+ # Logger which will be used to output debug, warn, and error messages, will use log4r if available, otherwise logger
121
+ Log = Logger.new 'MasterView'
122
+ Log.outputters = Outputter.stdout
123
+ rescue # else fallback to built in logger
124
+ require 'logger'
125
+ Log = Logger.new STDOUT # :nodoc:
126
+ end
127
+ end
128
+
129
+
@@ -0,0 +1,47 @@
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/directives/block')
7
+
8
+ class TestBlock < Test::Unit::TestCase
9
+ include MasterView::Directives
10
+
11
+ def setup
12
+ @directives = MasterView::DirectiveSet.new
13
+ end
14
+
15
+ def test_do
16
+ @directives.directives = []
17
+ attr_value = 'if true do'
18
+ @directives << Block.new(attr_value)
19
+ assert_equal "<% #{attr_value} %>", @directives.determine_dcs(:stag).render.join
20
+ assert_equal "<% end %>", @directives.determine_dcs(:etag).render.join
21
+ end
22
+
23
+ def test_brack
24
+ @directives.directives = []
25
+ attr_value = 'if true {'
26
+ @directives << Block.new(attr_value)
27
+ assert_equal "<% #{attr_value} %>", @directives.determine_dcs(:stag).render.join
28
+ assert_equal "<% } %>", @directives.determine_dcs(:etag).render.join
29
+ end
30
+
31
+ def test_brack2
32
+ @directives.directives = []
33
+ attr_value = 'if true { :foo => :bar } {'
34
+ @directives << Block.new(attr_value)
35
+ assert_equal "<% #{attr_value} %>", @directives.determine_dcs(:stag).render.join
36
+ assert_equal "<% } %>", @directives.determine_dcs(:etag).render.join
37
+ end
38
+
39
+ def test_do2
40
+ @directives.directives = []
41
+ attr_value = 'if true { :foo => :bar } do'
42
+ @directives << Block.new(attr_value)
43
+ assert_equal 1, @directives.directives.size
44
+ assert_equal "<% #{attr_value} %>", @directives.determine_dcs(:stag).render.join
45
+ assert_equal "<% end %>", @directives.determine_dcs(:etag).render.join
46
+ end
47
+ end
@@ -0,0 +1,26 @@
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/directives/content')
7
+
8
+ class TestContent < Test::Unit::TestCase
9
+ include MasterView::Directives
10
+
11
+ def setup
12
+ @directives = MasterView::DirectiveSet.new
13
+ @tag = MasterView::Tag.new(@directives, 'foo', {}, :normal, nil)
14
+ end
15
+
16
+ def test_hello
17
+ @directives.directives = []
18
+ attr_value = 'hello world'
19
+ @directives << Content.new(attr_value)
20
+ dcs = @directives.determine_dcs(:etag)
21
+ dcs.context = @tag.create_context
22
+ assert_equal '', dcs.render.join
23
+ assert_equal "<%= #{attr_value} %>", dcs.context[:tag].content
24
+ end
25
+
26
+ end
data/test/else_test.rb ADDED
@@ -0,0 +1,31 @@
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/directives/else')
7
+
8
+ class TestElse < Test::Unit::TestCase
9
+ include MasterView::Directives
10
+
11
+ def setup
12
+ @directives = MasterView::DirectiveSet.new
13
+ end
14
+
15
+ def test_else
16
+ parent_tag = MasterView::Tag.new(@directives, 'div', {}, :normal, nil)
17
+ parent_tag.content = ['<% if true %>hello world', '<% end %>']
18
+
19
+ else_tag = MasterView::Tag.new(@directives, 'bar', {}, :normal, parent_tag)
20
+ @directives.directives = []
21
+ attr_value = 'not used'
22
+ @directives << Else.new(attr_value)
23
+ dcs = @directives.determine_dcs(:stag)
24
+ dcs.context = else_tag.create_context
25
+
26
+ assert_equal "<% else %>", dcs.render.join
27
+ assert_equal "<% if true %>hello world", parent_tag.content.join
28
+ assert_equal "<% end %>", @directives.determine_dcs(:etag).render.join
29
+ end
30
+
31
+ end
@@ -0,0 +1,31 @@
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/directives/elsif')
7
+
8
+ class TestElsif < Test::Unit::TestCase
9
+ include MasterView::Directives
10
+
11
+ def setup
12
+ @directives = MasterView::DirectiveSet.new
13
+ end
14
+
15
+ def test_elsif
16
+ parent_tag = MasterView::Tag.new(@directives, 'div', {}, :normal, nil)
17
+ parent_tag.content = ['<% if true %>hello world', '<% end %>']
18
+
19
+ elsif_tag = MasterView::Tag.new(@directives, 'bar', {}, :normal, parent_tag)
20
+ @directives.directives = []
21
+ attr_value = '@foobar'
22
+ @directives << Elsif.new(attr_value)
23
+ dcs = @directives.determine_dcs(:stag)
24
+ dcs.context = elsif_tag.create_context
25
+
26
+ assert_equal "<% elsif #{attr_value} %>", dcs.render.join
27
+ assert_equal "<% if true %>hello world", parent_tag.content.join
28
+ assert_equal "<% end %>", @directives.determine_dcs(:etag).render.join
29
+ end
30
+
31
+ end
@@ -0,0 +1,11 @@
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 TestExample < Test::Unit::TestCase
8
+ include MasterView::Directives
9
+ def test_nothing
10
+ end
11
+ end
@@ -0,0 +1,142 @@
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 TestDirectiveHelpers < Test::Unit::TestCase
8
+ include MasterView::Directives
9
+ include MasterView::DirectiveHelpers
10
+
11
+ def test_parse_eval_into_array_a
12
+ a = parse_eval_into_array("hello, world")
13
+ assert_equal "hello", a[0]
14
+ assert_equal "world", a[1]
15
+ end
16
+
17
+ def test_parse_eval_into_array_b
18
+ a = parse_eval_into_array("'hello', 'world'")
19
+ assert_equal "hello", a[0]
20
+ assert_equal "world", a[1]
21
+ end
22
+
23
+ def test_parse_eval_into_array_c
24
+ a = parse_eval_into_array("hello, 'world'")
25
+ assert_equal "hello", a[0]
26
+ assert_equal "world", a[1]
27
+ end
28
+
29
+ def test_parse_eval_into_array_d
30
+ a = parse_eval_into_array("\"hello\", 'world'")
31
+ assert_equal "hello", a[0]
32
+ assert_equal "world", a[1]
33
+ end
34
+
35
+ def test_parse_eval_into_array_e
36
+ a = parse_eval_into_array("hello, \"world\"")
37
+ assert_equal "hello", a[0]
38
+ assert_equal "world", a[1]
39
+ end
40
+
41
+ def test_parse_eval_into_array_f
42
+ a = parse_eval_into_array(":foo => :bar")
43
+ assert_equal( {:foo => :bar}, a[0] )
44
+ end
45
+
46
+ def test_parse_eval_into_array_g
47
+ a = parse_eval_into_array(":foo => :bar, :baz => :cat")
48
+ assert_equal( {:foo => :bar, :baz => :cat}, a[0] )
49
+ end
50
+
51
+ def test_parse_eval_into_array_h
52
+ a = parse_eval_into_array(":foo => :bar, :baz => 'cat'")
53
+ assert_equal( {:foo => :bar, :baz => 'cat'}, a[0] )
54
+ end
55
+
56
+ def test_parse_eval_into_array_i
57
+ a = parse_eval_into_array(":foo => 'bar', :baz => :cat")
58
+ assert_equal( {:foo => 'bar', :baz => :cat}, a[0] )
59
+ end
60
+
61
+ def test_parse_eval_into_array_j
62
+ a = parse_eval_into_array("hello, :foo => :bar, :baz => :cat")
63
+ assert_equal "hello", a[0]
64
+ assert_equal( {:foo => :bar, :baz => :cat}, a[1] )
65
+ end
66
+
67
+ def test_parse_eval_into_array_k
68
+ a = parse_eval_into_array("'hello', {:foo => :bar, :baz => :cat}" )
69
+ assert_equal "hello", a[0]
70
+ assert_equal( {:foo => :bar, :baz => :cat}, a[1] )
71
+ end
72
+
73
+ def test_parse_eval_into_array_l
74
+ a = parse_eval_into_array("\"hello\", {:foo => :bar, :baz => :cat}")
75
+ assert_equal "hello", a[0]
76
+ assert_equal( {:foo => :bar, :baz => :cat}, a[1] )
77
+ end
78
+
79
+ def test_parse_eval_into_array_m
80
+ a = parse_eval_into_array("hello, {:foo => :bar, :baz => :cat}")
81
+ assert_equal "hello", a[0]
82
+ assert_equal( {:foo => :bar, :baz => :cat}, a[1] )
83
+ end
84
+
85
+ def test_parse_eval_into_array_n
86
+ a = parse_eval_into_array("hello, {:foo => :bar, :baz => :cat}")
87
+ assert_equal "hello", a[0]
88
+ assert_equal( {:foo => :bar, :baz => :cat}, a[1] )
89
+ end
90
+
91
+ def test_parse_eval_into_array_o
92
+ a = parse_eval_into_array("hello, {:foo => :bar, :baz => [1,2]}")
93
+ assert_equal "hello", a[0]
94
+ assert_equal( {:foo => :bar, :baz => [1,2]}, a[1] )
95
+ end
96
+
97
+ def test_parse_eval_into_array_n
98
+ a = parse_eval_into_array("hello, {:foo => :bar, :baz => ['one', 'two']}")
99
+ assert_equal "hello", a[0]
100
+ assert_equal( {:foo => :bar, :baz => ['one', 'two']}, a[1] )
101
+ end
102
+
103
+ def test_parse_eval_into_array_o
104
+ a = parse_eval_into_array("hello, {:foo => :bar, :baz => :cat}, {:dog => :egg}")
105
+ assert_equal "hello", a[0]
106
+ assert_equal( {:foo => :bar, :baz => :cat}, a[1] )
107
+ assert_equal( {:dog => :egg}, a[2] )
108
+ end
109
+
110
+ def test_parse_hash
111
+ assert_equal "foo/bar", find_string_val_in_string_hash(":partial => 'foo/bar'", ":partial")
112
+ assert_equal "foo/bar", find_string_val_in_string_hash(':partial => "foo/bar"', ":partial")
113
+ assert_equal "foo/bar", find_string_val_in_string_hash(":baz => :cat, :partial => 'foo/bar'", ":partial")
114
+ assert_equal "foo/bar", find_string_val_in_string_hash(":partial => 'foo/bar', :baz => 'cat'", ":partial")
115
+ assert_equal "foo/bar", find_string_val_in_string_hash(":partial=>'foo/bar'", ":partial")
116
+ assert_equal "foo/bar", find_string_val_in_string_hash(" :partial => 'foo/bar' ", ":partial")
117
+ assert_equal "foo/bar", find_string_val_in_string_hash("'hello', :partial => 'foo/bar'", ":partial")
118
+ assert_equal "foo/bar", find_string_val_in_string_hash("hello, :partial => 'foo/bar'", ":partial")
119
+ end
120
+
121
+ def test_parse_hash_passing_symbol
122
+ assert_equal "foo/bar", find_string_val_in_string_hash(":partial => 'foo/bar'", :partial)
123
+ assert_equal "foo/bar", find_string_val_in_string_hash(':partial => "foo/bar"', :partial)
124
+ assert_equal "foo/bar", find_string_val_in_string_hash(":baz => :cat, :partial => 'foo/bar'", :partial)
125
+ assert_equal "foo/bar", find_string_val_in_string_hash(":partial => 'foo/bar', :baz => 'cat'", :partial)
126
+ assert_equal "foo/bar", find_string_val_in_string_hash(":partial=>'foo/bar'", :partial)
127
+ assert_equal "foo/bar", find_string_val_in_string_hash(" :partial => 'foo/bar' ", :partial)
128
+ assert_equal "foo/bar", find_string_val_in_string_hash("'hello', :partial => 'foo/bar'", :partial)
129
+ assert_equal "foo/bar", find_string_val_in_string_hash("hello, :partial => 'foo/bar'", :partial)
130
+ end
131
+
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}" )
138
+
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
+
142
+ end
data/test/form_test.rb ADDED
@@ -0,0 +1,66 @@
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/directives/form')
7
+
8
+ class TestForm < Test::Unit::TestCase
9
+ include MasterView::Directives
10
+
11
+ def setup
12
+ @directives = MasterView::DirectiveSet.new
13
+ end
14
+
15
+ def test_default
16
+ tag = MasterView::Tag.new(@directives, 'foo', {}, :normal, nil)
17
+ @directives.directives = []
18
+ attr_value = ":action => 'create'"
19
+ @directives << Form.new(attr_value)
20
+ dcs = @directives.determine_dcs(:stag)
21
+ dcs.context = tag.create_context
22
+ assert_equal "<%= form_tag :action => 'create' %>", dcs.render
23
+ assert_equal "<%= end_form_tag %>", @directives.determine_dcs(:etag).render
24
+ end
25
+
26
+ def test_get_uc
27
+ tag = MasterView::Tag.new(@directives, 'foo', { 'method' => 'GET'}, :normal, nil)
28
+ @directives.directives = []
29
+ attr_value = ":action => 'create'"
30
+ @directives << Form.new(attr_value)
31
+ dcs = @directives.determine_dcs(:stag)
32
+ dcs.context = tag.create_context
33
+ assert_equal "<%= form_tag {:action => 'create'}, :method => \"get\" %>", dcs.render
34
+ end
35
+
36
+ def test_get
37
+ tag = MasterView::Tag.new(@directives, 'foo', { 'method' => 'get' }, :normal, nil)
38
+ @directives.directives = []
39
+ attr_value = ":action => 'create'"
40
+ @directives << Form.new(attr_value)
41
+ dcs = @directives.determine_dcs(:stag)
42
+ dcs.context = tag.create_context
43
+ assert_equal "<%= form_tag {:action => 'create'}, :method => \"get\" %>", dcs.render
44
+ end
45
+
46
+ def test_post_uc
47
+ tag = MasterView::Tag.new(@directives, 'foo', { 'method' => 'POST' }, :normal, nil)
48
+ @directives.directives = []
49
+ attr_value = ":action => 'create'"
50
+ @directives << Form.new(attr_value)
51
+ dcs = @directives.determine_dcs(:stag)
52
+ dcs.context = tag.create_context
53
+ assert_equal "<%= form_tag :action => 'create' %>", dcs.render
54
+ end
55
+
56
+ def test_post
57
+ tag = MasterView::Tag.new(@directives, 'foo', { 'method' => 'post' }, :normal, nil)
58
+ @directives.directives = []
59
+ attr_value = ":action => 'create'"
60
+ @directives << Form.new(attr_value)
61
+ dcs = @directives.determine_dcs(:stag)
62
+ dcs.context = tag.create_context
63
+ assert_equal "<%= form_tag :action => 'create' %>", dcs.render
64
+ end
65
+
66
+ end
@@ -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/directives/global_inline_erb')
7
+
8
+ class TestGlobalInlineErb < Test::Unit::TestCase
9
+ include MasterView::Directives
10
+
11
+ def setup
12
+ @directives = MasterView::DirectiveSet.new
13
+ end
14
+
15
+ def test_hello
16
+ @tag = MasterView::Tag.new(@directives, 'foo', {'hello' => 'foo bar {{{=hello world}}}', 'world' => '{{{fine}}}'}, :normal, nil)
17
+ @directives.directives = []
18
+ @directives << Global_inline_erb.new
19
+ @directives << MasterView::SimpleRenderHandler.new
20
+ dcs = @directives.determine_dcs(:stag)
21
+ dcs.context = @tag.create_context
22
+ assert_equal '<foo hello="foo bar <%=hello world%>" world="<%fine%>">', dcs.render.join
23
+ #assert_equal "<%= #{attr_value} %>", dcs.context[:tag].content
24
+
25
+ dcs = @directives.determine_dcs(:characters)
26
+ dcs.context = @tag.create_context(:content_part => 'more text here {{{= foo(bar) }}} more then {{{exec {:hello => :world} }}} finally')
27
+ assert_equal 'more text here <%= foo(bar) %> more then <%exec {:hello => :world} %> finally', dcs.render.join
28
+ end
29
+
30
+ end
@@ -0,0 +1,62 @@
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/directives/hidden_field')
7
+
8
+ class TestHiddenField < Test::Unit::TestCase
9
+ include MasterView::Directives
10
+
11
+ def setup
12
+ @directives = MasterView::DirectiveSet.new
13
+ end
14
+
15
+ def hidden_field_exec(obj, method, other, options)
16
+ 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 << Hidden_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
27
+
28
+ def test_normal
29
+ obj = ':product'
30
+ method = ':price'
31
+ ret = hidden_field_exec(obj, method, nil, { 'type' => 'hidden', 'value' => 'fake text' } )
32
+ assert_equal "<%= hidden_field #{obj}, #{method} %>", ret
33
+ end
34
+
35
+ def test_extra
36
+ obj = ':product'
37
+ method = ':price'
38
+ ret = hidden_field_exec(obj, method, "'more', 'stuff'", { 'type' => 'hidden', 'value' => 'fake text' } )
39
+ assert_equal "<%= hidden_field #{obj}, #{method} %>", ret
40
+ end
41
+
42
+ def test_all
43
+ obj = ':product'
44
+ method = ':price'
45
+ ret = hidden_field_exec(obj, method, nil,
46
+ {
47
+ 'type' => 'hidden', 'value' => 'fake text'
48
+ } )
49
+ assert_equal "<%= hidden_field #{obj}, #{method} %>", ret
50
+ end
51
+
52
+ def test_all_uc
53
+ obj = ':product'
54
+ method = ':price'
55
+ ret = hidden_field_exec(obj, method, nil,
56
+ {
57
+ 'TYPE' => 'HIDDEN', 'value' => 'fake text'
58
+ } )
59
+ assert_equal "<%= hidden_field #{obj}, #{method} %>", ret
60
+ end
61
+
62
+ end
data/test/if_test.rb ADDED
@@ -0,0 +1,23 @@
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/directives/if')
7
+
8
+ class TestIf < Test::Unit::TestCase
9
+ include MasterView::Directives
10
+
11
+ def setup
12
+ @directives = MasterView::DirectiveSet.new
13
+ end
14
+
15
+ def test_if
16
+ @directives.directives = []
17
+ attr_value = 'true'
18
+ @directives << If.new(attr_value)
19
+ assert_equal "<% if #{attr_value} %>", @directives.determine_dcs(:stag).render.join
20
+ assert_equal "<% end %>", @directives.determine_dcs(:etag).render.join
21
+ end
22
+
23
+ end
@@ -0,0 +1,26 @@
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/directives/javascript_include' )
7
+
8
+ class JavascriptIncludeTest < Test::Unit::TestCase
9
+ include MasterView::Directives
10
+
11
+ def setup
12
+ @directives = MasterView::DirectiveSet.new
13
+ end
14
+
15
+ def test_default
16
+ tag = MasterView::Tag.new(@directives, 'foo', {}, :normal, nil)
17
+ @directives.directives = []
18
+ attr_value = "hello world"
19
+ @directives << Javascript_include.new(attr_value)
20
+ assert_equal nil, @directives.determine_dcs(:stag).render
21
+ dcs = @directives.determine_dcs(:etag)
22
+ dcs.context = tag.create_context
23
+ assert_equal "<%= javascript_include_tag 'hello world' %>", dcs.render
24
+ end
25
+
26
+ end
@@ -0,0 +1,27 @@
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/directives/link_to_if')
7
+
8
+ class TestLinkToIf < Test::Unit::TestCase
9
+ include MasterView::Directives
10
+
11
+ def setup
12
+ @directives = MasterView::DirectiveSet.new
13
+ end
14
+
15
+ def test_previous
16
+ tag = MasterView::Tag.new(@directives, 'foo', {}, :normal, nil)
17
+ @directives.directives = []
18
+ attr_value = "@product_pages.current.previous, {:page => @product_pages.current.previous }"
19
+ @directives << Link_to_if.new(attr_value)
20
+ assert_equal nil, @directives.determine_dcs(:stag).render
21
+ dcs = @directives.determine_dcs(:etag)
22
+ dcs.context = tag.create_context
23
+ dcs.context[:tag].content = "Previous page"
24
+ assert_equal "<%= link_to_if @product_pages.current.previous, 'Previous page', {:page => @product_pages.current.previous } %>", dcs.render
25
+ end
26
+
27
+ end