Module: Octopress::Docs
- Defined in:
- lib/octopress-docs.rb,
lib/octopress-docs/doc.rb,
lib/octopress-docs/tag.rb,
lib/octopress-docs/page.rb,
lib/octopress-docs/hooks.rb,
lib/octopress-docs/command.rb,
lib/octopress-docs/version.rb
Defined Under Namespace
Classes: Commands, Doc, DocUrlTag, DocsSiteHook, Page
Constant Summary
collapse
- VERSION =
"0.0.5"
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Attribute Details
#docs ⇒ Object
Returns the value of attribute docs.
16
17
18
|
# File 'lib/octopress-docs.rb', line 16
def docs
@docs
end
|
Class Method Details
.add(options) ⇒ Object
110
111
112
113
114
115
116
|
# File 'lib/octopress-docs.rb', line 110
def self.add(options)
options[:docs] ||= %w{readme changelog}
options[:docs_path] ||= File.join(options[:dir], 'assets', 'docs')
docs = []
docs.concat add_root_docs(options)
docs.concat
end
|
.add_doc_page(options) ⇒ Object
144
145
146
147
148
149
|
# File 'lib/octopress-docs.rb', line 144
def self.add_doc_page(options)
page = Docs::Doc.new(options)
@docs[options[:slug]] ||= []
@docs[options[:slug]] << page
page
end
|
.add_plugin_docs(plugin) ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/octopress-docs.rb', line 59
def self.add_plugin_docs(plugin)
plugin_doc_pages = []
options = plugin_options(plugin)
find_doc_pages(options).each do |doc|
unless doc =~ /^_/
opts = options.merge({file: doc, dir: options[:docs_path]})
plugin_doc_pages << add_doc_page(opts)
end
end
has_index = !plugin_doc_pages.select {|d| d.file =~ /^index/ }.empty?
plugin_doc_pages << add_root_plugin_doc(plugin, 'readme', index: !has_index)
plugin_doc_pages << add_root_plugin_doc(plugin, 'changelog')
plugin_doc_pages
end
|
.add_root_doc(filename, options) ⇒ Object
131
132
133
134
135
|
# File 'lib/octopress-docs.rb', line 131
def self.add_root_doc(filename, options)
if file = select_first(options[:dir], filename)
add_doc_page(options.merge({file: file}))
end
end
|
.add_root_docs(options) ⇒ Object
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/octopress-docs.rb', line 118
def self.add_root_docs(options)
root_docs = []
options[:docs].each do |doc|
if doc =~ /readme/
root_docs << add_root_doc(doc, options.merge({index: true}))
else
root_docs << add_root_doc(doc, options)
end
end
root_docs
end
|
.add_root_plugin_doc(plugin, filename, options = {}) ⇒ Object
137
138
139
140
141
142
|
# File 'lib/octopress-docs.rb', line 137
def self.add_root_plugin_doc(plugin, filename, options={})
options = plugin_options(plugin).merge(options)
require 'pry-byebug'; binding.pry
add_root_doc(filename, options)
end
|
.base_url(options) ⇒ Object
102
103
104
105
106
107
108
|
# File 'lib/octopress-docs.rb', line 102
def self.base_url(options)
options[:base_url] || if options[:type] == 'theme'
File.join('docs', 'theme')
else
File.join('docs', 'plugins', options[:slug])
end
end
|
.default_options(options) ⇒ Object
90
91
92
93
94
95
|
# File 'lib/octopress-docs.rb', line 90
def self.default_options(options)
options[:type] ||= 'plugin'
options[:slug] = slug(options)
options[:base_url] = base_url(options)
options[:dir] ||= '.'
end
|
.gem_dir(dir = '') ⇒ Object
21
22
23
|
# File 'lib/octopress-docs.rb', line 21
def self.gem_dir(dir='')
File.expand_path(File.join(File.dirname(__FILE__), '../', dir))
end
|
.pages ⇒ Object
27
28
29
|
# File 'lib/octopress-docs.rb', line 27
def self.pages
@docs.values.flatten.map {|d| d.page }
end
|
.pages_info ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/octopress-docs.rb', line 31
def self.pages_info
docs = @docs.clone
docs.each { |slug, pages|
docs[slug] = {
"name" => pages.first.plugin_name,
"docs" => plugin_docs(pages)
}
}
{ 'plugin_docs' => docs }
end
|
.plugin_docs(pages) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/octopress-docs.rb', line 43
def self.plugin_docs(pages)
pages.clone.map { |d|
page = d.page
title = page.data['link_title'] || page.data['title'] || page.basename
url = File.join('/', d.base_url, page.url.sub('index.html', ''))
{
'title' => title,
'url' => url
}
}.sort_by { |i|
i['url'].split('/').size
}
end
|
.plugin_options(plugin) ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/octopress-docs.rb', line 78
def self.plugin_options(plugin)
{
name: plugin.name,
slug: plugin.slug,
type: plugin.type,
base_url: plugin.docs_url,
dir: plugin.path,
docs_path: File.join(plugin.assets_path, 'docs'),
docs: %w{readme changelog}
}
end
|
.slug(options) ⇒ Object
97
98
99
100
|
# File 'lib/octopress-docs.rb', line 97
def self.slug(options)
slug = options[:slug] || options[:name]
options[:type] == 'theme' ? 'theme' : Jekyll::Utils.slugify(slug)
end
|