Sha256: 9fd7fc7efd0aade4deff238c3c391593f84269bd08e7f2627b5fff823a4889a7

Contents?: true

Size: 962 Bytes

Versions: 2

Compression:

Stored size: 962 Bytes

Contents

module Slippers
  class TemplateGroup
    def initialize(params={})
      @templates = params[:templates]
      @super_group = params[:super_group]
    end
    
    def find(subtemplate)
      return nil unless @templates
      return @templates[subtemplate.to_sym] if @templates.include?(subtemplate.to_sym)
      find_in_super_group(subtemplate)
    end
    
    def has_registered?(class_name)
       return false unless @templates
       return true if @templates.include?(class_name) 
       return false unless @super_group
       @super_group.has_registered?(class_name)  
    end
    
    def render(item)
      return '' unless @templates
      return @templates[item.class].render(item) if has_registered?(item.class)
      return '' unless @super_group
      @super_group.render(item)
    end
    
    private
      def find_in_super_group(subtemplate)
        return nil unless @super_group 
        @super_group.find(subtemplate)
      end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
starapor-slippers-0.0.6 lib/engine/template_group.rb
starapor-slippers-0.0.8 lib/engine/template_group.rb