Class: Retter::Command

Inherits:
Thor
  • Object
show all
Includes:
Site
Defined in:
lib/retter/command.rb

Instance Method Summary collapse

Methods included from Site

#config, #entries, #load, #reset!

Methods included from Configurable

#configurable, #define_configurable_method, #define_instance_shortcut_method

Instance Method Details

#callbackObject



101
102
103
# File 'lib/retter/command.rb', line 101

def callback
  invoke_after options[:after].intern
end

#cleanObject



84
85
86
87
88
# File 'lib/retter/command.rb', line 84

def clean
  return unless config.cache.respond_to?(:clear)

  config.cache.clear
end

#commitObject



65
66
67
68
69
70
71
72
# File 'lib/retter/command.rb', line 65

def commit
  Repository.open config.retter_home do |git|
    say git.add(config.retter_home), :green
    say git.commit_all('Retter commit'), :green
  end

  invoke_after :commit
end

#edit(identifier = options[:date] || options[:key]) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/retter/command.rb', line 20

def edit(identifier = options[:date] || options[:key])
  entry = entries.detect_by_string(identifier)

  system config.editor, entry.path.to_path

  invoke_after :edit
end

#homeObject



91
92
93
94
95
96
97
# File 'lib/retter/command.rb', line 91

def home
  Dir.chdir config.retter_home.to_path

  system config.shell

  say 'bye', :green
end

#listObject



75
76
77
78
79
80
81
# File 'lib/retter/command.rb', line 75

def list
  entries.each_with_index do |entry, n|
    say "[e#{n}] #{entry.date}"
    say "  #{entry.articles.map(&:title).join(', ')}"
    say
  end
end

#newObject



106
# File 'lib/retter/command.rb', line 106

def new; end

#openObject



42
43
44
45
46
# File 'lib/retter/command.rb', line 42

def open
  index_page = Page::Index.new

  Launchy.open index_page.path.to_path
end

#preview(identifier = options[:date] || options[:key]) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/retter/command.rb', line 32

def preview(identifier = options[:date] || options[:key])
  preprint = Preprint.new
  entry    = entries.detect_by_string(identifier)

  preprint.bind entry

  Launchy.open preprint.path.to_path
end

#rebindObject Also known as: bind



50
51
52
53
54
55
56
57
# File 'lib/retter/command.rb', line 50

def rebind
  entries.commit_wip_entry!

  Binder.new(entries).bind!

  invoke_after :bind
  invoke_after :rebind
end

#usageObject



109
110
111
# File 'lib/retter/command.rb', line 109

def usage
  say Command.usage, :green
end

#versionObject



114
115
116
# File 'lib/retter/command.rb', line 114

def version
  say "Retter version #{VERSION}"
end