Class: Hologram::DocParser

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

Constant Summary collapse

DEFAULT_SUPPORTED_EXTENSIONS =
['.css', '.scss', '.less', '.sass', '.styl', '.js', '.md', '.markdown', '.erb' ]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_path, index_name = nil, plugins = [], opts = {}) ⇒ DocParser

Returns a new instance of DocParser.



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

def initialize(source_path, index_name = nil, plugins=[], opts={})
  @plugins = plugins
  @source_paths = Array(source_path)
  @index_name = index_name
  @nav_level = opts[:nav_level] || 'page'
  @pages = {}
  @output_files_by_category = {}
  @supported_extensions = DEFAULT_SUPPORTED_EXTENSIONS
  @supported_extensions += opts[:custom_extensions] if opts[:custom_extensions]
  @ignore_paths = opts[:ignore_paths] || []
end

Instance Attribute Details

#doc_blocksObject

Returns the value of attribute doc_blocks.



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

def doc_blocks
  @doc_blocks
end

Returns the value of attribute nav_level.



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

def nav_level
  @nav_level
end

#pagesObject

Returns the value of attribute pages.



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

def pages
  @pages
end

#source_pathObject

Returns the value of attribute source_path.



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

def source_path
  @source_path
end

Instance Method Details

#parseObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/hologram/doc_parser.rb', line 18

def parse
  # recursively traverse our directory structure looking for files that
  # match our "parseable" file types. Open those files pulling out any
  # comments matching the hologram doc style /*doc */ and create DocBlock
  # objects from those comments, then add those to a collection object which
  # is then returned.

  doc_block_collection = DocBlockCollection.new

  @source_paths.each do |source_path|
    process_dir(source_path, doc_block_collection)
  end

  # doc blocks can define parent/child relationships that will nest their
  # documentation appropriately. we can't put everything into that structure
  # on our first pass through because there is no guarantee we'll parse files
  # in the correct order. This step takes the full collection and creates the
  # proper structure.
  doc_block_collection.create_nested_structure


  # hand off our properly nested collection to the output generator
  build_output(doc_block_collection.doc_blocks)

  @plugins.finalize(@pages)

  # if we have an index category defined in our config copy that
  # page to index.html
  if @index_name
    name = @index_name + '.html'
    if @pages.has_key?(name)
      @pages['index.html'] = @pages[name]
      title, _ = @output_files_by_category.rassoc(name)
      @output_files_by_category[title] = 'index.html'
    end
  end

  return @pages, @output_files_by_category
end