Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce ingredients as new content structure #2061

Merged
merged 57 commits into from
Jul 1, 2021
Merged
Changes from 1 commit
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
5ac5be3
Add Alchemy::Ingredient model
tvdeyen Apr 8, 2021
cf15c5d
Add a Text Ingredient class
tvdeyen Apr 8, 2021
774568f
Add ingredient_attributes class methods to ingredient
tvdeyen Apr 8, 2021
c8a9408
Add more ingredient classes
tvdeyen Apr 8, 2021
1aac6f1
Add File ingredient
tvdeyen Apr 8, 2021
1172261
Add Node and Page ingredients
tvdeyen Apr 8, 2021
a17dfd7
Add Picture ingredient class
tvdeyen Apr 8, 2021
e85957d
Add Richtext ingredient
tvdeyen Apr 8, 2021
b71a93b
Typecast boolean and datetime ingredients
tvdeyen Apr 8, 2021
cd1bf39
Add preview_text to ingredient classes
tvdeyen Apr 8, 2021
d35e875
Return related object from ingredient if present
tvdeyen Apr 8, 2021
ca0e05e
Add has_many ingredients relation to element
tvdeyen Apr 9, 2021
5222d53
Add settings and partial name to Ingredient model
tvdeyen Apr 12, 2021
64320a7
Add predicate methods to ingredient class
tvdeyen Apr 12, 2021
add3f1b
Add hints to Ingredient class
tvdeyen Apr 12, 2021
b1ed76f
Add IngredientEditor
tvdeyen Apr 12, 2021
94f445e
Add ingredient views
tvdeyen Apr 12, 2021
3779b58
Add thumbnail_url to picture ingredient
tvdeyen Apr 14, 2021
2b06cc2
Allow translated ingredient default text
tvdeyen Apr 14, 2021
1e353b4
Update picture ingredient to latest essence picture changes
tvdeyen May 25, 2021
52ab28a
Rewrite ingredient_attributes to class attribute
tvdeyen May 25, 2021
69f2f2f
Adds admin ingredients controller
tvdeyen May 25, 2021
093de6f
Render ingredient editors
tvdeyen Apr 10, 2021
e6e1745
Add Headline ingredient
tvdeyen May 26, 2021
1ac49d7
Update headline partials
tvdeyen May 26, 2021
2ff6fca
Add audio and video ingredients
tvdeyen May 26, 2021
e241902
Add ingredients elements to page layout
tvdeyen May 26, 2021
61d345e
Add custom tinymce config feature to ingredients
tvdeyen May 26, 2021
cae0aad
Add ingredient scopes
tvdeyen May 26, 2021
fd0dd8c
Add has_tinymce? to ingredient
tvdeyen May 26, 2021
4ea76c6
Init tinymce editor for ingredients
tvdeyen May 26, 2021
54e5108
Add *_id methods for related_object_alias
tvdeyen May 28, 2021
4a0e93b
Use fields_for for ingredient editor partials
tvdeyen May 28, 2021
45f8e68
Set related object type when we set the id
tvdeyen May 28, 2021
0e4390e
Remove nonsense spec
tvdeyen Jun 7, 2021
79a9301
Autoformat elements controller spec
tvdeyen Jun 7, 2021
c3f5c9a
Update elements generator for ingredients
tvdeyen Jun 7, 2021
25015a9
Add templates for elements with ingredients
tvdeyen Jun 7, 2021
5e3dd08
Support ingredients in block level helpers
tvdeyen Jun 10, 2021
9efffd4
Make sure to persist ingredient values
tvdeyen Jun 10, 2021
172038e
Add ingredient validations
tvdeyen Jun 10, 2021
210e3c6
Display ingredient validation errors on element editor
tvdeyen Jun 10, 2021
6684d2f
Use CropAction concern in admin ingredients controller
tvdeyen Jun 25, 2021
4d2a437
Use "having picture thumbnails" on picture ingredient
tvdeyen Jun 25, 2021
ff5dffb
Make link dialog work with ingredients
tvdeyen Jun 27, 2021
373a30b
Do not create contents if ingredients are defined as well
tvdeyen Jun 28, 2021
796aec1
Add rake task to migrate elements to ingredients
tvdeyen Jun 28, 2021
c5ea77a
Show element editor if element has no contents but ingredients defined
tvdeyen Jun 28, 2021
c71efbe
Add ingredient generator
tvdeyen Jun 28, 2021
2eb7895
Touch element on changing ingredients
mamhoff Jun 29, 2021
c642161
Destroy contents in migrator
mamhoff Jun 29, 2021
228d73e
Duplicate ingredients with Elements
mamhoff Jun 29, 2021
eb38d58
Pick Ingredients first in ElementBlockHelper
mamhoff Jun 29, 2021
42c2e4d
Use Rails' store_accessor for ingredients data
tvdeyen Jun 29, 2021
c322280
Eager load ingredients in admin and API controllers
tvdeyen Jun 29, 2021
57dc0fb
Update brakeman ignores
tvdeyen Jun 29, 2021
9234ecd
Add an ingredient factory
tvdeyen Jun 30, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add audio and video ingredients
  • Loading branch information
