Class: PDoc::Generators::Html::Website
Class Attribute Summary collapse
Instance Attribute Summary collapse
#options, #root
Class Method Summary
collapse
Instance Method Summary
collapse
#auto_link, #auto_link_code, #auto_link_content, #auto_link_types, #dom_id, #path_prefix, #path_to
#content_tag, #htmlize, #img_tag, #inline_htmlize, #javascript_include_tag, #link_to, #stylesheet_link_tag, #tag
#mkdir
Constructor Details
#initialize(parser_output, options = {}) ⇒ Website
Returns a new instance of Website.
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/pdoc/generators/html/website.rb', line 26
def initialize(parser_output, options = {})
super
@templates_directory = File.expand_path(options[:templates] || TEMPLATES_DIRECTORY)
@index_page = options[:index_page] && File.expand_path(options[:index_page])
@custom_assets = @options[:assets] && File.expand_path(@options[:assets])
self.class.syntax_highlighter = SyntaxHighlighter.new(options[:syntax_highlighter])
self.class.pretty_urls = options[:pretty_urls]
set_markdown_parser(options[:markdown_parser])
load_custom_helpers
end
|
Class Attribute Details
.markdown_parser ⇒ Object
Returns the value of attribute markdown_parser.
16
17
18
|
# File 'lib/pdoc/generators/html/website.rb', line 16
def markdown_parser
@markdown_parser
end
|
.syntax_highlighter ⇒ Object
Returns the value of attribute syntax_highlighter.
15
16
17
|
# File 'lib/pdoc/generators/html/website.rb', line 15
def syntax_highlighter
@syntax_highlighter
end
|
Instance Attribute Details
#custom_assets ⇒ Object
Returns the value of attribute custom_assets.
25
26
27
|
# File 'lib/pdoc/generators/html/website.rb', line 25
def custom_assets
@custom_assets
end
|
#index_page ⇒ Object
Returns the value of attribute index_page.
25
26
27
|
# File 'lib/pdoc/generators/html/website.rb', line 25
def index_page
@index_page
end
|
#templates_directory ⇒ Object
Returns the value of attribute templates_directory.
25
26
27
|
# File 'lib/pdoc/generators/html/website.rb', line 25
def templates_directory
@templates_directory
end
|
Class Method Details
.pretty_urls=(boolean) ⇒ Object
21
22
23
|
# File 'lib/pdoc/generators/html/website.rb', line 21
def pretty_urls=(boolean)
@pretty_urls = boolean
end
|
.pretty_urls? ⇒ Boolean
17
18
19
|
# File 'lib/pdoc/generators/html/website.rb', line 17
def pretty_urls?
!!@pretty_urls
end
|
Instance Method Details
#copy_assets ⇒ Object
Copies the content of the assets folder to the generated website’s root directory.
125
126
127
|
# File 'lib/pdoc/generators/html/website.rb', line 125
def copy_assets
FileUtils.cp_r(Dir.glob(File.join(templates_directory, "assets", "**")), '.')
end
|
#copy_custom_assets ⇒ Object
129
130
131
132
133
|
# File 'lib/pdoc/generators/html/website.rb', line 129
def copy_custom_assets
if custom_assets
FileUtils.cp_r(Dir.glob(File.join(custom_assets, "**")), ".")
end
end
|
#load_custom_helpers ⇒ Object
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/pdoc/generators/html/website.rb', line 54
def load_custom_helpers
begin
require File.join(templates_directory, "helpers")
rescue LoadError => e
return nil
end
self.class.__send__(:include, Helpers::BaseHelper)
Page.__send__(:include, Helpers::BaseHelper)
Helpers.constants.map(&Helpers.method(:const_get)).each(&DocPage.method(:include))
end
|
#render(output) ⇒ Object
Generates the website to the specified directory.
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/pdoc/generators/html/website.rb', line 66
def render(output)
@depth = 0
path = File.expand_path(output)
FileUtils.mkdir_p(path)
Dir.chdir(path) do
render_index
copy_assets
copy_custom_assets
render_children(root)
if root.sections?
root.sections.each do |section|
@depth = 0
render_template('section', { :doc_instance => section })
end
end
dest = File.join("javascripts", "pdoc", "item_index.js")
DocPage.new("item_index.js", false, variables).render_to_file(dest)
end
end
|
#render_children(obj) ⇒ Object
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/pdoc/generators/html/website.rb', line 110
def render_children(obj)
[:namespaces, :classes, :mixins].each do |prop|
obj.send(prop).each(&method(:render_node)) if obj.respond_to?(prop)
end
obj.utilities.each(&method(:render_leaf)) if obj.respond_to?(:utilities)
render_leaf(obj.constructor) if obj.respond_to?(:constructor) && obj.constructor
[:instance_methods, :instance_properties, :class_methods, :class_properties, :constants].each do |prop|
obj.send(prop).each(&method(:render_leaf)) if obj.respond_to?(prop)
end
end
|
#render_index ⇒ Object
89
90
91
92
|
# File 'lib/pdoc/generators/html/website.rb', line 89
def render_index
vars = variables.merge(:index_page_content => index_page_content, :home => true)
DocPage.new('index', 'layout', vars).render_to_file('index.html')
end
|
#render_json(dest, obj) ⇒ Object
106
107
108
|
# File 'lib/pdoc/generators/html/website.rb', line 106
def render_json(dest, obj)
open(dest, 'w') { |file| file << obj.to_json }
end
|
#render_leaf(object) ⇒ Object
135
136
137
138
139
140
|
# File 'lib/pdoc/generators/html/website.rb', line 135
def render_leaf(object)
is_proto_prop = is_proto_prop?(object)
@depth += 1 if is_proto_prop
render_template('leaf', { :doc_instance => object })
@depth -= 1 if is_proto_prop
end
|
#render_node(object) ⇒ Object
142
143
144
|
# File 'lib/pdoc/generators/html/website.rb', line 142
def render_node(object)
render_template('node', { :doc_instance => object })
end
|
#render_template(template, var = {}) ⇒ Object
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/pdoc/generators/html/website.rb', line 94
def render_template(template, var = {})
@depth += 1
doc = var[:doc_instance]
dest = doc.url(File::SEPARATOR)
puts " Rendering #{dest}..."
FileUtils.mkdir_p(dest)
DocPage.new(template, variables.merge(var)).render_to_file(File.join(dest, 'index.html'))
render_json("#{dest}.json", doc) if json_api?
render_children(doc)
@depth -= 1
end
|
#set_markdown_parser(parser = nil) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/pdoc/generators/html/website.rb', line 37
def set_markdown_parser(parser = nil)
parser = :rdiscount if parser.nil?
case parser.to_sym
when :rdiscount
require 'rdiscount'
self.class.markdown_parser = RDiscount
when :bluecloth
require 'bluecloth'
self.class.markdown_parser = BlueCloth
when :maruku
require 'maruku'
self.class.markdown_parser = Maruku
else
raise "Requested unsupported Markdown parser: #{parser}."
end
end
|