sexy_form 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
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,114 @@
1
+ require_relative "../../spec_helper"
2
+ require_relative "./theme_spec_helper"
3
+
4
+ theme_klass = SexyForm::Themes::Bootstrap4Vertical
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("bootstrap_4_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" do
23
+ expected = build_string do |str|
24
+ str << %Q(<form method="post">)
25
+ str << %Q(<div class="form-group">)
26
+ str << %Q(<label for="email">Email</label>)
27
+ str << %Q(<input type="text" class="form-control" name="email" id="email">)
28
+ str << "</div>"
29
+
30
+ str << %Q(<div class="form-group">)
31
+ str << %Q(<label for="password">Password</label>)
32
+ str << %Q(<input type="password" class="form-control" name="password" id="password">)
33
+ str << "</div>"
34
+
35
+ str << %Q(<div class="form-group form-check">)
36
+ str << %Q(<input type="checkbox" class="form-check-input" name="remember_me" id="remember_me">)
37
+ str << %Q(<label class="form-check-label" for="remember_me">Remember Me</label>)
38
+ str << "</div>"
39
+
40
+ str << %Q(<button type="submit" class="btn btn-primary">Sign in</button>)
41
+ str << "</form>"
42
+ end
43
+
44
+ actual = SexyForm.form(theme: theme_klass.theme_name) do |f|
45
+ f << f.field(type: :text, name: :email)
46
+ f << f.field(type: :password, name: :password)
47
+ f << f.field(type: :checkbox, name: :remember_me)
48
+ f << %Q(<button type="submit" class="btn btn-primary">Sign in</button>)
49
+ end
50
+
51
+ actual.should eq(expected)
52
+ end
53
+ end
54
+
55
+ describe ".form_html_attributes" do
56
+ it "returns correct attributes" do
57
+ attrs = {}
58
+
59
+ theme.form_html_attributes(html_attrs: {}).should eq(attrs)
60
+ end
61
+ end
62
+
63
+ SexyForm::Builder::FIELD_TYPES.each do |field_type|
64
+ describe ".input_html_attributes" do
65
+ it "returns correct #{field_type} attributes" do
66
+ attrs = {}
67
+
68
+ case field_type
69
+ when "checkbox", "radio"
70
+ attrs["class"] = "form-check-input"
71
+ when "file"
72
+ attrs["class"] = "form-control-file"
73
+ else
74
+ attrs["class"] = "form-control"
75
+ end
76
+
77
+ theme.input_html_attributes(html_attrs: {}, field_type: field_type, has_errors: false).should eq(attrs)
78
+ end
79
+ end
80
+
81
+ describe ".label_html_attributes" do
82
+ it "returns correct #{field_type} attributes" do
83
+ attrs = {}
84
+
85
+ if ["checkbox", "radio"].include?(field_type)
86
+ attrs["class"] = "form-check-label"
87
+ end
88
+
89
+ theme.label_html_attributes(html_attrs: {}, field_type: field_type, has_errors: false).should eq(attrs)
90
+ end
91
+ end
92
+
93
+ describe ".build_html_help_text" do
94
+ it "returns correct #{field_type} attributes" do
95
+ expected = "<small class=\"form-text\">foobar</small>"
96
+
97
+ attrs = {}
98
+
99
+ theme.build_html_help_text(html_attrs: attrs, field_type: field_type, help_text: "foobar").should eq(expected)
100
+ end
101
+ end
102
+
103
+ describe ".build_html_error" do
104
+ it "returns correct #{field_type} attributes" do
105
+ expected = "<div class=\"invalid-feedback\">foobar</div>"
106
+
107
+ attrs = {}
108
+
109
+ theme.build_html_error(html_attrs: attrs, field_type: field_type, error: "foobar").should eq(expected)
110
+ end
111
+ end
112
+ end
113
+
114
+ end
@@ -0,0 +1,126 @@
1
+ require_relative "../../spec_helper"
2
+ require_relative "./theme_spec_helper"
3
+
4
+ theme_klass = SexyForm::Themes::BulmaHorizontal
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("bulma_horizontal")
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="field is-horizontal">)
26
+ str << %Q(<label class="label is-normal" for="email">Email</label>)
27
+ str << %Q(<div class="field-body">)
28
+ str << %Q(<div class="field">)
29
+ str << %Q(<div class="control">)
30
+ str << %Q(<input type="text" name="email" id="email">)
31
+ str << "</div>"
32
+ str << "</div>"
33
+ str << "</div>"
34
+ str << "</div>"
35
+
36
+ str << %Q(<div class="field is-horizontal">)
37
+ str << %Q(<label class="label is-normal" for="password">Password</label>)
38
+ str << %Q(<div class="field-body">)
39
+ str << %Q(<div class="field">)
40
+ str << %Q(<div class="control">)
41
+ str << %Q(<input type="password" name="password" id="password">)
42
+ str << "</div>"
43
+ str << "</div>"
44
+ str << "</div>"
45
+ str << "</div>"
46
+
47
+ str << %Q(<div class="field is-horizontal">)
48
+ str << %Q(<div class="field-body">)
49
+ str << %Q(<div class="field">)
50
+ str << %Q(<div class="control">)
51
+ str << %Q(<label class="checkbox" for="remember_me">)
52
+ str << %Q(<input type="checkbox" name="remember_me" id="remember_me"> Remember Me)
53
+ str << %Q(</label>)
54
+ str << "</div>"
55
+ str << "</div>"
56
+ str << "</div>"
57
+ str << "</div>"
58
+
59
+ str << %Q(<button type="submit" class="button">Sign in</button>)
60
+ str << "</form>"
61
+ end
62
+
63
+ actual = SexyForm.form(theme: theme_klass.theme_name) do |f|
64
+ f << f.field(type: :text, name: :email)
65
+ f << f.field(type: :password, name: :password)
66
+ f << f.field(type: :checkbox, name: :remember_me)
67
+ f << %Q(<button type="submit" class="button">Sign in</button>)
68
+ end
69
+
70
+ actual.should eq(expected)
71
+ end
72
+ end
73
+
74
+ describe ".form_html_attributes" do
75
+ it "returns correct attributes" do
76
+ attrs = {}
77
+
78
+ theme.form_html_attributes(html_attrs: {}).should eq(attrs)
79
+ end
80
+ end
81
+
82
+ SexyForm::Builder::FIELD_TYPES.each do |field_type|
83
+ describe ".input_html_attributes" do
84
+ it "returns correct #{field_type} attributes" do
85
+ attrs = {}
86
+
87
+ theme.input_html_attributes(html_attrs: {}, field_type: field_type, has_errors: false).should eq(attrs)
88
+ end
89
+ end
90
+
91
+ describe ".label_html_attributes" do
92
+ it "returns correct #{field_type} attributes" do
93
+ attrs = {}
94
+
95
+ if ["checkbox", "radio"].include?(field_type)
96
+ attrs["class"] = field_type
97
+ else
98
+ attrs["class"] = "label is-normal"
99
+ end
100
+
101
+ theme.label_html_attributes(html_attrs: {}, field_type: field_type, has_errors: false).should eq(attrs)
102
+ end
103
+ end
104
+
105
+ describe ".build_html_help_text" do
106
+ it "returns correct #{field_type} attributes" do
107
+ expected = "<p class=\"help\">foobar</p>"
108
+
109
+ attrs = {}
110
+
111
+ theme.build_html_help_text(html_attrs: attrs, field_type: field_type, help_text: "foobar").should eq(expected)
112
+ end
113
+ end
114
+
115
+ describe ".build_html_error" do
116
+ it "returns correct #{field_type} attributes" do
117
+ expected = "<p class=\"help is-danger\">foobar</p>"
118
+
119
+ attrs = {}
120
+
121
+ theme.build_html_error(html_attrs: attrs, field_type: field_type, error: "foobar").should eq(expected)
122
+ end
123
+ end
124
+ end
125
+
126
+ end
@@ -0,0 +1,114 @@
1
+ require_relative "../../spec_helper"
2
+ require_relative "./theme_spec_helper"
3
+
4
+ theme_klass = SexyForm::Themes::BulmaVertical
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("bulma_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 method="post">)
25
+ str << %Q(<div class="field">)
26
+ str << %Q(<label class="label" for="email">Email</label>)
27
+ str << %Q(<div class="control">)
28
+ str << %Q(<input type="text" name="email" id="email">)
29
+ str << "</div>"
30
+ str << "</div>"
31
+
32
+ str << %Q(<div class="field">)
33
+ str << %Q(<label class="label" for="password">Password</label>)
34
+ str << %Q(<div class="control">)
35
+ str << %Q(<input type="password" name="password" id="password">)
36
+ str << "</div>"
37
+ str << "</div>"
38
+
39
+ str << %Q(<div class="field">)
40
+ str << %Q(<div class="control">)
41
+ str << %Q(<label class="checkbox" for="remember_me">)
42
+ str << %Q(<input type="checkbox" name="remember_me" id="remember_me"> Remember Me)
43
+ str << %Q(</label>)
44
+ str << "</div>"
45
+ str << "</div>"
46
+
47
+ str << %Q(<button type="submit" class="button">Sign in</button>)
48
+ str << "</form>"
49
+ end
50
+
51
+ actual = SexyForm.form(theme: theme_klass.theme_name) do |f|
52
+ f << f.field(type: :text, name: :email)
53
+ f << f.field(type: :password, name: :password)
54
+ f << f.field(type: :checkbox, name: :remember_me)
55
+ f << %Q(<button type="submit" class="button">Sign in</button>)
56
+ end
57
+
58
+ actual.should eq(expected)
59
+ end
60
+ end
61
+
62
+ describe ".form_html_attributes" do
63
+ it "returns correct attributes" do
64
+ attrs = {}
65
+
66
+ theme.form_html_attributes(html_attrs: {}).should eq(attrs)
67
+ end
68
+ end
69
+
70
+ SexyForm::Builder::FIELD_TYPES.each do |field_type|
71
+ describe ".input_html_attributes" do
72
+ it "returns correct #{field_type} attributes" do
73
+ attrs = {}
74
+
75
+ theme.input_html_attributes(html_attrs: {}, field_type: field_type, has_errors: false).should eq(attrs)
76
+ end
77
+ end
78
+
79
+ describe ".label_html_attributes" do
80
+ it "returns correct #{field_type} attributes" do
81
+ attrs = {}
82
+
83
+ if ["checkbox", "radio"].include?(field_type)
84
+ attrs["class"] = field_type
85
+ else
86
+ attrs["class"] = "label"
87
+ end
88
+
89
+ theme.label_html_attributes(html_attrs: {}, field_type: field_type, has_errors: false).should eq(attrs)
90
+ end
91
+ end
92
+
93
+ describe ".build_html_help_text" do
94
+ it "returns correct #{field_type} attributes" do
95
+ expected = "<p class=\"help\">foobar</p>"
96
+
97
+ attrs = {}
98
+
99
+ theme.build_html_help_text(html_attrs: attrs, field_type: field_type, help_text: "foobar").should eq(expected)
100
+ end
101
+ end
102
+
103
+ describe ".build_html_error" do
104
+ it "returns correct #{field_type} attributes" do
105
+ expected = "<p class=\"help is-danger\">foobar</p>"
106
+
107
+ attrs = {}
108
+
109
+ theme.build_html_error(html_attrs: attrs, field_type: field_type, error: "foobar").should eq(expected)
110
+ end
111
+ end
112
+ end
113
+
114
+ end
@@ -0,0 +1,102 @@
1
+ require_relative "../../spec_helper"
2
+ require_relative "./theme_spec_helper"
3
+
4
+ theme_klass = SexyForm::Themes::Default
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("default")
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</label>)
27
+ str << %Q(<input type="text" name="email" id="email">)
28
+ str << "</div>"
29
+
30
+ str << %Q(<div>)
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>)
36
+ str << %Q(<label for="remember_me">)
37
+ str << %Q(<input type="checkbox" name="remember_me" id="remember_me"> Remember Me)
38
+ str << %Q(</label>)
39
+ str << "</div>"
40
+
41
+ str << %Q(<button type="submit">Sign in</button>)
42
+ str << "</form>"
43
+ end
44
+
45
+ actual = SexyForm.form(theme: theme_klass.theme_name) do |f|
46
+ f << f.field(type: :text, name: :email)
47
+ f << f.field(type: :password, name: :password)
48
+ f << f.field(type: :checkbox, name: :remember_me)
49
+ f << %Q(<button type="submit">Sign in</button>)
50
+ end
51
+
52
+ actual.should eq(expected)
53
+ end
54
+ end
55
+
56
+ describe ".form_html_attributes" do
57
+ it "returns correct attributes" do
58
+ attrs = {}
59
+
60
+ theme.form_html_attributes(html_attrs: {}).should eq(attrs)
61
+ end
62
+ end
63
+
64
+ SexyForm::Builder::FIELD_TYPES.each do |field_type|
65
+ describe ".input_html_attributes" do
66
+ it "returns correct #{field_type} attributes" do
67
+ attrs = {}
68
+
69
+ theme.input_html_attributes(html_attrs: {}, field_type: field_type, has_errors: false).should eq(attrs)
70
+ end
71
+ end
72
+
73
+ describe ".label_html_attributes" do
74
+ it "returns correct #{field_type} attributes" do
75
+ attrs = {}
76
+
77
+ theme.label_html_attributes(html_attrs: {}, field_type: field_type, has_errors: false).should eq(attrs)
78
+ end
79
+ end
80
+
81
+ describe ".build_html_help_text" do
82
+ it "returns correct #{field_type} attributes" do
83
+ expected = "<div>foobar</div>"
84
+
85
+ attrs = {}
86
+
87
+ theme.build_html_help_text(html_attrs: attrs, field_type: field_type, help_text: "foobar").should eq(expected)
88
+ end
89
+ end
90
+
91
+ describe ".build_html_error" do
92
+ it "returns correct #{field_type} attributes" do
93
+ expected = "<div>foobar</div>"
94
+
95
+ attrs = {}
96
+
97
+ theme.build_html_error(html_attrs: attrs, field_type: field_type, error: "foobar").should eq(expected)
98
+ end
99
+ end
100
+ end
101
+
102
+ end