Class: Hologram::Plugin

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, args) ⇒ Plugin

Plugin constructor: config: This is the config object generated from the config file hologram was loaded with args: These are the command line arguments hologram was run with



9
10
11
# File 'lib/hologram/plugin.rb', line 9

def initialize(config, args)
  @active = self.get_active(args);
end

Instance Attribute Details

#activeObject (readonly)

Returns the value of attribute active.



3
4
5
# File 'lib/hologram/plugin.rb', line 3

def active
  @active
end

Instance Method Details

#block(comment_block, filename, has_plugin) ⇒ Object

This is called on every block that hologram parses. Params: comment_block: This is a doc_block object. It provides name, children, title, markdown, yml config accessors. filename: The filename for the current file being processed has_plugin: This is a boolean that is true if this comment block has plugin data for this plugin and false otherwise.



61
# File 'lib/hologram/plugin.rb', line 61

def block(comment_block, filename, has_plugin) end

#finalize(pages) ⇒ Object

This method is called after hologram has processed all the source files. Pages is a dictionary of html pages to be written. The key is the file name while the value is the html source.



80
# File 'lib/hologram/plugin.rb', line 80

def finalize(pages) end

#get_active(args) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/hologram/plugin.rb', line 13

def get_active(args)
  flagged = false
  OptionParser.new do |opt|
    opt.on_tail("--#{@name}") { flagged = true }
    begin
      opt.parse!(args)
    rescue OptionParser::InvalidOption
      flagged = false
    end
  end

  return flagged
end

#is_active?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/hologram/plugin.rb', line 27

def is_active?()
  @active
end

#parse_block(comment_block, file) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/hologram/plugin.rb', line 31

def parse_block(comment_block, file)

  plugin_sections = comment_block.markdown.scan(/^\s*\[\[\[plugin:#{Regexp.quote(@name)}(.*?)\]\]\]/m)

  if self.is_active?

    self.block(comment_block, file, !plugin_sections.empty?)

    for section in plugin_sections
      plugin_data = section[0]
      replace_text = self.plugin(plugin_data, comment_block, file)
      comment_block.markdown = comment_block.markdown.gsub("[[[plugin:#{@name}#{plugin_data}]]]", replace_text)
    end
  else
    # plugin is inactive, so remove it from our markdown
    for section in plugin_sections
      plugin_data = section[0]
      comment_block.markdown = comment_block.markdown.gsub("[[[plugin:#{@name}#{plugin_data}]]]", '')
    end
  end

end

#plugin(data, block, filename) ⇒ Object

This is called everytime parse_block encounters a [[[plugin:name ]]] section. Params: data: The text inside the plugin section. block: The current doc_block object filename: The filename of the file the plugin section is in

Returns: A string that will replace the plugin block in the documentation



72
73
74
# File 'lib/hologram/plugin.rb', line 72

def plugin(data, block, filename)
  return ""
end