Class: Hologram::DocParser

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

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_path, index_name = nil) ⇒ DocParser

Returns a new instance of DocParser.



6
7
8
9
10
11
# File 'lib/hologram/doc_parser.rb', line 6

def initialize(source_path, index_name = nil)
  @source_path = source_path
  @index_name = index_name
  @pages = {}
  @categories = {}
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

#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



13
14
15
16
17
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
# File 'lib/hologram/doc_parser.rb', line 13

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 = process_dir(source_path)

  # 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)

  # 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]
    end
  end

  return @pages, @categories
end