Class: SemiStatic::Backend

Inherits:
Page
  • Object
show all
Defined in:
lib/semi_static/backend.rb

Instance Attribute Summary

Attributes inherited from Page

#body, #slug, #title

Instance Method Summary collapse

Methods inherited from Page

all, find, first, #persisted?, #render, #to_param, #to_s

Constructor Details

#initialize(root) ⇒ Backend

Returns a new instance of Backend.



4
5
6
7
# File 'lib/semi_static/backend.rb', line 4

def initialize(root)
  @root = root
  @cache = {}
end

Instance Method Details

#all(page_type) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/semi_static/backend.rb', line 9

def all(page_type)
  if !@cache.key?(page_type) || !Rails.application.config.cache_classes
    path = File.join(@root,ActiveModel::Naming.plural(page_type), "*")
    @cache[page_type] = Dir.glob(path).map do |f|
      yaml, body = File.read(f).split("\n...\n", 2)
      h = YAML.load(yaml)
      page_type.new(SemiStatic::TiltWrapper.template(f,body), h)
    end
  end
  @cache[page_type]
end