Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: pantographe/view_component-form
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 03368652ecd1ef05f48ab52bf6e73422778e5328
Choose a base ref
..
head repository: pantographe/view_component-form
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 8f800836d0f2f3fc817d0c263d738ebefe43affd
Choose a head ref
Showing with 488 additions and 69 deletions.
  1. +10 −1 .github/workflows/main.yml
  2. +1 −0 .rubocop.yml
  3. +4 −0 Appraisals
  4. +27 −2 CHANGELOG.md
  5. +2 −0 Gemfile
  6. +14 −4 Gemfile.lock
  7. +10 −4 README.md
  8. +1 −1 app/components/view_component/form/field_component.rb
  9. +28 −0 bin/release
  10. +29 −0 bin/rspec
  11. +2 −0 config.ru
  12. +3 −3 gemfiles/rails_6.0.x.gemfile
  13. +3 −3 gemfiles/rails_6.1.x.gemfile
  14. +17 −0 gemfiles/rails_head.gemfile
  15. +1 −1 lib/generators/vcf/builder/templates/builder.rb.erb
  16. +38 −11 lib/view_component/form/builder.rb
  17. +1 −1 lib/view_component/form/version.rb
  18. +9 −0 spec/internal/app/components/form/label_component.rb
  19. +9 −0 spec/internal/app/components/form/text_field_component.rb
  20. +9 −0 spec/internal/app/components/inline_form/label_component.rb
  21. +5 −0 spec/internal/app/forms/custom_form_builder.rb
  22. +5 −0 spec/internal/app/forms/inline_custom_form_builder.rb
  23. +11 −0 spec/spec_helper.rb
  24. +1 −1 spec/support/matchers/eq_html.rb
  25. +41 −0 spec/view_component/form/base_component_spec.rb
  26. +26 −0 spec/view_component/form/builder_spec.rb
  27. +4 −3 spec/view_component/form/check_box_component_spec.rb
  28. +27 −3 spec/view_component/form/collection_check_boxes_component_spec.rb
  29. +28 −4 spec/view_component/form/collection_radio_buttons_component_spec.rb
  30. +10 −4 spec/view_component/form/date_select_component_spec.rb
  31. +18 −4 spec/view_component/form/datetime_select_component_spec.rb
  32. +70 −0 spec/view_component/form/field_component_spec.rb
  33. +5 −7 spec/view_component/form/rich_text_area_component_spec.rb
  34. +6 −4 spec/view_component/form/select_component_spec.rb
  35. +8 −4 spec/view_component/form/time_select_component_spec.rb
  36. +5 −4 spec/view_component/form/time_zone_select_component_spec.rb
11 changes: 10 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -13,6 +13,8 @@ jobs:
- { ruby: "3.0", rails: "6.0.x" }
- { ruby: "2.7", rails: "6.1.x" }
- { ruby: "3.0", rails: "6.1.x" }
- { ruby: "2.7", rails: "head" }
- { ruby: "3.0", rails: "head" }

env:
BUNDLE_GEMFILE: gemfiles/rails_${{ matrix.versions.rails }}.gemfile
@@ -27,4 +29,11 @@ jobs:

- name: Test with Rake
run: |
bundle exec rake
COVERAGE=true bundle exec rake
- name: Upload coverage results
uses: actions/upload-artifact@v2
if: always()
with:
name: coverage-report-ruby-${{ matrix.versions.ruby }}-rails-${{ matrix.versions.rails }}
path: coverage
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ AllCops:
TargetRubyVersion: 2.7
NewCops: enable
Exclude:
- bin/**/*
- lib/generators/**/templates/**/*
- gemfiles/**/*
- vendor/**/*
4 changes: 4 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -7,3 +7,7 @@ end
appraise "rails-6.1.x" do
gem "rails", "~> 6.1.0"
end

appraise "rails-head" do
gem "rails", github: "rails/rails", branch: "main"
end
29 changes: 27 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [0.1.0] - 2021-06-11
## [0.1.1] - 2021-09-27

