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

Add support for additional image attributes #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion lib/tip_tap/nodes/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def include_empty_content_in_json?
end

def to_html
image_tag(src)
image_tag(src, attrs.except("src"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if the goal is setting alt that we just allow alt or at minimum the allow options that can be passed to the image_tag helper. https://api.rubyonrails.org/v7.2.2/classes/ActionView/Helpers/AssetTagHelper.html#method-i-image_tag

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy to change it to only set alt for now.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be great, thanks!

end

def src
Expand Down
10 changes: 9 additions & 1 deletion spec/tip_tap/nodes/image_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,18 @@
expect(html).to be_a(String)
expect(html).to eq('<img src="https://img.companycam.com/abcd1234.jpeg" />')
end

it "optionally returns additional attributes" do
node = TipTap::Nodes::Image.new(src: "https://img.companycam.com/abcd1234.jpeg", alt: "Alt text example")
html = node.to_html

expect(html).to be_a(String)
expect(html).to eq('<img alt="Alt text example" src="https://img.companycam.com/abcd1234.jpeg" />')
end
end

describe "src" do
it "returns a the src attribute" do
it "returns the src attribute" do
node = TipTap::Nodes::Image.new(src: "https://img.companycam.com/abcd1234.jpeg")
expect(node.src).to eq("https://img.companycam.com/abcd1234.jpeg")
end
Expand Down