diff --git a/app.coffee b/app.coffee index cc24f3c..9213298 100755 --- a/app.coffee +++ b/app.coffee @@ -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' diff --git a/core/clusters.coffee b/core/clusters.coffee index 8efc738..79d8046 100644 --- a/core/clusters.coffee +++ b/core/clusters.coffee @@ -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 diff --git a/core/pluggable.coffee b/core/pluggable.coffee index a3b3270..9a1ef86 100644 --- a/core/pluggable.coffee +++ b/core/pluggable.coffee @@ -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 diff --git a/core/static/script/layout.coffee b/core/static/script/layout.coffee index a718764..b1df10b 100644 --- a/core/static/script/layout.coffee +++ b/core/static/script/layout.coffee @@ -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 diff --git a/core/view/layout.jade b/core/view/layout.jade index 227fac2..b58783a 100644 --- a/core/view/layout.jade +++ b/core/view/layout.jade @@ -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 diff --git a/plugin/linux/index.coffee b/plugin/linux/index.coffee index a1fba78..12cdcf1 100644 --- a/plugin/linux/index.coffee +++ b/plugin/linux/index.coffee @@ -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: -> diff --git a/plugin/rpvhost/index.coffee b/plugin/rpvhost/index.coffee index e3904f2..2a0a32b 100644 --- a/plugin/rpvhost/index.coffee +++ b/plugin/rpvhost/index.coffee @@ -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 diff --git a/plugin/shadowsocks/index.coffee b/plugin/shadowsocks/index.coffee index 658d522..63ce58b 100644 --- a/plugin/shadowsocks/index.coffee +++ b/plugin/shadowsocks/index.coffee @@ -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 ]