rb-dayone 0.4.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ .DS_Store
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ tmp
12
+ .ruby-version
13
+
14
+ # YARD artifacts
15
+ .yardoc
16
+ _yardoc
17
+ doc/
18
+
19
+ # Rarity artefacts
20
+ .rarity
data/Gemfile CHANGED
@@ -2,5 +2,4 @@ source :rubygems
2
2
 
3
3
  gem 'builder', '~> 2.0'
4
4
  gem 'commander', '~> 4.1.2'
5
- gem 'libxml-ruby', '~> 2.3.3'
6
5
  gem 'nokogiri', '~> 1.5.0'
data/Gemfile.lock ADDED
@@ -0,0 +1,16 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ builder (2.1.2)
5
+ commander (4.1.2)
6
+ highline (~> 1.6.11)
7
+ highline (1.6.13)
8
+ nokogiri (1.5.6)
9
+
10
+ PLATFORMS
11
+ ruby
12
+
13
+ DEPENDENCIES
14
+ builder (~> 2.0)
15
+ commander (~> 4.1.2)
16
+ nokogiri (~> 1.5.0)
data/Manifest CHANGED
@@ -1,28 +1,22 @@
1
+ # INCLUDE lib/**/*
2
+ # INCLUDE bin/*
3
+ # INCLUDE *
4
+ # EXCLUDE **/.DS_Store
5
+ # EXCLUDE .rarity
6
+ # EXCLUDE .yardopts
7
+
8
+ .gitignore
1
9
  bin/dayone
2
10
  Gemfile
3
- History.rdoc
11
+ Gemfile.lock
4
12
  lib/rb-dayone.rb
5
13
  lib/rb-dayone/entry.rb
6
14
  lib/rb-dayone/entry_importer.rb
15
+ lib/rb-dayone/location.rb
7
16
  lib/rb-dayone/plist_reader.rb
8
17
  lib/rb-dayone/search.rb
9
18
  Manifest
10
19
  Rakefile
11
20
  rb-dayone.gemspec
12
21
  README.md
13
- spec/data/entries/748AD5D252F44149920485B0CEA478E3.doentry
14
- spec/data/entries/F13723CDFD454481B24312DCD627BFD7.doentry
15
- spec/data/foo.doentry
16
- spec/data/locations/location-auto/location
17
- spec/data/locations/location-specified/location
18
- spec/data/locations/location-unspecified
19
- spec/data/sample.doentry
20
- spec/data/sample.plist
21
- spec/data/utf.doentry
22
- spec/dayone_spec.rb
23
- spec/entry_importer_spec.rb
24
- spec/entry_spec.rb
25
- spec/plist_reader_spec.rb
26
- spec/search_spec.rb
27
- spec/spec_helper.rb
28
- version.txt
22
+ version.txt
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # rb-dayone
2
2
 
3
- A means to create DayOne entries in ruby. Also, my first public ruby gem!
3
+ A means to create DayOne entries in ruby.
4
4
 
5
5
  ## Examples
6
6
 
7
- You can create an entry pretty simply, by passing in your entry text:
7
+ You can create an entry pretty simply:
8
8
 
9
9
  e = DayOne::Entry.new "# Hello, world!"
10
10
 
@@ -21,58 +21,110 @@ When you're ready to save your entry, just run the `create!` method:
21
21
 
22
22
  e.create!
23
23
 
24
- Alternatively, run from the command line:
24
+ ## Binary
25
25
 
26
- dayone add --text "#Hello, world" --starred
26
+ Rb-dayone ships with a binary, `dayone`. Run `dayone --help` for instructions on how to use it.
27
27
 
28
- For more information on what you can do from the command line:
28
+ ## Install
29
29
 
30
- dayone --help
30
+ gem install rb-dayone
31
31
 
32
- ### Validating and repairing doentry files ###
32
+ ## Author
33
33
 
