retter 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog.md +53 -0
- data/README.md +39 -7
- data/bin/retter +1 -1
- data/lib/retter/command.rb +106 -97
- data/lib/retter/config.rb +54 -76
- data/lib/retter/configurable.rb +26 -0
- data/lib/retter/entries.rb +28 -26
- data/lib/retter/entry.rb +76 -74
- data/lib/retter/generator/skel/Retterfile +26 -17
- data/lib/retter/page/view_helper.rb +5 -5
- data/lib/retter/page.rb +8 -6
- data/lib/retter/pages/article.rb +37 -35
- data/lib/retter/pages/entries.rb +15 -0
- data/lib/retter/pages/entry.rb +25 -22
- data/lib/retter/pages/feed.rb +35 -33
- data/lib/retter/pages/index.rb +9 -7
- data/lib/retter/pages/profile.rb +9 -7
- data/lib/retter/pages.rb +50 -13
- data/lib/retter/preprint.rb +5 -5
- data/lib/retter/renderers.rb +0 -1
- data/lib/retter/repository.rb +5 -4
- data/lib/retter/version.rb +1 -1
- data/lib/retter.rb +20 -24
- data/retter.gemspec +3 -1
- data/spec/bin/fake_editor +3 -0
- data/spec/command/callback_spec.rb +1 -1
- data/spec/command/commit_spec.rb +2 -2
- data/spec/command/edit_spec.rb +9 -7
- data/spec/command/invoke_after_spec.rb +2 -2
- data/spec/command/list_spec.rb +4 -2
- data/spec/command/open_spec.rb +1 -1
- data/spec/command/preview_spec.rb +2 -2
- data/spec/command/rebind_spec.rb +50 -10
- data/spec/spec_helper.rb +11 -6
- data/spec/support/example_group_helper.rb +1 -9
- metadata +68 -43
- data/CHANGELOG.md +0 -21
- data/lib/retter/pages/archive.rb +0 -13
data/ChangeLog.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# 0.2.1
|
2
|
+
|
3
|
+
## Features
|
4
|
+
|
5
|
+
### Multiple template engine support.
|
6
|
+
|
7
|
+
To change, remove existing template and create new template (e.g. retter.html.haml -> retter.html.erb).
|
8
|
+
|
9
|
+
### Skipping page binding.
|
10
|
+
|
11
|
+
You can skip following pages bind.
|
12
|
+
|
13
|
+
* profile.html
|
14
|
+
* entries.html
|
15
|
+
* feed.rss
|
16
|
+
|
17
|
+
If you want, add `allow_binding` configuration to Retterfile.
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
# skip all pages
|
21
|
+
allow_binding :none
|
22
|
+
|
23
|
+
# allow only entries.html and feed.html
|
24
|
+
allow_binding [:profile, :entries, :feed]
|
25
|
+
```
|
26
|
+
|
27
|
+
## Bugfix
|
28
|
+
|
29
|
+
### Fix cache bugs.
|
30
|
+
|
31
|
+
Retter creates cache directory if not exists.
|
32
|
+
|
33
|
+
# 0.2.0
|
34
|
+
|
35
|
+
## Features
|
36
|
+
|
37
|
+
Pygments Support.
|
38
|
+
|
39
|
+
Pygments syntax highlight is now available.
|
40
|
+
To use, add a following line to Retterfile.
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
renderer Retter::Renderers::PygmentsRenderer
|
44
|
+
```
|
45
|
+
|
46
|
+
## Improves
|
47
|
+
|
48
|
+
* Improved boot overhead of all command.
|
49
|
+
* Improved wait time for rebind (bind) command by cache.
|
50
|
+
|
51
|
+
# 0.0.1
|
52
|
+
|
53
|
+
It's first release.
|
data/README.md
CHANGED
@@ -203,14 +203,14 @@ In Retterfile:
|
|
203
203
|
$ retter callback --after edit
|
204
204
|
~~~~
|
205
205
|
|
206
|
-
|
206
|
+
# Install DISQUS (Comment tool)
|
207
207
|
|
208
|
-
|
208
|
+
## Prepare
|
209
209
|
|
210
210
|
1. Create DISQUS Account
|
211
211
|
2. Add new site for retter
|
212
212
|
|
213
|
-
|
213
|
+
## Install
|
214
214
|
|
215
215
|
First, Add your `disqus_shortname` to Retterfile.
|
216
216
|
|
@@ -239,12 +239,22 @@ To use, add a following line to Retterfile.
|
|
239
239
|
renderer Retter::Renderers::PygmentsRenderer
|
240
240
|
```
|
241
241
|
|
242
|
-
|
242
|
+
# Remove caches
|
243
|
+
|
244
|
+
When change the renderer, you have to remove cache files.
|
245
|
+
Cache files is in `tmp/cache`.
|
246
|
+
Please remove these files manually.
|
247
|
+
|
248
|
+
```
|
249
|
+
$ rm -rf tmp/cache/*
|
250
|
+
```
|
251
|
+
|
252
|
+
# Built-in themes
|
243
253
|
|
244
254
|
Retter has some themes.
|
245
255
|
You can switch the theme by replacing stylesheet.
|
246
256
|
|
247
|
-
|
257
|
+
## Default
|
248
258
|
|
249
259
|
~~~~haml
|
250
260
|
%link{href: '/stylesheets/default.css', media: 'screen', rel: 'stylesheet', type: 'text/css'}
|
@@ -252,7 +262,7 @@ You can switch the theme by replacing stylesheet.
|
|
252
262
|
|
253
263
|
![Default](http://hibariya.github.com/images/theme_samples/retter_default.jpg)
|
254
264
|
|
255
|
-
|
265
|
+
## Orange
|
256
266
|
|
257
267
|
~~~~haml
|
258
268
|
%link{href: '/stylesheets/orange.css', media: 'screen', rel: 'stylesheet', type: 'text/css'}
|
@@ -260,7 +270,7 @@ You can switch the theme by replacing stylesheet.
|
|
260
270
|
|
261
271
|
![Orange](http://hibariya.github.com/images/theme_samples/retter_orange.jpg)
|
262
272
|
|
263
|
-
|
273
|
+
# HTML Layout
|
264
274
|
|
265
275
|
To customize layout, edit following files.
|
266
276
|
|
@@ -274,6 +284,28 @@ layouts
|
|
274
284
|
`-- retter.html.haml # Basic layout
|
275
285
|
~~~~
|
276
286
|
|
287
|
+
# Skipping page binding
|
288
|
+
|
289
|
+
You can skip following pages bind.
|
290
|
+
|
291
|
+
* profile.html
|
292
|
+
* entries.html
|
293
|
+
* feed.rss
|
294
|
+
|
295
|
+
If you want, add `allow_binding` configuration to Retterfile.
|
296
|
+
|
297
|
+
```ruby
|
298
|
+
# skip all pages
|
299
|
+
allow_binding :none
|
300
|
+
|
301
|
+
# allow only entries.html and feed.html
|
302
|
+
allow_binding [:profile, :entries, :feed]
|
303
|
+
```
|
304
|
+
|
305
|
+
# Other template engines
|
306
|
+
|
307
|
+
If you want change the template engine, remove existing template and create new template (e.g. retter.html.haml to retter.html.erb).
|
308
|
+
|
277
309
|
# LICENSE
|
278
310
|
|
279
311
|
The MIT License
|
data/bin/retter
CHANGED
data/lib/retter/command.rb
CHANGED
@@ -3,132 +3,140 @@
|
|
3
3
|
require 'thor'
|
4
4
|
require 'launchy'
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
module Retter
|
7
|
+
class Command < Thor
|
8
|
+
include Stationery
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
map '-v' => :version,
|
11
|
+
'-e' => :edit,
|
12
|
+
'-p' => :preview,
|
13
|
+
'-o' => :open,
|
14
|
+
'-r' => :rebind,
|
15
|
+
'-b' => :bind
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
desc 'edit', 'Open $EDITOR. Write an article with Markdown.'
|
18
|
+
method_options date: :string, key: :string, silent: :boolean
|
19
|
+
def edit(identifier = options[:date] || options[:key])
|
20
|
+
entry = entries.detect_by_string(identifier)
|
20
21
|
|
21
|
-
|
22
|
+
system config.editor, entry.path
|
22
23
|
|
23
|
-
|
24
|
-
|
24
|
+
invoke_after :edit unless silent?
|
25
|
+
end
|
25
26
|
|
26
|
-
|
27
|
+
default_task :edit
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
desc 'preview', 'Preview the draft article (browser will open).'
|
30
|
+
method_options date: :string, key: :string
|
31
|
+
def preview(identifier = options[:date] || options[:key])
|
32
|
+
preprint = Preprint.new
|
33
|
+
entry = entries.detect_by_string(identifier)
|
32
34
|
|
33
|
-
|
35
|
+
preprint.print entry
|
34
36
|
|
35
|
-
|
36
|
-
|
37
|
+
Launchy.open preprint.path
|
38
|
+
end
|
37
39
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
40
|
+
desc 'open', 'Open your (static) site top page (browser will open).'
|
41
|
+
def open
|
42
|
+
index_page = Pages::Index.new
|
43
|
+
|
44
|
+
Launchy.open index_page.path
|
45
|
+
end
|
42
46
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
+
desc 'rebind', 'Bind the draft article, re-generate all html pages.'
|
48
|
+
method_options silent: :boolean
|
49
|
+
def rebind
|
50
|
+
entries.commit_wip_entry!
|
47
51
|
|
48
|
-
|
52
|
+
pages.bind!
|
49
53
|
|
50
|
-
|
51
|
-
|
52
|
-
|
54
|
+
unless silent?
|
55
|
+
invoke_after :bind
|
56
|
+
invoke_after :rebind
|
57
|
+
end
|
53
58
|
end
|
54
|
-
end
|
55
59
|
|
56
|
-
|
57
|
-
|
58
|
-
|
60
|
+
desc 'bind', 'Alias of rebind'
|
61
|
+
method_options silent: :boolean
|
62
|
+
alias_method :bind, :rebind
|
59
63
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
64
|
+
desc 'commit', "cd $RETTER_HOME && git add . && git commit -m 'Retter commit'"
|
65
|
+
method_options silent: :boolean
|
66
|
+
def commit
|
67
|
+
Repository.open config.retter_home do |git|
|
68
|
+
say git.add(config.retter_home), :green
|
69
|
+
say git.commit_all('Retter commit'), :green
|
70
|
+
end
|
67
71
|
|
68
|
-
|
69
|
-
|
72
|
+
invoke_after :commit unless silent?
|
73
|
+
end
|
70
74
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
75
|
+
desc 'list', 'List retters'
|
76
|
+
def list
|
77
|
+
entries.each_with_index do |entry, n|
|
78
|
+
say "[e#{n}] #{entry.date}"
|
79
|
+
say " #{entry.articles.map(&:title).join(', ')}"
|
80
|
+
say
|
81
|
+
end
|
77
82
|
end
|
78
|
-
end
|
79
83
|
|
80
|
-
|
81
|
-
|
82
|
-
|
84
|
+
desc 'home', 'Open a new shell in $RETTER_HOME'
|
85
|
+
def home
|
86
|
+
Dir.chdir config.retter_home.to_path
|
83
87
|
|
84
|
-
|
85
|
-
say 'bye', :green
|
86
|
-
end
|
88
|
+
system config.shell
|
87
89
|
|
88
|
-
|
89
|
-
|
90
|
-
def callback
|
91
|
-
invoke_after options[:after].intern
|
92
|
-
end
|
90
|
+
say 'bye', :green
|
91
|
+
end
|
93
92
|
|
94
|
-
|
95
|
-
|
93
|
+
desc 'callback', 'Call a callback process only'
|
94
|
+
method_options after: :string
|
95
|
+
def callback
|
96
|
+
invoke_after options[:after].intern
|
97
|
+
end
|
96
98
|
|
97
|
-
|
98
|
-
|
99
|
+
desc 'new', 'Create a new site'
|
100
|
+
def new; end
|
99
101
|
|
100
|
-
|
101
|
-
|
102
|
-
say Retter::Command.usage, :green
|
103
|
-
end
|
102
|
+
desc 'gen', 'Generate initial files'
|
103
|
+
def gen; end
|
104
104
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
105
|
+
desc 'usage', 'Show usage.'
|
106
|
+
def usage
|
107
|
+
say Command.usage, :green
|
108
|
+
end
|
109
109
|
|
110
|
-
|
110
|
+
desc 'version', 'Show version.'
|
111
|
+
def version
|
112
|
+
say "Retter version #{VERSION}"
|
113
|
+
end
|
111
114
|
|
112
|
-
|
113
|
-
!options[:silent].nil?
|
114
|
-
end
|
115
|
+
private
|
115
116
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
instance_eval &callback
|
123
|
-
when Symbol
|
124
|
-
invoke callback
|
125
|
-
else
|
126
|
-
raise ArgumentError
|
117
|
+
def pages
|
118
|
+
@pages ||= Pages.new
|
119
|
+
end
|
120
|
+
|
121
|
+
def silent?
|
122
|
+
!options[:silent].nil?
|
127
123
|
end
|
128
|
-
end
|
129
124
|
|
130
|
-
|
131
|
-
|
125
|
+
def invoke_after(name)
|
126
|
+
callback = config.after_callback(name)
|
127
|
+
|
128
|
+
case callback
|
129
|
+
when Proc
|
130
|
+
instance_eval &callback
|
131
|
+
when Symbol
|
132
|
+
invoke callback
|
133
|
+
else
|
134
|
+
# noop
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def self.usage
|
139
|
+
<<-EOM
|
132
140
|
Usage:
|
133
141
|
# 1. Startup
|
134
142
|
cd /path/to/dir
|
@@ -175,6 +183,7 @@ Usage:
|
|
175
183
|
retter open # Open your (static) site top page (browser will open).
|
176
184
|
|
177
185
|
See also: https://github.com/hibariya/retter
|
178
|
-
|
186
|
+
EOM
|
187
|
+
end
|
179
188
|
end
|
180
189
|
end
|
data/lib/retter/config.rb
CHANGED
@@ -1,116 +1,94 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
3
|
require 'active_support/cache'
|
4
|
+
require 'forwardable'
|
5
|
+
require 'fileutils'
|
4
6
|
|
5
7
|
module Retter
|
6
8
|
class EnvError < RetterError; end
|
7
9
|
|
8
10
|
class Config
|
9
|
-
|
10
|
-
:editor,
|
11
|
-
:shell,
|
12
|
-
:renderer,
|
13
|
-
:cache,
|
14
|
-
:title,
|
15
|
-
:description,
|
16
|
-
:url,
|
17
|
-
:author,
|
18
|
-
:retters_dir,
|
19
|
-
:wip_file,
|
20
|
-
:layouts_dir,
|
21
|
-
:layout_file,
|
22
|
-
:profile_layout_file,
|
23
|
-
:entry_layout_file,
|
24
|
-
:article_layout_file,
|
25
|
-
:entries_layout_file,
|
26
|
-
:index_layout_file,
|
27
|
-
:entries_dir,
|
28
|
-
:profile_file,
|
29
|
-
:index_file,
|
30
|
-
:entries_file,
|
31
|
-
:feed_file
|
32
|
-
] + [ # extras
|
33
|
-
:disqus_shortname
|
34
|
-
]
|
11
|
+
extend Forwardable
|
35
12
|
|
36
|
-
|
37
|
-
|
38
|
-
def #{att}(val = nil)
|
39
|
-
val ? @options[:#{att}] = val : @options[:#{att}]
|
40
|
-
end
|
41
|
-
EOM
|
42
|
-
end
|
13
|
+
def_delegators Entries, :renderer, :retters_dir, :wip_file
|
14
|
+
def_delegators Pages, :layouts_dir, :entries_dir, :allow_binding
|
43
15
|
|
44
16
|
attr_reader :retter_home
|
45
17
|
|
46
18
|
def initialize(env)
|
47
|
-
@env
|
19
|
+
@env = env
|
48
20
|
@after_callbacks = {}
|
21
|
+
@attributes = {}
|
49
22
|
|
50
23
|
detect_retter_home
|
51
|
-
|
52
|
-
raise Retter::EnvError, 'Set $RETTER_HOME and $EDITOR, first.'
|
53
|
-
end
|
24
|
+
environments_required
|
54
25
|
|
55
26
|
@retter_home = Pathname.new(@env['RETTER_HOME'])
|
56
27
|
load_defaults
|
57
28
|
load_retterfile_if_exists
|
58
|
-
rescue
|
59
|
-
$stderr.puts
|
60
|
-
|
29
|
+
rescue EnvError => e
|
30
|
+
$stderr.puts e.message
|
31
|
+
|
32
|
+
say Command.usage, :green
|
61
33
|
|
62
34
|
exit 1
|
63
35
|
end
|
64
36
|
|
65
|
-
def
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
retters_dir retter_home.join('retters/')
|
72
|
-
wip_file retters_dir.join('today.md')
|
73
|
-
layouts_dir retter_home.join('layouts/')
|
74
|
-
layout_file layouts_dir.join('retter.html.haml')
|
75
|
-
profile_layout_file layouts_dir.join('profile.html.haml')
|
76
|
-
entry_layout_file layouts_dir.join('entry.html.haml')
|
77
|
-
article_layout_file layouts_dir.join('article.html.haml')
|
78
|
-
entries_layout_file layouts_dir.join('entries.html.haml')
|
79
|
-
index_layout_file layouts_dir.join('index.html.haml')
|
80
|
-
entries_dir retter_home.join('entries/')
|
81
|
-
profile_file retter_home.join('profile.html')
|
82
|
-
index_file retter_home.join('index.html')
|
83
|
-
entries_file retter_home.join('entries.html')
|
84
|
-
feed_file retter_home.join('entries.rss')
|
37
|
+
def after_callback(name, sym = nil, &block)
|
38
|
+
if callback = sym || block
|
39
|
+
@after_callbacks[name] = callback
|
40
|
+
else
|
41
|
+
@after_callbacks[name]
|
42
|
+
end
|
85
43
|
end
|
86
44
|
|
87
|
-
|
88
|
-
|
89
|
-
|
45
|
+
alias_method :after, :after_callback
|
46
|
+
|
47
|
+
[ # base
|
48
|
+
:editor, :shell, :cache, :title, :description, :url, :author,
|
49
|
+
# extra
|
50
|
+
:disqus_shortname
|
51
|
+
].each do |att|
|
52
|
+
class_eval <<-EOM
|
53
|
+
def #{att}(val = nil)
|
54
|
+
val ? @attributes[:#{att}] = val : @attributes[:#{att}]
|
55
|
+
end
|
56
|
+
EOM
|
90
57
|
end
|
91
58
|
|
59
|
+
private
|
60
|
+
|
92
61
|
def detect_retter_home
|
93
|
-
# TODO こういうの上のディレクトリも見て判断するのを何か参考にして書く
|
94
62
|
@env['RETTER_HOME'] = Dir.pwd if File.exist? 'Retterfile'
|
95
63
|
end
|
96
64
|
|
97
|
-
def
|
98
|
-
|
99
|
-
|
65
|
+
def load_defaults
|
66
|
+
editor @env['EDITOR']
|
67
|
+
shell @env['SHELL']
|
68
|
+
url 'http://example.com'
|
69
|
+
|
70
|
+
renderer Retter::Renderers::CodeRayRenderer
|
71
|
+
retters_dir retter_home.join('retters/')
|
72
|
+
wip_file retters_dir.join('today.md')
|
73
|
+
|
74
|
+
layouts_dir retter_home.join('layouts/')
|
75
|
+
entries_dir retter_home.join('entries/')
|
100
76
|
|
101
|
-
|
102
|
-
|
77
|
+
cache_dir = retter_home.join('tmp/cache')
|
78
|
+
cache ActiveSupport::Cache::FileStore.new(cache_dir.to_path)
|
79
|
+
|
80
|
+
FileUtils.mkdir_p cache_dir.to_path unless cache_dir.directory? # for old versions
|
103
81
|
end
|
104
82
|
|
105
|
-
def
|
106
|
-
|
83
|
+
def load_retterfile_if_exists
|
84
|
+
retterfile = retter_home.join('Retterfile')
|
85
|
+
|
86
|
+
instance_eval retterfile.read, retterfile.to_path if retterfile.exist?
|
107
87
|
end
|
108
88
|
|
109
|
-
def
|
110
|
-
|
111
|
-
|
112
|
-
else
|
113
|
-
@after_callbacks[name]
|
89
|
+
def environments_required
|
90
|
+
unless @env.values_at('EDITOR', 'RETTER_HOME').all?
|
91
|
+
raise EnvError, 'Set $RETTER_HOME and $EDITOR, first.'
|
114
92
|
end
|
115
93
|
end
|
116
94
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module Retter
|
4
|
+
module Configurable
|
5
|
+
def configurable(*names)
|
6
|
+
names.each do |name|
|
7
|
+
define_configurable_method name
|
8
|
+
define_instance_shortcut_method name
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def define_configurable_method(name)
|
13
|
+
instance_eval <<-EOM
|
14
|
+
def #{name}(val = nil)
|
15
|
+
val ? @#{name} = val : @#{name}
|
16
|
+
end
|
17
|
+
EOM
|
18
|
+
end
|
19
|
+
|
20
|
+
def define_instance_shortcut_method(name)
|
21
|
+
define_method name do
|
22
|
+
self.class.send(name)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|