Sha256: 3cb005c649edcfa41c0dc6f260f8a77ccb189aea8568b1736d100b61d942b2e5

Contents?: true

Size: 1.39 KB

Versions: 26

Compression:

Stored size: 1.39 KB

Contents

require 'haml'

module Caboodle
  Pages = []
  class Page
  
    attr_accessor :slug
    attr_accessor :body
    attr_accessor :file
  
    def initialize slug
      @slug = slug
    end
  
    def file
      @file ||= File.new(Dir[File.join(File.dirname(__FILE__),"pages","#{@slug}.haml")].first)
    end
  
    def self.all
      return Caboodle::Pages unless Caboodle::Pages.empty?
      Dir[File.join(File.dirname(__FILE__),"pages","*.haml")].map do |a| 
        p = Page.new(a.split("/").last.gsub(".haml",""))
        Caboodle::Pages << p
        Caboodle::MenuItems << {:display=>p.title, :link=>p.link}
      end
      
      return Caboodle::Pages
    end
  
    def self.get slug
      STDERR.puts "Get page: #{slug}"
      return nil unless Caboodle::Pages.map{|a| a.slug}.include?(slug)
      Page.new(slug.gsub(" ", "_"))
    end
  
    def body
      @body ||= file.read
    end
  
    def to_html
      Haml::Engine.new(body).render
    end
  
    def title
      @slug.gsub("_","").capitalize
    end
    
    def link
      "/#{slug}"
    end
  
  end
  
  class PageApp < Caboodle::Kit
        
    Caboodle::Site.pages = Caboodle::Page.all
    Caboodle::Site.pages.each do |page|
      get "/#{page.slug}" do
        @page = Page.get(request.path_info.gsub("/",""))
        pass if @page.blank?
        @title = @page.title
        haml :page, :locals => {:page => @page}
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
caboodle-0.2.21 lib/caboodle/kits/page/page.rb
caboodle-0.2.20 lib/caboodle/kits/page/page.rb
caboodle-0.2.19 lib/caboodle/kits/page/page.rb
caboodle-0.2.18 lib/caboodle/kits/page/page.rb
caboodle-0.2.16 lib/caboodle/kits/page/page.rb
caboodle-0.2.15 lib/caboodle/kits/page/page.rb
caboodle-0.2.14 lib/caboodle/kits/page/page.rb
caboodle-0.2.13 lib/caboodle/kits/page/page.rb
caboodle-0.2.12 lib/caboodle/kits/page/page.rb
caboodle-0.2.11 lib/caboodle/kits/page/page.rb
caboodle-0.2.10 lib/caboodle/kits/page/page.rb
caboodle-0.2.9 lib/caboodle/kits/page/page.rb
caboodle-0.2.8 lib/caboodle/kits/page/page.rb
caboodle-0.2.7 lib/caboodle/kits/page/page.rb
caboodle-0.2.6 lib/caboodle/kits/page/page.rb
caboodle-0.2.5 lib/caboodle/kits/page/page.rb
caboodle-0.2.3 lib/caboodle/kits/page/page.rb
caboodle-0.2.2 lib/caboodle/kits/page/page.rb
caboodle-0.2.1 lib/caboodle/kits/page/page.rb
caboodle-0.2.0 lib/caboodle/kits/page/page.rb