retter 0.2.2 → 0.2.3

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.
Files changed (52) hide show
  1. data/.travis.yml +1 -1
  2. data/ChangeLog.md +10 -0
  3. data/README.md +1 -3
  4. data/bin/retter +8 -4
  5. data/lib/retter/binder.rb +50 -0
  6. data/lib/retter/command.rb +42 -39
  7. data/lib/retter/config.rb +24 -23
  8. data/lib/retter/entries.rb +14 -18
  9. data/lib/retter/entry.rb +52 -29
  10. data/lib/retter/generator/base.rb +6 -7
  11. data/lib/retter/generator/skel/Gemfile +1 -2
  12. data/lib/retter/generator/skel/Retterfile +2 -2
  13. data/lib/retter/generator/skel/layouts/article.html.haml +3 -2
  14. data/lib/retter/generator/skel/layouts/entry.html.haml +3 -2
  15. data/lib/retter/generator/skel/layouts/index.html.haml +4 -2
  16. data/lib/retter/generator.rb +0 -1
  17. data/lib/retter/{renderers.rb → markdown.rb} +22 -1
  18. data/lib/retter/page/article.rb +54 -0
  19. data/lib/retter/page/base.rb +97 -0
  20. data/lib/retter/page/entries.rb +17 -0
  21. data/lib/retter/page/entry.rb +46 -0
  22. data/lib/retter/page/feed.rb +63 -0
  23. data/lib/retter/page/index.rb +17 -0
  24. data/lib/retter/page/profile.rb +17 -0
  25. data/lib/retter/page/view_helper.rb +9 -1
  26. data/lib/retter/page.rb +22 -74
  27. data/lib/retter/preprint.rb +19 -10
  28. data/lib/retter/version.rb +1 -1
  29. data/lib/retter.rb +41 -29
  30. data/retter.gemspec +44 -53
  31. data/spec/command/callback_spec.rb +16 -6
  32. data/spec/command/clean_spec.rb +20 -0
  33. data/spec/command/commit_spec.rb +11 -12
  34. data/spec/command/edit_spec.rb +28 -38
  35. data/spec/command/list_spec.rb +4 -4
  36. data/spec/command/open_spec.rb +2 -2
  37. data/spec/command/preview_spec.rb +7 -12
  38. data/spec/command/rebind_spec.rb +143 -66
  39. data/spec/spec_helper.rb +10 -3
  40. data/spec/support/example_group_helper.rb +55 -15
  41. data/spec/support/matchers.rb +0 -1
  42. metadata +195 -78
  43. data/lib/retter/generator/updator.rb +0 -7
  44. data/lib/retter/pages/article.rb +0 -41
  45. data/lib/retter/pages/entries.rb +0 -15
  46. data/lib/retter/pages/entry.rb +0 -35
  47. data/lib/retter/pages/feed.rb +0 -51
  48. data/lib/retter/pages/index.rb +0 -15
  49. data/lib/retter/pages/profile.rb +0 -15
  50. data/lib/retter/pages.rb +0 -77
  51. data/spec/command/invoke_after_spec.rb +0 -29
  52. data/spec/fixtures/sample.md +0 -295
