From fa7ceda7edfd3cecb2cc44225346989a94d0eb33 Mon Sep 17 00:00:00 2001 From: Sudara Date: Fri, 28 Aug 2020 16:32:49 +0200 Subject: [PATCH 1/3] Action Text WIP --- .postcssrc.yml | 3 --- app/assets/stylesheets/application.scss | 2 ++ app/controllers/assets_controller.rb | 3 ++- app/javascript/packs/application.js | 6 ++++-- app/models/asset.rb | 4 +++- app/views/assets/_edit.html.erb | 2 +- app/views/shared/_asset.html.erb | 2 +- package.json | 2 ++ yarn.lock | 24 ++++++++++++++++++++++++ 9 files changed, 39 insertions(+), 9 deletions(-) delete mode 100644 .postcssrc.yml diff --git a/.postcssrc.yml b/.postcssrc.yml deleted file mode 100644 index 150dac3c6c..0000000000 --- a/.postcssrc.yml +++ /dev/null @@ -1,3 +0,0 @@ -plugins: - postcss-import: {} - postcss-cssnext: {} diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index c783bc8a78..2db61f5819 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -3,5 +3,7 @@ @import 'normalize'; @import 'variables'; @import 'layout'; +@import "trix/dist/trix"; +@import 'actiontext'; @import 'components/**/*'; \ No newline at end of file diff --git a/app/controllers/assets_controller.rb b/app/controllers/assets_controller.rb index 9c4f1c39df..6828dd36e9 100644 --- a/app/controllers/assets_controller.rb +++ b/app/controllers/assets_controller.rb @@ -202,7 +202,8 @@ def asset_params :title, :user, :user_id, - :youtube_embed + :youtube_embed, + :post ) end diff --git a/app/javascript/packs/application.js b/app/javascript/packs/application.js index 7f534efe09..5e29d8ad9f 100644 --- a/app/javascript/packs/application.js +++ b/app/javascript/packs/application.js @@ -14,6 +14,9 @@ import { definitionsFromContext } from 'stimulus/webpack-helpers' import gsap from 'gsap' // needed for tests to run import { makeSVGFromTitle } from '../animation/default_playlist_images' import { } from '../misc/bugsnag.js.erb' +/* eslint-disable-next-line import/extensions */ +import 'trix/dist/trix.js'; +import '@rails/actiontext'; Rails.start() Turbolinks.start() @@ -26,7 +29,6 @@ const application = Application.start() const context = require.context('../controllers', true, /\.js$/) application.load(definitionsFromContext(context)) - function handlers() { document.querySelectorAll('.large_cover .no_pic, .small_cover .no_pic').forEach((pic) => { const title = document.querySelector('h1').textContent.trim() @@ -53,5 +55,5 @@ function handlers() { document.addEventListener('turbolinks:load', handlers) export { - gsap + gsap, } diff --git a/app/models/asset.rb b/app/models/asset.rb index 9b6ab1cce9..138ff7021f 100644 --- a/app/models/asset.rb +++ b/app/models/asset.rb @@ -12,6 +12,8 @@ class Asset < ApplicationRecord include Asset::Statistics include Asset::Waveform + has_rich_text :post + attribute :user_agent, :string serialize :waveform, Array @@ -25,7 +27,7 @@ class Asset < ApplicationRecord scope :hottest, -> { where('hotness > 0').reorder(hotness: :desc) } scope :most_commented, -> { where('comments_count > 0').reorder('comments_count DESC') } scope :most_listened, -> { where('listens_count > 0').reorder('listens_count DESC') } - scope :with_preloads, -> { includes(user: { avatar_image_attachment: :blob }) } + scope :with_preloads, -> { with_rich_text_post_and_embeds.includes(user: { avatar_image_attachment: :blob }) } belongs_to :user after_commit :update_user_assets_count, on: :create diff --git a/app/views/assets/_edit.html.erb b/app/views/assets/_edit.html.erb index 8c6e94c43e..6a569323a7 100644 --- a/app/views/assets/_edit.html.erb +++ b/app/views/assets/_edit.html.erb @@ -20,7 +20,7 @@ - <%= f.text_area :description, placeholder: "Tell us a story...", id: "description_#{asset.id}" %> + <%= f.rich_text_area :post %> <%= f.text_area :credits, placeholder: "Credits for this track" %>
diff --git a/app/views/shared/_asset.html.erb b/app/views/shared/_asset.html.erb index 29b1571660..69fbd6c394 100644 --- a/app/views/shared/_asset.html.erb +++ b/app/views/shared/_asset.html.erb @@ -24,7 +24,7 @@
- <%= format_track_description(@asset.description) %> + <%= @asset.post %>
<%= markdown(@asset.credits) if @asset.credits.present? %> diff --git a/package.json b/package.json index 599ec19b72..23b54c5609 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "@babel/plugin-transform-runtime": "^7.11.0", "@babel/preset-env": "^7.11.0", "@bugsnag/js": "^7.2.1", + "@rails/actiontext": "^6.0.3-2", "@rails/ujs": "^6.0.3-1", "@rails/webpacker": "^5.1.1", "babel-loader": "^8.1.0", @@ -16,6 +17,7 @@ "seedrandom": "^3.0.5", "sortablejs": "^1.10.2", "stimulus": "^1.1.1", + "trix": "^1.2.0", "turbolinks": "^5.2.0" }, "devDependencies": { diff --git a/yarn.lock b/yarn.lock index 51c35555e3..07ae2ae867 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1899,6 +1899,20 @@ which "^2.0.1" winston "^3.0.0" +"@rails/actiontext@^6.0.3-2": + version "6.0.3-2" + resolved "https://registry.yarnpkg.com/@rails/actiontext/-/actiontext-6.0.3-2.tgz#19739f5c58fed879fedcd98039baf2be0bece52d" + integrity sha512-X7e7mDFeQZoTyPn+Dtu+dhwWfr/9I/h+pVhsAKCithCslcefuk5q4vmlfKWyIaKYNF5j821UdR3gfI8Nwr8Wjg== + dependencies: + "@rails/activestorage" "^6.0.0-alpha" + +"@rails/activestorage@^6.0.0-alpha": + version "6.0.3" + resolved "https://registry.yarnpkg.com/@rails/activestorage/-/activestorage-6.0.3.tgz#401d2a28ecb7167cdb5e830ffddaa17c308c31aa" + integrity sha512-YdNwyfryHlcKj7Ruix89wZ2aiN3KTYULdW1Y/hNlHJlrY2/PXjT2YBTzZiVd+dcjrwHBsXV2rExdy+Z/lsrlEg== + dependencies: + spark-md5 "^3.0.0" + "@rails/ujs@^6.0.3-1": version "6.0.3-2" resolved "https://registry.yarnpkg.com/@rails/ujs/-/ujs-6.0.3-2.tgz#e14c1f29086858215ce7ccd9ad6d8888c458b4a3" @@ -9282,6 +9296,11 @@ source-map@^0.6.0, source-map@^0.6.1, source-map@~0.6.1: resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263" integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g== +spark-md5@^3.0.0: + version "3.0.1" + resolved "https://registry.yarnpkg.com/spark-md5/-/spark-md5-3.0.1.tgz#83a0e255734f2ab4e5c466e5a2cfc9ba2aa2124d" + integrity sha512-0tF3AGSD1ppQeuffsLDIOWlKUd3lS92tFxcsrh5Pe3ZphhnoK+oXIBTzOAThZCiuINZLvpiLH/1VS1/ANEJVig== + spdx-correct@^3.0.0: version "3.1.1" resolved "https://registry.yarnpkg.com/spdx-correct/-/spdx-correct-3.1.1.tgz#dece81ac9c1e6713e5f7d1b6f17d468fa53d89a9" @@ -9880,6 +9899,11 @@ triple-beam@^1.2.0, triple-beam@^1.3.0: resolved "https://registry.yarnpkg.com/triple-beam/-/triple-beam-1.3.0.tgz#a595214c7298db8339eeeee083e4d10bd8cb8dd9" integrity sha512-XrHUvV5HpdLmIj4uVMxHggLbFSZYIn7HEWsqePZcI50pco+MPqJ50wMGY794X7AOOhxOBAjbkqfAbEe/QMp2Lw== +trix@^1.2.0: + version "1.2.4" + resolved "https://registry.yarnpkg.com/trix/-/trix-1.2.4.tgz#8b8f8ea58c2605ad3d04a3b82d60a994576e33a5" + integrity sha512-S6YUUaaHngNbW1jzBV3MQ35pisTV/x5yKlNZrAf8exkOnHsTj+2OJHx2jBLqRQEtpWHpg85pHjo2A7dKK2RQbQ== + "true-case-path@^1.0.2": version "1.0.3" resolved "https://registry.yarnpkg.com/true-case-path/-/true-case-path-1.0.3.tgz#f813b5a8c86b40da59606722b144e3225799f47d" From 215b09a9f5fa9f39d4fd502768c85dec8b63e59e Mon Sep 17 00:00:00 2001 From: Sudara Date: Fri, 28 Aug 2020 16:33:33 +0200 Subject: [PATCH 2/3] Action Text Migration and css --- app/assets/stylesheets/actiontext.scss | 34 +++++++++++++++++++ app/views/active_storage/blobs/_blob.html.erb | 14 ++++++++ ...6_create_action_text_tables.action_text.rb | 14 ++++++++ test/fixtures/action_text/rich_texts.yml | 4 +++ 4 files changed, 66 insertions(+) create mode 100644 app/assets/stylesheets/actiontext.scss create mode 100644 app/views/active_storage/blobs/_blob.html.erb create mode 100644 db/migrate/20200828123506_create_action_text_tables.action_text.rb create mode 100644 test/fixtures/action_text/rich_texts.yml diff --git a/app/assets/stylesheets/actiontext.scss b/app/assets/stylesheets/actiontext.scss new file mode 100644 index 0000000000..f0ca41f13b --- /dev/null +++ b/app/assets/stylesheets/actiontext.scss @@ -0,0 +1,34 @@ +// +// 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. +// +// We need to override trix.css’s image gallery styles to accommodate the +// 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 0000000000..c9820c3028 --- /dev/null +++ b/app/views/active_storage/blobs/_blob.html.erb @@ -0,0 +1,14 @@ +
attachment--<%= blob.filename.extension %>"> + <% if blob.representable? %> + <%= image_tag blob.representation(resize_to_limit: local_assigns[:in_gallery] ? [ 800, 600 ] : [ 1024, 768 ]) %> + <% end %> + +
+ <% if caption = blob.try(:caption) %> + <%= caption %> + <% else %> + <%# <%= blob.filename %> + <%# <%= number_to_human_size blob.byte_size %> %> %> + <% end %> +
+
diff --git a/db/migrate/20200828123506_create_action_text_tables.action_text.rb b/db/migrate/20200828123506_create_action_text_tables.action_text.rb new file mode 100644 index 0000000000..5dfbd1561b --- /dev/null +++ b/db/migrate/20200828123506_create_action_text_tables.action_text.rb @@ -0,0 +1,14 @@ +# This migration comes from action_text (originally 20180528164100) +class CreateActionTextTables < ActiveRecord::Migration[6.0] + def change + create_table :action_text_rich_texts do |t| + t.string :name, null: false + t.text :body, size: :long + t.references :record, null: false, polymorphic: true, index: false + + t.timestamps + + t.index [ :record_type, :record_id, :name ], name: "index_action_text_rich_texts_uniqueness", unique: true + end + end +end diff --git a/test/fixtures/action_text/rich_texts.yml b/test/fixtures/action_text/rich_texts.yml new file mode 100644 index 0000000000..8b371ea604 --- /dev/null +++ b/test/fixtures/action_text/rich_texts.yml @@ -0,0 +1,4 @@ +# one: +# record: name_of_fixture (ClassOfFixture) +# name: content +# body:

In a million stars!

From 0679ae0bb29254fadcee355daf50f6df1638ed2c Mon Sep 17 00:00:00 2001 From: Sudara Date: Fri, 28 Aug 2020 17:59:45 +0200 Subject: [PATCH 3/3] Fix newline issue caused by blanket form styles --- app/assets/stylesheets/application.scss | 5 +++-- app/assets/stylesheets/components/forms.scss | 3 --- app/javascript/packs/application.js | 4 ++-- app/views/active_storage/blobs/_blob.html.erb | 2 -- app/views/assets/_edit.html.erb | 1 + 5 files changed, 6 insertions(+), 9 deletions(-) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 2db61f5819..1be5b5c7aa 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -3,7 +3,8 @@ @import 'normalize'; @import 'variables'; @import 'layout'; + +@import 'components/**/*'; + @import "trix/dist/trix"; @import 'actiontext'; - -@import 'components/**/*'; \ No newline at end of file diff --git a/app/assets/stylesheets/components/forms.scss b/app/assets/stylesheets/components/forms.scss index ee74985dad..1f214270c3 100644 --- a/app/assets/stylesheets/components/forms.scss +++ b/app/assets/stylesheets/components/forms.scss @@ -68,9 +68,6 @@ form { input[type="file"] { background-color: transparent; } - br { - display: none; - } label { margin-bottom: 6px !important; font-family: $medium-sans-font; diff --git a/app/javascript/packs/application.js b/app/javascript/packs/application.js index 5e29d8ad9f..808e102ee5 100644 --- a/app/javascript/packs/application.js +++ b/app/javascript/packs/application.js @@ -15,8 +15,8 @@ import gsap from 'gsap' // needed for tests to run import { makeSVGFromTitle } from '../animation/default_playlist_images' import { } from '../misc/bugsnag.js.erb' /* eslint-disable-next-line import/extensions */ -import 'trix/dist/trix.js'; -import '@rails/actiontext'; +require('trix/dist/trix.js') +require('@rails/actiontext') Rails.start() Turbolinks.start() diff --git a/app/views/active_storage/blobs/_blob.html.erb b/app/views/active_storage/blobs/_blob.html.erb index c9820c3028..e9ea5bf94f 100644 --- a/app/views/active_storage/blobs/_blob.html.erb +++ b/app/views/active_storage/blobs/_blob.html.erb @@ -7,8 +7,6 @@ <% if caption = blob.try(:caption) %> <%= caption %> <% else %> - <%# <%= blob.filename %> - <%# <%= number_to_human_size blob.byte_size %> %> %> <% end %> diff --git a/app/views/assets/_edit.html.erb b/app/views/assets/_edit.html.erb index 6a569323a7..f760b4f280 100644 --- a/app/views/assets/_edit.html.erb +++ b/app/views/assets/_edit.html.erb @@ -1,5 +1,6 @@ <%= form_with(model: asset, url: "/#{@user.login}/tracks/#{asset.id}", local: (true unless @assets), data: { action: 'ajax:beforeSend->save#spin ajax:success->save#success ajax:error->save#error ajax:complete->save#complete' }) do |f| %> + <% if asset.errors.any? %>
There were some problems...