octopress-docs 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e40b0a59fde57b0e5436076083f368276f0d240e
4
- data.tar.gz: 99c0393286971084bd5c27d5bc8d66de128c471f
3
+ metadata.gz: 05c977ae69bac6575c3cdb60de74d2cf97a7bee7
4
+ data.tar.gz: d35af90cad7c439f4cdf8d74291d5991c0e96db1
5
5
  SHA512:
6
- metadata.gz: 780a883f9b27afd456bca8f3454f6810bad1a738152276bfec751680e00e6730c4c621e84a347a092927a2743dc32b40ebafa5a4ce014c638f754cdaccd6ae7e
7
- data.tar.gz: 3874da1c6823efc2f33ee128f0f0a8e96349a70211dd97ba522fe4d866ea0fec00b6150470f4a10e9f850f6dd2f80df8d3a435d14efe29ed1834f738db69db8d
6
+ metadata.gz: 1daeb7c34ff8e14d2851596368a6a5097f531279938984b031727a539d7b8846805d33ff57525846db7f4823eada5bda9438665fb25601f1f3f6204e7097d8c7
7
+ data.tar.gz: e1a3d5b71f3c10ce2a2a06a7eeed2dfeff050b72d39b5c9e5b0f2f170df7242cfc94dd8b7dd84f446d4250cef2a6632a3a9058b7b48bdbb8544d58883e01d3f1
data/README.md CHANGED
@@ -18,16 +18,17 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- Automatically add your Readme and Changelog files:
21
+ Automatically add your Readme and Changelog files along with any pages in your gem path under `/assets/docs`.
22
22
 
23
23
  ```ruby
24
24
  begin
25
25
  require 'octopress-docs'
26
26
  Octopress::Docs.add({
27
27
  name: "Your Plugin",
28
- dir: File.expand_path(File.join(File.dirname(__FILE__), "../../")),
28
+ slug: "your-plugin",
29
+ dir: File.expand_path(File.join(File.dirname(__FILE__), "../../"))
29
30
  })
30
- rescue
31
+ rescue LoadError
31
32
  end
32
33
  ```
33
34
 
@@ -7,7 +7,7 @@ layout: default
7
7
  <h4>{{ page.plugin.name }} Doc Pages</h4>
8
8
  <nav role='navigation'>
9
9
  <ul>
10
- {% for doc in doc_pages[page.plugin.slug].pages %}
10
+ {% for doc in plugin_docs[page.plugin.slug].docs %}
11
11
  <li><a href="{{ doc.url }}">{{ doc.title }}</a></li>
12
12
  {% endfor %}
13
13
  </ul>
data/docs/index.html CHANGED
@@ -3,9 +3,9 @@ layout: default
3
3
  ---
4
4
 
5
5
  {% for plugin in plugin_docs %}
6
- <h4>{{ plugin.name }}</h4>
6
+ <h4>{{ plugin[1].name }}</h4>
7
7
  <ul>
8
- {% for doc in plugin.docs %}
8
+ {% for doc in plugin[1].docs %}
9
9
  <li><a href="{{ doc.url }}">{{ doc.title }}</a></li>
10
10
  {% endfor %}
11
11
  </ul>
@@ -36,7 +36,7 @@ module Octopress
36
36
  'config-file' => File.join(site_dir, '_octopress.yml'),
37
37
  'override' => { 'docs_mode' => true }
38
38
  })
39
- require_gems
39
+ require_plugins
40
40
  options['source'] = site_dir
41
41
  options['destination'] = File.join(site_dir, '_site')
42
42
  options
@@ -59,16 +59,32 @@ module Octopress
59
59
  Docs.gem_dir('docs')
60
60
  end
61
61
 
