diff --git a/README.md b/README.md index b01cb8bbf3..715c60e9c2 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Active Text +# Action Text πŸ€Έβ€β™‚οΈπŸ’°πŸ“ @@ -10,7 +10,7 @@ Assumes a Rails 5.2+ application with Active Storage and Webpacker installed. ```ruby # Gemfile - gem "activetext", github: "basecamp/activetext", require: "active_text" + gem "activetext", github: "basecamp/activetext", require: "action_text" gem "mini_magick" # for Active Storage variants ``` @@ -32,7 +32,7 @@ Assumes a Rails 5.2+ application with Active Storage and Webpacker installed. import "activetext" ``` -1. Declare text columns as Active Text attributes: +1. Declare text columns as Action Text attributes: ```ruby # app/models/message.rb diff --git a/Rakefile b/Rakefile index f6c2a1304c..fdcbee9c15 100644 --- a/Rakefile +++ b/Rakefile @@ -8,7 +8,7 @@ require 'rdoc/task' RDoc::Task.new(:rdoc) do |rdoc| rdoc.rdoc_dir = 'rdoc' - rdoc.title = 'Active Text' + rdoc.title = 'Action Text' rdoc.options << '--line-numbers' rdoc.rdoc_files.include('README.md') rdoc.rdoc_files.include('lib/**/*.rb') diff --git a/activetext.gemspec b/actiontext.gemspec similarity index 92% rename from activetext.gemspec rename to actiontext.gemspec index 37fe805279..8139154e74 100644 --- a/activetext.gemspec +++ b/actiontext.gemspec @@ -1,12 +1,12 @@ $:.push File.expand_path("lib", __dir__) # Maintain your gem's version: -require "active_text/version" +require "action_text/version" # Describe your gem and declare its dependencies: Gem::Specification.new do |s| s.name = "activetext" - s.version = ActiveText::VERSION + s.version = ActionText::VERSION s.authors = ["Javan Makhmali", "Sam Stephenson"] s.email = ["javan@javan.us", "sstephenson@gmail.com"] s.summary = "Edit and display rich text in Rails applications" diff --git a/app/helpers/active_text/tag_helper.rb b/app/helpers/action_text/tag_helper.rb similarity index 87% rename from app/helpers/active_text/tag_helper.rb rename to app/helpers/action_text/tag_helper.rb index 1b97621dac..bd2727bca6 100644 --- a/app/helpers/active_text/tag_helper.rb +++ b/app/helpers/action_text/tag_helper.rb @@ -1,11 +1,11 @@ -module ActiveText +module ActionText module TagHelper cattr_accessor(:id, instance_accessor: false) { 0 } def rich_text_field_tag(name, value = nil, options = {}) options = options.symbolize_keys - options[:input] ||= "trix_input_#{ActiveText::TagHelper.id += 1}" + options[:input] ||= "trix_input_#{ActionText::TagHelper.id += 1}" options[:data] ||= {} options[:data][:direct_upload_url] = rails_direct_uploads_url options[:data][:blob_url_template] = rails_service_blob_url(":signed_id", ":filename") @@ -19,7 +19,7 @@ module ActiveText end module ActionView::Helpers - class Tags::ActiveText < Tags::Base + class Tags::ActionText < Tags::Base delegate :dom_id, to: ActionView::RecordIdentifier def render @@ -36,7 +36,7 @@ module ActionView::Helpers module FormHelper def rich_text_field(object_name, method, options = {}) - Tags::ActiveText.new(object_name, method, self, options).render + Tags::ActionText.new(object_name, method, self, options).render end end diff --git a/app/javascript/activetext/attachment_upload.js b/app/javascript/actiontext/attachment_upload.js similarity index 100% rename from app/javascript/activetext/attachment_upload.js rename to app/javascript/actiontext/attachment_upload.js diff --git a/app/javascript/activetext/index.js b/app/javascript/actiontext/index.js similarity index 100% rename from app/javascript/activetext/index.js rename to app/javascript/actiontext/index.js diff --git a/lib/active_text.rb b/lib/action_text.rb similarity index 93% rename from lib/active_text.rb rename to lib/action_text.rb index 8275d7d17a..0559dce2ba 100644 --- a/lib/active_text.rb +++ b/lib/action_text.rb @@ -1,8 +1,8 @@ require "active_record" -require "active_text/engine" +require "action_text/engine" require "nokogiri" -module ActiveText +module ActionText extend ActiveSupport::Autoload mattr_accessor(:renderer) diff --git a/lib/active_text/attachable.rb b/lib/action_text/attachable.rb similarity index 84% rename from lib/active_text/attachable.rb rename to lib/action_text/attachable.rb index f3ea47282f..83a6cf0c17 100644 --- a/lib/active_text/attachable.rb +++ b/lib/action_text/attachable.rb @@ -1,4 +1,4 @@ -module ActiveText +module ActionText module Attachable extend ActiveSupport::Concern @@ -8,12 +8,12 @@ module ActiveText def from_node(node) if attachable = attachable_from_sgid(node["sgid"]) attachable - elsif attachable = ActiveText::Attachables::ContentAttachment.from_node(node) + elsif attachable = ActionText::Attachables::ContentAttachment.from_node(node) attachable - elsif attachable = ActiveText::Attachables::RemoteImage.from_node(node) + elsif attachable = ActionText::Attachables::RemoteImage.from_node(node) attachable else - ActiveText::Attachables::MissingAttachable + ActionText::Attachables::MissingAttachable end end @@ -33,7 +33,7 @@ module ActiveText class_methods do def from_attachable_sgid(sgid) - ActiveText::Attachable.from_attachable_sgid(sgid, only: self) + ActionText::Attachable.from_attachable_sgid(sgid, only: self) end end diff --git a/lib/active_text/attachables/content_attachment.rb b/lib/action_text/attachables/content_attachment.rb similarity index 84% rename from lib/active_text/attachables/content_attachment.rb rename to lib/action_text/attachables/content_attachment.rb index 316d7e304a..3ebd734786 100644 --- a/lib/active_text/attachables/content_attachment.rb +++ b/lib/action_text/attachables/content_attachment.rb @@ -1,4 +1,4 @@ -module ActiveText +module ActionText module Attachables class ContentAttachment include ActiveModel::Model @@ -25,11 +25,11 @@ module ActiveText end def to_partial_path - "active_text/attachables/content_attachment" + "action_text/attachables/content_attachment" end def to_trix_content_attachment_partial_path - "active_text/attachables/content_attachments/#{name.underscore}" + "action_text/attachables/content_attachments/#{name.underscore}" end end end diff --git a/lib/active_text/attachables/missing_attachable.rb b/lib/action_text/attachables/missing_attachable.rb similarity index 66% rename from lib/active_text/attachables/missing_attachable.rb rename to lib/action_text/attachables/missing_attachable.rb index 94a095ce09..54b36d3cce 100644 --- a/lib/active_text/attachables/missing_attachable.rb +++ b/lib/action_text/attachables/missing_attachable.rb @@ -1,10 +1,10 @@ -module ActiveText +module ActionText module Attachables module MissingAttachable extend ActiveModel::Naming def self.to_partial_path - "active_text/attachables/missing_attachable" + "action_text/attachables/missing_attachable" end end end diff --git a/lib/active_text/attachables/remote_image.rb b/lib/action_text/attachables/remote_image.rb similarity index 94% rename from lib/active_text/attachables/remote_image.rb rename to lib/action_text/attachables/remote_image.rb index 0624b5564d..2333427371 100644 --- a/lib/active_text/attachables/remote_image.rb +++ b/lib/action_text/attachables/remote_image.rb @@ -1,4 +1,4 @@ -module ActiveText +module ActionText module Attachables class RemoteImage extend ActiveModel::Naming @@ -37,7 +37,7 @@ module ActiveText end def to_partial_path - "active_text/attachables/remote_image" + "action_text/attachables/remote_image" end end end diff --git a/lib/active_text/attachment.rb b/lib/action_text/attachment.rb similarity index 94% rename from lib/active_text/attachment.rb rename to lib/action_text/attachment.rb index fab6c3507b..2129a3985b 100644 --- a/lib/active_text/attachment.rb +++ b/lib/action_text/attachment.rb @@ -1,4 +1,4 @@ -module ActiveText +module ActionText class Attachment include Attachments::TrixConversion, Attachments::Minification, Attachments::Caching @@ -12,7 +12,7 @@ module ActiveText end def from_node(node, attachable = nil) - new(node, attachable || ActiveText::Attachable.from_node(node)) + new(node, attachable || ActionText::Attachable.from_node(node)) end def from_attachables(attachables) @@ -34,7 +34,7 @@ module ActiveText private def node_from_attributes(attributes) if attributes = process_attributes(attributes).presence - ActiveText::HtmlConversion.create_element(TAG_NAME, attributes) + ActionText::HtmlConversion.create_element(TAG_NAME, attributes) end end diff --git a/lib/active_text/attachments/caching.rb b/lib/action_text/attachments/caching.rb similarity index 93% rename from lib/active_text/attachments/caching.rb rename to lib/action_text/attachments/caching.rb index b0194170e1..b867e2ff91 100644 --- a/lib/active_text/attachments/caching.rb +++ b/lib/action_text/attachments/caching.rb @@ -1,4 +1,4 @@ -module ActiveText +module ActionText module Attachments module Caching def cache_key(*args) diff --git a/lib/active_text/attachments/minification.rb b/lib/action_text/attachments/minification.rb similarity index 77% rename from lib/active_text/attachments/minification.rb rename to lib/action_text/attachments/minification.rb index aa25875aae..b1ca43b7b8 100644 --- a/lib/active_text/attachments/minification.rb +++ b/lib/action_text/attachments/minification.rb @@ -1,11 +1,11 @@ -module ActiveText +module ActionText module Attachments module Minification extend ActiveSupport::Concern class_methods do def fragment_by_minifying_attachments(content) - Fragment.wrap(content).replace(ActiveText::Attachment::SELECTOR) do |node| + Fragment.wrap(content).replace(ActionText::Attachment::SELECTOR) do |node| node.tap { |n| n.inner_html = "" } end end diff --git a/lib/active_text/attachments/trix_conversion.rb b/lib/action_text/attachments/trix_conversion.rb similarity index 91% rename from lib/active_text/attachments/trix_conversion.rb rename to lib/action_text/attachments/trix_conversion.rb index 3eb83453f4..39989ce644 100644 --- a/lib/active_text/attachments/trix_conversion.rb +++ b/lib/action_text/attachments/trix_conversion.rb @@ -1,4 +1,4 @@ -module ActiveText +module ActionText module Attachments module TrixConversion extend ActiveSupport::Concern @@ -24,7 +24,7 @@ module ActiveText private def trix_attachment_content if partial_path = attachable.try(:to_trix_content_attachment_partial_path) - ActiveText.renderer.render(partial: partial_path, object: self, as: model_name.element) + ActionText.renderer.render(partial: partial_path, object: self, as: model_name.element) end end end diff --git a/lib/active_text/attribute.rb b/lib/action_text/attribute.rb similarity index 83% rename from lib/active_text/attribute.rb rename to lib/action_text/attribute.rb index 9f3ee49998..32dd1d0e3f 100644 --- a/lib/active_text/attribute.rb +++ b/lib/action_text/attribute.rb @@ -1,10 +1,10 @@ -module ActiveText +module ActionText module Attribute extend ActiveSupport::Concern class_methods do def has_rich_text(attribute_name) - serialize(attribute_name, ActiveText::Content) + serialize(attribute_name, ActionText::Content) has_many_attached "#{attribute_name}_attachments" diff --git a/lib/active_text/content.rb b/lib/action_text/content.rb similarity index 78% rename from lib/active_text/content.rb rename to lib/action_text/content.rb index 0e97374ded..c63e0c3525 100644 --- a/lib/active_text/content.rb +++ b/lib/action_text/content.rb @@ -1,4 +1,4 @@ -module ActiveText +module ActionText class Content include Serialization @@ -7,7 +7,7 @@ module ActiveText delegate :blank?, :empty?, :html_safe, :present?, to: :to_s def initialize(content = nil) - @fragment = ActiveText::Attachment.fragment_by_canonicalizing_attachments(content) + @fragment = ActionText::Attachment.fragment_by_canonicalizing_attachments(content) end def links @@ -22,17 +22,17 @@ module ActiveText def attachables @attachables ||= attachment_nodes.map do |node| - ActiveText::Attachable.from_node(node) + ActionText::Attachable.from_node(node) end end def append_attachables(attachables) - attachments = ActiveText::Attachment.from_attachables(attachables) + attachments = ActionText::Attachment.from_attachables(attachables) self.class.new([self.to_s.presence, *attachments].compact.join("\n")) end def render_attachments(**options, &block) - fragment.replace(ActiveText::Attachment::SELECTOR) do |node| + fragment.replace(ActionText::Attachment::SELECTOR) do |node| block.call(attachment_for_node(node, **options)) end end @@ -48,7 +48,7 @@ module ActiveText def to_html render_attachments do |attachment| attachment.node.tap do |node| - node.inner_html = ActiveText.renderer.render(attachment) + node.inner_html = ActionText.renderer.render(attachment) end end.to_html end @@ -73,11 +73,11 @@ module ActiveText private def attachment_nodes - @attachment_nodes ||= fragment.find_all(ActiveText::Attachment::SELECTOR) + @attachment_nodes ||= fragment.find_all(ActionText::Attachment::SELECTOR) end def attachment_for_node(node, with_full_attributes: true) - attachment = ActiveText::Attachment.from_node(node) + attachment = ActionText::Attachment.from_node(node) with_full_attributes ? attachment.with_full_attributes : attachment end end diff --git a/lib/active_text/engine.rb b/lib/action_text/engine.rb similarity index 53% rename from lib/active_text/engine.rb rename to lib/action_text/engine.rb index aac0c57881..71db6d6a26 100644 --- a/lib/active_text/engine.rb +++ b/lib/action_text/engine.rb @@ -1,21 +1,21 @@ require "rails/engine" -module ActiveText +module ActionText class Engine < Rails::Engine - isolate_namespace ActiveText - config.eager_load_namespaces << ActiveText + isolate_namespace ActionText + config.eager_load_namespaces << ActionText - initializer "active_text.attribute" do + initializer "action_text.attribute" do ActiveSupport.on_load(:active_record) do - include ActiveText::Attribute + include ActionText::Attribute end end - initializer "active_text.active_storage_extension" do + initializer "action_text.active_storage_extension" do require "active_storage/blob" class ActiveStorage::Blob - include ActiveText::Attachable + include ActionText::Attachable def previewable_attachable? representable? @@ -23,21 +23,21 @@ module ActiveText end end - initializer "active_text.helper" do + initializer "action_text.helper" do ActiveSupport.on_load(:action_controller_base) do - helper ActiveText::TagHelper + helper ActionText::TagHelper end end - initializer "active_text.config" do + initializer "action_text.config" do config.after_initialize do |app| - ActiveText.renderer ||= ApplicationController.renderer + ActionText.renderer ||= ApplicationController.renderer # FIXME: ApplicationController should have a per-request specific renderer - # that's been set with the request.env env, and ActiveText should just piggyback off + # that's been set with the request.env env, and ActionText should just piggyback off # that by default rather than doing this work directly. ApplicationController.before_action do - ActiveText.renderer = ActiveText.renderer.new(request.env) + ActionText.renderer = ActionText.renderer.new(request.env) end end end diff --git a/lib/active_text/fragment.rb b/lib/action_text/fragment.rb similarity index 92% rename from lib/active_text/fragment.rb rename to lib/action_text/fragment.rb index 9e0af6f57a..63b088f3e1 100644 --- a/lib/active_text/fragment.rb +++ b/lib/action_text/fragment.rb @@ -1,4 +1,4 @@ -module ActiveText +module ActionText class Fragment class << self def wrap(fragment_or_html) @@ -13,7 +13,7 @@ module ActiveText end def from_html(html) - new(ActiveText::HtmlConversion.fragment_for_html(html.to_s.strip)) + new(ActionText::HtmlConversion.fragment_for_html(html.to_s.strip)) end end diff --git a/lib/active_text/html_conversion.rb b/lib/action_text/html_conversion.rb similarity index 96% rename from lib/active_text/html_conversion.rb rename to lib/action_text/html_conversion.rb index 7c35e5cf94..1c70504fb7 100644 --- a/lib/active_text/html_conversion.rb +++ b/lib/action_text/html_conversion.rb @@ -1,4 +1,4 @@ -module ActiveText +module ActionText module HtmlConversion extend self diff --git a/lib/active_text/plain_text_conversion.rb b/lib/action_text/plain_text_conversion.rb similarity index 99% rename from lib/active_text/plain_text_conversion.rb rename to lib/action_text/plain_text_conversion.rb index ecd598e192..c9867bd8c9 100644 --- a/lib/active_text/plain_text_conversion.rb +++ b/lib/action_text/plain_text_conversion.rb @@ -1,4 +1,4 @@ -module ActiveText +module ActionText module PlainTextConversion extend self diff --git a/lib/active_text/serialization.rb b/lib/action_text/serialization.rb similarity index 96% rename from lib/active_text/serialization.rb rename to lib/action_text/serialization.rb index 46ebeba1aa..ac2b0602d5 100644 --- a/lib/active_text/serialization.rb +++ b/lib/action_text/serialization.rb @@ -1,4 +1,4 @@ -module ActiveText +module ActionText module Serialization extend ActiveSupport::Concern diff --git a/lib/active_text/trix_attachment.rb b/lib/action_text/trix_attachment.rb similarity index 94% rename from lib/active_text/trix_attachment.rb rename to lib/action_text/trix_attachment.rb index 19add53414..717d130d12 100644 --- a/lib/active_text/trix_attachment.rb +++ b/lib/action_text/trix_attachment.rb @@ -1,4 +1,4 @@ -module ActiveText +module ActionText class TrixAttachment TAG_NAME = "figure" SELECTOR = "[data-trix-attachment]" @@ -19,7 +19,7 @@ module ActiveText trix_attachment_attributes = attributes.except("caption") trix_attributes = attributes.slice("caption") - node = ActiveText::HtmlConversion.create_element(TAG_NAME) + node = ActionText::HtmlConversion.create_element(TAG_NAME) node["data-trix-attachment"] = JSON.generate(trix_attachment_attributes) node["data-trix-attributes"] = JSON.generate(trix_attributes) if trix_attributes.any? @@ -54,7 +54,7 @@ module ActiveText end def to_html - ActiveText::HtmlConversion.node_to_html(node) + ActionText::HtmlConversion.node_to_html(node) end def to_s diff --git a/lib/active_text/version.rb b/lib/action_text/version.rb similarity index 57% rename from lib/active_text/version.rb rename to lib/action_text/version.rb index 29b47f7eab..bc34656697 100644 --- a/lib/active_text/version.rb +++ b/lib/action_text/version.rb @@ -1,3 +1,3 @@ -module ActiveText +module ActionText VERSION = '0.1.0' end diff --git a/test/dummy/app/controllers/application_controller.rb b/test/dummy/app/controllers/application_controller.rb index baaa725746..c774981e25 100644 --- a/test/dummy/app/controllers/application_controller.rb +++ b/test/dummy/app/controllers/application_controller.rb @@ -1,8 +1,8 @@ class ApplicationController < ActionController::Base - before_action :set_active_text_renderer + before_action :set_action_text_renderer private - def set_active_text_renderer - ActiveText.renderer = self.class.renderer.new(request.env) + def set_action_text_renderer + ActionText.renderer = self.class.renderer.new(request.env) end end diff --git a/test/dummy/config/application.rb b/test/dummy/config/application.rb index 7f41fce8d0..ddee05a4db 100644 --- a/test/dummy/config/application.rb +++ b/test/dummy/config/application.rb @@ -3,7 +3,7 @@ require_relative 'boot' require 'rails/all' Bundler.require(*Rails.groups) -require "active_text" +require "action_text" module Dummy class Application < Rails::Application diff --git a/test/unit/content_test.rb b/test/unit/content_test.rb index 5299ae3f8f..e5773361e4 100644 --- a/test/unit/content_test.rb +++ b/test/unit/content_test.rb @@ -1,6 +1,6 @@ require_relative '../test_helper' -module ActiveText +module ActionText class ContentTest < ActiveSupport::TestCase test "plain text conversion" do message = Message.create!(subject: "Greetings", content: "

Hello world

")