aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2018-04-13 14:10:18 -0700
committerDavid Heinemeier Hansson <david@loudthinking.com>2018-04-13 14:10:18 -0700
commit491bee6e64863f2dc6e8d1f59829e61d4a8c86ad (patch)
treee5c536c6cd106685633d2e7d1fc67f2d8b95406c
parent7c4e70ea0bf0f00c0e919128447412fab49772f9 (diff)
downloadrails-491bee6e64863f2dc6e8d1f59829e61d4a8c86ad.tar.gz
rails-491bee6e64863f2dc6e8d1f59829e61d4a8c86ad.tar.bz2
rails-491bee6e64863f2dc6e8d1f59829e61d4a8c86ad.zip
Use rich_text instead of active_text
Just like we use has_many_attachments instead of active_storage_attachements.
-rw-r--r--README.md6
-rw-r--r--app/helpers/active_text/tag_helper.rb10
-rw-r--r--lib/active_text/attachable.rb2
-rw-r--r--lib/active_text/attachment.rb4
-rw-r--r--lib/active_text/attribute.rb2
-rw-r--r--test/dummy/app/models/message.rb2
-rw-r--r--test/dummy/app/views/messages/_form.html.erb2
7 files changed, 14 insertions, 14 deletions
diff --git a/README.md b/README.md
index 8a21ed843b..b01cb8bbf3 100644
--- a/README.md
+++ b/README.md
@@ -37,11 +37,11 @@ Assumes a Rails 5.2+ application with Active Storage and Webpacker installed.
```ruby
# app/models/message.rb
class Message < ActiveRecord::Base
- active_text_attribute :content
+ has_rich_text :content
end
```
-1. Replace form `text_area`s with `active_text_field`s:
+1. Replace form `text_area`s with `rich_text_field`s:
```erb
<%# app/views/messages/_form.html.erb %>
@@ -49,7 +49,7 @@ Assumes a Rails 5.2+ application with Active Storage and Webpacker installed.
<div class="field">
<%= form.label :content %>
- <%= form.active_text_field :content %>
+ <%= form.rich_text_field :content %>
</div>
<% end %>
diff --git a/app/helpers/active_text/tag_helper.rb b/app/helpers/active_text/tag_helper.rb
index 590ff93fd5..1b97621dac 100644
--- a/app/helpers/active_text/tag_helper.rb
+++ b/app/helpers/active_text/tag_helper.rb
@@ -2,7 +2,7 @@ module ActiveText
module TagHelper
cattr_accessor(:id, instance_accessor: false) { 0 }
- def active_text_field_tag(name, value = nil, options = {})
+ def rich_text_field_tag(name, value = nil, options = {})
options = options.symbolize_keys
options[:input] ||= "trix_input_#{ActiveText::TagHelper.id += 1}"
@@ -26,7 +26,7 @@ module ActionView::Helpers
options = @options.stringify_keys
add_default_name_and_id(options)
options["input"] ||= dom_id(object, [options["id"], :trix_input].compact.join("_"))
- @template_object.active_text_field_tag(options.delete("name"), editable_value, options)
+ @template_object.rich_text_field_tag(options.delete("name"), editable_value, options)
end
def editable_value
@@ -35,14 +35,14 @@ module ActionView::Helpers
end
module FormHelper
- def active_text_field(object_name, method, options = {})
+ def rich_text_field(object_name, method, options = {})
Tags::ActiveText.new(object_name, method, self, options).render
end
end
class FormBuilder
- def active_text_field(method, options = {})
- @template.active_text_field(@object_name, method, objectify_options(options))
+ def rich_text_field(method, options = {})
+ @template.rich_text_field(@object_name, method, objectify_options(options))
end
end
end
diff --git a/lib/active_text/attachable.rb b/lib/active_text/attachable.rb
index 3a6648331e..f3ea47282f 100644
--- a/lib/active_text/attachable.rb
+++ b/lib/active_text/attachable.rb
@@ -53,7 +53,7 @@ module ActiveText
super.merge(attachable_sgid: attachable_sgid)
end
- def to_active_text_attributes(attributes = {})
+ def to_rich_text_attributes(attributes = {})
attributes.dup.tap do |attributes|
attributes[:sgid] = attachable_sgid
attributes[:content_type] = attachable_content_type
diff --git a/lib/active_text/attachment.rb b/lib/active_text/attachment.rb
index 870390f63e..fab6c3507b 100644
--- a/lib/active_text/attachment.rb
+++ b/lib/active_text/attachment.rb
@@ -20,7 +20,7 @@ module ActiveText
end
def from_attachable(attachable, attributes = {})
- if node = node_from_attributes(attachable.to_active_text_attributes(attributes))
+ if node = node_from_attributes(attachable.to_rich_text_attributes(attributes))
new(node, attachable)
end
end
@@ -91,7 +91,7 @@ module ActiveText
end
def attachable_attributes
- @attachable_attributes ||= (attachable.try(:to_active_text_attributes) || {}).stringify_keys
+ @attachable_attributes ||= (attachable.try(:to_rich_text_attributes) || {}).stringify_keys
end
def sgid_attributes
diff --git a/lib/active_text/attribute.rb b/lib/active_text/attribute.rb
index 9d872a87a1..9f3ee49998 100644
--- a/lib/active_text/attribute.rb
+++ b/lib/active_text/attribute.rb
@@ -3,7 +3,7 @@ module ActiveText
extend ActiveSupport::Concern
class_methods do
- def active_text_attribute(attribute_name)
+ def has_rich_text(attribute_name)
serialize(attribute_name, ActiveText::Content)
has_many_attached "#{attribute_name}_attachments"
diff --git a/test/dummy/app/models/message.rb b/test/dummy/app/models/message.rb
index bb0ae59ad7..db63a1fe3f 100644
--- a/test/dummy/app/models/message.rb
+++ b/test/dummy/app/models/message.rb
@@ -1,3 +1,3 @@
class Message < ApplicationRecord
- active_text_attribute :content
+ has_rich_text :content
end
diff --git a/test/dummy/app/views/messages/_form.html.erb b/test/dummy/app/views/messages/_form.html.erb
index c8edcb78e5..bd5f0bea4a 100644
--- a/test/dummy/app/views/messages/_form.html.erb
+++ b/test/dummy/app/views/messages/_form.html.erb
@@ -18,7 +18,7 @@
<div class="field">
<%= form.label :content %>
- <%= form.active_text_field :content, class: "trix-content" %>
+ <%= form.rich_text_field :content, class: "trix-content" %>
</div>
<div class="actions">