Skip to content

Commit

Permalink
Merge pull request #39 from sascha-karnatz/update-alchemy-7
Browse files Browse the repository at this point in the history
Update to Alchemy 7.0
  • Loading branch information
tvdeyen authored Sep 1, 2023
2 parents ec6ae1e + d64dbac commit 1b6bafb
Show file tree
Hide file tree
Showing 41 changed files with 587 additions and 732 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7
ruby-version: 3.2
bundler-cache: true
- name: Prepare database
run: bundle exec rake alchemy:spec:prepare
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Gemfile.lock
spec/dummy/log/*.log
spec/dummy/db/*.sqlite3*
spec/dummy/tmp/*
spec/dummy/public/*
spec/dummy/uploads/*
.ruby-*
node_modules
yarn.lock
Expand Down
8 changes: 3 additions & 5 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ source "https://rubygems.org"

gemspec

gem "rails", "~> 6.0.0"
ENV.fetch("ALCHEMY_BRANCH", "6.1-stable").tap do |branch|
gem "alchemy_cms", github: "AlchemyCMS/alchemy_cms", branch: branch
end
gem "rails", "~> 7.0.0"
gem "alchemy_cms", "~> 7.0.0"

gem "sassc-rails"
gem "sassc", "~> 2.4.0"
gem "webpacker"
gem "pg", "~> 1.0"
gem "puma"

Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ $ bin/rails g alchemy:pg_search:install

## Usage

Every `EssenceText`, `EssenceRichtext` and `EssencePicture` will be indexed unless you tell Alchemy to not index a specific content.
Every `Ingredient` will be indexed unless you tell Alchemy to not index a specific content.

### Disable Indexing

Expand All @@ -51,7 +51,7 @@ Pass `searchable: false` to your element definitions and Alchemy will not index
- name: secret_sauce
searchable: false
ingredients:
- name: sauce
- role: sauce
type: Text
default: 'This is my secret sauce.'
```
Expand All @@ -63,9 +63,9 @@ Pass `searchable: false` to your content definitions and Alchemy will not index
```yaml
# elements.yml
- name: secrets
contents:
- name: passwords
type: EssenceText
ingredients:
- role: passwords
type: Text
searchable: false
default: 'This is my secret password.'
```
Expand All @@ -76,7 +76,7 @@ The same works for `ingredients` as well
# elements.yml
- name: secrets
ingredients:
- name: passwords
- role: passwords
type: Text
searchable: false
default: 'This is my secret password.'
Expand Down
2 changes: 1 addition & 1 deletion alchemy-pg_search.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^spec/}) }
spec.require_paths = ["lib"]

spec.add_runtime_dependency "alchemy_cms", [">= 6.1", "< 7"]
spec.add_runtime_dependency "alchemy_cms", [">= 7.0", "< 8"]
spec.add_runtime_dependency "pg_search", ["~> 2.1"]
spec.add_runtime_dependency "pg"

Expand Down
19 changes: 0 additions & 19 deletions app/extensions/alchemy/pg_search/content_extension.rb

This file was deleted.

19 changes: 0 additions & 19 deletions app/extensions/alchemy/pg_search/essence_picture_extension.rb

This file was deleted.

20 changes: 0 additions & 20 deletions app/extensions/alchemy/pg_search/essence_richtext_extension.rb

This file was deleted.

19 changes: 0 additions & 19 deletions app/extensions/alchemy/pg_search/essence_text_extension.rb

This file was deleted.

19 changes: 14 additions & 5 deletions app/extensions/alchemy/pg_search/ingredient_extension.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
module Alchemy::PgSearch::IngredientExtension
def self.prepended(base)
base.include PgSearch::Model
base.multisearchable(

def self.multisearch_config
{
against: [
:value,
],
additional_attributes: ->(ingredient) { { page_id: ingredient.element.page.id } },
if: :searchable?,
)
if: :searchable?
}
end

def self.prepended(base)
base.include PgSearch::Model
base.multisearchable(multisearch_config)
end

def searchable?
Expand All @@ -17,4 +22,8 @@ def searchable?
end
end

# add the PgSearch model to all ingredients
Alchemy::Ingredient.prepend(Alchemy::PgSearch::IngredientExtension)

# only enable the search for Text, Richtext, and Picture
Alchemy::Ingredients::Picture.multisearchable(Alchemy::PgSearch::IngredientExtension.multisearch_config.merge({against: [:caption]}))
15 changes: 4 additions & 11 deletions lib/alchemy-pg_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,11 @@ module PgSearch
extend Config

##
# is essence or ingredient searchable?
# @param essence_type [string]
# is ingredient searchable?
# @param ingredient_type [string]
# @return [boolean]
def self.is_searchable?(essence_type)
SEARCHABLE_INGREDIENTS.include?(essence_type.gsub(/Alchemy::(Essence|Ingredients::)/, ""))
end

##
# generate an array of all supported essences classes
# @return [array]
def self.searchable_essence_classes
SEARCHABLE_INGREDIENTS.map { |k| "Alchemy::Essence#{k.classify}".constantize }
def self.is_searchable?(ingredient_type)
SEARCHABLE_INGREDIENTS.include?(ingredient_type.gsub(/Alchemy::Ingredients::/, ""))
end

##
Expand Down
14 changes: 5 additions & 9 deletions lib/alchemy/pg_search/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Search
##
# index all supported Alchemy models
def self.rebuild
([Alchemy::Page, Alchemy::Ingredient] + Alchemy::PgSearch.searchable_essence_classes).each do |model|
[Alchemy::Page, Alchemy::Ingredient].each do |model|
::PgSearch::Multisearch.rebuild(model)
end
end
Expand All @@ -19,20 +19,16 @@ def self.remove_page(page)
end

##
# index a single page and indexable essences
# index a single page and indexable ingredients
#
# @param page [Alchemy::Page]
def self.index_page(page)
remove_page page

page.update_pg_search_document
page.all_elements.includes(:ingredients, contents: :essence).find_each do |element|
element.contents.each do |content|
content.essence.update_pg_search_document if Alchemy::PgSearch.is_searchable?(content.essence_type)
end

element.ingredients.each do |ingredient|
ingredient.update_pg_search_document if Alchemy::PgSearch.is_searchable?(ingredient.type)
page.all_elements.includes(:ingredients).find_each do |element|
element.ingredients.select { |i| Alchemy::PgSearch.is_searchable?(i.type) }.each do |ingredient|
ingredient.update_pg_search_document
end
end
end
Expand Down
1 change: 0 additions & 1 deletion spec/dummy/app/javascript/packs/alchemy/admin.js

This file was deleted.

18 changes: 0 additions & 18 deletions spec/dummy/app/javascript/packs/application.js

This file was deleted.

18 changes: 0 additions & 18 deletions spec/dummy/bin/webpack

This file was deleted.

18 changes: 0 additions & 18 deletions spec/dummy/bin/webpack-dev-server

This file was deleted.

4 changes: 3 additions & 1 deletion spec/dummy/config.ru
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# This file is used by Rack-based servers to start the application.

require ::File.expand_path('../config/environment', __FILE__)
require_relative "config/environment"

run Rails.application
Rails.application.load_server
12 changes: 6 additions & 6 deletions spec/dummy/config/alchemy/config.yml.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ items_per_page: 15
#
# Example:
# - name: some_element
# contents:
# - name: some_picture
# type: EssencePicture
# ingredients:
# - role: some_picture
# type: Picture
# settings:
# hint: true
# crop: true # turns on image cropping
Expand All @@ -82,7 +82,7 @@ items_per_page: 15
# preprocess_image_resize [String] # Use this option to resize images to the given size when they are uploaded to the image library. Downsizing example: '1000x1000>' (Default nil)
# image_output_format [String] # The global image output format setting. (Default +original+)
#
# NOTE: You can always override the output format in the settings of your Essence in elements.yml, I.E. {format: 'gif'}
# NOTE: You can always override the output format in the settings of your ingredients in elements.yml, I.E. {format: 'gif'}
#
output_image_jpg_quality: 85
preprocess_image_resize:
Expand All @@ -91,7 +91,7 @@ image_output_format: original
# This is used by the seeder to create the default site.
default_site:
name: Default Site
host: '*'
host: "*"

# This is the default language when seeding.
default_language:
Expand Down Expand Up @@ -191,7 +191,7 @@ link_target_options: [blank]
# === Format matchers
#
# Named aliases for regular expressions that can be used in various places.
# The most common use case is the format validation of essences, or attribute validations of your individual models.
# The most common use case is the format validation of ingredients, or attribute validations of your individual models.
#
# == Example:
#
Expand Down
Loading

0 comments on commit 1b6bafb

Please sign in to comment.