ultimate-base 0.3.5.0 → 0.4.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,60 +0,0 @@
1
- #= require ultimate/underscore/underscore
2
- #= require ultimate/underscore/underscore.string
3
- #= require ultimate/underscore/underscore.inflection
4
- #= require ultimate/helpers/record_tag
5
-
6
- module "Ultimate.Helpers.RecordTag"
7
-
8
- _.extend @, Ultimate.Helpers.RecordTag
9
-
10
- class RecordTagPost
11
- body: "What a wonderful world!"
12
- constructor: (options = {}) ->
13
- _.extend @, options
14
-
15
- record = new RecordTagPost()
16
- singular = 'record_tag_post'
17
-
18
- test "dom_class", ->
19
- equal dom_class(record), singular
20
- equal dom_class(record.constructor.name), singular
21
- equal dom_class(record, "custom_prefix"), "custom_prefix_#{singular}"
22
-
23
- test "dom_id", ->
24
- record.id = null
25
- equal dom_id(record), "new_#{singular}"
26
- equal dom_id(record, "custom_prefix"), "custom_prefix_#{singular}"
27
- record.id = 1
28
- equal dom_id(record), "#{singular}_1"
29
- equal dom_id(record, "edit"), "edit_#{singular}_1"
30
-
31
- test "content_tag_for", ->
32
- record.id = 45
33
- equal content_tag_for('li', record),
34
- "<li class=\"#{singular}\" id=\"#{singular}_45\"></li>"
35
- equal content_tag_for('ul', record, 'archived'),
36
- "<ul class=\"archived_#{singular}\" id=\"archived_#{singular}_45\"></ul>"
37
- equal content_tag_for('tr', record, class: "special", style: "background-color: #f0f0f0"),
38
- "<tr class=\"#{singular} special\" id=\"#{singular}_45\" style=\"background-color: #f0f0f0\"></tr>"
39
- equal content_tag_for('tr', record, 'archived', class: "special", style: "background-color: #f0f0f0"),
40
- "<tr class=\"archived_#{singular} special\" id=\"archived_#{singular}_45\" style=\"background-color: #f0f0f0\"></tr>"
41
- equal content_tag_for('tr', record, -> "<b>#{record.body}</b>"),
42
- "<tr class=\"#{singular}\" id=\"#{singular}_45\"><b>What a wonderful world!</b></tr>"
43
- post_1 = new RecordTagPost(id: 101, body: "Hello!")
44
- post_2 = new RecordTagPost(id: 102, body: "World!")
45
- equal content_tag_for('li', [post_1, post_2], (post) -> post.body),
46
- "<li class=\"#{singular}\" id=\"#{singular}_101\">Hello!</li>\n<li class=\"#{singular}\" id=\"#{singular}_102\">World!</li>"
47
- options = class: 'important'
48
- content_tag_for('li', record, options)
49
- deepEqual options, class: 'important'
50
- strictEqual content_tag_for('tr', null), ""
51
- strictEqual content_tag_for('tr', [null, null]), "\n"
52
-
53
- test "div_for", ->
54
- record.id = 36
55
- equal div_for(record, class: 'special', -> record.body),
56
- "<div class=\"#{singular} special\" id=\"#{singular}_36\">What a wonderful world!</div>"
57
- post_1 = new RecordTagPost(id: 101, body: "Hello!")
58
- post_2 = new RecordTagPost(id: 102, body: "World!")
59
- equal div_for([post_1, post_2], (post) -> post.body),
60
- "<div class=\"#{singular}\" id=\"#{singular}_101\">Hello!</div>\n<div class=\"#{singular}\" id=\"#{singular}_102\">World!</div>"
@@ -1,58 +0,0 @@
1
- #= require ultimate/underscore/underscore
2
- #= require ultimate/underscore/underscore.string
3
- #= require ultimate/helpers/tag
4
-
5
- module "Ultimate.Helpers.Tag"
6
-
7
- _.extend @, Ultimate.Helpers.Tag
8
-
9
- test "tag_options", ->
10
- strictEqual tag_options(), ""
11
- strictEqual tag_options({}), ""
12
- ok /title="Some title"/.test tag_options(class: "some-class", title: "Some title")
13
- equal tag_options(class: ["song", "play>"]), ' class="song play&gt;"'
14
- equal tag_options(disabled: true, itemscope: false, multiple: true, readonly: true), ' disabled="disabled" multiple="multiple" readonly="readonly"'
15
- equal tag_options(data: {remote: true}, role: "ajax"), ' data-remote="true" role="ajax"'
16
- equal tag_options(data: {inner: {section: true}}), ' data-inner="{&quot;section&quot;:true}"'
17
- equal tag_options(data: {inner: {section: true}}, false), ' data-inner="{"section":true}"'
18
- equal tag_options(included: ''), ' included=""'
19
-
20
- test "tag", ->
21
- equal tag('br'), '<br />'
22
- equal tag('br', null, true), '<br>'
23
- equal tag('input', type: 'text', disabled: true), '<input disabled="disabled" type="text" />'
24
- equal tag('img', src: 'open & shut.png'), '<img src="open &amp; shut.png" />'
25
- equal tag("img", {src: "open &amp; shut.png"}, false, false), '<img src="open &amp; shut.png" />'
26
- equal tag("div", data: {name: 'Stephen', city_state: ['Chicago', 'IL']}), '<div data-city-state="[&quot;Chicago&quot;,&quot;IL&quot;]" data-name="Stephen" />'
27
-
28
- test "content_tag", ->
29
- equal content_tag('div', '', class: ['some', 'class']), '<div class="some class"></div>'
30
- equal content_tag('div', '<Inner content>', class: 'some class'), '<div class="some class">&lt;Inner content&gt;</div>'
31
- equal content_tag('div', '<Inner content>', class: 'some class', false), '<div class="some class"><Inner content></div>'
32
- equal content_tag('div', class: 'some class', -> '<Inner content>'), '<div class="some class">&lt;Inner content&gt;</div>'
33
- equal content_tag('div', class: 'some class', false, -> '<Inner content>'), '<div class="some class">&lt;Inner content&gt;</div>'
34
-
35
- test "cdata_section", ->
36
- equal cdata_section("<hello world>"), "<![CDATA[<hello world>]]>"
37
- equal cdata_section("hello]]>world"), "<![CDATA[hello]]]]><![CDATA[>world]]>"
38
- equal cdata_section("hello]]>world]]>again"), "<![CDATA[hello]]]]><![CDATA[>world]]]]><![CDATA[>again]]>"
39
-
40
- test "concat_class", ->
41
- strictEqual concat_class(), ''
42
- strictEqual concat_class(null), ''
43
- strictEqual concat_class([]), ''
44
- equal concat_class('lol', 0), 'lol'
45
- equal concat_class(' lol ', false, ' wow '), 'lol wow'
46
- equal concat_class('lol', null, 'rofl lol wow ', ' wow '), 'lol rofl wow'
47
- equal concat_class([['lol', [null]], 'rofl lol wow '], ' wow '), 'lol rofl wow'
48
-
49
- test "selectorToHtml", ->
50
- equal selectorToHtml(''), ''
51
- equal selectorToHtml('.lol'), '<div class="lol"></div>'
52
- equal selectorToHtml('.mega-lol'), '<div class="mega-lol"></div>'
53
- equal selectorToHtml('tr.lol'), '<tr class="lol"></tr>'
54
- equal selectorToHtml('tr.lol#rofl'), '<tr class="lol" id="rofl"></tr>'
55
- equal selectorToHtml('#rofl.lol'), '<div class="lol" id="rofl"></div>'
56
- equal selectorToHtml('.lol.wow'), '<div class="lol wow"></div>'
57
- equal selectorToHtml('.wow#rofl.lol'), '<div class="wow lol" id="rofl"></div>'
58
- # equal selectorToHtml('h1.one+p.two'), '<h1 class="one"></h1><p class="two"></p>'
@@ -1,76 +0,0 @@
1
- #= require ultimate/underscore/underscore
2
- #= require ultimate/underscore/underscore.string
3
- #= require ultimate/helpers/url
4
-
5
- module "Ultimate.Helpers.Url"
6
-
7
- _.extend @, Ultimate.Helpers.Url
8
-
9
- test "url_for", ->
10
- strictEqual url_for(), 'javascript:;'
11
- strictEqual url_for({}), 'javascript:;'
12
- strictEqual url_for(gamma: 2.2), '?gamma=2.2'
13
- strictEqual url_for(gamma: 2.2, url: 'some_url'), 'some_url?gamma=2.2'
14
- # strictEqual url_for(host: "www.example.com"), 'http://www.example.com/'
15
- strictEqual url_for(url: -> 'some_url'), 'some_url'
16
- options = gamma: 2.2, anchor: 'comments', url: 'some_url', lambda: false
17
- strictEqual url_for(options), 'some_url?gamma=2.2&lambda=false#comments'
18
- deepEqual options, gamma: 2.2, anchor: 'comments', url: 'some_url', lambda: false
19
- strictEqual url_for("back"), 'javascript:history.back();'
20
- strictEqual url_for("/back"), '/back'
21
-
22
- test "link_to", ->
23
- equal link_to('Hello', 'http://www.example.com'), '<a href="http://www.example.com">Hello</a>'
24
- equal link_to('Test Link', '/'), '<a href="/">Test Link</a>'
25
- equal link_to(null, 'http://ya.ru/'), '<a href="http://ya.ru/">http://ya.ru/</a>'
26
- equal link_to('caption'), '<a href="javascript:;">caption</a>'
27
- equal link_to('caption', null, class: 'link'), '<a class="link" href="javascript:;">caption</a>'
28
- equal link_to("Hello", "http://www.example.com", class: "red", data: {confirm: 'You cant possibly be sure,\n can you?'}),
29
- '<a class="red" data-confirm="You cant possibly be sure,\n can you?" href="http://www.example.com">Hello</a>'
30
- equal link_to(null, -> 'caption'), '<a href="javascript:;">caption</a>'
31
- equal link_to(-> 'caption'), '<a href="javascript:;">caption</a>'
32
- equal link_to('0', 'http://www.example.com'), '<a href="http://www.example.com">0</a>'
33
- equal link_to(0, 'http://www.example.com'), '<a href="http://www.example.com">0</a>'
34
- equal link_to(false, 'http://www.example.com'), '<a href="http://www.example.com">false</a>'
35
- equal link_to('', 'http://www.example.com'), '<a href="http://www.example.com"></a>'
36
-
37
- test "link_to_js", ->
38
- equal link_to_js('caption'), '<a href="javascript:;">caption</a>'
39
- equal link_to_js('caption', class: 'link'), '<a class="link" href="javascript:;">caption</a>'
40
- equal link_to_js("Hello", class: "red", data: {confirm: 'You cant possibly be sure,\n can you?'}),
41
- '<a class="red" data-confirm="You cant possibly be sure,\n can you?" href="javascript:;">Hello</a>'
42
- equal link_to_js(null, -> 'caption'), '<a href="javascript:;">caption</a>'
43
- equal link_to_js(class: 'link', -> 'caption'), '<a class="link" href="javascript:;">caption</a>'
44
- equal link_to_js(-> 'caption'), '<a href="javascript:;">caption</a>'
45
-
46
- test "mail_to", ->
47
- equal mail_to("david@loudthinking.com"),
48
- '<a href="mailto:david@loudthinking.com">david@loudthinking.com</a>'
49
- equal mail_to("david@loudthinking.com", "David Heinemeier Hansson"),
50
- '<a href="mailto:david@loudthinking.com">David Heinemeier Hansson</a>'
51
- equal mail_to("david@loudthinking.com", "David Heinemeier Hansson", class: "admin"),
52
- '<a class="admin" href="mailto:david@loudthinking.com">David Heinemeier Hansson</a>'
53
- equal mail_to("me@domain.com", "My email", encode: "javascript"),
54
- "<script>eval(decodeURIComponent('%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%5c%22%6d%61%69%6c%74%6f%3a%6d%65%40%64%6f%6d%61%69%6e%2e%63%6f%6d%5c%22%3e%4d%79%20%65%6d%61%69%6c%3c%5c%2f%61%3e%27%29%3b'))</script>"
55
- # equal mail_to("unicode@example.com", "únicode", encode: "javascript"),
56
- # "<script>eval(decodeURIComponent('%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%5c%22%6d%61%69%6c%74%6f%3a%75%6e%69%63%6f%64%65%40%65%78%61%6d%70%6c%65%2e%63%6f%6d%5c%22%3e%c3%ba%6e%69%63%6f%64%65%3c%5c%2f%61%3e%27%29%3b'))</script>"
57
- equal mail_to("me@example.com", "My email", cc: "ccaddress@example.com", bcc: "bccaddress@example.com", subject: "This is an example email", body: "This is the body of the message."),
58
- '<a href="mailto:me@example.com?cc=ccaddress%40example.com&amp;bcc=bccaddress%40example.com&amp;body=This%20is%20the%20body%20of%20the%20message.&amp;subject=This%20is%20an%20example%20email">My email</a>'
59
- equal mail_to('feedback@example.com', '<img src="/feedback.png" />'),
60
- '<a href="mailto:feedback@example.com"><img src="/feedback.png" /></a>'
61
- equal mail_to("me@domain.com", "My email", encode: "hex"),
62
- '<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d">My email</a>'
63
- equal mail_to("me@domain.com", null, encode: "hex"),
64
- '<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d">&#109;&#101;&#64;&#100;&#111;&#109;&#97;&#105;&#110;&#46;&#99;&#111;&#109;</a>'
65
- equal mail_to("wolfgang@stufenlos.net", null, replace_at: "(at)", replace_dot: "(dot)"),
66
- '<a href="mailto:wolfgang@stufenlos.net">wolfgang(at)stufenlos(dot)net</a>'
67
- equal mail_to("me@domain.com", null, encode: "hex", replace_at: "(at)"),
68
- '<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d">&#109;&#101;&#40;&#97;&#116;&#41;&#100;&#111;&#109;&#97;&#105;&#110;&#46;&#99;&#111;&#109;</a>'
69
- equal mail_to("me@domain.com", "My email", encode: "hex", replace_at: "(at)"),
70
- '<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d">My email</a>'
71
- equal mail_to("me@domain.com", null, encode: "hex", replace_at: "(at)", replace_dot: "(dot)"),
72
- '<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d">&#109;&#101;&#40;&#97;&#116;&#41;&#100;&#111;&#109;&#97;&#105;&#110;&#40;&#100;&#111;&#116;&#41;&#99;&#111;&#109;</a>'
73
- equal mail_to("me@domain.com", "My email", encode: "javascript", replace_at: "(at)", replace_dot: "(dot)"),
74
- "<script>eval(decodeURIComponent('%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%5c%22%6d%61%69%6c%74%6f%3a%6d%65%40%64%6f%6d%61%69%6e%2e%63%6f%6d%5c%22%3e%4d%79%20%65%6d%61%69%6c%3c%5c%2f%61%3e%27%29%3b'))</script>"
75
- equal mail_to("me@domain.com", null, encode: "javascript", replace_at: "(at)", replace_dot: "(dot)"),
76
- "<script>eval(decodeURIComponent('%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%5c%22%6d%61%69%6c%74%6f%3a%6d%65%40%64%6f%6d%61%69%6e%2e%63%6f%6d%5c%22%3e%6d%65%28%61%74%29%64%6f%6d%61%69%6e%28%64%6f%74%29%63%6f%6d%3c%5c%2f%61%3e%27%29%3b'))</script>"