Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for Current Radiant Edge #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ To add stereotypes you need to add fields to the Radiant::Config table. There ar

1.) Page Parts (and filters)

The key has to look like: `stereotype.<name_of_the_stereotype>.parts` and the value `body:markdown,sidebar:textile`.
The key has to look like: `stereotype.<name_of_the_stereotype>.parts` and the value `body:Markdown,sidebar:Textile`.

2.) Layout

Expand Down
14 changes: 11 additions & 3 deletions lib/stereotype/page_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@ module PageExtensions
def self.included(base)
base.extend ClassMethods
base.class_eval do
class <<self
class << self
alias_method_chain :new_with_defaults, :stereotype
end
after_save :update_custom_fields
include InstanceMethods
end

Admin::PagesController.class_eval do
def new
@page = self.model = model_class.new_with_defaults(config, params)
assign_page_attributes
response_for :new
end
end
end

module InstanceMethods
Expand All @@ -31,10 +39,10 @@ def update_custom_fields
end

module ClassMethods
def new_with_defaults_with_stereotype(config = Radiant::Config)
def new_with_defaults_with_stereotype(config = Radiant::Config, params = nil)
page = new

custom_field = CustomField.find(:first, :conditions => { :name => "stereotype", :page_id => page.parent_id})
custom_field = CustomField.find(:first, :conditions => { :name => "stereotype", :page_id => params['page_id']})
name = custom_field && custom_field.value

if name
Expand Down