ultimate-base 0.3.1.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. data/Gemfile.lock +15 -15
  2. data/app/assets/javascripts/ultimate/backbone/lib/backbone.js +70 -56
  3. data/app/assets/javascripts/ultimate/backbone/model.js.coffee +2 -2
  4. data/app/assets/javascripts/ultimate/backbone/view.js.coffee +5 -4
  5. data/app/assets/javascripts/ultimate/backbone/views/typed-fields.js.coffee +1 -1
  6. data/app/assets/javascripts/ultimate/helpers/asset_tag.js.coffee +21 -19
  7. data/app/assets/javascripts/ultimate/helpers/form_options.js.coffee +65 -0
  8. data/app/assets/javascripts/ultimate/helpers/form_tag.js.coffee +177 -0
  9. data/app/assets/javascripts/ultimate/helpers/javascript.js.coffee +31 -0
  10. data/app/assets/javascripts/ultimate/helpers/record_tag.js.coffee +29 -15
  11. data/app/assets/javascripts/ultimate/helpers/tag.js.coffee +7 -3
  12. data/app/assets/javascripts/ultimate/helpers/url.js.coffee +62 -7
  13. data/app/assets/javascripts/ultimate/jquery-plugin-adapter.js.coffee +1 -0
  14. data/app/assets/javascripts/ultimate/jquery-plugin-class.js.coffee +35 -16
  15. data/app/assets/javascripts/ultimate/jquery.base.js.coffee +1 -1
  16. data/app/assets/javascripts/ultimate/underscore/underscore.js +292 -192
  17. data/app/assets/javascripts/ultimate/underscore/underscore.outcasts.js.coffee +27 -2
  18. data/app/assets/javascripts/ultimate/underscore/underscore.string.js +4 -4
  19. data/app/assets/stylesheets/polyfills/PIE.htc +81 -81
  20. data/app/assets/stylesheets/polyfills/boxsizing.htc +255 -54
  21. data/app/assets/stylesheets/ultimate/mixins/_vendors.scss +9 -0
  22. data/app/assets/stylesheets/ultimate/mixins/css3.scss +39 -28
  23. data/app/assets/stylesheets/ultimate/mixins/microstructures.scss +32 -6
  24. data/lib/ultimate/base/version.rb +1 -1
  25. data/test/javascripts/tests/helpers/asset_tag_test.js.coffee +1 -1
  26. data/test/javascripts/tests/helpers/form_options_test.js.coffee +96 -0
  27. data/test/javascripts/tests/helpers/form_tag_test.js.coffee +225 -0
  28. data/test/javascripts/tests/helpers/javascript_test.js.coffee +25 -0
  29. data/test/javascripts/tests/helpers/record_tag_test.js.coffee +5 -3
  30. data/test/javascripts/tests/helpers/tag_test.js.coffee +22 -17
  31. data/test/javascripts/tests/helpers/url_test.js.coffee +50 -6
  32. data/test/javascripts/tests/underscore/underscore.outcasts.test.js.coffee +9 -0
  33. metadata +8 -4
  34. data/app/assets/javascripts/ultimate/helpers/translation.js.coffee +0 -97
  35. data/test/javascripts/tests/helpers/translation_test.js.coffee +0 -140
@@ -32,3 +32,12 @@
32
32
  #{$property}: $params;
33
33
  }
34
34
  }
35
+
36
+ @mixin vendors-full($vendors, $property, $params, $origin: true) {
37
+ @each $vendor in $vendors {
38
+ -#{$vendor}-#{$property}: -#{$vendor}-#{$params};
39
+ }
40
+ @if $origin {
41
+ #{$property}: $params;
42
+ }
43
+ }
@@ -122,7 +122,7 @@ $boxsizing-url: asset-url("polyfills/boxsizing.htc", '') !default;
122
122
  // produce:
123
123
  // background-color: $bg-color;
124
124
  // background-image: -webkit-gradient(linear, right top, left top, color-stop(0%, green), color-stop(20%, orange), color-stop(100%, red)); // old webkit (Safari <= 5.0, iOS-Safari <= 4.3, Android <= 3.0)
125
- // background-image: -webkit-linear-gradient(right, green, orange 20%, red 100%); // Chrome 10+, Safari 5.1+
125
+ // background-image: -webkit-linear-gradient(right, green, orange 20%, red 100%); // Chrome 10+, Safari 5.1+, Android 4.0+
126
126
  // background-image: -moz-linear-gradient(right, green, orange 20%, red 100%); // FF 3.6+
127
127
  // background-image: -ms-linear-gradient(right, green, orange 20%, red 100%); // IE 10+
128
128
  // background-image: -o-linear-gradient(right, green, orange 20%, red 100%); // Opera 11.1+
@@ -147,7 +147,7 @@ $boxsizing-url: asset-url("polyfills/boxsizing.htc", '') !default;
147
147
  }
148
148
  $wk_stops: ();
149
149
  $stops_length: length($stops);
150
- $repcents-by-stop: 100 / ($stops_length - 1);
150
+ $percents-by-stop: 100 / ($stops_length - 1);
151
151
  $i: 0;
