Skip to content

Commit

Permalink
Wiki: UI for page new
Browse files Browse the repository at this point in the history
  • Loading branch information
unknwon committed Nov 26, 2015
1 parent 2f28a03 commit 2b10fdc
Show file tree
Hide file tree
Showing 20 changed files with 307 additions and 49 deletions.
20 changes: 15 additions & 5 deletions cmd/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ func runWeb(ctx *cli.Context) {
}, func(ctx *middleware.Context) {
ctx.Data["PageIsSettings"] = true
})
}, reqSignIn, middleware.RepoAssignment(true), reqRepoAdmin, middleware.RepoRef())
}, reqSignIn, middleware.RepoAssignment(), reqRepoAdmin, middleware.RepoRef())

m.Group("/:username/:reponame", func() {
m.Get("/action/:action", repo.Action)
Expand Down Expand Up @@ -516,7 +516,7 @@ func runWeb(ctx *cli.Context) {

m.Combo("/compare/*").Get(repo.CompareAndPullRequest).
Post(bindIgnErr(auth.CreateIssueForm{}), repo.CompareAndPullRequestPost)
}, reqSignIn, middleware.RepoAssignment(true))
}, reqSignIn, middleware.RepoAssignment())

m.Group("/:username/:reponame", func() {
m.Group("", func() {
Expand All @@ -530,7 +530,17 @@ func runWeb(ctx *cli.Context) {
})
m.Get("/^:type(issues|pulls)$/:index", repo.ViewIssue)

m.Get("/branches", repo.Branches)
// m.Get("/branches", repo.Branches)

m.Group("/wiki", func() {
m.Get("/?:page", repo.Wiki)

m.Group("", func() {
m.Get("/_new", repo.NewWiki)
m.Get("/:page/_edit", repo.EditWiki)
}, reqSignIn)
}, middleware.RepoRef())

m.Get("/archive/*", repo.Download)

m.Group("/pulls/:index", func() {
Expand All @@ -550,13 +560,13 @@ func runWeb(ctx *cli.Context) {
}, middleware.RepoRef())

m.Get("/compare/:before([a-z0-9]{40})...:after([a-z0-9]{40})", repo.CompareDiff)
}, ignSignIn, middleware.RepoAssignment(true))
}, ignSignIn, middleware.RepoAssignment())

m.Group("/:username", func() {
m.Group("/:reponame", func() {
m.Get("", repo.Home)
m.Get("\\.git$", repo.Home)
}, ignSignIn, middleware.RepoAssignment(true, true), middleware.RepoRef())
}, ignSignIn, middleware.RepoAssignment(true), middleware.RepoRef())

