Class: Octopress::Docs::Commands

Inherits:
Command
  • Object
show all
Defined in:
lib/octopress-docs/command.rb

Class Method Summary collapse

Class Method Details

.init_jekyll_docs(options) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/octopress-docs/command.rb', line 45

def self.init_jekyll_docs(options)
  options.delete('jekyll')

  # Find local Jekyll gem path
  #
  spec = Gem::Specification.find_by_name("jekyll")
  gem_path = spec.gem_dir

  options['source'] = "#{gem_path}/site",
  options['destination'] = "#{gem_path}/site/_site"
  options
end

.init_octopress_docs(options) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/octopress-docs/command.rb', line 34

def self.init_octopress_docs(options)
  Octopress.config({
    'config-file' => File.join(site_dir, '_octopress.yml'),
    'override' => { 'docs_mode' => true }
  })
  require_plugins
  options['source'] = site_dir
  options['destination'] = File.join(site_dir, '_site')
  options
end

.init_with_program(p) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/octopress-docs/command.rb', line 4

def self.init_with_program(p)
  p.command(:docs) do |c|
    c.syntax 'octopress docs'
    c.description "Launch local server with docs for Octopress v#{Octopress::VERSION} and Octopress plugins."

    c.option 'port', '-P', '--port [PORT]', 'Port to listen on'
    c.option 'host', '-H', '--host [HOST]', 'Host to bind to'
    if ENV['OCTODEV']
      c.option 'watch', '--watch', 'Watch docs site for changes and rebuild. (For docs development)'
    end
    c.option 'jekyll', '--jekyll', "Launch local server with docs for Jekyll v#{Jekyll::VERSION}"

    c.action do |args, options|
      serve_docs(options)
    end
  end
end

.plugins_pathObject

Returns an Array of plugin search paths



80
81
82
83
84
85
86
# File 'lib/octopress-docs/command.rb', line 80

def self.plugins_path
  if (Octopress.site.config['plugins'] == Jekyll::Configuration::DEFAULTS['plugins'])
    [Jekyll.sanitized_path(Octopress.site.source, Octopress.site.config['plugins'])]
  else
    Array(Octopress.site.config['plugins']).map { |d| File.expand_path(d) }
  end
end

.require_pluginsObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/octopress-docs/command.rb', line 62

def self.require_plugins
  config = Octopress.site.config

  if config['gems'].is_a?(Array)
    config['gems'].each {|g| require g }
  end

  unless config['safe']
    plugins_path.each do |plugins|
      Dir[File.join(plugins, "**", "*.rb")].sort.each do |f|
        require f
      end
    end
  end
  
end

.serve_docs(options) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/octopress-docs/command.rb', line 22

def self.serve_docs(options)
  if options['jekyll']
    options = init_jekyll_docs(options)
  else
    options = init_octopress_docs(options)
  end
  options["serving"] = true
  options = Jekyll.configuration Jekyll::Utils.symbolize_hash_keys(options)
  Jekyll::Commands::Build.process(options)
  Jekyll::Commands::Serve.process(options)
end

.site_dirObject



58
59
60
# File 'lib/octopress-docs/command.rb', line 58

def self.site_dir
  Docs.gem_dir('docs')
end