module Octopress::Ink

Constants

DEFAULT_OPTIONS
VERSION

Public Class Methods

configuration(options={}) click to toggle source
# File lib/octopress-ink/configuration.rb, line 21
def self.configuration(options={})
  @config ||= Jekyll::Utils.deep_merge_hashes(DEFAULT_OPTIONS, Octopress.configuration(options))
end

Public Instance Methods

add_docs(options={}) click to toggle source
# File lib/octopress-ink.rb, line 98
def add_docs(options={})
  Docs.register_docs options
end
add_plugin(options={}) click to toggle source

Create a new plugin from a configuration hash

options - A hash of configuration options.

# File lib/octopress-ink.rb, line 90
def add_plugin(options={})
  register_plugin Plugin, options
end
add_theme(options={}) click to toggle source
# File lib/octopress-ink.rb, line 94
def add_theme(options={})
  register_theme Plugin, options
end
config() click to toggle source
# File lib/octopress-ink.rb, line 108
def config
  @config ||= Configuration.config
end
copy_doc(source, dest, permalink=nil) click to toggle source

Makes it easy for Ink plugins to copy README and CHANGELOG files to doc folder to be used as a documentation asset file

Usage: In rakefile require ‘octopress-ink’

then add task calling Octopress::Ink.copy_doc for each file
# File lib/octopress-ink.rb, line 216
def copy_doc(source, dest, permalink=nil)
  contents = File.open(source).read

  # Convert H1 to title and add permalink in YAML front-matter
  #
  contents.sub!(/^# (.*)$/, "#{doc_yaml('\1', permalink).strip}")

  FileUtils.mkdir_p File.dirname(dest)
  File.open(dest, 'w') {|f| f.write(contents) }
  puts "Updated #{dest} from #{source}"
end
copy_path(name, options) click to toggle source
# File lib/octopress-ink.rb, line 182
def copy_path(name, options)
  if path = options.delete('path')
    full_path = File.join(Dir.pwd, path)
    if !Dir["#{full_path}/*"].empty? && options['force'].nil?
      abort "Error: directory #{path} is not empty. Use --force to overwrite files."
    end
  else
    full_path = File.join(Plugins.custom_dir, name)
  end

  full_path
end
copy_plugin_assets(name, options) click to toggle source
# File lib/octopress-ink.rb, line 162
def copy_plugin_assets(name, options)
  config = options.delete('config') # Jekyll conflicts with this option
  Octopress.site(options)
  Plugins.register
  options['config'] = config if config

  path = copy_path(name, options)

  if p = plugin(name)
    copied = p.copy_asset_files(path, options)
    if !copied.empty?
      puts "Copied files:\n#{copied.join("\n")}"
    else
      puts "No files copied from #{name}."
    end
  else
    not_found(name)
  end
end
enabled?() click to toggle source
# File lib/octopress-ink.rb, line 64
def enabled?
  @load_plugin_assets
end
gem_dir(*subdirs) click to toggle source
# File lib/octopress-ink.rb, line 206
def gem_dir(*subdirs)
  File.expand_path(File.join(File.dirname(__FILE__), '../', *subdirs))
end
list(options={}) click to toggle source

Prints a list of plugins and details

options - a Hash of options from the ‘list` command

Note: if options are empty, this will display a
list of plugin names, slugs, versions, and descriptions,
but no assets, i.e. 'minimal' info.
# File lib/octopress-ink.rb, line 132
def list(options={})
  site = Octopress.site(options)
  Plugins.register
  options = {'minimal'=>true} if options.empty?
  message = "Octopress Ink - v#{VERSION}\n"

  if plugins.size > 0
    plugins.each do |plugin|
      message += plugin.list(options)
    end
  else
    message += "You have no plugins installed."
  end
  puts message
end
list_plugins(options={}) click to toggle source
# File lib/octopress-ink.rb, line 195
def list_plugins(options={})
  Octopress.site(options)
  Plugins.register
  puts "\nCurrently installed plugins:"
  if plugins.size > 0
    plugins.each { |plugin| puts plugin.name + " (#{plugin.slug})" }
  else
    puts "You have no plugins installed."
  end
end
load_plugin_assets=(setting) click to toggle source
# File lib/octopress-ink.rb, line 68
def load_plugin_assets=(setting)
  @load_plguin_assets = setting
end
payload(lang=nil) click to toggle source
# File lib/octopress-ink.rb, line 51
def payload(lang=nil)
  config = Plugins.config(lang)
  ink_payload = {
    'plugins'   => config['plugins'],
    'theme'     => config['theme'],
    'octopress' => {
      'version' => version,
    }
  }

  ink_payload
end
plugin(name) click to toggle source
# File lib/octopress-ink.rb, line 116
def plugin(name)
  begin
    Plugins.plugin(name)
  rescue
  end
end
plugin_list(name, options) click to toggle source
# File lib/octopress-ink.rb, line 148
def plugin_list(name, options)
  config = options.delete('config') # Jekyll conflicts with this option
  Octopress.site(options)
  Octopress.site.read
  Plugins.register
  options['config'] = config if config

  if p = plugin(name)
    puts p.list(options)
  else
    not_found(name)
  end
end
plugins() click to toggle source
# File lib/octopress-ink.rb, line 112
def plugins
  Plugins.plugins
end
register_plugin(plugin, options={}) click to toggle source

Register a new plugin

plugin - A subclass of Plugin

# File lib/octopress-ink.rb, line 76
def register_plugin(plugin, options={})
  options[:type] ||= 'plugin'
  Plugins.register_plugin(plugin, options)
end
register_theme(plugin, options={}) click to toggle source
# File lib/octopress-ink.rb, line 81
def register_theme(plugin, options={})
  options[:type] = 'theme'
  Plugins.register_plugin(plugin, options)
end
version() click to toggle source
# File lib/octopress-ink.rb, line 43
def version
  version = "Jekyll v#{Jekyll::VERSION}, "
  if defined? Octopress::VERSION
    version << "Octopress v#{Octopress::VERSION} "
  end
  version << "Octopress Ink v#{Octopress::Ink::VERSION}"
end
watch_assets(site) click to toggle source
# File lib/octopress-ink.rb, line 102
def watch_assets(site)
  if site.config['ink_watch']
    require 'octopress-ink/watch'
  end
end

Private Instance Methods

doc_yaml(title, permalink) click to toggle source
# File lib/octopress-ink.rb, line 235
def doc_yaml(title, permalink)
  yaml  = "---\n"
  yaml += "title: \"#{title.strip}\"\n"
  yaml += "permalink: #{permalink.strip}\n" if permalink
  yaml += "---"
end
not_found(plugin) click to toggle source
# File lib/octopress-ink.rb, line 230
def not_found(plugin)
  puts "Plugin '#{plugin}' not found."
  list_plugins
end