tvdeyen committed Jun 28, 2021
commit 2ff6fca2c7f1614a51ca6150224c4efda22c9e23
30 changes: 30 additions & 0 deletions app/models/alchemy/ingredients/audio.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

module Alchemy
module Ingredients
# A audio attachment
#
class Audio < Alchemy::Ingredient
self.ingredient_attributes = %i[
autoplay
controls
loop
muted
]

related_object_alias :attachment

delegate :name, to: :attachment, allow_nil: true

# The first 30 characters of the attachments name
#
# Used by the Element#preview_text method.
#
# @param [Integer] max_length (30)
#
def preview_text(max_length = 30)
name.to_s[0..max_length - 1]
end
end
end
end
34 changes: 34 additions & 0 deletions app/models/alchemy/ingredients/video.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: true

module Alchemy
module Ingredients
# A video attachment
#
class Video < Alchemy::Ingredient
self.ingredient_attributes = %i[
allow_fullscreen
autoplay
controls
height
loop
muted
preload
width
]

related_object_alias :attachment

delegate :name, to: :attachment, allow_nil: true

# The first 30 characters of the attachments name
#
# Used by the Element#preview_text method.
#
# @param [Integer] max_length (30)
#
def preview_text(max_length = 30)
name.to_s[0..max_length - 1]
end
end
end
end
5 changes: 5 additions & 0 deletions app/views/alchemy/ingredients/_audio_editor.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%= render(
"alchemy/ingredients/file_editor",
file_editor_counter: audio_editor_counter,
file_editor: audio_editor
) %>
14 changes: 14 additions & 0 deletions app/views/alchemy/ingredients/_audio_view.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<%- if audio_view.attachment -%>
<%= content_tag :audio,
controls: audio_view.controls,
autoplay: audio_view.autoplay,
loop: audio_view.loop,
muted: audio_view.muted do %>
<%= tag :source,
src: alchemy.show_attachment_path(
audio_view.attachment,
format: audio_view.attachment.suffix
),
type: audio_view.attachment.file_mime_type %>
<% end %>
<%- end -%>
5 changes: 5 additions & 0 deletions app/views/alchemy/ingredients/_video_editor.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%= render(
"alchemy/ingredients/file_editor",
file_editor_counter: video_editor_counter,
file_editor: video_editor
) %>
17 changes: 17 additions & 0 deletions app/views/alchemy/ingredients/_video_view.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<%- if video_view.attachment -%>
<%= content_tag :video,
controls: video_view.controls,
autoplay: video_view.autoplay,
loop: video_view.loop,
muted: video_view.muted,
preload: video_view.preload.presence,
width: video_view.width.presence,
height: video_view.height.presence do %>
<%= tag :source,
src: alchemy.show_attachment_path(
video_view.attachment,
format: video_view.attachment.suffix
),
type: video_view.attachment.file_mime_type %>
<% end %>
<%- end -%>
93 changes: 93 additions & 0 deletions spec/models/alchemy/ingredients/audio_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe Alchemy::Ingredients::Audio do
it_behaves_like "an alchemy ingredient"

let(:element) { build(:alchemy_element) }
let(:attachment) { build(:alchemy_attachment) }

let(:audio_ingredient) do
described_class.new(
element: element,
type: described_class.name,
role: "podcast",
related_object: attachment,
)
end

