Skip to content

Commit

Permalink
adding support for rich_text_area
Browse files Browse the repository at this point in the history
  • Loading branch information
GBH committed Dec 1, 2019
1 parent 1f92834 commit c3c61fc
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 16 deletions.
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem "listen", ">= 3.0.5", "< 3.2"
gem "web-console", ">= 3.3.0"

gem "sassc-rails"
gem "webpacker"
gem "rubocop", "0.70.0", require: false
end

Expand Down
2 changes: 1 addition & 1 deletion demo/app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class User < ActiveRecord::Base

has_rich_text :rich_content
end
1 change: 1 addition & 0 deletions demo/app/views/bootstrap/form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<%= form.date_select :date %>
<%= form.datetime_select :datetime %>
<%= form.time_select :time %>
<%= form.rich_text_area :rich_content, bootstrap: {label: "ActiveText Input", help: "Help Text"} %>
<%= form.check_box :terms, bootstrap: {label: {text: "I agree to Terms and Conditions"}, help: "By clicking Agree you're also acknowledging that Apple may sew your mouth to a ... "} %>
<%= form.primary "Press to Register" do %>
<a href="/" class="btn btn-link">Maybe Later</a>
Expand Down
3 changes: 3 additions & 0 deletions demo/app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
</style>

<title>Hello, world!</title>

<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
<%= csrf_meta_tags %>
</head>

Expand Down
2 changes: 1 addition & 1 deletion lib/comfy_bootstrap_form/form_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class FormBuilder < ActionView::Helpers::FormBuilder
FIELD_HELPERS = %w[
color_field date_field datetime_field email_field month_field
password_field phone_field range_field search_field text_area
text_field time_field url_field week_field
text_field rich_text_area time_field url_field week_field
].freeze

