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
12 changes: 12 additions & 0 deletions spec/blueprint/html/attributes_handling_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ describe "attributes handling" do
actual_html.should eq expected_html
end

it "doesn't render nil attributes" do
actual_html = Blueprint::HTML.build do
div class: nil, data: {id: nil}
end

expected_html = normalize_html <<-HTML
<div></div>
HTML

actual_html.should eq expected_html
end

it "expands NamedTuple attributes" do
actual_html = Blueprint::HTML.build do
nav aria: {target: "#home", selected: "false", enabled: true, hidden: false} do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,25 @@ private class Example
end
end

describe "custom elements registration" do
it "allows custom elements definition" do
describe "custom elements" do
it "allows custom elements rendering" do
actual_html = Blueprint::HTML.build do
element :foo, class: "bar", data: {tmp: true} do
"Hello"
end

void_element :portal, class: "my-portal"
end

expected_html = normalize_html <<-HTML
<foo class="bar" data-tmp>Hello</foo>
<portal class="my-portal">
HTML

actual_html.should eq expected_html
end

it "allows custom elements registration" do
actual_html = Example.new.to_s do |example|
example.v_btn(href: "#home", data: {id: 12, visible: true, disabled: false}) { "Home" }
end
Expand Down
8 changes: 6 additions & 2 deletions spec/blueprint/html/svg_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ describe "SVG" do

it "defines all SVG element helper methods" do
actual_html = Blueprint::HTML.build do
svg do
svg

svg viewBox: "0 0 100 100" do
{% for element in ELEMENTS %}
{{element.id}}
{{element.id}}(attribute: "test")
Expand All @@ -44,7 +46,9 @@ describe "SVG" do
end

expected_html = String.build do |io|
io << "<svg>"
io << "<svg></svg>"

io << %(<svg viewBox="0 0 100 100">)
ELEMENTS.each do |tag|
io << "<" << tag << ">" << "</" << tag << ">"
io << "<" << tag << " attribute=\"test\">" << "</" << tag << ">"
Expand Down
2 changes: 1 addition & 1 deletion src/blueprint/html/svg.cr
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct Blueprint::HTML::SVG(T)
end

private def blueprint(&) : Nil
element :svg, **@attributes do
svg **@attributes do
yield
end
end
Expand Down