Class: Lotus::View::Rendering::LayoutFinder Private

Inherits:
Object
  • Object
show all
Defined in:
lib/lotus/view/rendering/layout_finder.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Defines the logic to find a layout

See Also:

Since:

  • 0.1.0

Constant Summary collapse

SUFFIX =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Layout class name suffix

Since:

  • 0.1.0

'Layout'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(view) ⇒ LayoutFinder

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize the finder

Parameters:

  • view (Class, #layout)

Since:

  • 0.1.0



58
59
60
# File 'lib/lotus/view/rendering/layout_finder.rb', line 58

def initialize(view)
  @view = view
end

Class Method Details

.find(layout) ⇒ Lotus::Layout

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Find a layout from the given name.

Examples:

With given name

require 'lotus/view'

Lotus::View::Rendering::LayoutFinder.find(:article) # =>
  ArticleLayout

With nil

require 'lotus/view'

Lotus::View.layout # => :application
Lotus::View::Rendering::LayoutFinder.find(nil) # =>
  ApplicationLayout

Parameters:

  • layout (Symbol, String, NilClass)

    layout name or nil if you want to fallback to the framework defaults (see ‘Lotus::View.layout`).

Returns:

  • (Lotus::Layout)

    the layout for the given name or ‘Lotus::View.layout`

Since:

  • 0.1.0



42
43
44
45
46
47
48
49
50
# File 'lib/lotus/view/rendering/layout_finder.rb', line 42

def self.find(layout)
  case layout
  when Symbol, String
    class_name = "#{ Utils::String.new(layout).classify }#{ SUFFIX }"
    Object.const_get(class_name)
  when nil
    Lotus::View.layout
  end
end

Instance Method Details

#findLotus::Layout

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Find the layout for the view

Examples:

With layout

require 'lotus/view'

module Articles
  class Show
    include Lotus::View
    layout :article
  end
end

Lotus::View::Rendering::LayoutFinder.new(Articles::Show) # =>
  ArticleLayout

Without layout

require 'lotus/view'

module Dashboard
  class Index
    include Lotus::View
  end
end

Lotus::View.layout # => :application

Lotus::View::Rendering::LayoutFinder.new(Dashboard::Index) # =>
  ApplicationLayout

Returns:

See Also:

Since:

  • 0.1.0



98
99
100
# File 'lib/lotus/view/rendering/layout_finder.rb', line 98

def find
  self.class.find(@view.layout)
end