62
- def self.require_gems
63
- file = File.join(Dir.pwd, '_config.yml')
64
- if File.exist? file
65
- config = YAML.safe_load(File.open(file))
66
- gems = config['gems']
67
- if gems && gems.is_a?(Array)
68
- gems.each {|g| require g }
62
+ def self.require_plugins
63
+ config = Octopress.site.config
64
+
65
+ if config['gems'].is_a?(Array)
66
+ config['gems'].each {|g| require g }
67
+ end
68
+
69
+ unless config['safe']
70
+ plugins_path.each do |plugins|
71
+ Dir[File.join(plugins, "**", "*.rb")].sort.each do |f|
72
+ require f
73
+ end
69
74
  end
70
75
  end
76
+
77
+ end
78
+
79
+ # Returns an Array of plugin search paths
80
+ def self.plugins_path
81
+ if (Octopress.site.config['plugins'] == Jekyll::Configuration::DEFAULTS['plugins'])
82
+ [Jekyll.sanitized_path(Octopress.site.source, Octopress.site.config['plugins'])]
83
+ else
84
+ Array(Octopress.site.config['plugins']).map { |d| File.expand_path(d) }
85
+ end
71
86
  end
87
+
72
88
  end
73
89
  end
74
90
  end
@@ -1,15 +1,15 @@
1
1
  module Octopress
2
2
  module Docs
3
3
  class Doc
4
- attr_reader :filename, :plugin_name
4
+ attr_reader :filename, :plugin_name, :base_url
5
5
 
6
6
  def initialize(options={})
7
7
  @file = options[:file]
8
8
  @dir = options[:dir] ||= '.'
9
9
  @file_dir = File.dirname(@file)
10
10
  @plugin_name = options[:name]
11
- @plugin_slug ||= options[:slug] || @plugin_name
12
- @plugin_type = options[:type] || 'plugin'
11
+ @plugin_slug = options[:slug]
12
+ @plugin_type = options[:type]
13
13
  @base_url = options[:base_url]
14
14
  @index = options[:index]
15
15
  end
@@ -36,26 +36,18 @@ module Octopress
36
36
 
37
37
  def page
38
38
  return @page if @page
39
- @page = Octopress::Ink::Page.new(Octopress.site, @dir, page_dir, file, {'path'=>base_url})
39
+ @page = Octopress::Docs::Page.new(Octopress.site, @dir, page_dir, file, {'path'=>@base_url})
40
40
  @page.data['layout'] = 'docs'
41
41
  @page.data['plugin'] = {
42
42
  'name' => @plugin_name,
43
43
  'slug' => plugin_slug,
44
- 'docs_base_url' => base_url
44
+ 'docs_base_url' => @base_url
45
45
  }
46
46
  @page.data['dir'] = doc_dir
47
47
  @page.data['permalink'] = "/" if @index
48
48
  @page
49
49
  end
50
50
 
51
- def base_url
52
- @base_url || if @plugin_type == 'theme'
53
- File.join('docs', 'theme')
54
- else
55
- File.join('docs', 'plugins', @plugin_slug)
56
- end
57
- end
58
-
59
51
  private
60
52
 
61
53
  def permalink
@@ -1,7 +1,7 @@
1
1
  module Octopress
2
2
  module Docs
3
3
  class DocsSiteHook < Octopress::Hooks::Site
4
- def post_read(site)
4
+ def pre_render(site)
5
5
  if Octopress.config['docs_mode']
6
6
  site.pages.concat Octopress::Docs.pages
7
7
  end
