Class: Lookbook::Parser

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(paths) ⇒ Parser

Returns a new instance of Parser.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/lookbook/parser.rb', line 6

def initialize(paths)
  @paths = paths.map { |p| "#{p}/**/*preview.rb" }
  @after_parse_callbacks = []
  @after_parse_once_callbacks = []
  @parsing = false

  YARD::Parser::SourceParser.after_parse_list do
    [*@after_parse_callbacks, *@after_parse_once_callbacks].each do |callback|
      callback.call(YARD::Registry)
    end
    @after_parse_once_callbacks = []
    @parsing = false
  end
end

Instance Attribute Details

#registry_pathObject (readonly)

Returns the value of attribute registry_path.



5
6
7
# File 'lib/lookbook/parser.rb', line 5

def registry_path
  @registry_path
end

Class Method Details

.define_tags(custom = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/lookbook/parser.rb', line 35

def define_tags(custom = {})
  YARD::Tags::Library.define_tag("Hidden status", :hidden)
  YARD::Tags::Library.define_tag("Label", :label)
  YARD::Tags::Library.define_tag("Display", :display)
  YARD::Tags::Library.define_tag("Position", :position)
  YARD::Tags::Library.define_tag("ID", :id)
  YARD::Tags::Library.define_tag("Component", :component)
  custom.each do |name, opts|
    YARD::Tags::Library.define_tag(name.to_s.titleize, name)
  end
end

Instance Method Details

#after_parse(&block) ⇒ Object



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

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

#parse(&block) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/lookbook/parser.rb', line 21

def parse(&block)
  unless @parsing
    @parsing = true
    @after_parse_once_callbacks << block if block
    YARD::Registry.clear
    YARD.parse(@paths)
  end
end