Skip to content
This repository has been archived by the owner on Aug 15, 2018. It is now read-only.

Commit

Permalink
added plugin architecture and content section plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Adams committed Aug 24, 2008
1 parent 7dafc06 commit 2f5843e
Show file tree
Hide file tree
Showing 39 changed files with 326 additions and 9 deletions.
16 changes: 16 additions & 0 deletions README
Expand Up @@ -7,3 +7,19 @@ out of the box than any other Rails CMS we’re aware of.
By combing the CMSes of Isshen Solutions and Isotope 11, we plan to create
a best-of-breed technology suitable for production use on a myriad of sites.
Ansuz will be licensed initially via GPLv2.

== Quick Start

1. clone from github: git clone git://github.com/knewter/ansuz.git
2. create database config in config/database.yml (see config/database.yml.example if you need help)
3. create databases: rake db:create:all
4. run migrations: rake db:migrate
5. run tests: rake spec
6. start console: script/console
7. create a new user: u = User.new :login => ‘admin’, :email => ‘admin@example.com’, :password => ‘admin’, :password_confirmation => ‘admin’
8. save the user: u.save
9. check the user exists: User.last
10. exist console: exit
11. start server: script/server -p 3000
12. goto: http://localhost:3000/admin
13. login with admin/admin
23 changes: 23 additions & 0 deletions app/controllers/content_sections_controller.rb
@@ -0,0 +1,23 @@
class ContentSectionsController < ApplicationController
before_filter :load_content_section, :only => [:show, :edit, :update, :destroy]
protected
def load_content_section
@content_section = Ansuz::JAdams::ContentSection.find(params[:id])
end
public
def show
end

def edit
end

def update
if @content_section.update_attributes(params[:content_section])
flash[:notice] = "Content Section has been updated."
redirect_to content_section_path(@content_section)
else
flash.now[:error] = "There was a problem updating the ContentSection. Please try again."
render :action => 'edit'
end
end
end
37 changes: 37 additions & 0 deletions app/controllers/page_plugins_controller.rb
@@ -0,0 +1,37 @@
class PagePluginsController < ApplicationController
before_filter :load_page, :only => [:new, :create]
before_filter :load_new_page_plugin, :only => [:new, :create]
before_filter :load_page_plugin, :only => [:edit]

protected
def load_page
@page = Page.find(params[:page_id])
end

def load_new_page_plugin
@page_plugin = PagePlugin.new(params[:page_plugin])
@page_plugin.page = @page
end

def load_page_plugin
@page_plugin = PagePlugin.find(params[:id])
end

public
def new
end

def edit
redirect_to @page_plugin.module.edit_path
end

def create
if @page_plugin.save
flash[:notice] = "Successfully saved the Page Plugin"
redirect_to '/admin'
else
flash.now[:error] = "There was a problem saving the Page Plugin"
render :action => 'new'
end
end
end
5 changes: 5 additions & 0 deletions app/controllers/plugins_controller.rb
@@ -0,0 +1,5 @@
class PluginsController < ApplicationController
def index
end

end
2 changes: 2 additions & 0 deletions app/helpers/page_plugins_helper.rb
@@ -0,0 +1,2 @@
module PagePluginsHelper
end
2 changes: 2 additions & 0 deletions app/helpers/plugins_helper.rb
@@ -0,0 +1,2 @@
module PluginsHelper
end
5 changes: 3 additions & 2 deletions app/models/page.rb
Expand Up @@ -20,9 +20,10 @@
#

class Page < ActiveRecord::Base
acts_as_tree :order => 'page_order'
before_save :check_page_type, :check_page_order
acts_as_tree :order => 'page_order'
before_save :check_page_type, :check_page_order
attr_protected :page_number, :pages
has_many :page_plugins

def full_title
full_title = read_attribute('full_title')
Expand Down
24 changes: 24 additions & 0 deletions app/models/page_plugin.rb
@@ -0,0 +1,24 @@
class PagePlugin < ActiveRecord::Base
belongs_to :page
after_create :create_module

def module
if module_type and module_id
module_class.find(module_id)
end
end

def module_class
module_type.constantize
end

def module_default_name
"Module for Page Plugin ##{self.id}"
end

