From b34f8fbe3d547476da62aa1a2a0059f4ce8a9deb Mon Sep 17 00:00:00 2001 From: Mathieu Magnin <mathieu.magnin@gmail.com> Date: Tue, 9 Apr 2019 15:44:36 +0200 Subject: [PATCH] Add ActionText --- Gemfile | 1 + Gemfile.lock | 10 ++++++ .../stylesheets/new_design/actiontext.scss | 36 +++++++++++++++++++ app/views/active_storage/blobs/_blob.html.erb | 14 ++++++++ config/initializers/assets.rb | 2 +- ...6_create_action_text_tables.action_text.rb | 15 ++++++++ db/schema.rb | 10 ++++++ 7 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 app/assets/stylesheets/new_design/actiontext.scss create mode 100644 app/views/active_storage/blobs/_blob.html.erb create mode 100644 db/migrate/20190409132006_create_action_text_tables.action_text.rb diff --git a/Gemfile b/Gemfile index 3842e381e..be3d60fb6 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,7 @@ source 'https://rubygems.org' gem 'aasm' +gem 'actiontext', github: 'kobaltz/actiontext', branch: 'archive', require: 'action_text' gem 'active_link_to' # Automatically set a class on active links gem 'active_model_serializers' gem 'activestorage-openstack', git: 'https://github.com/fredZen/activestorage-openstack.git', branch: 'frederic/fix_upload_signature' diff --git a/Gemfile.lock b/Gemfile.lock index e29bc5849..4e80820c2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,12 @@ +GIT + remote: git://github.com/kobaltz/actiontext.git + revision: ef59c4ba99d1b7614dd47f5a294eef553224db88 + branch: archive + specs: + actiontext (0.1.0) + nokogiri + rails (>= 5.2.0) + GIT remote: https://github.com/fredZen/activestorage-openstack.git revision: c71d5107a51701eab9d9267dd0000e6c1cf3e39a @@ -669,6 +678,7 @@ PLATFORMS DEPENDENCIES aasm + actiontext! active_link_to active_model_serializers activestorage-openstack! diff --git a/app/assets/stylesheets/new_design/actiontext.scss b/app/assets/stylesheets/new_design/actiontext.scss new file mode 100644 index 000000000..b4560ecae --- /dev/null +++ b/app/assets/stylesheets/new_design/actiontext.scss @@ -0,0 +1,36 @@ +// +// Provides a drop-in pointer for the default Trix stylesheet that will format the toolbar and +// the trix-editor content (whether displayed or under editing). Feel free to incorporate this +// inclusion directly in any other asset bundle and remove this file. +// +// = require trix + +// We need to override trix.css’s image gallery styles to accommodate the +// <action-text-attachment> element we wrap around attachments. Otherwise, +// images in galleries will be squished by the max-width: 33%; rule. +.trix-content { + .attachment-gallery { + > action-text-attachment, + > .attachment { + flex: 1 0 33%; + padding: 0 0.5em; + max-width: 33%; + } + + &.attachment-gallery--2, + &.attachment-gallery--4 { + > action-text-attachment, + > .attachment { + flex-basis: 50%; + max-width: 50%; + } + } + } + + action-text-attachment { + .attachment { + padding: 0 !important; + max-width: 100% !important; + } + } +} diff --git a/app/views/active_storage/blobs/_blob.html.erb b/app/views/active_storage/blobs/_blob.html.erb new file mode 100644 index 000000000..049f57e80 --- /dev/null +++ b/app/views/active_storage/blobs/_blob.html.erb @@ -0,0 +1,14 @@ +<figure class="attachment attachment--<%= blob.representable? ? "preview" : "file" %> attachment--<%= blob.filename.extension %>"> + <% if blob.representable? %> + <%= image_tag blob.representation(resize_to_fit: local_assigns[:in_gallery] ? [ 800, 600 ] : [ 1024, 768 ]) %> + <% end %> + + <figcaption class="attachment__caption"> + <% if caption = blob.try(:caption) %> + <%= caption %> + <% else %> + <span class="attachment__name"><%= blob.filename %></span> + <span class="attachment__size"><%= number_to_human_size blob.byte_size %></span> + <% end %> + </figcaption> +</figure> diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 87cf30a15..ee9bff7b4 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -4,7 +4,7 @@ Rails.application.config.assets.version = '1.0' # Add additional assets to the asset load path -# Rails.application.config.assets.paths << Emoji.images_path +Rails.application.config.assets.paths << Rails.root.join('node_modules', 'trix', 'dist') # Precompile additional assets. # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. diff --git a/db/migrate/20190409132006_create_action_text_tables.action_text.rb b/db/migrate/20190409132006_create_action_text_tables.action_text.rb new file mode 100644 index 000000000..a749b0d6e --- /dev/null +++ b/db/migrate/20190409132006_create_action_text_tables.action_text.rb @@ -0,0 +1,15 @@ +# This migration comes from action_text (originally 201805281641) +class CreateActionTextTables < ActiveRecord::Migration[5.2] + def change + create_table :action_text_rich_texts do |t| + t.string :name, null: false + t.text :body, limit: 16777215 + t.references :record, null: false, polymorphic: true, index: false + + t.datetime :created_at, null: false + t.datetime :updated_at, null: false + + t.index [:record_type, :record_id, :name], name: "index_action_text_rich_texts_uniqueness", unique: true + end + end +end diff --git a/db/schema.rb b/db/schema.rb index f2b821f01..703ebbd8e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -16,6 +16,16 @@ ActiveRecord::Schema.define(version: 2019_06_27_132911) do enable_extension "plpgsql" enable_extension "unaccent" + create_table "action_text_rich_texts", force: :cascade do |t| + t.string "name", null: false + t.text "body" + t.string "record_type", null: false + t.bigint "record_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["record_type", "record_id", "name"], name: "index_action_text_rich_texts_uniqueness", unique: true + end + create_table "active_storage_attachments", force: :cascade do |t| t.string "name", null: false t.string "record_type", null: false