Class: Hologram::Plugins

Inherits:
Object
  • Object
show all
Defined in:
lib/hologram/plugins.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = {}, args) ⇒ Plugins

Returns a new instance of Plugins.



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/hologram/plugins.rb', line 6

def initialize(config = {}, args)
  @plugins = []

  if config.has_key?('plugins')
    for plugin_file in config['plugins']
      plugin_path = Pathname.new(plugin_file).realpath
      load plugin_path
      plugin_class = Utils.get_class_name(plugin_file)
      register(plugin_class, config, args)
    end
  end
end

Instance Attribute Details

#pluginsObject

Returns the value of attribute plugins.



4
5
6
# File 'lib/hologram/plugins.rb', line 4

def plugins
  @plugins
end

Instance Method Details

#block(comment_block, file) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/hologram/plugins.rb', line 31

def block(comment_block, file)
  for plugin in @plugins
    #We parse comment blocks even when the plugin is not active,
    #this allows us to remove the plugin's data blocks from the
    #markdown output
    plugin.parse_block(comment_block, file)
  end
end

#finalize(pages) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/hologram/plugins.rb', line 40

def finalize(pages)
  for plugin in @plugins
    if plugin.is_active?
      plugin.finalize(pages)
    end
  end
end

#register(plugin_class, config, args) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/hologram/plugins.rb', line 19

def register(plugin_class, config, args)
  clazz = Object.const_get(plugin_class)
  obj = clazz.new(config, args)
  if obj.is_active?
    DisplayMessage.info("Plugin active: #{plugin_class}")
  else
    DisplayMessage.info("Plugin not active: #{plugin_class}")
  end

  @plugins.push(obj)
end