152
152
  $p: 0;
153
153
  @each $stop in $stops {
@@ -158,12 +158,12 @@ $boxsizing-url: asset-url("polyfills/boxsizing.htc", '') !default;
158
158
  }
159
159
  $stop: "#{$cp}, #{nth($stop, 1)}";
160
160
  $wk_stops: append($wk_stops, color-stop(#{$stop}), comma);
161
- $p: $p + $repcents-by-stop;
161
+ $p: $p + $percents-by-stop;
162
162
  }
163
163
  $bg-color: nth(nth($stops, 1), 1);
164
164
  background-color: $bg-color;
165
165
  background-image: -webkit-gradient(linear, $wk_start, $wk_end, $wk_stops);
166
- $linear-gradient: linear-gradient($corner_angle, $stops);
166
+ $linear-gradient: linear-gradient($corner_angle, change-separator($stops));
167
167
  @include vendors-param(webkit moz ms o, background-image, $linear-gradient);
168
168
  @if $support-ie and $pie-url {
169
169
  -pie-background: $bg-color $linear-gradient;
@@ -189,35 +189,42 @@ $boxsizing-url: asset-url("polyfills/boxsizing.htc", '') !default;
189
189
  // example:
190
190
  // @include radial-gradient(center 45deg, circle closest-side, (orange 0%, red 100%));
191
191
  // produce:
192
- // background-image: -webkit-radial-gradient(center 45deg, circle closest-side, orange 0%, red 100%); // Chrome 10+, Safari 5.1+
192
+ // background-image: -webkit-radial-gradient(center 45deg, circle closest-side, orange 0%, red 100%); // Chrome 10+, Safari 5.1+, Android 4.0+
193
193
  // background-image: -moz-radial-gradient(center 45deg, circle closest-side, orange 0%, red 100%); // FF 3.6+
194
194
  // background-image: -ms-radial-gradient(center 45deg, circle closest-side, orange 0%, red 100%); // IE 10+
195
195
  // background-image: -o-radial-gradient(center 45deg, circle closest-side, orange 0%, red 100%); // Opera 11.6+
196
196
  // background-image: radial-gradient(center 45deg, circle closest-side, orange 0%, red 100%); // future
197
197
  @mixin radial-gradient($position_angle, $shape_size, $stops) {
198
- // TODO may be deprecate background-image: -webkit-gradient(radial, $wk_start, $wk_end, unquote(list-to-string($wk_stops, ", ")));
199
198
  @include vendors-param(webkit moz ms o, background-image, radial-gradient($position_angle, $shape_size, change-separator($stops)));
200
199
  }
201
200
 
201
+ @mixin border-gradient_simple($color_start, $color_stop, $is_horizontal: false) {
202
+ $color_mix: mix($color_start, $color_stop);
203
+ @if $is_horizontal {
204
+ border-color: $color_mix $color_stop $color_mix $color_start;
205
+ } @else {
206
+ border-color: $color_start $color_mix $color_stop;
207
+ }
208
+ }
209
+
202
210
  // EXPERIMENTAL
211
+ // Temporary remove webkit support, because find bug in Chromium 20
203
212
  @mixin border-gradient($color_start, $color_stop, $is_horizontal: false) {
213
+ @include border-gradient_simple($color_start, $color_stop, $is_horizontal);
204
214
  $start: top;
205
- $wk_start: left top;
206
- $wk_stop: left bottom;
215
+ //$wk_start: left top;
216
+ //$wk_stop: left bottom;
207
217
  @if $is_horizontal {
208
218
  $start: left;
209
- $wk_stop: right top;
210
- } @else {
211
- $start: top;
212
- $wk_stop: left bottom;
219
+ //$wk_stop: right top;
213
220
  }
214
- border-color: $color_start mix($color_start, $color_stop) $color_stop;
215
- -webkit-border-image: -webkit-gradient(linear, $wk_start, $wk_stop, from($color_start), to($color_stop)); // old webkit (Safari <= 5.0, iOS-Safari <= 4.3, Android <= 3.0)
216
- // TODO may be new -webkit-gradient?
217
- -moz-border-image: -moz-linear-gradient($start, $color_start, $color_stop); // FF 3.5+
218
- -ms-border-image: -ms-linear-gradient($start, $color_start, $color_stop); // IE 10+
219
- -o-border-image: -o-linear-gradient($start, $color_start, $color_stop); // Opera 11.0+
220
- border-image: linear-gradient($start, $color_start, $color_stop); // future
221
+ // -webkit-border-image: -webkit-gradient(linear, $wk_start, $wk_stop, from($color_start), to($color_stop)); // old webkit (Safari <= 5.0, iOS-Safari <= 4.3, Android <= 3.0)
222
+ @include vendors-full(moz ms o, border-image, linear-gradient($start, $color_start, $color_stop));
223
+ //-webkit-border-image: -webkit-linear-gradient($start, $color_start, $color_stop); // Chrome 10+, Safari 5.1+, Android 4.0+
224
+ // -moz-border-image: -moz-linear-gradient($start, $color_start, $color_stop); // FF 3.5+
225
+ // -ms-border-image: -ms-linear-gradient($start, $color_start, $color_stop); // IE 10+
226
+ // -o-border-image: -o-linear-gradient($start, $color_start, $color_stop); // Opera 11.0+
227
+ // border-image: linear-gradient($start, $color_start, $color_stop); // future
221
228
  }
222
229
 
223
230
  // Provide cross-browser CSS opacity.
@@ -320,12 +327,16 @@ $boxsizing-url: asset-url("polyfills/boxsizing.htc", '') !default;
320
327
  }
321
328
  }
