retter 0.1.3 → 0.2.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 +0 -1
- data/.rspec +1 -0
- data/.travis.yml +1 -2
- data/CHANGELOG.md +21 -0
- data/README.md +111 -180
- data/lib/retter.rb +12 -22
- data/lib/retter/command.rb +4 -2
- data/lib/retter/config.rb +11 -8
- data/lib/retter/entries.rb +32 -25
- data/lib/retter/entry.rb +2 -0
- data/lib/retter/generator/base.rb +2 -0
- data/lib/retter/generator/skel/Retterfile +3 -1
- data/lib/retter/generator/skel/layouts/retter.html.haml +2 -0
- data/lib/retter/generator/skel/stylesheets/orange.css +8 -6
- data/lib/retter/generator/skel/stylesheets/pygments.css +288 -0
- data/lib/retter/page.rb +3 -0
- data/lib/retter/pages/feed.rb +4 -1
- data/lib/retter/renderers.rb +27 -0
- data/lib/retter/repository.rb +2 -0
- data/lib/retter/version.rb +1 -1
- data/retter.gemspec +11 -19
- data/spec/command/callback_spec.rb +6 -7
- data/spec/command/commit_spec.rb +13 -9
- data/spec/command/edit_spec.rb +25 -33
- data/spec/command/invoke_after_spec.rb +11 -11
- data/spec/command/list_spec.rb +1 -8
- data/spec/command/open_spec.rb +4 -9
- data/spec/command/preview_spec.rb +16 -21
- data/spec/command/rebind_spec.rb +61 -18
- data/spec/fixtures/sample.md +295 -0
- data/spec/spec_helper.rb +7 -5
- data/spec/support/example_group_helper.rb +66 -0
- metadata +69 -51
- data/lib/retter/renderer.rb +0 -9
- data/spec/support/config_support.rb +0 -14
- data/spec/support/html_support.rb +0 -9
- data/spec/support/stream_capture.rb +0 -16
data/lib/retter/page.rb
CHANGED
data/lib/retter/pages/feed.rb
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# coding: utf-8
|
|
2
2
|
|
|
3
|
+
require 'builder'
|
|
4
|
+
require 'uri'
|
|
5
|
+
|
|
3
6
|
class Retter::Pages::Feed
|
|
4
7
|
include Retter::Page
|
|
5
8
|
|
|
@@ -32,7 +35,7 @@ class Retter::Pages::Feed
|
|
|
32
35
|
xml.items { xml.rdf(:Seq) { entries.each {|e| xml.rdf:li, :'rdf:resource' => entry_url(e.date) } } }
|
|
33
36
|
end
|
|
34
37
|
|
|
35
|
-
entries.each do |entry|
|
|
38
|
+
entries[0...20].each do |entry| # XXX hardcoding
|
|
36
39
|
xml.item about: entry_url(entry.date) do
|
|
37
40
|
xml.title entry.date.strftime('%Y/%m/%d')
|
|
38
41
|
xml.description { xml.cdata! entry.body }
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'redcarpet'
|
|
4
|
+
require 'pygments'
|
|
5
|
+
require 'coderay'
|
|
6
|
+
require 'digest/sha1'
|
|
7
|
+
require 'set'
|
|
8
|
+
|
|
9
|
+
module Retter
|
|
10
|
+
module Renderers
|
|
11
|
+
class CodeRayRenderer < Redcarpet::Render::HTML
|
|
12
|
+
def block_code(code, lang)
|
|
13
|
+
CodeRay.scan(code, lang ? lang.intern : :plain).div
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
class PygmentsRenderer < Redcarpet::Render::HTML
|
|
18
|
+
LANGUAGES = Set.new(Pygments.lexers.map {|_, l| l[:aliases] }.flatten)
|
|
19
|
+
|
|
20
|
+
def block_code(code, lang)
|
|
21
|
+
lang = LANGUAGES.include?(lang) ? lang : 'text'
|
|
22
|
+
|
|
23
|
+
Pygments.highlight(code, lexer: lang, formatter: 'html', options: {encoding: 'utf-8'})
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
data/lib/retter/repository.rb
CHANGED
data/lib/retter/version.rb
CHANGED
data/retter.gemspec
CHANGED
|
@@ -13,26 +13,14 @@ Gem::Specification.new do |s|
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
s.post_install_message = <<-EOM
|
|
16
|
-
**Important** Some features were added or updated.
|
|
17
|
-
|
|
18
|
-
* DISQUS (comment system) support is now available.
|
|
19
|
-
First, Add your `disqus_shortname` to Retterfile.
|
|
20
|
-
|
|
21
|
-
in Retterfile:
|
|
22
|
-
disqus_shortname 'your_disqus_shortname'
|
|
23
|
-
|
|
24
|
-
Second, Edit templete and paste `render_disqus_comment_form`.
|
|
25
|
-
|
|
26
|
-
in layouts/article.html.haml:
|
|
27
|
-
#comments= render_disqus_comment_form
|
|
28
|
-
|
|
29
|
-
* Filename is now specificable.
|
|
30
|
-
Examples:
|
|
31
|
-
$ retter edit today.md
|
|
32
|
-
$ retter edit 20110101.md
|
|
33
|
-
$ retter preview 20110101.md
|
|
34
|
-
|
|
35
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
|
+
```
|
|
36
24
|
EOM
|
|
37
25
|
|
|
38
26
|
s.files = `git ls-files`.split("\n")
|
|
@@ -44,12 +32,16 @@ Gem::Specification.new do |s|
|
|
|
44
32
|
s.add_runtime_dependency 'builder', ['>= 3.0.0']
|
|
45
33
|
s.add_runtime_dependency 'redcarpet', ['>= 2.0.0b3']
|
|
46
34
|
s.add_runtime_dependency 'coderay', ['>= 0.9.8']
|
|
35
|
+
s.add_runtime_dependency 'pygments.rb', ['>= 0.2.7']
|
|
47
36
|
s.add_runtime_dependency 'nokogiri', ['>= 1.5.0']
|
|
48
37
|
s.add_runtime_dependency 'launchy', ['>= 2.0.5']
|
|
49
38
|
s.add_runtime_dependency 'haml', ['>= 3.1.3']
|
|
50
39
|
s.add_runtime_dependency 'bundler', ['>= 1.0']
|
|
51
40
|
s.add_runtime_dependency 'grit', ['>= 2.4.1']
|
|
52
41
|
s.add_runtime_dependency 'activesupport', ['>= 3.1.0']
|
|
42
|
+
|
|
43
|
+
# XXX for ActiveSupport dependency
|
|
44
|
+
s.add_runtime_dependency 'rack', ['>= 1.4.1']
|
|
53
45
|
s.add_runtime_dependency 'i18n', ['>= 0.6.0']
|
|
54
46
|
|
|
55
47
|
s.add_development_dependency 'rake', ['>= 0.9.2']
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
# coding: utf-8
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require 'spec_helper'
|
|
4
4
|
|
|
5
5
|
describe 'Retter::Command#callback', clean: :all do
|
|
6
|
-
let(:command) { Retter::Command.new }
|
|
7
|
-
|
|
8
6
|
before do
|
|
9
|
-
Retter.stub!(:config) { retter_config }
|
|
10
|
-
|
|
11
7
|
retter_config.after(:edit) { commit }
|
|
12
|
-
command.should_receive(:commit).and_return(true)
|
|
13
8
|
|
|
14
9
|
command.stub!(:options) { {after: :edit} }
|
|
15
10
|
end
|
|
16
11
|
|
|
17
|
-
|
|
12
|
+
specify 'callback should called' do
|
|
13
|
+
command.should_receive(:commit)
|
|
14
|
+
|
|
15
|
+
command.callback
|
|
16
|
+
end
|
|
18
17
|
end
|
data/spec/command/commit_spec.rb
CHANGED
|
@@ -1,37 +1,41 @@
|
|
|
1
1
|
# coding: utf-8
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
require 'grit'
|
|
4
5
|
|
|
5
6
|
describe 'Retter::Command#commit', clean: :all do
|
|
6
|
-
let(:command) { Retter::Command.new }
|
|
7
|
-
let(:wip_file) { retter_config.wip_file }
|
|
8
7
|
let(:repo) { Grit::Repo.new(retter_config.retter_home.to_s) }
|
|
9
8
|
let(:article) { '今日の記事' }
|
|
10
9
|
|
|
11
10
|
before do
|
|
12
|
-
Grit::Repo.init retter_config.retter_home.to_s
|
|
13
|
-
|
|
14
|
-
Retter.stub!(:config) { retter_config }
|
|
15
11
|
command.stub!(:say) { true }
|
|
16
12
|
wip_file.open('w') {|f| f.puts article }
|
|
17
13
|
command.rebind
|
|
14
|
+
|
|
15
|
+
Grit::Repo.init retter_config.retter_home.to_s
|
|
18
16
|
end
|
|
19
17
|
|
|
20
18
|
context 'with no options' do
|
|
21
19
|
before do
|
|
22
20
|
command.should_receive(:invoke_after).with(:commit)
|
|
21
|
+
|
|
23
22
|
command.commit
|
|
24
23
|
end
|
|
25
24
|
|
|
26
|
-
|
|
25
|
+
subject { repo.commits.first }
|
|
26
|
+
|
|
27
|
+
its(:message) { should == 'Retter commit' }
|
|
27
28
|
end
|
|
28
29
|
|
|
29
30
|
context 'with silent option' do
|
|
30
31
|
before do
|
|
31
32
|
command.stub!(:options) { {silent: true} }
|
|
32
|
-
command.should_not_receive(:invoke_after)
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
specify 'callback should not called' do
|
|
36
|
+
command.should_not_receive(:invoke_after)
|
|
37
|
+
|
|
38
|
+
command.commit
|
|
39
|
+
end
|
|
36
40
|
end
|
|
37
41
|
end
|
data/spec/command/edit_spec.rb
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
1
|
# coding: utf-8
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require 'spec_helper'
|
|
4
4
|
|
|
5
5
|
describe 'Retter::Command#edit', clean: :all do
|
|
6
|
-
let(:command) { Retter::Command.new }
|
|
7
|
-
let(:wip_file) { retter_config.wip_file }
|
|
8
|
-
|
|
9
|
-
before do
|
|
10
|
-
Retter.stub!(:config) { retter_config }
|
|
11
|
-
end
|
|
12
|
-
|
|
13
6
|
context 'no options' do
|
|
14
7
|
before do
|
|
15
8
|
command.should_receive(:invoke_after).with(:edit)
|
|
@@ -19,38 +12,35 @@ describe 'Retter::Command#edit', clean: :all do
|
|
|
19
12
|
it { wip_file.should written }
|
|
20
13
|
end
|
|
21
14
|
|
|
22
|
-
context '
|
|
23
|
-
let(:
|
|
15
|
+
context 'after edit and rebind (no options)' do
|
|
16
|
+
let(:today) { '20110101' }
|
|
17
|
+
let(:today_entry) { Retter.entries.detect_by_string(today) }
|
|
24
18
|
|
|
25
19
|
before do
|
|
26
|
-
|
|
20
|
+
stub_time today
|
|
21
|
+
today_entry.pathname.open('w') { |f| f.puts 'written' }
|
|
22
|
+
command.rebind
|
|
27
23
|
|
|
28
24
|
command.edit
|
|
29
|
-
command.bind
|
|
30
|
-
command.edit
|
|
31
25
|
end
|
|
32
26
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
describe "today's file" do
|
|
36
|
-
subject { retter_config.retters_dir.join("#{date_str}.md") }
|
|
37
|
-
|
|
38
|
-
it { should written }
|
|
27
|
+
specify 'wip file should not be written' do
|
|
28
|
+
wip_file.should_not be_exist
|
|
39
29
|
end
|
|
40
30
|
end
|
|
41
31
|
|
|
42
32
|
context 'with date (YYYYMMDD) option' do
|
|
43
33
|
let(:date_str) { '20110101' }
|
|
34
|
+
let(:date) { Date.parse(date_str) }
|
|
44
35
|
|
|
45
36
|
before do
|
|
46
|
-
command.should_receive(:invoke_after).with(:edit)
|
|
47
37
|
command.edit date_str
|
|
48
38
|
end
|
|
49
39
|
|
|
50
|
-
it { wip_file.should_not
|
|
40
|
+
it { wip_file.should_not written }
|
|
51
41
|
|
|
52
|
-
describe '
|
|
53
|
-
subject { retter_config.retter_file(
|
|
42
|
+
describe 'date file' do
|
|
43
|
+
subject { retter_config.retter_file(date) }
|
|
54
44
|
|
|
55
45
|
it { should written }
|
|
56
46
|
end
|
|
@@ -58,14 +48,15 @@ describe 'Retter::Command#edit', clean: :all do
|
|
|
58
48
|
|
|
59
49
|
context 'with date (1.day.ago) option' do
|
|
60
50
|
before do
|
|
61
|
-
|
|
51
|
+
stub_time '2011/04/02'
|
|
62
52
|
|
|
63
|
-
command.should_receive(:invoke_after).with(:edit)
|
|
64
53
|
command.edit '1.day.ago'
|
|
65
54
|
end
|
|
66
55
|
|
|
67
56
|
describe 'target date file' do
|
|
68
|
-
|
|
57
|
+
let(:one_day_ago) { Date.parse('2011/04/01') }
|
|
58
|
+
|
|
59
|
+
subject { retter_config.retter_file(one_day_ago) }
|
|
69
60
|
|
|
70
61
|
it { should written }
|
|
71
62
|
end
|
|
@@ -73,29 +64,31 @@ describe 'Retter::Command#edit', clean: :all do
|
|
|
73
64
|
|
|
74
65
|
context 'with date (yesterday) option' do
|
|
75
66
|
before do
|
|
76
|
-
|
|
67
|
+
stub_time '2011/04/02'
|
|
77
68
|
|
|
78
|
-
command.should_receive(:invoke_after).with(:edit)
|
|
79
69
|
command.edit 'yesterday'
|
|
80
70
|
end
|
|
81
71
|
|
|
82
72
|
describe 'target date file' do
|
|
83
|
-
|
|
73
|
+
let(:yesterday) { Date.parse('2011/04/01') }
|
|
74
|
+
|
|
75
|
+
subject { retter_config.retter_file(yesterday) }
|
|
84
76
|
|
|
85
77
|
it { should written }
|
|
86
78
|
end
|
|
87
79
|
end
|
|
88
80
|
|
|
89
81
|
context 'with filename (20110401.md) option' do
|
|
82
|
+
let(:a_day) { Date.parse('20110401') }
|
|
83
|
+
|
|
90
84
|
before do
|
|
91
|
-
FileUtils.touch retter_config.retter_file(
|
|
85
|
+
FileUtils.touch retter_config.retter_file(a_day)
|
|
92
86
|
|
|
93
|
-
command.should_receive(:invoke_after).with(:edit)
|
|
94
87
|
command.edit '20110401.md'
|
|
95
88
|
end
|
|
96
89
|
|
|
97
90
|
describe 'target date file' do
|
|
98
|
-
subject { retter_config.retter_file(
|
|
91
|
+
subject { retter_config.retter_file(a_day) }
|
|
99
92
|
|
|
100
93
|
it { should written }
|
|
101
94
|
end
|
|
@@ -111,7 +104,6 @@ describe 'Retter::Command#edit', clean: :all do
|
|
|
111
104
|
before do
|
|
112
105
|
FileUtils.touch retter_config.wip_file.to_s
|
|
113
106
|
|
|
114
|
-
command.should_receive(:invoke_after).with(:edit)
|
|
115
107
|
command.edit 'today.md'
|
|
116
108
|
end
|
|
117
109
|
|
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
# coding: utf-8
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require 'spec_helper'
|
|
4
4
|
|
|
5
5
|
describe 'Retter::Command#invoke_after', clean: :all do
|
|
6
|
-
let(:command) { Retter::Command.new }
|
|
7
|
-
|
|
8
6
|
context 'invoke with proc' do
|
|
9
7
|
before do
|
|
10
|
-
Retter.stub!(:config) { retter_config }
|
|
11
|
-
|
|
12
8
|
retter_config.after(:edit) { commit }
|
|
13
|
-
command.should_receive(:commit).and_return(true)
|
|
14
9
|
end
|
|
15
10
|
|
|
16
|
-
|
|
11
|
+
specify 'callback should called' do
|
|
12
|
+
command.should_receive(:commit)
|
|
13
|
+
|
|
14
|
+
command.edit
|
|
15
|
+
end
|
|
17
16
|
end
|
|
18
17
|
|
|
19
18
|
context 'invoke with symbol' do
|
|
20
19
|
before do
|
|
21
|
-
Retter.stub!(:config) { retter_config }
|
|
22
|
-
|
|
23
20
|
retter_config.after(:edit, :commit)
|
|
24
|
-
command.should_receive(:invoke).with(:commit).and_return(true)
|
|
25
21
|
end
|
|
26
22
|
|
|
27
|
-
|
|
23
|
+
specify 'callback should called' do
|
|
24
|
+
command.should_receive(:invoke).with(:commit)
|
|
25
|
+
|
|
26
|
+
command.edit
|
|
27
|
+
end
|
|
28
28
|
end
|
|
29
29
|
end
|
data/spec/command/list_spec.rb
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
1
|
# coding: utf-8
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require 'spec_helper'
|
|
4
4
|
|
|
5
5
|
describe 'Retter::Command#list', clean: :all do
|
|
6
|
-
let(:command) { Retter::Command.new }
|
|
7
|
-
let(:wip_file) { retter_config.wip_file }
|
|
8
|
-
|
|
9
|
-
before do
|
|
10
|
-
Retter.stub!(:config) { retter_config }
|
|
11
|
-
end
|
|
12
|
-
|
|
13
6
|
context 'happy case' do
|
|
14
7
|
before do
|
|
15
8
|
retter_config.retter_file(Date.parse('20110101')).open('w') do |f|
|
data/spec/command/open_spec.rb
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
# coding: utf-8
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
require 'launchy'
|
|
4
5
|
|
|
5
6
|
describe 'Retter::Command#open', clean: :all do
|
|
6
|
-
|
|
7
|
-
let(:wip_file) { retter_config.wip_file }
|
|
8
|
-
|
|
9
|
-
before do
|
|
10
|
-
Retter.stub!(:config) { retter_config }
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
it 'should be open application' do
|
|
7
|
+
specify 'should be open application' do
|
|
14
8
|
Launchy.should_receive(:open).with(retter_config.index_file.to_s)
|
|
9
|
+
|
|
15
10
|
command.open
|
|
16
11
|
end
|
|
17
12
|
end
|
|
@@ -1,50 +1,45 @@
|
|
|
1
1
|
# coding: utf-8
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
require 'launchy'
|
|
4
5
|
|
|
5
6
|
describe 'Retter::Command#preview', clean: :all do
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
let(:date_file) { retter_config.retter_file(Date.parse(date_str)) }
|
|
7
|
+
def preview_html
|
|
8
|
+
retter_config.retter_home.join('.preview.html').read
|
|
9
|
+
end
|
|
10
10
|
|
|
11
11
|
before do
|
|
12
|
-
|
|
12
|
+
Launchy.should_receive(:open).with(anything)
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
context 'no options' do
|
|
16
|
-
let(:article) { 'w00t!' }
|
|
17
|
-
|
|
18
16
|
before do
|
|
19
|
-
wip_file.open('w') {|f| f.puts
|
|
20
|
-
|
|
21
|
-
Launchy.stub!(:open).with(anything)
|
|
17
|
+
wip_file.open('w') {|f| f.puts 'w00t!' }
|
|
22
18
|
|
|
23
19
|
command.preview
|
|
24
20
|
end
|
|
25
21
|
|
|
26
|
-
subject { texts_of(
|
|
22
|
+
subject { texts_of(preview_html, 'article p') }
|
|
27
23
|
|
|
28
|
-
it { should
|
|
24
|
+
it { should include 'w00t!' }
|
|
29
25
|
end
|
|
30
26
|
|
|
31
|
-
context 'with date' do
|
|
32
|
-
let(:article) { 'おはようございます' }
|
|
27
|
+
context 'with date option' do
|
|
33
28
|
let(:date_str) { '20110101' }
|
|
29
|
+
let(:date_file) { retter_config.retter_file(Date.parse(date_str)) }
|
|
34
30
|
|
|
35
31
|
before do
|
|
36
|
-
wip_file.open('w') {|f| f.puts '
|
|
37
|
-
date_file.open('w') {|f| f.puts
|
|
32
|
+
wip_file.open('w') {|f| f.puts 'w00t!' }
|
|
33
|
+
date_file.open('w') {|f| f.puts 'preview me' }
|
|
38
34
|
|
|
39
|
-
Launchy.stub!(:open).with(anything)
|
|
40
35
|
command.stub!(:options) { {date: date_str} }
|
|
41
36
|
|
|
42
37
|
command.preview
|
|
43
38
|
end
|
|
44
39
|
|
|
45
|
-
subject { texts_of(
|
|
40
|
+
subject { texts_of(preview_html, 'article p') }
|
|
46
41
|
|
|
47
|
-
it { should_not
|
|
48
|
-
it { should
|
|
42
|
+
it { should_not include 'w00t!' }
|
|
43
|
+
it { should include 'preview me' }
|
|
49
44
|
end
|
|
50
45
|
end
|