Module: Hanami::View::Dsl
- Defined in:
- gems/gems/hanami-view-1.3.3/lib/hanami/view/dsl.rb
Overview
Class level DSL
Instance Method Summary collapse
-
#format(value = nil) ⇒ Symbol?
When a value is given, specify the handled format.
-
#layout(value = nil) ⇒ Symbol?
When a value is given, it specifies the layout.
-
#root(value = nil) ⇒ Pathname
When a value is given, specify a templates root path for the view.
-
#template(value = nil) ⇒ String
When a value is given, specify the relative path to the template.
Instance Method Details
#format(value = nil) ⇒ Symbol?
When a value is given, specify the handled format. Otherwise, it returns the previously specified format.
Source: | on GitHub
def format(value = nil) if value.nil? @format ||= nil else @format = value end end |
#layout(value = nil) ⇒ Symbol?
When a value is given, it specifies the layout. When false is given, Hanami::View::Rendering::NullLayout is returned. Otherwise, it returns the previously specified layout.
When the global configuration is set (Hanami::View.layout=
), after the loading process, it will return that layout if not otherwise specified.
#root(value = nil) ⇒ Pathname
When a value is given, specify a templates root path for the view. Otherwise, it returns templates root path.
When not initialized, it will return the global value from Hanami::View.root
.
#template(value = nil) ⇒ String
When a value is given, specify the relative path to the template. Otherwise, it returns the name that follows Hanami::View conventions.
@example Default usage require ‘hanami/view’
module Articles class Show include Hanami::View end
class JsonShow < Show
format :json
end
end
Articles::Show.template # => ‘articles/show’ Articles::JsonShow.template # => ‘articles/show’
@example Custom template require ‘hanami/view’
module Articles class Show include Hanami::View template ‘articles/single_article’ end
class JsonShow < Show
format :json
end
end
Articles::Show.template # => ‘articles/single_article’ Articles::JsonShow.template # => ‘articles/single_article’