manatee 0.0.1.pre1

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 (58) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +23 -0
  3. data/LICENSE.txt +22 -0
  4. data/README.mdown +55 -0
  5. data/Rakefile +7 -0
  6. data/app/assets/javascripts/manatee.js +1 -0
  7. data/app/assets/javascripts/manatee/helpers.js +4 -0
  8. data/app/assets/javascripts/manatee/helpers/asset_tag.jsh.coffee +138 -0
  9. data/app/assets/javascripts/manatee/helpers/asset_url.jsh.coffee +90 -0
  10. data/app/assets/javascripts/manatee/helpers/csrf.jsh.coffee +5 -0
  11. data/app/assets/javascripts/manatee/helpers/date.jsh.coffee +54 -0
  12. data/app/assets/javascripts/manatee/helpers/debug.jsh.coffee +2 -0
  13. data/app/assets/javascripts/manatee/helpers/form.jsh.coffee +25 -0
  14. data/app/assets/javascripts/manatee/helpers/form_builder.jsh.coffee +24 -0
  15. data/app/assets/javascripts/manatee/helpers/form_options.jsh.coffee +267 -0
  16. data/app/assets/javascripts/manatee/helpers/form_tag.jsh.coffee +204 -0
  17. data/app/assets/javascripts/manatee/helpers/javascript.jsh.coffee +15 -0
  18. data/app/assets/javascripts/manatee/helpers/number.jsh.coffee +58 -0
  19. data/app/assets/javascripts/manatee/helpers/sanitize.jsh.coffee +5 -0
  20. data/app/assets/javascripts/manatee/helpers/tag.jsh.coffee +58 -0
  21. data/app/assets/javascripts/manatee/helpers/text.jsh.coffee +12 -0
  22. data/app/assets/javascripts/manatee/helpers/translation.jsh.coffee +7 -0
  23. data/app/assets/javascripts/manatee/helpers/url.jsh.coffee +36 -0
  24. data/app/assets/javascripts/manatee/helpers/util.jsh.coffee +41 -0
  25. data/app/assets/javascripts/manatee/rails_helpers.js +2 -0
  26. data/app/assets/javascripts/manatee/rails_helpers/routes.js.erb +195 -0
  27. data/app/assets/javascripts/manatee/rails_routes.js +1 -0
  28. data/app/assets/javascripts/manatee/renderer.js.erb +53 -0
  29. data/app/assets/javascripts/manatee_railsless.js +1 -0
  30. data/lib/manatee.rb +87 -0
  31. data/lib/manatee/config.rb +51 -0
  32. data/lib/manatee/handler.rb +45 -0
  33. data/lib/manatee/rails.rb +6 -0
  34. data/lib/manatee/rails/extensions.rb +23 -0
  35. data/lib/manatee/rails/handler.rb +16 -0
  36. data/lib/manatee/rails/hash_visitor.rb +35 -0
  37. data/lib/manatee/rails/helper.rb +9 -0
  38. data/lib/manatee/rails/resolver.rb +70 -0
  39. data/lib/manatee/rails/routes_compiler.rb +34 -0
  40. data/lib/manatee/sprockets.rb +8 -0
  41. data/lib/manatee/sprockets/jsh_processor_2x.rb +32 -0
  42. data/lib/manatee/sprockets/jsh_processor_3x.rb +31 -0
  43. data/lib/manatee/version.rb +3 -0
  44. data/manatee.gemspec +32 -0
  45. data/test/example/renderer.js.erb +8 -0
  46. data/test/example/translations.en.yml +410 -0
  47. data/test/example/views/index.jst.eco +12 -0
  48. data/test/helpers/asset_tag_test.rb +175 -0
  49. data/test/helpers/asset_url_test.rb +349 -0
  50. data/test/helpers/form_options_test.rb +718 -0
  51. data/test/helpers/form_tag_test.rb +387 -0
  52. data/test/helpers/javascript_test.rb +39 -0
  53. data/test/helpers/number_test.rb +111 -0
  54. data/test/helpers/tag_test.rb +71 -0
  55. data/test/support/dom_assertion.rb +49 -0
  56. data/test/support/view_test.rb +91 -0
  57. data/test/test_helper.rb +17 -0
  58. metadata +213 -0
@@ -0,0 +1,12 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>A Random Page</title>
5
+ <meta charset="utf-8">
6
+ <%- @csrfMetaTags() %>
7
+ </head>
8
+ <body>
9
+ <p>This page has this CSRF token: <%= @csrfToken %></p>
10
+ </body>
11
+ <script type="text/javascript"></script>
12
+ </html>
@@ -0,0 +1,175 @@
1
+ require_relative '../test_helper'
2
+
3
+ class AssetTagTest < Manatee::ViewTest
4
+
5
+ def setup
6
+ config_renderer do |config|
7
+ config.fonts_path = '/fonts'
8
+ config.audios_path = '/audios'
9
+ config.videos_path = '/videos'
10
+ config.images_path = '/images'
11
+ config.javascript_path = ''
12
+ config.stylesheet_path = ''
13
+ end
14
+ end
15
+
16
+ AudioTagParams = {
17
+ %( "xml.wav" ) => %(<audio src="/audios/xml.wav"></audio>),
18
+ %( "rss.wav", { autoplay: true, controls: true } ) => %(<audio autoplay="autoplay" controls="controls" src="/audios/rss.wav"></audio>),
19
+ %( "http://media.rubyonrails.org/audio/rails_blog_2.mov" ) => %(<audio src="http://media.rubyonrails.org/audio/rails_blog_2.mov"></audio>),
20
+ %( "//media.rubyonrails.org/audio/rails_blog_2.mov" ) => %(<audio src="//media.rubyonrails.org/audio/rails_blog_2.mov"></audio>),
21
+ %( "audio.mp3", "audio.ogg" ) => %(<audio><source src="/audios/audio.mp3" /><source src="/audios/audio.ogg" /></audio>),
22
+ %( "audio.mp3", "audio.ogg" ) => %(<audio><source src="/audios/audio.mp3" /><source src="/audios/audio.ogg" /></audio>),
23
+ %( "audio.mp3", "audio.ogg", { autobuffer: true, controls: true } ) => %(<audio autobuffer="autobuffer" controls="controls"><source src="/audios/audio.mp3" /><source src="/audios/audio.ogg" /></audio>)
24
+ }
25
+
26
+ def test_audio_tag
27
+ AudioTagParams.each do |params, expected|
28
+ assert_dom_js_helper expected, :audioTag, params
29
+ end
30
+ end
31
+
32
+ AutoDiscoveryLinkTagParams = {
33
+ %( ) => %(<link href="http://www.example.com" rel="alternate" title="RSS" type="application/rss+xml" />),
34
+ %( 'rss' ) => %(<link href="http://www.example.com" rel="alternate" title="RSS" type="application/rss+xml" />),
35
+ %( 'atom' ) => %(<link href="http://www.example.com" rel="alternate" title="ATOM" type="application/atom+xml" />),
36
+ %( 'rss', "http://localhost/feed" ) => %(<link href="http://localhost/feed" rel="alternate" title="RSS" type="application/rss+xml" />),
37
+ %( 'rss', "//localhost/feed" ) => %(<link href="//localhost/feed" rel="alternate" title="RSS" type="application/rss+xml" />),
38
+ %( 'rss', null, { title: "My RSS" } ) => %(<link href="http://www.example.com" rel="alternate" title="My RSS" type="application/rss+xml" />),
39
+ %( null, null, { type: "text/html" } ) => %(<link href="http://www.example.com" rel="alternate" title="" type="text/html" />),
40
+ %( null, null, { title: "No stream.. really", type: "text/html" } ) => %(<link href="http://www.example.com" rel="alternate" title="No stream.. really" type="text/html" />),
41
+ %( 'rss', null, { title: "My RSS", type: "text/html" } ) => %(<link href="http://www.example.com" rel="alternate" title="My RSS" type="text/html" />),
42
+ %( 'atom', null, { rel: "Not so alternate" } ) => %(<link href="http://www.example.com" rel="Not so alternate" title="ATOM" type="application/atom+xml" />)
43
+ }
44
+
45
+ def test_auto_discovery_link_tag
46
+ AutoDiscoveryLinkTagParams.each do |params, expected|
47
+ assert_dom_js_helper expected, :autoDiscoveryLinkTag, params
48
+ end
49
+ end
50
+
51
+ FaviconLinkTagParams = {
52
+ %( ) => %(<link href="favicon.ico" rel="shortcut icon" type="image/x-icon" />),
53
+ %( 'favicon.ico' ) => %(<link href="favicon.ico" rel="shortcut icon" type="image/x-icon" />),
54
+ %( 'favicon.ico', { rel: 'foo' } ) => %(<link href="favicon.ico" rel="foo" type="image/x-icon" />),
55
+ %( 'favicon.ico', { rel: 'foo', type: 'bar' } ) => %(<link href="favicon.ico" rel="foo" type="bar" />),
56
+ %( 'mb-icon.png', { rel: 'apple-touch-icon', type: 'image/png' } ) => %(<link href="mb-icon.png" rel="apple-touch-icon" type="image/png" />)
57
+ }
58
+
59
+ def test_favicon_link_tag
60
+ FaviconLinkTagParams.each do |params, expected|
61
+ assert_dom_js_helper expected, :faviconLinkTag, params
62
+ end
63
+ end
64
+
65
+ def test_image_alt
66
+ [nil, '/', '/foo/bar/', 'foo/bar/'].each do |prefix|
67
+ assert_helper 'Rails', :imageAlt, "#{prefix}rails.png"
68
+ assert_helper 'Rails', :imageAlt, "#{prefix}rails-9c0a079bdd7701d7e729bd956823d153.png"
69
+ assert_helper 'Long file name with hyphens', :imageAlt, "#{prefix}long-file-name-with-hyphens.png"
70
+ assert_helper 'Long file name with underscores', :imageAlt, "#{prefix}long_file_name_with_underscores.png"
71
+ end
72
+ end
73
+
74
+ GifEmbededSrc = "data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="
75
+ PngEmbededSrc = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="
76
+ ImageTagParams = {
77
+ %( "xml.png" ) => %(<img alt="Xml" src="/images/xml.png" />),
78
+ %( "rss.gif", { alt: "rss syndication" } ) => %(<img alt="rss syndication" src="/images/rss.gif" />),
79
+ %( "gold.png", { size: "20" } ) => %(<img alt="Gold" height="20" src="/images/gold.png" width="20" />),
80
+ %( "gold.png", { size: "45x70" } ) => %(<img alt="Gold" height="70" src="/images/gold.png" width="45" />),
81
+ %( "gold.png", { size: "45x70" } ) => %(<img alt="Gold" height="70" src="/images/gold.png" width="45" />),
82
+ %( "error.png", { size: "45 x 70" } ) => %(<img alt="Error" src="/images/error.png" />),
83
+ %( "error.png", { size: "x" } ) => %(<img alt="Error" src="/images/error.png" />),
84
+ %( "google.com.png" ) => %(<img alt="Google.com" src="/images/google.com.png" />),
85
+ %( "slash..png" ) => %(<img alt="Slash." src="/images/slash..png" />),
86
+ %( ".pdf.png" ) => %(<img alt=".pdf" src="/images/.pdf.png" />),
87
+ %( "http://www.rubyonrails.com/images/rails.png" ) => %(<img alt="Rails" src="http://www.rubyonrails.com/images/rails.png" />),
88
+ %( "//www.rubyonrails.com/images/rails.png" ) => %(<img alt="Rails" src="//www.rubyonrails.com/images/rails.png" />),
89
+ %( "mouse.png", { alt: null } ) => %(<img src="/images/mouse.png" />),
90
+ %( "#{GifEmbededSrc}", { alt: null } ) => %(<img src="#{GifEmbededSrc}" />),
91
+ %( "#{PngEmbededSrc}" ) => %(<img src="#{PngEmbededSrc}" />),
92
+ %( "#{PngEmbededSrc}", { alt: 'Red Dot'} ) => %(<img src="#{PngEmbededSrc}" alt="Red Dot" />),
93
+ %( "" ) => %(<img src="" />)
94
+ }
95
+
96
+ def test_image_tag
97
+ ImageTagParams.each do |params, expected|
98
+ assert_dom_js_helper expected, :imageTag, params
99
+ end
100
+ end
101
+
102
+ def test_javascript_include_tag
103
+ assert_dom_helper '<script src="/foo.js"></script>', :javascriptIncludeTag, '/foo'
104
+ assert_dom_helper '<script src="/foo"></script>', :javascriptIncludeTag, '/foo', format: false
105
+ assert_dom_helper '<script src="/foo.bar"></script>', :javascriptIncludeTag, '/foo', format: 'bar'
106
+ end
107
+
108
+ def test_javascript_include_tag_with_full_url
109
+ assert_dom_helper '<script src="http://foo.bar/javascript.js"></script>', :javascriptIncludeTag, 'http://foo.bar/javascript.js'
110
+ end
111
+
112
+ def test_javascript_multiple_include_tag
113
+ assert_dom_helper '<script src="/foo.js"></script><script src="/bar.js"></script>', :javascriptIncludeTag, '/foo', '/bar'
114
+ assert_dom_helper '<script src="/foo"></script><script src="/bar"></script>', :javascriptIncludeTag, '/foo', '/bar', format: false
115
+ assert_dom_helper '<script src="/foo.foo"></script><script src="/bar.foo"></script>', :javascriptIncludeTag, '/foo', '/bar', format: 'foo'
116
+ end
117
+
118
+ def test_javascript_multiple_include_tag_with_full_url
119
+ assert_dom_helper '<script src="http://foo.bar/javascript.js"></script><script src="http://bar.foo/javascript.js"></script>', :javascriptIncludeTag, 'http://foo.bar/javascript.js', 'http://bar.foo/javascript.js'
120
+ end
121
+
122
+ def test_stylesheet_include_tag
123
+ assert_dom_helper '<link rel="stylesheet" media="screen" href="/foo.css"/>', :stylesheetLinkTag, '/foo'
124
+ assert_dom_helper '<link rel="stylesheet" media="screen" href="/foo"/>', :stylesheetLinkTag, '/foo', format: false
125
+ assert_dom_helper '<link rel="stylesheet" media="screen" href="/foo.bar"/>', :stylesheetLinkTag, '/foo', format: 'bar'
126
+ end
127
+
128
+ def test_stylesheet_include_tag_with_options
129
+ assert_dom_helper '<link rel="stylesheet" media="all" href="/foo.css"/>', :stylesheetLinkTag, '/foo', media: 'all'
130
+ assert_dom_helper '<link rel="stylesheet" media="screen" attribute="what?" href="/foo.css"/>', :stylesheetLinkTag, '/foo', attribute: 'what?'
131
+ end
132
+
133
+ def test_stylesheet_include_tag_with_full_url
134
+ assert_dom_helper '<link rel="stylesheet" media="screen" href="http://foo.bar/stylesheet.css"/>', :stylesheetLinkTag, 'http://foo.bar/stylesheet.css'
135
+ end
136
+
137
+ def test_stylesheet_multiple_include_tag
138
+ assert_dom_helper '<link rel="stylesheet" media="screen" href="/foo.css"/><link rel="stylesheet" media="screen" href="/bar.css"/>', :stylesheetLinkTag, '/foo', '/bar'
139
+ assert_dom_helper '<link rel="stylesheet" media="screen" href="/foo"/><link rel="stylesheet" media="screen" href="/bar"/>', :stylesheetLinkTag, '/foo', '/bar', format: false
140
+ assert_dom_helper '<link rel="stylesheet" media="screen" href="/foo.foo"/><link rel="stylesheet" media="screen" href="/bar.foo"/>', :stylesheetLinkTag, '/foo', '/bar', format: 'foo'
141
+ end
142
+
143
+ def test_stylesheet_multiple_include_tag_with_options
144
+ assert_dom_helper '<link media="all" rel="stylesheet" href="/foo.css"/><link media="all" rel="stylesheet" href="/bar.css"/>', :stylesheetLinkTag, '/foo', '/bar', media: 'all'
145
+ assert_dom_helper '<link attribute="what?" rel="stylesheet" media="screen" href="/foo.css"/><link attribute="what?" rel="stylesheet" media="screen" href="/bar.css"/>', :stylesheetLinkTag, '/foo', '/bar', attribute: 'what?'
146
+ end
147
+
148
+ def test_stylesheet_multiple_include_tag_with_full_url
149
+ assert_dom_helper '<link rel="stylesheet" media="screen" href="http://foo.bar/stylesheet.css"/><link rel="stylesheet" media="screen" href="http://bar.foo/stylesheet.css"/>', :stylesheetLinkTag, 'http://foo.bar/stylesheet.css', 'http://bar.foo/stylesheet.css'
150
+ end
151
+
152
+ VideoTagParams = {
153
+ %( "xml.ogg" ) => %(<video src="/videos/xml.ogg"></video>),
154
+ %( "rss.m4v", { autoplay: true, controls: true } ) => %(<video autoplay="autoplay" controls="controls" src="/videos/rss.m4v"></video>),
155
+ %( "rss.m4v", { autobuffer: true } ) => %(<video autobuffer="autobuffer" src="/videos/rss.m4v"></video>),
156
+ %( "gold.m4v", { size: "160x120" } ) => %(<video height="120" src="/videos/gold.m4v" width="160"></video>),
157
+ %( "gold.m4v", { size: "320x240" } ) => %(<video height="240" src="/videos/gold.m4v" width="320"></video>),
158
+ %( "trailer.ogg", { poster: "screenshot.png" } ) => %(<video poster="/images/screenshot.png" src="/videos/trailer.ogg"></video>),
159
+ %( "error.avi", { size: "100" } ) => %(<video height="100" src="/videos/error.avi" width="100"></video>),
160
+ %( "error.avi", { size: "100 x 100"} ) => %(<video src="/videos/error.avi"></video>),
161
+ %( "error.avi", { size: "x" } ) => %(<video src="/videos/error.avi"></video>),
162
+ %( "http://media.rubyonrails.org/video/rails_blog_2.mov" ) => %(<video src="http://media.rubyonrails.org/video/rails_blog_2.mov"></video>),
163
+ %( "//media.rubyonrails.org/video/rails_blog_2.mov" ) => %(<video src="//media.rubyonrails.org/video/rails_blog_2.mov"></video>),
164
+ %( "multiple.ogg", "multiple.avi" ) => %(<video><source src="/videos/multiple.ogg" /><source src="/videos/multiple.avi" /></video>),
165
+ %( "multiple.ogg", "multiple.avi" ) => %(<video><source src="/videos/multiple.ogg" /><source src="/videos/multiple.avi" /></video>),
166
+ %( "multiple.ogg", "multiple.avi", { size: "160x120", controls: true } ) => %(<video controls="controls" height="120" width="160"><source src="/videos/multiple.ogg" /><source src="/videos/multiple.avi" /></video>)
167
+ }
168
+
169
+ def test_video_tag
170
+ VideoTagParams.each do |params, expected|
171
+ assert_dom_js_helper expected, :videoTag, params
172
+ end
173
+ end
174
+
175
+ end
@@ -0,0 +1,349 @@
1
+ require_relative '../test_helper'
2
+
3
+ class AssetUrlTest < Manatee::ViewTest
4
+
5
+ def setup
6
+ config_renderer do |config|
7
+ config.fonts_path = '/fonts'
8
+ config.audios_path = '/audios'
9
+ config.videos_path = '/videos'
10
+ config.images_path = '/images'
11
+ config.javascript_path = '/javascripts'
12
+ config.stylesheet_path = '/stylesheets'
13
+ end
14
+ end
15
+
16
+ ComputeAssetPathParams = {
17
+ %( "robots.txt" ) => "/robots.txt",
18
+ %( "/robots.txt" ) => "/robots.txt",
19
+ %( "foo.js", { type: 'javascript' } ) => "/javascripts/foo.js",
20
+ %( "/foo.js", { type: 'javascript' } ) => "/foo.js",
21
+ %( "foo.css", { type: 'stylesheet' } ) => "/stylesheets/foo.css",
22
+ %( "robots.txt", { domain: 'http://example.com' } ) => "http://example.com/robots.txt",
23
+ %( "/robots.txt", { domain: 'http://example.com' } ) => "http://example.com/robots.txt",
24
+ %( "foo.js", { domain: 'http://example.com', type: 'javascript' } ) => "http://example.com/javascripts/foo.js",
25
+ %( "/foo.js", { domain: 'http://example.com', type: 'javascript' } ) => "http://example.com/foo.js",
26
+ %( "foo.css", { domain: 'http://example.com', type: 'stylesheet' } ) => "http://example.com/stylesheets/foo.css"
27
+ }
28
+
29
+ def test_compute_asset_path
30
+ ComputeAssetPathParams.each do |params, expected|
31
+ assert_js_helper expected, :computeAssetPath, params
32
+ end
33
+ end
34
+
35
+ AssetPathParams = {
36
+ %( "foo" ) => '/foo',
37
+ %( "style.css" ) => '/style.css',
38
+ %( "xmlhr.js" ) => '/xmlhr.js',
39
+ %( "xml.png" ) => '/xml.png',
40
+ %( "dir/xml.png" ) => '/dir/xml.png',
41
+ %( "/dir/xml.png" ) => '/dir/xml.png',
42
+ %( "script.min" ) => '/script.min',
43
+ %( "script.min.js" ) => '/script.min.js',
44
+ %( "style.min" ) => '/style.min',
45
+ %( "style.min.css" ) => '/style.min.css',
46
+ %( "http://www.outside.com/image.jpg" ) => 'http://www.outside.com/image.jpg',
47
+ %( "HTTP://www.outside.com/image.jpg" ) => 'HTTP://www.outside.com/image.jpg',
48
+ %( "style", { type: 'stylesheet' } ) => '/stylesheets/style.css',
49
+ %( "xmlhr", { type: 'javascript' } ) => '/javascripts/xmlhr.js',
50
+ %( "xml.png", { type: 'image' } ) => '/images/xml.png',
51
+ %( "foo", { domain: 'http://other.example.com' } ) => 'http://other.example.com/foo',
52
+ %( "style.css", { domain: 'http://other.example.com' } ) => 'http://other.example.com/style.css',
53
+ %( "xmlhr.js", { domain: 'http://other.example.com' } ) => 'http://other.example.com/xmlhr.js',
54
+ %( "xml.png", { domain: 'http://other.example.com' } ) => 'http://other.example.com/xml.png',
55
+ %( "dir/xml.png", { domain: 'http://other.example.com' } ) => 'http://other.example.com/dir/xml.png',
56
+ %( "/dir/xml.png", { domain: 'http://other.example.com' } ) => 'http://other.example.com/dir/xml.png',
57
+ %( "script.min", { domain: 'http://other.example.com' } ) => 'http://other.example.com/script.min',
58
+ %( "script.min.js", { domain: 'http://other.example.com' } ) => 'http://other.example.com/script.min.js',
59
+ %( "style.min", { domain: 'http://other.example.com' } ) => 'http://other.example.com/style.min',
60
+ %( "style.min.css", { domain: 'http://other.example.com' } ) => 'http://other.example.com/style.min.css',
61
+ %( "http://www.outside.com/image.jpg", { domain: 'http://other.example.com' } ) => 'http://www.outside.com/image.jpg',
62
+ %( "HTTP://www.outside.com/image.jpg", { domain: 'http://other.example.com' } ) => 'HTTP://www.outside.com/image.jpg',
63
+ %( "style", { domain: 'http://other.example.com', type: 'stylesheet' } ) => 'http://other.example.com/stylesheets/style.css',
64
+ %( "xmlhr", { domain: 'http://other.example.com', type: 'javascript' } ) => 'http://other.example.com/javascripts/xmlhr.js',
65
+ %( "xml.png", { domain: 'http://other.example.com', type: 'image' } ) => 'http://other.example.com/images/xml.png'
66
+ }
67
+
68
+ def test_asset_path
69
+ AssetPathParams.each do |params, expected|
70
+ assert_js_helper expected, :assetPath, params
71
+ end
72
+ end
73
+
74
+ AssetUrlParams = {
75
+ %( "foo" ) => 'http://www.example.com/foo',
76
+ %( "style.css" ) => 'http://www.example.com/style.css',
77
+ %( "xmlhr.js" ) => 'http://www.example.com/xmlhr.js',
78
+ %( "xml.png" ) => 'http://www.example.com/xml.png',
79
+ %( "dir/xml.png" ) => 'http://www.example.com/dir/xml.png',
80
+ %( "/dir/xml.png" ) => 'http://www.example.com/dir/xml.png',
81
+ %( "script.min" ) => 'http://www.example.com/script.min',
82
+ %( "script.min.js" ) => 'http://www.example.com/script.min.js',
83
+ %( "style.min" ) => 'http://www.example.com/style.min',
84
+ %( "style.min.css" ) => 'http://www.example.com/style.min.css',
85
+ %( "http://www.outside.com/image.jpg" ) => 'http://www.outside.com/image.jpg',
86
+ %( "HTTP://www.outside.com/image.jpg" ) => 'HTTP://www.outside.com/image.jpg',
87
+ %( "style", { type: 'stylesheet' } ) => 'http://www.example.com/stylesheets/style.css',
88
+ %( "xmlhr", { type: 'javascript' } ) => 'http://www.example.com/javascripts/xmlhr.js',
89
+ %( "xml.png", { type: 'image' } ) => 'http://www.example.com/images/xml.png',
90
+ %( "foo", { domain: 'http://other.example.com' } ) => 'http://other.example.com/foo',
91
+ %( "style.css", { domain: 'http://other.example.com' } ) => 'http://other.example.com/style.css',
92
+ %( "xmlhr.js", { domain: 'http://other.example.com' } ) => 'http://other.example.com/xmlhr.js',
93
+ %( "xml.png", { domain: 'http://other.example.com' } ) => 'http://other.example.com/xml.png',
94
+ %( "dir/xml.png", { domain: 'http://other.example.com' } ) => 'http://other.example.com/dir/xml.png',
95
+ %( "/dir/xml.png", { domain: 'http://other.example.com' } ) => 'http://other.example.com/dir/xml.png',
96
+ %( "script.min", { domain: 'http://other.example.com' } ) => 'http://other.example.com/script.min',
97
+ %( "script.min.js", { domain: 'http://other.example.com' } ) => 'http://other.example.com/script.min.js',
98
+ %( "style.min", { domain: 'http://other.example.com' } ) => 'http://other.example.com/style.min',
99
+ %( "style.min.css", { domain: 'http://other.example.com' } ) => 'http://other.example.com/style.min.css',
100
+ %( "http://www.outside.com/image.jpg", { domain: 'http://other.example.com' } ) => 'http://www.outside.com/image.jpg',
101
+ %( "HTTP://www.outside.com/image.jpg", { domain: 'http://other.example.com' } ) => 'HTTP://www.outside.com/image.jpg',
102
+ %( "style", { domain: 'http://other.example.com', type: 'stylesheet' } ) => 'http://other.example.com/stylesheets/style.css',
103
+ %( "xmlhr", { domain: 'http://other.example.com', type: 'javascript' } ) => 'http://other.example.com/javascripts/xmlhr.js',
104
+ %( "xml.png", { domain: 'http://other.example.com', type: 'image' } ) => 'http://other.example.com/images/xml.png'
105
+ }
106
+
107
+ def test_asset_url
108
+ AssetUrlParams.each do |params, expected|
109
+ assert_js_helper expected, :assetUrl, params
110
+ end
111
+ end
112
+
113
+ AudioPathParams = {
114
+ %( "xml" ) => '/audios/xml',
115
+ %( "xml.wav" ) => '/audios/xml.wav',
116
+ %( "dir/xml.wav" ) => '/audios/dir/xml.wav',
117
+ %( "/dir/xml.wav" ) => '/dir/xml.wav',
118
+ %( "xml", { domain: 'http://www.example.com' } ) => 'http://www.example.com/audios/xml',
119
+ %( "xml.wav", { domain: 'http://www.example.com' } ) => 'http://www.example.com/audios/xml.wav',
120
+ %( "dir/xml.wav", { domain: 'http://www.example.com' } ) => 'http://www.example.com/audios/dir/xml.wav',
121
+ %( "/dir/xml.wav", { domain: 'http://www.example.com' } ) => 'http://www.example.com/dir/xml.wav'
122
+ }
123
+
124
+ def test_audio_path
125
+ AudioPathParams.each do |params, expected|
126
+ assert_js_helper expected, :audioPath, params
127
+ end
128
+ end
129
+
130
+ AudioUrlParams = {
131
+ %( "xml" ) => 'http://www.example.com/audios/xml',
132
+ %( "xml.wav" ) => 'http://www.example.com/audios/xml.wav',
133
+ %( "dir/xml.wav" ) => 'http://www.example.com/audios/dir/xml.wav',
134
+ %( "/dir/xml.wav" ) => 'http://www.example.com/dir/xml.wav',
135
+ %( "xml", { domain: 'http://other.example.com' } ) => 'http://other.example.com/audios/xml',
136
+ %( "xml.wav", { domain: 'http://other.example.com' } ) => 'http://other.example.com/audios/xml.wav',
137
+ %( "dir/xml.wav", { domain: 'http://other.example.com' } ) => 'http://other.example.com/audios/dir/xml.wav',
138
+ %( "/dir/xml.wav", { domain: 'http://other.example.com' } ) => 'http://other.example.com/dir/xml.wav'
139
+ }
140
+
141
+ def test_audioUrl
142
+ AudioUrlParams.each do |params, expected|
143
+ assert_js_helper expected, :audioUrl, params
144
+ end
145
+ end
146
+
147
+ FontPathParams = {
148
+ %( "font.eot" ) => '/fonts/font.eot',
149
+ %( "font.eot#iefix" ) => '/fonts/font.eot#iefix',
150
+ %( "font.woff" ) => '/fonts/font.woff',
151
+ %( "font.ttf" ) => '/fonts/font.ttf',
152
+ %( "font.ttf?123" ) => '/fonts/font.ttf?123',
153
+ %( "font.eot", { domain: 'http://www.example.com' } ) => 'http://www.example.com/fonts/font.eot',
154
+ %( "font.eot#iefix", { domain: 'http://www.example.com' } ) => 'http://www.example.com/fonts/font.eot#iefix',
155
+ %( "font.woff", { domain: 'http://www.example.com' } ) => 'http://www.example.com/fonts/font.woff',
156
+ %( "font.ttf", { domain: 'http://www.example.com' } ) => 'http://www.example.com/fonts/font.ttf',
157
+ %( "font.ttf?123", { domain: 'http://www.example.com' } ) => 'http://www.example.com/fonts/font.ttf?123'
158
+ }
159
+
160
+ def test_font_path
161
+ FontPathParams.each do |params, expected|
162
+ assert_js_helper expected, :fontPath, params
163
+ end
164
+ end
165
+
166
+ FontUrlParams = {
167
+ %( "font.eot" ) => 'http://www.example.com/fonts/font.eot',
168
+ %( "font.eot#iefix" ) => 'http://www.example.com/fonts/font.eot#iefix',
169
+ %( "font.woff" ) => 'http://www.example.com/fonts/font.woff',
170
+ %( "font.ttf" ) => 'http://www.example.com/fonts/font.ttf',
171
+ %( "font.ttf?123" ) => 'http://www.example.com/fonts/font.ttf?123',
172
+ %( "font.eot", { domain: 'http://other.example.com' } ) => 'http://other.example.com/fonts/font.eot',
173
+ %( "font.eot#iefix", { domain: 'http://other.example.com' } ) => 'http://other.example.com/fonts/font.eot#iefix',
174
+ %( "font.woff", { domain: 'http://other.example.com' } ) => 'http://other.example.com/fonts/font.woff',
175
+ %( "font.ttf", { domain: 'http://other.example.com' } ) => 'http://other.example.com/fonts/font.ttf',
176
+ %( "font.ttf?123", { domain: 'http://other.example.com' } ) => 'http://other.example.com/fonts/font.ttf?123'
177
+ }
178
+
179
+ def test_font_url
180
+ FontUrlParams.each do |params, expected|
181
+ assert_js_helper expected, :fontUrl, params
182
+ end
183
+ end
184
+
185
+ ImagePathParams = {
186
+ %( "xml" ) => '/images/xml',
187
+ %( "xml.png" ) => '/images/xml.png',
188
+ %( "dir/xml.png" ) => '/images/dir/xml.png',
189
+ %( "/dir/xml.png" ) => '/dir/xml.png',
190
+ %( "xml", { domain: 'http://www.example.com' } ) => 'http://www.example.com/images/xml',
191
+ %( "xml.png", { domain: 'http://www.example.com' } ) => 'http://www.example.com/images/xml.png',
192
+ %( "dir/xml.png", { domain: 'http://www.example.com' } ) => 'http://www.example.com/images/dir/xml.png',
193
+ %( "/dir/xml.png", { domain: 'http://www.example.com' } ) => 'http://www.example.com/dir/xml.png'
194
+ }
195
+
196
+ def test_image_path
197
+ ImagePathParams.each do |params, expected|
198
+ assert_js_helper expected, :imagePath, params
199
+ end
200
+ end
201
+
202
+ ImageUrlParams = {
203
+ %( "xml" ) => 'http://www.example.com/images/xml',
204
+ %( "xml.png" ) => 'http://www.example.com/images/xml.png',
205
+ %( "dir/xml.png" ) => 'http://www.example.com/images/dir/xml.png',
206
+ %( "/dir/xml.png" ) => 'http://www.example.com/dir/xml.png',
207
+ %( "xml", { domain: 'http://other.example.com' } ) => 'http://other.example.com/images/xml',
208
+ %( "xml.png", { domain: 'http://other.example.com' } ) => 'http://other.example.com/images/xml.png',
209
+ %( "dir/xml.png", { domain: 'http://other.example.com' } ) => 'http://other.example.com/images/dir/xml.png',
210
+ %( "/dir/xml.png", { domain: 'http://other.example.com' } ) => 'http://other.example.com/dir/xml.png'
211
+ }
212
+
213
+ def test_image_url
214
+ ImageUrlParams.each do |params, expected|
215
+ assert_js_helper expected, :imageUrl, params
216
+ end
217
+ end
218
+
219
+ JavascriptPathParams = {
220
+ %( "xmlhr" ) => '/javascripts/xmlhr.js',
221
+ %( "super/xmlhr" ) => '/javascripts/super/xmlhr.js',
222
+ %( "/super/xmlhr.js" ) => '/super/xmlhr.js',
223
+ %( "xmlhr.min" ) => '/javascripts/xmlhr.min.js',
224
+ %( "xmlhr.min.js" ) => '/javascripts/xmlhr.min.js',
225
+ %( "xmlhr.js?123" ) => '/javascripts/xmlhr.js?123',
226
+ %( "xmlhr.js?body=1" ) => '/javascripts/xmlhr.js?body=1',
227
+ %( "xmlhr.js#hash" ) => '/javascripts/xmlhr.js#hash',
228
+ %( "xmlhr.js?123#hash" ) => '/javascripts/xmlhr.js?123#hash',
229
+ %( "xmlhr", { domain: 'http://www.example.com' } ) => 'http://www.example.com/javascripts/xmlhr.js',
230
+ %( "super/xmlhr", { domain: 'http://www.example.com' } ) => 'http://www.example.com/javascripts/super/xmlhr.js',
231
+ %( "/super/xmlhr.js", { domain: 'http://www.example.com' } ) => 'http://www.example.com/super/xmlhr.js',
232
+ %( "xmlhr.min", { domain: 'http://www.example.com' } ) => 'http://www.example.com/javascripts/xmlhr.min.js',
233
+ %( "xmlhr.min.js", { domain: 'http://www.example.com' } ) => 'http://www.example.com/javascripts/xmlhr.min.js',
234
+ %( "xmlhr.js?123", { domain: 'http://www.example.com' } ) => 'http://www.example.com/javascripts/xmlhr.js?123',
235
+ %( "xmlhr.js?body=1", { domain: 'http://www.example.com' } ) => 'http://www.example.com/javascripts/xmlhr.js?body=1',
236
+ %( "xmlhr.js#hash", { domain: 'http://www.example.com' } ) => 'http://www.example.com/javascripts/xmlhr.js#hash',
237
+ %( "xmlhr.js?123#hash", { domain: 'http://www.example.com' } ) => 'http://www.example.com/javascripts/xmlhr.js?123#hash'
238
+ }
239
+
240
+ def test_javascript_path
241
+ JavascriptPathParams.each do |params, expected|
242
+ assert_js_helper expected, :javascriptPath, params
243
+ end
244
+ end
245
+
246
+ JavascriptUrlParams = {
247
+ %( "xmlhr" ) => 'http://www.example.com/javascripts/xmlhr.js',
248
+ %( "super/xmlhr" ) => 'http://www.example.com/javascripts/super/xmlhr.js',
249
+ %( "/super/xmlhr.js" ) => 'http://www.example.com/super/xmlhr.js',
250
+ %( "xmlhr.min" ) => 'http://www.example.com/javascripts/xmlhr.min.js',
251
+ %( "xmlhr.min.js" ) => 'http://www.example.com/javascripts/xmlhr.min.js',
252
+ %( "xmlhr.js?123" ) => 'http://www.example.com/javascripts/xmlhr.js?123',
253
+ %( "xmlhr.js?body=1" ) => 'http://www.example.com/javascripts/xmlhr.js?body=1',
254
+ %( "xmlhr.js#hash" ) => 'http://www.example.com/javascripts/xmlhr.js#hash',
255
+ %( "xmlhr.js?123#hash" ) => 'http://www.example.com/javascripts/xmlhr.js?123#hash',
256
+ %( "xmlhr", { domain: 'http://other.example.com' } ) => 'http://other.example.com/javascripts/xmlhr.js',
257
+ %( "super/xmlhr", { domain: 'http://other.example.com' } ) => 'http://other.example.com/javascripts/super/xmlhr.js',
258
+ %( "/super/xmlhr.js", { domain: 'http://other.example.com' } ) => 'http://other.example.com/super/xmlhr.js',
259
+ %( "xmlhr.min", { domain: 'http://other.example.com' } ) => 'http://other.example.com/javascripts/xmlhr.min.js',
260
+ %( "xmlhr.min.js", { domain: 'http://other.example.com' } ) => 'http://other.example.com/javascripts/xmlhr.min.js',
261
+ %( "xmlhr.js?123", { domain: 'http://other.example.com' } ) => 'http://other.example.com/javascripts/xmlhr.js?123',
262
+ %( "xmlhr.js?body=1", { domain: 'http://other.example.com' } ) => 'http://other.example.com/javascripts/xmlhr.js?body=1',
263
+ %( "xmlhr.js#hash", { domain: 'http://other.example.com' } ) => 'http://other.example.com/javascripts/xmlhr.js#hash',
264
+ %( "xmlhr.js?123#hash", { domain: 'http://other.example.com' } ) => 'http://other.example.com/javascripts/xmlhr.js?123#hash'
265
+ }
266
+
267
+ def test_javascript_url
268
+ JavascriptUrlParams.each do |params, expected|
269
+ assert_js_helper expected, :javascriptUrl, params
270
+ end
271
+ end
272
+
273
+ StylesheetPathParams = {
274
+ %( 'bank' ) => '/stylesheets/bank.css',
275
+ %( 'bank.css' ) => '/stylesheets/bank.css',
276
+ %( 'subdir/subdir' ) => '/stylesheets/subdir/subdir.css',
277
+ %( '/subdir/subdir.css' ) => '/subdir/subdir.css',
278
+ %( 'style.min' ) => '/stylesheets/style.min.css',
279
+ %( 'style.min.css' ) => '/stylesheets/style.min.css',
280
+ %( 'bank', { domain: 'http://www.example.com' } ) => 'http://www.example.com/stylesheets/bank.css',
281
+ %( 'bank.css', { domain: 'http://www.example.com' } ) => 'http://www.example.com/stylesheets/bank.css',
282
+ %( 'subdir/subdir', { domain: 'http://www.example.com' } ) => 'http://www.example.com/stylesheets/subdir/subdir.css',
283
+ %( '/subdir/subdir.css', { domain: 'http://www.example.com' } ) => 'http://www.example.com/subdir/subdir.css',
284
+ %( 'style.min', { domain: 'http://www.example.com' } ) => 'http://www.example.com/stylesheets/style.min.css',
285
+ %( 'style.min.css', { domain: 'http://www.example.com' } ) => 'http://www.example.com/stylesheets/style.min.css'
286
+ }
287
+
288
+ def test_stylesheet_path
289
+ StylesheetPathParams.each do |params, expected|
290
+ assert_js_helper expected, :stylesheetPath, params
291
+ end
292
+ end
293
+
294
+ StylesheetUrlParams = {
295
+ %( 'bank' ) => 'http://www.example.com/stylesheets/bank.css',
296
+ %( 'bank.css' ) => 'http://www.example.com/stylesheets/bank.css',
297
+ %( 'subdir/subdir' ) => 'http://www.example.com/stylesheets/subdir/subdir.css',
298
+ %( '/subdir/subdir.css' ) => 'http://www.example.com/subdir/subdir.css',
299
+ %( 'style.min' ) => 'http://www.example.com/stylesheets/style.min.css',
300
+ %( 'style.min.css' ) => 'http://www.example.com/stylesheets/style.min.css',
301
+ %( 'bank', { domain: 'http://other.example.com' } ) => 'http://other.example.com/stylesheets/bank.css',
302
+ %( 'bank.css', { domain: 'http://other.example.com' } ) => 'http://other.example.com/stylesheets/bank.css',
303
+ %( 'subdir/subdir', { domain: 'http://other.example.com' } ) => 'http://other.example.com/stylesheets/subdir/subdir.css',
304
+ %( '/subdir/subdir.css', { domain: 'http://other.example.com' } ) => 'http://other.example.com/subdir/subdir.css',
305
+ %( 'style.min', { domain: 'http://other.example.com' } ) => 'http://other.example.com/stylesheets/style.min.css',
306
+ %( 'style.min.css', { domain: 'http://other.example.com' } ) => 'http://other.example.com/stylesheets/style.min.css'
307
+ }
308
+
309
+ def test_stylesheet_url
310
+ StylesheetUrlParams.each do |params, expected|
311
+ assert_js_helper expected, :stylesheetUrl, params
312
+ end
313
+ end
314
+
315
+ VideoPathParams = {
316
+ %( 'xml' ) => '/videos/xml',
317
+ %( 'xml.ogg' ) => '/videos/xml.ogg',
318
+ %( 'dir/xml.ogg' ) => '/videos/dir/xml.ogg',
319
+ %( '/dir/xml.ogg' ) => '/dir/xml.ogg',
320
+ %( 'xml', { domain: 'http://www.example.com' } ) => 'http://www.example.com/videos/xml',
321
+ %( 'xml.ogg', { domain: 'http://www.example.com' } ) => 'http://www.example.com/videos/xml.ogg',
322
+ %( 'dir/xml.ogg', { domain: 'http://www.example.com' } ) => 'http://www.example.com/videos/dir/xml.ogg',
323
+ %( '/dir/xml.ogg', { domain: 'http://www.example.com' } ) => 'http://www.example.com/dir/xml.ogg'
324
+ }
325
+
326
+ def test_video_path
327
+ VideoPathParams.each do |params, expected|
328
+ assert_js_helper expected, :videoPath, params
329
+ end
330
+ end
331
+
332
+ VideoUrlParams = {
333
+ %( 'xml' ) => 'http://www.example.com/videos/xml',
334
+ %( 'xml.ogg' ) => 'http://www.example.com/videos/xml.ogg',
335
+ %( 'dir/xml.ogg' ) => 'http://www.example.com/videos/dir/xml.ogg',
336
+ %( '/dir/xml.ogg' ) => 'http://www.example.com/dir/xml.ogg',
337
+ %( 'xml', { domain: 'http://other.example.com' } ) => 'http://other.example.com/videos/xml',
338
+ %( 'xml.ogg', { domain: 'http://other.example.com' } ) => 'http://other.example.com/videos/xml.ogg',
339
+ %( 'dir/xml.ogg', { domain: 'http://other.example.com' } ) => 'http://other.example.com/videos/dir/xml.ogg',
340
+ %( '/dir/xml.ogg', { domain: 'http://other.example.com' } ) => 'http://other.example.com/dir/xml.ogg'
341
+ }
342
+
343
+ def test_video_url
344
+ VideoUrlParams.each do |params, expected|
345
+ assert_js_helper expected, :videoUrl, params
346
+ end
347
+ end
348
+
349
+ end