Class: Lookbook::PreviewParser

Inherits:
Object
  • Object
show all
Defined in:
lib/lookbook/preview_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(paths, tags = nil) ⇒ PreviewParser

Returns a new instance of PreviewParser.



5
6
7
8
9
10
11
12
13
# File 'lib/lookbook/preview_parser.rb', line 5

def initialize(paths, tags = nil)
  @paths = paths
  @after_parse_callbacks = []
  @after_parse_once_callbacks = []
  @parsing = false

  define_tags(tags)
  YARD::Parser::SourceParser.after_parse_list { run_callbacks }
end

Instance Method Details

#after_parse(&block) ⇒ Object



26
27
28
# File 'lib/lookbook/preview_parser.rb', line 26

def after_parse(&block)
  @after_parse_callbacks << block
end

#parse(files = nil, &block) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/lookbook/preview_parser.rb', line 15

def parse(files = nil, &block)
  unless @parsing
    @parsing = true
    @after_parse_once_callbacks << block if block
    files_list = files ? files.select { |file| file.to_s.end_with?(".rb") } : paths

    YARD::Registry.clear
    YARD.parse(files_list)
  end
end

#pathsObject



30
31
32
# File 'lib/lookbook/preview_parser.rb', line 30

def paths
  PathUtils.normalize_paths(@paths).map { |path| "#{path}/**/*preview.rb" }
end