data/retter.gemspec CHANGED
@@ -1,55 +1,46 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "retter/version"
4
-
5
- Gem::Specification.new do |s|
6
- s.name = "retter"
7
- s.version = Retter::VERSION
8
- s.authors = ["hibariya", "uzura29"]
9
- s.email = ["celluloid.key@gmail.com"]
10
- s.homepage = "https://github.com/hibariya/retter"
11
- s.summary = %q{Flyweight diary workflow}
12
- s.description = %q{Flyweight diary workflow. ruby-1.9.2 or later is required.}
13
-
14
-
15
- s.post_install_message = <<-EOM
16
- -- Thanks for flying Retter :-> --
17
-
18
- Pygments syntax highlight is now available.
19
- To use, add a following line to Retterfile.
20
-
21
- ```ruby
22
- renderer Retter::Renderers::PygmentsRenderer
23
- ```
24
- EOM
25
-
26
- s.files = `git ls-files`.split("\n")
27
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
28
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
29
- s.require_paths = ["lib"]
30
-
31
- s.add_runtime_dependency 'thor', ['>= 0.14.6']
32
- s.add_runtime_dependency 'builder', ['>= 3.0.0']
33
- s.add_runtime_dependency 'redcarpet', ['>= 2.0.0b3']
34
- s.add_runtime_dependency 'coderay', ['>= 0.9.8']
35
- s.add_runtime_dependency 'pygments.rb', ['>= 0.2.7']
36
- s.add_runtime_dependency 'nokogiri', ['>= 1.5.0']
37
- s.add_runtime_dependency 'launchy', ['>= 2.0.5']
38
- s.add_runtime_dependency 'haml', ['>= 3.1.3']
39
- s.add_runtime_dependency 'tilt', ['>= 1.1.3']
40
- s.add_runtime_dependency 'bundler', ['>= 1.0']
41
- s.add_runtime_dependency 'grit', ['>= 2.4.1']
42
- s.add_runtime_dependency 'chronic', ['>= 0.6.7']
43
- s.add_runtime_dependency 'activesupport', ['>= 3.1.0']
44
-
45
- # XXX for ActiveSupport dependency
46
- s.add_runtime_dependency 'rack', ['>= 1.4.1']
47
- s.add_runtime_dependency 'i18n', ['>= 0.6.0']
48
-
49
- s.add_development_dependency 'rake', ['>= 0.9.2']
50
- s.add_development_dependency 'ir_b', ['>= 1.4.0']
51
- s.add_development_dependency 'tapp', ['>= 1.1.0']
52
- s.add_development_dependency 'rspec', ['>= 2.6.0']
53
- s.add_development_dependency 'fuubar', ['>= 0.0.6']
54
- s.add_development_dependency 'simplecov', ['>= 0.5.3']
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'retter/version'
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = 'retter'
7
+ gem.version = Retter::VERSION
8
+ gem.authors = ['hibariya', 'uzura29']
9
+ gem.email = ['celluloid.key@gmail.com']
10
+ gem.homepage = 'https://github.com/hibariya/retter'
11
+ gem.summary = %q{Flyweight diary workflow}
12
+ gem.description = %q{Flyweight diary workflow. ruby-1.9.2 or later is required.}
13
+
14
+ gem.files = `git ls-files`.split("\n")
15
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ gem.require_paths = ['lib']
18
+
19
+ gem.required_ruby_version = '>= 1.9.1'
20
+
21
+ gem.add_runtime_dependency 'thor', ['>= 0.15.2']
22
+ gem.add_runtime_dependency 'builder', ['>= 3.0.0']
23
+ gem.add_runtime_dependency 'redcarpet', ['>= 2.1.1']
24
+ gem.add_runtime_dependency 'coderay', ['>= 1.0.7']
25
+ gem.add_runtime_dependency 'pygments.rb', ['>= 0.2.13']
26
+ gem.add_runtime_dependency 'nokogiri', ['>= 1.5.3']
27
+ gem.add_runtime_dependency 'launchy', ['>= 2.1.0']
28
+ gem.add_runtime_dependency 'haml', ['>= 3.1.6']
29
+ gem.add_runtime_dependency 'tilt', ['>= 1.3.3']
30
+ gem.add_runtime_dependency 'bundler', ['>= 1.1.4']
31
+ gem.add_runtime_dependency 'grit', ['>= 2.5.0']
32
+ gem.add_runtime_dependency 'chronic', ['>= 0.6.7']
33
+ gem.add_runtime_dependency 'activesupport', ['>= 3.2.5']
34
+
35
+ # XXX for ActiveSupport dependencies
36
+ gem.add_runtime_dependency 'rack', ['>= 1.4.1']
37
+ gem.add_runtime_dependency 'i18n', ['>= 0.6.0']
38
+
39
+ gem.add_development_dependency 'rake', ['>= 0.9.2']
40
+ gem.add_development_dependency 'ir_b', ['>= 1.5.0']
41
+ gem.add_development_dependency 'tapp', ['>= 1.3.1']
42
+ gem.add_development_dependency 'rspec', ['>= 2.10.0']
43
+ gem.add_development_dependency 'fuubar', ['>= 1.0.0']
44
+ gem.add_development_dependency 'simplecov', ['>= 0.6.4']
45
+ gem.add_development_dependency 'delorean', ['>= 2.0.0']
55
46
  end
