Sha256: 62ac9a6a716496e28a4c1ad19e01466ffaebf65ba548f11331c6a0a7cff7dacf
Contents?: true
Size: 1.17 KB
Versions: 1
Compression:
Stored size: 1.17 KB
Contents
module Kitsune module Page def self.included(model) model.class_eval do admin do display :title, :layout, :parent_id, :url wysiwyg :body select :layout, Proc.new {Dir.glob(File.join(RAILS_ROOT, 'app', 'views', 'layouts', '*.html.*')).map{|f| File.basename(f).split('.').first}} end before_save :update_url belongs_to :page, :foreign_key => "parent_id" belongs_to :parent, :class_name => 'Page' validate :must_be_kitsune_route validates_uniqueness_of :url def title_for_url CGI.escape(title.downcase.gsub(/\s+/, '-')).squeeze('-') end def url_for_page parent ? parent.url_for_page + '/' + title_for_url : '/' + title_for_url end def update_url write_attribute :url, (url.present? ? url : url_for_page) end def must_be_kitsune_route unless ActionController::Routing::Routes.recognize_path(url.present? ? url : url_for_page)[:controller] == 'kitsune' errors.add_to_base("URL is already being used") end end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
kitsune-0.1.4 | lib/kitsune/page.rb |