mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-11-28 09:24:24 +01:00
plugin underconstruction... !
This commit is contained in:
parent
26f0aa5e0d
commit
a14130473a
@ -72,3 +72,7 @@
|
||||
//= require_tree ./services
|
||||
//= require_tree ./directives
|
||||
//= require_tree ./filters
|
||||
|
||||
<%
|
||||
PluginRegistry.javascripts.each { |js| require_asset(js) }
|
||||
%>
|
@ -44,7 +44,8 @@ Application.Controllers.controller "MainNavController", ["$scope", "$location",
|
||||
})
|
||||
|
||||
|
||||
$scope.adminNavLinks = [
|
||||
Fablab.adminNavLinks = Fablab.adminNavLinks || []
|
||||
Fablab.adminNavLinks = [
|
||||
{
|
||||
state: 'app.admin.trainings'
|
||||
linkText: 'trainings_monitoring'
|
||||
@ -95,5 +96,7 @@ Application.Controllers.controller "MainNavController", ["$scope", "$location",
|
||||
linkText: 'customization'
|
||||
linkIcon: 'gear'
|
||||
}
|
||||
]
|
||||
].concat(Fablab.adminNavLinks)
|
||||
|
||||
$scope.adminNavLinks = Fablab.adminNavLinks
|
||||
]
|
||||
|
@ -34,3 +34,5 @@
|
||||
@import "modules/invoice";
|
||||
|
||||
@import "app.responsive";
|
||||
|
||||
@import "navi_gami"; // change it to be dynamic !!!
|
@ -13,12 +13,14 @@ require "rails/all"
|
||||
require 'elasticsearch/rails/instrumentation'
|
||||
require 'elasticsearch/persistence/model'
|
||||
|
||||
|
||||
# Require the gems listed in Gemfile, including any gems
|
||||
# you've limited to :test, :development, or :production.
|
||||
Bundler.require(*Rails.groups)
|
||||
|
||||
module Fablab
|
||||
class Application < Rails::Application
|
||||
require 'fab_manager'
|
||||
# Settings in config/environments/* take precedence over those specified here.
|
||||
# Application configuration should go into files in config/initializers
|
||||
# -- all .rb files in that directory are automatically loaded.
|
||||
@ -62,5 +64,14 @@ module Fablab
|
||||
config.web_console.whitelisted_ips << '10.0.2.2' #vagrant
|
||||
end
|
||||
|
||||
config.i18n.load_path += Dir["#{Rails.root}/plugins/*/config/locales/*.yml"]
|
||||
|
||||
FabManager.activate_plugins!
|
||||
|
||||
config.after_initialize do
|
||||
if plugins = FabManager.plugins
|
||||
plugins.each { |plugin| plugin.notify_after_initialize }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
17
lib/fab_manager.rb
Normal file
17
lib/fab_manager.rb
Normal file
@ -0,0 +1,17 @@
|
||||
require_dependency 'plugin/instance'
|
||||
|
||||
module FabManager
|
||||
class << self
|
||||
attr_reader :plugins
|
||||
end
|
||||
|
||||
def self.activate_plugins!
|
||||
all_plugins = Plugin::Instance.find_all("#{Rails.root}/plugins")
|
||||
|
||||
@plugins = []
|
||||
all_plugins.each do |p|
|
||||
p.activate!
|
||||
@plugins << p
|
||||
end
|
||||
end
|
||||
end
|
88
lib/plugin/instance.rb
Normal file
88
lib/plugin/instance.rb
Normal file
@ -0,0 +1,88 @@
|
||||
require 'fileutils'
|
||||
require 'plugin_registry'
|
||||
|
||||
module Plugin
|
||||
class Instance
|
||||
attr_accessor :path
|
||||
|
||||
[:assets, :initializers, :javascripts, :styles].each do |att|
|
||||
class_eval %Q{
|
||||
def #{att}
|
||||
@#{att} ||= []
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
def self.find_all(parent_path)
|
||||
[].tap { |plugins|
|
||||
# also follows symlinks - http://stackoverflow.com/q/357754
|
||||
Dir["#{parent_path}/**/*/**/plugin.rb"].sort.each do |path|
|
||||
|
||||
source = File.read(path)
|
||||
# metadata = Plugin::Metadata.parse(source)
|
||||
plugins << self.new(nil, path)
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
def initialize(metadata=nil, path=nil)
|
||||
@metadata = metadata
|
||||
@path = path
|
||||
@idx = 0
|
||||
end
|
||||
|
||||
def activate!
|
||||
if @path
|
||||
root_path = "#{File.dirname(@path)}/assets/javascripts"
|
||||
PluginRegistry.register_glob(root_path, 'coffee.erb')
|
||||
end
|
||||
|
||||
self.instance_eval File.read(path), path # execute all code of the plugin main file ! (named plugin.rb)
|
||||
|
||||
register_assets! unless assets.blank?
|
||||
|
||||
Rails.configuration.assets.paths << File.dirname(path) + "/assets"
|
||||
|
||||
Rails.configuration.assets.precompile += [lambda do |filename, path|
|
||||
(Dir["plugins/*/assets/templates"].any? { |p| path.include?(p) }) # useless because already included in application.css/js || (%w(.js).include?(File.extname(filename)) && Dir["plugins/*/assets/javascripts"].any? { |p| path.include?(p) }) || (%w(.css).include?(File.extname(filename)) && Dir["plugins/*/assets/stylesheets"].any? { |p| path.include?(p) })
|
||||
end] #
|
||||
|
||||
Rails.configuration.sass.load_paths += Dir["plugins/*/assets/stylesheets"]
|
||||
|
||||
|
||||
# Automatically include rake tasks
|
||||
Rake.add_rakelib(File.dirname(path) + "/lib/tasks")
|
||||
|
||||
# Automatically include migrations
|
||||
Rails.configuration.paths["db/migrate"] << File.dirname(path) + "/db/migrate"
|
||||
end
|
||||
|
||||
def register_asset(file, opts=nil) # to be used by the plugin !
|
||||
full_path = File.dirname(path) << "/assets/" << file
|
||||
assets << [full_path, opts]
|
||||
end
|
||||
|
||||
def after_initialize(&block)
|
||||
initializers << block
|
||||
end
|
||||
|
||||
def notify_after_initialize
|
||||
initializers.each do |callback|
|
||||
begin
|
||||
callback.call(self)
|
||||
rescue ActiveRecord::StatementInvalid => e
|
||||
# When running db:migrate for the first time on a new database, plugin initializers might
|
||||
# try to use models. Tolerate it.
|
||||
raise e unless e.message.try(:include?, "PG::UndefinedTable")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
def register_assets!
|
||||
assets.each do |asset, opts|
|
||||
PluginRegistry.register_asset(asset, opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
50
lib/plugin_registry.rb
Normal file
50
lib/plugin_registry.rb
Normal file
@ -0,0 +1,50 @@
|
||||
class PluginRegistry
|
||||
class << self
|
||||
attr_writer :javascripts
|
||||
attr_writer :stylesheets
|
||||
|
||||
def asset_globs
|
||||
@asset_globs ||= Set.new
|
||||
end
|
||||
|
||||
def javascripts
|
||||
@javascripts ||= Set.new
|
||||
end
|
||||
|
||||
def stylesheets
|
||||
@stylesheets ||= Set.new
|
||||
end
|
||||
end
|
||||
|
||||
def self.register_glob(root, extension, options=nil)
|
||||
self.asset_globs << [root, extension, options || {}]
|
||||
end
|
||||
|
||||
def self.register_asset(asset, opts=nil)
|
||||
if asset =~ /\.js$|\.js\.erb$|\.js\.es6$|\.coffee$|\.coffee\.erb/
|
||||
# if opts == :admin
|
||||
# self.admin_javascripts << asset
|
||||
# else
|
||||
# if opts == :server_side
|
||||
# self.server_side_javascripts << asset
|
||||
# end
|
||||
self.javascripts << asset
|
||||
# end
|
||||
elsif asset =~ /\.css$|\.scss$/
|
||||
# if opts == :mobile
|
||||
# self.mobile_stylesheets << asset
|
||||
# elsif opts == :desktop
|
||||
# self.desktop_stylesheets << asset
|
||||
# elsif opts == :variables
|
||||
# self.sass_variables << asset
|
||||
# else
|
||||
self.stylesheets << asset
|
||||
# end
|
||||
|
||||
# elsif asset =~ /\.hbs$/
|
||||
# self.handlebars << asset
|
||||
# elsif asset =~ /\.js\.handlebars$/
|
||||
# self.handlebars << asset
|
||||
end
|
||||
end
|
||||
end
|
0
plugins/.keep
Normal file
0
plugins/.keep
Normal file
48
plugins/navi_gami/assets/javascripts/navi_gami.coffee.erb
Normal file
48
plugins/navi_gami/assets/javascripts/navi_gami.coffee.erb
Normal file
@ -0,0 +1,48 @@
|
||||
plugin_name = 'navi gami'
|
||||
|
||||
# get fabmanager main module
|
||||
app = angular.module('application')
|
||||
|
||||
|
||||
# initialize module and configure routing
|
||||
angular.module('application.navi_gami', ['application'])
|
||||
.config [
|
||||
'$stateProvider',
|
||||
($stateProvider) ->
|
||||
$stateProvider
|
||||
.state 'app.admin.navi_gami',
|
||||
url: '/navinum_gamification'
|
||||
views:
|
||||
'main@':
|
||||
templateUrl: '<%= asset_path "templates/navi_gami.html" %>'
|
||||
controller: ->
|
||||
console.log 'ctrl navi_gami'
|
||||
|
||||
]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# injects dependecy to main app module
|
||||
app.requires.push('application.navi_gami')
|
||||
|
||||
|
||||
window.Fablab.adminNavLinks = window.Fablab.adminNavLinks || []
|
||||
window.Fablab.adminNavLinks.push(
|
||||
{
|
||||
state: 'app.admin.navi_gami'
|
||||
linkText: 'Gamification'
|
||||
linkIcon: 'gamepad'
|
||||
}
|
||||
)
|
0
plugins/navi_gami/assets/stylesheets/navi_gami.scss
Normal file
0
plugins/navi_gami/assets/stylesheets/navi_gami.scss
Normal file
1
plugins/navi_gami/assets/templates/navi_gami.html.erb
Normal file
1
plugins/navi_gami/assets/templates/navi_gami.html.erb
Normal file
@ -0,0 +1 @@
|
||||
TEST
|
15
plugins/navi_gami/plugin.rb
Normal file
15
plugins/navi_gami/plugin.rb
Normal file
@ -0,0 +1,15 @@
|
||||
register_asset "stylesheets/navi_gami.scss"
|
||||
register_asset "javascripts/navi_gami.coffee.erb"
|
||||
|
||||
PLUGIN_NAME ||= "navi_gami".freeze
|
||||
|
||||
|
||||
after_initialize do
|
||||
module ::NaviGami
|
||||
class Engine < ::Rails::Engine
|
||||
engine_name PLUGIN_NAME
|
||||
isolate_namespace NaviGami
|
||||
end
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue
Block a user