rb-dayone 0.1.5 → 0.1.6
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/Gemfile +2 -1
- data/{History.txt → History.rdoc} +6 -0
- data/Manifest +11 -0
- data/bin/dayone +31 -27
- data/lib/rb-dayone/entry.rb +77 -0
- data/lib/rb-dayone.rb +48 -0
- data/rb-dayone.gemspec +28 -0
- data/spec/entry_spec.rb +2 -1
- data/version.txt +1 -0
- metadata +9 -5
- data/Gemfile.lock +0 -10
- data/Rakefile +0 -21
data/Gemfile
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
== 0.1.6 / 2012-08-13
|
2
|
+
|
3
|
+
* Updated documentation so YARD would generate nice rdocs
|
4
|
+
* dayone binary now uses the Commander gem
|
5
|
+
* Now using a Manifest file rather than globbing in whole directories
|
6
|
+
|
1
7
|
== 0.1.5 / 2012-08-12
|
2
8
|
|
3
9
|
* [FIXED] Ouch, horrid horrid gemspec and readme. Let's make them prettier.
|
data/Manifest
ADDED
data/bin/dayone
CHANGED
@@ -1,34 +1,38 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'fileutils'
|
3
|
+
require 'commander/import'
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
5
|
+
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
8
|
|
9
|
-
|
10
|
-
|
11
|
-
exit 1
|
12
|
-
end
|
9
|
+
dayone_folder = File.join(ENV['HOME'], '.rb-dayone')
|
10
|
+
dayone_location_file = File.join(dayone_folder, 'location')
|
13
11
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
12
|
+
command :set do |c|
|
13
|
+
c.syntax = "set [key value]"
|
14
|
+
c.description = "Show or set program settings."
|
15
|
+
c.summary = "If sent without arguments, this will show all program settings. If sent with two arguments, this will set <key> to <value>"
|
16
|
+
|
17
|
+
c.action do |args|
|
18
|
+
case args.size
|
19
|
+
when 0
|
20
|
+
puts "location: #{File.read(dayone_location_file)}"
|
21
|
+
when 2
|
22
|
+
key, val = *args
|
23
|
+
case key
|
24
|
+
when 'location'
|
25
|
+
new_dayone_location = File.expand_path(val)
|
26
|
+
File.open(dayone_location_file,'w'){ |io| io << new_dayone_location }
|
27
|
+
puts "#{key}: #{new_dayone_location}"
|
28
|
+
else
|
29
|
+
puts "Key #{key} not recognised"
|
30
|
+
exit 1
|
31
|
+
end
|
32
|
+
else
|
33
|
+
puts c.syntax
|
34
|
+
puts c.summary
|
35
|
+
exit 1
|
36
|
+
end
|
31
37
|
end
|
32
|
-
else
|
33
|
-
usage
|
34
38
|
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# A text-only journal entry for DayOne.
|
2
|
+
class DayOne::Entry
|
3
|
+
|
4
|
+
# The date of the journal entry
|
5
|
+
attr_accessor :creation_date
|
6
|
+
|
7
|
+
# The journal entry's body text
|
8
|
+
attr_accessor :entry_text
|
9
|
+
|
10
|
+
# Whether the entry has been starred
|
11
|
+
attr_accessor :starred
|
12
|
+
|
13
|
+
# The PList doctype, used for XML export
|
14
|
+
DOCTYPE = 'plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"'
|
15
|
+
|
16
|
+
# Initialise a journal entry, ready for inclusion into your journal
|
17
|
+
# @param [String] entry_text the body text of the journal entry
|
18
|
+
# @param [Hash] hsh a hash of options - allowed keys include `:creation_date`, `:entry_text` and `:starred`, others are ignored
|
19
|
+
# @return [DayOne::Entry] the journal entry
|
20
|
+
def initialize entry_text='', hsh={}
|
21
|
+
# Some defaults
|
22
|
+
@creation_date = Time.now
|
23
|
+
@starred = false
|
24
|
+
@entry_text = entry_text
|
25
|
+
|
26
|
+
hsh.each do |k,v|
|
27
|
+
setter = "#{k}="
|
28
|
+
self.send(setter,v) if self.respond_to? setter
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Generate (or retrieve, if previously generatred) a UUID
|
33
|
+
# for this entry.
|
34
|
+
# @return [String] the entry's UUID
|
35
|
+
def uuid
|
36
|
+
@uuid ||= `uuidgen`.gsub('-','').strip
|
37
|
+
end
|
38
|
+
|
39
|
+
# Convert an entry to XML.
|
40
|
+
# @return [String] the entry as XML
|
41
|
+
def to_xml
|
42
|
+
builder = Builder::XmlMarkup.new
|
43
|
+
builder.instruct! # Basic xml tag
|
44
|
+
builder.declare! :DOCTYPE, DOCTYPE # PList doctype
|
45
|
+
builder.plist(version:1.0) do
|
46
|
+
builder.dict do
|
47
|
+
builder.key 'Creation Date'
|
48
|
+
builder.date creation_date.utc.iso8601
|
49
|
+
|
50
|
+
builder.key 'Entry Text'
|
51
|
+
builder.string entry_text
|
52
|
+
|
53
|
+
builder.key 'Starred'
|
54
|
+
if starred
|
55
|
+
builder.true
|
56
|
+
else
|
57
|
+
builder.false
|
58
|
+
end
|
59
|
+
|
60
|
+
builder.key 'UUID'
|
61
|
+
builder.string uuid
|
62
|
+
end
|
63
|
+
end
|
64
|
+
builder.target
|
65
|
+
end
|
66
|
+
|
67
|
+
# Create a .doentry file with this entry.
|
68
|
+
# This uses the #to_xml method to generate
|
69
|
+
# the entry proper.
|
70
|
+
# @return [Boolean] true if the operation was successful.
|
71
|
+
def create!
|
72
|
+
xml = self.to_xml
|
73
|
+
file_location = File.join(DayOne::journal_location,'entries',"#{uuid}.doentry")
|
74
|
+
File.open(file_location,'w'){ |io| io << xml }
|
75
|
+
return true
|
76
|
+
end
|
77
|
+
end
|
data/lib/rb-dayone.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'time'
|
2
|
+
require 'builder'
|
3
|
+
|
4
|
+
# This module contains all classes used in the DayOne gem,
|
5
|
+
# as well as some helper methods
|
6
|
+
module DayOne
|
7
|
+
class << self
|
8
|
+
# This is where all DayOne-relevant information is stored.
|
9
|
+
# Set by default to ~/.rb-dayone
|
10
|
+
attr_accessor :dayone_folder
|
11
|
+
|
12
|
+
# The location of the journal file
|
13
|
+
attr_accessor :journal_location
|
14
|
+
|
15
|
+
# This is where your DayOne Journal is kept. Modify either
|
16
|
+
# by directly modifying the ~/.rb-dayone/location file
|
17
|
+
# or by running `dayone --set location`
|
18
|
+
# @return [String] the location of DayOne's journal file.
|
19
|
+
def journal_location
|
20
|
+
@journal_location ||= File.read(journal_file).strip
|
21
|
+
end
|
22
|
+
|
23
|
+
# Error-checking method. Ensures that the journal location
|
24
|
+
# file exists.
|
25
|
+
# @return [Boolean] whether or not the journal location file exists
|
26
|
+
def journal_location_exists?
|
27
|
+
File.exists? journal_file
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
# The journal file location
|
33
|
+
# @return [String] the location of the journal file
|
34
|
+
def journal_file
|
35
|
+
@journal_file ||= File.join(dayone_folder, 'location')
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
DayOne::dayone_folder = File.join(ENV['HOME'], '.rb-dayone')
|
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
|
data/rb-dayone.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "rb-dayone"
|
5
|
+
s.version = File.read('version.txt')
|
6
|
+
|
7
|
+
s.summary = "Create DayOne journal entries in ruby."
|
8
|
+
s.description = "Create [DayOne](http://www.dayoneapp.com) journal entries simply and easily in ruby. Currently only supports text entries, image entries to come."
|
9
|
+
|
10
|
+
s.author = 'Jan-Yves Ruzicka'
|
11
|
+
s.email = 'janyves.ruzicka@gmail.com'
|
12
|
+
s.homepage = 'https://github.com/jyruzicka/rb-dayone'
|
13
|
+
|
14
|
+
s.files = File.read('Manifest').split("\n")
|
15
|
+
s.require_paths << 'lib'
|
16
|
+
s.bindir = 'bin'
|
17
|
+
s.executables << 'dayone'
|
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
|
+
|
27
|
+
s.add_runtime_dependency 'builder', '~> 2.0'
|
28
|
+
end
|
data/spec/entry_spec.rb
CHANGED
data/version.txt
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.6
|
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.1.
|
4
|
+
version: 0.1.6
|
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-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: builder
|
@@ -38,12 +38,15 @@ extra_rdoc_files:
|
|
38
38
|
files:
|
39
39
|
- bin/dayone
|
40
40
|
- Gemfile
|
41
|
-
-
|
42
|
-
-
|
43
|
-
-
|
41
|
+
- History.rdoc
|
42
|
+
- lib/rb-dayone.rb
|
43
|
+
- lib/rb-dayone/entry.rb
|
44
|
+
- Manifest
|
45
|
+
- rb-dayone.gemspec
|
44
46
|
- README.md
|
45
47
|
- spec/entry_spec.rb
|
46
48
|
- spec/spec_helper.rb
|
49
|
+
- version.txt
|
47
50
|
homepage: https://github.com/jyruzicka/rb-dayone
|
48
51
|
licenses: []
|
49
52
|
post_install_message: ! '--------------------------------------------------------------------------------
|
@@ -80,3 +83,4 @@ signing_key:
|
|
80
83
|
specification_version: 3
|
81
84
|
summary: Create DayOne journal entries in ruby.
|
82
85
|
test_files: []
|
86
|
+
has_rdoc:
|
data/Gemfile.lock
DELETED
data/Rakefile
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
gem_title = 'rb-dayone'
|
2
|
-
|
3
|
-
task :build do
|
4
|
-
specfile = "#{gem_title}.gemspec"
|
5
|
-
puts `gem build '#{specfile}'`
|
6
|
-
|
7
|
-
gem_file = Dir["#{gem_title}-*.gem"]
|
8
|
-
gem_file.each do |f|
|
9
|
-
puts `mv '#{f}' pkg`
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
task :install do
|
14
|
-
pkg = Dir['pkg/*.gem'].sort[-1]
|
15
|
-
puts `gem install #{pkg}`
|
16
|
-
end
|
17
|
-
|
18
|
-
task :go => [:build, :install] do
|
19
|
-
end
|
20
|
-
|
21
|
-
task :default => :go
|