nikki 0.1.0 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 44304d85497a945b10d26b403c1ffde95cd529b4
4
- data.tar.gz: e1666230471fd50b243da107cee48a7351c39b79
3
+ metadata.gz: 21a4942b6497d674f4f13d34edfaf921c16c83b3
4
+ data.tar.gz: 8405b9f8aee38bbe34ad0b2166679b092df21d1e
5
5
  SHA512:
6
- metadata.gz: 1de9407ab295181a8a958e0c22db022cb117de70d67ec5371874078fb3c37a1ccc79ed8f8176c980c26492ddc15a93139aad8892e34d4d1d4e2838844e608b86
7
- data.tar.gz: 64825596f66e99613f4d9c08e6a76b6b93463b72a8e2703b56c52063b3603bc93f0edacaf61e8d0a6cdc61ceb94eb448395550f6c663968ad48f738e25115b31
6
+ metadata.gz: 8774c8bb643a5896c88394b72acbaa19345f4c196f3e41d257cccc44114d6625b5c282c6069f4377f3d16fc0f72093d250c496cd084adb773b389acf9599cc4a
7
+ data.tar.gz: 0f80bc207652527b4e8abf25750e67c88558b14fd3587cba7c41549daf868eb714555b6da2a1b70ca7eb1ae20dfe38ed97c2dda7ad2334c7fe9179be5b3d1660
data/Gemfile CHANGED
@@ -2,5 +2,3 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in nikki.gemspec
4
4
  gemspec
