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.
- data/.travis.yml +1 -1
- data/ChangeLog.md +10 -0
- data/README.md +1 -3
- data/bin/retter +8 -4
- data/lib/retter/binder.rb +50 -0
- data/lib/retter/command.rb +42 -39
- data/lib/retter/config.rb +24 -23
- data/lib/retter/entries.rb +14 -18
- data/lib/retter/entry.rb +52 -29
- data/lib/retter/generator/base.rb +6 -7
- data/lib/retter/generator/skel/Gemfile +1 -2
- data/lib/retter/generator/skel/Retterfile +2 -2
- data/lib/retter/generator/skel/layouts/article.html.haml +3 -2
- data/lib/retter/generator/skel/layouts/entry.html.haml +3 -2
- data/lib/retter/generator/skel/layouts/index.html.haml +4 -2
- data/lib/retter/generator.rb +0 -1
- data/lib/retter/{renderers.rb → markdown.rb} +22 -1
- data/lib/retter/page/article.rb +54 -0
- data/lib/retter/page/base.rb +97 -0
- data/lib/retter/page/entries.rb +17 -0
- data/lib/retter/page/entry.rb +46 -0
- data/lib/retter/page/feed.rb +63 -0
- data/lib/retter/page/index.rb +17 -0
- data/lib/retter/page/profile.rb +17 -0
- data/lib/retter/page/view_helper.rb +9 -1
- data/lib/retter/page.rb +22 -74
- data/lib/retter/preprint.rb +19 -10
- data/lib/retter/version.rb +1 -1
- data/lib/retter.rb +41 -29
- data/retter.gemspec +44 -53
- data/spec/command/callback_spec.rb +16 -6
- data/spec/command/clean_spec.rb +20 -0
- data/spec/command/commit_spec.rb +11 -12
- data/spec/command/edit_spec.rb +28 -38
- data/spec/command/list_spec.rb +4 -4
- data/spec/command/open_spec.rb +2 -2
- data/spec/command/preview_spec.rb +7 -12
- data/spec/command/rebind_spec.rb +143 -66
- data/spec/spec_helper.rb +10 -3
- data/spec/support/example_group_helper.rb +55 -15
- data/spec/support/matchers.rb +0 -1
- metadata +195 -78
- data/lib/retter/generator/updator.rb +0 -7
- data/lib/retter/pages/article.rb +0 -41
- data/lib/retter/pages/entries.rb +0 -15
- data/lib/retter/pages/entry.rb +0 -35
- data/lib/retter/pages/feed.rb +0 -51
- data/lib/retter/pages/index.rb +0 -15
- data/lib/retter/pages/profile.rb +0 -15
- data/lib/retter/pages.rb +0 -77
- data/spec/command/invoke_after_spec.rb +0 -29
- data/spec/fixtures/sample.md +0 -295
data/.travis.yml
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
rvm:
|
2
|
-
- '1.9.3-
|
2
|
+
- '1.9.3-p194'
|
data/ChangeLog.md
CHANGED
data/README.md
CHANGED
@@ -242,11 +242,9 @@ renderer Retter::Renderers::PygmentsRenderer
|
|
242
242
|
# Remove caches
|
243
243
|
|
244
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
245
|
|
248
246
|
```
|
249
|
-
$
|
247
|
+
$ retter clean
|
250
248
|
```
|
251
249
|
|
252
250
|
# Built-in themes
|
data/bin/retter
CHANGED
@@ -3,20 +3,24 @@
|
|
3
3
|
|
4
4
|
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
|
5
5
|
|
6
|
+
trap :INT do
|
7
|
+
print "\r"
|
8
|
+
exit
|
9
|
+
end
|
10
|
+
|
6
11
|
require 'retter'
|
7
12
|
|
8
|
-
Retter.load ENV
|
13
|
+
Retter::Site.load ENV
|
9
14
|
|
10
15
|
case ARGV[0]
|
11
16
|
when 'new'
|
12
17
|
Retter::Generator::Creator.start ARGV[1..-1]
|
13
|
-
when 'gen'
|
14
|
-
Retter::Generator::Updator.start ARGV[1..-1]
|
15
18
|
else
|
16
19
|
begin
|
17
20
|
Retter::Command.start
|
18
21
|
rescue Errno::ENOENT
|
19
|
-
$stderr.puts "Some files might be broken.
|
22
|
+
$stderr.puts "Some files might be broken. Please re-generate site: `retter new site-name`"
|
23
|
+
|
20
24
|
raise
|
21
25
|
end
|
22
26
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module Retter
|
4
|
+
class Binder
|
5
|
+
extend Configurable
|
6
|
+
|
7
|
+
configurable :allow_binding
|
8
|
+
|
9
|
+
def initialize(entries)
|
10
|
+
@entries = entries
|
11
|
+
@singleton_pages = find_singleton_pages
|
12
|
+
end
|
13
|
+
|
14
|
+
def bind!
|
15
|
+
bind_entries
|
16
|
+
|
17
|
+
@singleton_pages.each(&:bind)
|
18
|
+
end
|
19
|
+
|
20
|
+
def bind_entries
|
21
|
+
@entries.each do |entry|
|
22
|
+
entry_page = Page::Entry.new(entry)
|
23
|
+
entry_page.bind
|
24
|
+
|
25
|
+
entry.articles.each do |article|
|
26
|
+
article_page = Page::Article.new(article)
|
27
|
+
article_page.bind
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def find_singleton_pages
|
35
|
+
available_singleton_page_names.map {|name|
|
36
|
+
Page.const_get(name.capitalize).new
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
def available_singleton_page_names
|
41
|
+
availables = [:index]
|
42
|
+
|
43
|
+
unless allow_binding == :none
|
44
|
+
availables += allow_binding || [:profile, :entries, :feed]
|
45
|
+
end
|
46
|
+
|
47
|
+
availables.map(&:downcase).uniq
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/retter/command.rb
CHANGED
@@ -2,10 +2,11 @@
|
|
2
2
|
|
3
3
|
require 'thor'
|
4
4
|
require 'launchy'
|
5
|
+
require 'pathname'
|
5
6
|
|
6
7
|
module Retter
|
7
8
|
class Command < Thor
|
8
|
-
include
|
9
|
+
include Site
|
9
10
|
|
10
11
|
map '-v' => :version,
|
11
12
|
'-e' => :edit,
|
@@ -14,54 +15,52 @@ module Retter
|
|
14
15
|
'-r' => :rebind,
|
15
16
|
'-b' => :bind
|
16
17
|
|
17
|
-
desc
|
18
|
+
desc :edit, %(Open $EDITOR. Write an article with Markdown.)
|
18
19
|
method_options date: :string, key: :string, silent: :boolean
|
19
20
|
def edit(identifier = options[:date] || options[:key])
|
20
21
|
entry = entries.detect_by_string(identifier)
|
21
22
|
|
22
|
-
system config.editor, entry.path
|
23
|
+
system config.editor, entry.path.to_path
|
23
24
|
|
24
|
-
invoke_after :edit
|
25
|
+
invoke_after :edit
|
25
26
|
end
|
26
27
|
|
27
28
|
default_task :edit
|
28
29
|
|
29
|
-
desc
|
30
|
+
desc :preview, %(Preview the draft article (browser will open).)
|
30
31
|
method_options date: :string, key: :string
|
31
32
|
def preview(identifier = options[:date] || options[:key])
|
32
33
|
preprint = Preprint.new
|
33
|
-
entry
|
34
|
+
entry = entries.detect_by_string(identifier)
|
34
35
|
|
35
|
-
preprint.
|
36
|
+
preprint.bind entry
|
36
37
|
|
37
|
-
Launchy.open preprint.path
|
38
|
+
Launchy.open preprint.path.to_path
|
38
39
|
end
|
39
40
|
|
40
|
-
desc
|
41
|
+
desc :open, %(Open your (static) site top page (browser will open).)
|
41
42
|
def open
|
42
|
-
index_page =
|
43
|
+
index_page = Page::Index.new
|
43
44
|
|
44
|
-
Launchy.open index_page.path
|
45
|
+
Launchy.open index_page.path.to_path
|
45
46
|
end
|
46
47
|
|
47
|
-
desc
|
48
|
+
desc :rebind, %(Bind the draft article, re-generate all html pages.)
|
48
49
|
method_options silent: :boolean
|
49
50
|
def rebind
|
50
51
|
entries.commit_wip_entry!
|
51
52
|
|
52
|
-
|
53
|
+
Binder.new(entries).bind!
|
53
54
|
|
54
|
-
|
55
|
-
|
56
|
-
invoke_after :rebind
|
57
|
-
end
|
55
|
+
invoke_after :bind
|
56
|
+
invoke_after :rebind
|
58
57
|
end
|
59
58
|
|
60
|
-
desc 'bind',
|
59
|
+
desc 'bind', %(Alias of rebind)
|
61
60
|
method_options silent: :boolean
|
62
|
-
alias_method
|
61
|
+
alias_method :bind, :rebind
|
63
62
|
|
64
|
-
desc
|
63
|
+
desc :commit, %(cd $RETTER_HOME && git add . && git commit -m 'Retter commit')
|
65
64
|
method_options silent: :boolean
|
66
65
|
def commit
|
67
66
|
Repository.open config.retter_home do |git|
|
@@ -69,10 +68,10 @@ module Retter
|
|
69
68
|
say git.commit_all('Retter commit'), :green
|
70
69
|
end
|
71
70
|
|
72
|
-
invoke_after :commit
|
71
|
+
invoke_after :commit
|
73
72
|
end
|
74
73
|
|
75
|
-
desc
|
74
|
+
desc :list, %(List retters)
|
76
75
|
def list
|
77
76
|
entries.each_with_index do |entry, n|
|
78
77
|
say "[e#{n}] #{entry.date}"
|
@@ -81,7 +80,14 @@ module Retter
|
|
81
80
|
end
|
82
81
|
end
|
83
82
|
|
84
|
-
desc
|
83
|
+
desc :clean, %(Clear all caches)
|
84
|
+
def clean
|
85
|
+
return unless config.cache.respond_to?(:clear)
|
86
|
+
|
87
|
+
config.cache.clear
|
88
|
+
end
|
89
|
+
|
90
|
+
desc :home, %(Open a new shell in $RETTER_HOME)
|
85
91
|
def home
|
86
92
|
Dir.chdir config.retter_home.to_path
|
87
93
|
|
@@ -90,51 +96,48 @@ module Retter
|
|
90
96
|
say 'bye', :green
|
91
97
|
end
|
92
98
|
|
93
|
-
desc
|
94
|
-
method_options
|
99
|
+
desc :callback, %(Call a callback process only)
|
100
|
+
method_options after: :string
|
95
101
|
def callback
|
96
102
|
invoke_after options[:after].intern
|
97
103
|
end
|
98
104
|
|
99
|
-
desc
|
105
|
+
desc :new, %(Create a new site)
|
100
106
|
def new; end
|
101
107
|
|
102
|
-
desc
|
103
|
-
def gen; end
|
104
|
-
|
105
|
-
desc 'usage', 'Show usage.'
|
108
|
+
desc :usage, %(Show usage.)
|
106
109
|
def usage
|
107
110
|
say Command.usage, :green
|
108
111
|
end
|
109
112
|
|
110
|
-
desc
|
113
|
+
desc :version, %(Show version.)
|
111
114
|
def version
|
112
115
|
say "Retter version #{VERSION}"
|
113
116
|
end
|
114
117
|
|
115
118
|
private
|
116
119
|
|
117
|
-
def pages
|
118
|
-
@pages ||= Pages.new
|
119
|
-
end
|
120
|
-
|
121
120
|
def silent?
|
122
121
|
!options[:silent].nil?
|
123
122
|
end
|
124
123
|
|
125
124
|
def invoke_after(name)
|
126
|
-
|
125
|
+
return if silent?
|
127
126
|
|
128
|
-
case callback
|
127
|
+
case callback = after_callback(name)
|
129
128
|
when Proc
|
130
129
|
instance_eval &callback
|
131
|
-
when Symbol
|
132
|
-
|
130
|
+
when Symbol, String
|
131
|
+
__send__ callback
|
133
132
|
else
|
134
133
|
# noop
|
135
134
|
end
|
136
135
|
end
|
137
136
|
|
137
|
+
def after_callback(name)
|
138
|
+
config.after_callback(name)
|
139
|
+
end
|
140
|
+
|
138
141
|
def self.usage
|
139
142
|
<<-EOM
|
140
143
|
Usage:
|
data/lib/retter/config.rb
CHANGED
@@ -10,10 +10,12 @@ module Retter
|
|
10
10
|
class Config
|
11
11
|
extend Forwardable
|
12
12
|
|
13
|
-
def_delegators Entries, :
|
14
|
-
def_delegators
|
15
|
-
|
16
|
-
|
13
|
+
def_delegators Entries, :retters_dir, :wip_file, :markup, :cache
|
14
|
+
def_delegators Markdown, :renderer
|
15
|
+
def_delegators Binder, :allow_binding
|
16
|
+
def_delegators Page, :layouts_dir, :entries_dir
|
17
|
+
def_delegators Retter::Site, :title, :description, :url, :author
|
18
|
+
def_delegator Retter::Site, :home, :retter_home
|
17
19
|
|
18
20
|
def initialize(env)
|
19
21
|
@env = env
|
@@ -23,13 +25,10 @@ module Retter
|
|
23
25
|
detect_retter_home
|
24
26
|
environments_required
|
25
27
|
|
26
|
-
@retter_home = Pathname.new(@env['RETTER_HOME'])
|
27
28
|
load_defaults
|
28
|
-
|
29
|
+
load_retterfile
|
29
30
|
rescue EnvError => e
|
30
|
-
$stderr.puts e.message
|
31
|
-
|
32
|
-
say Command.usage, :green
|
31
|
+
$stderr.puts e.message, Command.usage
|
33
32
|
|
34
33
|
exit 1
|
35
34
|
end
|
@@ -45,7 +44,7 @@ module Retter
|
|
45
44
|
alias_method :after, :after_callback
|
46
45
|
|
47
46
|
[ # base
|
48
|
-
:editor, :shell,
|
47
|
+
:editor, :shell,
|
49
48
|
# extra
|
50
49
|
:disqus_shortname
|
51
50
|
].each do |att|
|
@@ -62,12 +61,26 @@ module Retter
|
|
62
61
|
@env['RETTER_HOME'] = Dir.pwd if File.exist? 'Retterfile'
|
63
62
|
end
|
64
63
|
|
64
|
+
def load_retterfile
|
65
|
+
retterfile = retter_home.join('Retterfile')
|
66
|
+
|
67
|
+
instance_eval retterfile.read, retterfile.to_path if retterfile.exist?
|
68
|
+
end
|
69
|
+
|
70
|
+
def environments_required
|
71
|
+
unless @env.values_at('EDITOR', 'RETTER_HOME').all?
|
72
|
+
raise EnvError, 'Set $RETTER_HOME and $EDITOR, first.'
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
65
76
|
def load_defaults
|
77
|
+
retter_home Pathname.new(@env['RETTER_HOME'])
|
78
|
+
|
66
79
|
editor @env['EDITOR']
|
67
80
|
shell @env['SHELL']
|
68
81
|
url 'http://example.com'
|
69
82
|
|
70
|
-
renderer Retter::
|
83
|
+
renderer Retter::Markdown::CodeRayRenderer
|
71
84
|
retters_dir retter_home.join('retters/')
|
72
85
|
wip_file retters_dir.join('today.md')
|
73
86
|
|
@@ -79,17 +92,5 @@ module Retter
|
|
79
92
|
|
80
93
|
FileUtils.mkdir_p cache_dir.to_path unless cache_dir.directory? # for old versions
|
81
94
|
end
|
82
|
-
|
83
|
-
def load_retterfile_if_exists
|
84
|
-
retterfile = retter_home.join('Retterfile')
|
85
|
-
|
86
|
-
instance_eval retterfile.read, retterfile.to_path if retterfile.exist?
|
87
|
-
end
|
88
|
-
|
89
|
-
def environments_required
|
90
|
-
unless @env.values_at('EDITOR', 'RETTER_HOME').all?
|
91
|
-
raise EnvError, 'Set $RETTER_HOME and $EDITOR, first.'
|
92
|
-
end
|
93
|
-
end
|
94
95
|
end
|
95
96
|
end
|
data/lib/retter/entries.rb
CHANGED
@@ -9,10 +9,9 @@ module Retter
|
|
9
9
|
class EntryLoadError < RetterError; end
|
10
10
|
|
11
11
|
class Entries < Array
|
12
|
-
include Stationery
|
13
12
|
extend Configurable
|
14
13
|
|
15
|
-
configurable :
|
14
|
+
configurable :retters_dir, :wip_file, :markup, :cache
|
16
15
|
|
17
16
|
def initialize
|
18
17
|
load_entries retters_dir
|
@@ -47,7 +46,7 @@ module Retter
|
|
47
46
|
when wip_file.basename.to_path
|
48
47
|
wip_entry
|
49
48
|
else
|
50
|
-
detect {|e| e.
|
49
|
+
detect {|e| e.path.basename.to_path == filename }
|
51
50
|
end
|
52
51
|
end
|
53
52
|
|
@@ -70,7 +69,7 @@ module Retter
|
|
70
69
|
date = date || Date.today
|
71
70
|
body = file.exist? ? file.read : ''
|
72
71
|
|
73
|
-
Entry.new date: date, body: rendered_body(body),
|
72
|
+
Entry.new date: date, body: rendered_body(body), path: file, entries: self
|
74
73
|
end
|
75
74
|
|
76
75
|
def commit_wip_entry!
|
@@ -80,7 +79,7 @@ module Retter
|
|
80
79
|
wip_file.unlink
|
81
80
|
end
|
82
81
|
|
83
|
-
|
82
|
+
reload
|
84
83
|
end
|
85
84
|
|
86
85
|
def load_entries(path)
|
@@ -90,29 +89,26 @@ module Retter
|
|
90
89
|
}.sort_by(&:first)
|
91
90
|
|
92
91
|
date_files.reverse_each {|date, file|
|
93
|
-
self << Entry.new(date: date, body: rendered_body(file.read))
|
92
|
+
self << Entry.new(date: date, body: rendered_body(file.read), entries: self)
|
94
93
|
}
|
95
94
|
end
|
96
95
|
|
96
|
+
def reload
|
97
|
+
clear
|
98
|
+
|
99
|
+
load_entries retters_dir
|
100
|
+
end
|
101
|
+
|
97
102
|
def find_markup_files(path)
|
98
103
|
path = Pathname.new(path).realpath
|
99
|
-
Dir.open(path, &:to_a).grep(/^\d{4}(?:0[1-9]|1[012])(?:0[1-9]|[12][0-9]|3[01])
|
104
|
+
Dir.open(path, &:to_a).grep(/^\d{4}(?:0[1-9]|1[012])(?:0[1-9]|[12][0-9]|3[01])\..*$/).map {|f| path.join f }
|
100
105
|
end
|
101
106
|
|
102
107
|
def rendered_body(body)
|
103
108
|
key = Digest::SHA1.hexdigest('entry_' + body)
|
104
109
|
|
105
|
-
|
106
|
-
|
107
|
-
renderer,
|
108
|
-
autolink: true,
|
109
|
-
space_after_headers: true,
|
110
|
-
fenced_code_blocks: true,
|
111
|
-
strikethrough: true,
|
112
|
-
superscript: true,
|
113
|
-
fenced_code_blocks: true,
|
114
|
-
tables: true
|
115
|
-
).render(body)
|
110
|
+
cache.fetch(key) do
|
111
|
+
(markup || Markdown.instance).render(body)
|
116
112
|
end
|
117
113
|
end
|
118
114
|
end
|
data/lib/retter/entry.rb
CHANGED
@@ -8,7 +8,14 @@ module Retter
|
|
8
8
|
attr_accessor :entry, :id, :title, :body
|
9
9
|
|
10
10
|
def initialize(attrs = {})
|
11
|
-
|
11
|
+
attrs = {actual: true}.merge(attrs)
|
12
|
+
|
13
|
+
@id, @entry, @title, @body, @actual = attrs.values_at(:id, :entry, :title, :body, :actual)
|
14
|
+
end
|
15
|
+
|
16
|
+
# XXX return false if generated by Entry#to_article
|
17
|
+
def actual?
|
18
|
+
@actual
|
12
19
|
end
|
13
20
|
|
14
21
|
def to_s
|
@@ -24,32 +31,35 @@ module Retter
|
|
24
31
|
end
|
25
32
|
|
26
33
|
def index
|
27
|
-
articles.index(self)
|
34
|
+
articles.index(self).to_i
|
28
35
|
end
|
29
36
|
|
30
37
|
def articles
|
31
38
|
@articles ||= entry.articles
|
32
39
|
end
|
33
|
-
end
|
34
40
|
|
35
|
-
|
41
|
+
def snippet(length = 200)
|
42
|
+
snip = tags_stripped_body[0, length]
|
43
|
+
|
44
|
+
tags_stripped_body.length > length ? "#{snip}..." : snip
|
45
|
+
end
|
46
|
+
|
47
|
+
def tags_stripped_body
|
48
|
+
@tags_stripped_body ||= body.gsub(/<\/?\s?[^>]+>/, '')
|
49
|
+
end
|
50
|
+
end
|
36
51
|
|
37
52
|
attr_accessor :date, :lede, :body, :articles
|
38
|
-
attr_reader :
|
53
|
+
attr_reader :path
|
39
54
|
|
40
|
-
def initialize(attrs={})
|
41
|
-
@date, @body = attrs.values_at(:date, :body)
|
55
|
+
def initialize(attrs = {})
|
56
|
+
@entries, @date, @body = attrs.values_at(:entries, :date, :body)
|
42
57
|
|
43
|
-
|
44
|
-
@
|
58
|
+
path_by_date = Entries.retters_dir.join(date.strftime('%Y%m%d.md'))
|
59
|
+
@path = attrs[:path] || path_by_date
|
45
60
|
|
46
|
-
attach_titles
|
47
61
|
extract_articles
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
def path
|
52
|
-
pathname.to_path
|
62
|
+
assign_lede
|
53
63
|
end
|
54
64
|
|
55
65
|
def to_s
|
@@ -57,15 +67,19 @@ module Retter
|
|
57
67
|
end
|
58
68
|
|
59
69
|
def next
|
60
|
-
entries[index.next]
|
70
|
+
@entries[index.next]
|
61
71
|
end
|
62
72
|
|
63
73
|
def prev
|
64
|
-
entries[index.pred] unless index.pred < 0
|
74
|
+
@entries[index.pred] unless index.pred < 0
|
65
75
|
end
|
66
76
|
|
67
77
|
def index
|
68
|
-
entries.index(self) || 0
|
78
|
+
@entries.index(self) || 0
|
79
|
+
end
|
80
|
+
|
81
|
+
def to_article
|
82
|
+
Article.new(entry: self, id: 'a0', title: date.to_s, body: body, actual: false)
|
69
83
|
end
|
70
84
|
|
71
85
|
private
|
@@ -74,7 +88,7 @@ module Retter
|
|
74
88
|
Nokogiri::HTML(body)
|
75
89
|
end
|
76
90
|
|
77
|
-
def
|
91
|
+
def assign_ids
|
78
92
|
html = body_elements
|
79
93
|
html.search('//h1').each_with_index do |h1, seq|
|
80
94
|
h1.set_attribute 'id', "a#{seq}"
|
@@ -84,23 +98,32 @@ module Retter
|
|
84
98
|
end
|
85
99
|
|
86
100
|
def extract_articles
|
87
|
-
|
101
|
+
assign_ids
|
102
|
+
|
103
|
+
@articles = body_elements.search('body > *').each_with_object([]) {|c, articles|
|
88
104
|
if c.name == 'h1'
|
89
|
-
|
105
|
+
articles << Article.new(entry: self, id: c.attr('id'), title: c.text, body: '')
|
90
106
|
else
|
91
|
-
next if
|
107
|
+
next if articles.empty?
|
92
108
|
|
93
|
-
article =
|
109
|
+
article = articles.last
|
94
110
|
article.body += c.to_s
|
95
111
|
end
|
96
|
-
}
|
112
|
+
}
|
113
|
+
|
114
|
+
@articles = [to_article] if @articles.empty?
|
97
115
|
end
|
98
116
|
|
99
|
-
def
|
100
|
-
@lede =
|
101
|
-
|
102
|
-
|
103
|
-
|
117
|
+
def assign_lede
|
118
|
+
@lede =
|
119
|
+
if articles.any?(&:actual?)
|
120
|
+
body_elements.search('body > *').each_with_object('') {|c, r|
|
121
|
+
break r if c.name == 'h1'
|
122
|
+
r << c.to_s
|
123
|
+
}
|
124
|
+
else
|
125
|
+
''
|
126
|
+
end
|
104
127
|
end
|
105
128
|
end
|
106
129
|
end
|
@@ -47,20 +47,19 @@ class Retter::Generator::Base < Thor::Group
|
|
47
47
|
|
48
48
|
def create_files
|
49
49
|
FILES.each do |file|
|
50
|
-
copy_file(
|
50
|
+
copy_file %(skel/#{file}), %(#{name}/#{file})
|
51
51
|
end
|
52
52
|
|
53
53
|
TEMPLATES.each do |file|
|
54
|
-
template(
|
54
|
+
template %(skel/#{file}), %(#{name}/#{file})
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
58
|
def bundle_install
|
59
|
-
|
60
|
-
|
59
|
+
Dir.chdir name do
|
60
|
+
cli = Bundler::CLI.new
|
61
61
|
|
62
|
-
|
63
|
-
|
64
|
-
FileUtils.cd pwd
|
62
|
+
cli.install
|
63
|
+
end
|
65
64
|
end
|
66
65
|
end
|
@@ -5,7 +5,7 @@ url 'http://retter.example.com/'
|
|
5
5
|
title '<%= name %>'
|
6
6
|
description '<%= name %>'
|
7
7
|
author '<%= ENV["USER"] %>'
|
8
|
-
renderer Retter::
|
8
|
+
renderer Retter::Markdown::PygmentsRenderer
|
9
9
|
|
10
10
|
# Callbacks for retter sub-command: edit, rebind, commit
|
11
11
|
#
|
@@ -24,7 +24,7 @@ renderer Retter::Renderers::PygmentsRenderer
|
|
24
24
|
# end
|
25
25
|
#
|
26
26
|
# after :edit do
|
27
|
-
# Retter.reset!
|
27
|
+
# Retter::Site.reset!
|
28
28
|
# ident = ARGV.pop
|
29
29
|
#
|
30
30
|
# preview ident if yes?("Preview now? [yes/no]")
|