From bdc42488e9b0d297e0773040e077f414b6605c3d Mon Sep 17 00:00:00 2001 From: vsizov Date: Mon, 20 Feb 2012 20:16:55 +0300 Subject: [PATCH] wiki is done --- app/assets/stylesheets/main.scss | 2 ++ app/assets/stylesheets/projects.css.scss | 4 ++++ app/assets/stylesheets/wiki.scss | 5 +++++ app/controllers/wikis_controller.rb | 5 ++--- app/helpers/wikis_helper.rb | 5 +++++ app/views/wikis/show.html.haml | 12 +++++++++--- config/routes.rb | 2 +- db/schema.rb | 14 ++++++++++++++ 8 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 app/assets/stylesheets/wiki.scss create mode 100644 app/helpers/wikis_helper.rb diff --git a/app/assets/stylesheets/main.scss b/app/assets/stylesheets/main.scss index df61cc81..841b4307 100644 --- a/app/assets/stylesheets/main.scss +++ b/app/assets/stylesheets/main.scss @@ -65,4 +65,6 @@ $hover: #FDF5D9; @import "highlight.css.scss"; @import "highlight.black.css.scss"; +@import "wiki.scss"; + diff --git a/app/assets/stylesheets/projects.css.scss b/app/assets/stylesheets/projects.css.scss index b54e12c8..487925db 100644 --- a/app/assets/stylesheets/projects.css.scss +++ b/app/assets/stylesheets/projects.css.scss @@ -221,3 +221,7 @@ input.git_clone_url { width:270px; background:#fff !important; } + +.span12 hr{ + margin-top: 2px; +} diff --git a/app/assets/stylesheets/wiki.scss b/app/assets/stylesheets/wiki.scss new file mode 100644 index 00000000..acc37b96 --- /dev/null +++ b/app/assets/stylesheets/wiki.scss @@ -0,0 +1,5 @@ +p.time { + color: #999; + font-size: 90%; + margin: 30px 3px 3px 2px; +} diff --git a/app/controllers/wikis_controller.rb b/app/controllers/wikis_controller.rb index 9a1638f2..544f9887 100644 --- a/app/controllers/wikis_controller.rb +++ b/app/controllers/wikis_controller.rb @@ -42,11 +42,10 @@ class WikisController < ApplicationController end def destroy - @wiki = @project.wikis.find(params[:id]) - @wiki.destroy + @wikis = @project.wikis.where(:slug => params[:id]).delete_all respond_to do |format| - format.html { redirect_to wikis_url } + format.html { redirect_to project_wiki_path(@project, :index), notice: "Page was successfully deleted" } end end end diff --git a/app/helpers/wikis_helper.rb b/app/helpers/wikis_helper.rb new file mode 100644 index 00000000..0c24f57a --- /dev/null +++ b/app/helpers/wikis_helper.rb @@ -0,0 +1,5 @@ +module WikisHelper + def markdown_to_html(text) + RDiscount.new(text).to_html.html_safe + end +end diff --git a/app/views/wikis/show.html.haml b/app/views/wikis/show.html.haml index 5a4b9045..63a166fe 100644 --- a/app/views/wikis/show.html.haml +++ b/app/views/wikis/show.html.haml @@ -1,9 +1,15 @@ %h3 = @wiki.title + = link_to edit_project_wiki_path(@project, @wiki), :class => "right btn small" do + Edit - if can? current_user, :write_wiki, @project = link_to history_project_wiki_path(@project, @wiki), :class => "right btn small" do History - = link_to edit_project_wiki_path(@project, @wiki), :class => "right btn small" do - Edit +%hr -= markdown @wiki.content += markdown_to_html @wiki.content + +%p.time Last edited by #{@wiki.user.name}, in #{time_ago_in_words @wiki.created_at} +- if can? current_user, :write_wiki, @project + = link_to project_wiki_path(@project, @wiki), :confirm => "Are you sure you want to delete this page?", :method => :delete do + Delete this page diff --git a/config/routes.rb b/config/routes.rb index eae5b7ea..653ec089 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -58,7 +58,7 @@ Gitlab::Application.routes.draw do resources :wikis, :only => [:show, :edit, :destroy, :create] do member do - get "history" + get "history" end end diff --git a/db/schema.rb b/db/schema.rb index c32df7ea..cf4b226c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -159,6 +159,20 @@ ActiveRecord::Schema.define(:version => 20120219193300) do t.datetime "updated_at" end + create_table "wiki_pages", :force => true do |t| + t.string "slug" + t.string "title" + t.text "content" + t.integer "author_id" + t.integer "project_id" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "wiki_pages", ["author_id"], :name => "index_wiki_pages_on_author_id" + add_index "wiki_pages", ["project_id"], :name => "index_wiki_pages_on_project_id" + add_index "wiki_pages", ["slug"], :name => "index_wiki_pages_on_slug", :unique => true + create_table "wikis", :force => true do |t| t.string "title" t.text "content"