Module: Hanami::View

Includes:
Utils::ClassAttribute
Defined in:
gems/gems/hanami-view-1.3.1/lib/hanami/view.rb,
gems/gems/hanami-view-1.3.1/lib/hanami/view/dsl.rb,
gems/gems/hanami-view-1.3.1/lib/hanami/view/errors.rb,
gems/gems/hanami-view-1.3.1/lib/hanami/view/escape.rb,
gems/gems/hanami-view-1.3.1/lib/hanami/view/version.rb,
gems/gems/hanami-view-1.3.1/lib/hanami/view/template.rb,
gems/gems/hanami-view-1.3.1/lib/hanami/view/rendering.rb,
gems/gems/hanami-view-1.3.1/lib/hanami/view/inheritable.rb,
gems/gems/hanami-view-1.3.1/lib/hanami/view/configuration.rb,
gems/gems/hanami-view-1.3.1/lib/hanami/view/rendering/scope.rb,
gems/gems/hanami-view-1.3.1/lib/hanami/view/rendering/options.rb,
gems/gems/hanami-view-1.3.1/lib/hanami/view/rendering/partial.rb,
gems/gems/hanami-view-1.3.1/lib/hanami/view/rendering/registry.rb,
gems/gems/hanami-view-1.3.1/lib/hanami/view/rendering/subscope.rb,
gems/gems/hanami-view-1.3.1/lib/hanami/view/rendering/template.rb,
gems/gems/hanami-view-1.3.1/lib/hanami/view/rendering/null_view.rb,
gems/gems/hanami-view-1.3.1/lib/hanami/view/rendering/null_local.rb,
gems/gems/hanami-view-1.3.1/lib/hanami/view/rendering/null_layout.rb,
gems/gems/hanami-view-1.3.1/lib/hanami/view/rendering/view_finder.rb,
gems/gems/hanami-view-1.3.1/lib/hanami/view/rendering/layout_scope.rb,
gems/gems/hanami-view-1.3.1/lib/hanami/view/rendering/partial_file.rb,
gems/gems/hanami-view-1.3.1/lib/hanami/view/rendering/layout_finder.rb,
gems/gems/hanami-view-1.3.1/lib/hanami/view/rendering/null_template.rb,
gems/gems/hanami-view-1.3.1/lib/hanami/view/rendering/template_name.rb,
gems/gems/hanami-view-1.3.1/lib/hanami/view/rendering/partial_finder.rb,
gems/gems/hanami-view-1.3.1/lib/hanami/view/rendering/layout_registry.rb,
gems/gems/hanami-view-1.3.1/lib/hanami/view/rendering/template_finder.rb,
gems/gems/hanami-view-1.3.1/lib/hanami/view/rendering/templates_finder.rb,
gems/gems/hanami-view-1.3.1/lib/hanami/view/rendering/partial_templates_finder.rb,
gems/gems/hanami-view-1.3.3/lib/hanami/view/dsl.rb,
gems/gems/hanami-view-1.3.3/lib/hanami/view/errors.rb,
gems/gems/hanami-view-1.3.3/lib/hanami/view/escape.rb,
gems/gems/hanami-view-1.3.3/lib/hanami/view/version.rb,
gems/gems/hanami-view-1.3.3/lib/hanami/view/template.rb,
gems/gems/hanami-view-1.3.3/lib/hanami/view/rendering.rb,
gems/gems/hanami-view-1.3.3/lib/hanami/view/inheritable.rb,
gems/gems/hanami-view-1.3.3/lib/hanami/view/configuration.rb,
gems/gems/hanami-view-1.3.3/lib/hanami/view/rendering/scope.rb,
gems/gems/hanami-view-1.3.3/lib/hanami/view/rendering/options.rb,
gems/gems/hanami-view-1.3.3/lib/hanami/view/rendering/partial.rb,
gems/gems/hanami-view-1.3.3/lib/hanami/view/rendering/registry.rb,
gems/gems/hanami-view-1.3.3/lib/hanami/view/rendering/subscope.rb,
gems/gems/hanami-view-1.3.3/lib/hanami/view/rendering/template.rb,
gems/gems/hanami-view-1.3.3/lib/hanami/view/rendering/null_view.rb,
gems/gems/hanami-view-1.3.3/lib/hanami/view/rendering/null_local.rb,
gems/gems/hanami-view-1.3.3/lib/hanami/view/rendering/null_layout.rb,
gems/gems/hanami-view-1.3.3/lib/hanami/view/rendering/view_finder.rb,
gems/gems/hanami-view-1.3.3/lib/hanami/view/rendering/layout_scope.rb,
gems/gems/hanami-view-1.3.3/lib/hanami/view/rendering/partial_file.rb,
gems/gems/hanami-view-1.3.3/lib/hanami/view/rendering/layout_finder.rb,
gems/gems/hanami-view-1.3.3/lib/hanami/view/rendering/null_template.rb,
gems/gems/hanami-view-1.3.3/lib/hanami/view/rendering/template_name.rb,
gems/gems/hanami-view-1.3.3/lib/hanami/view/rendering/partial_finder.rb,
gems/gems/hanami-view-1.3.3/lib/hanami/view/rendering/layout_registry.rb,
gems/gems/hanami-view-1.3.3/lib/hanami/view/rendering/template_finder.rb,
gems/gems/hanami-view-1.3.3/lib/hanami/view/rendering/templates_finder.rb,
gems/gems/hanami-view-1.3.3/lib/hanami/view/rendering/partial_templates_finder.rb,
gems/gems/hanami-view-1.3.3/lib/hanami/view.rb

