Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 37
- Log:
Completed the ERB behavior code. Extended the system to allow
filters access to instance variables too, thus providing better
ERB filter behavior. ERB filter renamed to reflect the new
requirement for Radiant changes - the old one can be used side
by side if need be, though the older one is deleted here since
the Web site doesn't need it. Added "execute command on change"
for filters and added a command to clear caches and restart the
ROOL site server.
- Author:
- adh
- Date:
- Sat Jul 29 22:15:05 +0100 2006
- Size:
- 2654 Bytes
1 | require_dependency 'advanced_delegation' |
2 | |
3 | class Page < ActiveRecord::Base |
4 | |
5 | class MissingRootPageError < StandardError |
6 | def initialize(message = 'Database missing root page'); super end |
7 | end |
8 | |
9 | # Callbacks |
10 | before_save :update_published_at, :update_virtual |
11 | |
12 | # Associations |
13 | acts_as_tree :order => 'virtual DESC, title ASC' |
14 | has_many :parts, :class_name => 'PagePart', :dependent => :destroy |
15 | belongs_to :layout |
16 | belongs_to :created_by, :class_name => 'User', :foreign_key => 'created_by' |
17 | belongs_to :updated_by, :class_name => 'User', :foreign_key => 'updated_by' |
18 | |
19 | # Validations |
20 | validates_presence_of :title, :slug, :breadcrumb, :status_id, :message => 'required' |
21 | |
22 | validates_length_of :title, :maximum => 255, :message => '%d-character limit' |
23 | validates_length_of :slug, :maximum => 100, :message => '%d-character limit' |
24 | validates_length_of :breadcrumb, :maximum => 160, :message => '%d-character limit' |
25 | validates_length_of :behavior_id, :maximum => 25, :allow_nil => true, :message => '%d-character limit' |
26 | |
27 | validates_format_of :slug, :with => %r{^([-_.A-Za-z0-9]*|/)$}, :message => 'invalid format' |
28 | validates_uniqueness_of :slug, :scope => :parent_id, :message => 'slug already in use for child of parent' |
29 | validates_numericality_of :id, :status_id, :parent_id, :allow_nil => true, :only_integer => true, :message => 'must be a number' |
30 | |
31 | delegate_to :behavior, :url => :page_url, :cache? => :cache_page?, :find_by_url => :find_page_by_url, |
32 | :render => :render_page, :virtual? => :page_virtual? |
33 | |
34 | delegate_to :behavior, :process, :child_url |
35 | |
36 | def after_initialize |
37 | class << self |
38 | define_method(:layout) do |*params| |
39 | super || (parent and parent.layout) |
40 | end |
41 | end |
42 | end |
43 | |
44 | def part(name) |
45 | parts.find_by_name name.to_s |
46 | end |
47 | |
48 | def status |
49 | Status.find(self.status_id) |
50 | end |
51 | |
52 | def status=(value) |
53 | self.status_id = value.id |
54 | end |
55 | |
56 | def published? |
57 | status == Status[:published] |
58 | end |
59 | |
60 | def behavior |
61 | if @behavior.nil? or (@old_behavior_id != behavior_id) |
62 | @old_behavior_id = behavior_id |
63 | @behavior = Behavior[behavior_id].new(self) |
64 | else |
65 | @behavior |
66 | end |
67 | end |
68 | |
69 | def self.find_by_url(url, live = true) |
70 | root = find_by_parent_id(nil) |
71 | raise MissingRootPageError unless root |
72 | root.find_by_url(url, live) |
73 | end |
74 | |
75 | def virtual |
76 | !(read_attribute('virtual').to_s =~ /^(false|f|0|)$/) |
77 | end |
78 | |
79 | private |
80 | |
81 | def update_published_at |
82 | write_attribute('published_at', Time.now) if (status_id.to_i == Status[:published].id) and published_at.nil? |
83 | true |
84 | end |
85 | |
86 | def update_virtual |
87 | write_attribute('virtual', virtual?) |
88 | true |
89 | end |
90 | |
91 | end |