wiki plugin

This commit is contained in:
jysperm
2014-12-02 17:54:42 +08:00
parent b758a8ea09
commit c31a93b8b5
7 changed files with 78 additions and 66 deletions

View File

@@ -11,6 +11,14 @@ rpvhostPlugin = module.exports = new Plugin
target: '_blank'
t_body: 'official_blog'
'plugins.wiki.pages':
category: 'rpvhost'
name: 'Terms.md'
t_category: ''
t_title: 'terms'
language: 'zh_CN'
content_markdown: fs.readFileSync("#{__dirname}/wiki/Terms.md").toString()
'billing.payment_methods':
type: 'taobao'
widget_generator: (req, callback) ->

View File

@@ -3,6 +3,7 @@
"greenshadow": "GreenShadow",
"taobao": "Taobao",
"official_blog": "Official Blog",
"terms": "Terms Of Service",
"view": {
"payment_tips": "Purchase the following product, and tell us your username and which server.",
"go_pay": "Pay on Taobao",

View File

@@ -3,6 +3,7 @@
"greenshadow": "GreenShadow",
"taobao": "淘宝",
"official_blog": "官方博客",
"terms": "服务条款",
"view": {
"payment_tips": "拍下对应宝贝后付款即可,购买时注意选择服务器节点选项,备注填写你的用户名。",
"go_pay": "淘宝购买",

View File

@@ -1,23 +1,27 @@
{fs, path} = app.libs
{pluggable, config} = app
{Plugin} = app.classes
exports = module.exports = class WikiPlugin extends pluggable.Plugin
@NAME: 'wiki'
@type: 'extension'
wikiPlugin = module.exports = new Plugin
name: 'wiki'
exports.registerHook 'view.layout.menu_bar',
href: '/wiki/'
t_body: 'plugins.wiki.'
register_hooks:
'view.layout.menu_bar':
href: '/wiki/'
t_body: ''
unless config.plugins.wiki?.disable_default_wiki
wiki_path = "#{__dirname}/../../WIKI"
initialize: ->
unless config.plugins.wiki?.disable_default_wiki
wiki_path = "#{__dirname}/../../WIKI"
for category_name in fs.readdirSync(wiki_path)
for file_name in fs.readdirSync("#{wiki_path}/#{category_name}")
exports.registerHook 'plugin.wiki.pages',
t_category: category_name
t_title: file_name
language: 'zh_CN'
content_markdown: fs.readFileSync("#{wiki_path}/#{category_name}/#{file_name}").toString()
for category_name in fs.readdirSync(wiki_path)
for file_name in fs.readdirSync("#{wiki_path}/#{category_name}")
@registerHook 'plugins.wiki.pages',
category: category_name
name: file_name
t_category: category_name
t_title: file_name
language: 'zh_CN'
content_markdown: fs.readFileSync("#{wiki_path}/#{category_name}/#{file_name}").toString()
app.express.use '/wiki', require './wiki'
app.express.use '/wiki', require './router'

44
plugin/wiki/router.coffee Normal file
View File

@@ -0,0 +1,44 @@
{markdown, path, jade, fs, _, express} = app.libs
{pluggable} = app
wikiPlugin = null
process.nextTick ->
wikiPlugin = require './index'
module.exports = exports = express.Router()
exports.get '/', (req, res) ->
pages_by_category = {}
for page in pluggable.selectHook 'plugins.wiki.pages'
pages_by_category[page.category] ?= []
pages_by_category[page.category].push page
categories = []
for category, pages of pages_by_category
categories.push
t_name: _.first(pages).t_category
name: category
pages: pages
wikiPlugin.render 'index', req, {categories: categories}, (html) ->
res.send html
exports.get '/:category/:name', (req, res) ->
page = _.findWhere pluggable.selectHook('plugins.wiki.pages'),
category: req.params.category
name: req.params.name
unless page
return res.status(404).end()
console.log page
view_data =
title: page.plugin.getTranslator(req) page.t_title
content: markdown.toHTML page.content_markdown
wikiPlugin.render 'page', req, view_data, (html) ->
res.send html

View File

@@ -4,10 +4,10 @@ prepend header
title #{t('')} | #{t(config.web.t_name)}
block main
for category in category_list
h2= category.category
for category in categories
h2= category.pages[0].plugin.getTranslator(req)(category.t_name)
ul
for page in category.pages
li
a(href="/wiki/#{category.t_category}/#{page.t_title}")= page.title
|   (#{page.language})
a(href="/wiki/#{category.name}/#{page.name}")= page.plugin.getTranslator(req)(page.t_title)
small   (#{page.language})

View File

@@ -1,46 +0,0 @@
{markdown, path, jade, fs, _, express} = app.libs
{pluggable} = app
WikiPlugin = require './index'
module.exports = exports = express.Router()
exports.get '/', (req, res) ->
pages = pluggable.selectHook req.account, 'plugin.wiki.pages'
pages_by_category = {}
for page in pages
page.title = res.t page.t_title
pages_by_category[page.t_category] ?= []
pages_by_category[page.t_category].push page
result = []
for category_name, pages of pages_by_category
result.push
t_category: category_name
category: res.t category_name
pages: pages
view_data = _.extend res.locals,
category_list: result
WikiPlugin.render 'index', req, view_data, (html) ->
res.send html
exports.get '/:category/:title', (req, res) ->
matched_page = _.findWhere pluggable.selectHook(req.account, 'plugin.wiki.pages'),
t_category: req.params.category
t_title: req.params.title
unless matched_page
return res.status(404).end()
view_data = _.extend res.locals,
title: res.t matched_page.t_title
content: markdown.toHTML matched_page.content_markdown
WikiPlugin.render 'page', req, view_data, (html) ->
res.send html