class Cheatly::CLI

Public Instance Methods

create(handle) click to toggle source
# File lib/cheatly/cli.rb, line 47
def create(handle)
  sheet = LocalSheet.new(handle)
  sheet.body = write_to_tempfile(handle)
  sheet.save
end
edit(handle) click to toggle source
# File lib/cheatly/cli.rb, line 54
def edit(handle)
  sheet = LocalSheet.find(handle)
  sheet.body = write_to_tempfile(handle, sheet.body)
  sheet.save
end
help() click to toggle source
# File lib/cheatly/cli.rb, line 61
def help
  show('help')
end
list() click to toggle source
# File lib/cheatly/cli.rb, line 34
def list
  sheets = model.all
  page unless options[:nopaginate]
  puts "List of available cheat-sheets:"
  sheets.each do |sheet|
    puts "  #{sheet.title}"
  end
end
Also aliased as: ls
ls()
Alias for: list
show(handle) click to toggle source
# File lib/cheatly/cli.rb, line 21
def show(handle)
  sheet = model.find(handle)
  unless sheet
    puts "Sheet not found, run 'cheatly list' to see the availables."
    return
  end
  page unless options[:nopaginate]
  renderer = Renderer.new
  md = Redcarpet::Markdown.new(renderer, no_intra_emphasis: true)
  puts md.render(sheet.to_s)
end
version() click to toggle source
# File lib/cheatly/cli.rb, line 66
def version
  puts "Cheatly version #{Cheatly::VERSION}"
end

Private Instance Methods

editor() click to toggle source
# File lib/cheatly/cli.rb, line 92
def editor
  ENV['VISUAL'] || ENV['EDITOR'] || "nano"
end
model() click to toggle source
# File lib/cheatly/cli.rb, line 73
def model
  if options[:local]
    LocalSheet
  else
    Sheet
  end
end
write_to_tempfile(title, body = nil) click to toggle source
# File lib/cheatly/cli.rb, line 81
def write_to_tempfile(title, body = nil)
  tempfile = Tempfile.new(title + '.md')
  tempfile.write(body) if body
  tempfile.close
  system "#{editor} #{tempfile.path}"
  tempfile.open
  body = tempfile.read
  tempfile.close
  body
end