-
Notifications
You must be signed in to change notification settings - Fork 94
/
Copy pathgenerators.rb
99 lines (80 loc) · 2.74 KB
/
generators.rb
1
2
3
4
5
6
7
8
9
10
11
12
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
module Pod
module Doc
# Generators generate the static data used by the static website builder
# (the Middleman).
#
# The data is serialized in a YAML file that contains the representation of
# the CodeObjects classes. These classes are intended to be dumb.
#
module Generators
# The base Generator is an abstract class that provides support for
# concrete subclass. It generates a YAML file suited for building static
# sites.
#
# A generator describes a single YARD Object.
#
class Base
require 'html_helpers'
include ::HTMLHelpers
# @param [String, Array<String>] source_files
# The source files that contains the comments providing the
# docs.
#
def initialize(source_files)
require 'bundler/setup'
require 'yard'
require 'redcarpet'
require 'pygments'
require 'active_support/core_ext/string/inflections'
require 'active_support/core_ext/array/conversions'
@source_files = Array(source_files)
end
# @return [Array<String>] The source files of the generator.
#
attr_reader :source_files
# @return [String] The name of the generator. Subclasses use it find
# the root YARD object.
#
attr_accessor :name
# @return [String] The output file where the generator should be saved.
#
attr_accessor :output_file
#---------------------------------------------------------------------#
# @return [CodeObjects::Base]
#
def generate
puts "\e[1;32mGenerating #{output_file}\e[0m"
generate_code_object
end
# @return [CodeObjects::Base]
#
def generate_code_object
end
# Generates and saves the code object in YAML format to the specified
# output file.
#
# @return [void]
#
def save
require 'yaml'
File.open(output_file, 'w') { |f| f.puts(generate.to_yaml) }
end
#---------------------------------------------------------------------#
private
# @return [YARD::Registry] The yard registry initialized with the
# source files for this generator.
#
def yard_registry
return @yard_registry if @yard_registry
YARD::Registry.clear
raise 'Yard registry not clean' unless YARD::Registry.all.count.zero?
YARD::Registry.load(source_files, true)
@yard_registry = YARD::Registry
end
end
require 'doc/generators/commands'
require 'doc/generators/dsl'
require 'doc/generators/gem'
end
end
end