Sha256: c14354ec94cd69e8bda416e8065d19e5d0cc3eaeffc2cb9dac0b267ba9d9cbcf
Contents?: true
Size: 872 Bytes
Versions: 3
Compression:
Stored size: 872 Bytes
Contents
module Suricate class TemplateRepository class TemplateNotFound < StandardError; end SUPPORTED_FORMATS = %w(html txt).freeze attr_reader :path def initialize(path) @path = path end def find_widget(name) path = File.join('widgets', name) find(path) end def find_page(name) path = File.join('pages', name) find(path) end def find(name) path = find_full_path(name) or raise TemplateNotFound.new("#{name} can't be found in #{@path}") Template.new(path) end private def find_full_path(name) base_path = File.join(@path, name) if File.exists?(base_path) base_path else possible_paths = SUPPORTED_FORMATS.map { |format| base_path + ".#{format}" } possible_paths.find { |path| File.exists?(path) } end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
suricate-0.0.4 | lib/suricate/template/template_repository.rb |
suricate-0.0.3 | lib/suricate/template/template_repository.rb |
suricate-0.0.2 | lib/suricate/template/template_repository.rb |