Module: Lotus::View

Defined in:
lib/lotus/view.rb,
lib/lotus/view/dsl.rb,
lib/lotus/view/version.rb,
lib/lotus/view/template.rb,
lib/lotus/view/rendering.rb,
lib/lotus/view/inheritable.rb,
lib/lotus/view/rendering/scope.rb,
lib/lotus/view/rendering/partial.rb,
lib/lotus/view/rendering/registry.rb,
lib/lotus/view/rendering/template.rb,
lib/lotus/view/rendering/null_layout.rb,
lib/lotus/view/rendering/view_finder.rb,
lib/lotus/view/rendering/layout_scope.rb,
lib/lotus/view/rendering/layout_finder.rb,
lib/lotus/view/rendering/null_template.rb,
lib/lotus/view/rendering/partial_finder.rb,
lib/lotus/view/rendering/layout_registry.rb,
lib/lotus/view/rendering/template_finder.rb,
lib/lotus/view/rendering/templates_finder.rb

Overview

View

Since:

  • 0.1.0

Defined Under Namespace

Modules: Dsl, Inheritable, Rendering Classes: MissingFormatError, MissingTemplateError, Template

Constant Summary collapse

VERSION =

Defines the version

Since:

  • 0.1.0

'0.1.0'.freeze

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object

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.

Register a view

Examples:

require 'lotus/view'

class IndexView
  include Lotus::View
end

Since:

  • 0.1.0



55
56
57
58
59
60
61
62
63
# File 'lib/lotus/view.rb', line 55

def self.included(base)
  base.class_eval do
    extend Inheritable.dup
    extend Dsl.dup
    extend Rendering.dup
  end

  views.add(base)
end

.layoutClass, Rendering::NullLayout

Returns the default layout to assign to the registered views. If not already set, it returns a Rendering::NullLayout.

Returns:

See Also:

Since:

  • 0.1.0



139
140
141
# File 'lib/lotus/view.rb', line 139

def self.layout
  @layout ||= Rendering::NullLayout
end

.layout=(layout) ⇒ Object

Sets the default layout for all the registered views.

Examples:

require 'lotus/view'

Lotus::View.layout = :application

class IndexView
  include Lotus::View
end

Lotus::View.load!
IndexView.layout # => ApplicationLayout

Parameters:

  • layout (Symbol)

    the layout name

See Also:

Since:

  • 0.1.0



127
128
129
# File 'lib/lotus/view.rb', line 127

def self.layout=(layout)
  @layout = Rendering::LayoutFinder.find(layout)
end

.layoutsSet

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.

A set of registered layouts.

Returns:

  • (Set)

    all the registered layout.

Since:

  • 0.1.0



159
160
161
# File 'lib/lotus/view.rb', line 159

def self.layouts
  @layouts ||= Set.new
end

.load!Object

FIXME extract a Loader class

Since:

  • 0.1.0



164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/lotus/view.rb', line 164

def self.load!
  root.freeze
  layout.freeze
  views.freeze

  views.each do |view|
    view.send(:load!)
  end

  layouts.each do |layout|
    layout.send(:load!)
  end
end

.rootPathname

Returns the directory root where templates are located. If not already set, it returns the current directory.

Examples:

with already set value

require 'lotus/view'

Lotus::View.root = '/path/to/templates'
Lotus::View.root # => #<Pathname:/path/to/templates>

with missing set value

require 'lotus/view'

Lotus::View.root # => #<Pathname:.>

Returns:

  • (Pathname)

    the root path for templates

See Also:

Since:

  • 0.1.0



100
101
102
103
104
105
# File 'lib/lotus/view.rb', line 100

def self.root
  @root ||= begin
    self.root = '.'
    @root
  end
end

.root=(root) ⇒ Object

Set the directory root where templates are located

Examples:

require 'lotus/view'

Lotus::View.root = '/path/to/templates'

Parameters:

  • root (String)

    the root path

See Also:

Since:

  • 0.1.0



77
78
79
# File 'lib/lotus/view.rb', line 77

def self.root=(root)
  @root = Pathname.new(root) rescue nil
end

.unload!Object

Since:

  • 0.1.0



178
179
180
181
182
183
# File 'lib/lotus/view.rb', line 178

def self.unload!
  instance_variable_set(:@root, nil)
  instance_variable_set(:@layout, nil)
  instance_variable_set(:@views, Set.new)
  instance_variable_set(:@layouts, Set.new)
end

.viewsSet

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.

A set of registered views.

Returns:

  • (Set)

    all the registered views.

Since:

  • 0.1.0



149
150
151
# File 'lib/lotus/view.rb', line 149

def self.views
  @views ||= Set.new
end