Module: Lotus::View::Dsl
- Defined in:
- lib/lotus/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.
77 78 79 80 81 82 83 |
# File 'lib/lotus/view/dsl.rb', line 77 def format(value = nil) if value @format = value else @format end end |
#layout(value = nil) ⇒ Symbol?
When a value is given, it specifies the layout. Otherwise, it returns the previously specified layout.
When the global configuration is set (‘Lotus::View.layout=`), after the loading process, it will return that layout if not otherwise specified.
218 219 220 221 222 223 224 |
# File 'lib/lotus/view/dsl.rb', line 218 def layout(value = nil) if value @layout = value else @layout end end |
#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 ‘Lotus::View.root`.
45 46 47 48 49 50 51 |
# File 'lib/lotus/view/dsl.rb', line 45 def root(value = nil) if value @@root = Pathname.new value else @@root ||= Lotus::View.root end end |
#template(value = nil) ⇒ String
When a value is given, specify the relative path to the template. Otherwise, it returns the name that follows Lotus::View conventions.
@example Default usage
require 'lotus/view'
module Articles
class Show
include Lotus::View
end
class JsonShow < Show
format :json
end
end
Articles::Show.template # => 'articles/show'
Articles::JsonShow.template # => 'articles/show'
@example Custom template
require 'lotus/view'
module Articles
class Show
include Lotus::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'
127 128 129 130 131 132 133 |
# File 'lib/lotus/view/dsl.rb', line 127 def template(value = nil) if value @@template = value else @@template ||= Utils::String.new(name).underscore end end |