Releases: stephannv/blueprint
v0.11.0
What's Changed
Add escape_once
helper
It escapes HTML without affecting existing escaped entities
class ExamplePage
include Blueprint::HTML
def blueprint
plain escape_once("1 < 2 & 3")
span escape_once("<< Accept & Checkout")
span { escape_once("<script>alert('content')</script>") }
end
end
puts ExamplePage.new.to_s
Output:
1 < 2 & 3
<span><< Accept & Checkout</span>
<span><script>alert('content')</script></span>
Change attribute value escaper
Before attribute values were escaped using HTML.escape
, now the escape is done using .gsub('"', """)
.
class ExamplePage
include Blueprint::HTML
def blueprint
input(value: %(>'test'<">))
# Before <input value=">'test'<">">
# After <input value=">'test'<">">
end
end
Full Changelog: v0.10.0...v0.11.0
v0.10.0
What's Changed
- feat: Loose #plain/#comment argument type by @stephannv in #78
Now you can pass any object that respondsto_s
to#plain
/#comment
methods.
class ExamplePage
include Blueprint::HTML
def blueprint
# before:
plain custom_object.to_s
comment other_object.to_s
# after:
plain custom_object
comment other_object
end
end
Full Changelog: v0.9.0...v0.10.0
v0.9.0 - Form Builder
Using #form_builder
you can access some utility methods to build labels and inputs:
class ExamplePage
include Blueprint::HTML
def blueprint
form_builder action: "/sign-in", method: :post do |form|
form.label :email
form.email_input :email
form.label :password
form.password_input :password
end
end
end
puts ExamplePage.new.to_s
# <form action="/sign-in" method="post">
# <label for="email">Email</label>
# <input type="email" id="email" name="email">
#
# <label for="password">Password</label>
# <input type="password" id="password" name="password">
# </form>
More examples at docs: https://stephannv.github.io/blueprint-docs/handbook/forms/
New docs, style builder, tokens, safe rendering and breaking changes
Overhauled docs
The Blueprint Docs was revised.
Style Variants (Experimental)
Simplify the management of CSS class combinations:
class AlertComponent
include Blueprint::HTML
style_builder do
base "alert"
variants do
type {
info "alert-info"
danger "alert-danger"
}
size {
xs "text-xs p-2"
md "text-md p-4"
lg "text-lg p-6"
}
closable {
yes "alert-closable"
}
special {
yes "alert-special"
no "alert-default"
}
end
defaults type: :info, size: :md
end
def blueprint
div(class: build_style(type: :danger, size: :lg, closable: true)) do
"My styled alert component"
end
end
end
puts AlertComponent.build_style(type: :info, size: :xs, special: false)
# "alert alert-info text-xs p-2 alert-default"
puts AlertComponent.new.to_s
# <div class="alert alert-danger text-lg p-6 alert-closable">
# My styled alert component
# </div>
Tokens (Experimental)
Allows to build classes based on conditionals.
class UserComponent
include Blueprint::HTML
def blueprint
h1 class: tokens(admin?: "is-admin", moderator?: "is-moderator") do
"Jane Doe"
end
end
def admin?
false
end
def moderator?
true
end
end
puts UserComponent.new.to_s
# <h1 class="is-moderator">
# Jane Doe
# </h1>
Add #safe
helper
The #safe
method wraps the given object in a Blueprint::SafeValue
, indicating to Blueprint that the content should be rendered without escaping.
BREAKING: Change #to_html
to #to_s
Instead of MyComponent.new.to_html
you should use MyComponent.new.to_s
.
BREAKING: Remove some utils methods
The methods #plain(&)
and #comment(&)
were removed, but you still can use the #plain(content : String)
and #comment(content : String)
.
BREAKING: Remove #unsafe_raw
#unsafe_raw
was removed in favor of #raw
.
# BEFORE
unsafe_raw "<script>My Script</script>"
# AFTER
raw safe("<script>My Script</script>")
BREAKING: Remove Blueprint::RawHTML
The Blueprint::RawHTML
included in 0.7.0 was removed. A module focused on performance will be planned in the future.
Include Blueprint::HTML::ComponenentRegistrar by default
You don't need to require and include Blueprint::HTML::ComponenentRegistrar
, it is already included when you include Blueprint::HTML
.
v0.7.0
What's Changed
- Allow passing comment via argument
comment "Cool comment here"
- Allow rendering unsafe content using
unsafe_raw
unsafe_raw "<script>alert('Danger!')</script>"
- Add
RawHtml
to priorize performance over safety
require "blueprint/raw_html"
class MyHTML
include Blueprint::RawHTML
def blueprint
div "<script>alert('Danger!')</script>" # this will not be escaped
end
end
- Code refactoring to improve performance
- Fix safety when passing content to elements via argument
Full Changelog: v0.6.0...v0.7.0
v0.6.0
What's Changed
- feat: Allow passing element content without using block by @stephannv in #53
h1 { "Hello World!" }
# or just
h1 "Hello World!"
Full Changelog: v0.5.1...v0.6.0
v0.5.1
Fix Crystal version string requirement.
Full Changelog: v0.5.0...v0.5.1
v0.5.0
What's Changed
Performance improvements: Increased speed execution by 15%.
v0.5.0 364.46k ( 2.74µs) (± 0.52%) 7.95kB/op fastest
v0.4.0 317.83k ( 3.15µs) (± 0.76%) 8.99kB/op 1.15× slower
- fix: Ignore nil elements from array attribute parsing by @stephannv in #48
- perf: Use String::Builder to improve render times by @stephannv in #51
Full Changelog: v0.4.0...v0.5.0
v0.4.0 - SVG support
Full details: https://blueprint.gunbolt.org/changelogs/v0.4.0/
What's Changed
- feat: Support SVG rendering by @stephannv in #42
Full Changelog: v0.3.0...v0.4.0
v0.3.0
Full details: https://blueprint.gunbolt.org/changelogs/v0.3.0/
What's Changed
- feat: Add experimental Blueprint::HTML.builder by @stephannv in #39
Full Changelog: v0.2.0...v0.3.0