Method: Hanami::View::Configuration#root

Defined in:
lib/hanami/view/configuration.rb

#root(value) ⇒ Object #rootPathname

Set the root path where to search for templates

If not set, this value defaults to the current directory.

This is part of a DSL, for this reason when this method is called with an argument, it will set the corresponding instance variable. When called without, it will return the already set value, or the default.

Examples:

Getting the value

require 'hanami/view'

Hanami::View.configuration.root # => #<Pathname:.>

Setting the value

require 'hanami/view'

Hanami::View.configure do
  root '/path/to/templates'
end

Hanami::View.configuration.root # => #<Pathname:/path/to/templates>

Overloads:

  • #root(value) ⇒ Object

    Sets the given value

    Raises:

    • (Errno::ENOENT)

      if the given path doesn't exist

  • #rootPathname

    Gets the value

See Also:

Since:

  • 0.2.0


187
188
189
190
191
192
193
# File 'lib/hanami/view/configuration.rb', line 187

def root(value = nil)
  if value
    @root = Utils::Kernel.Pathname(value).realpath
  else
    @root
  end
end