ultimate-base 0.2.4 → 0.3.0.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. data/.gitignore +4 -1
  2. data/.rvmrc +0 -1
  3. data/.rvmrc.example +0 -1
  4. data/Gemfile +6 -0
  5. data/Gemfile.lock +113 -1
  6. data/app/assets/javascripts/ultimate/backbone/base.js.coffee +14 -2
  7. data/app/assets/javascripts/ultimate/backbone/extra/jquery-plugin-adapter.js.coffee +1 -1
  8. data/app/assets/javascripts/ultimate/backbone/model.js.coffee +6 -0
  9. data/app/assets/javascripts/ultimate/backbone/view.js.coffee +5 -4
  10. data/app/assets/javascripts/ultimate/backbone/views/slider.js.coffee +4 -1
  11. data/app/assets/javascripts/ultimate/helpers/asset_tag.js.coffee +71 -54
  12. data/app/assets/javascripts/ultimate/helpers/base.js.coffee +3 -0
  13. data/app/assets/javascripts/ultimate/helpers/decor.js.coffee +19 -14
  14. data/app/assets/javascripts/ultimate/helpers/number.js.coffee +600 -0
  15. data/app/assets/javascripts/ultimate/helpers/record_tag.js.coffee +66 -0
  16. data/app/assets/javascripts/ultimate/helpers/tag.js.coffee +77 -0
  17. data/app/assets/javascripts/ultimate/helpers/url.js.coffee +49 -0
  18. data/app/assets/javascripts/ultimate/helpers.js.coffee +39 -66
  19. data/app/assets/javascripts/ultimate/{devise.js.coffee → improves/devise.js.coffee} +0 -0
  20. data/app/assets/javascripts/ultimate/improves/i18n-lite.js.coffee +18 -12
  21. data/app/assets/javascripts/ultimate/improves/magic-radios.js.coffee +2 -0
  22. data/app/assets/javascripts/ultimate/improves/typed-fields.js.coffee +13 -14
  23. data/app/assets/javascripts/ultimate/{base.js.coffee → jquery.base.js.coffee} +24 -37
  24. data/app/assets/javascripts/ultimate/{experimental/_inflections → underscore}/underscore.inflection.js +19 -18
  25. data/app/assets/javascripts/ultimate/underscore/underscore.outcasts.js.coffee +123 -0
  26. data/app/assets/javascripts/ultimate/underscore/underscore.string.js +16 -6
  27. data/config/routes.rb +2 -0
  28. data/lib/{ultimate-base → ultimate/base}/engine.rb +1 -0
  29. data/lib/{ultimate-base → ultimate/base}/version.rb +1 -1
  30. data/lib/ultimate/base.rb +10 -0
  31. data/lib/{ultimate-base → ultimate}/extensions/directive_processor.rb +0 -0
  32. data/lib/{ultimate-base → ultimate}/extensions/sass_script_functions.rb +0 -0
  33. data/scripts/rails +8 -0
  34. data/test/dummy/Rakefile +7 -0
  35. data/test/dummy/_emfile +18 -0
  36. data/{app/assets/javascripts/ultimate/helpers/forms.js.coffee → test/dummy/app/assets/images/.gitkeep} +0 -0
  37. data/test/dummy/app/assets/javascripts/application.js +3 -0
  38. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  39. data/test/dummy/app/assets/stylesheets/global/forms.css.scss +65 -0
  40. data/test/dummy/app/assets/stylesheets/global/layout/footer.scss +18 -0
  41. data/test/dummy/app/assets/stylesheets/global/layout/header.scss +13 -0
  42. data/test/dummy/app/assets/stylesheets/global/layout/main-menu.scss +68 -0
  43. data/test/dummy/app/assets/stylesheets/global/layout.css.scss +46 -0
  44. data/test/dummy/app/assets/stylesheets/global/reserved.css.scss +79 -0
  45. data/test/dummy/app/assets/stylesheets/global/reset.css.scss +85 -0
  46. data/test/dummy/app/assets/stylesheets/global/structures.css.scss +9 -0
  47. data/test/dummy/app/assets/stylesheets/import/base.scss +34 -0
  48. data/test/dummy/app/assets/stylesheets/plugins/qunit.css.scss +3 -0
  49. data/test/dummy/app/controllers/application_controller.rb +4 -0
  50. data/test/dummy/app/controllers/main_controller.rb +8 -0
  51. data/test/dummy/app/helpers/application_helper.rb +2 -0
  52. data/test/dummy/app/mailers/.gitkeep +0 -0
  53. data/test/dummy/app/models/.gitkeep +0 -0
  54. data/test/dummy/app/views/application/_footer.html.haml +3 -0
  55. data/test/dummy/app/views/application/_header.html.haml +4 -0
  56. data/test/dummy/app/views/application/_main_menu.html.haml +11 -0
  57. data/test/dummy/app/views/layouts/application.html.haml +24 -0
  58. data/test/dummy/app/views/main/index.html.haml +13 -0
  59. data/test/dummy/app/views/main/qunit.html.haml +7 -0
  60. data/test/dummy/config/application.rb +59 -0
  61. data/test/dummy/config/boot.rb +10 -0
  62. data/test/dummy/config/database.yml +25 -0
  63. data/test/dummy/config/environment.rb +5 -0
  64. data/test/dummy/config/environments/development.rb +40 -0
  65. data/test/dummy/config/environments/production.rb +67 -0
  66. data/test/dummy/config/environments/test.rb +37 -0
  67. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  68. data/test/dummy/config/initializers/inflections.rb +15 -0
  69. data/test/dummy/config/initializers/mime_types.rb +5 -0
  70. data/test/dummy/config/initializers/qunit-rails.rb +1 -0
  71. data/test/dummy/config/initializers/secret_token.rb +7 -0
  72. data/test/dummy/config/initializers/session_store.rb +8 -0
  73. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  74. data/test/dummy/config/locales/en.yml +5 -0
  75. data/test/dummy/config/routes.rb +63 -0
  76. data/test/dummy/config.ru +4 -0
  77. data/test/dummy/log/.gitkeep +0 -0
  78. data/test/dummy/public/404.html +26 -0
  79. data/test/dummy/public/422.html +26 -0
  80. data/test/dummy/public/500.html +25 -0
  81. data/test/dummy/public/favicon.ico +0 -0
  82. data/test/dummy/script/rails +6 -0
  83. data/test/javascripts/all_tests.js.coffee +13 -0
  84. data/test/javascripts/test_helper.js.coffee +3 -0
  85. data/test/javascripts/tests/base_test.js.coffee +42 -0
  86. data/test/javascripts/tests/helpers/asset_tag_test.js.coffee +51 -0
  87. data/test/javascripts/tests/helpers/number_test.js.coffee +250 -0
  88. data/test/javascripts/tests/helpers/record_tag_test.js.coffee +56 -0
  89. data/test/javascripts/tests/helpers/tag_test.js.coffee +33 -0
  90. data/test/javascripts/tests/helpers/url_test.js.coffee +28 -0
  91. data/test/javascripts/tests/helpers_test.js.coffee +47 -0
  92. data/test/javascripts/tests/improves/i18n-lite_test.js.coffee +25 -0
  93. data/test/javascripts/tests/underscore/underscore.outcasts.test.js.coffee +38 -0
  94. data/test/stylesheets/test_helper.css +4 -0
  95. data/ultimate-base.gemspec +4 -4
  96. metadata +116 -24
  97. data/app/assets/javascripts/ultimate/bus.js.coffee +0 -57
  98. data/app/assets/javascripts/ultimate/experimental/_inflections/dzone.inflections.js +0 -154
  99. data/app/assets/javascripts/ultimate/helpers/array.js.coffee +0 -63
  100. data/app/assets/javascripts/ultimate/helpers/tags.js.coffee +0 -73
  101. data/app/assets/javascripts/ultimate/widgets/dock.js.coffee +0 -70
  102. data/app/assets/javascripts/ultimate/widgets/gear.js.coffee +0 -84
  103. data/app/assets/javascripts/ultimate/widgets/jquery-ext.js.coffee +0 -104
  104. data/app/assets/javascripts/ultimate/widgets/jquery.adapter.js.coffee +0 -62
  105. data/app/assets/javascripts/ultimate/widgets/widget.js.coffee +0 -115
  106. data/lib/ultimate-base.rb +0 -10
@@ -0,0 +1,51 @@
1
+ #= require ultimate/underscore/underscore
2
+ #= require ultimate/underscore/underscore.string
3
+ #= require ultimate/helpers/asset_tag
4
+
5
+ module "Ultimate.Helpers.AssetTag"
6
+
7
+ _.extend @, Ultimate.Helpers.AssetTag
8
+
9
+ test "favicon_link_tag", ->
10
+ equal favicon_link_tag(), '<link href="/images/favicon.ico" rel="shortcut icon" type="image/vnd.microsoft.icon" />'
11
+ equal favicon_link_tag('favicon.ico'), '<link href="/images/favicon.ico" rel="shortcut icon" type="image/vnd.microsoft.icon" />'
12
+ equal favicon_link_tag('favicon.ico', rel: 'foo'), '<link href="/images/favicon.ico" rel="foo" type="image/vnd.microsoft.icon" />'
13
+ equal favicon_link_tag('favicon.ico', rel: 'foo', type: 'bar'), '<link href="/images/favicon.ico" rel="foo" type="bar" />'
14
+ equal favicon_link_tag('mb-icon.png', rel: 'apple-touch-icon', type: 'image/png'), '<link href="/images/mb-icon.png" rel="apple-touch-icon" type="image/png" />'
15
+
16
+ test "image_path", ->
17
+ equal image_path(""), ''
18
+ equal image_path("xml"), '/images/xml'
19
+ equal image_path("xml.png"), '/images/xml.png'
20
+ equal image_path("dir/xml.png"), '/images/dir/xml.png'
21
+ equal image_path("/dir/xml.png"), '/dir/xml.png'
22
+
23
+ test "path_to_image", ->
24
+ equal path_to_image(""), ''
25
+ equal path_to_image("xml"), '/images/xml'
26
+ equal path_to_image("xml.png"), '/images/xml.png'
27
+ equal path_to_image("dir/xml.png"), '/images/dir/xml.png'
28
+ equal path_to_image("/dir/xml.png"), '/dir/xml.png'
29
+
30
+ test "image_alt", ->
31
+ for prefix in ['', '/', '/foo/bar/', 'foo/bar/']
32
+ equal image_alt("#{prefix}rails.png"), 'Rails'
33
+ equal image_alt("#{prefix}rails-9c0a079bdd7701d7e729bd956823d153.png"), 'Rails'
34
+ equal image_alt("#{prefix}avatar-0000.png"), 'Avatar-0000'
35
+
36
+ test "image_tag", ->
37
+ equal image_tag("xml.png"), '<img alt="Xml" src="/images/xml.png" />'
38
+ equal image_tag("rss.gif", alt: "rss syndication"), '<img alt="rss syndication" src="/images/rss.gif" />'
39
+ equal image_tag("gold.png", size: "45x70"), '<img alt="Gold" height="70" src="/images/gold.png" width="45" />'
40
+ equal image_tag("gold.png", size: "45x70"), '<img alt="Gold" height="70" src="/images/gold.png" width="45" />'
41
+ equal image_tag("error.png", size: "45"), '<img alt="Error" src="/images/error.png" />'
42
+ equal image_tag("error.png", size: "45 x 70"), '<img alt="Error" src="/images/error.png" />'
43
+ equal image_tag("error.png", size: "x"), '<img alt="Error" src="/images/error.png" />'
44
+ equal image_tag("google.com.png"), '<img alt="Google.com" src="/images/google.com.png" />'
45
+ equal image_tag("slash..png"), '<img alt="Slash." src="/images/slash..png" />'
46
+ equal image_tag(".pdf.png"), '<img alt=".pdf" src="/images/.pdf.png" />'
47
+ equal image_tag("http://www.rubyonrails.com/images/rails.png"), '<img alt="Rails" src="http://www.rubyonrails.com/images/rails.png" />'
48
+ equal image_tag("//www.rubyonrails.com/images/rails.png"), '<img alt="Rails" src="//www.rubyonrails.com/images/rails.png" />'
49
+ equal image_tag("mouse.png", alt: null), '<img src="/images/mouse.png" />'
50
+ equal image_tag("data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==", alt: null), '<img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" />'
51
+ equal image_tag(""), '<img src="" />'
@@ -0,0 +1,250 @@
1
+ #= require ultimate/underscore/underscore
2
+ #= require ultimate/underscore/underscore.string
3
+ #= require ultimate/improves/i18n-lite
4
+ #= require ultimate/helpers/number
5
+
6
+ module "Ultimate.Helpers.Number"
7
+
8
+ _.extend @, Ultimate.Helpers.Number
9
+
10
+ kilobytes = (number) -> number * 1024
11
+ megabytes = (number) -> kilobytes(number) * 1024
12
+ gigabytes = (number) -> megabytes(number) * 1024
13
+ terabytes = (number) -> gigabytes(number) * 1024
14
+
15
+ test "number_to_phone", ->
16
+ equal number_to_phone(5551234), "555-1234"
17
+ equal number_to_phone(8005551212), "800-555-1212"
18
+ equal number_to_phone(8005551212, area_code: true), "(800) 555-1212"
19
+ strictEqual number_to_phone("", area_code: true), ""
20
+ equal number_to_phone(8005551212, delimiter: " "), "800 555 1212"
21
+ equal number_to_phone(8005551212, area_code: true, extension: 123), "(800) 555-1212 x 123"
22
+ equal number_to_phone(8005551212, extension: " "), "800-555-1212"
23
+ strictEqual number_to_phone(5551212, delimiter: '.'), "555.1212"
24
+ equal number_to_phone("8005551212"), "800-555-1212"
25
+ equal number_to_phone(8005551212, country_code: 1), "+1-800-555-1212"
26
+ strictEqual number_to_phone(8005551212, country_code: 1, delimiter: ''), "+18005551212"
27
+ equal number_to_phone(225551212), "22-555-1212"
28
+ equal number_to_phone(225551212, country_code: 45), "+45-22-555-1212"
29
+ equal number_to_phone(911), "911"
30
+ equal number_to_phone(0), "0"
31
+ equal number_to_phone(-1), "1"
32
+
33
+ test "number_to_currency", ->
34
+ equal number_to_currency(1234567890.50), "$1,234,567,890.50"
35
+ equal number_to_currency(1234567890.506), "$1,234,567,890.51"
36
+ equal number_to_currency(-1234567890.50), "-$1,234,567,890.50"
37
+ equal number_to_currency(-1234567890.50, format: "%u %n"), "-$ 1,234,567,890.50"
38
+ equal number_to_currency(-1234567890.50, negative_format: "(%u%n)"), "($1,234,567,890.50)"
39
+ equal number_to_currency(1234567891.50, precision: 0), "$1,234,567,892"
40
+ equal number_to_currency(1234567890.50, precision: 1), "$1,234,567,890.5"
41
+ equal number_to_currency(1234567890.50, unit: "&pound;", separator: ",", delimiter: ""), "&pound;1234567890,50"
42
+ equal number_to_currency("1234567890.50"), "$1,234,567,890.50"
43
+ equal number_to_currency("1234567890.50", unit: "K&#269;", format: "%n %u"), "1,234,567,890.50 K&#269;"
44
+ equal number_to_currency("-1234567890.50", unit: "K&#269;", format: "%n %u", negative_format: "%n - %u"), "1,234,567,890.50 - K&#269;"
45
+ strictEqual number_to_currency(0.0, unit: "", negative_format: "(%n)"), "0.00"
46
+
47
+ test "number_to_percentage", ->
48
+ equal number_to_percentage(100), "100.000%"
49
+ equal number_to_percentage(100, precision: 0), "100%"
50
+ equal number_to_percentage(302.0574, precision: 2), "302.06%"
51
+ equal number_to_percentage("100"), "100.000%"
52
+ equal number_to_percentage("1000"), "1000.000%"
53
+ equal number_to_percentage(123.400, precision: 3, strip_insignificant_zeros: true), "123.4%"
54
+ equal number_to_percentage(1000, delimiter: '.', separator: ','), "1.000,000%"
55
+ equal number_to_percentage(1000, format: "%n %"), "1000.000 %"
56
+ equal number_to_percentage(0), "0.000%"
57
+ equal number_to_percentage(-1), "-1.000%"
58
+
59
+ test "number_to_delimited", ->
60
+ strictEqual number_to_delimited(12345678), "12,345,678"
61
+ strictEqual number_to_delimited(0), "0"
62
+ strictEqual number_to_delimited(123), "123"
63
+ strictEqual number_to_delimited(123456), "123,456"
64
+ strictEqual number_to_delimited(123456.78), "123,456.78"
65
+ strictEqual number_to_delimited(123456.789), "123,456.789"
66
+ strictEqual number_to_delimited(123456.78901), "123,456.78901"
67
+ strictEqual number_to_delimited(123456789.78901), "123,456,789.78901"
68
+ strictEqual number_to_delimited(0.78901), "0.78901"
69
+ strictEqual number_to_delimited("123456.78"), "123,456.78"
70
+ strictEqual number_to_delimited(12345678, delimiter: ' '), "12 345 678"
71
+ strictEqual number_to_delimited(12345678.05, separator: '-'), "12,345,678-05"
72
+ strictEqual number_to_delimited(12345678.05, separator: ',', delimiter: '.'), "12.345.678,05"
73
+ strictEqual number_to_delimited(12345678.05, delimiter: '.', separator: ','), "12.345.678,05"
74
+
75
+ test "round_with_precision", ->
76
+ strictEqual round_with_precision(10/3), 3.33
77
+ strictEqual round_with_precision(10/3, 0), 3
78
+ strictEqual round_with_precision(100/3, 5), 33.33333
79
+ strictEqual round_with_precision(100/3, -1), 30
80
+ strictEqual round_with_precision("19.3", -1), 20
81
+ # strictEqual round_with_precision(9.995, 2), 10
82
+ strictEqual round_with_precision(null), 0
83
+
84
+ test "number_to_rounded", ->
85
+ strictEqual number_to_rounded(-111.2346), "-111.235"
86
+ strictEqual number_to_rounded(111.2346), "111.235"
87
+ strictEqual number_to_rounded(31.825, precision: 2), "31.83"
88
+ strictEqual number_to_rounded(111.2346, precision: 2), "111.23"
89
+ strictEqual number_to_rounded(111, precision: 2), "111.00"
90
+ strictEqual number_to_rounded("111.2346"), "111.235"
91
+ strictEqual number_to_rounded("31.825", precision: 2), "31.83"
92
+ strictEqual number_to_rounded((32.6751 * 100.00), precision: 0), "3268"
93
+ strictEqual number_to_rounded(111.50, precision: 0), "112"
94
+ strictEqual number_to_rounded(1234567891.50, precision: 0), "1234567892"
95
+ strictEqual number_to_rounded(0, precision: 0), "0"
96
+ strictEqual number_to_rounded(0.001, precision: 5), "0.00100"
97
+ strictEqual number_to_rounded(0.00111, precision: 3), "0.001"
98
+ # strictEqual number_to_rounded(9.995, precision: 2), "10.00"
99
+ strictEqual number_to_rounded(10.995, precision: 2), "11.00"
100
+ strictEqual number_to_rounded(-0.001, precision: 2), "0.00"
101
+ strictEqual number_to_rounded(31.825, precision: 2, separator: ','), "31,83"
102
+ strictEqual number_to_rounded(1231.825, precision: 2, separator: ',', delimiter: '.'), "1.231,83"
103
+ strictEqual number_to_rounded(123987, precision: 3, significant: true), "124000"
104
+ strictEqual number_to_rounded(123987876, precision: 2, significant: true ), "120000000"
105
+ strictEqual number_to_rounded("43523", precision: 1, significant: true ), "40000"
106
+ strictEqual number_to_rounded(9775, precision: 4, significant: true ), "9775"
107
+ strictEqual number_to_rounded(5.3923, precision: 2, significant: true ), "5.4"
108
+ strictEqual number_to_rounded(5.3923, precision: 1, significant: true ), "5"
109
+ strictEqual number_to_rounded(1.232, precision: 1, significant: true ), "1"
110
+ strictEqual number_to_rounded(7, precision: 1, significant: true ), "7"
111
+ strictEqual number_to_rounded(1, precision: 1, significant: true ), "1"
112
+ strictEqual number_to_rounded(52.7923, precision: 2, significant: true ), "53"
113
+ strictEqual number_to_rounded(9775, precision: 6, significant: true ), "9775.00"
114
+ strictEqual number_to_rounded(5.3929, precision: 7, significant: true ), "5.392900"
115
+ strictEqual number_to_rounded(0, precision: 2, significant: true ), "0.0"
116
+ strictEqual number_to_rounded(0, precision: 1, significant: true ), "0"
117
+ strictEqual number_to_rounded(0.0001, precision: 1, significant: true ), "0.0001"
118
+ strictEqual number_to_rounded(0.0001, precision: 3, significant: true ), "0.000100"
119
+ strictEqual number_to_rounded(0.0001111, precision: 1, significant: true ), "0.0001"
120
+ # strictEqual number_to_rounded(9.995, precision: 3, significant: true), "10.0"
121
+ strictEqual number_to_rounded(9.994, precision: 3, significant: true), "9.99"
122
+ strictEqual number_to_rounded(10.995, precision: 3, significant: true), "11.0"
123
+ strictEqual number_to_rounded(9775.43, precision: 4, strip_insignificant_zeros: true ), "9775.43"
124
+ strictEqual number_to_rounded(9775.2, precision: 6, significant: true, strip_insignificant_zeros: true ), "9775.2"
125
+ strictEqual number_to_rounded(0, precision: 6, significant: true, strip_insignificant_zeros: true ), "0"
126
+ strictEqual number_to_rounded(123.987, precision: 0, significant: true), "124"
127
+ strictEqual number_to_rounded(12, precision: 0, significant: true ), "12"
128
+ strictEqual number_to_rounded("12.3", precision: 0, significant: true ), "12"
129
+
130
+ test "number_to_human_size", ->
131
+ equal number_to_human_size(0), "0 Bytes"
132
+ # equal number_to_human_size(1), "1 Byte"
133
+ equal number_to_human_size(3.14159265), "3 Bytes"
134
+ equal number_to_human_size(123.0), "123 Bytes"
135
+ equal number_to_human_size(123), "123 Bytes"
136
+ equal number_to_human_size(1234), "1.21 KB"
137
+ equal number_to_human_size(12345), "12.1 KB"
138
+ equal number_to_human_size(1234567), "1.18 MB"
139
+ equal number_to_human_size(1234567890), "1.15 GB"
140
+ equal number_to_human_size(1234567890123), "1.12 TB"
141
+ equal number_to_human_size(terabytes(1026)), "1030 TB"
142
+ equal number_to_human_size(kilobytes(444)), "444 KB"
143
+ equal number_to_human_size(megabytes(1023)), "1020 MB"
144
+ equal number_to_human_size(terabytes(3)), "3 TB"
145
+ equal number_to_human_size(1234567, precision: 2), "1.2 MB"
146
+ equal number_to_human_size(3.14159265, precision: 4), "3 Bytes"
147
+ equal number_to_human_size('123'), "123 Bytes"
148
+ equal number_to_human_size(kilobytes(1.0123), precision: 2), "1 KB"
149
+ equal number_to_human_size(kilobytes(1.0100), precision: 4), "1.01 KB"
150
+ equal number_to_human_size(kilobytes(10.000), precision: 4), "10 KB"
151
+ # equal number_to_human_size(1.1), "1 Byte"
152
+ equal number_to_human_size(10), "10 Bytes"
153
+ equal number_to_human_size(3.14159265, prefix: 'si'), "3 Bytes"
154
+ equal number_to_human_size(123.0, prefix: 'si'), "123 Bytes"
155
+ equal number_to_human_size(123, prefix: 'si'), "123 Bytes"
156
+ equal number_to_human_size(1234, prefix: 'si'), "1.23 KB"
157
+ equal number_to_human_size(12345, prefix: 'si'), "12.3 KB"
158
+ equal number_to_human_size(1234567, prefix: 'si'), "1.23 MB"
159
+ equal number_to_human_size(1234567890, prefix: 'si'), "1.23 GB"
160
+ equal number_to_human_size(1234567890123, prefix: 'si'), "1.23 TB"
161
+ equal number_to_human_size(1234567, precision: 2), "1.2 MB"
162
+ equal number_to_human_size(3.14159265, precision: 4), "3 Bytes"
163
+ equal number_to_human_size(kilobytes(1.0123), precision: 2), "1 KB"
164
+ equal number_to_human_size(kilobytes(1.0100), precision: 4), "1.01 KB"
165
+ equal number_to_human_size(kilobytes(10.000), precision: 4), "10 KB"
166
+ equal number_to_human_size(1234567890123, precision: 1), "1 TB"
167
+ equal number_to_human_size(524288000, precision: 3), "500 MB"
168
+ equal number_to_human_size(9961472, precision: 0), "10 MB"
169
+ equal number_to_human_size(41010, precision: 1), "40 KB"
170
+ equal number_to_human_size(41100, precision: 2), "40 KB"
171
+ equal number_to_human_size(kilobytes(1.0123), precision: 2, strip_insignificant_zeros: false), "1.0 KB"
172
+ equal number_to_human_size(kilobytes(1.0123), precision: 3, significant: false), "1.012 KB"
173
+ equal number_to_human_size(kilobytes(1.0123), precision: 0, significant: true), "1 KB" #ignores significant it precision is 0
174
+ equal number_to_human_size(kilobytes(1.0123), precision: 3, separator: ','), "1,01 KB"
175
+ equal number_to_human_size(kilobytes(1.0100), precision: 4, separator: ','), "1,01 KB"
176
+ equal number_to_human_size(terabytes(1000.1), precision: 5, delimiter: '.', separator: ','), "1.000,1 TB"
177
+
178
+ test "number_to_human", ->
179
+ strictEqual number_to_human(-123), "-123"
180
+ strictEqual number_to_human(-0.5), "-0.5"
181
+ strictEqual number_to_human(0), "0"
182
+ strictEqual number_to_human(0.5), "0.5"
183
+ strictEqual number_to_human(123), "123"
184
+ equal number_to_human(1234), "1.23 Thousand"
185
+ equal number_to_human(12345), "12.3 Thousand"
186
+ equal number_to_human(1234567), "1.23 Million"
187
+ equal number_to_human(1234567890), "1.23 Billion"
188
+ equal number_to_human(1234567890123), "1.23 Trillion"
189
+ equal number_to_human(1234567890123456), "1.23 Quadrillion"
190
+ equal number_to_human(1234567890123456789), "1230 Quadrillion"
191
+ equal number_to_human(489939, precision: 2), "490 Thousand"
192
+ equal number_to_human(489939, precision: 4), "489.9 Thousand"
193
+ equal number_to_human(489000, precision: 4), "489 Thousand"
194
+ equal number_to_human(489000, precision: 4, strip_insignificant_zeros: false), "489.0 Thousand"
195
+ equal number_to_human(1234567, precision: 4, significant: false), "1.2346 Million"
196
+ equal number_to_human(1234567, precision: 1, significant: false, separator: ','), "1,2 Million"
197
+ equal number_to_human(1234567, precision: 0, significant: true, separator: ','), "1 Million" #significant forced to false
198
+ #Only integers
199
+ volume = unit: "ml", thousand: "lt", million: "m3"
200
+ equal number_to_human(123456, units: volume), "123 lt"
201
+ equal number_to_human(12, units: volume), "12 ml"
202
+ equal number_to_human(1234567, units: volume), "1.23 m3"
203
+ #Including fractionals
204
+ distance = mili: "mm", centi: "cm", deci: "dm", unit: "m", ten: "dam", hundred: "hm", thousand: "km"
205
+ equal number_to_human(0.00123, units: distance), "1.23 mm"
206
+ equal number_to_human(0.0123, units: distance), "1.23 cm"
207
+ equal number_to_human(0.123, units: distance), "1.23 dm"
208
+ equal number_to_human(1.23, units: distance), "1.23 m"
209
+ equal number_to_human(12.3, units: distance), "1.23 dam"
210
+ equal number_to_human(123, units: distance), "1.23 hm"
211
+ equal number_to_human(1230, units: distance), "1.23 km"
212
+ equal number_to_human(1230, units: distance), "1.23 km"
213
+ equal number_to_human(1230, units: distance), "1.23 km"
214
+ equal number_to_human(12300, units: distance), "12.3 km"
215
+ #The quantifiers don't need to be a continuous sequence
216
+ gangster = hundred: "hundred bucks", million: "thousand quids"
217
+ equal number_to_human(100, units: gangster), "1 hundred bucks"
218
+ equal number_to_human(2500, units: gangster), "25 hundred bucks"
219
+ equal number_to_human(25000000, units: gangster), "25 thousand quids"
220
+ equal number_to_human(12345000000, units: gangster), "12300 thousand quids"
221
+ #Spaces are stripped from the resulting string
222
+ strictEqual number_to_human(4, units: unit: "", ten: 'tens '), "4"
223
+ equal number_to_human(45, units: unit: "", ten: ' tens '), "4.5 tens"
224
+ equal number_to_human(123456, format: "%n times %u"), "123 times Thousand"
225
+ volume = unit: "ml", thousand: "lt", million: "m3"
226
+ equal number_to_human(123456, units: volume, format: "%n.%u"), "123.lt"
227
+
228
+ number_to_helpers = _.string.words("phone currency percentage delimited rounded human_size human")
229
+
230
+ test "number helpers should return empty string when given null", number_to_helpers.length, =>
231
+ for h in number_to_helpers
232
+ strictEqual @["number_to_#{h}"](null), "", "number_to_#{h}"
233
+
234
+ test "number helpers don't mutate options hash", number_to_helpers.length, =>
235
+ options = raise: true
236
+ for h in number_to_helpers
237
+ @["number_to_#{h}"](1, options)
238
+ deepEqual options, {raise: true}, "number_to_#{h}"
239
+
240
+ test "number helpers should return non numeric param unchanged", ->
241
+ equal number_to_phone("x", country_code: 1, extension: 123), "+1-x x 123"
242
+ equal number_to_phone("x"), "x"
243
+ equal number_to_currency("x."), "$x."
244
+ equal number_to_currency("x"), "$x"
245
+ equal number_to_percentage("x"), "x%"
246
+ equal number_to_delimited("x"), "x"
247
+ equal number_to_rounded("x."), "x."
248
+ equal number_to_rounded("x"), "x"
249
+ equal number_to_human_size('x'), "x"
250
+ equal number_to_human('x'), "x"
@@ -0,0 +1,56 @@
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, "custom_prefix"), "custom_prefix_#{singular}"
21
+
22
+ test "dom_id", ->
23
+ record.id = null
24
+ equal dom_id(record), "new_#{singular}"
25
+ equal dom_id(record, "custom_prefix"), "custom_prefix_#{singular}"
26
+ record.id = 1
27
+ equal dom_id(record), "#{singular}_1"
28
+ equal dom_id(record, "edit"), "edit_#{singular}_1"
29
+
30
+ test "content_tag_for", ->
31
+ record.id = 45
32
+ equal content_tag_for('li', record),
33
+ "<li class=\"#{singular}\" id=\"#{singular}_45\"></li>"
34
+ equal content_tag_for('ul', record, 'archived'),
35
+ "<ul class=\"archived_#{singular}\" id=\"archived_#{singular}_45\"></ul>"
36
+ equal content_tag_for('tr', record, class: "special", style: "background-color: #f0f0f0"),
37
+ "<tr class=\"#{singular} special\" id=\"#{singular}_45\" style=\"background-color: #f0f0f0\"></tr>"
38
+ equal content_tag_for('tr', record, 'archived', class: "special", style: "background-color: #f0f0f0"),
39
+ "<tr class=\"archived_#{singular} special\" id=\"archived_#{singular}_45\" style=\"background-color: #f0f0f0\"></tr>"
40
+ equal content_tag_for('tr', record, -> record.body),
41
+ "<tr class=\"#{singular}\" id=\"#{singular}_45\">What a wonderful world!</tr>"
42
+ post_1 = new RecordTagPost(id: 101, body: "Hello!")
43
+ post_2 = new RecordTagPost(id: 102, body: "World!")
44
+ equal content_tag_for('li', [post_1, post_2], (post) -> post.body),
45
+ "<li class=\"#{singular}\" id=\"#{singular}_101\">Hello!</li>\n<li class=\"#{singular}\" id=\"#{singular}_102\">World!</li>"
46
+ options = class: 'important'
47
+ content_tag_for('li', record, options)
48
+ deepEqual options, class: 'important'
49
+
50
+ test "div_for", ->
51
+ equal div_for(record, class: 'special', -> record.body),
52
+ "<div class=\"#{singular} special\" id=\"#{singular}_45\">What a wonderful world!</div>"
53
+ post_1 = new RecordTagPost(id: 101, body: "Hello!")
54
+ post_2 = new RecordTagPost(id: 102, body: "World!")
55
+ equal div_for([post_1, post_2], (post) -> post.body),
56
+ "<div class=\"#{singular}\" id=\"#{singular}_101\">Hello!</div>\n<div class=\"#{singular}\" id=\"#{singular}_102\">World!</div>"
@@ -0,0 +1,33 @@
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
+ strictEqual tag_options(class: ["song", "play>"]), ' class="song play&gt;"'
14
+ strictEqual tag_options(disabled: true, itemscope: false, multiple: true, readonly: true), ' disabled="disabled" multiple="multiple" readonly="readonly"'
15
+ strictEqual tag_options(data: {remote: true}, role: "ajax"), ' data-remote="true" role="ajax"'
16
+ strictEqual tag_options(data: {inner: {section: true}}), ' data-inner="{&quot;section&quot;:true}"'
17
+ strictEqual tag_options(data: {inner: {section: true}}, false), ' data-inner="{"section":true}"'
18
+ strictEqual tag_options(included: ''), ' included=""'
19
+
20
+ test "tag", ->
21
+ strictEqual tag('br'), '<br />'
22
+ strictEqual tag('br', null, true), '<br>'
23
+ strictEqual tag('input', type: 'text', disabled: true), '<input disabled="disabled" type="text" />'
24
+ strictEqual tag('img', src: 'open & shut.png'), '<img src="open &amp; shut.png" />'
25
+ # strictEqual tag("img", {src: "open &amp; shut.png"}, false, false), '<img src="open &amp; shut.png" />'
26
+ # strictEqual tag("div", data: {name: 'Stephen', city_state: "(Chicago IL)"}), '<div data-name="Stephen" data-city-state="[&quot;Chicago&quot;,&quot;IL&quot;]" />'
27
+
28
+ test "content_tag", ->
29
+ strictEqual content_tag('div', '', class: ['some', 'class']), '<div class="some class"></div>'
30
+ strictEqual content_tag('div', '<Inner content>', class: 'some class'), '<div class="some class">&lt;Inner content&gt;</div>'
31
+ strictEqual content_tag('div', '<Inner content>', class: 'some class', false), '<div class="some class"><Inner content></div>'
32
+ strictEqual content_tag('div', class: 'some class', -> '<Inner content>'), '<div class="some class">&lt;Inner content&gt;</div>'
33
+ strictEqual content_tag('div', class: 'some class', false, -> '<Inner content>'), '<div class="some class">&lt;Inner content&gt;</div>'
@@ -0,0 +1,28 @@
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
+ strictEqual link_to('Hello', 'http://www.example.com'), '<a href="http://www.example.com">Hello</a>'
24
+ strictEqual link_to('Test Link', '/'), '<a href="/">Test Link</a>'
25
+ strictEqual link_to(null, 'http://ya.ru/'), '<a href="http://ya.ru/">http://ya.ru/</a>'
26
+ strictEqual link_to('caption'), '<a href="javascript:;">caption</a>'
27
+ strictEqual link_to("Hello", "http://www.example.com", class: "red", data: {confirm: 'You cant possibly be sure,\n can you?'}),
28
+ '<a class="red" data-confirm="You cant possibly be sure,\n can you?" href="http://www.example.com">Hello</a>'
@@ -0,0 +1,47 @@
1
+ #= require ultimate/underscore/underscore
2
+ #= require ultimate/helpers
3
+
4
+ module "ultimate/helpers"
5
+
6
+ test "cout", ->
7
+ ok _.isBoolean(window.DEBUG_MODE), "global DEBUG_MODE is Boolean"
8
+ window.DEBUG_MODE = true
9
+ strictEqual cout(123), 123, "cout() must return first argument"
10
+ window.DEBUG_MODE = false
11
+ for method in ['log', 'info', 'warn', 'error', 'assert', 'clear']
12
+ strictEqual cout(method, 123), 123, "cout() must return second argument if first is `#{method}` as method"
13
+ window.DEBUG_MODE = true
14
+
15
+ test "_cout", ->
16
+ strictEqual _cout(123), 123, "_cout() must return first argument"
17
+ for method in ['log', 'info', 'warn', 'error', 'assert', 'clear']
18
+ strictEqual _cout(method, 123), method, "_cout() on so strong that it does not use the method `#{method}` as first argument, and return first argument always"
19
+
20
+ test "deprecate", ->
21
+ equal deprecate('first thing'), "`first thing` DEPRECATED!", "log and return message about deprecated function"
22
+ equal deprecate('first thing', 'second thing'), "`first thing` DEPRECATED! Use instead `second thing`", "log and return message about deprecated function, and hint about using instead"
23
+
24
+ test "todo", ->
25
+ ok _.isBoolean(window.LOG_TODO), "global LOG_TODO is Boolean"
26
+ window.LOG_TODO = true
27
+ equal todo('some todo'), "TODO: some todo", "log and return todo"
28
+ equal todo('some todo', "helpers_test.js.coffee"), "TODO: some todo ### helpers_test.js.coffee", "log and return todo with location string"
29
+ equal todo('some todo', "helpers_test.js.coffee", "test \"deprecate\""), "TODO: some todo ### helpers_test.js.coffee > test \"deprecate\"", "log and return todo with description of function"
30
+ equal todo('some todo', "helpers_test.js.coffee", 12), "TODO: some todo ### helpers_test.js.coffee:12", "log and return message with string number"
31
+ window.LOG_TODO = false
32
+ equal todo('some todo'), undefined, "don't log and return `undefined` if global LOG_TODO == false"
33
+ window.LOG_TODO = true
34
+
35
+ test "logicalXOR", ->
36
+ strictEqual logicalXOR(false, false), false, "false XOR false === false"
37
+ strictEqual logicalXOR(false, true), true, "false XOR true === true"
38
+ strictEqual logicalXOR(true, false), true, "true XOR false === true"
39
+ strictEqual logicalXOR(true, true), false, "true XOR true === false"
40
+
41
+ test "bound", ->
42
+ equal bound(0, 10, 100), 10
43
+ equal bound(100, 10, 100), 100
44
+ equal bound(50, 10, 100), 50
45
+ equal bound(-20, -10, 100), -10
46
+ equal bound(-20, 10, -10), 10
47
+ equal bound(20, 10, -10), 10
@@ -0,0 +1,25 @@
1
+ #= require ultimate/underscore/underscore
2
+ #= require ultimate/underscore/underscore.string
3
+ #= require ultimate/improves/i18n-lite
4
+
5
+ module "ultimate/improves/i18n-lite"
6
+
7
+ I18n.translations =
8
+ models:
9
+ post:
10
+ title: "Post title"
11
+ body: "Post body"
12
+
13
+ test "locale", ->
14
+ equal I18n.locale, 'en'
15
+
16
+ test "translate", ->
17
+ ok _.isFunction(I18n.translate)
18
+ ok _.isFunction(I18n.t)
19
+ equal I18n.translate('models.post.missing_key'), 'models.post.missing_key'
20
+ equal I18n.translate('models.post.missing_key', default: 'Default value'), 'Default value'
21
+ equal I18n.translate('models.post.missing_key', default: 0), 0
22
+ equal I18n.translate('models.post.missing_key', default: ''), ''
23
+ equal I18n.translate('models.post.body'), 'Post body'
24
+ equal I18n.t('models.post.body'), 'Post body'
25
+ deepEqual I18n.t('models.post'), title: 'Post title', body: 'Post body'
@@ -0,0 +1,38 @@
1
+ #= require ultimate/underscore/underscore
2
+ #= require ultimate/underscore/underscore.outcasts
3
+
4
+ # Include Underscore.outcasts methods to Underscore namespace
5
+ _.mixin(_.outcasts.exports())
6
+
7
+ module('Underscore.outcasts')
8
+
9
+ test "delete", ->
10
+ obj = a: 'Apple', b: 'Banana'
11
+ equal _.delete(obj, 'a'), 'Apple'
12
+ deepEqual obj, {b: 'Banana'}
13
+
14
+ test "blockGiven", ->
15
+ do (v1 = 111, v2 = 222, v3 = 333) ->
16
+ strictEqual _.blockGiven(arguments), null
17
+ strictEqual _.blockGiven([]), null
18
+ do (v1 = 111, v2 = 222, block = (_v) -> "block #{_v}") ->
19
+ ok _.isFunction(_.blockGiven(arguments))
20
+ equal _.blockGiven(arguments)('given'), "block given"
21
+
22
+ test "sortHash", ->
23
+ deepEqual _.sortHash({}), []
24
+ deepEqual _.sortHash(title: 'cadabra', alt: 'bubble', href: 'abra'), [['alt', 'bubble'], ['href', 'abra'], ['title', 'cadabra']]
25
+ deepEqual _.sortHash(title: 'cadabra', alt: 'bubble', href: 'abra', true), [['href', 'abra'], ['alt', 'bubble'], ['title', 'cadabra']]
26
+
27
+ test "invert", ->
28
+ deepEqual _.invert(a: 1, b: 2, c: 0), {1: 'a', 2: 'b', 0: 'c'}
29
+ obj =
30
+ a: 1
31
+ b: 2
32
+ c: 0
33
+ d: 1
34
+ 2: 'e-1'
35
+ f: -> 'func'
36
+ deepEqual _.invert(obj), {1: ['a', 'd'], 2: 'b', 0: 'c', 'e-1': '2'}
37
+ deepEqual _.invert(_.invert(obj)), {a: '1', b: '2', c: '0', d: '1', 2: 'e-1'}
38
+ deepEqual _.invert(), {}
@@ -0,0 +1,4 @@
1
+ /*
2
+ *= require application
3
+ *= require_tree .
4
+ */
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
- require "ultimate-base/version"
3
+ require "ultimate/base/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "ultimate-base"
@@ -13,9 +13,9 @@ Gem::Specification.new do |s|
13
13
 
14
14
  s.rubyforge_project = "ultimate-base"
15
15
 
16
- #s.add_dependency "rails", "~> 3.1"
17
- #s.add_dependency "coffee-script", "~> 2.1"
18
- #s.add_dependency "sass", "~> 3.1"
16
+ s.add_development_dependency "rails", "~> 3.2.8"
17
+ s.add_development_dependency "sqlite3"
18
+ s.add_development_dependency "coffee-rails", "~> 3.2.1"
19
19
 
20
20
  s.files = `git ls-files`.split("\n")
21
21
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")