DATE_SELECT_HELPERS = %w[
Expand Down
19 changes: 19 additions & 0 deletions test/comfy_bootstrap_form/fields_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

class FieldsTest < ActionView::TestCase

include ActionText::TagHelper

setup do
@user = User.new
@builder = ComfyBootstrapForm::FormBuilder.new(:user, @user, self, {})
Expand Down Expand Up @@ -280,6 +282,23 @@ def test_text_area
assert_xml_equal expected, actual
end

def test_rich_text_area
actual = @builder.rich_text_area(:rich_content)
expected = <<-HTML
<div class="form-group">
<label for="user_rich_content">Rich content</label>
<input id="user_rich_content_trix_input_user" name="user[rich_content]" type="hidden"/>
<trix-editor class="form-control"
data-blob-url-template="http://test.host/rails/active_storage/blobs/:signed_id/:filename"
data-direct-upload-url="http://test.host/rails/active_storage/direct_uploads"
id="user_rich_content"
input="user_rich_content_trix_input_user"
/>
</div>
HTML
assert_xml_equal expected, actual
end

def test_time_field
actual = @builder.time_field(:test)
expected = <<-HTML
Expand Down
32 changes: 20 additions & 12 deletions test/comfy_bootstrap_form/view_helpers_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,21 @@ class ViewHelpersTest < ActionView::TestCase

include ComfyBootstrapForm::ViewHelper

# Rails 6 doesn't use utf8 input anymore
def utf8_input
return if Rails.version > "5.2"
<<~HTML
<input name="utf8" type="hidden" value="&#x2713;" />
HTML
end

def test_bootstrap_form_with
skip if Rails.version < "5.1"

actual = bootstrap_form_with(url: "/test") {}
expected = <<-HTML
<form action="/test" accept-charset="UTF-8" data-remote="true" method="post">
<input name="utf8" type="hidden" value="&#x2713;" />
#{utf8_input}
</form>
HTML
assert_xml_equal expected, actual
Expand All @@ -34,7 +42,7 @@ def test_bootstrap_form_with_and_field

expected = <<-HTML
<form accept-charset="UTF-8" action="/test" data-remote="true" method="post">
<input name="utf8" type="hidden" value="&#x2713;"/>
#{utf8_input}
<div class="form-group">
<label for="value">Value</label>
#{input}
Expand All @@ -60,7 +68,7 @@ def test_bootstrap_form_with_horizontal

expected = <<-HTML
<form accept-charset="UTF-8" action="/test" data-remote="true" method="post">
<input name="utf8" type="hidden" value="&#x2713;"/>
#{utf8_input}
<div class="form-group row">
<label class="col-form-label col-sm-2 text-sm-right" for="value">Value</label>
<div class="col-sm-10">
Expand All @@ -81,7 +89,7 @@ def test_bootstrap_form_with_inline
end
expected = <<-HTML
<form accept-charset="UTF-8" action="/test" class="form-inline" data-remote="true" method="post">
<input name="utf8" type="hidden" value="&#x2713;"/>
#{utf8_input}
<div class="form-group">
<input class="btn" data-disable-with="Save " name="commit" type="submit" value="Save "/>
</div>
Expand All @@ -108,7 +116,7 @@ def test_bootstrap_form_with_supress_field_errors

expected = <<-HTML
<form accept-charset="UTF-8" action="/test" data-remote="true" method="post">
<input name="utf8" type="hidden" value="&#x2713;"/>
#{utf8_input}
<div class="form-group">
<label for="user_test">Test</label>
#{input}
Expand All @@ -135,7 +143,7 @@ def test_bootstrap_form_with_builder_override

expected = <<-HTML
<form accept-charset="UTF-8" action="/test" data-remote="true" method="post">
<input name="utf8" type="hidden" value="&#x2713;"/>
#{utf8_input}
#{input}
</form>
HTML
Expand All @@ -146,7 +154,7 @@ def test_bootstrap_form_for
actual = bootstrap_form_for(User.new) {}
expected = <<-HTML
<form action="/users" class="new_user" id="new_user" accept-charset="UTF-8" method="post">
<input name="utf8" type="hidden" value="&#x2713;" />
#{utf8_input}
</form>
HTML
assert_xml_equal expected, actual
Expand All @@ -158,7 +166,7 @@ def test_bootstrap_form_for_and_field
end
expected = <<-HTML
<form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post">
<input name="utf8" type="hidden" value="&#x2713;"/>
#{utf8_input}
<div class="form-group">
<label for="user_email">Email</label>
<input class="form-control" id="user_email" name="user[email]" type="email"/>
Expand All @@ -174,7 +182,7 @@ def test_bootstrap_form_for_horizontal
end
expected = <<-HTML
<form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post">
<input name="utf8" type="hidden" value="&#x2713;"/>
#{utf8_input}
<div class="form-group row">
<label class="col-form-label col-sm-2 text-sm-right" for="user_email">Email</label>
<div class="col-sm-10">
Expand All @@ -192,7 +200,7 @@ def test_bootstrap_form_for_inline
end
expected = <<-HTML
<form accept-charset="UTF-8" action="/users" class="form-inline" id="new_user" method="post">
<input name="utf8" type="hidden" value="&#x2713;"/>
#{utf8_input}
<div class="form-group mr-sm-2">
<label class="mr-sm-2" for="user_email">Email</label>
<input class="form-control" id="user_email" name="user[email]" type="email"/>
Expand All @@ -210,7 +218,7 @@ def test_bootstrap_form_for_supress_field_errors
end
expected = <<-HTML
<form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post">
<input name="utf8" type="hidden" value="&#x2713;"/>
#{utf8_input}
<div class="form-group">
<label for="user_email">Email</label>
<input class="form-control is-invalid" id="user_email" name="user[email]" type="email"/>
Expand All @@ -227,7 +235,7 @@ def test_bootstrap_form_for_builder_override
end
expected = <<-HTML
<form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post">
<input name="utf8" type="hidden" value="&#x2713;"/>
#{utf8_input}
<input id="user_email" name="user[email]" type="email"/>
</form>
HTML
Expand Down
2 changes: 1 addition & 1 deletion test/gemfiles/6.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ source "http://rubygems.org"

gemspec path: "../../"

gem "rails", "~> 5.2.2"
gem "rails", "~> 6.0.0"

group :test do
gem "coveralls", require: false
Expand Down

0 comments on commit c3c61fc

Please sign in to comment.