Enveloping
By overriding the #envelope
method, you can create a wrapper around your view
content. This is useful when defining layouts for pages, for example. Don't
forget to yield a block inside #envelope
method.
class ExamplePage
include Blueprint::HTML
private def blueprint
h1 { "Home" }
end
private def envelope
html do
body do
yield
end
end
end
end
ExamplePage.new.to_s
Output:
With #envelope
method you can create some flexible layouts for your pages. For
example, you can use inheritance to have multiple layouts on your application.
class MainLayout
include Blueprint::HTML
private def envelope
html do
body do
div class: "main-layout" do
yield
end
end
end
end
end
class AuthLayout
include Blueprint::HTML
private def envelope
html do
body do
div class: "auth-layout" do
yield
end
end
end
end
end
class HomePage < MainLayout
private def blueprint
h1 { "Welcome" }
end
end
class LoginPage < AuthLayout
private def blueprint
h1 { "Sign In" }
end
end
HomePage.new.to_s
LoginPage.new.to_s
HomePage output:
LoginPage output: