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

Commit

Permalink
added theme repository, installer
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Adams committed Oct 3, 2008
1 parent 7c92a43 commit 06b03be
Show file tree
Hide file tree
Showing 25 changed files with 325 additions and 1 deletion.
3 changes: 2 additions & 1 deletion config/routes.rb
Expand Up @@ -5,7 +5,8 @@
map.from_plugin :ansuz_content_section
map.from_plugin :ansuz_user_manager
map.from_plugin :ansuz_menu_system
map.from_plugin :ansuz_scrollable_content
map.from_plugin :ansuz_theme_repository
map.from_plugin :ansuz_theme_installer

map.resources :users
map.resources :tags
Expand Down
4 changes: 4 additions & 0 deletions vendor/plugins/ansuz_theme_installer/README
@@ -0,0 +1,4 @@
AnsuzThemeRepository
===================

This plugin provides the ability for an ansuz site to serve as a theme repository for other ansuz sites.
22 changes: 22 additions & 0 deletions vendor/plugins/ansuz_theme_installer/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
@@ -0,0 +1,21 @@
class Admin::AnsuzThemeInstallersController < Admin::BaseController
unloadable # This is required if you subclass a controller provided by the base rails app

layout 'admin'
before_filter :load_themes, :only => [:index]

protected
def load_themes
@themes = Ansuz::JAdams::AnsuzThemesListing.listing
end

public
def index
end

def install
Ansuz::JAdams::AnsuzThemesListing.install(params[:repository_url])
flash[:notice] = "Theme installed successfully."
redirect_to admin_ansuz_theme_installers_path
end
end
@@ -0,0 +1,7 @@
class Ansuz
class JAdams
class AnsuzTheme < ActiveRecord::Base
validates_uniqueness_of :name
end
end
end
10 changes: 10 additions & 0 deletions vendor/plugins/ansuz_theme_installer/app/models/menu_entry.rb
@@ -0,0 +1,10 @@
class Ansuz
class JAdams
class MenuEntry < ActiveRecord::Base
acts_as_tree :order => 'position'
def self.root_entries
Ansuz::JAdams::MenuEntry.find(:all, :conditions => "parent_id IS NULL", :order => 'position')
end
end
end
end
@@ -0,0 +1,15 @@
<%= title "Install Themes" -%>
<table class='subdued'>
<thead>
<tr>
<th>Name</th>
</tr>
</thead>
<tbody>
<% @themes.each do |theme| -%>
<tr>
<td><%= link_to(theme[0], install_admin_ansuz_theme_installers_path(:repository_url => theme[1])) -%></td>
</tr>
<% end -%>
</tbody>
</table>
@@ -0,0 +1,13 @@
class CreateAnsuzThemes < ActiveRecord::Migration
def self.up
create_table "ansuz_themes", :force => true do |t|
t.string "name"
t.string "repository_url"
t.timestamps
end
end

def self.end
drop_table "ansuz_themes"
end
end
3 changes: 3 additions & 0 deletions vendor/plugins/ansuz_theme_installer/init.rb
@@ -0,0 +1,3 @@
# Include hook code here
require 'ansuz/jadams/ansuz_themes_listing'
Ansuz::PluginManagerInstance.register_admin_plugin_nav('Install Themes', '/admin/ansuz_theme_installers')
@@ -0,0 +1,34 @@
require 'open-uri'
class Ansuz
class JAdams
class AnsuzThemesListing
REPOSITORY = "http://localhost:3001/ansuz_themes.xml"

# Returns an array of theme arrays. A theme array
# looks like [name, repository_url]
def self.listing
ary = []
xml.elements.each("themes/theme") do |theme|
name = theme.elements["name"].text
repository_url = theme.elements["repository_url"].text
ary << [name, repository_url]
end
ary
end

def self.xml_document
uri = URI.parse REPOSITORY
uri.read
end

def self.xml
REXML::Document.new xml_document
end

# This method will install a theme, given a repository url
def self.install repository_url
`cd #{RAILS_ROOT}/themes; git clone #{repository_url}`
end
end
end
end
3 changes: 3 additions & 0 deletions vendor/plugins/ansuz_theme_installer/routes.rb
@@ -0,0 +1,3 @@
namespace :admin do |admin|
admin.resources :ansuz_theme_installers, :collection => [:install]
end
4 changes: 4 additions & 0 deletions vendor/plugins/ansuz_theme_repository/README
@@ -0,0 +1,4 @@
AnsuzThemeRepository
===================

This plugin provides the ability for an ansuz site to serve as a theme repository for other ansuz sites.
22 changes: 22 additions & 0 deletions vendor/plugins/ansuz_theme_repository/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
@@ -0,0 +1,56 @@
class Admin::AnsuzThemesController < Admin::BaseController
unloadable # This is required if you subclass a controller provided by the base rails app

layout 'admin'
before_filter :load_ansuz_theme, :only => [:show, :edit, :update]
before_filter :load_new_ansuz_theme, :only => [:new, :create]
before_filter :load_ansuz_themes, :only => [:index]

protected
def load_ansuz_theme
@ansuz_theme = Ansuz::JAdams::AnsuzTheme.find(params[:id])
end

def load_new_ansuz_theme
@ansuz_theme = Ansuz::JAdams::AnsuzTheme.new(params[:ansuz_theme])
end