Overview

View

Since:

  • 0.1.0

Defined Under Namespace

Modules: Dsl, Escape, Inheritable, Rendering Classes: Configuration, Error, MissingFormatError, MissingTemplateError, MissingTemplateLayoutError, Template, UnknownRenderTypeError

Constant Summary

VERSION =

Defines the version

Since:

  • 0.1.0

'1.3.3'.freeze

Class Method Summary collapse

Class Method Details

.configure(&blk) ⇒ Object

Configure the framework. It yields the given block in the context of the configuration

Examples:

require 'hanami/view'

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

Parameters:

  • blk (Proc)

    the configuration block

See Also:

Since:

  • 0.2.0

def self.configure(&blk)
  configuration.instance_eval(&blk)
end

.duplicate(mod, views = 'Views', &blk) ⇒ Module

Duplicate the framework and generate modules for the target application

module MyApp::Views::Dashboard class Index include MyApp::View end end

Examples:

Basic usage

require 'hanami/view'

module MyApp
  View = Hanami::View.duplicate(self)
end

# It will:
#
# 1. Generate MyApp::View
# 2. Generate MyApp::Layout
# 3. Generate MyApp::Presenter
# 4. Generate MyApp::Views
# 5. Configure MyApp::Views as the default namespace for views

Compare code

require 'hanami/view'

module MyApp
  View = Hanami::View.duplicate(self) do
    # ...
  end
end

# it's equivalent to:

module MyApp
  View   = Hanami::View.dupe
  Layout = Hanami::Layout.dup

  module Views
  end

  View.configure do
    namespace 'MyApp::Views'
  end

  View.configure do
    # ...
  end
end

Custom views module

require 'hanami/view

module MyApp
  View = Hanami::View.duplicate(self, 'Vs')
end

defined?(MyApp::Views) # => nil
defined?(MyApp::Vs)    # => "constant"

# Developers can namespace views under Vs
module MyApp::Vs::Dashboard
  # ...
end

Nil views module

require 'hanami/view'

module MyApp
  View = Hanami::View.duplicate(self, nil)
end

defined?(MyApp::Views) # => nil

# Developers can namespace views under MyApp
module MyApp
  # ...
end

Block usage

require 'hanami/view'

module MyApp
  View = Hanami::View.duplicate(self) do
    root '/path/to/root'
  end
end

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

Parameters:

  • mod (Module)

    the Ruby namespace of the application

  • views (String) (defaults to: 'Views')

    the optional namespace where the application’s views will live

  • blk (Proc)

    an optional block to configure the framework

Returns:

  • (Module)

    a copy of Hanami::View

See Also:

Since:

  • 0.2.0

def self.duplicate(mod, views = 'Views', &blk)
  dupe.tap do |duplicated|
    mod.module_eval %{ module #{ views }; end } if views
    mod.module_eval %{
      Layout = Hanami::Layout.dup
      Presenter = Hanami::Presenter.dup
    }

    duplicated.configure do
      namespace [mod, views].compact.join '::'
    end

    duplicated.configure(&blk) if block_given?
  end
end