First steps for an own wiki.
* Scaffold for Page Objekt * Using textile for rendering html * Easy wiki-links with [[wikipage]]
This commit is contained in:
parent
37199bae1d
commit
f450070dbf
16 changed files with 252 additions and 1 deletions
86
app/controllers/pages_controller.rb
Normal file
86
app/controllers/pages_controller.rb
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
class PagesController < ApplicationController
|
||||||
|
|
||||||
|
def index
|
||||||
|
@page = Page.find_by_permalink "home"
|
||||||
|
|
||||||
|
if @page
|
||||||
|
render :action => 'show'
|
||||||
|
else
|
||||||
|
redirect_to all_pages_path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def show
|
||||||
|
@page = Page.find_by_permalink(params[:permalink])
|
||||||
|
|
||||||
|
if @page.nil?
|
||||||
|
redirect_to new_page_path(:title => params[:permalink])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# GET /pages/new
|
||||||
|
# GET /pages/new.xml
|
||||||
|
def new
|
||||||
|
@page = Page.new(:title => params[:title])
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html # new.html.erb
|
||||||
|
format.xml { render :xml => @page }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# GET /pages/1/edit
|
||||||
|
def edit
|
||||||
|
@page = Page.find(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
# POST /pages
|
||||||
|
# POST /pages.xml
|
||||||
|
def create
|
||||||
|
@page = Page.new(params[:page])
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
if @page.save
|
||||||
|
flash[:notice] = 'Page was successfully created.'
|
||||||
|
format.html { redirect_to(@page) }
|
||||||
|
format.xml { render :xml => @page, :status => :created, :location => @page }
|
||||||
|
else
|
||||||
|
format.html { render :action => "new" }
|
||||||
|
format.xml { render :xml => @page.errors, :status => :unprocessable_entity }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# PUT /pages/1
|
||||||
|
# PUT /pages/1.xml
|
||||||
|
def update
|
||||||
|
@page = Page.find(params[:id])
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
if @page.update_attributes(params[:page])
|
||||||
|
flash[:notice] = 'Page was successfully updated.'
|
||||||
|
format.html { redirect_to(@page) }
|
||||||
|
format.xml { head :ok }
|
||||||
|
else
|
||||||
|
format.html { render :action => "edit" }
|
||||||
|
format.xml { render :xml => @page.errors, :status => :unprocessable_entity }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# DELETE /pages/1
|
||||||
|
# DELETE /pages/1.xml
|
||||||
|
def destroy
|
||||||
|
@page = Page.find(params[:id])
|
||||||
|
@page.destroy
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { redirect_to(pages_url) }
|
||||||
|
format.xml { head :ok }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def all
|
||||||
|
@pages = Page.all :order => 'created_at'
|
||||||
|
end
|
||||||
|
end
|
18
app/helpers/pages_helper.rb
Normal file
18
app/helpers/pages_helper.rb
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
module PagesHelper
|
||||||
|
|
||||||
|
def wikified_body(body)
|
||||||
|
r = RedCloth.new(body)
|
||||||
|
r.gsub!(/\[\[(.*?)(\|(.*?))?\]\]/) { wiki_link($1, $3) }
|
||||||
|
sanitize r.to_html
|
||||||
|
r.to_html
|
||||||
|
end
|
||||||
|
|
||||||
|
def wiki_link(wiki_words, link_text = nil)
|
||||||
|
permalink = wiki_words.downcase.gsub(' ', '-')
|
||||||
|
if Page.exists?(:permalink => permalink)
|
||||||
|
link_to((link_text || wiki_words), wiki_page_url(permalink))
|
||||||
|
else
|
||||||
|
link_to((link_text || wiki_words), wiki_page_url(permalink), :class => "new_wiki_link")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
12
app/models/page.rb
Normal file
12
app/models/page.rb
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
class Page < ActiveRecord::Base
|
||||||
|
|
||||||
|
validates_presence_of :title, :body
|
||||||
|
|
||||||
|
before_save :set_permalink
|
||||||
|
|
||||||
|
def set_permalink
|
||||||
|
if self.permalink.blank? #FIXME: or title.changed?
|
||||||
|
self.permalink = Page.count == 0 ? "home" : "#{title.downcase.strip.gsub(/ |\.|@/, '-')}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -16,6 +16,11 @@
|
||||||
{ :name => "Aufgaben", :url => "/tasks"}
|
{ :name => "Aufgaben", :url => "/tasks"}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{ :name => "Wiki", :url => "/pages", :active => ["pages", "wiki"],
|
||||||
|
:subnav => [
|
||||||
|
{ :name => "Alle Seiten", :url => "pages/all" }
|
||||||
|
]
|
||||||
|
},
|
||||||
{ :name => "Bestellungen", :url => u.ordergroup ? "/ordering/" : "/orders",
|
{ :name => "Bestellungen", :url => u.ordergroup ? "/ordering/" : "/orders",
|
||||||
:active => ["orders", "ordering"],
|
:active => ["orders", "ordering"],
|
||||||
:subnav => [
|
:subnav => [
|
||||||
|
|
15
app/views/pages/_form.html.haml
Normal file
15
app/views/pages/_form.html.haml
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
- form_for @page do |f|
|
||||||
|
= f.error_messages
|
||||||
|
|
||||||
|
%p
|
||||||
|
%b Title
|
||||||
|
%br/
|
||||||
|
= f.text_field :title
|
||||||
|
%p
|
||||||
|
%b Inhalt
|
||||||
|
%br/
|
||||||
|
= f.text_area :body, :size => "60x30"
|
||||||
|
%p
|
||||||
|
= f.submit "Speichern"
|
||||||
|
|
|
||||||
|
= link_to "Abbrechen", :back
|
12
app/views/pages/all.html.haml
Normal file
12
app/views/pages/all.html.haml
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
- title "Alle Wikiseiten"
|
||||||
|
|
||||||
|
%p= link_to "Neue Seite anlegen", new_page_path
|
||||||
|
|
||||||
|
%table
|
||||||
|
%tr
|
||||||
|
%th Title
|
||||||
|
%th zuletzt aktualisiert
|
||||||
|
- for page in @pages
|
||||||
|
%tr
|
||||||
|
%td= link_to page.title, page
|
||||||
|
%td= format_date page.updated_at
|
3
app/views/pages/edit.html.haml
Normal file
3
app/views/pages/edit.html.haml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
- title "#{@page.title} bearbeiten"
|
||||||
|
|
||||||
|
= render :partial => 'form'
|
3
app/views/pages/new.html.haml
Normal file
3
app/views/pages/new.html.haml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
- title "Neue Wikiseite anlegen"
|
||||||
|
|
||||||
|
= render :partial => 'form'
|
7
app/views/pages/show.html.haml
Normal file
7
app/views/pages/show.html.haml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
- title @page.title
|
||||||
|
|
||||||
|
= wikified_body @page.body
|
||||||
|
|
||||||
|
%hr/
|
||||||
|
%p
|
||||||
|
= link_to "Seite bearbeiten", edit_page_path(@page)
|
|
@ -68,6 +68,7 @@ Rails::Initializer.run do |config|
|
||||||
config.gem "fastercsv"
|
config.gem "fastercsv"
|
||||||
config.gem "prawn"
|
config.gem "prawn"
|
||||||
config.gem "haml", :version => '>=2.0.6'
|
config.gem "haml", :version => '>=2.0.6'
|
||||||
|
config.gem 'RedCloth'
|
||||||
|
|
||||||
# The internationalization framework can be changed to have another default locale (standard is :en) or more load paths.
|
# The internationalization framework can be changed to have another default locale (standard is :en) or more load paths.
|
||||||
# All files from config/locales/*.rb,yml are added automatically.
|
# All files from config/locales/*.rb,yml are added automatically.
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
ActionController::Routing::Routes.draw do |map|
|
ActionController::Routing::Routes.draw do |map|
|
||||||
|
map.resources :pages, :collection => { :all => :get }
|
||||||
|
map.wiki_page "/wiki/:permalink", :controller => 'pages', :action => 'show'
|
||||||
|
|
||||||
map.logout '/logout', :controller => 'login', :action => 'logout'
|
map.logout '/logout', :controller => 'login', :action => 'logout'
|
||||||
map.my_profile '/home/profile', :controller => 'home', :action => 'profile'
|
map.my_profile '/home/profile', :controller => 'home', :action => 'profile'
|
||||||
|
|
15
db/migrate/20090325175756_create_pages.rb
Normal file
15
db/migrate/20090325175756_create_pages.rb
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
class CreatePages < ActiveRecord::Migration
|
||||||
|
def self.up
|
||||||
|
create_table :pages do |t|
|
||||||
|
t.string :title
|
||||||
|
t.text :body
|
||||||
|
t.string :permalink
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.down
|
||||||
|
drop_table :pages
|
||||||
|
end
|
||||||
|
end
|
10
db/schema.rb
10
db/schema.rb
|
@ -9,7 +9,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended to check this file into your version control system.
|
# It's strongly recommended to check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(:version => 20090317175355) do
|
ActiveRecord::Schema.define(:version => 20090325175756) do
|
||||||
|
|
||||||
create_table "article_categories", :force => true do |t|
|
create_table "article_categories", :force => true do |t|
|
||||||
t.string "name", :default => "", :null => false
|
t.string "name", :default => "", :null => false
|
||||||
|
@ -211,6 +211,14 @@ ActiveRecord::Schema.define(:version => 20090317175355) do
|
||||||
t.decimal "foodcoop_result", :precision => 8, :scale => 2
|
t.decimal "foodcoop_result", :precision => 8, :scale => 2
|
||||||
end
|
end
|
||||||
|
|
||||||
|
create_table "pages", :force => true do |t|
|
||||||
|
t.string "title"
|
||||||
|
t.text "body"
|
||||||
|
t.string "permalink"
|
||||||
|
t.datetime "created_at"
|
||||||
|
t.datetime "updated_at"
|
||||||
|
end
|
||||||
|
|
||||||
create_table "stock_changes", :force => true do |t|
|
create_table "stock_changes", :force => true do |t|
|
||||||
t.integer "delivery_id"
|
t.integer "delivery_id"
|
||||||
t.integer "order_id"
|
t.integer "order_id"
|
||||||
|
|
11
test/fixtures/pages.yml
vendored
Normal file
11
test/fixtures/pages.yml
vendored
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
||||||
|
|
||||||
|
one:
|
||||||
|
title: MyString
|
||||||
|
body: MyText
|
||||||
|
permalink: MyString
|
||||||
|
|
||||||
|
two:
|
||||||
|
title: MyString
|
||||||
|
body: MyText
|
||||||
|
permalink: MyString
|
45
test/functional/pages_controller_test.rb
Normal file
45
test/functional/pages_controller_test.rb
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class PagesControllerTest < ActionController::TestCase
|
||||||
|
test "should get index" do
|
||||||
|
get :index
|
||||||
|
assert_response :success
|
||||||
|
assert_not_nil assigns(:pages)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get new" do
|
||||||
|
get :new
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should create page" do
|
||||||
|
assert_difference('Page.count') do
|
||||||
|
post :create, :page => { }
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_redirected_to page_path(assigns(:page))
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should show page" do
|
||||||
|
get :show, :id => pages(:one).id
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get edit" do
|
||||||
|
get :edit, :id => pages(:one).id
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should update page" do
|
||||||
|
put :update, :id => pages(:one).id, :page => { }
|
||||||
|
assert_redirected_to page_path(assigns(:page))
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should destroy page" do
|
||||||
|
assert_difference('Page.count', -1) do
|
||||||
|
delete :destroy, :id => pages(:one).id
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_redirected_to pages_path
|
||||||
|
end
|
||||||
|
end
|
8
test/unit/page_test.rb
Normal file
8
test/unit/page_test.rb
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class PageTest < ActiveSupport::TestCase
|
||||||
|
# Replace this with your real tests.
|
||||||
|
test "the truth" do
|
||||||
|
assert true
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue