class Almanack::CLI

Constants

SKIP_THEMES

Public Class Methods

available_themes() click to toggle source
# File lib/almanack/cli.rb, line 13
def self.available_themes
  dirs = Pathname(__dir__).join("themes").children.select(&:directory?)

  dirs.map do |path|
    path.basename.to_s unless SKIP_THEMES.include?(path.basename.to_s)
  end.compact
end
exit_on_failure?() click to toggle source
# File lib/almanack/cli.rb, line 140
def self.exit_on_failure?
  true
end
source_root() click to toggle source
# File lib/almanack/cli.rb, line 144
def self.source_root
  Pathname(__dir__).parent.parent
end

Public Instance Methods

almanack_homepage() click to toggle source
# File lib/almanack/cli.rb, line 115
def almanack_homepage
  Almanack::HOMEPAGE
end
almanack_issues() click to toggle source
# File lib/almanack/cli.rb, line 119
def almanack_issues
  Almanack::ISSUES
end
available_themes() click to toggle source
# File lib/almanack/cli.rb, line 135
def available_themes
  self.class.available_themes
end
create_heroku_app(name) click to toggle source
# File lib/almanack/cli.rb, line 98
def create_heroku_app(name)
  heroku_command = `which heroku`.strip

  if heroku_command.empty?
    say "Heroku Toolbelt not detected. Please install from:"
    say "  https://toolbelt.heroku.com"
    abort
  end

  say_status :heroku, "creating app..."
  run "#{heroku_command} create #{name}"
end
deploy(name = nil) click to toggle source
# File lib/almanack/cli.rb, line 79
def deploy(name = nil)
  remotes = `git remote -v`

  heroku_remote = remotes.lines.find do |remote|
    remote.split(' ').first == "heroku"
  end

  if !heroku_remote
    say "No Heroku remote detected."
    create_heroku_app(name)
  end

  current_branch = git("rev-parse --abbrev-ref HEAD")

  say "Deploying #{current_branch}..."
  run "git push heroku #{current_branch}:master --force"
end
git(command) click to toggle source
# File lib/almanack/cli.rb, line 129
def git(command)
  output = `git #{command}`
  abort "Git failed: #{output}" if $?.exitstatus != 0
  output.strip
end
new(path) click to toggle source
# File lib/almanack/cli.rb, line 35
def new(path)
  @path = Pathname(path).cleanpath

  directory "templates/new", @path

  if options[:git]
    template('templates/gitignore', @path.join(".gitignore"))
  end

  create_file @path.join('tmp/.keep')

  inside @path do
    say_status :installing, "bundler dependencies"
    system "bundle install --quiet"

    if options[:git]
      say_status :git, "initializing repository"
      git "init"
    end

    say
    say "==> Run your new calendar!"
    say
    say "  cd #{@path}"
    say "  almanack start"
    say
  end
end
start() click to toggle source
# File lib/almanack/cli.rb, line 28
def start
  exec "bundle exec rackup #{options[:config]}"
end
theme(name) click to toggle source
# File lib/almanack/cli.rb, line 65
def theme(name)
  directory "lib/almanack/themes/starter", "themes/#{name}"

  config_file = Pathname("config.ru")

  if config_file.exist?
    say_status :update, "config.ru"
    set_theme_pattern = /\.theme\s*=\s*['"].*?['"]/
    replacement = config_file.read.gsub(set_theme_pattern, ".theme = '#{name}'")
    config_file.open('w') { |file| file.puts replacement }
  end
end
theme_name() click to toggle source
# File lib/almanack/cli.rb, line 111
def theme_name
  options[:theme]
end
title() click to toggle source
# File lib/almanack/cli.rb, line 123
def title
  basename = @path.to_s.split('/', 2).last.split('.', 2).first
  sanitized = basename.gsub('-', ' ')
  sanitized.split(/\s+/).map(&:capitalize).join(' ')
end
version() click to toggle source
# File lib/almanack/cli.rb, line 22
def version
  say "Almanack version #{VERSION} (#{CODENAME})"
end