Skip to content
This repository has been archived by the owner on Feb 7, 2020. It is now read-only.

Commit

Permalink
You can configure to use markdown as default.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOnly92 committed Jul 15, 2011
1 parent 0842c2f commit cf82f81
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
15 changes: 14 additions & 1 deletion controllers/admin.go
Expand Up @@ -66,6 +66,9 @@ func (c *Admin) PreferencesGet(ctx *web.Context) string {
if comment != "" {
vars["EnableComment"] = comment
}
if blogConfig.Get("markdown") == "1" {
vars["markdown"] = "1"
}
output := mustache.RenderFile("templates/preferences.mustache", vars)
return render(output, "Blog Preferernces")
}
Expand All @@ -81,6 +84,11 @@ func (c *Admin) PreferencesPost(ctx *web.Context) {
blogConfig.Update("dateFormat", ctx.Params["dateFormat"])
blogConfig.Update("postsPerPage", ctx.Params["postsPerPage"])
blogConfig.Update("enableComment", ctx.Params["enableComment"])
markdown := "0"
if ctx.Params["markdown"] == "on" {
markdown = "1"
}
blogConfig.Update("markdown", markdown)
ctx.Redirect(302, "/admin/preferences")
}

Expand Down Expand Up @@ -131,7 +139,12 @@ func (c *Admin) ListPost(ctx *web.Context) string {
p := PostModelInit()
results := p.PostListing(page)

output := mustache.RenderFile("templates/list-post.mustache", map[string][]map[string]string {"posts":results})
vars := map[string]interface{} {"posts":results}
if blogConfig.Get("markdown") == "1" {
vars["markdown"] = "1"
}

output := mustache.RenderFile("templates/list-post.mustache", vars)
return render(output, "List Posts")
}

Expand Down
2 changes: 2 additions & 0 deletions models/preferences.go
Expand Up @@ -45,6 +45,8 @@ func (preference *PreferenceModel) Get(name string) string {
return "10"
case "enableComment":
return "on"
case "markdown":
return "0"
}
} else if err != nil {
panic(err)
Expand Down
2 changes: 1 addition & 1 deletion templates/list-post.mustache
@@ -1,5 +1,5 @@
<h1>List of Your Posts</h1>
<p>[ <a href="/admin/post/new">New Post</a> <a href="/admin/preferences">Preferences</a> ]</p>
<p>[ <a href="/admin/post/new{{#markdown}}?markdown=1{{/markdown}}">New Post</a> <a href="/admin/preferences">Preferences</a> ]</p>
<form method="post">
<table cellpadding="0" cellspacing="0" border="0" style="width: 100%; font-size: 13px;">
{{#posts}}
Expand Down
4 changes: 3 additions & 1 deletion templates/preferences.mustache
Expand Up @@ -5,7 +5,9 @@
<label for="postsPerPage"><abbr title="Posts Per Page">PPP</abbr></label>
<input type="text" id="postsPerPage" name="postsPerPage" style="width: 300px" value="{{PostsPerPage}}" /><br />
<label for="enableComment">Comment?</label>
<input type="checkbox" id="enableComment" name="enableComment"{{#EnableComment}} checked="checked"{{/EnableComment}} />
<input type="checkbox" id="enableComment" name="enableComment"{{#EnableComment}} checked="checked"{{/EnableComment}} /><br />
<label for="markdown">Markdown?</label>
<input type="checkbox" id="markdown" name="markdown"{{#markdown}} checked="checked"{{/markdown}} />
<br />
<input type="submit" value="Save!" />
</form>

0 comments on commit cf82f81

Please sign in to comment.