class Octopress::Docs::Doc

Attributes

base_url[R]
description[R]
filename[R]
plugin_name[R]
plugin_slug[R]
plugin_type[R]
source_url[R]

Public Class Methods

new(options={}) click to toggle source
# File lib/octopress-docs/doc.rb, line 6
def initialize(options={})
  @file            = options[:file]
  @path            = options[:path] ||= '.'
  @file_dir        = File.dirname(@file)
  @plugin_name     = options[:name]
  @plugin_slug     = options[:slug]
  @plugin_type     = options[:type]
  @base_url        = options[:base_url]
  @source_url      = options[:source_url]
  @description     = options[:description]
  @data            = options[:data] || {}
end

Public Instance Methods

add() click to toggle source

Add doc page to Jekyll pages

# File lib/octopress-docs/doc.rb, line 21
def add
  Octopress.site.pages << page
end
disabled?() click to toggle source
# File lib/octopress-docs/doc.rb, line 25
def disabled?
  false
end
file() click to toggle source
# File lib/octopress-docs/doc.rb, line 29
def file
  File.basename(@file)
end
info() click to toggle source
# File lib/octopress-docs/doc.rb, line 33
def info
  "  - #{permalink.ljust(35)}"
end
page() click to toggle source
# File lib/octopress-docs/doc.rb, line 37
def page
  @page ||= begin
    p = Octopress::Docs::Page.new(Octopress.site, @path, page_dir, file, {'path'=>@base_url})
    p.data['layout'] = 'docs'
    p.data['escape_code'] = true

    p.data['plugin'] = { 
      'name'        => @plugin_name, 
      'slug'        => @plugin_slug,
      'type'        => @plugin_type,
      'source_url'  => @source_url,
      'description' => @description,
      'url'         => @base_url
    }

    p.data['dir'] = doc_dir
    p.data = @data.merge(p.data)
    p.data.merge!(comment_yaml(p.content))
    p
  end
end

Private Instance Methods

comment_yaml(content) click to toggle source
# File lib/octopress-docs/doc.rb, line 81
def comment_yaml(content)
  if content =~ /<!-{3}\s+(.+)?-{3}>/m
    SafeYAML.load($1)
  else
    {}
  end
end
doc_dir() click to toggle source
# File lib/octopress-docs/doc.rb, line 77
def doc_dir
  File.join(@path, page_dir, File.dirname(@file))
end
page_dir() click to toggle source
# File lib/octopress-docs/doc.rb, line 73
def page_dir
  @file_dir == '.' ? '' : @file_dir
end
read() click to toggle source
# File lib/octopress-docs/doc.rb, line 65
def read
  File.open(File.join(@path, @file)).read
end