5
- gem 'cucumber'
6
- gem 'thor'
File without changes
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Gem Version](https://badge.fury.io/rb/nikki.png)](http://badge.fury.io/rb/nikki) [![Build Status](https://travis-ci.org/brandonpittman/nikki.png?branch=master)](https://travis-ci.org/brandonpittman/nikki)
2
+
1
3
  # nikki
2
4
 
3
5
  > "Record something new learned every day of the year."
@@ -31,4 +33,4 @@ Or install it yourself as:
31
33
  2. Create your feature branch (`git checkout -b my-new-feature`)
32
34
  3. Commit your changes (`git commit -am 'Add some feature'`)
33
35
  4. Push to the branch (`git push origin my-new-feature`)
34
- 5. Create new Pull Request
36
+ 5. Create new Pull Request
data/TODO.md ADDED
@@ -0,0 +1,6 @@
1
+ # New Features
2
+
3
+ ## Add config file
4
+
5
+ - Let users set a custom location for their journal.
6
+ - Let users set the editor that they want to open if the mtime check failed.
@@ -0,0 +1,9 @@
1
+ Feature: Initialize a new config file
2
+ I want more information about exactly when last a journal was updated
3
+ And I want to have a place to save a custom journal location
4
+
5
+ Background: No config file exists
6
+
7
+ Scenario: New user wants to create a new journal using defaults
8
+
9
+ Scenario: New user wants to create a new journal with a custom save location
@@ -3,21 +3,22 @@ Feature: Add a new entry to the journal
3
3
  Because I'm keeping a daily one-line journal, I want to be able to be able to save a new line with the day of the month next to it.
4
4
 
5
5
  Background:
6
- Given I have a journal entry to make
6
+ Given I have a journal file
7
7
 
8
8
  Scenario: I haven't created a journal file
9
- When I try to save my entry
10
- And the journal file can't be found
9
+ When the journal file can't be found
11
10
  Then a file should be created
12
11
  And my journal entry saved
13
12
 
14
13
  Scenario: I have a journal file and it's the first of the month
15
- When I try to save my entry
16
- And it's the first of the month
17
- Then the name of the month as an H1 header should be appended
14
+ When it's the first of the month
15
+ Then the name of the month as an H2 header should be appended
18
16
  And and my entry should be saved
19
17
 
20
18
  Scenario: I have a journal file and it's *not* the first of the month
21
- When I try to save my entry
22
- And it's not the first of the month
19
+ When it's not the first of the month
23
20
  Then my entry should be appended along with the day of the month
21
+
22
+ Scenario: I didn't update the journal yesterday
23
+ When the mtime of the journal isn't yesterday
24
+ Then the journal should open in my editor
@@ -0,0 +1,9 @@
1
+ Feature: Reveal journal file
2
+
3
+ Scenario: I try to reveal a journal file
4
+ Given the file doesn't exist
5
+ Then create the file
6
+ And reveal the file
7
+
8
+ Given the file does exist
9
+ Then reveal the file
@@ -1,10 +1,13 @@
1
- Given(/^I have a (.+) to make$/) do |arg|
2
- @text = arg
3
- @file = "#{ENV['HOME']}/.nikki_#{Time.now.strftime("%Y")}"
4
- end
1
+ require "time"
2
+ require "pathname"
3
+ require "nikki"
4
+
5
+ include Nikki
5
6
 
6
- When(/^I try to (save) my entry$/) do |arg|
7
- arg == "save"
7
+ Given(/^I have a journal file$/) do
8
+ @nikki = Generator.new
9
+ @file = @nikki.file
10
+ FileUtils.touch(@file) unless @file.exist?
8
11
  end
9
12
 
10
13
  When(/^the journal file can't be found$/) do
@@ -16,26 +19,34 @@ Then(/^a file should be created$/) do
16
19
  end
17
20
 
18
21
  Then(/^(my journal entry) saved$/) do |arg|
19
- @entry = arg
20
- File.open(@file,"a") { |f| f.puts "#{Time.now.strftime("%d")}. #{arg}" }
22
+ File.open(@file,"a") { |f| f.puts @nikki.text(arg) }
21
23
  end
22
24
 
23
25
  When(/^it's the first of the month$/) do
24
- @date = Date.new(2014,2,1)
26
+ @first = Date.new(2014,2,1)
25
27
  end
26
28
 
27
- Then(/^the name of the month as an H1 header should be appended$/) do
28
- File.open(@file, "a") { |file| file.puts "#{@date.strftime("%B")}" }
29
+ Then(/^the name of the month as an H2 header should be appended$/) do
30
+ File.open(@file, "a") { |file| file.puts "\n## #{@first.strftime("%B").strip}\n\n" }
29
31
  end
30
32
 
31
33
  Then(/^and my (entry) should be saved$/) do |arg|
32
- File.open(@file, "a") { |file| file.puts "#{@date.strftime("%d").strip} #{arg}" }
34
+ File.open(@file, "a") { |file| file.puts "#{@first.strftime("%e").strip}. #{arg}" }
33
35
  end
34
36
 
35
37
  When(/^it's not the first of the month$/) do
36
- @date = Date.new(2014,2,2)
38
+ @not_first = Date.new(2014,2,2)
37
39
  end
38
40
 
39
41
  Then(/^my (entry) should be appended along with the day of the month$/) do |arg|
40
- File.open(@file, "a") { |file| file.puts "#{@date.strftime("%d").strip} #{arg}" }
41
- end
42
+ File.open(@file, "a") { |file| file.puts "#{@not_first.strftime("%e").strip}. #{arg}" }
43
+ end
44
+
45
+ When(/^the mtime of the journal isn't yesterday$/) do
46
+ today = Date.today
47
+ @file.mtime.to_date != Date.today-1
48
+ end
49
+
50
+ Then(/^the journal should open in my editor$/) do
51
+ %x{open -a 'Sublime Text' #{@file}}
52
+ end
@@ -0,0 +1,22 @@
1
+ require "pathname"
2
+ require "fileutils"
3
+
4
+ def file
5
+ path = Pathname.new("/tmp/journal.md")
6
+ end
7
+
8
+ Given(/^the file doesn't exist$/) do
9
+ FileUtils.rm_rf(file) if file.exist?
10
+ end
11
+
12
+ Then(/^create the file$/) do
13
+ FileUtils.touch(file)
14
+ end
15
+
16
+ Then(/^reveal the file$/) do
17
+ %x{open -a 'Sublime Text' #{file}}
18
+ end
19
+
20
+ Given(/^the file does exist$/) do
21
+ FileUtils.touch(file) unless file.exist?
22
+ end
@@ -0,0 +1,13 @@
1
+ # require "aruba/cucumber"
2
+ # require "fileutils"
3
+
4
+ # Before do
5
+ # @real_home = ENV['HOME']
6
+ # fake_home = File.join('/tmp','fake_home')
7
+ # FileUtils.rm_rf fake_home, secure: true
8
+ # ENV['HOME'] = fake_home
9
+ # end
10
+
11
+ # After do
12
+ # ENV['HOME'] = @real_home
13
+ # end
data/lib/nikki/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Nikki
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.5"
3
3
  end
data/lib/nikki.rb CHANGED
@@ -1,52 +1,106 @@
1
1
  require 'thor'
2
2
  require "pathname"
3
+ require "yaml"
4
+ require "date"
5
+ require 'time'
3
6
 
4
7
  module Nikki
5
8
  class Generator < Thor
9
+ @@config = nil
6
10
 
7
11
  desc "new ENTRY", "Creates a new entry in the Nikki journal."
8
12
  def new(entry)
9
13
  file.open('a') { |file| file.puts text(entry)}
14
+ open unless updated_yesterday?
15
+ @@config = config
16
+ @@config[:updated] = Date.today
17
+ config_file.open('w') { |t| t << @@config.to_yaml }
18
+ end
19
+
20
+ desc "open", "Opens current year's journal file in editor."
21
+ def open
22
+ %x{open -a "#{editor}" #{file}}
23
+ end
24
+
25
+ desc "setup", "Change Nikki's settings."
26
+ option :editor, :aliases => :e
27
+ def setup
28
+ @@config = config
29
+ @@config[:editor] = options[:editor] || 'TextEdit'
30
+ config_file.open('w') { |t| t << @@config.to_yaml }
10
31
  end
11
32
 
12
33
  no_commands do
34
+ def path
35
+ dropbox = Pathname.new("#{ENV['HOME']}/Dropbox/")
36
+ home = Pathname.new("#{ENV['HOME']}/")
37
+ path = dropbox.exist? ? dropbox : home
38
+ end
39
+
40
+ def config_file
41
+ path.join(".nikki.config.yaml")
42
+ end
43
+
44
+ def config
45
+ config_file_exist?
46
+ YAML.load(config_file.read)
47
+ end
48
+
49
+ def editor
50
+ config[:editor]
51
+ end
52
+
13
53
  def file
14
- Pathname.new("#{ENV['HOME']}/.nikki_#{Time.now.strftime("%Y")}.md")
54
+ path.join(".nikki_#{Time.now.strftime("%Y")}.md")
55
+ end
56
+
57
+ def config_file_exist?
58
+ return true if config_file.exist?
59
+ create_config_file
60
+ return true
15
61
  end
16
62
 
17
63
  def file_exist?
18
- if file.exist?
19
- return true
20
- else
21
- create_file
22
- return true
23
- end
64
+ return true if file.exist?
65
+ create_file
66
+ return true
67
+ end
68
+
69
+ def create_config_file
70
+ FileUtils.touch(config_file)
24
71
  end
25
72
 
26
73
  def create_file
27
74
  FileUtils.touch(file)
28
75
  end
29
76
 
77
+ def today
78
+ Date.today
79
+ end
80
+
30
81
  def first_of_month?
31
- Time.now.strftime("%d") == "1"
82
+ today.day == "1"
32
83
  end
33
84
 
34
85
  def date
35
- Time.now.strftime("%d")
86
+ today.day
36
87
  end
37
88
 
38
89
  def month
39
- Time.now.strftime("%B")
90
+ today.month
91
+ end
92
+
93
+ def updated_yesterday?
94
+ config[:updated] == Date.today-1
40
95
  end
41
96
 
42
97
  def text(entry)
43
98
  if first_of_month?
44
- "## #{month}\n\n#{date}. #{entry}"
99
+ "\n## #{month}\n\n#{date}. #{entry}"
45
100
  else
46
101
  "#{date}. #{entry}"
47
102
  end
48
103
  end
49
104
  end
50
-
51
105
  end
52
106
  end
data/nikki.gemspec CHANGED
@@ -20,7 +20,9 @@ Gem::Specification.new do |spec|
20
20
  spec.require_paths = ["lib"]
21
21
 
22
22
  spec.add_dependency "thor", "~> 0.18"
23
+
23
24
  spec.add_development_dependency "bundler", "~> 1.5"
24
25
  spec.add_development_dependency "rake"
25
26
  spec.add_development_dependency "cucumber"
27
+ spec.add_development_dependency "aruba"
26
28
  end
data/test/tc_nikki.rb CHANGED
@@ -2,7 +2,7 @@ require "minitest/autorun"
2
2
  require "minitest/unit"
3
3
  require "nikki"
4
4
 
5
- class TestCase < MiniTest::Unit::TestCase
5
+ class NikkiTest < MiniTest::Unit::TestCase
6
6
 
7
7
  include Nikki
8
8
 
@@ -11,4 +11,11 @@ class TestCase < MiniTest::Unit::TestCase
11
11
  assert_equal(true,nikki.file_exist?)
12
12
  end
13
13
 
14
+ def test_updated_yesterday?
15
+ nikki = Generator.new
16
+ file = nikki.file
17
+ FileUtils.touch(file, :mtime => Time.now-86000)
18
+ assert(nikki.updated_yesterday?)
19
+ end
20
+
14
21
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nikki
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Pittman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-25 00:00:00.000000000 Z
11
+ date: 2014-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: aruba
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description: A simple one-line-a-day journaling app.
70
84
  email:
71
85
  - brandonpittman@gmail.com
@@ -76,13 +90,17 @@ extra_rdoc_files: []
76
90
  files:
77
91
  - ".gitignore"
78
92
  - Gemfile
79
- - LICENSE
80
- - LICENSE.txt
93
+ - License.txt
81
94
  - README.md
82
95
  - Rakefile
96
+ - TODO.md
83
97
  - bin/nikki
98
+ - features/initialize_journal.feature
84
99
  - features/new_entry.feature
100
+ - features/reveal_journal.feature
85
101
  - features/step_definitions/new_entry.steps.rb
102
+ - features/step_definitions/reveal_file.steps.rb
103
+ - features/support/env.rb
86
104
  - lib/nikki.rb
87
105
  - lib/nikki/version.rb
88
106
  - nikki.gemspec
@@ -112,6 +130,10 @@ signing_key:
112
130
  specification_version: 4
113
131
  summary: A simple one-line-a-day journaling app.
114
132
  test_files:
133
+ - features/initialize_journal.feature
115
134
  - features/new_entry.feature
135
+ - features/reveal_journal.feature
116
136
  - features/step_definitions/new_entry.steps.rb
137
+ - features/step_definitions/reveal_file.steps.rb
138
+ - features/support/env.rb
117
139
  - test/tc_nikki.rb
data/LICENSE DELETED
@@ -1,20 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2013 brandonpittman
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy of
6
- this software and associated documentation files (the "Software"), to deal in
7
- the Software without restriction, including without limitation the rights to
8
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
- the Software, and to permit persons to whom the Software is furnished to do so,
10
- subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
- FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
- COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
- IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.