Module: Diary::CLI::Commands
- Included in:
- Diary::CLI
- Defined in:
- lib/diary/cli/commands.rb,
lib/diary/cli/commands/edit.rb,
lib/diary/cli/commands/init.rb,
lib/diary/cli/commands/sync.rb,
lib/diary/cli/commands/server.rb,
lib/diary/cli/commands/compile.rb,
lib/diary/cli/commands/new_item.rb
Instance Method Summary collapse
- #command(*args) ⇒ Object
- #compile(args, options) ⇒ Object
- #edit(args, options) ⇒ Object
- #init(args, options) ⇒ Object
- #new(args, options) ⇒ Object
- #server(args, options) ⇒ Object
- #sync(args, options) ⇒ Object
Instance Method Details
#command(*args) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/diary/cli/commands.rb', line 8 def command(*args) = Diary::CLI.parse(args) if args.size == 0 return end if respond_to?(args.first) self.send(args.shift, args, ) elsif Diary. :error, "No command found", :red end end |
#compile(args, options) ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/diary/cli/commands/compile.rb', line 4 def compile(args, ) if (args.first == "all") or (args.size == 0) Post.all.each { |p| p.output(.force) } Page.all.each { |p| p.output(.force) } elsif args.size >= 2 const_get(args.shift.capitalize).find(args.first).output(.force) else const_get(args.shift.capitalize).all.each { |p| p.output(.force) } end end |
#edit(args, options) ⇒ Object
4 5 6 |
# File 'lib/diary/cli/commands/edit.rb', line 4 def edit(args, ) `#{editor} #{const_get(args.shift.capitalize).find(args.first).path}` end |
#init(args, options) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/diary/cli/commands/init.rb', line 4 def init(args, ) # Create directories %w{ templates posts pages snippets public }.each do |directory| create_dir directory end # Create files create_file "templates/index.html.erb", "<%= content %>" create_file "config.yml", "sync:\n user: \n server: \n path: \n" unless File.exists?(".git") if .git Diary. :git, "Initial commit", :magenta init_git! else Diary. :skip, "git init", :red end else Diary. :git, "Already a git repository", :yellow end end |
#new(args, options) ⇒ Object
4 5 6 |
# File 'lib/diary/cli/commands/new_item.rb', line 4 def new(args, ) const_get(args.shift.capitalize).create(args.first) end |
#server(args, options) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/diary/cli/commands/server.rb', line 4 def server(args, ) Diary. :start, "Diary server is starting...", :green `ruby #{File.("../../../server.rb", __FILE__)}` rescue Interrupt Diary. :close, "Diary server is closing...", :red sleep(2) end |
#sync(args, options) ⇒ Object
4 5 6 7 |
# File 'lib/diary/cli/commands/sync.rb', line 4 def sync(args, ) Diary. :sync, sync_path, :magenta `rsync --verbose --progress --stats --compress --recursive --times --perms --links --delete --exclude "*bak" ./public/* #{sync_path}` end |