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: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions benchmark/benchmark.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 }
Expand Down
4 changes: 2 additions & 2 deletions shard.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ 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
version: 0.2.2

markout:
git: https://github.com/grottopress/markout.git
version: 1.0.0
version: 1.1.0

water:
git: https://github.com/shootingfly/water.git
Expand Down
27 changes: 27 additions & 0 deletions spec/instance_template/external_script_spec.cr
Original file line number Diff line number Diff line change
@@ -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>
<head>
<script src="https://example.com/example.js"><script>
<script src="https://example.com/example2.js"></script>
</head>
</html>
HTML
end
end
end
15 changes: 15 additions & 0 deletions src/external_script.cr
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions src/to_html.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ require "./instance_template"
require "./instance_tag_attrs"
require "./ext/**"
require "./layout"
require "./external_script"