@@ -0,0 +1,56 @@
1
+ module Octopress
2
+ module Docs
3
+ class Page < Jekyll::Page
4
+ include Jekyll::Convertible
5
+
6
+ # Purpose: Configs can override a page's permalink
7
+ #
8
+ # url - Path relative to destination directory.
9
+ # examples:
10
+ # - '/' for the _site/index.html page
11
+ # - '/archive/' for the _site/archive/index.html page
12
+ #
13
+ def initialize(site, base, dir, name, config={})
14
+ @config = config
15
+ super(site, base, dir, name)
16
+ post_init if respond_to?(:post_init)
17
+ end
18
+
19
+ def hooks
20
+ self.site.page_hooks
21
+ end
22
+
23
+ def destination(dest)
24
+ unless @dest
25
+ if @config['path']
26
+ dest = File.join(dest, @config['path'])
27
+ end
28
+ @dest = File.join(dest, self.url)
29
+ end
30
+ @dest
31
+ end
32
+
33
+ def relative_asset_path
34
+ site_source = Pathname.new Octopress.site.source
35
+ page_source = Pathname.new @base
36
+ page_source.relative_path_from(site_source).to_s
37
+ end
38
+
39
+ # Allow pages to read url from plugin configuration
40
+ #
41
+ def url
42
+ unless @url
43
+ super
44
+
45
+ if @url && @url =~ /\/$/
46
+ ext = (self.ext == '.xml'? 'xml' : 'html')
47
+ @url = File.join(@url, "index.#{ext}")
48
+ end
49
+ end
50
+
51
+ @url
52
+ end
53
+ end
54
+ end
55
+ end
56
+
@@ -1,5 +1,5 @@
1
1
  module Octopress
2
2
  module Docs
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
@@ -2,9 +2,11 @@ require "octopress"
2
2
  require "jekyll"
3
3
  require "octopress-escape-code"
4
4
  require "octopress-hooks"
5
+ require "find"
5
6
 
6
7
  require "octopress-docs/version"
7
8
  require "octopress-docs/command"
9
+ require "octopress-docs/page"
8
10
  require "octopress-docs/doc"
9
11
  require "octopress-docs/tag"
10
12
  require "octopress-docs/hooks"
@@ -27,14 +29,15 @@ module Octopress
27
29
  end
28
30
 
29
31
  def self.pages_info
30
- plugin_docs = []
31
- @docs.keys.each { |slug|
32
- plugin_docs << {
33
- "name" => @docs[slug].first.plugin_name,
34
- "docs" => plugin_docs(@docs[slug])
32
+ docs = @docs.clone
33
+ docs.each { |slug, pages|
34
+ docs[slug] = {
35
+ "name" => pages.first.plugin_name,
36
+ "docs" => plugin_docs(pages)
35
37
  }
36
38
  }
37
- { 'plugin_docs' => plugin_docs }
39
+
40
+ { 'plugin_docs' => docs }
38
41
  end
39
42
 
40
43
  def self.plugin_docs(pages)
@@ -53,20 +56,23 @@ module Octopress
53
56
  }
54
57
  end
55
58
 
56
- def self.add_plugin_docs(plugin, dir, files)
57
- pages = []
58
- options = plugin_options(plugin).merge({
59
- dir: File.join(plugin.assets_path, dir),
60
- })
61
-
62
- files.each do |doc|
59
+ def self.add_plugin_docs(plugin)
60
+ plugin_doc_pages = []
61
+ options = plugin_options(plugin)
62
+ find_doc_pages(options).each do |doc|
63
63
  unless doc =~ /^_/
64
- opts = options.merge({file: doc})
65
- pages << add_doc_page(opts)
64
+ opts = options.merge({file: doc, dir: options[:docs_path]})
65
+ plugin_doc_pages << add_doc_page(opts)
66
66
  end
67
67
  end
68
68
 
69
- pages
69
+ # If there is no docs index page, set the reame as the index page
70
+ has_index = !plugin_doc_pages.select {|d| d.file =~ /^index/ }.empty?
71
+ plugin_doc_pages << add_root_plugin_doc(plugin, 'readme', index: !has_index)
72
+
73
+ plugin_doc_pages << add_root_plugin_doc(plugin, 'changelog')
74
+
75
+ plugin_doc_pages
70
76
  end
71
77
 
72
78
  def self.plugin_options(plugin)
@@ -74,15 +80,43 @@ module Octopress
74
80
  name: plugin.name,
75
81
  slug: plugin.slug,
76
82
  type: plugin.type,
77
- base_url: plugin.docs_base_url,
78
- dir: plugin.path
83
+ base_url: plugin.docs_url,
84
+ dir: plugin.path,
85
+ docs_path: File.join(plugin.assets_path, 'docs'),
86
+ docs: %w{readme changelog}
79
87
  }
