Class: Bloggit::Plugin

Inherits:
Object
  • Object
show all
Includes:
Test::Unit::Assertions
Defined in:
lib/bloggit/plugin.rb

Overview

Plugin

Plugin.define :my_plugin do |conf|
  # default plugin settings...
end

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.pluginsObject (readonly)

Returns the value of attribute plugins.



15
16
17
# File 'lib/bloggit/plugin.rb', line 15

def plugins
  @plugins
end

.siteObject (readonly)

Returns the value of attribute site.



15
16
17
# File 'lib/bloggit/plugin.rb', line 15

def site
  @site
end

Class Method Details

.[](key) ⇒ Object



48
49
50
# File 'lib/bloggit/plugin.rb', line 48

def [](key)
  @plugins[key]
end

.active_siteObject



44
45
46
# File 'lib/bloggit/plugin.rb', line 44

def active_site
  @site
end

.init(site) ⇒ Object

:nodoc:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/bloggit/plugin.rb', line 17

def init(site) #:nodoc:
  @site = site
  @plugins = {}
  # Load/require plugins from plugins/ dir...
  @plugin_path = File.join(site.base_path, 'plugins')
  $: << @plugin_path
  Dir[ File.join(@plugin_path, '*') ].each do |dir|
    plugin_file = if FileTest.directory?(dir)
      plugin_lib_dir = File.join(dir, 'lib')
      $: << plugin_lib_dir if FileTest.directory?(plugin_lib_dir)
      "#{File.basename(dir)}/init"
    elsif dir.ends_with?('.rb') or dir.ends_with?('.plugin')
      "#{File.basename(dir)}"
    end
    require(plugin_file)
  end
end

.register(plugin_name, opts = {}, &block) ⇒ Object



35
36
37
38
# File 'lib/bloggit/plugin.rb', line 35

def register(plugin_name, opts={}, &block)
  # Yeah...
  @plugins[plugin_name] = block.call( settings_for(plugin_name) )
end

.settings_for(plugin_name) ⇒ Object



40
41
42
# File 'lib/bloggit/plugin.rb', line 40

def settings_for(plugin_name)
  @site.settings.plugins.fetch( plugin_name.to_s, {} )
end