Module: Octopress::Deploy

Defined in:
lib/octopress-deploy.rb,
lib/octopress-deploy/s3.rb,
lib/octopress-deploy/git.rb,
lib/octopress-deploy/rsync.rb,
lib/octopress-deploy/version.rb,
lib/octopress-deploy/commands.rb

Defined Under Namespace

Classes: Commands, Git, Rsync, S3

Constant Summary collapse

METHODS =
{
  'git'   => Git,
  'rsync' => Rsync,
  's3'    => S3
}
DEFAULT_OPTIONS =
{
  :config_file => '_deploy.yml',
  :site_dir => '_site',
}
VERSION =
"1.2.1"

Class Method Summary collapse

Class Method Details

.add_bucket(options = {}) ⇒ Object



48
49
50
51
# File 'lib/octopress-deploy.rb', line 48

def self.add_bucket(options={})
  options = merge_configs(options)
  get_deployment_method(options).new(options).add_bucket()
end

.check_config(options = {}) ⇒ Object



59
60
61
62
63
64
65
66
67
68
# File 'lib/octopress-deploy.rb', line 59

def self.check_config(options={})
  options = options.to_symbol_keys
  options[:config_file] ||= DEFAULT_OPTIONS[:config_file]

  if !File.exists? options[:config_file]
    abort "File not found: #{options[:config_file]}. Create a deployment config file with `octopress deploy init <METHOD>`."
  end

  options
end

.check_gitignoreObject

Checks the repository’s .gitignore for the config file

returns: Boolean - whether it is present or not.



130
131
132
133
134
135
136
137
138
139
140
# File 'lib/octopress-deploy.rb', line 130

def self.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) ⇒ Object



70
71
72
# File 'lib/octopress-deploy.rb', line 70

def self.deployer(options)
  get_deployment_method(options).new(options)
end

.gem_dir(*subdirs) ⇒ Object



142
143
144
# File 'lib/octopress-deploy.rb', line 142

def self.gem_dir(*subdirs)
  File.expand_path(File.join(File.dirname(__FILE__), '../', *subdirs))
end

.get_configObject



117
118
119
120
121
122
123
124
# File 'lib/octopress-deploy.rb', line 117

def self.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) ⇒ Object



74
75
76
# File 'lib/octopress-deploy.rb', line 74

def self.get_deployment_method(options)
  METHODS[options[:method].downcase]
end

.init_config(options = {}) ⇒ Object

Create a config file



91
92
93
94
95
96
97
98
99
100
101
# File 'lib/octopress-deploy.rb', line 91

def self.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

.merge_configs(options = {}) ⇒ Object



53
54
55
56
57
# File 'lib/octopress-deploy.rb', line 53

def self.merge_configs(options={})
  options = check_config(options)
  config  = SafeYAML.load(File.open(options[:config_file])).to_symbol_keys
  options = config.deep_merge(options)
end

.pull(options = {}) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/octopress-deploy.rb', line 34

def self.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 = {}) ⇒ Object



29
30
31
32
# File 'lib/octopress-deploy.rb', line 29

def self.push(options={})
  options = merge_configs(options)
  deployer(options).push
end

.site_dirObject



79
80
81
82
83
84
85
86
87
# File 'lib/octopress-deploy.rb', line 79

def self.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_configObject



103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/octopress-deploy.rb', line 103

def self.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