Skip to content

Commit

Permalink
Implemented Lotus::View::Configuration#views and #layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
jodosha committed Jun 5, 2014
1 parent 268cc22 commit cdf7fb8
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/lotus/view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def self.configure(&blk)
# @api private
# @since 0.1.0
def self.views
@views ||= Set.new
configuration.views
end

# A set of registered layouts.
Expand All @@ -97,7 +97,7 @@ def self.views
# @api private
# @since 0.1.0
def self.layouts
@layouts ||= Set.new
configuration.layouts
end

#FIXME extract a Loader class
Expand Down
13 changes: 13 additions & 0 deletions lib/lotus/view/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'set'
require 'lotus/utils/kernel'
require 'lotus/utils/load_paths'
require 'lotus/view/rendering/layout_finder'
Expand All @@ -9,6 +10,8 @@ class Configuration
DEFAULT_ROOT = '.'.freeze

attr_reader :load_paths
attr_reader :views
attr_reader :layouts

def initialize
reset!
Expand All @@ -30,9 +33,19 @@ def layout(value = nil)
end
end

def add_view(view)
@views.add(view)
end

def add_layout(layout)
@layouts.add(layout)
end

def reset!
root(DEFAULT_ROOT)

@views = Set.new
@layouts = Set.new
@load_paths = Utils::LoadPaths.new(root)
@layout = Rendering::NullLayout
end
Expand Down
40 changes: 40 additions & 0 deletions test/view/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,49 @@ def to_pathname
end
end

describe '#views' do
it 'defaults to an empty set' do
@configuration.views.must_be_empty
end

it 'allows to add views' do
@configuration.add_view(HelloWorldView)
@configuration.views.must_include(HelloWorldView)
end

it 'eliminates duplications' do
@configuration.add_view(RenderView)
@configuration.add_view(RenderView)

@configuration.views.size.must_equal(1)
end
end

describe '#layouts' do
it 'defaults to an empty set' do
@configuration.layouts.must_be_empty
end

it 'allows to add layouts' do
@configuration.add_layout(ApplicationLayout)
@configuration.layouts.must_include(ApplicationLayout)
end

it 'eliminates duplications' do
@configuration.add_layout(GlobalLayout)
@configuration.add_layout(GlobalLayout)

@configuration.layouts.size.must_equal(1)
end
end

describe '#reset!' do
before do
@configuration.root 'test'
@configuration.load_paths << '..'
@configuration.layout :application
@configuration.add_view(HelloWorldView)
@configuration.add_layout(ApplicationLayout)
@configuration.reset!
end

Expand All @@ -102,6 +140,8 @@ def to_pathname
@configuration.root.must_equal root
@configuration.load_paths.must_equal [root]
@configuration.layout.must_equal Lotus::View::Rendering::NullLayout
@configuration.views.must_be_empty
@configuration.layouts.must_be_empty
end
end
end

0 comments on commit cdf7fb8

Please sign in to comment.