80
88
  end
81
89
 
90
+ def self.default_options(options)
91
+ options[:type] ||= 'plugin'
92
+ options[:slug] = slug(options)
93
+ options[:base_url] = base_url(options)
94
+ options[:dir] ||= '.'
95
+ end
96
+
97
+ def self.slug(options)
98
+ slug = options[:slug] || options[:name]
99
+ options[:type] == 'theme' ? 'theme' : Jekyll::Utils.slugify(slug)
100
+ end
101
+
102
+ def self.base_url(options)
103
+ options[:base_url] || if options[:type] == 'theme'
104
+ File.join('docs', 'theme')
105
+ else
106
+ File.join('docs', 'plugins', options[:slug])
107
+ end
108
+ end
109
+
82
110
  def self.add(options)
111
+ options[:docs] ||= %w{readme changelog}
112
+ options[:docs_path] ||= File.join(options[:dir], 'assets', 'docs')
113
+ docs = []
114
+ docs.concat add_root_docs(options)
115
+ docs.concat
116
+ end
83
117
 
118
+ def self.add_root_docs(options)
84
119
  root_docs = []
85
- options[:docs] ||= %w{readme changelog}
86
120
  options[:docs].each do |doc|
87
121
  if doc =~ /readme/
88
122
  root_docs << add_root_doc(doc, options.merge({index: true}))
@@ -102,6 +136,8 @@ module Octopress
102
136
 
103
137
  def self.add_root_plugin_doc(plugin, filename, options={})
104
138
  options = plugin_options(plugin).merge(options)
139
+
140
+ require 'pry-byebug'; binding.pry
105
141
  add_root_doc(filename, options)
106
142
  end
107
143
 
@@ -112,8 +148,23 @@ module Octopress
112
148
  page
113
149
  end
114
150
 
151
+ private
152
+
153
+ def self.find_doc_pages(options)
154
+ full_dir = options[:docs_path]
155
+ glob_assets(full_dir).map do |file|
156
+ file.sub(full_dir+'/', '')
157
+ end
158
+ end
159
+
160
+ def self.glob_assets(dir)
161
+ return [] unless Dir.exist? dir
162
+ Find.find(dir).to_a.reject {|f| File.directory? f }
163
+ end
164
+
115
165
  def self.select_first(dir, match)
116
166
  Dir.new(dir).select { |f| f =~/#{match}/i}.first
117
167
  end
168
+
118
169
  end
119
170
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octopress-docs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Mathis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-15 00:00:00.000000000 Z
11
+ date: 2014-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.0'
27
- - !ruby/object:Gem::Dependency
28
- name: octopress
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: 3.0.0.rc
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: 3.0.0.rc
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: octopress-hooks
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +58,14 @@ dependencies:
72
58
  requirements:
73
59
  - - "~>"
74
60
  - !ruby/object:Gem::Version
75
- version: '1.3'
61
+ version: '1.6'
76
62
  type: :development
77
63
  prerelease: false
78
64
  version_requirements: !ruby/object:Gem::Requirement
79
65
  requirements:
80
66
  - - "~>"
81
67
  - !ruby/object:Gem::Version
82
- version: '1.3'
68
+ version: '1.6'
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: rake
85
71
  requirement: !ruby/object:Gem::Requirement
@@ -129,6 +115,7 @@ files:
129
115
  - lib/octopress-docs/command.rb
130
116
  - lib/octopress-docs/doc.rb
131
117
  - lib/octopress-docs/hooks.rb
118
+ - lib/octopress-docs/page.rb
132
119
  - lib/octopress-docs/tag.rb
133
120
  - lib/octopress-docs/version.rb
134
121
  homepage: https://github.com/octopress/docs