pages added

This commit is contained in:
Andreas Stephanides
2013-03-10 20:06:34 +01:00
parent 5bb60ec8d5
commit 24694612e8
17 changed files with 357 additions and 0 deletions

View File

@@ -0,0 +1,65 @@
class PagesController < ApplicationController
before_filter :find_page, :except => [:new, :show, :create]
before_filter :find_body, :only => [:edit]
def new
@page = Page.new
@page.name=params[:name]
end
def edit
end
def show
if params[:id].to_i >0
@page = Page.find(params[:id] || Page.welcome)
else
id=Page.find_id(params[:id])
if id.nil?
redirect_to url_for(:path_only=>true,:controller=>"pages",:action=>"new", :name=>params[:id])
else
@page =Page.find(Page.find_id(params[:id]))
end
end
end
def create
@page = Page.new(params[:page])
if @page.save
flash[:notice] = "Successfully created page."
redirect_to @page
else
render :action => 'new'
end
end
def update
if @page.update_attributes(params[:page])
flash[:notice] = "Successfully updated page."
redirect_to @page
else
render :action => 'edit'
end
end
def destroy
@page.destroy
flash[:notice] = "Successfully destroyed page."
end
def preview
render :text => @page.preview(params[:data])
end
private
def find_page
@page = Page.find(params[:id])
end
def find_body
@page.body = params[:page][:body] rescue @page.raw_content
end
end

View File

@@ -0,0 +1,11 @@
module PagesHelper
def breadcrumbs(page)
s = []
page.ancestors.each do |p|
s << content_tag(link_to p.name, page_path(p))
end
raw(s.join(' '))
end
end

75
app/models/page.rb Normal file
View File

@@ -0,0 +1,75 @@
class Page < ActiveRecord::Base
acts_as_nested_set
# Temporarily hard coded
FORMAT = :textile
WIKI = Rails.root.join("db", "wiki.git")
before_create :create_page
before_update :update_page
before_destroy :delete_page
attr_accessible :body, :name, :change_comment
attr_accessor :body, :change_comment
def content
page.formatted_data
end
def raw_content
page.raw_data
end
def self.welcome
Page.first(:conditions => {:name => 'Welcome'})
end
def author
page.version.author.name.gsub(/<>/, '')
end
def date
page.version.authored_date
end
def preview(data)
wiki.preview_page('Preview', data, FORMAT).formatted_data
end
def self.find_id(nme)
p=Page.first(:conditions=> {:name=>nme})
if p.nil?
pg=wiki.page(nme)
if !pg.nil?
p=Page.new(:name=>nme,:body=>pg.raw_data)
end
end
p
end
private
def self.wiki
@@golum ||= Gollum::Wiki.new(WIKI, :base_path =>"/pages",)
end
def wiki
@@golum ||= Gollum::Wiki.new(WIKI, :base_path =>"/pages")
end
def page
wiki.page(self.name)
end
def create_page
wiki.write_page(name, FORMAT, body || '', {:message => self.change_comment, :name => 'tester', :author => 'tester'})
end
def update_page
wiki.update_page(page, name, FORMAT, body || self.raw_content, {:message => self.change_comment, :name => 'tester', :author => 'tester'})
end
def delete_page
wiki.delete_page(page, COMMIT)
end
end

View File

@@ -0,0 +1,23 @@
= form_for(@page) do |f|
%p
= f.label :name
= f.text_field :name
%p
- unless @page.new_record?
= link_to 'Edit mode', '#', :id => 'write'
= link_to 'Preview mode', preview_page_path(@page), :id => 'preview'
#write_area
= f.textile_editor :body
#preview_area.hide
%p
= f.label 'Describe this change (optional)'
= f.text_field :change_comment
.actions
= f.submit
= cancel_link
= raw(textile_editor_initialize(:framework => :jquery))

View File

@@ -0,0 +1,12 @@
<%= tinymce_assets %>
<%= semantic_form_for @page do |f| %>
<%= f.inputs do %>
<%= f.input :name %>
<%= f.input :body, :as=>:text,:input_html=>{:style=>"width:100%"} %>
<%= f.input :change_comment %>
<% end %>
<%= tinymce %>
<%= f.actions do %>
<%= f.action :submit, :as =>:input %>
<% end %>
<% end %>

View File

@@ -0,0 +1,3 @@
%h3 Table of contents
%ul#pages_list= render Page.root

View File

View File

@@ -0,0 +1,7 @@
%li{:id => dom_id(page), :class => "level_#{page.level}"}
= link_to page.name, page_path(page)
= link_to '(Add)', new_page_path, :rel => dom_id(page)
- unless page.children.empty?
%ul= render page.children

View File