def create_module
the_module = module_class.find_or_create_by_name(module_default_name)
self.module_id = the_module.id
self.save
end
end
6 changes: 5 additions & 1 deletion app/views/content/page.html.erb
@@ -1,4 +1,8 @@
<% if @page.display_title %>
<h2><%= @page.full_title %></h2>
<% end %>
<%= @page.page_body %>
<% if @page.page_plugins.any? -%>
<% @page.page_plugins.each do |plugin| -%>
<%= render :partial => plugin.module_class.view_partial, :locals => { :plugin_module => plugin.module } -%>
<% end -%>
<% end -%>
1 change: 1 addition & 0 deletions app/views/content_sections/_content_section.html.erb
@@ -0,0 +1 @@
<%= plugin_module.contents -%>
1 change: 1 addition & 0 deletions app/views/content_sections/_edit.html.erb
@@ -0,0 +1 @@
This is the edit view
6 changes: 6 additions & 0 deletions app/views/content_sections/edit.html.erb
@@ -0,0 +1,6 @@
<h1>Editing Content Section</h1>
<% form_for :content_section, :url => content_section_path(@content_section), :html => { :method => :put } do |f| -%>
<%= f.text_field(:name) -%><br />
<%= f.text_area(:contents) -%><br />
<%= submit_tag("Update Content Section") -%>
<% end -%>
3 changes: 2 additions & 1 deletion app/views/menu/_main.html.erb
Expand Up @@ -3,8 +3,9 @@
<h2>Admin</h2>
<ul>
<li><%= link_to_remote "Manage Pages", :update => "sitetree", :url => { :controller => 'page_admin', :action => "manage_tree" } %></li>
<li><%= link_to_remote 'List Plugins', :update => 'main', :url => { :controller => 'plugins', :action => 'index' } %></li>
<li><%= link_to_remote 'Account Settings', :update => 'main', :url => { :controller => 'account', :action => 'update' } %></li>
<li><%= link_to "Logout", :controller => 'account', :action => 'logout' %></li>
</ul>
</div>
<% end %>
<% end %>
4 changes: 1 addition & 3 deletions app/views/page_admin/_form.html.erb
Expand Up @@ -20,7 +20,5 @@
<label for="page_linked" class="advanced_options">Linked</label>
<select id="page_linked" name="page[linked]"><%= options_for_select [true, false], @page.linked %></select><br /><br />
</div></a><!-- end Advanced Options --></div><br/>
<label for="page_body" class="title_label">Body:</label><br/>
<%= text_area 'page', 'body', "cols" => 80, "rows" => 20 %>
</div><!-- end float left-->
<!--[eoform:page]-->
<!--[eoform:page]-->
10 changes: 9 additions & 1 deletion app/views/page_admin/edit.html.erb
Expand Up @@ -8,4 +8,12 @@
:html => { 'name' => 'page_form' } do -%>
<%= render :partial => 'form' %>
<%= submit_tag 'Update', :class => 'submit' -%>
<% end -%>
<% end -%>

<h2>Plugins on this page</h2>
<ul class='page_plugins'>
<% @page.page_plugins.each do |plugin| -%>
<li><%= link_to(plugin.module_type, edit_page_plugin_path(plugin.id)) -%></li>
<% end -%>
</ul>
<%= link_to "Add Plugin", new_page_plugin_path(:page_id => @page.id) -%>
2 changes: 2 additions & 0 deletions app/views/page_plugins/create.html.erb
@@ -0,0 +1,2 @@
<h1>PagePlugins#create</h1>
<p>Find me in app/views/page_plugins/create.html.erb</p>
2 changes: 2 additions & 0 deletions app/views/page_plugins/edit.html.erb
@@ -0,0 +1,2 @@
<h1>Edit</h1>
<%= render :partial => @page_plugin.module_class.edit_template -%>
6 changes: 6 additions & 0 deletions app/views/page_plugins/new.html.erb
@@ -0,0 +1,6 @@
<h1>New PagePlugin</h1>
<% form_for @page_plugin do |f| -%>
<%= hidden_field_tag(:page_id, params[:page_id]) -%>
<%= f.select(:module_type, Ansuz::PluginManagerInstance.plugins.map(&:to_s)) -%>
<%= submit_tag("Add Plugin") -%>
<% end -%>
6 changes: 6 additions & 0 deletions app/views/plugins/index.html.erb
@@ -0,0 +1,6 @@
<h1>Installed Plugins</h1>
<ul>
<% Ansuz::PluginManagerInstance.plugins.each do |plugin| -%>
<li><%= plugin.to_s -%></li>
<% end -%>
</ul>
4 changes: 4 additions & 0 deletions config/environment.rb
Expand Up @@ -10,6 +10,10 @@
# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')

require 'ansuz'
# Initialize the Ansuz Plugin Manager instance
Ansuz::PluginManagerInstance = Ansuz::PluginManager.new