def load_ansuz_themes
@ansuz_themes = Ansuz::JAdams::AnsuzTheme.find(:all, :order => 'name DESC')
end
public
def new
end

def create
if @ansuz_theme.save
flash[:notice] = "Ansuz Theme was created successfully."
redirect_to admin_ansuz_themes_path
else
flash.now[:error] = "There was a problem creating the ansuz theme."
render :action => 'new'
end
end

def show
end

def edit
end

def update
if @ansuz_theme.update_attributes(params[:ansuz_theme])
flash[:notice] = "Ansuz Theme has been updated."
redirect_to admin_ansuz_themes_path
else
flash.now[:error] = "There was a problem updating the Ansuz Theme. Please try again."
render :action => 'edit'
end
end

def destroy
@ansuz_theme.destroy
flash[:notice] = "Ansuz Theme was deleted."
redirect_to admin_ansuz_themes_path
end
end
@@ -0,0 +1,18 @@
class AnsuzThemesController < ApplicationController
unloadable # This is required if you subclass a controller provided by the base rails app

before_filter :load_ansuz_themes, :only => [:index]

protected
def load_ansuz_themes
@ansuz_themes = Ansuz::JAdams::AnsuzTheme.find(:all)
end

public

def index
respond_to do |format|
format.xml{ render }
end
end
end
@@ -0,0 +1,7 @@
class Ansuz
class JAdams
class AnsuzTheme < ActiveRecord::Base
validates_uniqueness_of :name
end
end
end
10 changes: 10 additions & 0 deletions vendor/plugins/ansuz_theme_repository/app/models/menu_entry.rb
@@ -0,0 +1,10 @@
class Ansuz
class JAdams
class MenuEntry < ActiveRecord::Base
acts_as_tree :order => 'position'
def self.root_entries
Ansuz::JAdams::MenuEntry.find(:all, :conditions => "parent_id IS NULL", :order => 'position')
end
end
end
end
@@ -0,0 +1,2 @@
Name: <%= f.text_field(:name) -%><br />
Repository URL: <%= f.text_field(:repository_url) -%><br />
@@ -0,0 +1,8 @@
<%= title "Edit Ansuz Theme: #{@ansuz_theme}" -%>
<% content_for :sidebar do -%>
<%= link_to "All Ansuz Themes", admin_ansuz_themes_path -%>
<% end -%>
<% form_for :ansuz_theme, :url => admin_ansuz_theme_path(@ansuz_theme), :html => { :method => :put } do |f| -%>
<%= render :partial => 'form', :locals => { :f => f } -%>
<%= submit_tag("Update Ansuz Theme") -%> or <%= link_to "Cancel", admin_ansuz_themes_path -%>
<% end -%>
@@ -0,0 +1,28 @@
<%= title "Ansuz Themes" -%>
<% content_for :sidebar do -%>
<%= link_to "New Ansuz Theme", new_admin_ansuz_theme_path -%><br />
<%= link_to "Themes Feed", ansuz_themes_path(:format => 'xml') -%>
<% end -%>
<table class='subdued'>
<thead>
<tr>
<th>Name</th>
<th>Repository URL</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<% @ansuz_themes.each do |ansuz_theme| -%>
<tr class='<%= cycle('odd', 'even') -%>'>
<td><%= link_to h(ansuz_theme.name), admin_ansuz_theme_path(ansuz_theme) -%></td>
<td><%= ansuz_theme.repository_url -%></td>
<td>
<ul class='admin_actions'>
<li><%= link_to "Edit", edit_admin_ansuz_theme_path(ansuz_theme) -%></li>
<li><%= link_to "Delete", admin_ansuz_theme_path(ansuz_theme), :method => :delete, :confirm => "Are you sure you want to delete this ansuz theme?" -%></li>
</ul>
</td>
</tr>
<% end -%>
</tbody>
</table>
@@ -0,0 +1,8 @@
<%= title "New Ansuz Theme" -%>
<% content_for :sidebar do -%>
<%= link_to "All Ansuz Themes", admin_ansuz_themes_path -%>
<% end -%>
<% form_for :ansuz_theme, :url => admin_ansuz_themes_path do |f| -%>
<%= render :partial => 'form', :locals => { :f => f } -%>
<%= submit_tag("Create Ansuz Theme") -%> or <%= link_to "Cancel", admin_ansuz_themes_path -%>
<% end -%>
@@ -0,0 +1,8 @@
xml.themes do
@ansuz_themes.each do |theme|
xml.theme do
xml.name theme.name
xml.repository_url theme.repository_url
end
end
end
@@ -0,0 +1,13 @@
class CreateAnsuzThemes < ActiveRecord::Migration
def self.up
create_table "ansuz_themes", :force => true do |t|
t.string "name"
t.string "repository_url"
t.timestamps
end
end

def self.end
drop_table "ansuz_themes"
end
end
3 changes: 3 additions & 0 deletions vendor/plugins/ansuz_theme_repository/init.rb
@@ -0,0 +1,3 @@
# Include hook code here
require 'ansuz_theme'
Ansuz::PluginManagerInstance.register_admin_plugin_nav('Theme Repository', '/admin/ansuz_themes')
4 changes: 4 additions & 0 deletions vendor/plugins/ansuz_theme_repository/routes.rb
@@ -0,0 +1,4 @@
namespace :admin do |admin|
admin.resources :ansuz_themes
end
resources :ansuz_themes

0 comments on commit 06b03be

Please sign in to comment.