Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,23 @@ class ActionViewTagHelperToHTMLVisitor extends Visitor {
asMutable(node).element_source = "HTML"

if (node.body) {
for (const child of node.body) {
asMutable(node).body = node.body.map(child => {
if (isRubyLiteralNode(child)) {
return new ERBContentNode({
type: "AST_ERB_CONTENT_NODE",
location: child.location,
errors: [],
tag_opening: createSyntheticToken("<%="),
content: createSyntheticToken(` ${child.content} `),
tag_closing: createSyntheticToken("%>"),
parsed: false,
valid: true,
})
}

this.visit(child)
}
return child
})
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,26 @@ describe("ActionViewTagHelperToHTMLRewriter", () => {
})
})

describe("link_to helpers", () => {
test("link_to with path only", () => {
expect(transform("<%= link_to root_path %>")).toBe(
'<a href="<%= root_path %>"><%= root_path.to_s %></a>'
)
})

test("link_to with model", () => {
expect(transform("<%= link_to @profile %>")).toBe(
'<a href="<%= url_for(@profile) %>"><%= @profile.to_s %></a>'
)
})

test("link_to with :back", () => {
expect(transform('<%= link_to "Back", :back %>')).toBe(
'<a href="<%= url_for(:back) %>">Back</a>'
)
})
})

describe("non-ActionView elements", () => {
test("regular HTML elements are not modified", () => {
expect(transform('<div class="content">Hello</div>')).toBe(
Expand Down
Loading