-
-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
410af90
commit 0224f9f
Showing
11 changed files
with
60 additions
and
163 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
module SGMLHelper | ||
def phlex(component = Phlex::HTML, *, **, &) | ||
component.new(*, **).call do |e| | ||
e.instance_exec(&) | ||
end | ||
end | ||
end |
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 |
---|---|---|
@@ -1,61 +1,39 @@ | ||
# frozen_string_literal: true | ||
|
||
test "with string" do | ||
component = Class.new(Phlex::HTML) do | ||
define_method(:view_template) do | ||
plain "Hello, World!" | ||
end | ||
end | ||
require "sgml_helper" | ||
|
||
include SGMLHelper | ||
|
||
expect(component.new.call) == "Hello, World!" | ||
test "with string" do | ||
expect( | ||
phlex { plain "Hello, World!" }, | ||
) == "Hello, World!" | ||
end | ||
|
||
test "with symbol" do | ||
component = Class.new(Phlex::HTML) do | ||
define_method(:view_template) do | ||
plain :hello_world | ||
end | ||
end | ||
|
||
expect(component.new.call) == "hello_world" | ||
expect( | ||
phlex { plain :hello_world }, | ||
) == "hello_world" | ||
end | ||
|
||
test "with integer" do | ||
component = Class.new(Phlex::HTML) do | ||
define_method(:view_template) do | ||
plain 42 | ||
end | ||
end | ||
|
||
expect(component.new.call) == "42" | ||
expect( | ||
phlex { plain 42 }, | ||
) == "42" | ||
end | ||
|
||
test "with float" do | ||
component = Class.new(Phlex::HTML) do | ||
define_method(:view_template) do | ||
plain 3.14 | ||
end | ||
end | ||
|
||
expect(component.new.call) == "3.14" | ||
expect( | ||
phlex { plain 3.14 }, | ||
) == "3.14" | ||
end | ||
|
||
test "with nil" do | ||
component = Class.new(Phlex::HTML) do | ||
define_method(:view_template) do | ||
plain nil | ||
end | ||
end | ||
|
||
expect(component.new.call) == "" | ||
expect( | ||
phlex { plain nil }, | ||
) == "" | ||
end | ||
|
||
test "with array" do | ||
component = Class.new(Phlex::HTML) do | ||
define_method(:view_template) do | ||
plain [1, 2, 3] | ||
end | ||
end | ||
|
||
expect { component.new.call }.to_raise(Phlex::ArgumentError) | ||
test "with invalid arguments" do | ||
expect { phlex { plain [] } }.to_raise(Phlex::ArgumentError) | ||
end |
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 |
---|---|---|
@@ -1,45 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
def render(&) | ||
Phlex::HTML.new.call do |e| | ||
e.instance_exec(&) | ||
end | ||
end | ||
require "sgml_helper" | ||
|
||
include SGMLHelper | ||
|
||
test "with an unsafe object" do | ||
expect { | ||
render do | ||
raw "<div></div>" | ||
end | ||
}.to_raise(Phlex::ArgumentError) do |error| | ||
expect { phlex { raw "<div></div>" } }.to_raise(Phlex::ArgumentError) do |error| | ||
expect(error.message) == "You passed an unsafe object to `raw`." | ||
end | ||
end | ||
|
||
test "with a safe object" do | ||
expect( | ||
render do | ||
raw safe %(<div class="hello">&</div>) | ||
end, | ||
) == %(<div class="hello">&</div>) | ||
expect(phlex { raw safe %(<div class="hello">&</div>) }) == %(<div class="hello">&</div>) | ||
end | ||
|
||
test "with nil" do | ||
expect( | ||
render do | ||
div do | ||
raw nil | ||
end | ||
end, | ||
) == %(<div></div>) | ||
expect(phlex { div { raw nil } }) == %(<div></div>) | ||
end | ||
|
||
test "with empty string" do | ||
expect( | ||
render do | ||
div do | ||
raw "" | ||
end | ||
end, | ||
) == %(<div></div>) | ||
expect(phlex { div { raw "" } }) == %(<div></div>) | ||
end |
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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