@@ -3,15 +3,25 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe 'Retter::Command#callback', clean: :all do
6
- before do
7
- Retter.config.after(:edit) { commit }
6
+ context 'invoke with proc' do
7
+ specify 'callback should called' do
8
+ command.should_receive(:commit)
8
9
 
9
- command.stub!(:options) { {after: :edit} }
10
+ invoke_command :callback, after: :edit do |config|
11
+ config.after :edit do
12
+ commit
13
+ end
14
+ end
15
+ end
10
16
  end
11
17
 
12
- specify 'callback should called' do
13
- command.should_receive(:commit)
18
+ context 'invoke with symbol' do
19
+ specify 'callback should called' do
20
+ command.should_receive(:commit)
14
21
 
15
- command.callback
22
+ invoke_command :callback, after: :edit do |config|
23
+ config.after :edit, :commit
24
+ end
25
+ end
16
26
  end
17
27
  end
@@ -0,0 +1,20 @@
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'Retter::Command#clean', clean: :all do
6
+ let(:cache_path) { %(#{Retter::Site.config.cache.cache_path}/*) }
7
+
8
+ before do
9
+ write_to_wip_file 'hi'
10
+
11
+ invoke_command :rebind
12
+ flunk if Dir.glob(cache_path).empty?
13
+
14
+ invoke_command :clean
15
+ end
16
+
17
+ subject { Dir.glob(cache_path) }
18
+
19
+ it { should be_empty }
20
+ end
@@ -4,22 +4,25 @@ require 'spec_helper'
4
4
  require 'grit'
5
5
 
6
6
  describe 'Retter::Command#commit', clean: :all do
7
- let(:repo) { Grit::Repo.new(Retter.config.retter_home) }
7
+ let(:retter_home) { Retter::Site.config.retter_home }
8
+ let(:repo) { Grit::Repo.new(retter_home) }
8
9
  let(:article) { '今日の記事' }
9
10
 
10
11
  before do
11
12
  command.stub!(:say) { true }
12
- wip_file.open('w') {|f| f.puts article }
13
- command.rebind
14
13
 
15
- Grit::Repo.init Retter.config.retter_home.to_path
14
+ write_to_wip_file article
15
+
16
+ invoke_command :rebind
17
+
18
+ Grit::Repo.init retter_home.to_path
16
19
  end
17
20
 
18
21
  context 'with no options' do
19
22
  before do
20
- command.should_receive(:invoke_after).with(:commit)
23
+ command.should_receive(:after_callback).with(:commit)
21
24
 
22
- command.commit
25
+ invoke_command :commit
23
26
  end
24
27
 
25
28
  subject { repo.commits.first }
@@ -28,14 +31,10 @@ describe 'Retter::Command#commit', clean: :all do
28
31
  end
29
32
 
30
33
  context 'with silent option' do
31
- before do
32
- command.stub!(:options) { {silent: true} }
33
- end
34
-
35
34
  specify 'callback should not called' do
36
- command.should_not_receive(:invoke_after)
35
+ command.should_not_receive(:after_callback).with(:commit)
37
36
 
38
- command.commit
37
+ invoke_command :commit, silent: :true
39
38
  end
40
39
  end
41
40
  end
@@ -5,23 +5,25 @@ require 'spec_helper'
5
5
  describe 'Retter::Command#edit', clean: :all do
6
6
  context 'no options' do
7
7
  before do
8
- command.should_receive(:invoke_after).with(:edit)
9
- command.edit
8
+ command.should_receive(:after_callback).with(:edit)
9
+
10
+ invoke_command :edit
10
11
  end
11
12
 
12
13
  it { wip_file.should written }
13
14
  end
14
15
 
15
16
  context 'after edit and rebind (no options)' do
16
- let(:today) { '20110101' }
17
- let(:today_entry) { Retter.entries.detect_by_string(today) }
17
+ let(:date_str) { '2011/01/01' }
18
+ let(:today_entry) { find_entry_by_string(date_str) }
18
19
 
19
20
  before do
20
- stub_time today
21
- today_entry.pathname.open('w') { |f| f.puts 'written' }
22
- command.rebind
21
+ time_travel_to date_str
22
+
23
+ today_entry.path.open('w') { |f| f.puts 'written' }
23
24
 
24
- command.edit
25
+ invoke_command :rebind
26
+ invoke_command :edit
25
27
  end
26
28
 
27
29
  specify 'wip file should not be written' do
@@ -30,17 +32,14 @@ describe 'Retter::Command#edit', clean: :all do
30
32
  end
31
33
 
32
34
  context 'with date (YYYYMMDD) option' do
33
- let(:date_str) { '20110101' }
34
- let(:date) { Date.parse(date_str) }
35
-
36
35
  before do
37
- command.edit date_str
36
+ invoke_command :edit, '20110101'
38
37
  end
39
38
 
40
39
  it { wip_file.should_not written }
41
40
 
42
41
  describe 'date file' do
43
- subject { Retter.entries.retter_file(date) }
42
+ subject { markdown_file('20110101' ) }
44
43
 
45
44
  it { should written }
46
45
  end
@@ -48,15 +47,13 @@ describe 'Retter::Command#edit', clean: :all do
48
47
 
49
48
  context 'with date (1.day.ago) option' do
50
49
  before do
51
- stub_time '2011/04/02'
50
+ time_travel_to '2011/04/02'
52
51
 
53
- command.edit '1.day.ago'
52
+ invoke_command :edit, '1.day.ago'
54
53
  end
55
54
 
56
55
  describe 'target date file' do
57
- let(:one_day_ago) { Date.parse('2011/04/01') }
58
-
59
- subject { Retter.entries.retter_file(one_day_ago) }
56
+ subject { markdown_file('2011/04/01') }
60
57
 
61
58
  it { should written }
62
59
  end
@@ -64,33 +61,29 @@ describe 'Retter::Command#edit', clean: :all do
64
61
 
65
62
  context 'with date (yesterday) option' do
66
63
  before do
67
- stub_time '2011/04/02'
64
+ time_travel_to '2011/04/02'
68
65
 
69
- command.edit 'yesterday'
66
+ invoke_command :edit, 'yesterday'
70
67
  end
71
68
 
72
69
  describe 'target date file' do
73
- let(:yesterday) { Date.parse('2011/04/01') }
74
-
75
- subject { Retter.entries.retter_file(yesterday) }
70
+ subject { markdown_file('2011/04/01') }
76
71
 
77
72
  it { should written }
78
73
  end
79
74
  end
80
75
 
81
76
  context 'with filename (20110401.md) option' do
82
- let(:a_day) { Date.parse('20110401') }
83
-
84
77
  before do
85
- FileUtils.touch Retter.entries.retter_file(a_day)
78
+ FileUtils.touch markdown_file('20110401')
86
79
 
87
- Retter.reset! # XXX
80
+ Retter::Site.reset! # XXX
88
81
 
89
- command.edit '20110401.md'
82
+ invoke_command :edit, '20110401.md'
90
83
  end
91
84
 
92
85
  describe 'target date file' do
93
- subject { Retter.entries.retter_file(a_day) }
86
+ subject { markdown_file('20110401') }
94
87
 
95
88
  it { should written }
96
89
  end
@@ -98,30 +91,27 @@ describe 'Retter::Command#edit', clean: :all do
98
91
 
99
92
  context 'with no exist filename option' do
100
93
  it {
101
- -> { command.edit '19850126.md' }.should raise_error(Retter::EntryLoadError)
94
+ -> { invoke_command :edit, '19850126.md' }.should raise_error(Retter::EntryLoadError)
102
95
  }
103
96
  end
104
97
 
105
98
  context 'with filename (today.md) option' do
106
99
  before do
107
- FileUtils.touch Retter.config.wip_file.to_path
100
+ FileUtils.touch wip_file.to_path
108
101
 
109
- command.edit 'today.md'
102
+ invoke_command :edit, 'today.md'
110
103
  end
111
104
 
112
105
  describe 'target file' do
113
- subject { Retter.config.wip_file }
114
-
115
- it { should written }
106
+ it { wip_file.should written }
116
107
  end
117
108
  end
118
109
 
119
110
  context 'with silent option' do
120
111
  before do
121
- command.stub!(:options) { {silent: true} }
112
+ command.should_not_receive(:after_callback)
122
113
 
123
- command.should_not_receive(:invoke_after)
124
- command.edit
114
+ invoke_command :edit, silent: true
125
115
  end
126
116
 
127
117
  it { wip_file.should written }
@@ -5,7 +5,7 @@ require 'spec_helper'
5
5
  describe 'Retter::Command#list', clean: :all do
6
6
  context 'happy case' do
7
7
  before do
8
- Retter.entries.retter_file(Date.parse('20110101')).open('w') do |f|
8
+ markdown_file('20110101').open('w') do |f|
9
9
  f.puts <<-EOM
10
10
  # 朝11時
11
11
 
@@ -17,7 +17,7 @@ describe 'Retter::Command#list', clean: :all do
17
17
  EOM
18
18
  end
19
19
 
20
- Retter.entries.retter_file(Date.parse('20110222')).open('w') do |f|
20
+ markdown_file('20110222').open('w') do |f|
21
21
  f.puts <<-EOM
22
22
  # 朝11時30分
23
23
 
@@ -29,10 +29,10 @@ describe 'Retter::Command#list', clean: :all do
29
29
  EOM
30
30
  end
31
31
 
32
- Retter.reset! # XXX
32
+ Retter::Site.reset! # XXX
33
33
  end
34
34
 
35
- subject { capture(:stdout) { command.list }.split(/\n+/) }
35
+ subject { capture(:stdout) { invoke_command :list }.split(/\n+/) }
36
36
 
37
37
  its([0]) { should match /\[e0\]\s+2011\-02\-22/ }
38
38
  its([1]) { should match /朝11時30分, 夜1時30分/ }
@@ -5,8 +5,8 @@ require 'launchy'
5
5
 
6
6
  describe 'Retter::Command#open', clean: :all do
7
7
  specify 'should be open application' do
8
- Launchy.should_receive(:open).with(Retter.config.retter_home.join('index.html').to_path)
8
+ Launchy.should_receive(:open).with(generated_file('index.html').to_path)
9
9
 
10
- command.open
10
+ invoke_command :open
11
11
  end
12
12
  end
@@ -4,9 +4,7 @@ require 'spec_helper'
4
4
  require 'launchy'
5
5
 
6
6
  describe 'Retter::Command#preview', clean: :all do
7
- def preview_html
8
- Retter.config.retter_home.join('.preview.html').read
9
- end
7
+ let(:preview_html) { generated_file('.preview.html').read }
10
8
 
11
9
  before do
12
10
  Launchy.should_receive(:open).with(anything)
@@ -14,9 +12,9 @@ describe 'Retter::Command#preview', clean: :all do
14
12
 
15
13
  context 'no options' do
16
14
  before do
17
- wip_file.open('w') {|f| f.puts 'w00t!' }
15
+ write_to_wip_file 'w00t!'
18
16
 
19
- command.preview
17
+ invoke_command :preview
20
18
  end
21
19
 
22
20
  subject { texts_of(preview_html, 'article p') }
@@ -25,21 +23,18 @@ describe 'Retter::Command#preview', clean: :all do
25
23
  end
26
24
 
27
25
  context 'with date option' do
28
- let(:date_str) { '20110101' }
29
- let(:date_file) { Retter.entries.retter_file(Date.parse(date_str)) }
26
+ let(:date_file) { markdown_file('20110101') }
30
27
 
31
28
  before do
32
- wip_file.open('w') {|f| f.puts 'w00t!' }
29
+ write_to_wip_file 'w00t!'
33
30
  date_file.open('w') {|f| f.puts 'preview me' }
34
31
 
35
- command.stub!(:options) { {date: date_str} }
36
-
37
- command.preview
32
+ invoke_command :preview, date: '20110101'
38
33
  end
39
34
 
40
35
  subject { texts_of(preview_html, 'article p') }
41
36
 
42
37
  it { should_not include 'w00t!' }
43
- it { should include 'preview me' }
38
+ it { should include 'preview me' }
44
39
  end
45
40
  end