### Changed
- Setup rspec-html-matchers and use it for complex components specs (#65)

### Fixed
- Fix errors methods in `BaseComponent` and `FieldComponent` (#71)

## [0.1.0] - 2021-09-16

### Added

- `FormBuilder`: add `.namespace` method to allow local lookup of components (#54)
- Add basic `ViewComponent::Form::Builder` that can be used in place of Rails' `ActionView::Helpers::FormBuilder` (#1)
- Add all standard FormBuilder helpers provided by Rails, implemented as ViewComponents (#4)
- Add a custom FormBuilder generator (#34)
- Add CHANGELOG (#50)
- Add CI (#2)

- Initial release
[Unreleased]: https://github.com/pantographe/view_component-form/compare/v0.1.1...HEAD
[0.1.1]: https://github.com/pantographe/view_component-form/compare/v0.1.0...v0.1.1
[0.1.0]: https://github.com/pantographe/view_component-form/releases/tag/v0.1.0
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -11,9 +11,11 @@ gem "combustion"
gem "rails"
gem "rake", "~> 13.0"
gem "rspec", "~> 3.0", require: false
gem "rspec-html-matchers"
gem "rubocop", require: false
gem "rubocop-performance", require: false
gem "rubocop-rspec", require: false
gem "simplecov", require: false, group: :test

group :development do
gem "view_component", require: "view_component/engine"
18 changes: 14 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
view_component-form (0.1.0.pre)
view_component-form (0.1.1)
actionview (>= 6.0.0, < 7.0)
activesupport (>= 6.0.0, < 7.0)
view_component (>= 2.34.0, < 3.0)
@@ -91,6 +91,7 @@ GEM
concurrent-ruby (1.1.9)
crass (1.0.6)
diff-lcs (1.4.4)
docile (1.3.4)
erubi (1.10.0)
ffi (1.15.4)
globalid (0.5.2)
@@ -118,12 +119,12 @@ GEM
mini_portile2 (2.6.1)
minitest (5.14.4)
nio4r (2.5.8)
nokogiri (1.12.4)
nokogiri (1.12.5)
mini_portile2 (~> 2.6.1)
racc (~> 1.4)
nokogiri (1.12.4-x86_64-darwin)
nokogiri (1.12.5-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.12.4-x86_64-linux)
nokogiri (1.12.5-x86_64-linux)
racc (~> 1.4)
parallel (1.20.1)
parser (3.0.2.0)
@@ -179,6 +180,9 @@ GEM
rspec-expectations (3.10.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-html-matchers (0.9.4)
nokogiri (~> 1)
rspec (>= 3.0.0.a, < 4)
rspec-mocks (3.10.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
@@ -201,6 +205,10 @@ GEM
rubocop (~> 1.0)
rubocop-ast (>= 1.1.0)
ruby-progressbar (1.11.0)
simplecov (0.18.5)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov-html (0.12.3)
sprockets (4.0.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
@@ -238,9 +246,11 @@ DEPENDENCIES
rails
rake (~> 13.0)
rspec (~> 3.0)
rspec-html-matchers
rubocop
rubocop-performance
rubocop-rspec
simplecov
sqlite3
view_component
view_component-form!
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,14 @@

**ViewComponent::Form** provides a `FormBuilder` with the same interface as [`ActionView::Helpers::FormBuilder`](https://api.rubyonrails.org/classes/ActionView/Helpers/FormBuilder.html), but using [ViewComponent](https://github.com/github/view_component)s for rendering the fields. It's a starting point for writing your own custom ViewComponents.

:warning: **This is an early release: the API is subject to change until we reach `v1.0.0`.**

## Compatibility

This gem is tested on:
- Rails 6.0+
- Ruby 2.7+

## Installation

Add this line to your application's Gemfile:
@@ -83,7 +91,7 @@ This allows you to pick the namespace your components will be loaded from.
# lib/custom_form_builder.rb
class CustomFormBuilder < ViewComponent::Form::Builder
# Set the namespace you want to use for your own components
self.components_namespace = "Form"
namespace Form
end
```

@@ -99,7 +107,7 @@ bin/rails generate vcf:builder AnotherCustomFormBuilder --namespace Forms::Compo
# app/forms/another_custom_form_builder.rb
class AnotherCustomFormBuilder < ViewComponent::Form::Builder
# Set the namespace you want to use for your own components
self.components_namespace = "Forms::Components"
namespace Forms::Components
end
```

@@ -130,8 +138,6 @@ You can then customize the behavior of your `Form::TextFieldComponent`:

module Form
class TextFieldComponent < ViewComponent::Form::TextFieldComponent
self.tag_klass = ActionView::Helpers::Tags::TextField

def html_class
class_names("text-field", "border-error": method_errors?)
end
2 changes: 1 addition & 1 deletion app/components/view_component/form/field_component.rb
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@ def value

def object_method_names
@object_method_names ||= begin
object_method_names = [method_name]
object_method_names = [method_name.to_sym]
if method_name.end_with?("_id") && object.respond_to?(singular_association_method_name)
object_method_names << singular_association_method_name
elsif method_name.end_with?("_ids") && object.respond_to?(collection_association_method_name)
28 changes: 28 additions & 0 deletions bin/release
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

VERSION=$1

if [[ -z "$VERSION" ]]; then
echo "Version should be specified. Example: bin/release v1.0.0"
exit 1
fi

printf "# frozen_string_literal: true\n\nmodule ViewComponent\n module Form\n VERSION = \"$VERSION\"\n end\nend\n" > ./lib/view_component/form/version.rb
bundle
$EDITOR CHANGELOG.md
git add Gemfile.lock lib/view_component/form/version.rb CHANGELOG.md
git commit -m "Bump version for $VERSION"

read -p "Are you sure you want to publish this release? " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1
fi

git push
git tag v$VERSION
git push --tags
gem build view_component-form.gemspec
gem push "view_component-form-$VERSION.gem" --host https://rubygems.org
rm "view_component-form-$VERSION.gem"
29 changes: 29 additions & 0 deletions bin/rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'rspec' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)

bundle_binstub = File.expand_path("../bundle", __FILE__)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end

require "rubygems"
require "bundler/setup"

load Gem.bin_path("rspec-core", "rspec")
2 changes: 2 additions & 0 deletions config.ru
Original file line number Diff line number Diff line change
@@ -8,6 +8,8 @@ require "bundler"
Bundler.require(:default, :development)

Combustion.initialize! :all do
config.load_defaults Rails.gem_version.segments[0..1].join("."

config.logger = ActiveSupport::TaggedLogging.new(Logger.new(nil))
config.log_level = :fatal

6 changes: 3 additions & 3 deletions gemfiles/rails_6.0.x.gemfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# frozen_string_literal: true

# This file was generated by Appraisal

source "https://rubygems.org"

gem "appraisal", require: false
gem "capybara", require: false
gem "combustion"
gem "rails", "~> 6.0.0"
gem "rake", "~> 13.0"
gem "rspec", "~> 3.0", require: false
gem "rspec-html-matchers"
gem "rubocop", require: false
gem "rubocop-performance", require: false
gem "rubocop-rspec", require: false
gem "simplecov", require: false, group: :test
gem "rails", "~> 6.0.0"

gemspec path: "../"
6 changes: 3 additions & 3 deletions gemfiles/rails_6.1.x.gemfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# frozen_string_literal: true

# This file was generated by Appraisal

source "https://rubygems.org"

gem "appraisal", require: false
gem "capybara", require: false
gem "combustion"
gem "rails", "~> 6.1.0"
gem "rake", "~> 13.0"
gem "rspec", "~> 3.0", require: false
gem "rspec-html-matchers"
gem "rubocop", require: false
gem "rubocop-performance", require: false
gem "rubocop-rspec", require: false
gem "simplecov", require: false, group: :test
gem "rails", "~> 6.1.0"

gemspec path: "../"
17 changes: 17 additions & 0 deletions gemfiles/rails_head.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "appraisal", require: false
gem "capybara", require: false
gem "combustion"
gem "rake", "~> 13.0"
gem "rspec", "~> 3.0", require: false
gem "rspec-html-matchers"
gem "rubocop", require: false
gem "rubocop-performance", require: false
gem "rubocop-rspec", require: false
gem "simplecov", require: false, group: :test
gem "rails", github: "rails/rails", branch: "main"

gemspec path: "../"
2 changes: 1 addition & 1 deletion lib/generators/vcf/builder/templates/builder.rb.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class <%= class_name %> < ViewComponent::Form::Builder
# Set the namespace you want to use for your own components
self.components_namespace = "<%= components_namespace %>"
namespace "<%= components_namespace %>"
end
Loading