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,52 @@
1
+ require_relative "../spec_helper"
2
+
3
+ theme = SexyForm::Themes::Bootstrap4Inline
4
+
5
+ describe SexyForm::Themes do
6
+
7
+ describe ".classes" do
8
+ it "Comes with default themes" do
9
+ classes = [SexyForm::Themes::Bootstrap2Horizontal, SexyForm::Themes::Bootstrap2Inline, SexyForm::Themes::Bootstrap2Vertical, SexyForm::Themes::Bootstrap3Horizontal, SexyForm::Themes::Bootstrap3Inline, SexyForm::Themes::Bootstrap3Vertical, SexyForm::Themes::Bootstrap4Horizontal, SexyForm::Themes::Bootstrap4Inline, SexyForm::Themes::Bootstrap4Vertical, SexyForm::Themes::BulmaHorizontal, SexyForm::Themes::BulmaVertical, SexyForm::Themes::Default, SexyForm::Themes::Foundation, SexyForm::Themes::Materialize, SexyForm::Themes::Milligram, SexyForm::Themes::SemanticUIInline, SexyForm::Themes::SemanticUIVertical]
10
+
11
+ SexyForm::Themes.classes.should eq(classes)
12
+
13
+ expected = ["bootstrap_2_horizontal", "bootstrap_2_inline", "bootstrap_2_vertical", "bootstrap_3_horizontal", "bootstrap_3_inline", "bootstrap_3_vertical", "bootstrap_4_horizontal", "bootstrap_4_inline", "bootstrap_4_vertical", "bulma_horizontal", "bulma_vertical", "default", "foundation", "materialize", "milligram", "semantic_ui_inline", "semantic_ui_vertical"]
14
+
15
+ classes.map{|x| x.theme_name}.should eq(expected)
16
+ end
17
+ end
18
+
19
+ describe ".from_name" do
20
+ it "works correctly" do
21
+ SexyForm::Themes.from_name("bootstrap_4_inline").should eq(theme)
22
+ end
23
+
24
+ it "fails correctly" do
25
+ expect {
26
+ SexyForm::Themes.from_name("invalid_theme")
27
+ }.to raise_exception(ArgumentError)
28
+ end
29
+ end
30
+
31
+ describe "Kitchen Sink" do
32
+ SexyForm::Themes.classes.each do |theme_class|
33
+ b = SexyForm::Builder.new(theme: theme_class.new)
34
+
35
+ SexyForm::Builder::FIELD_TYPES.each do |field_type|
36
+ it "theme: #{theme_class.name}, field_type: #{field_type}" do
37
+ if field_type == "select"
38
+ actual = b.field type: :select, name: :foobar, label: "Hello", help_text: "World", errors: ["error1", "error2"], input_html: {class: "foo"}, label_html: {class: "foo"}, wrapper_html: {class: "foo"}, help_text_html: {class: "foo"}, error_html: {class: "foo"}, collection: {options: [["foo", "bar"], "foobar"], selected: "foobar", disabled: "other", include_blank: true}
39
+ else
40
+ actual = b.field type: field_type, name: :foobar, label: "Hello", help_text: "World", value: "foo", errors: ["error1", "error2"], input_html: {class: "foo"}, label_html: {class: "foo"}, wrapper_html: {class: "foo"}, help_text_html: {class: "foo"}, error_html: {class: "foo"}
41
+ end
42
+
43
+ ### Ensure No Incorrect/Unparenthesized Ternary Values
44
+ actual.include?("true").should eq(false)
45
+ actual.include?("false").should eq(false)
46
+ actual.include?("empty?").should eq(false)
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ end
@@ -0,0 +1,54 @@
1
+ require "spec_helper"
2
+
3
+ describe SexyForm do
4
+
5
+ it "exposes a VERSION" do
6
+ SexyForm::VERSION.should be_a(String)
7
+ end
8
+
9
+ describe ".form" do
10
+ it "allows no block" do
11
+ result = SexyForm.form(action: "/products", method: :post, form_html: {style: "margin-top: 20px;", "data-foo": "bar"})
12
+
13
+ expected = "<form style=\"margin-top: 20px;\" data-foo=\"bar\" method=\"post\"></form>"
14
+
15
+ result.should eq(expected)
16
+ end
17
+
18
+ it "allows basic usage" do
19
+ result = SexyForm.form(theme: :bootstrap_4_inline, action: "/products", method: :post, form_html: {style: "margin-top: 20px;", "data-foo": "bar"}) do
20
+
21
+ end
22
+
23
+ expected = "<form style=\"margin-top: 20px;\" data-foo=\"bar\" class=\"form-inline\" method=\"post\"></form>"
24
+
25
+ result.should eq(expected)
26
+ end
27
+
28
+ it "allows for nested input fields" do
29
+ result = SexyForm.form(form_html: {"id" => "myForm"}) do |f|
30
+ f << f.field(name: :name, type: :text)
31
+ end
32
+
33
+ expected = "<form id=\"myForm\" method=\"post\"><div><label for=\"name\">Name</label><input type=\"text\" name=\"name\" id=\"name\"></div></form>"
34
+
35
+ result.should eq(expected)
36
+ end
37
+
38
+ it "sets up form for multipart" do
39
+ result = SexyForm.form(action: "/test/1", form_html: {id: "myForm", multipart: true})
40
+
41
+ expected = "<form id=\"myForm\" method=\"post\" enctype=\"multipart/form-data\"></form>"
42
+
43
+ result.should eq(expected)
44
+ end
45
+
46
+ it "String keys take precedence over Symbol keys on :form_html argument" do
47
+ result = SexyForm.form(action: "/test/1", form_html: {"id" => "string", :id => "symbol"})
48
+
49
+ result.include?("string").should eq(true)
50
+ result.include?("symbol").should eq(false)
51
+ end
52
+ end
53
+
54
+ end
@@ -0,0 +1,16 @@
1
+ require "sexy_form"
2
+
3
+ require 'custom_assertions'
4
+
5
+ RSpec.configure do |config|
6
+ config.expect_with(:rspec) do |c|
7
+ c.syntax = [:should, :expect]
8
+ end
9
+ end
10
+
11
+ ### Easier than rewriting all the Crystal String.build calls in spec folder
12
+ def build_string(&block)
13
+ s = ""
14
+ block.call(s)
15
+ return s
16
+ end
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sexy_form
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ platform: ruby
6
+ authors:
7
+ - Weston Ganger
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-05-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Dead simple HTML form builder for Ruby with built-in support for many
56
+ popular UI libraries such as Bootstrap
57
+ email: weston@westonganger.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - CHANGELOG.md
63
+ - LICENSE
64
+ - README.md
65
+ - Rakefile
66
+ - lib/sexy_form.rb
67
+ - lib/sexy_form/builder.rb
68
+ - lib/sexy_form/themes.rb
69
+ - lib/sexy_form/themes/base_theme.rb
70
+ - lib/sexy_form/themes/bootstrap_2_horizontal.rb
71
+ - lib/sexy_form/themes/bootstrap_2_inline.rb
72
+ - lib/sexy_form/themes/bootstrap_2_vertical.rb
73
+ - lib/sexy_form/themes/bootstrap_3_horizontal.rb
74
+ - lib/sexy_form/themes/bootstrap_3_inline.rb
75
+ - lib/sexy_form/themes/bootstrap_3_vertical.rb
76
+ - lib/sexy_form/themes/bootstrap_4_horizontal.rb
77
+ - lib/sexy_form/themes/bootstrap_4_inline.rb
78
+ - lib/sexy_form/themes/bootstrap_4_vertical.rb
79
+ - lib/sexy_form/themes/bulma_horizontal.rb
80
+ - lib/sexy_form/themes/bulma_vertical.rb
81
+ - lib/sexy_form/themes/default.rb
82
+ - lib/sexy_form/themes/foundation.rb
83
+ - lib/sexy_form/themes/materialize.rb
84
+ - lib/sexy_form/themes/milligram.rb
85
+ - lib/sexy_form/themes/semantic_ui_inline.rb
86
+ - lib/sexy_form/themes/semantic_ui_vertical.rb
87
+ - lib/sexy_form/version.rb
88
+ - spec/custom_assertions.rb
89
+ - spec/sexy_form/builder_spec.rb
90
+ - spec/sexy_form/themes/base_theme_spec.rb
91
+ - spec/sexy_form/themes/bootstrap_2_horizontal_spec.rb
92
+ - spec/sexy_form/themes/bootstrap_2_inline_spec.rb
93
+ - spec/sexy_form/themes/bootstrap_2_vertical_spec.rb
94
+ - spec/sexy_form/themes/bootstrap_3_horizontal_spec.rb
95
+ - spec/sexy_form/themes/bootstrap_3_inline_spec.rb
96
+ - spec/sexy_form/themes/bootstrap_3_vertical_spec.rb
97
+ - spec/sexy_form/themes/bootstrap_4_horizontal_spec.rb
98
+ - spec/sexy_form/themes/bootstrap_4_inline_spec.rb
99
+ - spec/sexy_form/themes/bootstrap_4_vertical_spec.rb
100
+ - spec/sexy_form/themes/bulma_horizontal_spec.rb
101
+ - spec/sexy_form/themes/bulma_vertical_spec.rb
102
+ - spec/sexy_form/themes/default_spec.rb
103
+ - spec/sexy_form/themes/foundation_spec.rb
104
+ - spec/sexy_form/themes/materialize_spec.rb
105
+ - spec/sexy_form/themes/milligram_spec.rb
106
+ - spec/sexy_form/themes/semantic_ui_inline_spec.rb
107
+ - spec/sexy_form/themes/semantic_ui_vertical_spec.rb
108
+ - spec/sexy_form/themes/theme_spec_helper.rb
109
+ - spec/sexy_form/themes_spec.rb
110
+ - spec/sexy_form_spec.rb
111
+ - spec/spec_helper.rb
112
+ homepage: https://github.com/westonganger/sexy_form
113
+ licenses: []
114
+ metadata: {}
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: 1.9.3
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 2.6.11
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: Dead simple HTML form builder for Ruby with built-in support for many popular
135
+ UI libraries such as Bootstrap
136
+ test_files:
137
+ - spec/spec_helper.rb
138
+ - spec/sexy_form_spec.rb
139
+ - spec/sexy_form/themes_spec.rb
140
+ - spec/sexy_form/themes/milligram_spec.rb
141
+ - spec/sexy_form/themes/bootstrap_2_vertical_spec.rb
142
+ - spec/sexy_form/themes/materialize_spec.rb
143
+ - spec/sexy_form/themes/bulma_horizontal_spec.rb
144
+ - spec/sexy_form/themes/semantic_ui_inline_spec.rb
145
+ - spec/sexy_form/themes/default_spec.rb
146
+ - spec/sexy_form/themes/foundation_spec.rb
147
+ - spec/sexy_form/themes/base_theme_spec.rb
148
+ - spec/sexy_form/themes/bootstrap_4_vertical_spec.rb
149
+ - spec/sexy_form/themes/bootstrap_3_horizontal_spec.rb
150
+ - spec/sexy_form/themes/bootstrap_3_inline_spec.rb
151
+ - spec/sexy_form/themes/semantic_ui_vertical_spec.rb
152
+ - spec/sexy_form/themes/bootstrap_4_inline_spec.rb
153
+ - spec/sexy_form/themes/bootstrap_3_vertical_spec.rb
154
+ - spec/sexy_form/themes/theme_spec_helper.rb
155
+ - spec/sexy_form/themes/bootstrap_2_horizontal_spec.rb
156
+ - spec/sexy_form/themes/bulma_vertical_spec.rb
157
+ - spec/sexy_form/themes/bootstrap_2_inline_spec.rb
158
+ - spec/sexy_form/themes/bootstrap_4_horizontal_spec.rb
159
+ - spec/sexy_form/builder_spec.rb
160
+ - spec/custom_assertions.rb