sexy_form 0.9.0

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 (52) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +5 -0
  3. data/LICENSE +21 -0
  4. data/README.md +275 -0
  5. data/Rakefile +15 -0
  6. data/lib/sexy_form.rb +84 -0
  7. data/lib/sexy_form/builder.rb +306 -0
  8. data/lib/sexy_form/themes.rb +22 -0
  9. data/lib/sexy_form/themes/base_theme.rb +39 -0
  10. data/lib/sexy_form/themes/bootstrap_2_horizontal.rb +83 -0
  11. data/lib/sexy_form/themes/bootstrap_2_inline.rb +73 -0
  12. data/lib/sexy_form/themes/bootstrap_2_vertical.rb +80 -0
  13. data/lib/sexy_form/themes/bootstrap_3_horizontal.rb +95 -0
  14. data/lib/sexy_form/themes/bootstrap_3_inline.rb +71 -0
  15. data/lib/sexy_form/themes/bootstrap_3_vertical.rb +70 -0
  16. data/lib/sexy_form/themes/bootstrap_4_horizontal.rb +95 -0
  17. data/lib/sexy_form/themes/bootstrap_4_inline.rb +80 -0
  18. data/lib/sexy_form/themes/bootstrap_4_vertical.rb +79 -0
  19. data/lib/sexy_form/themes/bulma_horizontal.rb +81 -0
  20. data/lib/sexy_form/themes/bulma_vertical.rb +73 -0
  21. data/lib/sexy_form/themes/default.rb +55 -0
  22. data/lib/sexy_form/themes/foundation.rb +67 -0
  23. data/lib/sexy_form/themes/materialize.rb +65 -0
  24. data/lib/sexy_form/themes/milligram.rb +62 -0
  25. data/lib/sexy_form/themes/semantic_ui_inline.rb +63 -0
  26. data/lib/sexy_form/themes/semantic_ui_vertical.rb +63 -0
  27. data/lib/sexy_form/version.rb +3 -0
  28. data/spec/custom_assertions.rb +21 -0
  29. data/spec/sexy_form/builder_spec.rb +104 -0
  30. data/spec/sexy_form/themes/base_theme_spec.rb +16 -0
  31. data/spec/sexy_form/themes/bootstrap_2_horizontal_spec.rb +114 -0
  32. data/spec/sexy_form/themes/bootstrap_2_inline_spec.rb +108 -0
  33. data/spec/sexy_form/themes/bootstrap_2_vertical_spec.rb +111 -0
  34. data/spec/sexy_form/themes/bootstrap_3_horizontal_spec.rb +116 -0
  35. data/spec/sexy_form/themes/bootstrap_3_inline_spec.rb +104 -0
  36. data/spec/sexy_form/themes/bootstrap_3_vertical_spec.rb +122 -0
  37. data/spec/sexy_form/themes/bootstrap_4_horizontal_spec.rb +124 -0
  38. data/spec/sexy_form/themes/bootstrap_4_inline_spec.rb +116 -0
  39. data/spec/sexy_form/themes/bootstrap_4_vertical_spec.rb +114 -0
  40. data/spec/sexy_form/themes/bulma_horizontal_spec.rb +126 -0
  41. data/spec/sexy_form/themes/bulma_vertical_spec.rb +114 -0
  42. data/spec/sexy_form/themes/default_spec.rb +102 -0
  43. data/spec/sexy_form/themes/foundation_spec.rb +103 -0
  44. data/spec/sexy_form/themes/materialize_spec.rb +103 -0
  45. data/spec/sexy_form/themes/milligram_spec.rb +120 -0
  46. data/spec/sexy_form/themes/semantic_ui_inline_spec.rb +105 -0
  47. data/spec/sexy_form/themes/semantic_ui_vertical_spec.rb +105 -0
  48. data/spec/sexy_form/themes/theme_spec_helper.rb +0 -0
  49. data/spec/sexy_form/themes_spec.rb +52 -0
  50. data/spec/sexy_form_spec.rb +54 -0
  51. data/spec/spec_helper.rb +16 -0
  52. metadata +160 -0
