- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Merge branch 'main' of https://github.com/phlex-ruby/phlex
Showing
5 changed files
with
120 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# frozen_string_literal: true | ||
|
||
class StandardElementExample < Phlex::HTML | ||
def view_template | ||
doctype | ||
div { | ||
comment { h1(id: "target") } | ||
h1 { "Before" } | ||
img(src: "before.jpg") | ||
whitespace | ||
comment { "This is a comment" } | ||
h1(id: "target") { | ||
plain "Hello" | ||
strong { "World" } | ||
img(src: "image.jpg") | ||
} | ||
img(src: "after.jpg") | ||
h1(id: "target") { "After" } | ||
} | ||
end | ||
end | ||
|
||
class VoidElementExample < Phlex::HTML | ||
def view_template | ||
doctype | ||
div { | ||
comment { h1(id: "target") } | ||
h1 { "Before" } | ||
img(src: "before.jpg") | ||
whitespace | ||
comment { "This is a comment" } | ||
h1 { | ||
plain "Hello" | ||
strong { "World" } | ||
img(id: "target", src: "image.jpg") | ||
} | ||
img(src: "after.jpg") | ||
h1(id: "target") { "After" } | ||
} | ||
end | ||
end | ||
|
||
describe Phlex::HTML do | ||
it "renders the just the target fragment" do | ||
expect( | ||
StandardElementExample.new.call(fragment: "target") | ||
).to be == %(<h1 id="target">Hello<strong>World</strong><img src="image.jpg"></h1>) | ||
end | ||
|
||
it "works with void elements" do | ||
expect( | ||
VoidElementExample.new.call(fragment: "target") | ||
).to be == %(<img id="target" src="image.jpg">) | ||
end | ||
end |