diff --git a/README.md b/README.md index b67025d..2ac4a1a 100644 --- a/README.md +++ b/README.md @@ -262,12 +262,12 @@ Have a look into the `benchmark/` folder to find out how these numbers were dete Execute `crystal run --release benchmark/benchmark.cr` to reproduce. ``` - ecr 1.55M (645.91ns) (± 5.16%) 4.27kB/op fastest - to_html 902.82k ( 1.11µs) (± 8.18%) 5.52kB/op 1.71× slower - blueprint 170.78k ( 5.86µs) (± 8.85%) 9.8kB/op 9.07× slower -html_builder 62.44k ( 16.01µs) (± 3.41%) 10.4kB/op 24.79× slower - water 61.90k ( 16.16µs) (± 1.18%) 11.2kB/op 25.01× slower - markout 44.77k ( 22.34µs) (± 1.72%) 15.6kB/op 34.58× slower + ecr 1.54M (651.31ns) (±11.60%) 4.27kB/op fastest + to_html 873.06k ( 1.15µs) (± 5.28%) 5.52kB/op 1.76× slower + blueprint 453.17k ( 2.21µs) (± 2.32%) 4.9kB/op 3.39× slower +html_builder 65.17k ( 15.34µs) (± 4.32%) 10.4kB/op 23.56× slower + water 61.96k ( 16.14µs) (± 4.11%) 11.2kB/op 24.78× slower + markout 43.80k ( 22.83µs) (± 3.79%) 20.7kB/op 35.05× slower ``` Compared shards taken from [awesome-crystal](https://github.com/veelenga/awesome-crystal#html-builders) diff --git a/benchmark/benchmark.cr b/benchmark/benchmark.cr index c793652..a00dcbd 100644 --- a/benchmark/benchmark.cr +++ b/benchmark/benchmark.cr @@ -21,7 +21,7 @@ to_html_output = normalize(to_html.to_html) { "ecr" => normalize(ecr.to_s), - "blueprint" => normalize(blueprint.to_html), + "blueprint" => normalize(blueprint.to_s), "water" => normalize(water.to_html), "html_builder" => normalize(html_builder.to_s), "markout" => normalize(markout.to_s) @@ -37,7 +37,7 @@ end Benchmark.ips do |x| x.report("ecr") { ToHtml::Benchmark::EcrTemplate.new.to_s } x.report("to_html") { ToHtml::Benchmark::ToHtmlTemplate.new.to_html } - x.report("blueprint") { ToHtml::Benchmark::BlueprintTemplate.new.to_html } + x.report("blueprint") { ToHtml::Benchmark::BlueprintTemplate.new.to_s } x.report("html_builder") { ToHtml::Benchmark::HtmlBuilderTemplate.new.to_s } x.report("water") { ToHtml::Benchmark::WaterTemplate.new.to_html } x.report("markout") { ToHtml::Benchmark::MarkoutTemplate.new.to_s } diff --git a/shard.lock b/shard.lock index cd1a299..c6f4514 100644 --- a/shard.lock +++ b/shard.lock @@ -2,7 +2,7 @@ version: 2.0 shards: blueprint: git: https://github.com/stephannv/blueprint.git - version: 0.4.0 + version: 1.0.0 html_builder: git: https://github.com/crystal-lang/html_builder.git @@ -10,7 +10,7 @@ shards: markout: git: https://github.com/grottopress/markout.git - version: 1.0.0 + version: 1.1.0 water: git: https://github.com/shootingfly/water.git diff --git a/spec/instance_template/external_script_spec.cr b/spec/instance_template/external_script_spec.cr new file mode 100644 index 0000000..a6955f3 --- /dev/null +++ b/spec/instance_template/external_script_spec.cr @@ -0,0 +1,27 @@ +require "../spec_helper" + +module ToHtml::ExternalScriptSpec + class MyView + ToHtml.class_template do + html do + head do + ExternalScript.new("https://example.com/example.js") + script ExternalScript.new("https://example.com/example2.js") + end + end + end + end + + describe "MyView.to_html" do + it "should return the correct HTML" do + expected = <<-HTML.squish + + + + + + HTML + end + end +end diff --git a/src/external_script.cr b/src/external_script.cr new file mode 100644 index 0000000..145b4bc --- /dev/null +++ b/src/external_script.cr @@ -0,0 +1,15 @@ +module ToHtml + class ExternalScript + getter url : String + + def initialize(@url); end + + ToHtml.instance_tag_attrs do + src = url + end + + ToHtml.instance_template do + script self + end + end +end diff --git a/src/to_html.cr b/src/to_html.cr index a82865a..785c558 100644 --- a/src/to_html.cr +++ b/src/to_html.cr @@ -2,3 +2,4 @@ require "./instance_template" require "./instance_tag_attrs" require "./ext/**" require "./layout" +require "./external_script"