322
329
 
323
- // TODO
324
- //@mixin placeholder($params) {
325
- // &::-webkit-input-placeholder, &:-moz-placeholder {
326
- // #{$params};
327
- // }
328
- //}
329
- //input::-webkit-input-placeholder { color: #a3a3a3 !important;}
330
- //input:-moz-placeholder { color: #a3a3a3 !important; }
331
-
330
+ // Style the html5 input placeholder in browsers that support it.
331
+ // The styles for the input placeholder are passed as mixin content.
332
+ // Mostly supported properties: color, font-*, letter-spacing.
333
+ // example:
334
+ // @include input-placeholder {
335
+ // color: #bfbfbf;
336
+ // font-style: italic;
337
+ // }
338
+ @mixin input-placeholder {
339
+ &::-webkit-input-placeholder { @content; }
340
+ &:-moz-placeholder { @content; }
341
+ &:-ms-input-placeholder { @content; }
342
+ }
@@ -65,18 +65,44 @@ $support-ie: true !default;
65
65
  }
66
66
  }
67
67
 
68
+ @mixin before($display: block, $content: '') {
69
+ &:before {
70
+ display: $display;
71
+ content: $content;
72
+ @content;
73
+ }
74
+ }
75
+
76
+ @mixin after($display: block, $content: '') {
77
+ &:after {
78
+ display: $display;
79
+ content: $content;
80
+ @content;
81
+ }
82
+ }
83
+
84
+ @mixin both($display: block, $content: '') {
85
+ &:before, &:after {
86
+ display: $display;
87
+ content: $content;
88
+ @content;
89
+ }
90
+ }
91
+
68
92
  // Set to container includes float blocks.