34
- As of version 0.2.0 of this gem, `rb-dayone` is finally outputting *nice* XML. Before then, it wasn't. You can check if any of your DayOne entries need repairing by running:
34
+ Original author: [Jan-Yves Ruzicka](http://www.1klb.com). Get in touch [via email](mailto:jan@1klb.com).
35
35
 
36
- dayone validate
36
+ ## History
37
37
 
38
- If they do, you might be able to fix them using:
38
+ ### 0.6.0 / 2013-01-14
39
39
 
40
- dayone repair
40
+ * [NEW] Location support
41
+ * [NEW] Re-added the binary with actual functionality.
42
+ * [FIXED] No longer relies on LibXML - all Nokogiri!
43
+ * [FIXED] Imports times correctly as UTC.
41
44
 
42
- If not, let me know, and I'll see what I can do to fix stuff.
45
+ ### 0.5.0 / 2013-01-09
43
46
 
44
- ## Install
47
+ * [NEW] Added support for tagging entries via `Entry#tag`, `Entry#tags`, and `Entry#add_tags_from_entry_text`.
48
+ * [REMOVED] Got rid of the binary. You can probably make a better library on your own.
45
49
 
46
- gem install rb-dayone
50
+ ## 0.4.1 / 2012-11-14
47
51
 
48
- ## Author
52
+ * [FIXED] rb-dayone was looking in the wrong place for preferences
53
+ * [FIXED] new preference files not json-parseable. Swapped to XML/Nokogiri
49
54
 
50
- Original author: [Jan-Yves Ruzicka](http://www.1klb.com) ([@akchizar](http://www.twitter.com/akchizar)). Get in touch [via email](mailto:janyves.ruzicka@gmail.com).
55
+ ## 0.4.0 / 2012-10-22
51
56
 
52
- ## To do
57
+ * Added image support
53
58
 
54
- * Image support
55
- * Location support?
59
+ ## 0.3.3 / 2012-08-17
60
+
61
+ * [FIXED] LibXML will now accept UTF-8 characters in journal entries.
62
+ * Added the command "repair" to the dayone binary, which will at least repair *my* damage.
63
+ * Added the command "verify" to the dayone binary, which I at least find helpful.
64
+ * Added a post-install note telling people upgrading from <= 0.2.0 to repair.
65
+
66
+ ## 0.3.2 / 2012-08-16
67
+
68
+ * Switched from REXML to LibXML-ruby for XML parsing. Now accepts ampersands in entries, as well as UTF-8. Rejoice!
69
+
70
+ ## 0.3.1 / 2012-08-16
71
+
72
+ * [FIXED] Minor bugfixes
73
+ * [FIXED] REXML will no longer kill the whole program if it can't parse a journal file.
74
+
75
+ ## 0.3.0 / 2012-08-16
76
+
77
+ * [FIXED] Fixed several bugs in Builder xml output, including:
78
+ * Output of trailing <target />
79
+ * Output of malformed DOCTYPE
80
+ * You can now import existing DayOne entries and search them
81
+
82
+ ## 0.2.0 / 2012-08-14
83
+
84
+ * Now auto-detects DayOne journal location from your plist file
56
85
 
57
- ## License
86
+ ## 0.1.7 / 2012-08-13
58
87
 
59
- Copyright (c) 2012 Jan-Yves Ruzicka
88
+ * The dayone binary can now add entries to your journal
89
+ * [FIXED] Managed to break the gem's include in 0.1.6, and because I'm a terrible amateur at all this, didn't pick up on it.
60
90
 
61
- Permission is hereby granted, free of charge, to any person obtaining
62
- a copy of this software and associated documentation files (the
63
- 'Software'), to deal in the Software without restriction, including
64
- without limitation the rights to use, copy, modify, merge, publish,
65
- distribute, sublicense, and/or sell copies of the Software, and to
66
- permit persons to whom the Software is furnished to do so, subject to
67
- the following conditions:
91
+ ## 0.1.6 / 2012-08-13
68
92
 
69
- The above copyright notice and this permission notice shall be
70
- included in all copies or substantial portions of the Software.
93
+ * Updated documentation so YARD would generate nice rdocs
94
+ * dayone binary now uses the Commander gem
95
+ * Now using a Manifest file rather than globbing in whole directories
71
96
 
72
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
73
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
74
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
75
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
76
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
77
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
78
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
97
+ ## 0.1.5 / 2012-08-12
98
+
99
+ * [FIXED] Ouch, horrid horrid gemspec and readme. Let's make them prettier.
100
+
101
+ ## 0.1.4 / 2012-08-12
102
+
103
+ * Added a couple more tests for better coverage
104
+
105
+ ## 0.1.3 / 2012-08-12
106
+
107
+ * Removed the SimpleXML class, now using the Builder gem
108
+
109
+ ## 0.1.2 / 2012-08-12
110
+
111
+ * [FIXED] Actual testing on my own system
112
+
113
+ ## 0.1.1 / 2012-08-07
114
+
115
+ * [FIXED] DayOne constants are now `attr_accessors` - set them yourself if you wish!
116
+
117
+ ## 0.1.0 / 2012-08-06
118
+
119
+ * Added binary
120
+ * Support for DayOne locations
121
+ * Uploaded to github!
122
+
123
+ ## 0.0.1 / 2012-08-05
124
+
125
+ * Started development
126
+
127
+ ## To do
128
+
129
+ * Location support?
130
+ * Switch from using two different XML libraries to one XML library.
data/bin/dayone CHANGED
@@ -1,152 +1,39 @@
1
1
  #!/usr/bin/env ruby
2
- require 'fileutils'
2
+ require 'rb-dayone'
3
3
  require 'commander/import'
4
+ require 'optparse/time'
5
+ require 'time'
4
6
 
5
7
  program :name, 'dayone'
6
- program :version, File.read(File.join(File.dirname(__FILE__),'../version.txt'))
7
- program :description, "Command line interface for the rb-dayone gem"
8
-
9
- dayone_folder = File.join(ENV['HOME'], '.rb-dayone')
10
- dayone_location_file = File.join(dayone_folder, 'location')
11
-
12
- command :set do |c|
13
- c.syntax = "set [key value]"
14
- c.description = "Show or set program settings."
15
- c.summary = <<-end
16
- If sent without arguments, this will show all program settings. If sent with two arguments, this will set <key> to <value>.
17
-
18
- Note: setting location to "auto" will set it from the DayOne plist file.
19
- end
20
-
21
- c.action do |args|
22
- case args.size
23
- when 0
24
- puts "location: #{File.read(dayone_location_file)}"
25
- when 2
26
- key, val = *args
27
- case key
28
- when 'location'
29
- new_dayone_location = (val == 'auto' ? 'auto' : File.expand_path(val))
30
- File.open(dayone_location_file,'w'){ |io| io << new_dayone_location }
31
- puts "#{key}: #{new_dayone_location}"
32
- else
33
- puts "Key #{key} not recognised"
34
- exit 1
35
- end
36
- else
37
- puts c.syntax
38
- puts c.summary
39
- exit 1
40
- end
41
- end
42
- end
43
-
44
- command :add do |c|
45
- c.syntax = "add [--text \"Entry text\"] [--image path/to/image.jpg] [--starred]"
46
- c.description = "Add an entry to your DayOne journal."
47
- c.summary = <<-end
48
- Add an entry to your DayOne journal. By default will add an unstarred entry - use the --starred flag to change this.
49
-
50
- If you don't specify the --text or --image tag, it will read text from STDIN and use this as the journal entry.
51
- end
52
-
53
- c.option "--text STRING", String, "Specify the journal entry text. If not specified, will read from STDIN"
54
- c.option "--starred", "Mark the entry starrd"
55
- c.option "--image path/to/image.jpg", "Add an image to the entry"
56
-
57
- c.action do |args, opts|
58
- require 'rb-dayone'
59
- entry = DayOne::Entry.new
60
-
61
- needs_stdin_help = !(opts.image || opts.text)
62
- if needs_stdin_help
63
- entry.entry_text = $stdin.read.strip
8
+ program :version, DayOne::version
9
+ program :description, 'A binary interface for the rb-dayone gem'
10
+
11
+ command :create do |c|
12
+ c.syntax = 'create [--starred] [--time=TIME] [--image=IMAGE] [--tags=TAGS] [--autotag] [--quiet] [ENTRYTEXT]'
13
+ c.description = "Create a DayOne entry. If you don't supply entry text, it will notify you and fetch it from STDIN."
14
+ c.option '--starred', "Make the entry starred"
15
+ c.option '--time=TIME', Time, "Set the time the entry was made at. Defaults to now."
16
+ c.option '--image=IMAGE', String, "Add an image to the entry, specified by the path."
17
+ c.option '--tags=TAGS', String, "Add tags to the entry. Tags may be comma-separated."
18
+ c.option '--autotag', "Automatically collects #tags from the entry text and populates the tags field of the entry"
19
+ c.option '--quiet', "Don't push feedback to STDOUT."
20
+
21
+ c.action do |args,opts|
22
+ e = DayOne::Entry.new
23
+ e.starred = opts.starred
24
+ e.creation_date = opts.time || Time.now
25
+ e.image = opts.image if opts.image
26
+ e.tags = opts.tags.split(',') if opts.tags
27
+ if args.empty?
28
+ puts "Entry text:" unless opts.quiet
29
+ e.entry_text = $stdin.read.strip
64
30
  else
65
- entry.entry_text = opts.text if opts.text
66
-
67
- if opts.image
68
- if File.exists? opts.image
69
- entry.image = opts.image
70
- else
71
- puts "Can't find image: #{opts.image}"
72
- exit 1
73
- end
74
- end
31
+ # puts "Creating entry, "
32
+ e.entry_text = args.shift
75
33
  end
76
34
 
77
- entry.starred = opts.starred
78
-
79
- entry.create!
80
- end
81
- end
82
-
83
- command :repair do |c|
84
- c.syntax = "repair"
85
- c.description = "Will repair any damage caused by previous versions of rb-dayone."
86
- c.summary = "This command will trawl your DayOne journal archive looking for any malformed DayOne entries created by previous versions of rb-dayone, and will fix them. Currently it fixed malformed doctype declarations and trailing target tags."
87
-
88
- c.action do |args, opts|
89
- require 'rb-dayone'
90
-
91
- repairs = {
92
- 'trailing target' => [
93
- /<target\/>\Z/,
94
- ''
95
- ],
96
- 'malformed doctype' => [
97
- %r|<!DOCTYPE "plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"">|,
98
- %|<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">|
99
- ]
100
- }
101
-
102
- DayOne.entries.each do |f|
103
- contents = File.read(f)
104
- modified = []
105
- repairs.each do |name, (replace_this, with_this)|
106
- if replace_this === contents
107
- modified << name
108
- contents = contents.gsub(replace_this, with_this)
109
- end
110
- end
111
-
112
- unless modified.empty?
113
- File.open(f,'w'){ |io| io.puts contents }
114
- puts "Repaired file #{f}:"
115
- modified.each{ |s| puts " Fixed #{s}" }
116
- end
117
- end
118
- puts "All files have been repaired!"
119
- end
120
- end
121
-
122
- command :validate do |c|
123
- c.syntax = "validate"
124
- c.description = "Checks through your DayOne database to see if any of your journal entries break XML validation."
125
-
126
- c.action do
127
- require 'libxml'
128
- require 'rb-dayone'
129
-
130
- LibXML::XML::Error.set_handler(&LibXML::XML::Error::QUIET_HANDLER)
131
- failed_entries = []
132
-
133
- all_entries = DayOne.entries
134
- puts "Checking #{all_entries.size} entr#{all_entries.size == 1 ? 'y' : 'ies'}..."
135
-
136
- all_entries.each do |f|
137
- begin
138
- contents = File.read(f)
139
- LibXML::XML::Parser.string(contents).parse
140
- rescue LibXML::XML::Error
141
- failed_entries << f
142
- end
143
- end
144
-
145
- if failed_entries.empty?
146
- puts "No errors. Everything is OK!"
147
- else
148
- puts "#{failed_entries.size} error#{failed_entries.size == 1 ? '' : 's'} in validation:"
149
- failed_entries.each{ |f| puts " #{f}" }
150
- end
35
+ e.add_tags_from_entry_text if opts.autotag
36
+ e.create!
37
+ puts "Entry created" unless opts.quiet
151
38
  end
152
39
  end
data/lib/rb-dayone.rb CHANGED
@@ -1,5 +1,9 @@
1
1
  require 'time'
2
2
  require 'builder'
3
+ require 'nokogiri'
4
+ require 'fileutils'
5
+
6
+ lib_root = File.dirname(__FILE__)
3
7
 
4
8
  # This module contains all classes used in the DayOne gem,
5
9
  # as well as some helper methods
@@ -20,19 +24,16 @@ module DayOne
20
24
  # will set from the DayOne plist (See +auto_journal_location+).
21
25
  # @return [String] the DayOne journal location
22
26
  def journal_location
23
- if !@journal_location
24
- if File.exists?(journal_file)
25
- contents = File.read(journal_file)
26
- @journal_location = if contents == 'auto'
27
- auto_journal_location
28
- else
29
- contents
30
- end
27
+ @journal_location ||= if File.exists?(journal_file)
28
+ contents = File.read(journal_file)
29
+ if contents == 'auto'
30
+ auto_journal_location
31
31
  else
32
- @journal_location = auto_journal_location
32
+ contents
33
33
  end
34
+ else
35
+ auto_journal_location
34
36
  end
35
- @journal_location
36
37
  end
37
38
 
38
39
  # The location of the DayOne journal file as determined by
@@ -47,9 +48,13 @@ module DayOne
47
48
  def entries
48
49
  Dir[File.join(journal_location, 'entries','*.doentry')]
49
50
  end
51
+
52
+ def version
53
+ @version ||= File.read(File.join(File.dirname(__FILE__),'..','version.txt'))
54
+ end
50
55
 
51
56
  private
52
-
57
+
53
58
  # The journal file location
54
59
  # @return [String] the location of the journal file
55
60
  def journal_file
@@ -58,7 +63,7 @@ module DayOne
58
63
  end
59
64
  end
60
65
 
61
- lib_root = File.dirname(__FILE__)
66
+
62
67
  Dir[File.join(lib_root, "rb-dayone", "*.rb")].each{ |f| require f }
63
68
 
64
69
  # Default values