Skip to content

Commit

Permalink
refactor: Clean up code (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephannv authored Apr 21, 2023
1 parent 17432d2 commit 10da2b0
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 30 deletions.
46 changes: 21 additions & 25 deletions spec/blueprint/html/standard_elements_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,34 @@ private NORMAL_ELEMENTS = %i[
private VOID_ELEMENTS = %i[area base br col embed hr img input link meta source track wbr]
private EMPTY_ELEMENTS = %i[iframe portal]

private macro define_dummy_class
private class DummyPage
include Blueprint::HTML
private class DummyPage
include Blueprint::HTML

private def blueprint
{% for element in NORMAL_ELEMENTS %}
{{element.id}}
{{element.id}}(attribute: "test")
{{element.id}} { "content" }
{{element.id}}(attribute: "test") { "content" }
{% end %}
private def blueprint
{% for element in NORMAL_ELEMENTS %}
{{element.id}}
{{element.id}}(attribute: "test")
{{element.id}} { "content" }
{{element.id}}(attribute: "test") { "content" }
{% end %}

{% for element in VOID_ELEMENTS %}
{{element.id}}
{{element.id}}(attribute: "test")
{% end %}
{% for element in VOID_ELEMENTS %}
{{element.id}}
{{element.id}}(attribute: "test")
{% end %}

{% for element in EMPTY_ELEMENTS %}
{{element.id}}
{{element.id}}(attribute: "test")
{% end %}
{% for element in EMPTY_ELEMENTS %}
{{element.id}}
{{element.id}}(attribute: "test")
{% end %}

select_tag
select_tag(attribute: "test")
select_tag { "content" }
select_tag(attribute: "test") { "content" }
end
select_tag
select_tag(attribute: "test")
select_tag { "content" }
select_tag(attribute: "test") { "content" }
end
end

define_dummy_class

describe "Blueprint::HTML standard HTML elements" do
it "defines all base HTML elements helper methods" do
page = DummyPage.new
Expand Down
2 changes: 1 addition & 1 deletion src/blueprint/html.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ require "./html/attributes_parser"
require "./html/builder"
require "./html/content_capture"
require "./html/element_registrar"
require "./html/elements"
require "./html/renderer"
require "./html/standard_elements"
require "./html/svg"
require "./html/utils"

Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/blueprint/html/svg.cr
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
require "../svg/component"

module Blueprint::HTML
def svg(**attributes, &)
private def svg(**attributes, &) : Nil
render Blueprint::SVG::Component.new(**attributes) do |component|
with component yield
end
end

def svg(**attributes)
private def svg(**attributes) : Nil
svg(**attributes) { }
end
end
4 changes: 2 additions & 2 deletions src/blueprint/svg/component.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ struct Blueprint::SVG::Component(T)

@attributes : T

def self.new(**kwargs)
def self.new(**kwargs) : Blueprint::SVG::Component
new kwargs
end

Expand All @@ -16,7 +16,7 @@ struct Blueprint::SVG::Component(T)
@attributes = attributes
end

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

0 comments on commit 10da2b0

Please sign in to comment.