Class: Betterdocs::Generator::Markdown
- Inherits:
-
Object
- Object
- Betterdocs::Generator::Markdown
show all
- Includes:
- ConfigShortcuts, FileUtils, Term::ANSIColor
- Defined in:
- lib/betterdocs/generator/markdown.rb
Instance Method Summary
collapse
#api_base_url, #config, #project_name, #section, #sections
Constructor Details
#initialize(only: nil) ⇒ Markdown
Returns a new instance of Markdown.
12
13
14
|
# File 'lib/betterdocs/generator/markdown.rb', line 12
def initialize(only: nil)
only and @only = Regexp.new(only)
end
|
Instance Method Details
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/betterdocs/generator/markdown.rb', line 33
def configure_for_creation
infobar.puts color(40, "Setting asset_host to #{Betterdocs::Global.asset_host.inspect}.")
Betterdocs.rails.configuration.action_controller.asset_host = Betterdocs::Global.asset_host
options = {
host: Betterdocs::Global.api_host,
protocol: Betterdocs::Global.api_protocol
}
infobar.puts color(40, "Setting default_url_options to #{options.inspect}.")
Betterdocs.rails.application.routes.default_url_options = options
self
end
|
#create_assets ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/betterdocs/generator/markdown.rb', line 73
def create_assets
Infobar(total: config.assets.size)
config.each_asset do |src, dst|
infobar.progress(
message: " Asset #{File.basename(src).inspect} %c/%t in %te ETA %e @%E ",
force: true
)
mkdir_p File.dirname(dst)
cp Betterdocs.rails.root.join(src), dst
end
infobar.finish message: ' %t assets created in %te, completed @%E '
infobar.newline
self
end
|
#create_readme(dirname) ⇒ Object
64
65
66
67
68
69
70
71
|
# File 'lib/betterdocs/generator/markdown.rb', line 64
def create_readme(dirname)
name = 'README.md'
cd dirname do
infobar.puts color(40, "Creating readme.")
render_to name, readme_template, binding
end
self
end
|
#create_sections(dirname) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/betterdocs/generator/markdown.rb', line 45
def create_sections(dirname)
Infobar(total: sections.size)
cd dirname do
for section in sections.values
infobar.progress(
message: " Section #{section.name.to_s.inspect} %c/%t in %te ETA %e @%E ",
force: true
)
if @only
@only =~ section.name or next
end
render_to "sections/#{section.name}.md", section_template, section.instance_eval('binding')
end
end
infobar.finish message: ' %t sections created in %te, completed @%E '
infobar.newline
self
end
|
#generate ⇒ Object
16
17
18
19
20
21
22
|
# File 'lib/betterdocs/generator/markdown.rb', line 16
def generate
if dir = config.output_directory.full?
generate_to dir
else
fail "Specify an output_directory in your configuration!"
end
end
|
#generate_to(dirname) ⇒ Object
24
25
26
27
28
29
30
31
|
# File 'lib/betterdocs/generator/markdown.rb', line 24
def generate_to(dirname)
configure_for_creation
prepare_dir dirname
create_sections(dirname)
create_readme dirname
create_assets
self
end
|