This commit is contained in:
jysperm
2014-12-02 16:52:59 +08:00
parent 24e49c9e77
commit b758a8ea09
8 changed files with 46 additions and 47 deletions

View File

@@ -83,15 +83,15 @@ app.redis = redis.createClient 6379, '127.0.0.1',
app.mailer = nodemailer.createTransport config.email.account
app.express = express()
app.models = {}
app.classes = {}
app.config = config
app.db = require './core/db'
app.cache = require './core/cache'
app.i18n = require './core/i18n'
app.pluggable = require './core/pluggable'
app.models = {}
app.classes = {}
require './core/model/Account'
require './core/model/Financials'
require './core/model/CouponCode'

View File

@@ -1,4 +1,4 @@
{SSHConnection, fs, child_process} = app.libs
{SSHConnection, fs, child_process, _, async} = app.libs
{config, logger} = app
clusters = exports
@@ -111,7 +111,6 @@ clusters.Node = Node = class Node
stderr = ''
@connectRemote (connection) ->
console.log command
connection.exec command, (err, stream) ->
return callback err if err

View File

@@ -30,7 +30,9 @@ pluggable.hooks =
resources_limit_changed: []
billing:
# widget_generator: function(req, callback(html))
# type
# widget_generator: function(req, callback(html)),
# details_message: function(req, deposit_log, callback(l_details))
payment_methods: []
view:
@@ -54,23 +56,42 @@ pluggable.hooks =
# path
styles: []
pay:
# type, filter: function(req, deposit_log, callback(l_details))
display_payment_details: []
Plugin = class Plugin
info: null
name: null
config: null
path: null
constructor: (@info) ->
@name = @info.name
@name = info.name
@config = config.plugins[@name] ? {}
@path = path.join __dirname, '../plugin', @name
for name, payload of info.register_hooks ? {}
if payload.register_if
unless payload.register_if.apply @
continue
@registerHook name, payload
if info.initialize
info.initialize.apply @
if fs.existsSync path.join(@path, 'locale')
i18n.initPlugin @
if fs.existsSync path.join(@path, 'static')
app.express.use harp.mount "/plugin/#{@name}", path.join(@path, 'static')
registerComponent: (info) ->
component_meta = new ComponentMeta _.extend info,
plugin: @
for path, payload of info.register_hooks ? {}
if payload.register_if and payload.register_if.apply @
@registerComponentHook path, _.extend payload,
component_meta: component_meta
pluggable.components[info.name] = component_meta
registerHook: (name, payload) ->
@@ -90,8 +111,10 @@ Plugin = class Plugin
else
t = i18n.getTranslatorByReq languages
full_name = "plugins.#{@name}.#{name}"
args = _.toArray arguments
args[0] = "plugins.#{@name}.#{name}"
args[0] = full_name
full_result = t.apply @, args
@@ -138,22 +161,6 @@ pluggable.selectHookPath = (name) ->
pluggable.selectHook = (name) ->
return pluggable.selectHookPath name
pluggable.initPlugin = (name) ->
plugin_path = path.join __dirname, '../plugin', name
plugin = require plugin_path
for path, payload in plugin.register_hooks ? {}
if payload.test and payload.test.apply @
plugin.registerHook path, payload
plugin.initialize()
if fs.existsSync path.join(plugin_path, 'locale')
i18n.initPlugin plugin, callback
if fs.existsSync path.join(plugin_path, 'static')
app.express.use harp.mount "/plugin/#{name}", path.join(plugin_path, 'static')
pluggable.initPlugins = ->
plugins_name = config.plugin.available_plugins
@@ -169,9 +176,6 @@ pluggable.initPlugins = ->
exports.plugins[name] = plugin
for name in plugins_name
pluggable.initPlugin name
_.extend app.classes,
Plugin: Plugin
ComponentMeta: ComponentMeta

View File

@@ -49,7 +49,7 @@ $ ->
if client_version == latest_version
window.i18n_data = JSON.parse localStorage.getItem 'locale_cache'
else
$.getJSON "/locale/", (result) ->
$.getJSON "/account/locale/", (result) ->
window.i18n_data = result
localStorage.setItem 'locale_version', latest_version

View File

@@ -22,12 +22,8 @@ html
#navbar-collapse.collapse.navbar-collapse
ul.nav.navbar-nav
for hook in selectHook('view.layout.menu_bar')
if hook.target
li
a(href=hook.href, target=hook.target)= t(hook.t_body)
else
li
a(href=hook.href)= t(hook.t_body)
li
a(href=hook.href, target=hook.target)= hook.plugin.getTranslator(req)(hook.t_body)
ul.nav.navbar-nav.navbar-right
if account
li

View File

@@ -19,7 +19,7 @@ linuxPlugin = module.exports = new Plugin
filter: linux.isUsernameAvailable
'app.started':
test: -> @config.monitor_cycle
register_if: -> @config.monitor_cycle
action: monitor.run
initialize: ->

View File

@@ -12,20 +12,20 @@ rpvhostPlugin = module.exports = new Plugin
t_body: 'official_blog'
'billing.payment_methods':
type: 'taobao'
widget_generator: (req, callback) ->
exports.render 'payment_method', req, {}, callback
rpvhostPlugin.render 'payment_method', req, {}, callback
'view.pay.display_payment_details.taobao':
filter: (req, deposit_log, callback) ->
callback rpvhostPlugin.t(req) 'view.payment_details',
details_message: (req, deposit_log, callback) ->
callback rpvhostPlugin.getTranslator(req) 'view.payment_details',
order_id: deposit_log.payload.order_id
'view.layout.styles':
test: -> @config.green_style
register_if: -> @config.green_style
path: '/plugin/rpvhost/style/green.css'
initialize: ->
unless @config.index_page == false
app.express.get '/', (req, res) ->
rpvhostPlugin.render 'index', req, {}, (html) ->
app.express.get '/', (req, res) =>
@render 'index', req, {}, (html) ->
res.send html

View File

@@ -18,7 +18,7 @@ shadowsocksPlugin = module.exports = new Plugin
'app.started': [
action: shadowsocks.initSupervisor
,
test: -> @config.monitor_cycle
register_if: -> @config.monitor_cycle
action: ->
setInterval shadowsocks.monitoring, config.plugins.shadowsocks.monitor_cycle
]