Browse Source

Implemented Angular Module support in plugins.

Added better plugin examle.
Added support to serve static resources from extra subfolder static.
pull/3/head
Simon Eisenmann 12 years ago
parent
commit
0b1a53da37
  1. 88
      doc/plugin-example.js
  2. 10
      src/app/spreed-speakfreely-server/main.go
  3. 11
      static/js/app.js
  4. 15
      static/js/main.js
  5. 8
      static/js/plugins/example1.js

88
doc/plugin-example.js

@ -0,0 +1,88 @@ @@ -0,0 +1,88 @@
/*
* Spreed Speak Freely.
* Copyright (C) 2013-2014 struktur AG
*
* This file is part of Spreed Speak Freely.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
define(['angular'], function(angular) {
return {
// Angular modules - either overwrite existing modules or add new
// ones. All app dependencies are already loaded so modules defined
// here will be used instead of the default ones.
// To load add a new module to the angular app, append the name of
// the module to the modules array.
// Defining a module in a plugin is optional.
module: function(modules) {
// Create and add a new module.
// See http://docs.angularjs.org/guide/module for details on Angular.
var module = angular.module('myExamplePluginModule', []).
config([function() { // provider-injector
// This is an example of config block.
// You can have as many of these as you want.
// You can only inject Providers (not instances)
// into the config blocks.
console.log("Configuring myExamplePluginModule plugin ...")
}]).
run(["$rootScope", function($rootScope) { // instance-injector
// This is an example of a run block.
// You can have as many of these as you want.
// You can only inject instances (not Providers)
// into the run blocks.
console.log("Initializing myExamplePluginModule plugin ...");
}]);
// Add an example service on module level.
module.service('myExamplePluginModuleService', [function() {
return {
nice: "plugin"
}
}]);
// Inject new module into modules array so that it gets loaded
// with the App.
modules.push(module.name);
},
// Initialize function for this module.
// Add your angular stuff here. The app is the base Angular module for
// the web application. The plugin initialize function is called after
// the app initialize function.
// Defining the initialize function is optional.
initialize: function(app) {
console.log("Initializing plugin-example ...");
// Add some directives and services.
app.service('myExamplePluginInitService', ["$window", function($window) {
// Service code here ...
return {
awesome: "plugin service"
}
}]);
app.directive('myExamplePluginInitDirective', [function() {
// Directive code here ...
}]);
}
}
});

10
src/app/spreed-speakfreely-server/main.go

@ -292,6 +292,16 @@ func runner(runtime phoenix.Runtime) error { @@ -292,6 +292,16 @@ func runner(runtime phoenix.Runtime) error {
r.Handle("/ws", makeWsHubHandler(hub))
r.HandleFunc("/{room}", httputils.MakeGzipHandler(roomHandler))
makeApiHandler(r, tokenProvider)
// Add extra/static support if configured and exists.
if extraFolder != "" {
extraFolderStatic := path.Join(extraFolder, "static")
if _, err = os.Stat(extraFolderStatic); err == nil {
r.Handle("/extra/static/{path:.*}", http.StripPrefix(fmt.Sprintf("%sextra", basePath), httputils.FileStaticServer(http.Dir(extraFolder))))
log.Printf("Added URL handler /extra/static/... for static files in %s/...\n", extraFolderStatic)
}
}
runtime.DefaultHTTPHandler(r)
return runtime.Start()

11
static/js/app.js

@ -41,9 +41,16 @@ define([ @@ -41,9 +41,16 @@ define([
], function(require, $, _, angular, modernizr, moment, services, directives, filters, controllers) {
var initialize = function() {
var initialize = function(ms) {
var app = angular.module('app', ['ui.bootstrap', 'ngSanitize', 'ngAnimate', 'ngHumanize', 'ngRoute', 'dialogs']);
var modules = ['ui.bootstrap', 'ngSanitize', 'ngAnimate', 'ngHumanize', 'ngRoute', 'dialogs'];
if (ms && ms.length) {
_.each(ms, function(module) {
modules.push(module);
});
}
var app = angular.module('app', modules);
services.initialize(app);
directives.initialize(app);
filters.initialize(app);

15
static/js/main.js

@ -149,13 +149,22 @@ define([ @@ -149,13 +149,22 @@ define([
}
});
require(load, function(App) {
var app = App.initialize();
var args = Array.prototype.slice.call(arguments, 1);
// Add Angular modules from plugins.
var modules = [];
_.each(args, function(plugin) {
if (plugin && plugin.module) {
plugin.module(modules);
}
});
// Init Angular app.
var app = App.initialize(modules);
// Init plugins.
_.each(args, function(plugin) {
if (plugin && plugin.initialize) {
plugin.initialize(app)
plugin.initialize(app);
}
})
});
});
});

8
static/js/plugins/example1.js

@ -1,8 +0,0 @@ @@ -1,8 +0,0 @@
// Example plugin shows the basic API.
define([], function() {
return {
initialize: function(app) {
console.log("Example plugin 1 loaded.", app);
}
}
});
Loading…
Cancel
Save