m.Group("/:reponame", func() {
m.Any("/*", ignSignInAndCsrf, repo.HTTP)
Expand Down
8 changes: 8 additions & 0 deletions conf/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,14 @@ milestones.deletion = Milestone Deletion
milestones.deletion_desc = Delete this milestone will remove its information in all related issues. Do you want to continue?
milestones.deletion_success = Milestone has been deleted successfully!

wiki = Wiki
wiki.welcome = Welcome to Wiki!
wiki.welcome_desc = Wiki is the place where you would like to document your project together and make it better.
wiki.create_first_page = Create the first page
wiki.new_page = Create New Page
wiki.default_commit_message = Write a note about this update (optional).
wiki.save_page = Save Page

settings = Settings
settings.options = Options
settings.collaboration = Collaboration
Expand Down
13 changes: 13 additions & 0 deletions models/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,14 @@ func (repo *Repository) RepoPath() (string, error) {
return repo.repoPath(x)
}

func (repo *Repository) WikiPath() (string, error) {
if err := repo.GetOwner(); err != nil {
return "", err
}

return WikiPath(repo.Owner.Name, repo.Name), nil
}

func (repo *Repository) RepoLink() (string, error) {
if err := repo.GetOwner(); err != nil {
return "", err
Expand Down Expand Up @@ -877,6 +885,11 @@ func RepoPath(userName, repoName string) string {
return filepath.Join(UserPath(userName), strings.ToLower(repoName)+".git")
}

// WikiPath returns wiki data path by given user and repository name.
func WikiPath(userName, repoName string) string {
return filepath.Join(UserPath(userName), strings.ToLower(repoName)+".wiki.git")
}

// TransferOwnership transfers all corresponding setting from old user to new one.
func TransferOwnership(u *User, newOwnerName string, repo *Repository) error {
newOwner, err := GetUserByName(newOwnerName)
Expand Down
56 changes: 28 additions & 28 deletions modules/bindata/bindata.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion modules/middleware/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func RetrieveBaseRepo(ctx *Context, repo *models.Repository) {
}
}

func RepoAssignment(redirect bool, args ...bool) macaron.Handler {
func RepoAssignment(args ...bool) macaron.Handler {
return func(ctx *Context) {
var (
displayBare bool // To display bare page if it is a bare repo.
Expand Down
13 changes: 11 additions & 2 deletions public/config.codekit
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"files": {
"\/css\/dropzone-4.2.0.css": {
"fileType": 16,
"ignore": 0,
"ignoreWasSetByUser": 0,
"ignore": 1,
"ignoreWasSetByUser": 1,
"inputAbbreviatedPath": "\/css\/dropzone-4.2.0.css",
"outputAbbreviatedPath": "No Output Path",
"outputPathIsOutsideProject": 0,
Expand Down Expand Up @@ -92,6 +92,15 @@
"outputPathIsOutsideProject": 0,
"outputPathIsSetByUser": 0
},
"\/css\/simplemde-1.8.1.min.css": {
"fileType": 16,
"ignore": 1,
"ignoreWasSetByUser": 1,
"inputAbbreviatedPath": "\/css\/simplemde-1.8.1.min.css",
"outputAbbreviatedPath": "No Output Path",
"outputPathIsOutsideProject": 0,
"outputPathIsSetByUser": 0
},
"\/css\/themes\/default\/assets\/images\/flags.png": {
"fileType": 32768,
"ignore": 0,
Expand Down
18 changes: 18 additions & 0 deletions public/css/gogs.css
Original file line number Diff line number Diff line change
Expand Up @@ -1758,6 +1758,11 @@ footer .container .links > *:first-child {
line-height: 10px;
white-space: nowrap;
}
.repository .navbar .ui.label {
margin-top: -2px;
margin-left: 7px;
padding: 3px 5px;
}
.repository .owner.dropdown {
min-width: 40% !important;
}
Expand Down Expand Up @@ -2513,6 +2518,19 @@ footer .container .links > *:first-child {
.repository.forks .list .item .link {
padding-top: 5px;
}
.repository.wiki.start .ui.segment {
padding-top: 70px;
padding-bottom: 100px;
}
.repository.wiki.start .ui.segment .mega-octicon {
font-size: 48px;
}
.repository.wiki.new .CodeMirror .CodeMirror-code .cm-comment {
background: inherit;
}
.repository.wiki.new .editor-preview {
background-color: white;
}
.repository.settings.collaboration .collaborator.list {
padding: 0;
}
Expand Down
7 changes: 7 additions & 0 deletions public/css/simplemde-1.8.1.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions public/js/gogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,53 @@ function initRepository() {
}
}

function initWiki() {
if ($('.repository.wiki').length == 0) {
return;
}


if ($('.repository.wiki.new').length > 0) {
var $edit_area = $('#edit-area');
var simplemde = new SimpleMDE({
autoDownloadFontAwesome: false,
element: $edit_area[0],
previewRender: function (plainText, preview) { // Async method
setTimeout(function () {
if ($('.editor-preview-active').length == 0) {
return;
}

$.post($edit_area.data('url'), {
"_csrf": csrf,
"mode": "gfm",
"context": $edit_area.data('context'),
"text": plainText
},
function (data) {
preview.innerHTML = '<div class="markdown">' + data + '</div>';
emojify.run($('.editor-preview')[0]);
}
);
}, 0);

return "Loading...";
},
renderingConfig: {
singleLineBreaks: false
},
spellChecker: false,
tabSize: 4,
toolbar: ["bold", "italic", "strikethrough", "|",
"heading", "heading-1", "heading-2", "heading-3", "|",
"code", "quote", "|",
"unordered-list", "ordered-list", "|",
"link", "image", "horizontal-rule", "|",
"preview", "fullscreen"]
})
}
}

function initOrganization() {
if ($('.organization').length == 0) {
return;
Expand Down Expand Up @@ -835,6 +882,7 @@ $(document).ready(function () {
initCommentForm();
initInstall();
initRepository();
initWiki();
initOrganization();
initUser();
initWebhook();
Expand Down
14 changes: 14 additions & 0 deletions public/js/libs/simplemde-1.8.1.min.js

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions public/less/_repository.less
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@
}
}

.navbar {
.ui.label {
margin-top: -2px;
margin-left: 7px;
padding: 3px 5px;
}
}

.owner.dropdown {
min-width: 40% !important;
}
Expand Down Expand Up @@ -939,6 +947,31 @@
}
}

&.wiki {
&.start {
.ui.segment {
padding-top: 70px;
padding-bottom: 100px;

.mega-octicon {
font-size: 48px;
}
}
}

&.new {
.CodeMirror {
.CodeMirror-code .cm-comment {
background: inherit;
}
}

.editor-preview {
background-color: white;
}
}
}

&.settings {
&.collaboration {
.collaborator.list {
Expand Down
6 changes: 1 addition & 5 deletions routers/api/v1/miscellaneous.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@
package v1

import (
"strings"

"github.com/gogits/gogs/modules/auth/apiv1"
"github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting"
)

// Render an arbitrary Markdown document.
Expand All @@ -27,8 +24,7 @@ func Markdown(ctx *middleware.Context, form apiv1.MarkdownForm) {

switch form.Mode {
case "gfm":
ctx.Write(base.RenderMarkdown([]byte(form.Text),
setting.AppUrl+strings.TrimPrefix(form.Context, "/")))
ctx.Write(base.RenderMarkdown([]byte(form.Text), form.Context))
default:
ctx.Write(base.RenderRawMarkdown([]byte(form.Text), ""))
}
Expand Down
3 changes: 1 addition & 2 deletions routers/repo/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const (

func Home(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Repo.Repository.Name
ctx.Data["PageIsViewCode"] = true
ctx.Data["RequireHighlightJS"] = true

branchName := ctx.Repo.BranchName
Expand All @@ -52,8 +53,6 @@ func Home(ctx *middleware.Context) {
treeLink += "/" + treename
}

ctx.Data["IsRepoToolbarSource"] = true

isViewBranch := ctx.Repo.IsBranch
ctx.Data["IsViewBranch"] = isViewBranch

Expand Down
Loading

0 comments on commit 2b10fdc

Please sign in to comment.