69
- @mixin g-line {
93
+ @mixin g-line($clear: both) {
70
94
  @include deprecate("@include g-line;", "overflow: hidden;");
71
95
  @if $support-ie {
72
96
  *zoom: 1;
73
97
  _height: 0;
74
98
  }
75
- &:after {
76
- content: " ";
77
- display: block;
78
- clear: both;
79
- height: 0;
99
+ @include clearfix($clear);
100
+ }
101
+
102
+ // Adapted from: [A new micro clearfix hack](http://nicolasgallagher.com/micro-clearfix-hack/)
103
+ @mixin clearfix($clear: both) {
104
+ @include both(table) {
105
+ clear: $clear;
80
106
  }
81
107
  }
82
108
 
@@ -1,5 +1,5 @@
1
1
  module Ultimate
2
2
  module Base
3
- VERSION = "0.3.1.1"
3
+ VERSION = "0.3.2"
4
4
  end
5
5
  end
@@ -36,9 +36,9 @@ test "image_alt", ->
36
36
  test "image_tag", ->
37
37
  equal image_tag("xml.png"), '<img alt="Xml" src="/images/xml.png" />'
38
38
  equal image_tag("rss.gif", alt: "rss syndication"), '<img alt="rss syndication" src="/images/rss.gif" />'
39
+ equal image_tag("gold.png", size: "20"), '<img alt="Gold" height="20" src="/images/gold.png" width="20" />'
39
40
  equal image_tag("gold.png", size: "45x70"), '<img alt="Gold" height="70" src="/images/gold.png" width="45" />'
40
41
  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
42
  equal image_tag("error.png", size: "45 x 70"), '<img alt="Error" src="/images/error.png" />'
43
43
  equal image_tag("error.png", size: "x"), '<img alt="Error" src="/images/error.png" />'
44
44
  equal image_tag("google.com.png"), '<img alt="Google.com" src="/images/google.com.png" />'
@@ -0,0 +1,96 @@
1
+ #= require ultimate/underscore/underscore
2
+ #= require ultimate/underscore/underscore.string
3
+ #= require ultimate/underscore/underscore.outcasts
4
+ #= require ultimate/helpers/form_options
5
+
6
+ module "Ultimate.Helpers.FormOptions"
7
+
8
+ _.extend @, Ultimate.Helpers.FormOptions
9
+
10
+ test "options_for_select", ->
11
+ options = '<option value="Denmark">Denmark</option><option value="USA">USA</option><option value="Sweden">Sweden</option>'
12
+ equal options_for_select(options), options
13
+ equal options_for_select([ "<Denmark>", "USA", "Sweden" ]),
14
+ "<option value=\"&lt;Denmark&gt;\">&lt;Denmark&gt;</option>\n<option value=\"USA\">USA</option>\n<option value=\"Sweden\">Sweden</option>"
15
+ equal options_for_select([ "Denmark", "<USA>", "Sweden" ], "<USA>"),
16
+ "<option value=\"Denmark\">Denmark</option>\n<option selected=\"selected\" value=\"&lt;USA&gt;\">&lt;USA&gt;</option>\n<option value=\"Sweden\">Sweden</option>"
17
+ equal options_for_select([ "Denmark", "<USA>", "Sweden" ], [ "<USA>", "Sweden" ]),
18
+ "<option value=\"Denmark\">Denmark</option>\n<option selected=\"selected\" value=\"&lt;USA&gt;\">&lt;USA&gt;</option>\n<option selected=\"selected\" value=\"Sweden\">Sweden</option>"
19
+ equal options_for_select([ "Denmark", "<USA>", "Sweden" ], disabled: "<USA>"),
20
+ "<option value=\"Denmark\">Denmark</option>\n<option disabled=\"disabled\" value=\"&lt;USA&gt;\">&lt;USA&gt;</option>\n<option value=\"Sweden\">Sweden</option>"
21
+ equal options_for_select([ "Denmark", "<USA>", "Sweden" ], disabled: ["<USA>", "Sweden"]),
22
+ "<option value=\"Denmark\">Denmark</option>\n<option disabled=\"disabled\" value=\"&lt;USA&gt;\">&lt;USA&gt;</option>\n<option disabled=\"disabled\" value=\"Sweden\">Sweden</option>"
23
+ equal options_for_select([ "Denmark", "<USA>", "Sweden" ], selected: "Denmark", disabled: "<USA>"),
24
+ "<option selected=\"selected\" value=\"Denmark\">Denmark</option>\n<option disabled=\"disabled\" value=\"&lt;USA&gt;\">&lt;USA&gt;</option>\n<option value=\"Sweden\">Sweden</option>"
25
+ equal options_for_select([ true, false ], selected: false, disabled: null),
26
+ "<option value=\"true\">true</option>\n<option selected=\"selected\" value=\"false\">false</option>"
27
+ equal options_for_select([1..3]),
28
+ "<option value=\"1\">1</option>\n<option value=\"2\">2</option>\n<option value=\"3\">3</option>"
29
+ equal options_for_select([ "ruby", "rubyonrails" ], "rubyonrails"),
30
+ "<option value=\"ruby\">ruby</option>\n<option selected=\"selected\" value=\"rubyonrails\">rubyonrails</option>"
31
+ equal options_for_select([ "ruby", "rubyonrails" ], "ruby"),
32
+ "<option selected=\"selected\" value=\"ruby\">ruby</option>\n<option value=\"rubyonrails\">rubyonrails</option>"
33
+ equal options_for_select([ "ruby", "rubyonrails", null ], "ruby"),
34
+ "<option selected=\"selected\" value=\"ruby\">ruby</option>\n<option value=\"rubyonrails\">rubyonrails</option>\n<option value=\"\"></option>"
35
+ equal options_for_select("$": "Dollar", "<DKR>": "<Kroner>"),
36
+ "<option value=\"Dollar\">$</option>\n<option value=\"&lt;Kroner&gt;\">&lt;DKR&gt;</option>"
37
+ equal options_for_select({ "$": "Dollar", "<DKR>": "<Kroner>" }, "Dollar"),
38
+ "<option selected=\"selected\" value=\"Dollar\">$</option>\n<option value=\"&lt;Kroner&gt;\">&lt;DKR&gt;</option>"
39
+ equal options_for_select({ "$": "Dollar", "<DKR>": "<Kroner>" }, [ "Dollar", "<Kroner>" ]),
40
+ "<option selected=\"selected\" value=\"Dollar\">$</option>\n<option selected=\"selected\" value=\"&lt;Kroner&gt;\">&lt;DKR&gt;</option>"
41
+ equal options_for_select([ [ "<Denmark>", { class: 'bold' } ], [ "USA", { onclick: "alert('Hello World');" } ], [ "Sweden" ], "Germany" ]),
42
+ "<option class=\"bold\" value=\"&lt;Denmark&gt;\">&lt;Denmark&gt;</option>\n<option onclick=\"alert(&apos;Hello World&apos;);\" value=\"USA\">USA</option>\n<option value=\"Sweden\">Sweden</option>\n<option value=\"Germany\">Germany</option>"
43
+ equal options_for_select([ [ "<Denmark>", { data: { test: 'bold' } } ] ]),
44
+ "<option data-test=\"bold\" value=\"&lt;Denmark&gt;\">&lt;Denmark&gt;</option>"
45
+ equal options_for_select([ [ "<Denmark>", { data: { test: '<bold>' } } ] ]),
46
+ "<option data-test=\"&lt;bold&gt;\" value=\"&lt;Denmark&gt;\">&lt;Denmark&gt;</option>"
47
+ equal options_for_select([ "<Denmark>", [ "USA", { class: 'bold' } ], "Sweden" ], "USA"),
48
+ "<option value=\"&lt;Denmark&gt;\">&lt;Denmark&gt;</option>\n<option class=\"bold\" selected=\"selected\" value=\"USA\">USA</option>\n<option value=\"Sweden\">Sweden</option>"
49
+ equal options_for_select([ "<Denmark>", [ "USA", { class: 'bold' } ], "Sweden" ], [ "USA", "Sweden" ]),
50
+ "<option value=\"&lt;Denmark&gt;\">&lt;Denmark&gt;</option>\n<option class=\"bold\" selected=\"selected\" value=\"USA\">USA</option>\n<option selected=\"selected\" value=\"Sweden\">Sweden</option>"
51
+ equal options_for_select([ [ "<Denmark>", { onclick: 'alert("<code>")' } ] ]),
52
+ "<option onclick=\"alert(&quot;&lt;code&gt;&quot;)\" value=\"&lt;Denmark&gt;\">&lt;Denmark&gt;</option>"
53
+
54
+
55
+
56
+ class Post
57
+ title : null
58
+ author_name : null
59
+ body : null
60
+ secret : null
61
+ written_on : null
62
+ category : null
63
+ origin : null
64
+ allow_comments : null
65
+
66
+ constructor: ->
67
+ keys = ['title', 'author_name', 'body', 'secret', 'written_on', 'category', 'origin', 'allow_comments']
68
+ for a, i in arguments
69
+ @[keys[i]] = a
70
+
71
+ dummy_posts =
72
+ [ new Post("<Abe> went home", "<Abe>", "To a little house", "shh!"),
73
+ new Post("Babe went home", "Babe", "To a little house", "shh!"),
74
+ new Post("Cabe went home", "Cabe", "To a little house", "shh!") ]
75
+
76
+ test "options_from_collection_for_select", ->
77
+ equal options_from_collection_for_select(dummy_posts, "author_name", "title"),
78
+ "<option value=\"&lt;Abe&gt;\">&lt;Abe&gt; went home</option>\n<option value=\"Babe\">Babe went home</option>\n<option value=\"Cabe\">Cabe went home</option>"
79
+ equal options_from_collection_for_select(dummy_posts, "author_name", "title", "Babe"),
80
+ "<option value=\"&lt;Abe&gt;\">&lt;Abe&gt; went home</option>\n<option selected=\"selected\" value=\"Babe\">Babe went home</option>\n<option value=\"Cabe\">Cabe went home</option>"
81
+ equal options_from_collection_for_select(dummy_posts, "author_name", "title", [ "Babe", "Cabe" ]),
82
+ "<option value=\"&lt;Abe&gt;\">&lt;Abe&gt; went home</option>\n<option selected=\"selected\" value=\"Babe\">Babe went home</option>\n<option selected=\"selected\" value=\"Cabe\">Cabe went home</option>"
83
+ equal options_from_collection_for_select(dummy_posts, "author_name", "title", (p) -> p.author_name is 'Babe'),
84
+ "<option value=\"&lt;Abe&gt;\">&lt;Abe&gt; went home</option>\n<option selected=\"selected\" value=\"Babe\">Babe went home</option>\n<option value=\"Cabe\">Cabe went home</option>"
85
+ equal options_from_collection_for_select(dummy_posts, "author_name", "title", disabled: "Babe"),
86
+ "<option value=\"&lt;Abe&gt;\">&lt;Abe&gt; went home</option>\n<option disabled=\"disabled\" value=\"Babe\">Babe went home</option>\n<option value=\"Cabe\">Cabe went home</option>"
87
+ equal options_from_collection_for_select(dummy_posts, "author_name", "title", disabled: [ "Babe", "Cabe" ]),
88
+ "<option value=\"&lt;Abe&gt;\">&lt;Abe&gt; went home</option>\n<option disabled=\"disabled\" value=\"Babe\">Babe went home</option>\n<option disabled=\"disabled\" value=\"Cabe\">Cabe went home</option>"
89
+ equal options_from_collection_for_select(dummy_posts, "author_name", "title", selected: "Cabe", disabled: "Babe"),
90
+ "<option value=\"&lt;Abe&gt;\">&lt;Abe&gt; went home</option>\n<option disabled=\"disabled\" value=\"Babe\">Babe went home</option>\n<option selected=\"selected\" value=\"Cabe\">Cabe went home</option>"
91
+ equal options_from_collection_for_select(dummy_posts, "author_name", "title", disabled: (p) -> p.author_name in ['Babe', 'Cabe']),
92
+ "<option value=\"&lt;Abe&gt;\">&lt;Abe&gt; went home</option>\n<option disabled=\"disabled\" value=\"Babe\">Babe went home</option>\n<option disabled=\"disabled\" value=\"Cabe\">Cabe went home</option>"
93
+ equal options_from_collection_for_select(dummy_posts, ((p) -> p.author_name), "title"),
94
+ "<option value=\"&lt;Abe&gt;\">&lt;Abe&gt; went home</option>\n<option value=\"Babe\">Babe went home</option>\n<option value=\"Cabe\">Cabe went home</option>"
95
+ equal options_from_collection_for_select(dummy_posts, "author_name", (p) -> p.title),
96
+ "<option value=\"&lt;Abe&gt;\">&lt;Abe&gt; went home</option>\n<option value=\"Babe\">Babe went home</option>\n<option value=\"Cabe\">Cabe went home</option>"
@@ -0,0 +1,225 @@
1
+ #= require ultimate/underscore/underscore
2
+ #= require ultimate/underscore/underscore.string
3
+ #= require ultimate/underscore/underscore.outcasts
4
+ #= require ultimate/helpers/form_tag
5
+
6
+ module "Ultimate.Helpers.FormTag"
7
+
8
+ _.extend @, Ultimate.Helpers.FormTag
9
+
10
+ hidden_fields = (options = {}) ->
11
+ method = options['method']
12
+ txt = '<div style="margin:0;padding:0;display:inline">'
13
+ txt += '<input name="utf8" type="hidden" value="&#x2713;" />'
14
+ if method and not (method in ['get', 'post'])
15
+ txt += '<input name="_method" type="hidden" value="' + method + '" />'
16
+ txt + '</div>'
17
+
18
+ form_text = (action = 'http://www.example.com', options = {}) ->
19
+ [remote, enctype, html_class, id, method] = _.map(_.string.words('remote enctype html_class id method'), (key) -> options[key])
20
+ method = 'post' if method isnt 'get'
21
+ txt = "<form accept-charset=\"UTF-8\" action=\"#{action}\""
22
+ txt += " enctype=\"multipart/form-data\"" if enctype
23
+ txt += " data-remote=\"true\"" if remote
24
+ txt += " class=\"#{html_class}\"" if html_class
25
+ txt += " id=\"#{id}\"" if id
26
+ txt += " method=\"#{method}\">"
27
+ txt
28
+
29
+ whole_form = (action = 'javascript:;', options = {}) ->
30
+ out = form_text(action, options) + hidden_fields(options)
31
+ if block = _.outcasts.blockGiven(arguments)
32
+ out += block() + "</form>"
33
+ out
34
+
35
+ test "form_tag", ->
36
+ equal form_tag(), whole_form()
37
+ equal form_tag({}, multipart: true), whole_form(null, enctype: true)
38
+ equal form_tag({}, method: 'patch'), whole_form(null, method: 'patch')
39
+ equal form_tag({}, method: 'put'), whole_form(null, method: 'put')
40
+ equal form_tag({}, method: 'delete'), whole_form(null, method: 'delete')
41
+ equal form_tag({}, remote: true), whole_form(null, remote: true)
42
+ equal form_tag(-> 'Hello world!'), whole_form(null, -> 'Hello world!')
43
+ equal form_tag(null, method: 'put', -> 'Hello world!'), whole_form(null, method: 'put', -> 'Hello world!')
44
+
45
+ test "select_tag", ->
46
+ equal select_tag("people", "<option>david</option>"),
47
+ '<select id="people" name="people"><option>david</option></select>'
48
+ equal select_tag("colors", "<option>Red</option><option>Blue</option><option>Green</option>", multiple: true),
49
+ '<select id="colors" multiple="multiple" name="colors[]"><option>Red</option><option>Blue</option><option>Green</option></select>'
50
+ equal select_tag("places", "<option>Home</option><option>Work</option><option>Pub</option>", disabled: true),
51
+ '<select disabled="disabled" id="places" name="places"><option>Home</option><option>Work</option><option>Pub</option></select>'
52
+ equal select_tag("places", "<option>Home</option><option>Work</option><option>Pub</option>", include_blank: true),
53
+ '<select id="places" name="places"><option value=""></option><option>Home</option><option>Work</option><option>Pub</option></select>'
54
+ equal select_tag("places", "<option>Home</option><option>Work</option><option>Pub</option>", prompt: "string"),
55
+ '<select id="places" name="places"><option value="">string</option><option>Home</option><option>Work</option><option>Pub</option></select>'
56
+ equal select_tag("places", "<option>Home</option><option>Work</option><option>Pub</option>", prompt: "<script>alert(1337)</script>"),
57
+ '<select id="places" name="places"><option value="">&lt;script&gt;alert(1337)&lt;/script&gt;</option><option>Home</option><option>Work</option><option>Pub</option></select>'
58
+ equal select_tag("places", "<option>Home</option><option>Work</option><option>Pub</option>", prompt: "string", include_blank: true),
59
+ '<select id="places" name="places"><option value="">string</option><option value=""></option><option>Home</option><option>Work</option><option>Pub</option></select>'
60
+ equal select_tag("places", null, include_blank: true),
61
+ '<select id="places" name="places"><option value=""></option></select>'
62
+ equal select_tag("places", null, prompt: "string"),
63
+ '<select id="places" name="places"><option value="">string</option></select>'
64
+
65
+ test "text_field_tag", ->
66
+ equal text_field_tag("title"),
67
+ '<input id="title" name="title" type="text" />'
68
+ equal text_field_tag("title", "Hello!", class: "admin"),
69
+ '<input class="admin" id="title" name="title" type="text" value="Hello!" />'
70
+ equal text_field_tag("title", "Hello!", size: 75),
71
+ '<input id="title" name="title" size="75" type="text" value="Hello!" />'
72
+ equal text_field_tag("title", "Hello!", disabled: true),
73
+ '<input disabled="disabled" id="title" name="title" type="text" value="Hello!" />'
74
+ equal text_field_tag("title", "Hello!", size: 70, maxlength: 80),
75
+ '<input id="title" maxlength="80" name="title" size="70" type="text" value="Hello!" />'
76
+
77
+ test "label_tag", ->
78
+ equal label_tag("title"), '<label for="title">Title</label>'
79
+ equal label_tag("title", "My Title"), '<label for="title">My Title</label>'
80
+ equal label_tag("title", "My Title", class: "small-label"), '<label class="small-label" for="title">My Title</label>'
81
+ equal label_tag( -> "Blocked" ), '<label>Blocked</label>'
82
+ equal label_tag("clock", -> "Grandfather"), '<label for="clock">Grandfather</label>'
83
+ equal label_tag("clock", id: "label_clock", -> "Grandfather"), '<label for="clock" id="label_clock">Grandfather</label>'
84
+
85
+ test "hidden_field_tag", ->
86
+ equal hidden_field_tag('id', 3), '<input id="id" name="id" type="hidden" value="3" />'
87
+
88
+ test "file_field_tag", ->
89
+ equal file_field_tag('picsplz'), '<input id="picsplz" name="picsplz" type="file" />'
90
+ equal file_field_tag('picsplz', class: 'pix'), '<input class="pix" id="picsplz" name="picsplz" type="file" />'
91
+
92
+ test "password_field_tag", ->
93
+ equal password_field_tag(), '<input id="password" name="password" type="password" />'
94
+
95
+ test "text_area_tag", ->
96
+ equal text_area_tag("body", "hello world", size: "20x40"),
97
+ '<textarea cols="20" id="body" name="body" rows="40">\nhello world</textarea>'
98
+ equal text_area_tag("body", "hello world", size: 20),
99
+ '<textarea id="body" name="body">\nhello world</textarea>'
100
+ equal text_area_tag("body", "<b>hello world</b>", size: "20x40"),
101
+ '<textarea cols="20" id="body" name="body" rows="40">\n&lt;b&gt;hello world&lt;/b&gt;</textarea>'
102
+ equal text_area_tag("body", "<b>hello world</b>", size: "20x40", escape: false),
103
+ '<textarea cols="20" id="body" name="body" rows="40">\n<b>hello world</b></textarea>'
104
+ equal text_area_tag("body", null, escape: false),
105
+ '<textarea id="body" name="body">\n</textarea>'
106
+
107
+ test "check_box_tag", ->
108
+ equal check_box_tag('admin'), '<input id="admin" name="admin" type="checkbox" value="1" />'
109
+
110
+ test "radio_button_tag", ->
111
+ equal radio_button_tag("people", "david"),
112
+ '<input id="people_david" name="people" type="radio" value="david" />'
113
+ equal radio_button_tag("num_people", 5),
114
+ '<input id="num_people_5" name="num_people" type="radio" value="5" />'
115
+ equal radio_button_tag("gender", "m") + radio_button_tag("gender", "f"),
116
+ '<input id="gender_m" name="gender" type="radio" value="m" /><input id="gender_f" name="gender" type="radio" value="f" />'
117
+ equal radio_button_tag("opinion", "-1") + radio_button_tag("opinion", "1"),
118
+ '<input id="opinion_-1" name="opinion" type="radio" value="-1" /><input id="opinion_1" name="opinion" type="radio" value="1" />'
119
+ equal radio_button_tag("person[gender]", "m"),
120
+ '<input id="person_gender_m" name="person[gender]" type="radio" value="m" />'
121
+ equal radio_button_tag('ctrlname', 'apache2.2'),
122
+ '<input id="ctrlname_apache2.2" name="ctrlname" type="radio" value="apache2.2" />'
123
+
124
+ test "submit_tag", ->
125
+ equal submit_tag("Save", onclick: "alert('hello!')", data: { disable_with: "Saving..." }),
126
+ '<input data-disable-with="Saving..." name="commit" onclick="alert(&apos;hello!&apos;)" type="submit" value="Save" />'
127
+ equal submit_tag("Save", data: { disable_with: "Saving..." }),
128
+ '<input data-disable-with="Saving..." name="commit" type="submit" value="Save" />'
129
+ equal submit_tag("Save", data: { confirm: "Are you sure?" }),
130
+ '<input data-confirm="Are you sure?" name="commit" type="submit" value="Save" />'
131
+
132
+ test "button_tag", ->
133
+ equal button_tag(),
134
+ '<button name="button" type="submit">Button</button>'
135
+ equal button_tag("Save", type: "submit"),
136
+ '<button name="button" type="submit">Save</button>'
137
+ equal button_tag("Button", type: "button"),
138
+ '<button name="button" type="button">Button</button>'
139
+ equal button_tag("Reset", type: "reset"),
140
+ '<button name="button" type="reset">Reset</button>'
141
+ equal button_tag("Reset", type: "reset", disabled: true),
142
+ '<button disabled="disabled" name="button" type="reset">Reset</button>'
143
+ equal button_tag("<b>Reset</b>", type: "reset", disabled: true),
144
+ '<button disabled="disabled" name="button" type="reset">&lt;b&gt;Reset&lt;/b&gt;</button>'
145
+ equal button_tag( -> 'Content' ),
146
+ '<button name="button" type="submit">Content</button>'
147
+ equal button_tag(name: 'temptation', type: 'button', -> content_tag('strong', 'Do not press me')),
148
+ '<button name="temptation" type="button"><strong>Do not press me</strong></button>'
149
+ equal button_tag("Save", type: "submit", data: { confirm: "Are you sure?" }),
150
+ '<button data-confirm="Are you sure?" name="button" type="submit">Save</button>'
151
+
152
+ test "image_submit_tag", ->
153
+ equal image_submit_tag("save.gif", data: { confirm: "Are you sure?" }),
154
+ '<input data-confirm="Are you sure?" src="/images/save.gif" type="image" />'
155
+
156
+ test "field_set_tag", ->
157
+ equal field_set_tag('Your details', -> 'Hello world!'),
158
+ '<fieldset><legend>Your details</legend>Hello world!</fieldset>'
159
+ equal field_set_tag(-> 'Hello world!'),
160
+ '<fieldset>Hello world!</fieldset>'
161
+ equal field_set_tag('', -> 'Hello world!'),
162
+ '<fieldset>Hello world!</fieldset>'
163
+ equal field_set_tag('', class: 'format', -> 'Hello world!'),
164
+ '<fieldset class="format">Hello world!</fieldset>'
165
+ equal field_set_tag(),
166
+ '<fieldset></fieldset>'
167
+ equal field_set_tag('You legend!'),
168
+ '<fieldset><legend>You legend!</legend></fieldset>'
169
+
170
+ test "different fields tags helpers", ->
171
+ equal color_field_tag("car"),
172
+ '<input id="car" name="car" type="color" />'
173
+ equal search_field_tag("query"),
174
+ '<input id="query" name="query" type="search" />'
175
+ equal telephone_field_tag("cell"),
176
+ '<input id="cell" name="cell" type="tel" />'
177
+ equal telephone_field_tag("cell"),
178
+ phone_field_tag("cell")
179
+ equal date_field_tag("cell"),
180
+ '<input id="cell" name="cell" type="date" />'
181
+ equal time_field_tag("cell"),
182
+ '<input id="cell" name="cell" type="time" />'
183
+ equal datetime_field_tag("appointment"),
184
+ '<input id="appointment" name="appointment" type="datetime" />'
185
+ equal datetime_local_field_tag("appointment"),
186
+ '<input id="appointment" name="appointment" type="datetime-local" />'
187
+ equal month_field_tag("birthday"),
188
+ '<input id="birthday" name="birthday" type="month" />'
189
+ equal week_field_tag("birthday"),
190
+ '<input id="birthday" name="birthday" type="week" />'
191
+ equal url_field_tag("homepage"),
192
+ '<input id="homepage" name="homepage" type="url" />'
193
+ equal email_field_tag("address"),
194
+ '<input id="address" name="address" type="email" />'
195
+ equal number_field_tag("quantity", null, in: {min: "1", max: "9"}),
196
+ '<input id="quantity" max="9" min="1" name="quantity" type="number" />'
197
+ equal range_field_tag("volume", null, in: {min: 0, max: 11}, step: 0.1),
198
+ '<input id="volume" max="11" min="0" name="volume" step="0.1" type="range" />'
199
+
200
+ test "boolean options", ->
201
+ equal check_box_tag("admin", 1, true, disabled: true, readonly: "yes"),
202
+ '<input checked="checked" disabled="disabled" id="admin" name="admin" readonly="readonly" type="checkbox" value="1" />'
203
+ equal check_box_tag("admin", 1, true, disabled: false, readonly: null),
204
+ '<input checked="checked" id="admin" name="admin" type="checkbox" value="1" />'
205
+ equal tag('input', type: "checkbox", checked: false),
206
+ '<input type="checkbox" />'
207
+ equal select_tag("people", "<option>david</option>", multiple: true),
208
+ '<select id="people" multiple="multiple" name="people[]"><option>david</option></select>'
209
+ equal select_tag("people[]", "<option>david</option>", multiple: true),
210
+ '<select id="people_" multiple="multiple" name="people[]"><option>david</option></select>'
211
+ equal select_tag("people", "<option>david</option>", multiple: null),
212
+ '<select id="people" name="people"><option>david</option></select>'
213
+
214
+ test "options side effects", ->
215
+ options = { option: "random_option" }
216
+ text_area_tag "body", "hello world", options
217
+ deepEqual options, { option: "random_option" }
218
+ submit_tag "submit value", options
219
+ deepEqual options, { option: "random_option" }
220
+ button_tag "button value", options
221
+ deepEqual options, { option: "random_option" }
222
+ image_submit_tag "submit source", options
223
+ deepEqual options, { option: "random_option" }
224
+ label_tag "submit source", "title", options
225
+ deepEqual options, { option: "random_option" }