lib/cnote/notes.rb in cnote-0.1.2 vs lib/cnote/notes.rb in cnote-0.1.3

- old
+ new

@@ -1,19 +1,14 @@ -require "ap" require "colorize" require "fileutils" require "time" require "cnote/note" class Notes def initialize(config) @config = config - @notes = Dir[File.join(@config.note_path, "**", "*")].select do |file| - File.extname(file) == ".md" - end.map do |file| - Note.new(file) - end + @notes = Dir[File.join(@config.note_path, "**/*.md")].map { |f| Note.new(f) } @filtered = @notes end #/================================\# # REPL type thing # @@ -160,12 +155,12 @@ def delete(params) num = params.first.to_i note = @filtered[num - 1] - if note - if confirm("You're #{"sure".italic} you want to delete note #{num.to_s.bold.white} with title #{note.title.bold.white}?") + if note and File.exists? note.path + if confirm("You're #{'sure'.italic} you want to delete note #{num.to_s.bold.white} with title #{note.title.bold.white}?") FileUtils.rm(note.path) @notes.delete(note) @filtered.delete(note) puts "Deleted!" else @@ -177,16 +172,19 @@ end def peek(params) note = @filtered[params.first.to_i - 1] if note + lines = note.content.lines puts puts "-" * 40 puts note.title.bold.white - puts note.content.split("\n").slice(0, 10) - puts - puts "... (cont'd) ...".italic.gray + puts lines.slice(0, 15) + if lines.length > 15 + puts + puts "(#{lines.length - 15} more line#{'s' if lines.length != 16}...)".italic + end puts "-" * 40 puts else puts "Note doesn't exist!" end @@ -279,10 +277,10 @@ puts " #{note.path.gsub(@config.note_path, "")}".italic.light_magenta if note.tags.length > 0 tags = note.tags.map { |tag| tag.yellow } puts " tags: " + "[#{tags.join('] [')}]" else - puts " <no tags>".gray + puts " <no tags>" end puts " modified: " + note.modified.strftime("%a, %b %e %Y, %l:%M%P").italic puts " created: " + note.created.strftime("%a, %b %e %Y, %l:%M%P").italic puts end \ No newline at end of file