rb-dayone 0.4.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +20 -0
- data/Gemfile +0 -1
- data/Gemfile.lock +16 -0
- data/Manifest +11 -17
- data/README.md +89 -37
- data/bin/dayone +30 -143
- data/lib/rb-dayone.rb +17 -12
- data/lib/rb-dayone/entry.rb +41 -11
- data/lib/rb-dayone/entry_importer.rb +51 -36
- data/lib/rb-dayone/location.rb +74 -0
- data/lib/rb-dayone/plist_reader.rb +1 -3
- data/lib/rb-dayone/search.rb +15 -7
- data/rb-dayone.gemspec +5 -17
- data/version.txt +1 -1
- metadata +20 -43
- data/History.rdoc +0 -76
- data/spec/data/entries/748AD5D252F44149920485B0CEA478E3.doentry +0 -14
- data/spec/data/entries/F13723CDFD454481B24312DCD627BFD7.doentry +0 -14
- data/spec/data/foo.doentry +0 -1
- data/spec/data/locations/location-auto/location +0 -1
- data/spec/data/locations/location-specified/location +0 -1
- data/spec/data/sample.doentry +0 -12
- data/spec/data/sample.plist +0 -0
- data/spec/data/utf.doentry +0 -12
- data/spec/dayone_spec.rb +0 -34
- data/spec/entry_importer_spec.rb +0 -69
- data/spec/entry_spec.rb +0 -57
- data/spec/plist_reader_spec.rb +0 -18
- data/spec/search_spec.rb +0 -35
- data/spec/spec_helper.rb +0 -15
data/.gitignore
ADDED
data/Gemfile
CHANGED
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
|
-
|
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
|
-
|
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.
|
3
|
+
A means to create DayOne entries in ruby.
|
4
4
|
|
5
5
|
## Examples
|
6
6
|
|
7
|
-
You can create an entry pretty simply
|
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
|
-
|
24
|
+
## Binary
|
25
25
|
|
26
|
-
|
26
|
+
Rb-dayone ships with a binary, `dayone`. Run `dayone --help` for instructions on how to use it.
|
27
27
|
|
28
|
-
|
28
|
+
## Install
|
29
29
|
|
30
|
-
dayone
|
30
|
+
gem install rb-dayone
|
31
31
|
|
32
|
-
|
32
|
+
## Author
|
33
33
|
|
34
|
-
|
34
|
+
Original author: [Jan-Yves Ruzicka](http://www.1klb.com). Get in touch [via email](mailto:jan@1klb.com).
|
35
35
|
|
36
|
-
|
36
|
+
## History
|
37
37
|
|
38
|
-
|
38
|
+
### 0.6.0 / 2013-01-14
|
39
39
|
|
40
|
-
|
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
|
-
|
45
|
+
### 0.5.0 / 2013-01-09
|
43
46
|
|
44
|
-
|
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
|
-
|
50
|
+
## 0.4.1 / 2012-11-14
|
47
51
|
|
48
|
-
|
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
|
-
|
55
|
+
## 0.4.0 / 2012-10-22
|
51
56
|
|
52
|
-
|
57
|
+
* Added image support
|
53
58
|
|
54
|
-
|
55
|
-
|
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
|
-
##
|
86
|
+
## 0.1.7 / 2012-08-13
|
58
87
|
|
59
|
-
|
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
|
-
|
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
|
-
|
70
|
-
|
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
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
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 '
|
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,
|
7
|
-
program :description,
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
c.
|
14
|
-
c.
|
15
|
-
c.
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
-
|
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
|
-
|
78
|
-
|
79
|
-
|
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
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
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
|
-
|
66
|
+
|
62
67
|
Dir[File.join(lib_root, "rb-dayone", "*.rb")].each{ |f| require f }
|
63
68
|
|
64
69
|
# Default values
|