Class: FluffyBarbarian::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/fluffy_barbarian/page.rb

Class Method Summary collapse

Class Method Details

.all(path = "content/_pages") ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/fluffy_barbarian/page.rb', line 3

def self.all(path="content/_pages")
  @pages = Dir[File.join(path, "**", "*")].select{ |f| File.file? f }
  @pages = @pages.sort.map do |file|
    title = File.basename(file, ".*").tidy
    dir = file.split("/")[2..-2].map{ |dir| dir.parameterize }.join("/")
    slug = title.parameterize
    { :title => title, :path => File.expand_path(file), :type => "page",
      :autoslug => slug,
      :slug => slug,
      :dir => dir,
      :url => "#{"/#{dir}" if dir != ""}/#{slug}",
      :extname => File.extname(file) }
  end
end

.find(splat, slug) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/fluffy_barbarian/page.rb', line 18

def self.find(splat, slug)
  dir = ""
  # scope by directory first
  if splat
    dir = splat.split("/").tidy.map{ |part| part.parameterize }.join("/")

    @page = all.find{|page| page[:dir] == dir && page[:slug] == slug.parameterize }
  end
  @page ||= all.find{|page| page[:slug] == slug.parameterize }

  return nil unless @page

  if slug != @page[:slug] || dir != @page[:dir]
    @page[:fuzzy] = true
  else
    @page[:content] ||= Tilt.new(@page[:path]).render
  end

  @page
end