retter 0.2.0 → 0.2.1

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/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
- ## Install DISQUS (Comment tool)
206
+ # Install DISQUS (Comment tool)
207
207
 
208
- ### Prepare
208
+ ## Prepare
209
209
 
210
210
  1. Create DISQUS Account
211
211
  2. Add new site for retter
212
212
 
213
- ### Install
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
- ## Built-in themes
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
- ### Default
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
- ### Orange
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
- ## HTML Layout
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
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
5
5
 
6
6
  require 'retter'
7
7
 
8
- Retter.load_config ENV
8
+ Retter.load ENV
9
9
 
10
10
  case ARGV[0]
11
11
  when 'new'
@@ -3,132 +3,140 @@
3
3
  require 'thor'
4
4
  require 'launchy'
5
5
 
6
- class Retter::Command < Thor
7
- include Retter::Stationery
6
+ module Retter
7
+ class Command < Thor
8
+ include Stationery
8
9
 
9
- map '-v' => :version,
10
- '-e' => :edit,
11
- '-p' => :preview,
12
- '-o' => :open,
13
- '-r' => :rebind,
14
- '-b' => :bind
10
+ map '-v' => :version,
11
+ '-e' => :edit,
12
+ '-p' => :preview,
13
+ '-o' => :open,
14
+ '-r' => :rebind,
15
+ '-b' => :bind
15
16
 
16
- desc 'edit', 'Open $EDITOR. Write an article with Markdown.'
17
- method_options date: :string, key: :string, silent: :boolean
18
- def edit(identifier = options[:date] || options[:key])
19
- entry = entries.detect_by_string(identifier)
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
- system "#{config.editor} #{entry.path}"
22
+ system config.editor, entry.path
22
23
 
23
- invoke_after :edit unless silent?
24
- end
24
+ invoke_after :edit unless silent?
25
+ end
25
26
 
26
- default_task :edit
27
+ default_task :edit
27
28
 
28
- desc 'preview', 'Preview the draft article (browser will open).'
29
- method_options date: :string, key: :string
30
- def preview(identifier = options[:date] || options[:key])
31
- entry = entries.detect_by_string(identifier)
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
- preprint.print entry
35
+ preprint.print entry
34
36
 
35
- Launchy.open preprint.path
36
- end
37
+ Launchy.open preprint.path
38
+ end
37
39
 
38
- desc 'open', 'Open your (static) site top page (browser will open).'
39
- def open
40
- Launchy.open pages.index.path
41
- end
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
- desc 'rebind', 'Bind the draft article, re-generate all html pages.'
44
- method_options silent: :boolean
45
- def rebind
46
- entries.commit_wip_entry!
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
- pages.bind!
52
+ pages.bind!
49
53
 
50
- unless silent?
51
- invoke_after :bind
52
- invoke_after :rebind
54
+ unless silent?
55
+ invoke_after :bind
56
+ invoke_after :rebind
57
+ end
53
58
  end
54
- end
55
59
 
56
- desc 'bind', 'Alias of rebind'
57
- method_options silent: :boolean
58
- alias_method :bind, :rebind
60
+ desc 'bind', 'Alias of rebind'
61
+ method_options silent: :boolean
62
+ alias_method :bind, :rebind
59
63
 
60
- desc 'commit', "cd $RETTER_HOME && git add . && git commit -m 'Retter commit'"
61
- method_options silent: :boolean
62
- def commit
63
- repository.open do |git|
64
- say git.add(config.retter_home), :green
65
- say git.commit_all('Retter commit'), :green
66
- end
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
- invoke_after :commit unless silent?
69
- end
72
+ invoke_after :commit unless silent?
73
+ end
70
74
 
71
- desc 'list', 'List retters'
72
- def list
73
- entries.each_with_index do |entry, n|
74
- say "[e#{n}] #{entry.date}"
75
- say " #{entry.articles.map(&:title).join(', ')}"
76
- say
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
- desc 'home', 'Open a new shell in $RETTER_HOME'
81
- def home
82
- Dir.chdir config.retter_home.to_s
84
+ desc 'home', 'Open a new shell in $RETTER_HOME'
85
+ def home
86
+ Dir.chdir config.retter_home.to_path
83
87
 
84
- system %(PS1="(retter) " #{config.shell})
85
- say 'bye', :green
86
- end
88
+ system config.shell
87
89
 
88
- desc 'callback', 'Call a callback process only'
89
- method_options after: :string
90
- def callback
91
- invoke_after options[:after].intern
92
- end
90
+ say 'bye', :green
91
+ end
93
92
 
94
- desc 'new', 'Create a new site'
95
- def new; end
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
- desc 'gen', 'Generate initial files'
98
- def gen; end
99
+ desc 'new', 'Create a new site'
100
+ def new; end
99
101
 
100
- desc 'usage', 'Show usage.'
101
- def usage
102
- say Retter::Command.usage, :green
103
- end
102
+ desc 'gen', 'Generate initial files'
103
+ def gen; end
104
104
 
105
- desc 'version', 'Show version.'
106
- def version
107
- say "Retter version #{Retter::VERSION}"
108
- end
105
+ desc 'usage', 'Show usage.'
106
+ def usage
107
+ say Command.usage, :green
108
+ end
109
109
 
110
- private
110
+ desc 'version', 'Show version.'
111
+ def version
112
+ say "Retter version #{VERSION}"
113
+ end
111
114
 
112
- def silent?
113
- !options[:silent].nil?
114
- end
115
+ private
115
116
 
116
- def invoke_after(name)
117
- callback = config.after(name)
118
- return unless callback
119
-
120
- case callback
121
- when Proc
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
- def self.usage
131
- <<-EOM
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
- EOM
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
- ATTRIBUTES = [
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
- ATTRIBUTES.each do |att|
37
- class_eval <<-EOM
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, @options = env, {}
19
+ @env = env
48
20
  @after_callbacks = {}
21
+ @attributes = {}
49
22
 
50
23
  detect_retter_home
51
- unless env.values_at('EDITOR', 'RETTER_HOME').all?
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 Retter::EnvError
59
- $stderr.puts 'Set $RETTER_HOME and $EDITOR, first.'
60
- say Retter::Command.usage, :green
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 load_defaults
66
- editor @env['EDITOR']
67
- shell @env['SHELL']
68
- renderer Retter::Renderers::CodeRayRenderer
69
- cache ActiveSupport::Cache::FileStore.new(retter_home.join('tmp/cache').to_s)
70
- url 'http://example.com'
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
- def load_retterfile_if_exists
88
- retterfile = retter_home.join('Retterfile')
89
- instance_eval retterfile.read, retterfile.to_s if retterfile.exist?
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 retter_file(date)
98
- retters_dir.join(date ? date.strftime("%Y%m%d.md") : "today.md")
99
- end
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
- def entry_file(date)
102
- entries_dir.join date.strftime('%Y%m%d.html')
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 entry_dir(date)
106
- entries_dir.join date.strftime('%Y%m%d')
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 after(name, sym = nil, &block)
110
- if callback = sym || block
111
- @after_callbacks[name] = callback
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