describe "#autoplay" do
subject { audio_ingredient.autoplay }
before { audio_ingredient.autoplay = false }
it { is_expected.to eq(false) }
end

describe "#controls" do
subject { audio_ingredient.controls }
before { audio_ingredient.controls = true }
it { is_expected.to eq(true) }
end

describe "#loop" do
subject { audio_ingredient.loop }
before { audio_ingredient.loop = false }
it { is_expected.to eq(false) }
end

describe "#muted" do
subject { audio_ingredient.muted }
before { audio_ingredient.muted = true }
it { is_expected.to eq(true) }
end

describe "#attachment" do
subject { audio_ingredient.attachment }

it { is_expected.to be_an(Alchemy::Attachment) }
end

describe "#attachment=" do
let(:attachment) { Alchemy::Attachment.new }

subject { audio_ingredient.attachment = attachment }

it { is_expected.to be(attachment) }
end

describe "#preview_text" do
subject { audio_ingredient.preview_text }

context "with a attachment" do
let(:attachment) do
Alchemy::Attachment.new(name: "A very long file name that would not fit")
end

it "returns first 30 characters of the attachment name" do
is_expected.to eq("A very long file name that wou")
end
end

context "with no attachment" do
let(:attachment) { nil }

it { is_expected.to eq("") }
end
end

describe "#value" do
subject { audio_ingredient.value }

context "with attachment assigned" do
it "returns attachment" do
is_expected.to be(attachment)
end
end

context "with no attachment assigned" do
let(:attachment) { nil }

it { is_expected.to be_nil }
end
end
end
117 changes: 117 additions & 0 deletions spec/models/alchemy/ingredients/video_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe Alchemy::Ingredients::Video do
it_behaves_like "an alchemy ingredient"

let(:element) { build(:alchemy_element) }
let(:attachment) { build(:alchemy_attachment) }

let(:video_ingredient) do
described_class.new(
element: element,
type: described_class.name,
role: "podcast",
related_object: attachment,
)
end

describe "#allow_fullscreen" do
subject { video_ingredient.allow_fullscreen }
before { video_ingredient.allow_fullscreen = true }
it { is_expected.to eq(true) }
end

describe "#autoplay" do
subject { video_ingredient.autoplay }
before { video_ingredient.autoplay = false }
it { is_expected.to eq(false) }
end

describe "#controls" do
subject { video_ingredient.controls }
before { video_ingredient.controls = true }
it { is_expected.to eq(true) }
end

describe "#height" do
subject { video_ingredient.height }
before { video_ingredient.height = 720 }
it { is_expected.to eq(720) }
end

describe "#loop" do
subject { video_ingredient.loop }
before { video_ingredient.loop = false }
it { is_expected.to eq(false) }
end

describe "#muted" do
subject { video_ingredient.muted }
before { video_ingredient.muted = true }
it { is_expected.to eq(true) }
end

describe "#preload" do
subject { video_ingredient.preload }
before { video_ingredient.preload = "auto" }
it { is_expected.to eq("auto") }
end

describe "#width" do
subject { video_ingredient.width }
before { video_ingredient.width = 1280 }
it { is_expected.to eq(1280) }
end

describe "#attachment" do
subject { video_ingredient.attachment }

it { is_expected.to be_an(Alchemy::Attachment) }
end

describe "#attachment=" do
let(:attachment) { Alchemy::Attachment.new }

subject { video_ingredient.attachment = attachment }

it { is_expected.to be(attachment) }
end

describe "#preview_text" do
subject { video_ingredient.preview_text }

context "with a attachment" do
let(:attachment) do
Alchemy::Attachment.new(name: "A very long file name that would not fit")
end

it "returns first 30 characters of the attachment name" do
is_expected.to eq("A very long file name that wou")
end
end

context "with no attachment" do
let(:attachment) { nil }

it { is_expected.to eq("") }
end
end

describe "#value" do
subject { video_ingredient.value }

context "with attachment assigned" do
it "returns attachment" do
is_expected.to be(attachment)
end
end

context "with no attachment assigned" do
let(:attachment) { nil }

it { is_expected.to be_nil }
end
end
end
Loading