@@ -0,0 +1,103 @@
1
+ require_relative "../../spec_helper"
2
+ require_relative "./theme_spec_helper"
3
+
4
+ theme_klass = SexyForm::Themes::Foundation
5
+ theme = theme_klass.new
6
+
7
+ describe theme_klass do
8
+
9
+ describe ".theme_name" do
10
+ it "is correct" do
11
+ theme_klass.theme_name.should eq("foundation")
12
+ end
13
+ end
14
+
15
+ describe ".wrap_field" do
16
+ it "works" do
17
+
18
+ end
19
+ end
20
+
21
+ describe "SexyForm.form" do
22
+ it "matches docs example with labels" do
23
+ expected = build_string do |str|
24
+ str << %Q(<form method="post">)
25
+ str << %Q(<div>)
26
+ str << %Q(<label for="email">Email)
27
+ str << %Q(<input type="text" name="email" id="email">)
28
+ str << "</label>"
29
+ str << "</div>"
30
+
31
+ str << %Q(<div>)
32
+ str << %Q(<label for="password">Password)
33
+ str << %Q(<input type="password" name="password" id="password">)
34
+ str << "</label>"
35
+ str << "</div>"
36
+
37
+ str << %Q(<div>)
38
+ str << %Q(<input type="checkbox" name="remember_me" id="remember_me">)
39
+ str << %Q(<label for="remember_me">Remember Me</label>)
40
+ str << "</div>"
41
+
42
+ str << %Q(<button type="submit">Sign in</button>)
43
+ str << "</form>"
44
+ end
45
+
46
+ actual = SexyForm.form(theme: theme_klass.theme_name) do |f|
47
+ f << f.field(type: :text, name: :email)
48
+ f << f.field(type: :password, name: :password)
49
+ f << f.field(type: :checkbox, name: :remember_me)
50
+ f << %Q(<button type="submit">Sign in</button>)
51
+ end
52
+
53
+ actual.should eq(expected)
54
+ end
55
+ end
56
+
57
+ describe ".form_html_attributes" do
58
+ it "returns correct attributes" do
59
+ attrs = {}
60
+
61
+ theme.form_html_attributes(html_attrs: {}).should eq(attrs)
62
+ end
63
+ end
64
+
65
+ SexyForm::Builder::FIELD_TYPES.each do |field_type|
66
+ describe ".input_html_attributes" do
67
+ it "returns correct #{field_type} attributes" do
68
+ attrs = {}
69
+
70
+ theme.input_html_attributes(html_attrs: {}, field_type: field_type, has_errors: false).should eq(attrs)
71
+ end
72
+ end
73
+
74
+ describe ".label_html_attributes" do
75
+ it "returns correct #{field_type} attributes" do
76
+ attrs = {}
77
+
78
+ theme.label_html_attributes(html_attrs: {}, field_type: field_type, has_errors: false).should eq(attrs)
79
+ end
80
+ end
81
+
82
+ describe ".build_html_help_text" do
83
+ it "returns correct #{field_type} attributes" do
84
+ expected = "<p class=\"help-text\">foobar</p>"
85
+
86
+ attrs = {}
87
+
88
+ theme.build_html_help_text(html_attrs: attrs, field_type: field_type, help_text: "foobar").should eq(expected)
89
+ end
90
+ end
91
+
92
+ describe ".build_html_error" do
93
+ it "returns correct #{field_type} attributes" do
94
+ expected = "<span class=\"form-error\">foobar</span>"
95
+
96
+ attrs = {}
97
+
98
+ theme.build_html_error(html_attrs: attrs, field_type: field_type, error: "foobar").should eq(expected)
99
+ end
100
+ end
101
+ end
102
+
103
+ end
@@ -0,0 +1,103 @@
1
+ require_relative "../../spec_helper"
2
+ require_relative "./theme_spec_helper"
3
+
4
+ theme_klass = SexyForm::Themes::Materialize
5
+ theme = theme_klass.new
6
+
7
+ describe theme_klass do
8
+
9
+ describe ".theme_name" do
10
+ it "is correct" do
11
+ theme_klass.theme_name.should eq("materialize")
12
+ end
13
+ end
14
+
15
+ describe ".wrap_field" do
16
+ it "works" do
17
+
18
+ end
19
+ end
20
+
21
+ describe "SexyForm.form" do
22
+ it "matches docs example with labels" do
23
+ expected = build_string do |str|
24
+ str << %Q(<form method="post">)
25
+ str << %Q(<div class="input-field">)
26
+ str << %Q(<input type="text" name="email" id="email">)
27
+ str << %Q(<label for="email">Email</label>)
28
+ str << "</div>"
29
+
30
+ str << %Q(<div class="input-field">)
31
+ str << %Q(<input type="password" name="password" id="password">)
32
+ str << %Q(<label for="password">Password</label>)
33
+ str << "</div>"
34
+
35
+ str << %Q(<div class="input-field">)
36
+ str << %Q(<label for="remember_me">)
37
+ str << %Q(<input type="checkbox" name="remember_me" id="remember_me">)
38
+ str << "<span>Remember Me</span>"
39
+ str << %Q(</label>)
40
+ str << "</div>"
41
+
42
+ str << %Q(<button type="submit">Sign in</button>)
43
+ str << "</form>"
44
+ end
45
+
46
+ actual = SexyForm.form(theme: theme_klass.theme_name) do |f|
47
+ f << f.field(type: :text, name: :email)
48
+ f << f.field(type: :password, name: :password)
49
+ f << f.field(type: :checkbox, name: :remember_me)
50
+ f << %Q(<button type="submit">Sign in</button>)
51
+ end
52
+
53
+ actual.should eq(expected)
54
+ end
55
+ end
56
+
57
+ describe ".form_html_attributes" do
58
+ it "returns correct attributes" do
59
+ attrs = {}
60
+
61
+ theme.form_html_attributes(html_attrs: {}).should eq(attrs)
62
+ end
63
+ end
64
+
65
+ SexyForm::Builder::FIELD_TYPES.each do |field_type|
66
+ describe ".input_html_attributes" do
67
+ it "returns correct #{field_type} attributes" do
68
+ attrs = {}
69
+
70
+ theme.input_html_attributes(html_attrs: {}, field_type: field_type, has_errors: false).should eq(attrs)
71
+ end
72
+ end
73
+
74
+ describe ".label_html_attributes" do
75
+ it "returns correct #{field_type} attributes" do
76
+ attrs = {}
77
+
78
+ theme.label_html_attributes(html_attrs: {}, field_type: field_type, has_errors: false).should eq(attrs)
79
+ end
80
+ end
81
+
82
+ describe ".build_html_help_text" do
83
+ it "returns correct #{field_type} attributes" do
84
+ expected = "<span class=\"helper-text\">foobar</span>"
85
+
86
+ attrs = {}
87
+
88
+ theme.build_html_help_text(html_attrs: attrs, field_type: field_type, help_text: "foobar").should eq(expected)
89
+ end
90
+ end
91
+
92
+ describe ".build_html_error" do
93
+ it "returns correct #{field_type} attributes" do
94
+ expected = "<span class=\"helper-text\">foobar</span>"
95
+
96
+ attrs = {}
97
+
98
+ theme.build_html_error(html_attrs: attrs, field_type: field_type, error: "foobar").should eq(expected)
99
+ end
100
+ end
101
+ end
102
+
103
+ end
@@ -0,0 +1,120 @@
1
+ require_relative "../../spec_helper"
2
+ require_relative "./theme_spec_helper"
3
+
4
+ theme_klass = SexyForm::Themes::Milligram
5
+ theme = theme_klass.new
6
+
7
+ describe theme_klass do
8
+
9
+ describe ".theme_name" do
10
+ it "is correct" do
11
+ theme_klass.theme_name.should eq("milligram")
12
+ end
13
+ end
14
+
15
+ describe ".wrap_field" do
16
+ it "works" do
17
+
18
+ end
19
+ end
20
+
21
+ describe "SexyForm.form" do
22
+ it "matches docs example with labels" do
23
+ expected = build_string do |str|
24
+ str << %Q(<form method="post">)
25
+ str << "<div>"
26
+ str << %Q(<label for="nameField">Name</label>)
27
+ str << %Q(<input type="text" placeholder="Name" name="nameField" id="nameField">)
28
+ str << "</div>"
29
+
30
+ str << "<div>"
31
+ str << %Q(<label for="ageRangeField">Age Range</label>)
32
+ str << %Q(<select name="ageRangeField" id="ageRangeField">)
33
+ str << %Q(<option value="0-13">0-13</option>)
34
+ str << %Q(<option value="14-17">14-17</option>)
35
+ str << %Q(<option value="18-23">18-23</option>)
36
+ str << %Q(<option value="24+">24+</option>)
37
+ str << %Q(</select>)
38
+ str << "</div>"
39
+
40
+ str << "<div>"
41
+ str << %Q(<label for="commentField">Comment</label>)
42
+ str << %Q(<textarea placeholder="Hello World" name="commentField" id="commentField"></textarea>)
43
+ str << "</div>"
44
+
45
+ str << %Q(<div class="float-right">)
46
+ str << "<div>"
47
+ str << %Q(<input type="checkbox" name="confirmField" id="confirmField">)
48
+ str << %Q(<label class="label-inline" for="confirmField">Confirm?</label>)
49
+ str << %Q(</div>)
50
+ str << "</div>"
51
+
52
+ str << %Q(<input type="submit" class="button-primary" value="Send">)
53
+ str << "</form>"
54
+ end
55
+
56
+ actual = SexyForm.form(theme: theme_klass.theme_name) do |f|
57
+ f << f.field(type: :text, name: :nameField, label: "Name", input_html: {placeholder: "Name"})
58
+ f << f.field(type: :select, name: :ageRangeField, label: "Age Range", collection: {options: ["0-13","14-17","18-23","24+"]})
59
+ f << f.field(type: :textarea, name: :commentField, label: "Comment", input_html: {placeholder: "Hello World"})
60
+ f << %Q(<div class="float-right">)
61
+ f << f.field(type: :checkbox, name: :confirmField, label: "Confirm?")
62
+ f << "</div>"
63
+ f << %Q(<input type="submit" class="button-primary" value="Send">)
64
+ end
65
+
66
+ actual.should eq(expected)
67
+ end
68
+ end
69
+
70
+ describe ".form_html_attributes" do
71
+ it "returns correct attributes" do
72
+ attrs = {}
73
+
74
+ theme.form_html_attributes(html_attrs: {}).should eq(attrs)
75
+ end
76
+ end
77
+
78
+ SexyForm::Builder::FIELD_TYPES.each do |field_type|
79
+ describe ".input_html_attributes" do
80
+ it "returns correct #{field_type} attributes" do
81
+ attrs = {}
82
+
83
+ theme.input_html_attributes(html_attrs: {}, field_type: field_type, has_errors: false).should eq(attrs)
84
+ end
85
+ end
86
+
87
+ describe ".label_html_attributes" do
88
+ it "returns correct #{field_type} attributes" do
89
+ attrs = {}
90
+
91
+ if ["checkbox", "radio"].include?(field_type)
92
+ attrs["class"] = "label-inline"
93
+ end
94
+
95
+ theme.label_html_attributes(html_attrs: {}, field_type: field_type, has_errors: false).should eq(attrs)
96
+ end
97
+ end
98
+
99
+ describe ".build_html_help_text" do
100
+ it "returns correct #{field_type} attributes" do
101
+ expected = "<small>foobar</small>"
102
+
103
+ attrs = {}
104
+
105
+ theme.build_html_help_text(html_attrs: attrs, field_type: field_type, help_text: "foobar").should eq(expected)
106
+ end
107
+ end
108
+
109
+ describe ".build_html_error" do
110
+ it "returns correct #{field_type} attributes" do
111
+ expected = "<small style=\"color: red;\">foobar</small>"
112
+
113
+ attrs = {}
114
+
115
+ theme.build_html_error(html_attrs: attrs, field_type: field_type, error: "foobar").should eq(expected)
116
+ end
117
+ end
118
+ end
119
+
120
+ end
@@ -0,0 +1,105 @@
1
+ require_relative "../../spec_helper"
2
+ require_relative "./theme_spec_helper"
3
+
4
+ theme_klass = SexyForm::Themes::SemanticUIInline
5
+ theme = theme_klass.new
6
+
7
+ describe theme_klass do
8
+
9
+ describe ".theme_name" do
10
+ it "is correct" do
11
+ theme_klass.theme_name.should eq("semantic_ui_inline")
12
+ end
13
+ end
14
+
15
+ describe ".wrap_field" do
16
+ it "works" do
17
+
18
+ end
19
+ end
20
+
21
+ describe "SexyForm.form" do
22
+ it "matches docs example with labels" do
23
+ expected = build_string do |str|
24
+ str << %Q(<form class="ui form" method="post">)
25
+ str << %Q(<div class="inline field">)
26
+ str << %Q(<label for="email">Email</label>)
27
+ str << %Q(<input type="text" name="email" id="email">)
28
+ str << "</div>"
29
+
30
+ str << %Q(<div class="inline field">)
31
+ str << %Q(<label for="password">Password</label>)
32
+ str << %Q(<input type="password" name="password" id="password">)
33
+ str << "</div>"
34
+
35
+ str << %Q(<div class="inline field">)
36
+ str << %Q(<div class="ui checkbox">)
37
+ str << %Q(<input type="checkbox" name="remember_me" id="remember_me">)
38
+ str << %Q(<label for="remember_me">Remember Me</label>)
39
+ str << "</div>"
40
+ str << "</div>"
41
+
42
+ str << %Q(<button type="submit">Sign in</button>)
43
+ str << "</form>"
44
+ end
45
+
46
+ actual = SexyForm.form(theme: theme_klass.theme_name) do |f|
47
+ f << f.field(type: :text, name: :email)
48
+ f << f.field(type: :password, name: :password)
49
+ f << f.field(type: :checkbox, name: :remember_me)
50
+ f << %Q(<button type="submit">Sign in</button>)
51
+ end
52
+
53
+ actual.should eq(expected)
54
+ end
55
+ end
56
+
57
+ describe ".form_html_attributes" do
58
+ it "returns correct attributes" do
59
+ attrs = {}
60
+
61
+ attrs["class"] = "ui form"
62
+
63
+ theme.form_html_attributes(html_attrs: {}).should eq(attrs)
64
+ end
65
+ end
66
+
67
+ SexyForm::Builder::FIELD_TYPES.each do |field_type|
68
+ describe ".input_html_attributes" do
69
+ it "returns correct #{field_type} attributes" do
70
+ attrs = {}
71
+
72
+ theme.input_html_attributes(html_attrs: {}, field_type: field_type, has_errors: false).should eq(attrs)
73
+ end
74
+ end
75
+
76
+ describe ".label_html_attributes" do
77
+ it "returns correct #{field_type} attributes" do
78
+ attrs = {}
79
+
80
+ theme.label_html_attributes(html_attrs: {}, field_type: field_type, has_errors: false).should eq(attrs)
81
+ end
82
+ end
83
+
84
+ describe ".build_html_help_text" do
85
+ it "returns correct #{field_type} attributes" do
86
+ expected = "<div>foobar</div>"
87
+
88
+ attrs = {}
89
+
90
+ theme.build_html_help_text(html_attrs: attrs, field_type: field_type, help_text: "foobar").should eq(expected)
91
+ end
92
+ end
93
+
94
+ describe ".build_html_error" do
95
+ it "returns correct #{field_type} attributes" do
96
+ expected = "<div style=\"color: red;\">foobar</div>"
97
+
98
+ attrs = {}
99
+
100
+ theme.build_html_error(html_attrs: attrs, field_type: field_type, error: "foobar").should eq(expected)
101
+ end
102
+ end
103
+ end
104
+
105
+ end
@@ -0,0 +1,105 @@
1
+ require_relative "../../spec_helper"
2
+ require_relative "./theme_spec_helper"
3
+
4
+ theme_klass = SexyForm::Themes::SemanticUIVertical
5
+ theme = theme_klass.new
6
+
7
+ describe theme_klass do
8
+
9
+ describe ".theme_name" do
10
+ it "is correct" do
11
+ theme_klass.theme_name.should eq("semantic_ui_vertical")
12
+ end
13
+ end
14
+
15
+ describe ".wrap_field" do
16
+ it "works" do
17
+
18
+ end
19
+ end
20
+
21
+ describe "SexyForm.form" do
22
+ it "matches docs example with labels" do
23
+ expected = build_string do |str|
24
+ str << %Q(<form class="ui form" method="post">)
25
+ str << %Q(<div class="field">)
26
+ str << %Q(<label for="email">Email</label>)
27
+ str << %Q(<input type="text" name="email" id="email">)
28
+ str << "</div>"
29
+
30
+ str << %Q(<div class="field">)
31
+ str << %Q(<label for="password">Password</label>)
32
+ str << %Q(<input type="password" name="password" id="password">)
33
+ str << "</div>"
34
+
35
+ str << %Q(<div class="field">)
36
+ str << %Q(<div class="ui checkbox">)
37
+ str << %Q(<input type="checkbox" name="remember_me" id="remember_me">)
38
+ str << %Q(<label for="remember_me">Remember Me</label>)
39
+ str << "</div>"
40
+ str << "</div>"
41
+
42
+ str << %Q(<button type="submit">Sign in</button>)
43
+ str << "</form>"
44
+ end
45
+
46
+ actual = SexyForm.form(theme: theme_klass.theme_name) do |f|
47
+ f << f.field(type: :text, name: :email)
48
+ f << f.field(type: :password, name: :password)
49
+ f << f.field(type: :checkbox, name: :remember_me)
50
+ f << %Q(<button type="submit">Sign in</button>)
51
+ end
52
+
53
+ actual.should eq(expected)
54
+ end
55
+ end
56
+
57
+ describe ".form_html_attributes" do
58
+ it "returns correct attributes" do
59
+ attrs = {}
60
+
61
+ attrs["class"] = "ui form"
62
+
63
+ theme.form_html_attributes(html_attrs: {}).should eq(attrs)
64
+ end
65
+ end
66
+
67
+ SexyForm::Builder::FIELD_TYPES.each do |field_type|
68
+ describe ".input_html_attributes" do
69
+ it "returns correct #{field_type} attributes" do
70
+ attrs = {}
71
+
72
+ theme.input_html_attributes(html_attrs: {}, field_type: field_type, has_errors: false).should eq(attrs)
73
+ end
74
+ end
75
+
76
+ describe ".label_html_attributes" do
77
+ it "returns correct #{field_type} attributes" do
78
+ attrs = {}
79
+
80
+ theme.label_html_attributes(html_attrs: {}, field_type: field_type, has_errors: false).should eq(attrs)
81
+ end
82
+ end
83
+
84
+ describe ".build_html_help_text" do
85
+ it "returns correct #{field_type} attributes" do
86
+ expected = "<div>foobar</div>"
87
+
88
+ attrs = {}
89
+
90
+ theme.build_html_help_text(html_attrs: attrs, field_type: field_type, help_text: "foobar").should eq(expected)
91
+ end
92
+ end
93
+
94
+ describe ".build_html_error" do
95
+ it "returns correct #{field_type} attributes" do
96
+ expected = "<div style=\"color: red;\">foobar</div>"
97
+
98
+ attrs = {}
99
+
100
+ theme.build_html_error(html_attrs: attrs, field_type: field_type, error: "foobar").should eq(expected)
101
+ end
102
+ end
103
+ end
104
+
105
+ end