rb-dayone 0.1.7 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +5 -1
- data/Manifest +7 -0
- data/README.md +16 -17
- data/bin/dayone +6 -2
- data/lib/rb-dayone.rb +32 -22
- data/lib/rb-dayone/plist_reader.rb +25 -0
- data/rb-dayone.gemspec +1 -7
- data/spec/dayone_spec.rb +32 -0
- data/spec/entry_spec.rb +2 -5
- data/spec/locations/location-auto/location +1 -0
- data/spec/locations/location-specified/location +1 -0
- data/spec/plist_reader_spec.rb +20 -0
- data/spec/sample.plist +0 -0
- data/spec/spec_helper.rb +0 -1
- data/version.txt +1 -1
- metadata +25 -13
data/History.rdoc
CHANGED
@@ -1,4 +1,8 @@
|
|
1
|
-
== 0.
|
1
|
+
== 0.2.0 / 2012-08-14
|
2
|
+
|
3
|
+
* Now auto-detects DayOne journal location from your plist file
|
4
|
+
|
5
|
+
== 0.1.7 / 2012-08-13
|
2
6
|
|
3
7
|
* The dayone binary can now add entries to your journal
|
4
8
|
* [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.
|
data/Manifest
CHANGED
@@ -3,9 +3,16 @@ Gemfile
|
|
3
3
|
History.rdoc
|
4
4
|
lib/rb-dayone.rb
|
5
5
|
lib/rb-dayone/entry.rb
|
6
|
+
lib/rb-dayone/plist_reader.rb
|
6
7
|
Manifest
|
7
8
|
rb-dayone.gemspec
|
8
9
|
README.md
|
10
|
+
spec/dayone_spec.rb
|
9
11
|
spec/entry_spec.rb
|
12
|
+
spec/locations/location-auto/location
|
13
|
+
spec/locations/location-specified/location
|
14
|
+
spec/locations/location-unspecified
|
10
15
|
spec/spec_helper.rb
|
16
|
+
spec/plist_reader_spec.rb
|
17
|
+
spec/sample.plist
|
11
18
|
version.txt
|
data/README.md
CHANGED
@@ -2,46 +2,45 @@
|
|
2
2
|
|
3
3
|
A means to create DayOne entries in ruby. Also, my first public ruby gem!
|
4
4
|
|
5
|
-
Examples
|
6
|
-
--------
|
5
|
+
## Examples
|
7
6
|
|
8
7
|
You can create an entry pretty simply, by passing in your entry text:
|
9
8
|
|
10
|
-
|
9
|
+
e = DayOne::Entry.new "# Hello, world!"
|
11
10
|
|
12
11
|
You can also set up other values via a hash:
|
13
12
|
|
14
|
-
|
13
|
+
e = DayOne::Entry.new "I totally posted this an hour ago", creation_date: Time.now-3600
|
15
14
|
|
16
15
|
Otherwise, you can set values using simple accessor methods, as you'd expect:
|
17
16
|
|
18
|
-
|
19
|
-
|
17
|
+
e = DayOne::Entry.new "I need to remember this."
|
18
|
+
e.starred = true
|
20
19
|
|
21
20
|
When you're ready to save your entry, just run the `create!` method:
|
22
21
|
|
23
|
-
|
22
|
+
e.create!
|
24
23
|
|
25
24
|
Alternatively, run from the command line:
|
26
25
|
|
27
|
-
|
26
|
+
dayone add --text "#Hello, world" --starred
|
28
27
|
|
29
|
-
|
30
|
-
-------
|
28
|
+
For more information on what you can do from the command line:
|
31
29
|
|
32
|
-
|
30
|
+
dayone --help
|
33
31
|
|
34
|
-
|
35
|
-
------
|
32
|
+
## Install
|
36
33
|
|
37
|
-
|
34
|
+
gem install rb-dayone
|
38
35
|
|
39
|
-
|
40
|
-
|
36
|
+
## Author
|
37
|
+
|
38
|
+
Original author: Jan-Yves Ruzicka (@akchizar). Get in touch [via email](mailto:janyves.ruzicka@gmail.com).
|
39
|
+
|
40
|
+
## To do
|
41
41
|
|
42
42
|
* Image support
|
43
43
|
* Location support?
|
44
|
-
* Auto-journal detection
|
45
44
|
|
46
45
|
License
|
47
46
|
-------
|
data/bin/dayone
CHANGED
@@ -12,7 +12,11 @@ dayone_location_file = File.join(dayone_folder, 'location')
|
|
12
12
|
command :set do |c|
|
13
13
|
c.syntax = "set [key value]"
|
14
14
|
c.description = "Show or set program settings."
|
15
|
-
c.summary =
|
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
|
16
20
|
|
17
21
|
c.action do |args|
|
18
22
|
case args.size
|
@@ -22,7 +26,7 @@ command :set do |c|
|
|
22
26
|
key, val = *args
|
23
27
|
case key
|
24
28
|
when 'location'
|
25
|
-
new_dayone_location = File.expand_path(val)
|
29
|
+
new_dayone_location = (val == 'auto' ? 'auto' : File.expand_path(val))
|
26
30
|
File.open(dayone_location_file,'w'){ |io| io << new_dayone_location }
|
27
31
|
puts "#{key}: #{new_dayone_location}"
|
28
32
|
else
|
data/lib/rb-dayone.rb
CHANGED
@@ -9,22 +9,37 @@ module DayOne
|
|
9
9
|
# Set by default to ~/.rb-dayone
|
10
10
|
attr_accessor :dayone_folder
|
11
11
|
|
12
|
-
# The location of the journal file
|
13
|
-
|
12
|
+
# The location of the DayOne journal file.
|
13
|
+
attr_writer :journal_location
|
14
|
+
|
15
|
+
# An interface to the propertylist reader
|
16
|
+
attr_accessor :plist_reader
|
14
17
|
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
# @return [String] the
|
18
|
+
# The location of the DayOne journal file.
|
19
|
+
# If the location is set to "auto" or is non-existant,
|
20
|
+
# will set from the DayOne plist (See +auto_journal_location+).
|
21
|
+
# @return [String] the DayOne journal location
|
19
22
|
def journal_location
|
20
|
-
|
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
|
31
|
+
else
|
32
|
+
@journal_location = auto_journal_location
|
33
|
+
end
|
34
|
+
end
|
35
|
+
@journal_location
|
21
36
|
end
|
22
37
|
|
23
|
-
#
|
24
|
-
# file
|
25
|
-
# @return [
|
26
|
-
def
|
27
|
-
File.
|
38
|
+
# The location of the DayOne journal file as determined by
|
39
|
+
# the DayOne plist file stored in +~/Library/Preferences+.
|
40
|
+
# @return [String] the DayONe journal location
|
41
|
+
def auto_journal_location
|
42
|
+
@auto_journal_location ||= File.expand_path(plist_reader['NSNavLastRootDirectory'])
|
28
43
|
end
|
29
44
|
|
30
45
|
private
|
@@ -37,14 +52,9 @@ module DayOne
|
|
37
52
|
end
|
38
53
|
end
|
39
54
|
|
40
|
-
|
41
|
-
|
42
|
-
unless DayOne::journal_location_exists?
|
43
|
-
puts <<-end
|
44
|
-
Error: DayOne journal file has not been located.
|
45
|
-
Please set this using the command `dayone --set location
|
46
|
-
before continuing.
|
47
|
-
end
|
48
|
-
end
|
55
|
+
lib_root = File.dirname(__FILE__)
|
56
|
+
Dir[File.join(lib_root, "rb-dayone", "*.rb")].each{ |f| require f }
|
49
57
|
|
50
|
-
|
58
|
+
# Default values
|
59
|
+
DayOne::dayone_folder = File.join(ENV['HOME'], '.rb-dayone')
|
60
|
+
DayOne::plist_reader = DayOne::PlistReader.new
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
class DayOne::PlistReader
|
4
|
+
attr_accessor :path
|
5
|
+
|
6
|
+
def initialize path=nil
|
7
|
+
@path = path || File.join(ENV['HOME'], 'Library', 'Preferences', 'com.dayoneapp.dayone.plist')
|
8
|
+
end
|
9
|
+
|
10
|
+
def body
|
11
|
+
if !@body
|
12
|
+
json_string = `plutil -convert json -o - '#{path}'`
|
13
|
+
@body = JSON.parse(json_string)
|
14
|
+
end
|
15
|
+
@body
|
16
|
+
end
|
17
|
+
|
18
|
+
def method_missing sym, *args
|
19
|
+
if self.body.respond_to? sym
|
20
|
+
self.body.send(sym, *args)
|
21
|
+
else
|
22
|
+
super sym, *args
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/rb-dayone.gemspec
CHANGED
@@ -16,13 +16,7 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.bindir = 'bin'
|
17
17
|
s.executables << 'dayone'
|
18
18
|
s.extra_rdoc_files = ['README.md']
|
19
|
-
s.post_install_message = <<-end
|
20
|
-
#{'-'*80}
|
21
|
-
Thank you for installing rb-dayone!
|
22
|
-
|
23
|
-
To finish setup, run `dayone set location <location>` to specify where your DayOne journal is stored.
|
24
|
-
#{'-'*80}
|
25
|
-
end
|
26
19
|
|
27
20
|
s.add_runtime_dependency 'builder', '~> 2.0'
|
21
|
+
s.add_runtime_dependency 'commander', '~> 4.1.2'
|
28
22
|
end
|
data/spec/dayone_spec.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require './spec/spec_helper'
|
2
|
+
|
3
|
+
describe DayOne do
|
4
|
+
describe "#journal_location" do
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
DayOne::journal_location = nil
|
8
|
+
DayOne::instance_variable_set('@journal_file',nil)
|
9
|
+
end
|
10
|
+
|
11
|
+
def location str
|
12
|
+
File.join(File.dirname(__FILE__),"locations", "location-#{str}")
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should return the value given by the +location+ file" do
|
16
|
+
DayOne::dayone_folder = location('specified')
|
17
|
+
DayOne::journal_location.should == 'sample location'
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should return a default value when +location+ is 'auto'" do
|
21
|
+
DayOne.plist_reader = {'NSNavLastRootDirectory' => 'foo'}
|
22
|
+
DayOne::dayone_folder = location('auto')
|
23
|
+
DayOne::journal_location.should == File.expand_path('foo')
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should return a default value if +location+ doesn't exist" do
|
27
|
+
DayOne.plist_reader = {'NSNavLastRootDirectory' => 'foo'}
|
28
|
+
DayOne::dayone_folder = location('unspecified')
|
29
|
+
DayOne::journal_location.should == File.expand_path('foo')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/spec/entry_spec.rb
CHANGED
@@ -2,9 +2,6 @@ require './spec/spec_helper'
|
|
2
2
|
require 'fileutils'
|
3
3
|
|
4
4
|
describe DayOne::Entry do
|
5
|
-
|
6
|
-
let(:entry){ DayOne::Entry.new }
|
7
|
-
|
8
5
|
after :all do
|
9
6
|
Dir['spec/entries/*.doentry'].each{ |f| FileUtils.rm(f) }
|
10
7
|
FileUtils.rmdir('spec/entries')
|
@@ -12,7 +9,7 @@ describe DayOne::Entry do
|
|
12
9
|
|
13
10
|
describe "#to_xml" do
|
14
11
|
it "should give a default entry" do
|
15
|
-
e =
|
12
|
+
e = subject.to_xml
|
16
13
|
e.should match %r|<key>Entry Text</key>\s*<string></string>|
|
17
14
|
e.should match %r|<key>Starred</key>\s*<false/>|
|
18
15
|
end
|
@@ -34,7 +31,7 @@ describe DayOne::Entry do
|
|
34
31
|
DayOne::journal_location = 'spec'
|
35
32
|
FileUtils::mkdir_p 'spec/entries'
|
36
33
|
|
37
|
-
e =
|
34
|
+
e = subject
|
38
35
|
e.entry_text = "Hello, world!"
|
39
36
|
e.create!
|
40
37
|
|
@@ -0,0 +1 @@
|
|
1
|
+
auto
|
@@ -0,0 +1 @@
|
|
1
|
+
sample location
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require './spec/spec_helper'
|
2
|
+
|
3
|
+
describe DayOne::PlistReader do
|
4
|
+
describe "#initialize" do
|
5
|
+
it "should default to the normal preference file" do
|
6
|
+
File.should exist(subject.path)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#body" do
|
11
|
+
it "should give us the location of the DayOne journal file" do
|
12
|
+
subject.should have_key('NSNavLastRootDirectory')
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should correctly parse binary plists" do
|
16
|
+
reader = DayOne::PlistReader.new(File.join(File.dirname(__FILE__),'sample.plist'))
|
17
|
+
reader['foo'].should == 'bar'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/spec/sample.plist
ADDED
Binary file
|
data/spec/spec_helper.rb
CHANGED
data/version.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rb-dayone
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: builder
|
@@ -27,6 +27,22 @@ dependencies:
|
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '2.0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: commander
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 4.1.2
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 4.1.2
|
30
46
|
description: Create [DayOne](http://www.dayoneapp.com) journal entries simply and
|
31
47
|
easily in ruby. Currently only supports text entries, image entries to come.
|
32
48
|
email: janyves.ruzicka@gmail.com
|
@@ -41,25 +57,21 @@ files:
|
|
41
57
|
- History.rdoc
|
42
58
|
- lib/rb-dayone.rb
|
43
59
|
- lib/rb-dayone/entry.rb
|
60
|
+
- lib/rb-dayone/plist_reader.rb
|
44
61
|
- Manifest
|
45
62
|
- rb-dayone.gemspec
|
46
63
|
- README.md
|
64
|
+
- spec/dayone_spec.rb
|
47
65
|
- spec/entry_spec.rb
|
66
|
+
- spec/locations/location-auto/location
|
67
|
+
- spec/locations/location-specified/location
|
48
68
|
- spec/spec_helper.rb
|
69
|
+
- spec/plist_reader_spec.rb
|
70
|
+
- spec/sample.plist
|
49
71
|
- version.txt
|
50
72
|
homepage: https://github.com/jyruzicka/rb-dayone
|
51
73
|
licenses: []
|
52
|
-
post_install_message:
|
53
|
-
|
54
|
-
Thank you for installing rb-dayone!
|
55
|
-
|
56
|
-
|
57
|
-
To finish setup, run `dayone set location <location>` to specify where your DayOne
|
58
|
-
journal is stored.
|
59
|
-
|
60
|
-
--------------------------------------------------------------------------------
|
61
|
-
|
62
|
-
'
|
74
|
+
post_install_message:
|
63
75
|
rdoc_options: []
|
64
76
|
require_paths:
|
65
77
|
- lib
|