module Octopress::Deploy

Constants

DEFAULT_OPTIONS
METHODS
VERSION

Public Instance Methods

add_bucket(options={}) click to toggle source
# File lib/octopress-deploy.rb, line 50
def add_bucket(options={})
  options = merge_configs(options)
  get_deployment_method(options).new(options).add_bucket()
end
check_gitignore() click to toggle source

Checks the repository’s .gitignore for the config file

returns: Boolean - whether it is present or not.

# File lib/octopress-deploy.rb, line 131
def check_gitignore
  gitignore = File.join(`git rev-parse --show-toplevel`.strip, ".gitignore")

  if !File.exist?(gitignore) ||
    File.open(gitignore).read.match(/^#{@options[:config_file]}/i).nil?
    puts "Remember to add #{@options[:config_file]} to your .gitignore."
    false
  else
    true
  end
end
deployer(options) click to toggle source
# File lib/octopress-deploy.rb, line 71
def deployer(options)
  get_deployment_method(options).new(options)
end
gem_dir(*subdirs) click to toggle source
# File lib/octopress-deploy.rb, line 143
def gem_dir(*subdirs)
  File.expand_path(File.join(File.dirname(__FILE__), '../', *subdirs))
end
get_config() click to toggle source
# File lib/octopress-deploy.rb, line 118
    def get_config
      <<-FILE
#{"method: #{@options[:method]}".ljust(40)}  # How do you want to deploy? git, rsync or s3.
#{"site_dir: #{@options[:site_dir]}".ljust(40)}  # Location of your static site files.

#{get_deployment_method(@options).default_config(@options)}
FILE
    end
get_deployment_method(options) click to toggle source
# File lib/octopress-deploy.rb, line 75
def get_deployment_method(options)
  METHODS[options[:method].downcase]
end
init_config(options={}) click to toggle source

Create a config file

# File lib/octopress-deploy.rb, line 92
def init_config(options={})
  options = options.to_symbol_keys

  if !options[:method]
    abort "Please provide a deployment method. e.g. #{METHODS.keys}"
  end

  @options = DEFAULT_OPTIONS.deep_merge(options)
  write_config
  check_gitignore
end
load_config(path) click to toggle source
# File lib/octopress-deploy.rb, line 62
def load_config(path)
  if File.exist?(path)
    YAML.load(ERB.new(File.read(path)).result || {}).to_symbol_keys
  else
    abort "File not found: #{options[:config_file]}. Create a deployment config file with `octopress deploy init <METHOD>`."
  end
end
merge_configs(options={}) click to toggle source
# File lib/octopress-deploy.rb, line 55
def merge_configs(options={})
  options = options.to_symbol_keys
  options[:config_file] ||= DEFAULT_OPTIONS[:config_file]

  load_config(options[:config_file]).deep_merge(options)
end
pull(options={}) click to toggle source
# File lib/octopress-deploy.rb, line 36
def pull(options={})
  options = merge_configs(options)

  if Dir.exist?(options[:dir]) &&
      !(Dir.entries(options[:dir]) - %w{. ..}).empty? &&
      !options[:force]
        puts "Pull failed. Directory #{options[:dir]} is not empty. Pass --force to overwrite."
        abort
  else
    FileUtils.mkdir_p options[:dir]
    deployer(options).pull
  end
end
push(options={}) click to toggle source
# File lib/octopress-deploy.rb, line 31
def push(options={})
  options = merge_configs(options)
  deployer(options).push
end
site_dir() click to toggle source
# File lib/octopress-deploy.rb, line 80
def site_dir
  if options[:site_dir]
    options[:site_dir]
  elsif File.exist? '_config.yml'
    SafeYAML.load(File.open('_config.yml'))['site_dir'] || '_site'
  else
    '_site'
  end
end
write_config() click to toggle source
# File lib/octopress-deploy.rb, line 104
def write_config
  if File.exist?(@options[:config_file]) && !@options[:force]
    abort "A config file already exists at #{@options[:config_file]}. Use --force to overwrite."
  end

  config = get_config.strip
  File.open(@options[:config_file], 'w') { |f| f.write(config) }
  puts "File #{@options[:config_file]} created.".green
  puts "------------------"
  puts "#{config.yellow}"
  puts "------------------"
  puts "Modify these configurations as necessary."
end