Class: Lokka::App

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/lokka/app.rb

Class Method Summary collapse

Class Method Details

.load_pluginObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/lokka/app.rb', line 3

def self.load_plugin
  names = []
  Dir["public/plugin/lokka-*/lib/lokka/*.rb"].each do |path|
    paths = path.split(File::SEPARATOR)
    $:.push File.join(paths[0], paths[1], paths[2], paths[3])

    i18n = File.join(paths[0], paths[1], paths[2], 'i18n')
    R18n.extension_places << R18n::Loader::YAML.new(i18n) if File.exist? i18n

    name, ext = paths[5].split('.')
    require "lokka/#{name}"
    begin
      plugee = ::Lokka.const_get(name.camelize)
      register plugee
      names << name
    rescue => e
      puts "plugin #{paths[2]} is identified as a suspect."
    end
  end

  plugins = []
  unless @routes['GET'].blank?
    matchers = @routes['GET'].map(&:first)
    names.map do |name|
      OpenStruct.new(
        :name => name,
        :have_admin_page => matchers.any? {|m| m =~ "/admin/plugins/#{name}" })
    end
  end
  set :plugins, plugins
end