lib/octopress-docs.rb in octopress-docs-0.0.8 vs lib/octopress-docs.rb in octopress-docs-0.0.9
- old
+ new
@@ -10,20 +10,39 @@
require "octopress-docs/doc"
require "octopress-docs/tag"
require "octopress-docs/hooks"
module Octopress
+ unless defined? Octopress.site
+ def self.site
+ @site
+ end
+
+ def self.site=(site)
+ @site = site
+ end
+ end
+
module Docs
attr_reader :docs
@docs = {}
+ @docs_mode = false
autoload :Doc, 'octopress-docs/doc'
def self.gem_dir(dir='')
File.expand_path(File.join(File.dirname(__FILE__), '../', dir))
end
+ def self.docs_mode
+ @docs_mode
+ end
+
+ def self.docs_mode=(mode)
+ @docs_mode = mode
+ end
+
# Get all doc pages
#
def self.pages
@docs.values.flatten.map {|d| d.page }
end
@@ -56,18 +75,14 @@
}
end
def self.add_plugin_docs(plugin)
options = plugin_options(plugin)
- plugin_doc_pages = add_asset_docs(options)
+ options[:docs] ||= %w{readme docs}
- # If there is no docs index page, set the reame as the index page
- 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 = add_asset_docs(options)
+ plugin_doc_pages.concat add_root_docs(options, plugin_doc_pages)
plugin_doc_pages
end
def self.plugin_options(plugin)
{
@@ -84,10 +99,11 @@
def self.default_options(options)
options[:type] ||= 'plugin'
options[:slug] = slug(options)
options[:base_url] = base_url(options)
options[:dir] ||= '.'
+ options
end
def self.slug(options)
slug = options[:slug] || options[:name]
options[:type] == 'theme' ? 'theme' : Jekyll::Utils.slugify(slug)
@@ -101,25 +117,30 @@
end
end
def self.add(options)
options[:docs] ||= %w{readme changelog}
+ options = default_options(options)
options[:docs_path] ||= File.join(options[:dir], 'assets', 'docs')
docs = []
- docs.concat add_root_docs(options)
docs.concat add_asset_docs(options)
+ docs.concat add_root_docs(options, docs)
docs.compact!
end
- def self.add_root_docs(options)
+ def self.add_root_docs(options, asset_docs=[])
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)
+ doc_data = {
+ 'title' => doc.capitalize
+ }
+
+ if doc =~ /readme/ && asset_docs.select {|d| d.file =~ /^index/ }.empty?
+ doc_data['permalink'] = '/'
end
+
+ root_docs << add_root_doc(doc, options.merge(data: doc_data))
end
root_docs
end
# Add a single root doc
@@ -127,15 +148,10 @@
if file = select_first(options[:dir], filename)
add_doc_page(options.merge({file: file}))
end
end
- def self.add_root_plugin_doc(plugin, filename, options={})
- options = plugin_options(plugin).merge(options)
- add_root_doc(filename, options)
- end
-
def self.add_doc_page(options)
page = Docs::Doc.new(options)
@docs[options[:slug]] ||= []
@docs[options[:slug]] << page
page
@@ -167,8 +183,7 @@
end
def self.select_first(dir, match)
Dir.new(dir).select { |f| f =~/#{match}/i}.first
end
-
end
end