Rails::Initializer.run do |config|
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
Expand Down
5 changes: 4 additions & 1 deletion config/routes.rb
@@ -1,4 +1,6 @@
ActionController::Routing::Routes.draw do |map|
map.resources :page_plugins
map.resources :content_sections
# The priority is based upon order of creation: first created -> highest priority.

# Sample of regular route:
Expand Down Expand Up @@ -39,8 +41,9 @@
# map.resource :admin, :controller => 'admin_pages'
map.connect 'admin/account/:action/:id', :controller => 'account'
map.connect 'admin/:action/:id', :controller => 'page_admin'
map.connect '*path', :controller => 'page', :action => 'indexer'
# stock rails routes
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
# Ansuz route
map.connect '*path', :controller => 'page', :action => 'indexer'
end
15 changes: 15 additions & 0 deletions db/migrate/20080824195700_create_page_plugins.rb
@@ -0,0 +1,15 @@
class CreatePagePlugins < ActiveRecord::Migration
def self.up
create_table :page_plugins do |t|
t.integer :page_id
t.string :module_type
t.integer :module_id

t.timestamps
end
end

def self.down
drop_table :page_plugins
end
end
13 changes: 13 additions & 0 deletions db/migrate/20080824204532_add_content_sections.rb
@@ -0,0 +1,13 @@
class AddContentSections < ActiveRecord::Migration
def self.up
create_table :content_sections do |t|
t.string :name
t.text :contents

t.timestamps
end
end

def self.down
end
end
1 change: 1 addition & 0 deletions lib/ansuz.rb
@@ -0,0 +1 @@
require 'ansuz/plugin_manager'
14 changes: 14 additions & 0 deletions lib/ansuz/plugin_manager.rb
@@ -0,0 +1,14 @@
class Ansuz
class PluginManager
attr_accessor :plugins

def initialize
@plugins = []
end

# A plugin can call register_plugin(ClassName) to add itself to the plugins array
def register_plugin klass
self.plugins << klass
end
end
end
2 changes: 2 additions & 0 deletions lib/ansuz_plugin.rb
@@ -0,0 +1,2 @@
class AnsuzPlugin
end
11 changes: 11 additions & 0 deletions test/fixtures/page_plugins.yml
@@ -0,0 +1,11 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html

one:
page_id: 1
module_type: MyString
module_id:

two:
page_id: 1
module_type: MyString
module_id:
8 changes: 8 additions & 0 deletions test/functional/page_plugins_controller_test.rb
@@ -0,0 +1,8 @@
require 'test_helper'

class PagePluginsControllerTest < ActionController::TestCase
# Replace this with your real tests.
def test_truth
assert true
end
end
8 changes: 8 additions & 0 deletions test/functional/plugins_controller_test.rb
@@ -0,0 +1,8 @@
require 'test_helper'

class PluginsControllerTest < ActionController::TestCase
# Replace this with your real tests.
def test_truth
assert true
end
end
8 changes: 8 additions & 0 deletions test/unit/page_plugin_test.rb
@@ -0,0 +1,8 @@
require 'test_helper'

class PagePluginTest < ActiveSupport::TestCase
# Replace this with your real tests.
def test_truth
assert true
end
end
20 changes: 20 additions & 0 deletions vendor/plugins/ansuz_content_section/MIT-LICENSE
@@ -0,0 +1,20 @@
Copyright (c) 2008 [name of plugin creator]

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13 changes: 13 additions & 0 deletions vendor/plugins/ansuz_content_section/README
@@ -0,0 +1,13 @@
AnsuzContentSection
===================

Introduction goes here.


Example
=======

Example goes here.


Copyright (c) 2008 [name of plugin creator], released under the MIT license
22 changes: 22 additions & 0 deletions vendor/plugins/ansuz_content_section/Rakefile
@@ -0,0 +1,22 @@
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'

desc 'Default: run unit tests.'
task :default => :test

desc 'Test the ansuz_content_section plugin.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end

desc 'Generate documentation for the ansuz_content_section plugin.'
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'AnsuzContentSection'
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.rdoc_files.include('README')
rdoc.rdoc_files.include('lib/**/*.rb')
end
3 changes: 3 additions & 0 deletions vendor/plugins/ansuz_content_section/init.rb
@@ -0,0 +1,3 @@
# Include hook code here
require 'content_section'
Ansuz::PluginManagerInstance.register_plugin(Ansuz::JAdams::ContentSection)
1 change: 1 addition & 0 deletions vendor/plugins/ansuz_content_section/install.rb
@@ -0,0 +1 @@
# Install hook code here

0 comments on commit 2f5843e

Please sign in to comment.