Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
4c1b8558
Commit
4c1b8558
authored
Feb 19, 2012
by
Valery Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Wiki: base implemetation logic
parent
eacea15a
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
35 additions
and
68 deletions
+35
-68
app/controllers/wikis_controller.rb
app/controllers/wikis_controller.rb
+13
-32
app/models/wiki.rb
app/models/wiki.rb
+15
-3
app/views/layouts/_project_menu.html.haml
app/views/layouts/_project_menu.html.haml
+1
-1
app/views/wikis/_form.html.haml
app/views/wikis/_form.html.haml
+2
-1
app/views/wikis/edit.html.haml
app/views/wikis/edit.html.haml
+2
-4
app/views/wikis/index.html.haml
app/views/wikis/index.html.haml
+0
-21
app/views/wikis/new.html.haml
app/views/wikis/new.html.haml
+0
-5
config/routes.rb
config/routes.rb
+2
-1
No files found.
app/controllers/wikis_controller.rb
View file @
4c1b8558
class
WikisController
<
ApplicationController
before_filter
:project
layout
"project"
respond_to
:html
def
show
@wiki
=
@project
.
wikis
.
find_by_slug
(
params
[
:id
])
respond_with
(
@wiki
)
end
def
new
@wiki
=
Wiki
.
new
@wiki
=
@project
.
wikis
.
where
(
:slug
=>
params
[
:id
]).
order
(
"created_at"
).
last
respond_to
do
|
format
|
format
.
html
# new.html.erb
format
.
json
{
render
json:
@wiki
}
if
@wiki
format
.
html
else
@wiki
=
@project
.
wikis
.
new
(
:slug
=>
params
[
:id
])
format
.
html
{
render
"edit"
}
end
end
end
def
edit
@wiki
=
Wiki
.
find
(
params
[
:id
])
@wiki
=
@project
.
wikis
.
where
(
:slug
=>
params
[
:id
]).
order
(
"created_at"
).
last
@wiki
=
Wiki
.
regenerate_from
@wiki
end
def
create
@wiki
=
Wiki
.
new
(
params
[
:wiki
])
@wiki
=
@project
.
wikis
.
new
(
params
[
:wiki
])
respond_to
do
|
format
|
if
@wiki
.
save
format
.
html
{
redirect_to
@wiki
,
notice:
'Wiki was successfully created.'
}
format
.
json
{
render
json:
@wiki
,
status: :created
,
location:
@wiki
}
else
format
.
html
{
render
action:
"new"
}
format
.
json
{
render
json:
@wiki
.
errors
,
status: :unprocessable_entity
}
end
end
end
def
update
@wiki
=
Wiki
.
find
(
params
[
:id
])
respond_to
do
|
format
|
if
@wiki
.
update_attributes
(
params
[
:wiki
])
format
.
html
{
redirect_to
@wiki
,
notice:
'Wiki was successfully updated.'
}
format
.
json
{
head
:no_content
}
format
.
html
{
redirect_to
[
@project
,
@wiki
],
notice:
'Wiki was successfully updated.'
}
else
format
.
html
{
render
action:
"edit"
}
format
.
json
{
render
json:
@wiki
.
errors
,
status: :unprocessable_entity
}
end
end
end
def
destroy
@wiki
=
Wiki
.
find
(
params
[
:id
])
@wiki
=
@project
.
wikis
.
find
(
params
[
:id
])
@wiki
.
destroy
respond_to
do
|
format
|
format
.
html
{
redirect_to
wikis_url
}
format
.
json
{
head
:no_content
}
end
end
end
app/models/wiki.rb
View file @
4c1b8558
...
...
@@ -2,10 +2,9 @@ class Wiki < ActiveRecord::Base
belongs_to
:project
validates
:content
,
:title
,
:presence
=>
true
validates
:title
,
:length
=>
1
..
250
,
:uniqueness
=>
{
:scope
=>
:project_id
,
:case_sensitive
=>
false
}
validates
:title
,
:length
=>
1
..
250
before_
sav
e
:set_slug
before_
updat
e
:set_slug
def
to_param
...
...
@@ -17,4 +16,17 @@ class Wiki < ActiveRecord::Base
def
set_slug
self
.
slug
=
self
.
title
.
parameterize
end
class
<<
self
def
regenerate_from
wiki
regenerated_field
=
[
:slug
,
:content
,
:title
]
new_wiki
=
Wiki
.
new
regenerated_field
.
each
do
|
field
|
new_wiki
.
send
(
"
#{
field
}
="
,
wiki
.
send
(
field
))
end
new_wiki
end
end
end
app/views/layouts/_project_menu.html.haml
View file @
4c1b8558
...
...
@@ -21,5 +21,5 @@
Wall
-
if
@project
.
wiki_enabled
-#= link_to project_wikis_path(@project
), :class => current_page?(:controller => "projects", :action => "wiki", :id => @project) ? "current" : nil do
=
link_to
project_wiki_path
(
@project
,
:index
),
:class
=>
current_page?
(
:controller
=>
"projects"
,
:action
=>
"wiki"
,
:id
=>
@project
)
?
"current"
:
nil
do
Wiki
app/views/wikis/_form.html.haml
View file @
4c1b8558
=
form_for
@wiki
do
|
f
|
=
form_for
[
@project
,
@wiki
]
do
|
f
|
-
if
@wiki
.
errors
.
any?
#error_explanation
%h2
=
"
#{
pluralize
(
@wiki
.
errors
.
count
,
"error"
)
}
prohibited this wiki from being saved:"
...
...
@@ -9,6 +9,7 @@
.field
=
f
.
label
:title
=
f
.
text_field
:title
=
f
.
hidden_field
:slug
.field
=
f
.
label
:content
=
f
.
text_area
:content
...
...
app/views/wikis/edit.html.haml
View file @
4c1b8558
%h1
Editing
wiki
%h1
Editing
page
=
render
'form'
=
link_to
'Show'
,
@wiki
\|
=
link_to
'Back'
,
wikis_path
=
link_to
'Show'
,
[
@project
,
@wiki
]
app/views/wikis/index.html.haml
deleted
100644 → 0
View file @
eacea15a
%h1
Listing wikis
%table
%tr
%th
Title
%th
Content
%th
%th
%th
-
@wikis
.
each
do
|
wiki
|
%tr
%td
=
wiki
.
title
%td
=
wiki
.
content
%td
=
link_to
'Show'
,
wiki
%td
=
link_to
'Edit'
,
edit_wiki_path
(
wiki
)
%td
=
link_to
'Destroy'
,
wiki
,
:confirm
=>
'Are you sure?'
,
:method
=>
:delete
%br
=
link_to
'New Wiki'
,
new_wiki_path
app/views/wikis/new.html.haml
deleted
100644 → 0
View file @
eacea15a
%h1
New wiki
=
render
'form'
=
link_to
'Back'
,
wikis_path
config/routes.rb
View file @
4c1b8558
...
...
@@ -56,7 +56,8 @@ Gitlab::Application.routes.draw do
get
"files"
end
resources
:wikis
,
:only
=>
[
:show
,
:edit
,
:destroy
]
resources
:wikis
,
:only
=>
[
:show
,
:edit
,
:destroy
,
:create
]
resource
:repository
do
member
do
get
"branches"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment