Skip to content

Commit

Permalink
Removed Lotus::View's class accessor for root, in favor of the API of…
Browse files Browse the repository at this point in the history
… Lotus::View::Configuration
  • Loading branch information
jodosha committed Jun 4, 2014
1 parent aecbdf9 commit 268cc22
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 89 deletions.
8 changes: 8 additions & 0 deletions lib/lotus/layout.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'lotus/utils/class_attribute'
require 'lotus/view/rendering/layout_registry'
require 'lotus/view/rendering/layout_scope'
require 'lotus/view/rendering/null_layout'
Expand All @@ -21,9 +22,16 @@ module Layout
# include Lotus::Layout
# end
def self.included(base)
conf = View.configuration

base.class_eval do
extend Lotus::View::Dsl.dup
extend ClassMethods

include Utils::ClassAttribute
class_attribute :configuration

self.configuration = conf
end

Lotus::View.layouts.add(base)
Expand Down
44 changes: 0 additions & 44 deletions lib/lotus/view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,48 +80,6 @@ def self.configure(&blk)
configuration.instance_eval(&blk)
end

# Set the directory root where templates are located
#
# @param root [String] the root path
#
# @see Lotus::View.root
#
# @since 0.1.0
#
# @example
# require 'lotus/view'
#
# Lotus::View.root = '/path/to/templates'
def self.root=(root)
@root = Pathname.new(root) rescue nil
end

# Returns the directory root where templates are located.
# If not already set, it returns the current directory.
#
# @return [Pathname] the root path for templates
#
# @see Lotus::View.root=
#
# @since 0.1.0
#
# @example with already set value
# require 'lotus/view'
#
# Lotus::View.root = '/path/to/templates'
# Lotus::View.root # => #<Pathname:/path/to/templates>
#
# @example with missing set value
# require 'lotus/view'
#
# Lotus::View.root # => #<Pathname:.>
def self.root
@root ||= begin
self.root = '.'
@root
end
end

# A set of registered views.
#
# @return [Set] all the registered views.
Expand All @@ -144,7 +102,6 @@ def self.layouts

#FIXME extract a Loader class
def self.load!
root.freeze
views.freeze

views.each do |view|
Expand All @@ -157,7 +114,6 @@ def self.load!
end

def self.unload!
instance_variable_set(:@root, nil)
instance_variable_set(:@views, Set.new)
instance_variable_set(:@layouts, Set.new)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/lotus/view/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def root(value = nil)
if value
@@root = Pathname.new value
else
@@root ||= Lotus::View.root
@@root ||= configuration.root
end
end

Expand Down
4 changes: 0 additions & 4 deletions test/load_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
Lotus::View.load!
end

it 'freezes .root' do
Lotus::View.root.frozen?.must_equal true
end

it 'freezes .root for all the views' do
AppView.root.frozen?.must_equal true
end
Expand Down
38 changes: 0 additions & 38 deletions test/root_test.rb

This file was deleted.

6 changes: 5 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
require 'minitest/autorun'
$:.unshift 'lib'
require 'lotus/view'
Lotus::View.root = Pathname.new __dir__ + '/fixtures/templates'

Lotus::View.configure do
root Pathname.new __dir__ + '/fixtures/templates'
end

require 'fixtures'
Lotus::View.load!

Expand Down
14 changes: 13 additions & 1 deletion test/view_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@
class ConfigurationView
include Lotus::View
end

class ConfigurationLayout
include Lotus::Layout
end
end

after do
Object.send(:remove_const, :ConfigurationView)
Object.send(:remove_const, :ConfigurationLayout)
end

it 'exposes class configuration' do
Expand All @@ -25,12 +30,19 @@ class ConfigurationView
Lotus::View.configuration.root.must_equal(Pathname.new('.').realpath)
end

it 'inheriths the configuration from the framework' do
it 'a view inheriths the configuration from the framework' do
expected = Lotus::View.configuration
actual = ConfigurationView.configuration

actual.must_equal(expected)
end

it 'a layout inheriths the configuration from the framework' do
expected = Lotus::View.configuration
actual = ConfigurationLayout.configuration

actual.must_equal(expected)
end
end

describe '.configure' do
Expand Down

0 comments on commit 268cc22

Please sign in to comment.