Skip to content

New docs, style builder, tokens, safe rendering and breaking changes

Latest
Compare
Choose a tag to compare
@stephannv stephannv released this 14 Sep 18:17
c9e86bf

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.