bulma_form_builder 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +7 -0
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +4 -0
  7. data/Gemfile.lock +158 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +71 -0
  10. data/Rakefile +6 -0
  11. data/bin/console +14 -0
  12. data/bin/setup +8 -0
  13. data/bulma_form_builder.gemspec +30 -0
  14. data/lib/bulma_form_builder.rb +4 -0
  15. data/lib/bulma_form_builder/components.rb +7 -0
  16. data/lib/bulma_form_builder/components/validation.rb +17 -0
  17. data/lib/bulma_form_builder/form_builder.rb +37 -0
  18. data/lib/bulma_form_builder/form_field.rb +36 -0
  19. data/lib/bulma_form_builder/form_field_builder.rb +11 -0
  20. data/lib/bulma_form_builder/form_helper.rb +23 -0
  21. data/lib/bulma_form_builder/helpers.rb +24 -0
  22. data/lib/bulma_form_builder/inputs.rb +17 -0
  23. data/lib/bulma_form_builder/inputs/base.rb +31 -0
  24. data/lib/bulma_form_builder/inputs/check_box.rb +33 -0
  25. data/lib/bulma_form_builder/inputs/collection_check_boxes.rb +24 -0
  26. data/lib/bulma_form_builder/inputs/date_field.rb +24 -0
  27. data/lib/bulma_form_builder/inputs/email_field.rb +13 -0
  28. data/lib/bulma_form_builder/inputs/month_field.rb +27 -0
  29. data/lib/bulma_form_builder/inputs/number_field.rb +13 -0
  30. data/lib/bulma_form_builder/inputs/password_field.rb +13 -0
  31. data/lib/bulma_form_builder/inputs/select.rb +23 -0
  32. data/lib/bulma_form_builder/inputs/text_area.rb +23 -0
  33. data/lib/bulma_form_builder/inputs/text_field.rb +13 -0
  34. data/lib/bulma_form_builder/inputs/time_field.rb +24 -0
  35. data/lib/bulma_form_builder/railtie.rb +12 -0
  36. data/lib/bulma_form_builder/version.rb +3 -0
  37. metadata +135 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 93dc7a5a3da2b117075258e5d6e13c2edd96329443b456ecbd1dade6a59456db