@@ -0,0 +1,5 @@
<% unless @page.errors.any? -%>
$("#flash_notice").html("<%= escape_javascript(flash[:notice])%>");
$("#flash_notice").show(300);
$("#<%= dom_id(@page)%>").fadeOut('fast');
<% end -%>

View File

@@ -0,0 +1,2 @@
%h1="Editing page \"#{@page.name}\""
= render 'form'

View File

@@ -0,0 +1,2 @@
<h1>Edit Form</h1>
<%= render 'form' %>

2
app/views/pages/new.haml Normal file
View File

@@ -0,0 +1,2 @@
%h1 New page
= render 'form'

15
app/views/pages/show.haml Normal file
View File

@@ -0,0 +1,15 @@
%small
= breadcrumbs(@page)
%h4
= "Page name: #{@page.name}"
= link_to '(Edit)', edit_page_path(@page)
= link_to '(Destroy)', @page, :remote => true, :confirm => 'Are you sure?', :method => :delete
%small= "Last edited by #{@page.author} #{time_ago_in_words(@page.date)} ago."
%hr
= raw(@page.content)
%hr

View File

@@ -0,0 +1,8 @@
<table class="table">
<% rubriken.each do |r| %>
<% r.neuigkeiten.each do |n| %>
<tr>
<td><%= r.name %></td><td><%= n.title %></td></tr>
<% end
end %>
</table>

View File

@@ -0,0 +1 @@
<%= render :partial=>"admin_liste", :locals=>{:rubriken=>@rubriken} %>

103
config/routes.rb.save Normal file
View File

@@ -0,0 +1,103 @@
Fetsite::Application.routes.draw do
resources :beispiele
devise_for :users
resources :home, :only=>[:index]
#get 'home',:controller=>home,:action=>:index,:as=>"home_index"
scope '(:locale)/admin' do
resources :users
get 'config',:controller=>:config,:action=>:index , :as => 'config'
get 'config/get_git_update',:controller=>:config,:action=>:get_git_update, :as=>'config_getgitupdate'
get 'config/get_git_update',:controller=>:config,:action=>:get_git_update
end
devise_for :users
resources :pages, :except => [:index] do
member do
post 'preview'
end
end
get 'pages', :to =>'pages#show'
scope '(:locale)' do
resources :studien, :only=>[:show,:new,:edit,:update,:destroy]
resources :modulgruppen,:only =>[:create,:index]
resources :studien,:except=>[:show,:new,:edit,:update,:destroy], :shallow=>true do
resources :modulgruppen, :path => "(:locale)/modulgruppen"
end
resources :semesters
resources :moduls
resources :lvas
resources :neuigkeiten, :except=>[:new,:show]
resources :rubriken do
resources :neuigkeiten, :only=>[:new, :show,:edit]
end
put 'rubriken/(:id)/addmoderator',:controller=>:rubriken,:action=>:addmoderator
get 'rubriken/:id/verwalten',:controller=>:rubriken,:action=>:verwalten, :as=>'verwalten_rubrik'
resources :home
end
# The priority is based upon order of creation:
# first created -> highest priority.
# Sample of regular route:
# match 'products/:id' => 'catalog#view'
# Keep in mind you can assign values other than :controller and :action
# Sample of named route:
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
# This route can be invoked with purchase_url(:id => product.id)
# Sample resource route (maps HTTP verbs to controller actions automatically):
# resources :products
# Sample resource route with options:
# resources :products do
# member do
# get 'short'
# post 'toggle'
# end
#
# collection do
# get 'sold'
# end
# end
# Sample resource route with sub-resources:
# resources :products do
# resources :comments, :sales
# resource :seller
# end
# Sample resource route with more complex sub-resources
# resources :products do
# resources :comments
# resources :sales do
# get 'recent', :on => :collection
# end
# end
# Sample resource route within a namespace:
# namespace :admin do
# # Directs /admin/products/* to Admin::ProductsController
# # (app/controllers/admin/products_controller.rb)
# resources :products
# end
# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
root :to => 'home#index'
# See how all your routes lay out with "rake routes"
# This is a legacy wild controller route that's not recommended for RESTful applications.
# Note: This route will make all actions in every controller accessible via GET requests.
# match ':controller(/:action(/:id))(.:format)'
end

View File

@@ -0,0 +1,23 @@
class CreatePages < ActiveRecord::Migration
def self.up
create_table :pages do |t|
t.string :name
t.string :url
t.integer :parent_id
t.integer :lft
t.integer :rgt
t.timestamps
end
add_index :pages, :parent_id
# Create parent Welcome page
Page.create(:name => 'Welcome', :body => 'Getting started guide')
end
def self.down
drop_table :pages
end
end