Skip to content

Commit

Permalink
Merge pull request #56 from jc00ke/master
Browse files Browse the repository at this point in the history
LayoutRegistry composes Hash instead of inheriting.
  • Loading branch information
jodosha committed Feb 4, 2015
2 parents 07b2871 + e856bbb commit 182ec0b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
11 changes: 5 additions & 6 deletions lib/lotus/view/rendering/layout_registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,15 @@ def initialize(template)
# @since 0.1.0
#
# @see Lotus::Layout::ClassMethods#registry
class LayoutRegistry < ::Hash
class LayoutRegistry
# Initialize the registry
#
# @param view [Class] the view
#
# @api private
# @since 0.1.0
def initialize(view)
super()

@registry = {}
@view = view
prepare!
end
Expand All @@ -50,15 +49,15 @@ def initialize(view)
# @api private
# @since 0.1.0
def resolve(context)
fetch(format(context)) { NullTemplate.new }
@registry.fetch(format(context)) { NullTemplate.new }
end

protected
def prepare!
templates.each do |template|
merge! template.format => template
@registry.merge! template.format => template
end
self.any? or raise MissingTemplateLayoutError.new(@view)
@registry.any? or raise MissingTemplateLayoutError.new(@view)
end

def templates
Expand Down
6 changes: 3 additions & 3 deletions lib/lotus/view/rendering/registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class Registry < LayoutRegistry
#
# @see Lotus::View::Rendering#render
def resolve(context)
view, template = fetch(format(context)) { self[DEFAULT_FORMAT] }
view, template = @registry.fetch(format(context)) { @registry[DEFAULT_FORMAT] }
view.new(template, context)
end

Expand All @@ -101,13 +101,13 @@ def prepare!

def prepare_views!
views.each do |view|
merge! view.format || DEFAULT_FORMAT => [ view, template_for(view) ]
@registry.merge! view.format || DEFAULT_FORMAT => [ view, template_for(view) ]
end
end

def prepare_templates!
templates.each do |template|
merge! template.format => [ view_for(template), template ]
@registry.merge! template.format => [ view_for(template), template ]
end
end

Expand Down

0 comments on commit 182ec0b

Please sign in to comment.