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.
@@ -1,5 +1,8 @@
1
1
  # coding: utf-8
2
2
 
3
+ require 'haml'
4
+ require 'nokogiri'
5
+
3
6
  module Retter
4
7
  module Page
5
8
  require 'retter/page/view_helper'
@@ -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
@@ -1,5 +1,7 @@
1
1
  # coding: utf-8
2
2
 
3
+ require 'grit'
4
+
3
5
  module Retter
4
6
  class Repository
5
7
  include Retter::Stationery
@@ -1,3 +1,3 @@
1
1
  module Retter
2
- VERSION = '0.1.3'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -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 File.dirname(__FILE__) + '/../spec_helper'
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
- it { command.callback.should }
12
+ specify 'callback should called' do
13
+ command.should_receive(:commit)
14
+
15
+ command.callback
16
+ end
18
17
  end
@@ -1,37 +1,41 @@
1
1
  # coding: utf-8
2
2
 
3
- require File.dirname(__FILE__) + '/../spec_helper'
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
- it { repo.commits.first.message.should == 'Retter commit' }
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
- it { command.commit.should }
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
@@ -1,15 +1,8 @@
1
1
  # coding: utf-8
2
2
 
3
- require File.dirname(__FILE__) + '/../spec_helper'
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 'no options after rebind' do
23
- let(:date_str) { '20110101' }
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
- Date.stub!(:today).and_return(Date.parse(date_str))
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
- it { wip_file.should_not be_exist }
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 be_exist }
40
+ it { wip_file.should_not written }
51
41
 
52
- describe 'target date file' do
53
- subject { retter_config.retter_file(Date.parse(date_str)) }
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
- Time.stub!(:now).and_return(Time.parse('2011/04/02'))
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
- subject { retter_config.retter_file(Date.parse('2011/04/01')) }
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
- Time.stub!(:now).and_return(Time.parse('2011/04/02'))
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
- subject { retter_config.retter_file(Date.parse('2011/04/01')) }
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(Date.parse('20110401'))
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(Date.parse('2011/04/01')) }
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 File.dirname(__FILE__) + '/../spec_helper'
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
- it { command.edit.should }
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
- it { command.edit.should }
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
@@ -1,15 +1,8 @@
1
1
  # coding: utf-8
2
2
 
3
- require File.dirname(__FILE__) + '/../spec_helper'
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|
@@ -1,17 +1,12 @@
1
1
  # coding: utf-8
2
2
 
3
- require File.dirname(__FILE__) + '/../spec_helper'
3
+ require 'spec_helper'
4
+ require 'launchy'
4
5
 
5
6
  describe 'Retter::Command#open', 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
- 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 File.dirname(__FILE__) + '/../spec_helper'
3
+ require 'spec_helper'
4
+ require 'launchy'
4
5
 
5
6
  describe 'Retter::Command#preview', clean: :all do
6
- let(:command) { Retter::Command.new }
7
- let(:preview) { retter_config.retter_home.join('.preview.html').read }
8
- let(:wip_file) { retter_config.wip_file }
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
- Retter.stub!(:config) { retter_config }
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 article }
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(preview, 'article p') }
22
+ subject { texts_of(preview_html, 'article p') }
27
23
 
28
- it { should == [article] }
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 article }
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(preview, 'article p') }
40
+ subject { texts_of(preview_html, 'article p') }
46
41
 
47
- it { should_not be_include('おやすみなさい') }
48
- it { should be_include(article) }
42
+ it { should_not include 'w00t!' }
43
+ it { should include 'preview me' }
49
44
  end
50
45
  end