From a7b6af83b67a3d27f718aa92a120b930ca03f588 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Tue, 22 Sep 2020 17:00:52 +0200 Subject: [PATCH 01/34] [a11y] Better image alt text support (#1940) Instead of only using the alt_tag attribute of the essence picture this now supports passing the alt attribute via the html_options and adds a fallback to a humanized picture name. This ensures we always have an alt text for accessibility reasons. --- app/models/alchemy/essence_picture_view.rb | 6 +- .../alchemy/essence_picture_view_spec.rb | 63 +++++++++++++++++-- 2 files changed, 62 insertions(+), 7 deletions(-) diff --git a/app/models/alchemy/essence_picture_view.rb b/app/models/alchemy/essence_picture_view.rb index 6465f4ebb0..eed72b8306 100644 --- a/app/models/alchemy/essence_picture_view.rb +++ b/app/models/alchemy/essence_picture_view.rb @@ -55,7 +55,7 @@ def caption def img_tag @_img_tag ||= image_tag( essence.picture_url(options.except(*DEFAULT_OPTIONS.keys)), { - alt: essence.alt_tag.presence, + alt: alt_text, title: essence.title.presence, class: caption ? nil : essence.css_class.presence, srcset: srcset.join(", ").presence, @@ -79,5 +79,9 @@ def srcset width.present? ? "#{url} #{width}w" : "#{url} #{height}h" end end + + def alt_text + essence.alt_tag.presence || html_options.delete(:alt) || essence.picture.name&.humanize + end end end diff --git a/spec/models/alchemy/essence_picture_view_spec.rb b/spec/models/alchemy/essence_picture_view_spec.rb index cfc56a5715..4c5598f6ec 100644 --- a/spec/models/alchemy/essence_picture_view_spec.rb +++ b/spec/models/alchemy/essence_picture_view_spec.rb @@ -70,7 +70,7 @@ context "but disabled in the options" do let(:options) do - {show_caption: false} + { show_caption: false } end it "should not enclose the image in a
element" do @@ -85,7 +85,7 @@ context "but disabled in the content settings" do before do - allow(content).to receive(:settings).and_return({show_caption: false}) + allow(content).to receive(:settings).and_return({ show_caption: false }) end it "should not enclose the image in a
element" do @@ -98,7 +98,7 @@ end context "but enabled in the options hash" do - let(:options) { {show_caption: true} } + let(:options) { { show_caption: true } } it "should enclose the image in a
element" do expect(view).to have_selector("figure img") @@ -179,7 +179,7 @@ end it "does not overwrite DEFAULT_OPTIONS" do - Alchemy::EssencePictureView.new(content, {my_custom_option: true}) + Alchemy::EssencePictureView.new(content, { my_custom_option: true }) expect(picture_view.options).to_not have_key(:my_custom_option) end end @@ -187,7 +187,7 @@ context "with srcset content setting" do before do allow(content).to receive(:settings) do - {srcset: srcset} + { srcset: srcset } end end @@ -244,7 +244,7 @@ context "with sizes content setting" do before do allow(content).to receive(:settings) do - {sizes: sizes} + { sizes: sizes } end end @@ -278,4 +278,55 @@ expect(view).not_to have_selector("img[sizes]") end end + + describe "alt text" do + subject(:view) do + Alchemy::EssencePictureView.new(content, {}, html_options).render + end + + let(:html_options) { {} } + + context "essence having alt text stored" do + let(:essence_picture) do + stub_model Alchemy::EssencePicture, + picture: picture, + alt_tag: "A cute cat" + end + + it "uses this as image alt text" do + expect(view).to have_selector('img[alt="A cute cat"]') + end + end + + context "essence not having alt text stored" do + context "but passed as html option" do + let(:html_options) { { alt: "Cute kittens" } } + + it "uses this as image alt text" do + expect(view).to have_selector('img[alt="Cute kittens"]') + end + end + + context "and not passed as html option" do + context "with name on the picture" do + let(:picture) do + stub_model Alchemy::Picture, + image_file_format: "png", + image_file: image, + name: "cute_kitty-cat" + end + + it "uses a humanized picture name as alt text" do + expect(view).to have_selector('img[alt="Cute kitty-cat"]') + end + end + + context "and no name on the picture" do + it "has no alt text" do + expect(view).to_not have_selector("img[alt]") + end + end + end + end + end end From c85d6bcf0f4b3150d9a7302c26bc1d49124e7a5d Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Sun, 26 Jul 2020 20:52:19 +0200 Subject: [PATCH 02/34] Move back to Travis CI (#1907) * Move back to Travis CI This reverts commit 411fc9d548d46b76f6e135a85d2966984b875fce. * Update codeclimate_test_reporter in travis.yml * Remove warnings from travis.yml * Update travis build matrix This with all supported Ruby and Rails versions * Set up travis jobs for rspec and jest specs * Skip coverage upload for Jest specs It is not trivial to merge the coverage with the RSpec coverage. Since we do not have much Jest specs yet, it is not worth it in the moment. * Adjust rails generators coverage filter We do not test generators and after we moved the generators out of the lib/rails folder we need to adjust the filter. --- .github/workflows/ci.yml | 134 --------------------------------------- .travis.yml | 45 +++++++++++++ Gemfile | 4 +- README.md | 2 +- spec/spec_helper.rb | 5 +- 5 files changed, 49 insertions(+), 141 deletions(-) delete mode 100644 .github/workflows/ci.yml create mode 100644 .travis.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index 5e176f7325..0000000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,134 +0,0 @@ -name: CI - -on: [push, pull_request] - -jobs: - RSpec: - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - rails: - - '5.2' - - '6.0' - ruby: - - '2.5.x' - - '2.6.x' - database: - - mysql - - postgresql - env: - DB: ${{ matrix.database }} - DB_USER: alchemy_user - DB_PASSWORD: password - DB_HOST: '127.0.0.1' - RAILS_ENV: test - RAILS_VERSION: ${{ matrix.rails }} - services: - postgres: - image: postgres:11 - env: - POSTGRES_USER: alchemy_user - POSTGRES_PASSWORD: password - POSTGRES_DB: alchemy_cms_dummy_test - ports: ['5432:5432'] - options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 - mysql: - image: mysql:latest - ports: ['3306:3306'] - env: - MYSQL_USER: alchemy_user - MYSQL_PASSWORD: password - MYSQL_DATABASE: alchemy_cms_dummy_test - MYSQL_ROOT_PASSWORD: password - options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=5 - steps: - - uses: actions/checkout@v1 - - name: Set up Ruby - uses: actions/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby }} - - name: Restore apt cache - id: apt-cache - uses: actions/cache@preview - with: - path: /home/runner/apt/cache - key: ${{ runner.os }}-apt-${{ matrix.database }} - restore-keys: | - ${{ runner.os }}-apt- - - name: Install Postgres headers - if: matrix.database == 'postgresql' - run: | - mkdir -p /home/runner/apt/cache - sudo apt update -qq - sudo apt install -qq --fix-missing libpq-dev -o dir::cache::archives="/home/runner/apt/cache" - sudo chown -R runner /home/runner/apt/cache - - name: Install MySQL headers - if: matrix.database == 'mysql' - run: | - mkdir -p /home/runner/apt/cache - sudo apt update -qq - sudo apt install -qq --fix-missing libmysqlclient-dev -o dir::cache::archives="/home/runner/apt/cache" - sudo chown -R runner /home/runner/apt/cache - - name: Install bundler - run: | - gem install bundler - - name: Restore Ruby Gems cache - id: cache - uses: actions/cache@preview - with: - path: vendor/bundle - key: ${{ runner.os }}-bundle-${{ matrix.ruby }}-${{ matrix.rails }}-${{ matrix.database }}-${{ hashFiles('**/Gemfile') }} - restore-keys: | - ${{ runner.os }}-bundle- - - name: Install bundle - timeout-minutes: 10 - run: | - bundle install --jobs 4 --retry 3 --path vendor/bundle - - name: Restore node modules cache - id: yarn-cache - uses: actions/cache@preview - with: - path: spec/dummy/node_modules - key: ${{ runner.os }}-yarn-dummy-${{ hashFiles('./package.json') }} - restore-keys: | - ${{ runner.os }}-yarn-dummy- - - name: Prepare database - run: | - bundle exec rake alchemy:spec:prepare - - name: Run tests & publish code coverage - uses: paambaati/codeclimate-action@v2.5.7 - env: - CC_TEST_REPORTER_ID: bca4349e32f97919210ac8a450b04904b90683fcdd57d65a22c0f5065482bc22 - with: - coverageCommand: bundle exec rspec - - uses: actions/upload-artifact@master - if: failure() - with: - name: Screenshots - path: spec/dummy/tmp/screenshots - Jest: - runs-on: ubuntu-latest - env: - NODE_ENV: test - steps: - - uses: actions/checkout@v1 - - name: Restore node modules cache - uses: actions/cache@preview - with: - path: node_modules - key: ${{ runner.os }}-yarn-${{ hashFiles('./package.json') }} - restore-keys: | - ${{ runner.os }}-yarn- - - name: Install yarn - run: yarn install - - name: Run jest - run: yarn jest - - name: Run jest & publish code coverage - uses: paambaati/codeclimate-action@v2.5.7 - env: - CC_TEST_REPORTER_ID: bca4349e32f97919210ac8a450b04904b90683fcdd57d65a22c0f5065482bc22 - with: - coverageLocations: - ./coverage/lcov.info:lcov - coverageCommand: yarn jest --collectCoverage --coverageDirectory=coverage diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000000..c919487c1d --- /dev/null +++ b/.travis.yml @@ -0,0 +1,45 @@ +language: ruby +os: linux +dist: bionic +services: + - mysql +addons: + postgresql: "10" +cache: + bundler: true + yarn: true + directories: + - /home/travis/.webdrivers/ +rvm: + - 2.6.6 + - 2.7.1 +before_script: + - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter + - chmod +x ./cc-test-reporter + - ./cc-test-reporter before-build +script: bundle exec rake + +after_script: + - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT + +jobs: + include: + - language: node_js + node_js: 12 + install: yarn install + script: yarn jest --coverage + env: NODE_ENV=test + before_script: skip + after_script: skip + +env: + global: + CC_TEST_REPORTER_ID=bca4349e32f97919210ac8a450b04904b90683fcdd57d65a22c0f5065482bc22 + jobs: + - DB=mysql RAILS_VERSION=5.2 + - DB=mysql RAILS_VERSION=6.0 + - DB=postgresql RAILS_VERSION=5.2 + - DB=postgresql RAILS_VERSION=6.0 +notifications: + slack: + secure: QzOFw1Ph69pzwWBFgtIVkOnjbcRxB9HPRQ+RYjK+2tg+fsbiTJ+wYgHcZL49tPYcLAls4kymkFWzWBF3PCAXJMfKgUCqXzdQ2FuJC/JoVRTLll4wDnZFPG33jsm5tVznmycZ3ma4+ZWfJQ+C+elEBOba6v1kG9eGIy6sH2cvXfE= diff --git a/Gemfile b/Gemfile index b1f343681e..91cc493c82 100644 --- a/Gemfile +++ b/Gemfile @@ -10,10 +10,10 @@ if ENV["DB"].nil? || ENV["DB"] == "sqlite" gem "sqlite3", "~> 1.4.1" end gem "mysql2", "~> 0.5.1" if ENV["DB"] == "mysql" -gem "pg", "~> 1.0" if ENV["DB"] == "postgresql" +gem "pg", "~> 1.0" if ENV["DB"] == "postgresql" group :development, :test do - if ENV["GITHUB_ACTIONS"] + if ENV["TRAVIS"] gem "sassc", "~> 2.4.0" # https://github.com/sass/sassc-ruby/issues/146 else gem "launchy" diff --git a/README.md b/README.md index 57dc2bcef5..c1fe9a70fe 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # AlchemyCMS [![Gem Version](https://badge.fury.io/rb/alchemy_cms.svg)](http://badge.fury.io/rb/alchemy_cms) -[![Build Status](https://github.com/AlchemyCMS/alchemy_cms/workflows/CI/badge.svg?branch=master)](https://github.com/AlchemyCMS/alchemy_cms/actions) +[![Build Status](https://travis-ci.com/AlchemyCMS/alchemy_cms.svg?branch=master)](https://travis-ci.com/AlchemyCMS/alchemy_cms) [![Maintainability](https://api.codeclimate.com/v1/badges/196c56c56568ed24a697/maintainability)](https://codeclimate.com/github/AlchemyCMS/alchemy_cms/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/196c56c56568ed24a697/test_coverage)](https://codeclimate.com/github/AlchemyCMS/alchemy_cms/test_coverage) [![Depfu](https://badges.depfu.com/badges/ebe56d2dd7b7044a8ae700cc81212a8e/overview.svg)](https://depfu.com/github/AlchemyCMS/alchemy_cms?project_id=4600) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index adf213972a..8d4e6c7fdc 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,13 +1,10 @@ # frozen_string_literal: true require "simplecov" -if ENV["TRAVIS"] - require "codeclimate-test-reporter" -end SimpleCov.start "rails" do add_filter "/lib/alchemy/upgrader" add_filter "/lib/alchemy/version" - add_filter "/lib/rails" + add_filter "/lib/generators" end require "rspec/core" From 5d33bd7c8306d3b667a6feb7d169a30f85a43c22 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Thu, 20 Aug 2020 09:53:42 +0200 Subject: [PATCH 03/34] Use Node 12 on CI runs (#1925) Webpacker needs Node >= 10.17. Let's use the current LTS version of Node --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index c919487c1d..6cf91d21cc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,10 +13,13 @@ cache: rvm: - 2.6.6 - 2.7.1 + before_script: - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter - chmod +x ./cc-test-reporter - ./cc-test-reporter before-build + - nvm use 12 + script: bundle exec rake after_script: From 0df93dc9cdce472058d07fffb8d002cc9de08be8 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Tue, 29 Sep 2020 21:11:14 +0200 Subject: [PATCH 04/34] v5.0.1 Better image alt text support --- CHANGELOG.md | 4 ++++ lib/alchemy/version.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 34ccf502cc..b19ddce4f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 5.0.1 (2020-09-29) + +- Better image alt text support [#1940](https://github.com/AlchemyCMS/alchemy_cms/pull/1940) ([tvdeyen](https://github.com/tvdeyen)) + ## 5.0.0 (2020-07-17) - Do not convert JPEG images into JPG [#1904](https://github.com/AlchemyCMS/alchemy_cms/pull/1904) ([tvdeyen](https://github.com/tvdeyen)) diff --git a/lib/alchemy/version.rb b/lib/alchemy/version.rb index 5ef2deab78..d89ab69af0 100644 --- a/lib/alchemy/version.rb +++ b/lib/alchemy/version.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Alchemy - VERSION = "5.0.0" + VERSION = "5.0.1" def self.version VERSION From 8a2f9ee667d835ea92838e78adfd3c17b391148b Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Fri, 18 Dec 2020 21:42:42 +0100 Subject: [PATCH 05/34] Merge pull request #1984 from tvdeyen/fix-page-sorting Fix page sorting --- app/serializers/alchemy/page_tree_serializer.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/serializers/alchemy/page_tree_serializer.rb b/app/serializers/alchemy/page_tree_serializer.rb index a59b6d810c..ab75eb5d4e 100644 --- a/app/serializers/alchemy/page_tree_serializer.rb +++ b/app/serializers/alchemy/page_tree_serializer.rb @@ -40,7 +40,7 @@ def pages level = path.count + base_level - path.last[:children] << page_hash(page, has_children, level, folded) + path.last[:children] << page_hash(page, level, folded) end tree @@ -48,7 +48,7 @@ def pages protected - def page_hash(page, has_children, level, folded) + def page_hash(page, level, folded) p_hash = { id: page.id, name: page.name, @@ -59,8 +59,8 @@ def page_hash(page, has_children, level, folded) urlname: page.urlname, url_path: page.url_path, level: level, - root: page.depth == 1, - root_or_leaf: page.depth == 1 || !has_children, + root: page.root?, + root_or_leaf: page.root? || page.leaf?, children: [], } From 7a126ea90336b5c48c91782ca7743cef88c1d0db Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Fri, 18 Dec 2020 22:00:28 +0100 Subject: [PATCH 06/34] Bump version to v5.0.2 - Fix page sorting [#1984](https://github.com/AlchemyCMS/alchemy_cms/pull/1984) ([tvdeyen](https://github.com/tvdeyen)) --- CHANGELOG.md | 4 ++++ lib/alchemy/version.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b19ddce4f6..1c299c2dd4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 5.0.2 (2020-12-18) + +- Fix page sorting [#1984](https://github.com/AlchemyCMS/alchemy_cms/pull/1984) ([tvdeyen](https://github.com/tvdeyen)) + ## 5.0.1 (2020-09-29) - Better image alt text support [#1940](https://github.com/AlchemyCMS/alchemy_cms/pull/1940) ([tvdeyen](https://github.com/tvdeyen)) diff --git a/lib/alchemy/version.rb b/lib/alchemy/version.rb index d89ab69af0..15981c4d6d 100644 --- a/lib/alchemy/version.rb +++ b/lib/alchemy/version.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Alchemy - VERSION = "5.0.1" + VERSION = "5.0.2" def self.version VERSION From 84ce8cb3de360210252e6965f39b12f81580caf1 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Sat, 12 Dec 2020 22:13:27 +0100 Subject: [PATCH 07/34] Merge pull request #1981 from tvdeyen/back-to-gh-actions Move away from Travis CI --- .github/workflows/ci.yml | 126 +++++++++++++++++++++++++++++++++++++++ .travis.yml | 48 --------------- Gemfile | 2 +- README.md | 2 +- 4 files changed, 128 insertions(+), 50 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000000..ed249045dd --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,126 @@ +name: CI + +on: [push, pull_request] + +jobs: + RSpec: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + rails: + - '5.2' + - '6.0' + ruby: + - '2.5.x' + - '2.6.x' + database: + - mysql + - postgresql + env: + DB: ${{ matrix.database }} + DB_USER: alchemy_user + DB_PASSWORD: password + DB_HOST: '127.0.0.1' + RAILS_ENV: test + RAILS_VERSION: ${{ matrix.rails }} + services: + postgres: + image: postgres:11 + env: + POSTGRES_USER: alchemy_user + POSTGRES_PASSWORD: password + POSTGRES_DB: alchemy_cms_dummy_test + ports: ['5432:5432'] + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 + mysql: + image: mysql:latest + ports: ['3306:3306'] + env: + MYSQL_USER: alchemy_user + MYSQL_PASSWORD: password + MYSQL_DATABASE: alchemy_cms_dummy_test + MYSQL_ROOT_PASSWORD: password + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=5 + steps: + - uses: actions/checkout@v2.3.4 + - name: Set up Ruby + uses: actions/setup-ruby@v1.1.2 + with: + ruby-version: ${{ matrix.ruby }} + - name: Restore apt cache + id: apt-cache + uses: actions/cache@v2.1.3 + with: + path: /home/runner/apt/cache + key: ${{ runner.os }}-apt-${{ matrix.database }} + restore-keys: | + ${{ runner.os }}-apt- + - name: Install Postgres headers + if: matrix.database == 'postgresql' + run: | + mkdir -p /home/runner/apt/cache + sudo apt update -qq + sudo apt install -qq --fix-missing libpq-dev -o dir::cache::archives="/home/runner/apt/cache" + sudo chown -R runner /home/runner/apt/cache + - name: Install MySQL headers + if: matrix.database == 'mysql' + run: | + mkdir -p /home/runner/apt/cache + sudo apt update -qq + sudo apt install -qq --fix-missing libmysqlclient-dev -o dir::cache::archives="/home/runner/apt/cache" + sudo chown -R runner /home/runner/apt/cache + - name: Install bundler + run: | + gem install bundler + - name: Restore Ruby Gems cache + id: cache + uses: actions/cache@v2.1.3 + with: + path: vendor/bundle + key: ${{ runner.os }}-bundle-${{ matrix.ruby }}-${{ matrix.rails }}-${{ matrix.database }}-${{ hashFiles('**/Gemfile') }} + restore-keys: | + ${{ runner.os }}-bundle- + - name: Install bundle + timeout-minutes: 10 + run: | + bundle install --jobs 4 --retry 3 --path vendor/bundle + - name: Restore node modules cache + id: yarn-cache + uses: actions/cache@v2.1.3 + with: + path: spec/dummy/node_modules + key: ${{ runner.os }}-yarn-dummy-${{ hashFiles('./package.json') }} + restore-keys: | + ${{ runner.os }}-yarn-dummy- + - name: Prepare database + run: | + bundle exec rake alchemy:spec:prepare + - name: Run tests & publish code coverage + uses: paambaati/codeclimate-action@v2.7.5 + env: + CC_TEST_REPORTER_ID: bca4349e32f97919210ac8a450b04904b90683fcdd57d65a22c0f5065482bc22 + with: + coverageCommand: bundle exec rspec + - uses: actions/upload-artifact@main + if: failure() + with: + name: Screenshots + path: spec/dummy/tmp/screenshots + Jest: + runs-on: ubuntu-latest + env: + NODE_ENV: test + steps: + - uses: actions/checkout@v2.3.4 + - name: Restore node modules cache + uses: actions/cache@v2.1.3 + with: + path: node_modules + key: ${{ runner.os }}-yarn-${{ hashFiles('./package.json') }} + restore-keys: | + ${{ runner.os }}-yarn- + - name: Install yarn + run: yarn install + - name: Run jest + run: yarn jest diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 6cf91d21cc..0000000000 --- a/.travis.yml +++ /dev/null @@ -1,48 +0,0 @@ -language: ruby -os: linux -dist: bionic -services: - - mysql -addons: - postgresql: "10" -cache: - bundler: true - yarn: true - directories: - - /home/travis/.webdrivers/ -rvm: - - 2.6.6 - - 2.7.1 - -before_script: - - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter - - chmod +x ./cc-test-reporter - - ./cc-test-reporter before-build - - nvm use 12 - -script: bundle exec rake - -after_script: - - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT - -jobs: - include: - - language: node_js - node_js: 12 - install: yarn install - script: yarn jest --coverage - env: NODE_ENV=test - before_script: skip - after_script: skip - -env: - global: - CC_TEST_REPORTER_ID=bca4349e32f97919210ac8a450b04904b90683fcdd57d65a22c0f5065482bc22 - jobs: - - DB=mysql RAILS_VERSION=5.2 - - DB=mysql RAILS_VERSION=6.0 - - DB=postgresql RAILS_VERSION=5.2 - - DB=postgresql RAILS_VERSION=6.0 -notifications: - slack: - secure: QzOFw1Ph69pzwWBFgtIVkOnjbcRxB9HPRQ+RYjK+2tg+fsbiTJ+wYgHcZL49tPYcLAls4kymkFWzWBF3PCAXJMfKgUCqXzdQ2FuJC/JoVRTLll4wDnZFPG33jsm5tVznmycZ3ma4+ZWfJQ+C+elEBOba6v1kG9eGIy6sH2cvXfE= diff --git a/Gemfile b/Gemfile index 91cc493c82..7f57e0a4d2 100644 --- a/Gemfile +++ b/Gemfile @@ -13,7 +13,7 @@ gem "mysql2", "~> 0.5.1" if ENV["DB"] == "mysql" gem "pg", "~> 1.0" if ENV["DB"] == "postgresql" group :development, :test do - if ENV["TRAVIS"] + if ENV["GITHUB_ACTIONS"] gem "sassc", "~> 2.4.0" # https://github.com/sass/sassc-ruby/issues/146 else gem "launchy" diff --git a/README.md b/README.md index c1fe9a70fe..0c1fdcd86b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # AlchemyCMS [![Gem Version](https://badge.fury.io/rb/alchemy_cms.svg)](http://badge.fury.io/rb/alchemy_cms) -[![Build Status](https://travis-ci.com/AlchemyCMS/alchemy_cms.svg?branch=master)](https://travis-ci.com/AlchemyCMS/alchemy_cms) +[![Build Status](https://github.com/AlchemyCMS/alchemy_cms/workflows/CI/badge.svg?branch=main)](https://github.com/AlchemyCMS/alchemy_cms/actions) [![Maintainability](https://api.codeclimate.com/v1/badges/196c56c56568ed24a697/maintainability)](https://codeclimate.com/github/AlchemyCMS/alchemy_cms/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/196c56c56568ed24a697/test_coverage)](https://codeclimate.com/github/AlchemyCMS/alchemy_cms/test_coverage) [![Depfu](https://badges.depfu.com/badges/ebe56d2dd7b7044a8ae700cc81212a8e/overview.svg)](https://depfu.com/github/AlchemyCMS/alchemy_cms?project_id=4600) From 66772879dee058e7c15082fff5606ce226bbc8d2 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Tue, 12 Jan 2021 13:32:15 +0100 Subject: [PATCH 08/34] Fix copy element feature With the introduction of the Element Editor decorator this feature broke. Instead of using the class of the element_editor local variable we use the remarkable type string that we exactly know in this case. --- .../admin/elements/_element_toolbar.html.erb | 2 +- spec/features/admin/edit_elements_feature_spec.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/views/alchemy/admin/elements/_element_toolbar.html.erb b/app/views/alchemy/admin/elements/_element_toolbar.html.erb index c139d246fa..4303d47e25 100644 --- a/app/views/alchemy/admin/elements/_element_toolbar.html.erb +++ b/app/views/alchemy/admin/elements/_element_toolbar.html.erb @@ -1,4 +1,4 @@ -<% remarkable_type = element.class.name.demodulize.underscore.pluralize %> +<% remarkable_type = "elements" %>
diff --git a/spec/features/admin/edit_elements_feature_spec.rb b/spec/features/admin/edit_elements_feature_spec.rb index 69c87b8f88..99f62a872f 100644 --- a/spec/features/admin/edit_elements_feature_spec.rb +++ b/spec/features/admin/edit_elements_feature_spec.rb @@ -35,4 +35,17 @@ expect(page).to have_selector(".add-nestable-element-button") end end + + describe "Copy element", :js do + let!(:element) { create(:alchemy_element, page: a_page) } + + scenario "is possible to copy element into clipboard" do + visit alchemy.admin_elements_path(page_id: element.page_id) + expect(page).to have_selector(".element-toolbar") + find(".fa-clone").click + within "#flash_notices" do + expect(page).to have_content(/Copied Article/) + end + end + end end From 625a7ae2bcf534e04ec81a72411601cfafbf2929 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Tue, 12 Jan 2021 15:27:24 +0100 Subject: [PATCH 09/34] v5.0.3 - Fix copy element feature [#1996](https://github.com/AlchemyCMS/alchemy_cms/pull/1996) ([tvdeyen](https://github.com/tvdeyen)) --- CHANGELOG.md | 4 ++++ lib/alchemy/version.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c299c2dd4..480b39d161 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 5.0.3 (2021-01-12) + +- Fix copy element feature [#1996](https://github.com/AlchemyCMS/alchemy_cms/pull/1996) ([tvdeyen](https://github.com/tvdeyen)) + ## 5.0.2 (2020-12-18) - Fix page sorting [#1984](https://github.com/AlchemyCMS/alchemy_cms/pull/1984) ([tvdeyen](https://github.com/tvdeyen)) diff --git a/lib/alchemy/version.rb b/lib/alchemy/version.rb index 15981c4d6d..8c2bcc7c3c 100644 --- a/lib/alchemy/version.rb +++ b/lib/alchemy/version.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Alchemy - VERSION = "5.0.2" + VERSION = "5.0.3" def self.version VERSION From bef5401e22ac23a914660867c42f7bf6ac4a3b04 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Thu, 6 May 2021 10:50:10 +0200 Subject: [PATCH 10/34] Use symbols in polymorphic routes for resources Rails 6.0.3.7 includes a security fix that forces us to use Symbols in polymorphic routes. --- lib/alchemy/resource.rb | 8 +++++--- spec/libraries/resource_spec.rb | 12 ++++++------ spec/libraries/resources_helper_spec.rb | 16 ++++++++-------- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/lib/alchemy/resource.rb b/lib/alchemy/resource.rb index 3f5ea1cc92..ca1ea2b71a 100644 --- a/lib/alchemy/resource.rb +++ b/lib/alchemy/resource.rb @@ -132,7 +132,9 @@ def resource_name end def namespaced_resource_name - @_namespaced_resource_name ||= namespaced_resources_name.singularize + @_namespaced_resource_name ||= begin + namespaced_resources_name.to_s.singularize + end.to_sym # Rails >= 6.0.3.7 needs symbols in polymorphic routes end def namespaced_resources_name @@ -140,13 +142,13 @@ def namespaced_resources_name resource_name_array = resource_array.dup resource_name_array.delete(engine_name) if in_engine? resource_name_array.join("_") - end + end.to_sym # Rails >= 6.0.3.7 needs symbols in polymorphic routes end def namespace_for_scope namespace_array = namespace_diff namespace_array.delete(engine_name) if in_engine? - namespace_array + namespace_array.map(&:to_sym) # Rails >= 6.0.3.7 needs symbols in polymorphic routes end # Returns an array of underscored association names diff --git a/spec/libraries/resource_spec.rb b/spec/libraries/resource_spec.rb index 1114721219..1ecfbb4b2e 100644 --- a/spec/libraries/resource_spec.rb +++ b/spec/libraries/resource_spec.rb @@ -143,19 +143,19 @@ module Alchemy end describe "#namespaced_resource_name" do - it "returns resource_name with namespace (namespace_party for Namespace::Party), i.e. for use in forms" do + it "returns resource_name symbol with namespace (namespace_party for Namespace::Party), i.e. for use in forms" do namespaced_resource = Resource.new("admin/namespace/parties") - expect(namespaced_resource.namespaced_resource_name).to eq("namespace_party") + expect(namespaced_resource.namespaced_resource_name).to eq(:namespace_party) end - it "equals resource_name if resource not namespaced" do + it "equals resource_name symbol if resource not namespaced" do namespaced_resource = Resource.new("admin/parties") - expect(namespaced_resource.namespaced_resource_name).to eq("party") + expect(namespaced_resource.namespaced_resource_name).to eq(:party) end it "doesn't include the engine's name" do namespaced_resource = Resource.new("admin/party_engine/namespace/parties", module_definition) - expect(namespaced_resource.namespaced_resource_name).to eq("namespace_party") + expect(namespaced_resource.namespaced_resource_name).to eq(:namespace_party) end end @@ -168,7 +168,7 @@ module Alchemy describe "#namespace_for_scope" do it "returns a scope for use in url_for based path helpers" do - expect(resource.namespace_for_scope).to eq(%w(admin)) + expect(resource.namespace_for_scope).to eq(%i(admin)) end end diff --git a/spec/libraries/resources_helper_spec.rb b/spec/libraries/resources_helper_spec.rb index 8d09e7b396..225f7230b2 100644 --- a/spec/libraries/resources_helper_spec.rb +++ b/spec/libraries/resources_helper_spec.rb @@ -33,7 +33,7 @@ def resource_handler let(:resource_item) { double("resource-item") } before { - allow(controller).to receive(:main_app).and_return "main_app_proxy" + allow(controller).to receive(:main_app).and_return :main_app_proxy controller.instance_variable_set("@my_resource", resource_item) controller.instance_variable_set("@my_resources", [resource_item]) } @@ -41,7 +41,7 @@ def resource_handler describe "path-helpers" do describe "#resource_url_proxy" do it "returns the current proxy for url-helper-methods" do - expect(controller.resource_url_proxy).to eq("main_app_proxy") + expect(controller.resource_url_proxy).to eq(:main_app_proxy) end context "when resource is in engine" do @@ -56,33 +56,33 @@ def resource_handler describe "#resource_scope" do it "returns an array containing a proxy and namespaces for url_for-based helper-methods" do - expect(controller.resource_scope).to eq(%w[main_app_proxy admin]) + expect(controller.resource_scope).to eq(%i[main_app_proxy admin]) end end describe "#resource_path" do it "invokes polymorphic-path with correct scope and object" do my_resource_item = double - expect(controller).to receive(:polymorphic_path).with(["main_app_proxy", "admin", my_resource_item], {}) + expect(controller).to receive(:polymorphic_path).with([:main_app_proxy, :admin, my_resource_item], {}) controller.resource_path(my_resource_item) end it "uses resource_name when no object is given" do - expect(controller).to receive(:polymorphic_path).with(["main_app_proxy", "admin", "namespace_my_resource"], {}) + expect(controller).to receive(:polymorphic_path).with([:main_app_proxy, :admin, :namespace_my_resource], {}) controller.resource_path end end describe "#resources_path" do it "invokes polymorphic-path with correct scope and resources_name" do - expect(controller).to receive(:polymorphic_path).with(["main_app_proxy", "admin", "namespace_my_resources"], {}) + expect(controller).to receive(:polymorphic_path).with([:main_app_proxy, :admin, :namespace_my_resources], {}) controller.resources_path end end describe "#new_resource_path" do it "invokes new_polymorphic_path with correct scope and resource_name" do - expect(controller).to receive(:new_polymorphic_path).with(["main_app_proxy", "admin", "namespace_my_resource"], {}) + expect(controller).to receive(:new_polymorphic_path).with([:main_app_proxy, :admin, :namespace_my_resource], {}) controller.new_resource_path end end @@ -90,7 +90,7 @@ def resource_handler describe "#edit_resource_path" do it "invokes edit_polymorphic_path with correct scope and resource_name" do my_resource_item = double - expect(controller).to receive(:edit_polymorphic_path).with(["main_app_proxy", "admin", my_resource_item], {}) + expect(controller).to receive(:edit_polymorphic_path).with([:main_app_proxy, :admin, my_resource_item], {}) controller.edit_resource_path(my_resource_item) end end From 42f2adc613401e4c7ca9bfd06b0c7749e63a57d9 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Thu, 6 May 2021 12:15:55 +0200 Subject: [PATCH 11/34] Bump version to v5.0.4 --- CHANGELOG.md | 4 ++++ lib/alchemy/version.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 480b39d161..e94dc6f974 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 5.0.4 (2021-05-06) + +- Use symbols in polymorphic routes for resources [#2087](https://github.com/AlchemyCMS/alchemy_cms/pull/2087) ([tvdeyen](https://github.com/tvdeyen)) + ## 5.0.3 (2021-01-12) - Fix copy element feature [#1996](https://github.com/AlchemyCMS/alchemy_cms/pull/1996) ([tvdeyen](https://github.com/tvdeyen)) diff --git a/lib/alchemy/version.rb b/lib/alchemy/version.rb index 8c2bcc7c3c..9357d61506 100644 --- a/lib/alchemy/version.rb +++ b/lib/alchemy/version.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Alchemy - VERSION = "5.0.3" + VERSION = "5.0.4" def self.version VERSION From 6f0b610583f6295e05b5431c9fb221990f13ff88 Mon Sep 17 00:00:00 2001 From: Antonio Facciolo Date: Fri, 14 May 2021 09:21:49 +0200 Subject: [PATCH 12/34] Fix Essence Picture View (#2083) Allow to render the essence picture view without options / html_options --- .../essences/_essence_picture_view.html.erb | 6 +++--- spec/views/essences/essence_picture_editor_spec.rb | 2 +- spec/views/essences/essence_picture_view_spec.rb | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 spec/views/essences/essence_picture_view_spec.rb diff --git a/app/views/alchemy/essences/_essence_picture_view.html.erb b/app/views/alchemy/essences/_essence_picture_view.html.erb index 3a8950655e..33777f6c8c 100644 --- a/app/views/alchemy/essences/_essence_picture_view.html.erb +++ b/app/views/alchemy/essences/_essence_picture_view.html.erb @@ -1,6 +1,6 @@ <% content = local_assigns[:content] || local_assigns[:essence_picture_view] %> <%= Alchemy::EssencePictureView.new( content, - local_assigns[:options], - local_assigns[:html_options] -).render %> \ No newline at end of file + local_assigns[:options] || {}, + local_assigns[:html_options] || {} +).render %> diff --git a/spec/views/essences/essence_picture_editor_spec.rb b/spec/views/essences/essence_picture_editor_spec.rb index dfc6155ed1..f9575f0c54 100644 --- a/spec/views/essences/essence_picture_editor_spec.rb +++ b/spec/views/essences/essence_picture_editor_spec.rb @@ -2,7 +2,7 @@ require "rails_helper" -describe "essences/_essence_picture_editor" do +describe "alchemy/essences/_essence_picture_editor" do let(:picture) { stub_model(Alchemy::Picture) } let(:essence_picture) do diff --git a/spec/views/essences/essence_picture_view_spec.rb b/spec/views/essences/essence_picture_view_spec.rb new file mode 100644 index 0000000000..8bc418c286 --- /dev/null +++ b/spec/views/essences/essence_picture_view_spec.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +require "rails_helper" + +describe "alchemy/essences/_essence_picture_view" do + let(:picture) { build_stubbed(:alchemy_picture) } + let(:essence) { build_stubbed(:alchemy_essence_picture, picture: picture) } + let(:content) { build_stubbed(:alchemy_content, essence: essence) } + + it "renders when passing only the content" do + render content, content: content + expect(rendered).to have_selector("img") + end +end From a25c729e0a24bea5cf2e3aa64297c76788fe8edf Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Tue, 8 Jun 2021 10:35:41 +0200 Subject: [PATCH 13/34] Only support Ruby < 3.0 --- .github/workflows/ci.yml | 2 +- alchemy_cms.gemspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ed249045dd..c974ff4ef3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,8 +12,8 @@ jobs: - '5.2' - '6.0' ruby: - - '2.5.x' - '2.6.x' + - '2.7.x' database: - mysql - postgresql diff --git a/alchemy_cms.gemspec b/alchemy_cms.gemspec index 74dec0ef7e..124df12812 100644 --- a/alchemy_cms.gemspec +++ b/alchemy_cms.gemspec @@ -13,7 +13,7 @@ Gem::Specification.new do |gem| gem.summary = 'A powerful, userfriendly and flexible CMS for Rails' gem.description = 'Alchemy is a powerful, userfriendly and flexible Rails CMS.' gem.requirements << 'ImageMagick (libmagick), v6.6 or greater.' - gem.required_ruby_version = '>= 2.3.0' + gem.required_ruby_version = '~> 2.3' gem.license = 'BSD New' gem.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^spec/}) } gem.require_paths = ['lib'] From 4cdc69c9c49147e948275c1c6c2dc9c3cf66478d Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Tue, 8 Jun 2021 10:40:09 +0200 Subject: [PATCH 14/34] Use a picture with image in picture view spec. Otherwise a nil exception will be raised from image_tag --- spec/views/essences/essence_picture_view_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/views/essences/essence_picture_view_spec.rb b/spec/views/essences/essence_picture_view_spec.rb index 8bc418c286..717073b2d6 100644 --- a/spec/views/essences/essence_picture_view_spec.rb +++ b/spec/views/essences/essence_picture_view_spec.rb @@ -3,7 +3,7 @@ require "rails_helper" describe "alchemy/essences/_essence_picture_view" do - let(:picture) { build_stubbed(:alchemy_picture) } + let(:picture) { create(:alchemy_picture) } let(:essence) { build_stubbed(:alchemy_essence_picture, picture: picture) } let(:content) { build_stubbed(:alchemy_content, essence: essence) } From 36825d7e4b1a54550c043da59a88d1238625e630 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Tue, 8 Jun 2021 10:01:47 +0200 Subject: [PATCH 15/34] Fixate Dragonfly to < 1.4 1.4 is a breaking release. --- alchemy_cms.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alchemy_cms.gemspec b/alchemy_cms.gemspec index 124df12812..80b2204f9c 100644 --- a/alchemy_cms.gemspec +++ b/alchemy_cms.gemspec @@ -23,7 +23,7 @@ Gem::Specification.new do |gem| gem.add_runtime_dependency 'awesome_nested_set', ['~> 3.1'] gem.add_runtime_dependency 'cancancan', ['>= 2.1', '< 4.0'] gem.add_runtime_dependency 'coffee-rails', ['~> 4.0', '< 5.0'] - gem.add_runtime_dependency 'dragonfly', ['~> 1.0', '>= 1.0.7'] + gem.add_runtime_dependency 'dragonfly', ['~> 1.0', '>= 1.0.7', '< 1.4.0'] gem.add_runtime_dependency 'dragonfly_svg', ['~> 0.0.4'] gem.add_runtime_dependency 'gutentag', ['~> 2.2', '>= 2.2.1'] gem.add_runtime_dependency 'handlebars_assets', ['~> 0.23'] From 03855a5648bb85f4aaea156aaf78e328a461dd88 Mon Sep 17 00:00:00 2001 From: Antonio Facciolo Date: Fri, 4 Jun 2021 17:29:10 +0200 Subject: [PATCH 16/34] expose translations in global Alchemy js object, #2113 --- package/admin.js | 2 ++ package/src/i18n.js | 4 +--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package/admin.js b/package/admin.js index ac4cdad839..4a9cb2d142 100644 --- a/package/admin.js +++ b/package/admin.js @@ -1,4 +1,5 @@ import translate from "./src/i18n" +import translationData from "./src/translations" import NodeTree from "./src/node_tree" // Global Alchemy object @@ -10,5 +11,6 @@ if (typeof window.Alchemy === "undefined") { Object.assign(Alchemy, { // Global utility method for translating a given string t: translate, + translations: Object.assign(Alchemy.translations || {}, translationData), NodeTree }) diff --git a/package/src/i18n.js b/package/src/i18n.js index a96bca74cb..4ebbc13831 100644 --- a/package/src/i18n.js +++ b/package/src/i18n.js @@ -1,5 +1,3 @@ -import translationData from "./translations" - const KEY_SEPARATOR = /\./ function currentLocale() { @@ -11,7 +9,7 @@ function currentLocale() { function getTranslations() { const locale = currentLocale() - const translations = translationData[locale] + const translations = Alchemy.translations[locale] if (translations) { return translations From c021dc34bebb51d8286eb28ae6dadfcbc421282b Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Mon, 7 Jun 2021 16:56:21 +0200 Subject: [PATCH 17/34] Fixes i18n Jest specs They were missing from #2114 --- package/src/__tests__/i18n.spec.js | 23 +++++++++++++++++++++++ package/src/i18n.js | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/package/src/__tests__/i18n.spec.js b/package/src/__tests__/i18n.spec.js index 0f2ffbbeae..2d627298ef 100644 --- a/package/src/__tests__/i18n.spec.js +++ b/package/src/__tests__/i18n.spec.js @@ -15,12 +15,20 @@ describe("translate", () => { }) describe("if translation is present", () => { + beforeEach(() => { + Alchemy.translations = { en: { help: "Help" } } + }) + it("Returns translated string", () => { expect(translate("help")).toEqual("Help") }) describe("if key includes a period", () => { describe("that is translated", () => { + beforeEach(() => { + Alchemy.translations = { en: { formats: { date: "Y-m-d" } } } + }) + it("splits into group", () => { expect(translate("formats.date")).toEqual("Y-m-d") }) @@ -40,6 +48,10 @@ describe("translate", () => { }) describe("if replacement is given", () => { + beforeEach(() => { + Alchemy.translations = { en: { allowed_chars: "of %{number} chars" } } + }) + it("replaces it", () => { expect(translate("allowed_chars", 5)).toEqual("of 5 chars") }) @@ -67,4 +79,15 @@ describe("translate", () => { spy.mockRestore() }) }) + + describe("if Alchemy.translations is not set", () => { + it("Returns passed string and logs a warning", () => { + const spy = jest.spyOn(console, "warn").mockImplementation(() => {}) + expect(translate("help")).toEqual("help") + expect(spy.mock.calls).toEqual([ + ["Translations for locale kl not found!"] + ]) + spy.mockRestore() + }) + }) }) diff --git a/package/src/i18n.js b/package/src/i18n.js index 4ebbc13831..ee987636f9 100644 --- a/package/src/i18n.js +++ b/package/src/i18n.js @@ -9,7 +9,7 @@ function currentLocale() { function getTranslations() { const locale = currentLocale() - const translations = Alchemy.translations[locale] + const translations = Alchemy.translations && Alchemy.translations[locale] if (translations) { return translations From d2879a118d3e6cd8dd7fc7bb046d37e876c60a95 Mon Sep 17 00:00:00 2001 From: dbwinger Date: Wed, 9 Jun 2021 11:31:14 -0400 Subject: [PATCH 18/34] Backport #2115 to v5.0 --- lib/alchemy/upgrader/five_point_zero.rb | 31 +++++++++++++++++++++++++ lib/tasks/alchemy/upgrade.rake | 20 ++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/lib/alchemy/upgrader/five_point_zero.rb b/lib/alchemy/upgrader/five_point_zero.rb index 338df576ea..a5abd211e9 100644 --- a/lib/alchemy/upgrader/five_point_zero.rb +++ b/lib/alchemy/upgrader/five_point_zero.rb @@ -1,9 +1,18 @@ # frozen_string_literal: true require_relative "tasks/harden_gutentag_migrations" +require "rails/generators" +require "thor" +require "alchemy/install/tasks" module Alchemy class Upgrader::FivePointZero < Upgrader + include Rails::Generators::Actions + include Thor::Base + include Thor::Actions + + source_root File.expand_path("../../generators/alchemy/install/files", __dir__) + class << self def install_gutentag_migrations desc "Install Gutentag migrations" @@ -36,6 +45,28 @@ def remove_root_page log "Root page not found.", :skip end end + + def run_webpacker_installer + # Webpacker does not create a package.json, but we need one + unless File.exist? app_root.join("package.json") + in_root { run "echo '{}' > package.json" } + end + new.rake("webpacker:install", abort_on_failure: true) + end + + def add_npm_package + new.run "yarn add @alchemy_cms/admin" + end + + def copy_alchemy_entry_point + webpack_config = YAML.load_file(app_root.join("config", "webpacker.yml"))[Rails.env] + new.copy_file "alchemy_admin.js", + app_root.join(webpack_config["source_path"], webpack_config["source_entry_path"], "alchemy/admin.js") + end + + def app_root + @_app_root ||= Rails.root + end end end end diff --git a/lib/tasks/alchemy/upgrade.rake b/lib/tasks/alchemy/upgrade.rake index 45c134dcc8..0c0831ddb8 100644 --- a/lib/tasks/alchemy/upgrade.rake +++ b/lib/tasks/alchemy/upgrade.rake @@ -42,6 +42,9 @@ namespace :alchemy do "alchemy:upgrade:5.0:install_gutentag_migrations", "alchemy:upgrade:5.0:remove_layout_roots", "alchemy:upgrade:5.0:remove_root_page", + "alchemy:upgrade:5.0:run_webpacker_installer", + "alchemy:upgrade:5.0:add_npm_package", + "alchemy:upgrade:5.0:copy_alchemy_entry_point", ] desc "Install Gutentag migrations" @@ -58,6 +61,23 @@ namespace :alchemy do task remove_root_page: [:environment] do Alchemy::Upgrader::FivePointZero.remove_root_page end + + desc "Run webpacker installer" + task run_webpacker_installer: [:environment] do + Alchemy::Upgrader::FivePointZero.run_webpacker_installer + end + + desc "Add NPM package" + task add_npm_package: [:environment] do + puts "adding npm_package..." + Alchemy::Upgrader::FivePointZero.add_npm_package + end + + desc "Copy alchemy entry point" + task copy_alchemy_entry_point: [:environment] do + puts "copying alchemy entry point" + Alchemy::Upgrader::FivePointZero.copy_alchemy_entry_point + end end end end From 488709cdd04f8dae2a98f0e731326aa2bfc35e7a Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Thu, 8 Jul 2021 20:35:07 +0200 Subject: [PATCH 19/34] Bump NPM package version to 5.0.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c5150b560e..715cfe15ee 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@alchemy_cms/admin", - "version": "0.2.0", + "version": "5.0.4", "description": "AlchemyCMS", "browser": "package/admin.js", "files": [ From 6dc58d60939825ef647db8f189e9e899100d3084 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Wed, 15 Sep 2021 21:21:09 +0200 Subject: [PATCH 20/34] Bump version to v5.0.5 - Backport #2115 to v5.0 [#2126](https://github.com/AlchemyCMS/alchemy_cms/pull/2126) ([dbwinger](https://github.com/dbwinger)) - Fixate Dragonfly to < 1.4 [#2122](https://github.com/AlchemyCMS/alchemy_cms/pull/2122) ([tvdeyen](https://github.com/tvdeyen)) - Backport #2114 to v5.0 [#2118](https://github.com/AlchemyCMS/alchemy_cms/pull/2118) ([afdev82](https://github.com/afdev82)) --- CHANGELOG.md | 6 ++++++ lib/alchemy/version.rb | 2 +- package.json | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e94dc6f974..ca5e00d63d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 5.0.5 (2021-09-15) + +- Backport #2115 to v5.0 [#2126](https://github.com/AlchemyCMS/alchemy_cms/pull/2126) ([dbwinger](https://github.com/dbwinger)) +- Fixate Dragonfly to < 1.4 [#2122](https://github.com/AlchemyCMS/alchemy_cms/pull/2122) ([tvdeyen](https://github.com/tvdeyen)) +- Backport #2114 to v5.0 [#2118](https://github.com/AlchemyCMS/alchemy_cms/pull/2118) ([afdev82](https://github.com/afdev82)) + ## 5.0.4 (2021-05-06) - Use symbols in polymorphic routes for resources [#2087](https://github.com/AlchemyCMS/alchemy_cms/pull/2087) ([tvdeyen](https://github.com/tvdeyen)) diff --git a/lib/alchemy/version.rb b/lib/alchemy/version.rb index 9357d61506..4e1766edae 100644 --- a/lib/alchemy/version.rb +++ b/lib/alchemy/version.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Alchemy - VERSION = "5.0.4" + VERSION = "5.0.5" def self.version VERSION diff --git a/package.json b/package.json index 715cfe15ee..0d5d0cb173 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@alchemy_cms/admin", - "version": "5.0.4", + "version": "5.0.5", "description": "AlchemyCMS", "browser": "package/admin.js", "files": [ From 7167a4ff6f369ab1648c8f9fd3877f594443eb57 Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Thu, 16 Sep 2021 10:40:34 +0200 Subject: [PATCH 21/34] Use self_and_ancestors in page_active? helper This helper used a method that has been removed in #1813. I'm also adding some specs. --- app/helpers/alchemy/pages_helper.rb | 2 +- spec/helpers/alchemy/pages_helper_spec.rb | 31 +++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/app/helpers/alchemy/pages_helper.rb b/app/helpers/alchemy/pages_helper.rb index c98ee22d4c..7bf7ed9b20 100644 --- a/app/helpers/alchemy/pages_helper.rb +++ b/app/helpers/alchemy/pages_helper.rb @@ -100,7 +100,7 @@ def render_menu(menu_type, options = {}) # Returns true if page is in the active branch def page_active?(page) - @_page_ancestors ||= Page.ancestors_for(@page) + @_page_ancestors ||= @page.self_and_ancestors.contentpages @_page_ancestors.include?(page) end diff --git a/spec/helpers/alchemy/pages_helper_spec.rb b/spec/helpers/alchemy/pages_helper_spec.rb index 3d93d5f8e9..e49ab053a8 100644 --- a/spec/helpers/alchemy/pages_helper_spec.rb +++ b/spec/helpers/alchemy/pages_helper_spec.rb @@ -357,5 +357,36 @@ module Alchemy expect(helper.picture_essence_caption(content)).to eq "my caption" end end + + describe "#page_active?" do + let(:child_page) { create(:alchemy_page, parent: public_page) } + + before do + @page = current_page + end + + subject { helper.page_active?(passed_page) } + + context "passed page is the current page" do + let(:passed_page) { public_page } + let(:current_page) { public_page } + + it { is_expected.to be true } + end + + context "passed page is an ancestor of the current page" do + let(:current_page) { child_page } + let(:passed_page) { public_page } + + it { is_expected.to be true } + end + + context "passed page is in another branch of the page tree" do + let(:passed_page) { create(:alchemy_page, parent: language_root) } + let(:current_page) { public_page } + + it { is_expected.to be false } + end + end end end From b63574d00a4efa95b52b513b3b8a7a14c082d3c3 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Fri, 17 Sep 2021 10:48:18 +0200 Subject: [PATCH 22/34] Bump version to v5.0.6 - Use self_and_ancestors in page_active? helper [#2193](https://github.com/AlchemyCMS/alchemy_cms/pull/2193) ([mamhoff](https://github.com/mamhoff)) --- CHANGELOG.md | 4 ++++ lib/alchemy/version.rb | 2 +- package.json | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca5e00d63d..daf6f80732 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 5.0.6 (2021-09-17) + +- Use self_and_ancestors in page_active? helper [#2193](https://github.com/AlchemyCMS/alchemy_cms/pull/2193) ([mamhoff](https://github.com/mamhoff)) + ## 5.0.5 (2021-09-15) - Backport #2115 to v5.0 [#2126](https://github.com/AlchemyCMS/alchemy_cms/pull/2126) ([dbwinger](https://github.com/dbwinger)) diff --git a/lib/alchemy/version.rb b/lib/alchemy/version.rb index 4e1766edae..23dcebc5a9 100644 --- a/lib/alchemy/version.rb +++ b/lib/alchemy/version.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Alchemy - VERSION = "5.0.5" + VERSION = "5.0.6" def self.version VERSION diff --git a/package.json b/package.json index 0d5d0cb173..a990eadf01 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@alchemy_cms/admin", - "version": "5.0.5", + "version": "5.0.6", "description": "AlchemyCMS", "browser": "package/admin.js", "files": [ From 03fe4be836ef14ad59a81f37cbbd3b999463f4af Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Tue, 26 Oct 2021 09:10:58 +0200 Subject: [PATCH 23/34] Make sure to install correct npm package Every Alchemy version has its npm package. During install and upgrading we need to make sure to pick the correct version. --- lib/alchemy/upgrader/five_point_zero.rb | 5 +++-- lib/generators/alchemy/install/install_generator.rb | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/alchemy/upgrader/five_point_zero.rb b/lib/alchemy/upgrader/five_point_zero.rb index a5abd211e9..64b8f96a19 100644 --- a/lib/alchemy/upgrader/five_point_zero.rb +++ b/lib/alchemy/upgrader/five_point_zero.rb @@ -4,6 +4,7 @@ require "rails/generators" require "thor" require "alchemy/install/tasks" +require "alchemy/version" module Alchemy class Upgrader::FivePointZero < Upgrader @@ -12,7 +13,7 @@ class Upgrader::FivePointZero < Upgrader include Thor::Actions source_root File.expand_path("../../generators/alchemy/install/files", __dir__) - + class << self def install_gutentag_migrations desc "Install Gutentag migrations" @@ -55,7 +56,7 @@ def run_webpacker_installer end def add_npm_package - new.run "yarn add @alchemy_cms/admin" + new.run "yarn add @alchemy_cms/admin@~#{Alchemy.version}" end def copy_alchemy_entry_point diff --git a/lib/generators/alchemy/install/install_generator.rb b/lib/generators/alchemy/install/install_generator.rb index 6eb640de3e..51c0f3f867 100644 --- a/lib/generators/alchemy/install/install_generator.rb +++ b/lib/generators/alchemy/install/install_generator.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require "rails/generators" require "alchemy/install/tasks" +require "alchemy/version" module Alchemy module Generators @@ -88,7 +89,7 @@ def run_webpacker_installer end def add_npm_package - run "yarn add @alchemy_cms/admin" + run "yarn add @alchemy_cms/admin@~#{Alchemy.version}" end def copy_alchemy_entry_point From c88f85b1519590cb50a1959b923def05a3e15887 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Tue, 26 Oct 2021 09:36:22 +0200 Subject: [PATCH 24/34] Bump version to v5.0.7 --- CHANGELOG.md | 4 ++++ lib/alchemy/version.rb | 2 +- package.json | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index daf6f80732..6cef4e5507 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 5.0.7 (2021-10-26) + +- Make sure to install correct npm package ([tvdeyen](https://github.com/tvdeyen)) + ## 5.0.6 (2021-09-17) - Use self_and_ancestors in page_active? helper [#2193](https://github.com/AlchemyCMS/alchemy_cms/pull/2193) ([mamhoff](https://github.com/mamhoff)) diff --git a/lib/alchemy/version.rb b/lib/alchemy/version.rb index 23dcebc5a9..20770c16c7 100644 --- a/lib/alchemy/version.rb +++ b/lib/alchemy/version.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Alchemy - VERSION = "5.0.6" + VERSION = "5.0.7" def self.version VERSION diff --git a/package.json b/package.json index a990eadf01..51965deaf7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@alchemy_cms/admin", - "version": "5.0.6", + "version": "5.0.7", "description": "AlchemyCMS", "browser": "package/admin.js", "files": [ From 70f585a559fe4299ec1eb4046669e28bbabb9fe1 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Mon, 15 Nov 2021 10:43:41 +0100 Subject: [PATCH 25/34] Use relative path for tinymce font-face Without that sprockets does not find the font files under some weird circumstances. --- .../tinymce/skins/alchemy/skin.min.css.scss | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/assets/stylesheets/tinymce/skins/alchemy/skin.min.css.scss b/app/assets/stylesheets/tinymce/skins/alchemy/skin.min.css.scss index ec4467346a..11cc8f678d 100755 --- a/app/assets/stylesheets/tinymce/skins/alchemy/skin.min.css.scss +++ b/app/assets/stylesheets/tinymce/skins/alchemy/skin.min.css.scss @@ -1566,18 +1566,18 @@ i.mce-i-resize { @font-face { font-family: 'tinymce'; - src: url('fonts/tinymce.woff') format('woff'), - url('fonts/tinymce.ttf') format('truetype'), - url('fonts/tinymce.svg#tinymce') format('svg'); + src: url('./fonts/tinymce.woff') format('woff'), + url('./fonts/tinymce.ttf') format('truetype'), + url('./fonts/tinymce.svg#tinymce') format('svg'); font-weight: normal; font-style: normal; } @font-face { font-family: 'tinymce-small'; - src: url('fonts/tinymce-small.woff') format('woff'), - url('fonts/tinymce-small.ttf') format('truetype'), - url('fonts/tinymce-small.svg#tinymce') format('svg'); + src: url('./fonts/tinymce-small.woff') format('woff'), + url('./fonts/tinymce-small.ttf') format('truetype'), + url('./fonts/tinymce-small.svg#tinymce') format('svg'); font-weight: normal; font-style: normal; } From 07782a7cd8d13c3462d6ca3d534ddece5620d625 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Tue, 16 Nov 2021 16:32:40 +0100 Subject: [PATCH 26/34] Set stampable user_class_name without root identifier Since Alchemy always prepends a root constant identifier to the user_class_name getter and userstamp (the originator gem) does the same this can lead to wrong constant names under some circumstances. Making sure we never set a root constant identifier by using class.name --- app/models/alchemy/attachment.rb | 2 +- app/models/alchemy/element.rb | 2 +- app/models/alchemy/node.rb | 2 +- app/models/alchemy/page.rb | 2 +- app/models/alchemy/picture.rb | 2 +- lib/alchemy/userstamp.rb | 2 +- spec/libraries/userstamp_spec.rb | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/models/alchemy/attachment.rb b/app/models/alchemy/attachment.rb index 92c75d1b25..ab5ddd5070 100644 --- a/app/models/alchemy/attachment.rb +++ b/app/models/alchemy/attachment.rb @@ -28,7 +28,7 @@ class Attachment < BaseRecord after_assign { |f| write_attribute(:file_mime_type, f.mime_type) } end - stampable stamper_class_name: Alchemy.user_class_name + stampable stamper_class_name: Alchemy.user_class.name has_many :essence_files, class_name: "Alchemy::EssenceFile", foreign_key: "attachment_id" has_many :contents, through: :essence_files diff --git a/app/models/alchemy/element.rb b/app/models/alchemy/element.rb index 4cef90a3b2..b0dcbf97a7 100644 --- a/app/models/alchemy/element.rb +++ b/app/models/alchemy/element.rb @@ -60,7 +60,7 @@ class Element < BaseRecord # acts_as_list scope: [:page_id, :fixed, :parent_element_id] - stampable stamper_class_name: Alchemy.user_class_name + stampable stamper_class_name: Alchemy.user_class.name has_many :contents, dependent: :destroy, inverse_of: :element diff --git a/app/models/alchemy/node.rb b/app/models/alchemy/node.rb index 187c310cf7..3bb20a20ae 100644 --- a/app/models/alchemy/node.rb +++ b/app/models/alchemy/node.rb @@ -7,7 +7,7 @@ class Node < BaseRecord before_destroy :check_if_related_essence_nodes_present acts_as_nested_set scope: "language_id", touch: true - stampable stamper_class_name: Alchemy.user_class_name + stampable stamper_class_name: Alchemy.user_class.name belongs_to :language, class_name: "Alchemy::Language" belongs_to :page, class_name: "Alchemy::Page", optional: true, inverse_of: :nodes diff --git a/app/models/alchemy/page.rb b/app/models/alchemy/page.rb index 669ad7b92c..b16ca06dfe 100644 --- a/app/models/alchemy/page.rb +++ b/app/models/alchemy/page.rb @@ -82,7 +82,7 @@ class Page < BaseRecord acts_as_nested_set(dependent: :destroy, scope: [:layoutpage, :language_id]) - stampable stamper_class_name: Alchemy.user_class_name + stampable stamper_class_name: Alchemy.user_class.name belongs_to :language diff --git a/app/models/alchemy/picture.rb b/app/models/alchemy/picture.rb index 961f14805f..829de0eb83 100644 --- a/app/models/alchemy/picture.rb +++ b/app/models/alchemy/picture.rb @@ -93,7 +93,7 @@ def allowed_filetypes case_sensitive: false, message: Alchemy.t("not a valid image") - stampable stamper_class_name: Alchemy.user_class_name + stampable stamper_class_name: Alchemy.user_class.name scope :named, ->(name) { where("#{table_name}.name LIKE ?", "%#{name}%") } scope :recent, -> { where("#{table_name}.created_at > ?", Time.current - 24.hours).order(:created_at) } diff --git a/lib/alchemy/userstamp.rb b/lib/alchemy/userstamp.rb index f372448261..3b94b99b4e 100644 --- a/lib/alchemy/userstamp.rb +++ b/lib/alchemy/userstamp.rb @@ -7,6 +7,6 @@ if Alchemy.user_class < ActiveRecord::Base Alchemy.user_class.class_eval do model_stamper - stampable stamper_class_name: Alchemy.user_class_name + stampable stamper_class_name: Alchemy.user_class.name end end diff --git a/spec/libraries/userstamp_spec.rb b/spec/libraries/userstamp_spec.rb index 91f6c90f09..be7d1805fa 100644 --- a/spec/libraries/userstamp_spec.rb +++ b/spec/libraries/userstamp_spec.rb @@ -6,7 +6,7 @@ describe ".user_class" do it "injects userstamp class methods" do expect(Alchemy.user_class).to respond_to(:stamper_class_name) - expect(Alchemy.user_class.stamper_class_name).to eq(:"::DummyUser") + expect(Alchemy.user_class.stamper_class_name).to eq(:DummyUser) end end end From e0a8f5a221516006e7429b415928e63f863ace7f Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Wed, 17 Nov 2021 09:47:59 +0100 Subject: [PATCH 27/34] Bump version to v5.0.8 --- CHANGELOG.md | 5 +++++ lib/alchemy/version.rb | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cef4e5507..8d43439a3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 5.0.8 (2021-11-17) + +- Set stampable user_class_name without root identifier ([tvdeyen](https://github.com/tvdeyen)) +- Use relative path for tinymce font-face ([tvdeyen](https://github.com/tvdeyen)) + ## 5.0.7 (2021-10-26) - Make sure to install correct npm package ([tvdeyen](https://github.com/tvdeyen)) diff --git a/lib/alchemy/version.rb b/lib/alchemy/version.rb index 20770c16c7..0c16fc5155 100644 --- a/lib/alchemy/version.rb +++ b/lib/alchemy/version.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Alchemy - VERSION = "5.0.7" + VERSION = "5.0.8" def self.version VERSION From 135827ad37c722f645636d48fad3a03414687620 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Wed, 17 Nov 2021 09:51:02 +0100 Subject: [PATCH 28/34] Bump npm package version to v5.0.8 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 51965deaf7..2806b7efe5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@alchemy_cms/admin", - "version": "5.0.7", + "version": "5.0.8", "description": "AlchemyCMS", "browser": "package/admin.js", "files": [ From 48b29fc8ef4c679d06622855af13d21556c80c92 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Tue, 23 Nov 2021 18:28:37 +0100 Subject: [PATCH 29/34] Adjust tinymce skin assets urls again Thanks to another breaking release of sprockets-rails (3.4.0) all urls are now assumed to be absolute, but without the leading slash. --- .../tinymce/skins/alchemy/content.min.css.scss | 6 +++--- .../tinymce/skins/alchemy/skin.min.css.scss | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/assets/stylesheets/tinymce/skins/alchemy/content.min.css.scss b/app/assets/stylesheets/tinymce/skins/alchemy/content.min.css.scss index a6cd0f8d0c..8526e000fb 100644 --- a/app/assets/stylesheets/tinymce/skins/alchemy/content.min.css.scss +++ b/app/assets/stylesheets/tinymce/skins/alchemy/content.min.css.scss @@ -30,7 +30,7 @@ td,th { .mce-object { border: 1px dotted #3a3a3a; - background: #d5d5d5 url(img/object.gif) no-repeat center; + background: #d5d5d5 url('tinymce/skins/alchemy/fonts/img/object.gif') no-repeat center; } .mce-pagebreak { @@ -55,7 +55,7 @@ td,th { width: 9px!important; height: 9px!important; border: 1px dotted #3a3a3a; - background: #d5d5d5 url(img/anchor.gif) no-repeat center; + background: #d5d5d5 url('tinymce/skins/alchemy/fonts/img/anchor.gif') no-repeat center; } .mce-nbsp { @@ -77,7 +77,7 @@ hr { } .mce-spellchecker-word { - background: url(img/wline.gif) repeat-x bottom left; + background: url('tinymce/skins/alchemy/fonts/img/wline.gif') repeat-x bottom left; cursor: default; } diff --git a/app/assets/stylesheets/tinymce/skins/alchemy/skin.min.css.scss b/app/assets/stylesheets/tinymce/skins/alchemy/skin.min.css.scss index 11cc8f678d..22420f5734 100755 --- a/app/assets/stylesheets/tinymce/skins/alchemy/skin.min.css.scss +++ b/app/assets/stylesheets/tinymce/skins/alchemy/skin.min.css.scss @@ -1561,23 +1561,23 @@ i.mce-i-resize { opacity: 0.6; filter: alpha(opacity=60); zoom: 1; - background: #fff url('img/loader.gif') no-repeat center center; + background: #fff url('tinymce/skins/alchemy/fonts/img/loader.gif') no-repeat center center; } @font-face { font-family: 'tinymce'; - src: url('./fonts/tinymce.woff') format('woff'), - url('./fonts/tinymce.ttf') format('truetype'), - url('./fonts/tinymce.svg#tinymce') format('svg'); + src: url('tinymce/skins/alchemy/fonts/tinymce.woff') format('woff'), + url('tinymce/skins/alchemy/fonts/tinymce.ttf') format('truetype'), + url('tinymce/skins/alchemy/fonts/tinymce.svg#tinymce') format('svg'); font-weight: normal; font-style: normal; } @font-face { font-family: 'tinymce-small'; - src: url('./fonts/tinymce-small.woff') format('woff'), - url('./fonts/tinymce-small.ttf') format('truetype'), - url('./fonts/tinymce-small.svg#tinymce') format('svg'); + src: url('tinymce/skins/alchemy/fonts/tinymce-small.woff') format('woff'), + url('tinymce/skins/alchemy/fonts/tinymce-small.ttf') format('truetype'), + url('tinymce/skins/alchemy/fonts/tinymce-small.svg#tinymce') format('svg'); font-weight: normal; font-style: normal; } From 5a0d40240ca6c8d44a9e661b7d0949e78db67bfc Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Wed, 24 Nov 2021 09:42:11 +0100 Subject: [PATCH 30/34] Bump version to v5.0.9 - Adjust tinymce skin assets urls again ([tvdeyen](https://github.com/tvdeyen)) --- CHANGELOG.md | 4 ++++ lib/alchemy/version.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d43439a3d..a95b7c2e54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 5.0.9 (2021-11-24) + +- Adjust tinymce skin assets urls again ([tvdeyen](https://github.com/tvdeyen)) + ## 5.0.8 (2021-11-17) - Set stampable user_class_name without root identifier ([tvdeyen](https://github.com/tvdeyen)) diff --git a/lib/alchemy/version.rb b/lib/alchemy/version.rb index 0c16fc5155..094e079b41 100644 --- a/lib/alchemy/version.rb +++ b/lib/alchemy/version.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Alchemy - VERSION = "5.0.8" + VERSION = "5.0.9" def self.version VERSION From d4cd17a8f92411b0b755cd56fb1c8a4bc36b42b0 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Wed, 24 Nov 2021 09:48:01 +0100 Subject: [PATCH 31/34] Bump npm package --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2806b7efe5..0b3ad1d5aa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@alchemy_cms/admin", - "version": "5.0.8", + "version": "5.0.9", "description": "AlchemyCMS", "browser": "package/admin.js", "files": [ From 7a148b3eb4e8944b6059f8241cb37bca71b98e97 Mon Sep 17 00:00:00 2001 From: Benjamin Behr Date: Wed, 24 Nov 2021 16:54:52 +0100 Subject: [PATCH 32/34] make the admin error tracker customizable Alchemy doesn't support other error trackers than Airbrake. We need to be able to add our own error tracker to catch errors thrown while using the Alchemy admin backend. --- app/controllers/alchemy/admin/base_controller.rb | 12 +++++++++--- lib/alchemy/engine.rb | 7 +++++++ lib/alchemy/error_tracking.rb | 14 ++++++++++++++ lib/alchemy/error_tracking/airbrake_handler.rb | 13 +++++++++++++ lib/alchemy_cms.rb | 1 + .../alchemy/admin/base_controller_spec.rb | 13 +++++++++++++ 6 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 lib/alchemy/error_tracking.rb create mode 100644 lib/alchemy/error_tracking/airbrake_handler.rb diff --git a/app/controllers/alchemy/admin/base_controller.rb b/app/controllers/alchemy/admin/base_controller.rb index 63a0a4e34e..47f8d76ee1 100644 --- a/app/controllers/alchemy/admin/base_controller.rb +++ b/app/controllers/alchemy/admin/base_controller.rb @@ -40,9 +40,7 @@ def set_layout def exception_handler(error) exception_logger(error) show_error_notice(error) - if defined?(Airbrake) - notify_airbrake(error) unless Rails.env.development? || Rails.env.test? - end + notify_error_tracker(error) end # Displays an error notice in the Alchemy backend. @@ -147,6 +145,14 @@ def current_alchemy_site site end end + + def notify_error_tracker(exception) + if ::Alchemy::ErrorTracking.notification_handler.respond_to?(:call) + ::Alchemy::ErrorTracking.notification_handler.call(exception) + else + Rails.logger.warn("To use the Alchemy::ErrorTracking.notification_handler, it must respond to #call.") + end + end end end end diff --git a/lib/alchemy/engine.rb b/lib/alchemy/engine.rb index 08b2ad8e64..2ef7cb9c7f 100644 --- a/lib/alchemy/engine.rb +++ b/lib/alchemy/engine.rb @@ -43,5 +43,12 @@ class Engine < Rails::Engine config.after_initialize do require_relative "./userstamp" end + + initializer "alchemy.error_tracking" do + if defined?(Airbrake) + require_relative "error_tracking/airbrake_handler" + Alchemy::ErrorTracking.notification_handler = Alchemy::ErrorTracking::AirbrakeHandler + end + end end end diff --git a/lib/alchemy/error_tracking.rb b/lib/alchemy/error_tracking.rb new file mode 100644 index 0000000000..c5d836a07e --- /dev/null +++ b/lib/alchemy/error_tracking.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +module Alchemy + module ErrorTracking + class BaseHandler + def self.call(exception) + # implement your own notification method + end + end + + mattr_accessor :notification_handler + @@notification_handler = BaseHandler + end +end diff --git a/lib/alchemy/error_tracking/airbrake_handler.rb b/lib/alchemy/error_tracking/airbrake_handler.rb new file mode 100644 index 0000000000..61fa4e0a33 --- /dev/null +++ b/lib/alchemy/error_tracking/airbrake_handler.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Alchemy + module ErrorTracking + class AirbrakeHandler < BaseHandler + def self.call(exception) + return if ["development", "test"].include?(Rails.env) + + notify_airbrake(exception) + end + end + end +end diff --git a/lib/alchemy_cms.rb b/lib/alchemy_cms.rb index 5cd6e4712c..963bf660ad 100644 --- a/lib/alchemy_cms.rb +++ b/lib/alchemy_cms.rb @@ -38,6 +38,7 @@ module Alchemy require_relative "alchemy/controller_actions" require_relative "alchemy/deprecation" require_relative "alchemy/elements_finder" +require_relative "alchemy/error_tracking" require_relative "alchemy/errors" require_relative "alchemy/essence" require_relative "alchemy/filetypes" diff --git a/spec/controllers/alchemy/admin/base_controller_spec.rb b/spec/controllers/alchemy/admin/base_controller_spec.rb index cce76cd11a..2180245e51 100644 --- a/spec/controllers/alchemy/admin/base_controller_spec.rb +++ b/spec/controllers/alchemy/admin/base_controller_spec.rb @@ -75,5 +75,18 @@ expect(assigns(:locked_pages).pluck(:name)).to eq(["Page 2", "Page 1"]) end end + + describe "#notify_error_tracker" do + it "does not throw an error if the proc is nil" do + allow(Alchemy::ErrorTracking).to receive(:notification_handler).and_return(nil) + expect { controller.send(:notify_error_tracker, StandardError.new) }.not_to raise_error + end + + it "calls error notification handler" do + error = StandardError.new + expect(Alchemy::ErrorTracking.notification_handler).to receive(:call).with(error) + controller.send(:notify_error_tracker, error) + end + end end end From 5240ddec5abd7d7431f0c1d8b0d8522b8ccd7030 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Tue, 25 May 2021 10:35:10 +0200 Subject: [PATCH 33/34] Add crop_resize Dragonfly processor The build in thumb processor does not support to resize the image after it has been cropped. In order to make it work in dragonfly 1.4 we add our own processor. Signed-off-by: Thomas von Deyen --- alchemy_cms.gemspec | 2 +- app/models/alchemy/picture/transformations.rb | 6 ++-- config/initializers/dragonfly.rb | 8 +++++ .../dragonfly/processors/crop_resize.rb | 35 +++++++++++++++++++ .../dragonfly/processors/crop_resize_spec.rb | 23 ++++++++++++ spec/models/alchemy/picture_url_spec.rb | 4 +-- spec/support/dragonfly_test_app.rb | 8 +++++ 7 files changed, 80 insertions(+), 6 deletions(-) create mode 100644 lib/alchemy/dragonfly/processors/crop_resize.rb create mode 100644 spec/libraries/dragonfly/processors/crop_resize_spec.rb create mode 100644 spec/support/dragonfly_test_app.rb diff --git a/alchemy_cms.gemspec b/alchemy_cms.gemspec index 80b2204f9c..f37922d216 100644 --- a/alchemy_cms.gemspec +++ b/alchemy_cms.gemspec @@ -23,7 +23,7 @@ Gem::Specification.new do |gem| gem.add_runtime_dependency 'awesome_nested_set', ['~> 3.1'] gem.add_runtime_dependency 'cancancan', ['>= 2.1', '< 4.0'] gem.add_runtime_dependency 'coffee-rails', ['~> 4.0', '< 5.0'] - gem.add_runtime_dependency 'dragonfly', ['~> 1.0', '>= 1.0.7', '< 1.4.0'] + gem.add_runtime_dependency 'dragonfly', ['~> 1.4'] gem.add_runtime_dependency 'dragonfly_svg', ['~> 0.0.4'] gem.add_runtime_dependency 'gutentag', ['~> 2.2', '>= 2.2.1'] gem.add_runtime_dependency 'handlebars_assets', ['~> 0.23'] diff --git a/app/models/alchemy/picture/transformations.rb b/app/models/alchemy/picture/transformations.rb index e3c59cf40e..381e526fc5 100644 --- a/app/models/alchemy/picture/transformations.rb +++ b/app/models/alchemy/picture/transformations.rb @@ -241,12 +241,12 @@ def center_crop(dimensions, upsample) # Use imagemagick to custom crop an image. Uses -thumbnail for better performance when resizing. # def xy_crop_resize(dimensions, top_left, crop_dimensions, upsample) - crop_argument = "-crop #{dimensions_to_string(crop_dimensions)}" + crop_argument = dimensions_to_string(crop_dimensions) crop_argument += "+#{top_left[:x]}+#{top_left[:y]}" - resize_argument = "-resize #{dimensions_to_string(dimensions)}" + resize_argument = dimensions_to_string(dimensions) resize_argument += ">" unless upsample - image_file.convert "#{crop_argument} #{resize_argument}" + image_file.crop_resize(crop_argument, resize_argument) end # Used when centercropping. diff --git a/config/initializers/dragonfly.rb b/config/initializers/dragonfly.rb index 786b23a6b5..b5f28a47fc 100644 --- a/config/initializers/dragonfly.rb +++ b/config/initializers/dragonfly.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true require "dragonfly_svg" +require "alchemy/dragonfly/processors/crop_resize" # Logger Dragonfly.logger = Rails.logger @@ -9,3 +10,10 @@ ActiveRecord::Base.extend Dragonfly::Model ActiveRecord::Base.extend Dragonfly::Model::Validations end + +# Dragonfly 1.4.0 only allows `quality` as argument to `encode` +Dragonfly::ImageMagick::Processors::Encode::WHITELISTED_ARGS << "flatten" + +Rails.application.config.after_initialize do + Dragonfly.app(:alchemy_pictures).add_processor(:crop_resize, Alchemy::Dragonfly::Processors::CropResize.new) +end diff --git a/lib/alchemy/dragonfly/processors/crop_resize.rb b/lib/alchemy/dragonfly/processors/crop_resize.rb new file mode 100644 index 0000000000..be664ddf9d --- /dev/null +++ b/lib/alchemy/dragonfly/processors/crop_resize.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require "dragonfly/image_magick/commands" + +module Alchemy + module Dragonfly + module Processors + class CropResize + include ::Dragonfly::ParamValidators + + IS_CROP_ARGUMENT = ->(args_string) { + args_string.match?(::Dragonfly::ImageMagick::Processors::Thumb::CROP_GEOMETRY) + } + + IS_RESIZE_ARGUMENT = ->(args_string) { + args_string.match?(::Dragonfly::ImageMagick::Processors::Thumb::RESIZE_GEOMETRY) + } + + def call(content, crop_argument, resize_argument) + validate!(crop_argument, &IS_CROP_ARGUMENT) + validate!(resize_argument, &IS_RESIZE_ARGUMENT) + ::Dragonfly::ImageMagick::Commands.convert( + content, + "-crop #{crop_argument} -resize #{resize_argument}" + ) + end + + def update_url(attrs, _args = "", opts = {}) + format = opts["format"] + attrs.ext = format if format + end + end + end + end +end diff --git a/spec/libraries/dragonfly/processors/crop_resize_spec.rb b/spec/libraries/dragonfly/processors/crop_resize_spec.rb new file mode 100644 index 0000000000..ff61fd9a5e --- /dev/null +++ b/spec/libraries/dragonfly/processors/crop_resize_spec.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +require "rails_helper" +require_relative "../../../support/dragonfly_test_app" + +RSpec.describe Alchemy::Dragonfly::Processors::CropResize do + let(:app) { dragonfly_test_app } + let(:file) { Pathname.new(File.expand_path("../../../fixtures/80x60.png", __dir__)) } + let(:image) { Dragonfly::Content.new(app, file) } + let(:processor) { described_class.new } + + it "validates bad crop and resize arguments" do + expect { + processor.call(image, "h4ck", "m3") + }.to raise_error(Dragonfly::ParamValidators::InvalidParameter) + end + + it "works with correct crop and resize arguments" do + expect { + processor.call(image, "4x4+0+0", "20x20>") + }.to_not raise_error + end +end diff --git a/spec/models/alchemy/picture_url_spec.rb b/spec/models/alchemy/picture_url_spec.rb index 8bf3a33c9d..c61f2c558a 100644 --- a/spec/models/alchemy/picture_url_spec.rb +++ b/spec/models/alchemy/picture_url_spec.rb @@ -9,7 +9,7 @@ module Alchemy # Helper to dedoce a hashed dragonfly job def decode_dragon_fly_job(url) job = url.split("/")[2] - Dragonfly::Serializer.json_b64_decode(job) + ::Dragonfly::Serializer.json_b64_decode(job) end let(:image) do @@ -96,7 +96,7 @@ def decode_dragon_fly_job(url) it "crops and resizes the picture" do job = decode_dragon_fly_job(url) - expect(job[1]).to include("-crop 123x44+0+0 -resize 160x120>") + expect(job[1]).to include("crop_resize").and include("123x44+0+0").and include("160x120>") end end end diff --git a/spec/support/dragonfly_test_app.rb b/spec/support/dragonfly_test_app.rb new file mode 100644 index 0000000000..ddf38f2048 --- /dev/null +++ b/spec/support/dragonfly_test_app.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +def dragonfly_test_app(name = nil) + app = Dragonfly::App.instance(name) + app.datastore = Dragonfly::MemoryDataStore.new + app.secret = "test secret" + app +end From 325d500ede685f561b4826d8010d1f7eb07e0432 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Mon, 28 Feb 2022 20:59:49 +0100 Subject: [PATCH 34/34] Bump version to v5.0.10 --- CHANGELOG.md | 4 ++++ lib/alchemy/version.rb | 2 +- package.json | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a95b7c2e54..d7ebd4a826 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 5.0.10 (2022-02-28) + +- Add crop_resize Dragonfly processor ([tvdeyen](https://github.com/tvdeyen)) + ## 5.0.9 (2021-11-24) - Adjust tinymce skin assets urls again ([tvdeyen](https://github.com/tvdeyen)) diff --git a/lib/alchemy/version.rb b/lib/alchemy/version.rb index 094e079b41..7c97f6beb7 100644 --- a/lib/alchemy/version.rb +++ b/lib/alchemy/version.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Alchemy - VERSION = "5.0.9" + VERSION = "5.0.10" def self.version VERSION diff --git a/package.json b/package.json index 0b3ad1d5aa..52cea22f25 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@alchemy_cms/admin", - "version": "5.0.9", + "version": "5.0.10", "description": "AlchemyCMS", "browser": "package/admin.js", "files": [