4
+ data.tar.gz: a8a03a1e51a1407195305e49976796636ac442db30ccb42db115e5a52b7ad740
5
+ SHA512:
6
+ metadata.gz: ed585ec68ff443b33ba8b55147577fac46e67ed04edd407cd97404e12a810b0c3222f16d38eea4cb2b057470812e30c0faf144c3111f456573d116ecfb7038c2
7
+ data.tar.gz: 2346c2105b2fd649da3b2ed4adbc3bf061d412b3a8dee839662c8b0bee9acbb7dff9e9eb44a82c4b86ab9fbe69e8b082ecd6938ba362a2c77f4b19852457ae7e
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.3
7
+ before_install: gem install bundler -v 2.0.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at lala.akira@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in bulma_form_builder.gemspec
4
+ gemspec
@@ -0,0 +1,158 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bulma_form_builder (0.1.0)
5
+ rails (>= 5.2.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actioncable (6.0.1)
11
+ actionpack (= 6.0.1)
12
+ nio4r (~> 2.0)
13
+ websocket-driver (>= 0.6.1)
14
+ actionmailbox (6.0.1)
15
+ actionpack (= 6.0.1)
16
+ activejob (= 6.0.1)
17
+ activerecord (= 6.0.1)
18
+ activestorage (= 6.0.1)
19
+ activesupport (= 6.0.1)
20
+ mail (>= 2.7.1)
21
+ actionmailer (6.0.1)
22
+ actionpack (= 6.0.1)
23
+ actionview (= 6.0.1)
24
+ activejob (= 6.0.1)
25
+ mail (~> 2.5, >= 2.5.4)
26
+ rails-dom-testing (~> 2.0)
27
+ actionpack (6.0.1)
28
+ actionview (= 6.0.1)
29
+ activesupport (= 6.0.1)
30
+ rack (~> 2.0)
31
+ rack-test (>= 0.6.3)
32
+ rails-dom-testing (~> 2.0)
33
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
34
+ actiontext (6.0.1)
35
+ actionpack (= 6.0.1)
36
+ activerecord (= 6.0.1)
37
+ activestorage (= 6.0.1)
38
+ activesupport (= 6.0.1)
39
+ nokogiri (>= 1.8.5)
40
+ actionview (6.0.1)
41
+ activesupport (= 6.0.1)
42
+ builder (~> 3.1)
43
+ erubi (~> 1.4)
44
+ rails-dom-testing (~> 2.0)
45
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
46
+ activejob (6.0.1)
47
+ activesupport (= 6.0.1)
48
+ globalid (>= 0.3.6)
49
+ activemodel (6.0.1)
50
+ activesupport (= 6.0.1)
51
+ activerecord (6.0.1)
52
+ activemodel (= 6.0.1)
53
+ activesupport (= 6.0.1)
54
+ activestorage (6.0.1)
55
+ actionpack (= 6.0.1)
56
+ activejob (= 6.0.1)
57
+ activerecord (= 6.0.1)
58
+ marcel (~> 0.3.1)
59
+ activesupport (6.0.1)
60
+ concurrent-ruby (~> 1.0, >= 1.0.2)
61
+ i18n (>= 0.7, < 2)
62
+ minitest (~> 5.1)
63
+ tzinfo (~> 1.1)
64
+ zeitwerk (~> 2.2)
65
+ builder (3.2.3)
66
+ concurrent-ruby (1.1.5)
67
+ crass (1.0.5)
68
+ diff-lcs (1.3)
69
+ erubi (1.9.0)
70
+ globalid (0.4.2)
71
+ activesupport (>= 4.2.0)
72
+ i18n (1.7.0)
73
+ concurrent-ruby (~> 1.0)
74
+ loofah (2.3.1)
75
+ crass (~> 1.0.2)
76
+ nokogiri (>= 1.5.9)
77
+ mail (2.7.1)
78
+ mini_mime (>= 0.1.1)
79
+ marcel (0.3.3)
80
+ mimemagic (~> 0.3.2)
81
+ method_source (0.9.2)
82
+ mimemagic (0.3.3)
83
+ mini_mime (1.0.2)
84
+ mini_portile2 (2.4.0)
85
+ minitest (5.13.0)
86
+ nio4r (2.5.2)
87
+ nokogiri (1.10.5)
88
+ mini_portile2 (~> 2.4.0)
89
+ rack (2.0.7)
90
+ rack-test (1.1.0)
91
+ rack (>= 1.0, < 3)
92
+ rails (6.0.1)
93
+ actioncable (= 6.0.1)
94
+ actionmailbox (= 6.0.1)
95
+ actionmailer (= 6.0.1)
96
+ actionpack (= 6.0.1)
97
+ actiontext (= 6.0.1)
98
+ actionview (= 6.0.1)
99
+ activejob (= 6.0.1)
100
+ activemodel (= 6.0.1)
101
+ activerecord (= 6.0.1)
102
+ activestorage (= 6.0.1)
103
+ activesupport (= 6.0.1)
104
+ bundler (>= 1.3.0)
105
+ railties (= 6.0.1)
106
+ sprockets-rails (>= 2.0.0)
107
+ rails-dom-testing (2.0.3)
108
+ activesupport (>= 4.2.0)
109
+ nokogiri (>= 1.6)
110
+ rails-html-sanitizer (1.3.0)
111
+ loofah (~> 2.3)
112
+ railties (6.0.1)
113
+ actionpack (= 6.0.1)
114
+ activesupport (= 6.0.1)
115
+ method_source
116
+ rake (>= 0.8.7)
117
+ thor (>= 0.20.3, < 2.0)
118
+ rake (10.5.0)
119
+ rspec (3.9.0)
120
+ rspec-core (~> 3.9.0)
121
+ rspec-expectations (~> 3.9.0)
122
+ rspec-mocks (~> 3.9.0)
123
+ rspec-core (3.9.0)
124
+ rspec-support (~> 3.9.0)
125
+ rspec-expectations (3.9.0)
126
+ diff-lcs (>= 1.2.0, < 2.0)
127
+ rspec-support (~> 3.9.0)
128
+ rspec-mocks (3.9.0)
129
+ diff-lcs (>= 1.2.0, < 2.0)
130
+ rspec-support (~> 3.9.0)
131
+ rspec-support (3.9.0)
132
+ sprockets (4.0.0)
133
+ concurrent-ruby (~> 1.0)
134
+ rack (> 1, < 3)
135
+ sprockets-rails (3.2.1)
136
+ actionpack (>= 4.0)
137
+ activesupport (>= 4.0)
138
+ sprockets (>= 3.0.0)
139
+ thor (0.20.3)
140
+ thread_safe (0.3.6)
141
+ tzinfo (1.2.5)
142
+ thread_safe (~> 0.1)
143
+ websocket-driver (0.7.1)
144
+ websocket-extensions (>= 0.1.0)
145
+ websocket-extensions (0.1.4)
146
+ zeitwerk (2.2.1)
147
+
148
+ PLATFORMS
149
+ ruby
150
+
151
+ DEPENDENCIES
152
+ bulma_form_builder!
153
+ bundler (~> 2.0)
154
+ rake (~> 10.0)
155
+ rspec (~> 3.0)
156
+
157
+ BUNDLED WITH
158
+ 2.0.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 aki
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,71 @@
1
+ # bulma_form_builder
2
+
3
+ `bulma_form_builder` is a Rails form builder that makes it super easy to integrate Bulma style forms into your Rails application.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'bulma_form_builder'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```
22
+ $ gem install bulma_form_builder
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ To get started, use the `bulma_form_with` helper in place of the Rails `form_with` helper. Here's an example:
28
+
29
+ ```erb
30
+ <%= bulma_form_with(model: @user, local: true) do |f| %>
31
+ <%= f.email_field :email %>
32
+ <%= f.password_field :password %>
33
+ <%= f.check_box :remember_me %>
34
+ <%= f.submit "Log In" %>
35
+ <% end %>
36
+ ```
37
+
38
+ This generates the following HTML:
39
+
40
+ ```html
41
+ <form action="/user" accept-charset="UTF-8" method="post">
42
+ <div class="field">
43
+ <label class="label" for="user_email">Email</label>
44
+ <div class="control">
45
+ <input class="input" type="email" name="user[email]" id="user_email" />
46
+ </div>
47
+ </div>
48
+ <div class="field">
49
+ <label class="label" for="user_password">Password</label>
50
+ <div class="control">
51
+ <input class="input" type="password" name="user[password]" id="user_password" />
52
+ </div>
53
+ </div>
54
+ <div class="field">
55
+ <label class="checkbox">
56
+ <input name="user[remember_me]" type="hidden" value="0" />
57
+ <input type="checkbox" value="1" name="user[remember_me]" id="user_remember_me" />
58
+ <span class="control-label">Remember me</span>
59
+ </label>
60
+ </div>
61
+ <input type="submit" name="commit" value="login" data-disable-with="login" />
62
+ </form>
63
+ ```
64
+
65
+ ## Contributing
66
+
67
+ Bug reports and pull requests are welcome on GitHub at https://github.com/aki77/bulma_form_builder. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
68
+
69
+ ## License
70
+
71
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "bulma_form_builder"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,30 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "bulma_form_builder/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "bulma_form_builder"
7
+ spec.version = BulmaFormBuilder::VERSION
8
+ spec.authors = ["aki77"]
9
+ spec.email = ["aki77@users.noreply.github.com"]
10
+
11
+ spec.summary = "Rails form builder"
12
+ spec.description = "bulma_form_builder is a Rails form builder that makes it super easy to integrate Bulma style forms into your Rails application."
13
+ spec.homepage = "https://github.com/aki77/bulma_form_builder"
14
+ spec.license = "MIT"
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_dependency "rails", ">= 5.2.0"
26
+
27
+ spec.add_development_dependency "bundler", "~> 2.0"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rspec", "~> 3.0"
30
+ end
@@ -0,0 +1,4 @@
1
+ require 'bulma_form_builder/railtie'
2
+
3
+ module BulmaFormBuilder
4
+ end
@@ -0,0 +1,7 @@
1
+ require 'bulma_form_builder/components/validation'
2
+
3
+ module BulmaFormBuilder
4
+ module Components
5
+ include Validation
6
+ end
7
+ end
@@ -0,0 +1,17 @@
1
+ module BulmaFormBuilder
2
+ module Components
3
+ module Validation
4
+ extend ActiveSupport::Concern
5
+
6
+ private
7
+
8
+ def error?(name)
9
+ object.respond_to?(:errors) && !(name.nil? || object.errors[name].empty?)
10
+ end
11
+
12
+ def error_messages_for(name)
13
+ object.errors.full_messages_for(name).join("\n")
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,37 @@
1
+ require 'bulma_form_builder/form_field_builder'
2
+ require 'bulma_form_builder/form_field'
3
+ require 'bulma_form_builder/components'
4
+ require 'bulma_form_builder/helpers'
5
+ require 'bulma_form_builder/inputs'
6
+
7
+ module BulmaFormBuilder
8
+ class FormBuilder < ActionView::Helpers::FormBuilder
9
+ attr_reader :layout
10
+
11
+ include BulmaFormBuilder::FormFieldBuilder
12
+ include BulmaFormBuilder::FormField
13
+ include BulmaFormBuilder::Components
14
+
15
+ include BulmaFormBuilder::Helpers
16
+
17
+ include BulmaFormBuilder::Inputs::Base
18
+ include BulmaFormBuilder::Inputs::EmailField
19
+ include BulmaFormBuilder::Inputs::DateField
20
+ include BulmaFormBuilder::Inputs::TimeField
21
+ include BulmaFormBuilder::Inputs::MonthField
22
+ include BulmaFormBuilder::Inputs::NumberField
23
+ include BulmaFormBuilder::Inputs::PasswordField
24
+ include BulmaFormBuilder::Inputs::Select
25
+ include BulmaFormBuilder::Inputs::TextField
26
+ include BulmaFormBuilder::Inputs::TextArea
27
+ include BulmaFormBuilder::Inputs::CheckBox
28
+ include BulmaFormBuilder::Inputs::CollectionCheckBoxes
29
+
30
+ delegate :content_tag, :capture, :concat, to: :@template
31
+
32
+ def initialize(object_name, object, template, options)
33
+ @layout = options[:layout]
34
+ super
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,36 @@
1
+ module BulmaFormBuilder
2
+ module FormField
3
+ extend ActiveSupport::Concern
4
+
5
+ def form_field(*args, &block)
6
+ name = args.first
7
+ options = args.extract_options!
8
+
9
+ content_tag(:div, class: 'field') do
10
+ concat field_label(name, options) unless options[:hide_label]
11
+ concat field_control(&block)
12
+ concat field_help(name, options)
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def field_control(&block)
19
+ content_tag(:div, class: 'control', &block)
20
+ end
21
+
22
+ def field_help(name, options)
23
+ if error?(name)
24
+ content_tag(:p, error_messages_for(name), class: 'help is-danger')
25
+ elsif options[:help].present?
26
+ content_tag(:p, options[:help], class: 'help')
27
+ end
28
+ end
29
+
30
+ def field_label(name, options)
31
+ classes = %w[label]
32
+ classes << 'required' if options[:required]
33
+ label(name, options[:label], class: classes)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,11 @@
1
+ module BulmaFormBuilder
2
+ module FormFieldBuilder
3
+ extend ActiveSupport::Concern
4
+
5
+ private
6
+
7
+ def form_field_builder(method, options, _html_options = nil)
8
+ form_field(method, options) { yield }
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,23 @@
1
+ require 'bulma_form_builder/form_builder'
2
+
3
+ module BulmaFormBuilder
4
+ module FormHelper
5
+ def bulma_form_with(options = {}, &block)
6
+ options.reverse_merge!(builder: ::BulmaFormBuilder::FormBuilder)
7
+
8
+ _with_bulma_form_field_error_proc do
9
+ form_with(options, &block)
10
+ end
11
+ end
12
+
13
+ def _with_bulma_form_field_error_proc
14
+ original_proc = ActionView::Base.field_error_proc
15
+ ActionView::Base.field_error_proc = proc do |html_tag, _instance_tag|
16
+ html_tag
17
+ end
18
+ yield
19
+ ensure
20
+ ActionView::Base.field_error_proc = original_proc
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,24 @@
1
+ module BulmaFormBuilder
2
+ module Helpers
3
+ def alert_message(options = {})
4
+ title = options[:title] || I18n.t('errors.messages.alert')
5
+ css = options[:class] || 'notification is-danger'
6
+ return unless object.respond_to?(:errors) && object.errors.full_messages.any?
7
+
8
+ content_tag :div, class: css do
9
+ concat content_tag :p, title
10
+ concat error_summary unless options[:error_summary] == false
11
+ end
12
+ end
13
+
14
+ def error_summary
15
+ return unless object.errors.any?
16
+
17
+ content_tag :ul, class: 'error-summary' do
18
+ object.errors.full_messages.each do |error|
19
+ concat content_tag(:li, error)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,17 @@
1
+ require 'bulma_form_builder/inputs/base'
2
+ require 'bulma_form_builder/inputs/check_box'
3
+ require 'bulma_form_builder/inputs/collection_check_boxes'
4
+ require 'bulma_form_builder/inputs/date_field'
5
+ require 'bulma_form_builder/inputs/email_field'
6
+ require 'bulma_form_builder/inputs/month_field'
7
+ require 'bulma_form_builder/inputs/number_field'
8
+ require 'bulma_form_builder/inputs/password_field'
9
+ require 'bulma_form_builder/inputs/select'
10
+ require 'bulma_form_builder/inputs/text_area'
11
+ require 'bulma_form_builder/inputs/text_field'
12
+ require 'bulma_form_builder/inputs/time_field'
13
+
14
+ module BulmaFormBuilder
15
+ module Inputs
16
+ end
17
+ end
@@ -0,0 +1,31 @@
1
+ module BulmaFormBuilder
2
+ module Inputs
3
+ module Base
4
+ extend ActiveSupport::Concern
5
+
6
+ ELEMENTS_WITH_INPUT_CLASS = %i[email_field number_field password_field text_field].freeze
7
+
8
+ class_methods do
9
+ def bulma_field(field_name)
10
+ define_method "#{field_name}_with_bulma" do |name, options = {}|
11
+ form_field_builder(name, options) do
12
+ classes = [options[:class]]
13
+ classes <<= 'input' if ELEMENTS_WITH_INPUT_CLASS.include?(field_name)
14
+ classes <<= 'is-danger' if error?(name)
15
+ options[:class] = classes.compact.join(' ')
16
+
17
+ send("#{field_name}_without_bulma".to_sym, name, options)
18
+ end
19
+ end
20
+
21
+ bulma_alias(field_name)
22
+ end
23
+
24
+ def bulma_alias(field_name)
25
+ alias_method "#{field_name}_without_bulma".to_sym, field_name
26
+ alias_method field_name, "#{field_name}_with_bulma".to_sym
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,33 @@
1
+ module BulmaFormBuilder
2
+ module Inputs
3
+ module CheckBox
4
+ extend ActiveSupport::Concern
5
+
6
+ include Base
7
+
8
+ included do
9
+ def check_box_with_bulma(name, options = {}, checked_value = '1', unchecked_value = '0', &block)
10
+ options = options.symbolize_keys!
11
+ check_box_options = options.except(:class, :label, :label_class, :error_message, :help, :inline, :custom, :hide_label, :skip_label, :wrapper_class)
12
+
13
+ content_tag(:div, class: 'field') do
14
+ content_tag(:label, class: 'checkbox') do
15
+ html = check_box_without_bulma(name, check_box_options, checked_value, unchecked_value)
16
+ html.concat(check_box_label(name)) unless options[:skip_label]
17
+ html.concat(generate_error(name)) if options[:error_message]
18
+ html
19
+ end
20
+ end
21
+ end
22
+
23
+ bulma_alias(:check_box)
24
+ end
25
+
26
+ private
27
+
28
+ def check_box_label(name)
29
+ content_tag(:span, object.class.human_attribute_name(name), class: 'control-label')
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,24 @@
1
+ module BulmaFormBuilder
2
+ module Inputs
3
+ module CollectionCheckBoxes
4
+ extend ActiveSupport::Concern
5
+ include Base
6
+
7
+ included do
8
+ def collection_check_boxes_with_bulma(method, collection, value_method, text_method, options = {}, html_options = {}) # rubocop:disable Metrics/ParameterLists
9
+ html = form_field_builder(method, options, html_options) do
10
+ collection_check_boxes_without_bulma(method, collection, value_method, text_method, options, html_options) do |b|
11
+ content_tag(:label, class: 'checkbox') do
12
+ concat b.check_box
13
+ concat content_tag(:span, class: 'control-label') { b.text }
14
+ end
15
+ end
16
+ end
17
+ hidden_field(method, value: '', multiple: true).concat(html)
18
+ end
19
+
20
+ bulma_alias :collection_check_boxes
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ module BulmaFormBuilder
2
+ module Inputs
3
+ module DateField
4
+ extend ActiveSupport::Concern
5
+
6
+ include Base
7
+
8
+ included do
9
+ def date_field_with_bulma(name, options = {})
10
+ form_field_builder(name, options) do
11
+ classes = [options[:class]]
12
+ classes <<= 'input'
13
+ classes <<= 'is-danger' if error?(name)
14
+ options[:class] = classes.compact.join(' ')
15
+
16
+ date_field_without_bulma(name, options)
17
+ end
18
+ end
19
+
20
+ bulma_alias :date_field
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,13 @@
1
+ module BulmaFormBuilder
2
+ module Inputs
3
+ module EmailField
4
+ extend ActiveSupport::Concern
5
+
6
+ include Base
7
+
8
+ included do
9
+ bulma_field(:email_field)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,27 @@
1
+ module BulmaFormBuilder
2
+ module Inputs
3
+ module MonthField
4
+ extend ActiveSupport::Concern
5
+
6
+ include Base
7
+
8
+ included do
9
+ def month_field_with_bulma(name, options = {})
10
+ form_field_builder(name, options) do
11
+ classes = [options[:class]]
12
+ classes <<= 'input'
13
+ classes <<= 'is-danger' if error?(name)
14
+ options[:class] = classes.compact.join(' ')
15
+
16
+ # NOTE: month_fieldの場合だけこれがないと初期値が入らないので
17
+ options[:value] = object.public_send(name)
18
+
19
+ month_field_without_bulma(name, options)
20
+ end
21
+ end
22
+
23
+ bulma_alias :month_field
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,13 @@
1
+ module BulmaFormBuilder
2
+ module Inputs
3
+ module NumberField
4
+ extend ActiveSupport::Concern
5
+
6
+ include Base
7
+
8
+ included do
9
+ bulma_field(:number_field)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module BulmaFormBuilder
2
+ module Inputs
3
+ module PasswordField
4
+ extend ActiveSupport::Concern
5
+
6
+ include Base
7
+
8
+ included do
9
+ bulma_field(:password_field)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,23 @@
1
+ module BulmaFormBuilder
2
+ module Inputs
3
+ module Select
4
+ extend ActiveSupport::Concern
5
+
6
+ include Base
7
+
8
+ included do
9
+ def select_with_bulma(method, choices = nil, options = {}, html_options = {}, &block)
10
+ html_options[:required] = options[:required]
11
+
12
+ form_field_builder(method, options, html_options) do
13
+ content_tag(:div, class: 'select') do
14
+ select_without_bulma(method, choices, options, html_options, &block)
15
+ end
16
+ end
17
+ end
18
+
19
+ bulma_alias(:select)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ module BulmaFormBuilder
2
+ module Inputs
3
+ module TextArea
4
+ extend ActiveSupport::Concern
5
+ include Base
6
+
7
+ included do
8
+ def text_area_with_bulma(name, options = {})
9
+ form_field_builder(name, options) do
10
+ classes = [options[:class]]
11
+ classes <<= 'textarea'
12
+ classes <<= 'is-danger' if error?(name)
13
+ options[:class] = classes.compact.join(' ')
14
+
15
+ text_area_without_bulma(name, options)
16
+ end
17
+ end
18
+
19
+ bulma_alias :text_area
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,13 @@
1
+ module BulmaFormBuilder
2
+ module Inputs
3
+ module TextField
4
+ extend ActiveSupport::Concern
5
+
6
+ include Base
7
+
8
+ included do
9
+ bulma_field(:text_field)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,24 @@
1
+ module BulmaFormBuilder
2
+ module Inputs
3
+ module TimeField
4
+ extend ActiveSupport::Concern
5
+
6
+ include Base
7
+
8
+ included do
9
+ def time_field_with_bulma(name, options = {})
10
+ form_field_builder(name, options) do
11
+ classes = [options[:class]]
12
+ classes <<= 'input'
13
+ classes <<= 'is-danger' if error?(name)
14
+ options[:class] = classes.compact.join(' ')
15
+
16
+ time_field_without_bulma(name, options)
17
+ end
18
+ end
19
+
20
+ bulma_alias :time_field
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,12 @@
1
+ require 'rails/railtie'
2
+
3
+ module BulmaFormBuilder
4
+ class Railtie < Rails::Railtie
5
+ initializer :bulma_form_builder do
6
+ ActiveSupport.on_load(:action_view) do
7
+ require 'bulma_form_builder/form_helper'
8
+ include BulmaFormBuilder::FormHelper
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module BulmaFormBuilder
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bulma_form_builder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - aki77
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-11-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 5.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 5.2.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: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: bulma_form_builder is a Rails form builder that makes it super easy to
70
+ integrate Bulma style forms into your Rails application.
71
+ email:
72
+ - aki77@users.noreply.github.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - CODE_OF_CONDUCT.md
81
+ - Gemfile
82
+ - Gemfile.lock
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - bin/console
87
+ - bin/setup
88
+ - bulma_form_builder.gemspec
89
+ - lib/bulma_form_builder.rb
90
+ - lib/bulma_form_builder/components.rb
91
+ - lib/bulma_form_builder/components/validation.rb
92
+ - lib/bulma_form_builder/form_builder.rb
93
+ - lib/bulma_form_builder/form_field.rb
94
+ - lib/bulma_form_builder/form_field_builder.rb
95
+ - lib/bulma_form_builder/form_helper.rb
96
+ - lib/bulma_form_builder/helpers.rb
97
+ - lib/bulma_form_builder/inputs.rb
98
+ - lib/bulma_form_builder/inputs/base.rb
99
+ - lib/bulma_form_builder/inputs/check_box.rb
100
+ - lib/bulma_form_builder/inputs/collection_check_boxes.rb
101
+ - lib/bulma_form_builder/inputs/date_field.rb
102
+ - lib/bulma_form_builder/inputs/email_field.rb
103
+ - lib/bulma_form_builder/inputs/month_field.rb
104
+ - lib/bulma_form_builder/inputs/number_field.rb
105
+ - lib/bulma_form_builder/inputs/password_field.rb
106
+ - lib/bulma_form_builder/inputs/select.rb
107
+ - lib/bulma_form_builder/inputs/text_area.rb
108
+ - lib/bulma_form_builder/inputs/text_field.rb
109
+ - lib/bulma_form_builder/inputs/time_field.rb
110
+ - lib/bulma_form_builder/railtie.rb
111
+ - lib/bulma_form_builder/version.rb
112
+ homepage: https://github.com/aki77/bulma_form_builder
113
+ licenses:
114
+ - MIT
115
+ metadata: {}
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubygems_version: 3.0.3
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: Rails form builder
135
+ test_files: []