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