Skip to content

Commit

Permalink
Merge pull request #2798 from AlchemyCMS/picture-view-fixes
Browse files Browse the repository at this point in the history
Picture view fixes
  • Loading branch information
tvdeyen authored Mar 22, 2024
2 parents d300b23 + 7b8a43a commit e7feafb
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/components/alchemy/ingredients/picture_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def call
def caption
return unless show_caption?

@_caption ||= content_tag(:figcaption, ingredient.caption)
@_caption ||= content_tag(:figcaption, ingredient.caption.html_safe)
end

def src
Expand Down
2 changes: 1 addition & 1 deletion app/models/alchemy/picture_variant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def initialize(picture, options = {})

@picture = picture
@options = options
@render_format = options[:format] || picture.default_render_format
@render_format = (options[:format] || picture.default_render_format).to_s
end

# Process a variant of picture
Expand Down
16 changes: 16 additions & 0 deletions spec/components/alchemy/ingredients/picture_view_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,22 @@
expect(page).to have_content("This is a cute cat")
end

context "having html tags" do
let(:ingredient) do
stub_model Alchemy::Ingredients::Picture,
role: "image",
picture: picture,
data: {
caption: "This is a<br />cute cat"
}
end

it "should show the caption" do
render_view
expect(page).to have_content("This is acute cat")
end
end

it "does not pass default options to picture url" do
expect(ingredient).to receive(:picture_url).with({}) { picture_url }
render_view
Expand Down
12 changes: 12 additions & 0 deletions spec/models/alchemy/picture_variant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,18 @@
end
end
end

context "passed as symbol" do
let(:options) do
{format: :gif}
end

it "converts the format" do
step = subject.steps[0]
expect(step.name).to eq(:encode)
expect(step.arguments).to include("gif")
end
end
end

context "requesting a not allowed format" do
Expand Down

0 comments on commit e7feafb

Please sign in to comment.