runeblog 0.2.43 → 0.2.48
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/blog +8 -10
- data/empty_view/assets/austin-pano.jpg +0 -0
- data/empty_view/themes/standard/blog/generate.lt3 +5 -3
- data/empty_view/themes/standard/blog/post_entry.lt3 +14 -10
- data/empty_view/themes/standard/etc/blog.css.lt3 +18 -0
- data/empty_view/themes/standard/navbar/faq.lt3 +1 -0
- data/empty_view/themes/standard/navbar/navbar.lt3 +1 -0
- data/empty_view/themes/standard/widgets/ad/ad.lt3 +8 -1
- data/empty_view/themes/standard/widgets/ad/ad1.png +0 -0
- data/empty_view/themes/standard/widgets/ad/ad2.png +0 -0
- data/empty_view/themes/standard/widgets/ad/ad3.png +0 -0
- data/empty_view/themes/standard/widgets/ad/ad4.png +0 -0
- data/empty_view/themes/standard/widgets/bydates/bydates.rb +7 -3
- data/empty_view/themes/standard/widgets/links/links.rb +28 -3
- data/empty_view/themes/standard/widgets/news/news.rb +7 -3
- data/empty_view/themes/standard/widgets/pages/pages.rb +10 -3
- data/empty_view/themes/standard/widgets/pinned/pinned.rb +7 -3
- data/empty_view/themes/standard/widgets/search/search.rb +7 -3
- data/empty_view/themes/standard/widgets/sitemap/sitemap.rb +7 -3
- data/empty_view/themes/standard/widgets/tag-cloud/tag-cloud.rb +7 -3
- data/lib/default.rb +1 -1
- data/lib/global.rb +15 -40
- data/lib/helpers-blog.rb +15 -44
- data/lib/liveblog.rb +86 -62
- data/lib/logging.rb +17 -8
- data/lib/post.rb +24 -20
- data/lib/publish.rb +4 -5
- data/lib/repl.rb +52 -11
- data/lib/runeblog.rb +115 -93
- data/lib/runeblog_version.rb +1 -1
- data/lib/view.rb +2 -9
- data/lib/xlate.rb +34 -33
- data/test/austin.rb +31 -20
- metadata +8 -5
- data/empty_view/remote/widgets/links/list.data +0 -3
- data/empty_view/remote/widgets/news/list.data +0 -4
- data/empty_view/remote/widgets/pages/list.data +0 -4
data/lib/publish.rb
CHANGED
@@ -21,29 +21,28 @@ class RuneBlog::Publishing
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def to_h
|
24
|
-
log!(enter: __method__)
|
24
|
+
log!(enter: __method__, level: 3)
|
25
25
|
{user: @user, server: @server, docroot: @docroot,
|
26
26
|
path: @path, proto: @proto}
|
27
27
|
end
|
28
28
|
|
29
29
|
def url
|
30
|
-
log!(enter: __method__)
|
30
|
+
log!(enter: __method__, level: 3)
|
31
31
|
vname = @blog.view.name # .gsub(/_/, "\\_")
|
32
32
|
url = "#@proto://#@server/#@path" # /#{vname}"
|
33
33
|
end
|
34
34
|
|
35
35
|
def system!(str)
|
36
|
-
log!(enter: __method__, args: [str])
|
36
|
+
log!(enter: __method__, args: [str], level: 1)
|
37
37
|
rc = system(str)
|
38
38
|
rc
|
39
39
|
end
|
40
40
|
|
41
41
|
def publish(files, assets=[])
|
42
|
-
log!(enter: __method__, args: [files, assets])
|
42
|
+
log!(enter: __method__, args: [files, assets], level: 1)
|
43
43
|
dir = @docroot/@path
|
44
44
|
view_name = @blog.view.name
|
45
45
|
viewpath = dir # /view_name
|
46
|
-
# result = system!("ssh #@user@#@server -x mkdir -p #{viewpath}")
|
47
46
|
result = system!("ssh #@user@#@server -x mkdir -p #{viewpath}/assets")
|
48
47
|
files.each do |file|
|
49
48
|
dest = "#@user@#@server:" + dir # /view_name
|
data/lib/repl.rb
CHANGED
@@ -7,18 +7,19 @@ make_exception(:PublishError, "Error during publishing")
|
|
7
7
|
make_exception(:EditorProblem, "Could not edit $1")
|
8
8
|
|
9
9
|
module RuneBlog::REPL
|
10
|
-
|
11
10
|
def edit_file(file)
|
12
11
|
result = system!("#{@blog.editor} #{file}")
|
13
12
|
raise EditorProblem(file) unless result
|
14
13
|
sleep 0.1
|
15
|
-
|
14
|
+
cmd_clear(nil)
|
16
15
|
end
|
17
16
|
|
18
17
|
def cmd_quit(arg, testing = false)
|
19
18
|
check_empty(arg)
|
20
19
|
RubyText.stop
|
21
|
-
|
20
|
+
sleep 0.1
|
21
|
+
cmd_clear(nil)
|
22
|
+
sleep 0.1
|
22
23
|
exit
|
23
24
|
end
|
24
25
|
|
@@ -99,6 +100,13 @@ module RuneBlog::REPL
|
|
99
100
|
result = system!("open #{local}")
|
100
101
|
raise CantOpen(local) unless result
|
101
102
|
@out
|
103
|
+
rescue => err
|
104
|
+
out = "/tmp/blog#{rand(100)}.txt"
|
105
|
+
File.open(out, "w") do |f|
|
106
|
+
f.puts err
|
107
|
+
f.puts err.backtrace.join("\n")
|
108
|
+
end
|
109
|
+
puts "Error: See #{out}"
|
102
110
|
end
|
103
111
|
|
104
112
|
def cmd_publish(arg, testing = false)
|
@@ -136,6 +144,13 @@ module RuneBlog::REPL
|
|
136
144
|
output! "...finished.\n"
|
137
145
|
end
|
138
146
|
return @out
|
147
|
+
rescue => err
|
148
|
+
out = "/tmp/blog#{rand(100)}.txt"
|
149
|
+
File.open(out, "w") do |f|
|
150
|
+
f.puts err
|
151
|
+
f.puts err.backtrace.join("\n")
|
152
|
+
end
|
153
|
+
puts "Error: See #{out}"
|
139
154
|
end
|
140
155
|
|
141
156
|
def cmd_rebuild(arg, testing = false)
|
@@ -144,7 +159,15 @@ module RuneBlog::REPL
|
|
144
159
|
check_empty(arg)
|
145
160
|
puts unless testing
|
146
161
|
@blog.generate_view(@blog.view)
|
162
|
+
@blog.generate_index(@blog.view)
|
147
163
|
@out
|
164
|
+
rescue => err
|
165
|
+
out = "/tmp/blog#{rand(100)}.txt"
|
166
|
+
File.open(out, "w") do |f|
|
167
|
+
f.puts err
|
168
|
+
f.puts err.backtrace.join("\n")
|
169
|
+
end
|
170
|
+
puts "Error: See #{out}"
|
148
171
|
end
|
149
172
|
|
150
173
|
def cmd_change_view(arg, testing = false)
|
@@ -178,18 +201,30 @@ module RuneBlog::REPL
|
|
178
201
|
@out
|
179
202
|
rescue ViewAlreadyExists
|
180
203
|
puts 'Blog already exists'
|
204
|
+
rescue => err
|
205
|
+
out = "/tmp/blog#{rand(100)}.txt"
|
206
|
+
File.open(out, "w") do |f|
|
207
|
+
f.puts err
|
208
|
+
f.puts err.backtrace.join("\n")
|
209
|
+
end
|
210
|
+
puts "Error: See #{out}"
|
181
211
|
end
|
182
212
|
|
183
213
|
def cmd_new_post(arg, testing = false)
|
184
214
|
reset_output
|
185
215
|
check_empty(arg)
|
186
216
|
title = ask("\nTitle: ")
|
217
|
+
puts
|
187
218
|
@blog.create_new_post(title)
|
188
219
|
# STDSCR.clear
|
189
220
|
@out
|
190
221
|
rescue => err
|
191
|
-
|
192
|
-
|
222
|
+
out = "/tmp/blog#{rand(100)}.txt"
|
223
|
+
File.open(out, "w") do |f|
|
224
|
+
f.puts err
|
225
|
+
f.puts err.backtrace.join("\n")
|
226
|
+
end
|
227
|
+
puts "Error: See #{out}"
|
193
228
|
end
|
194
229
|
|
195
230
|
def _remove_post(arg, testing=false)
|
@@ -199,7 +234,6 @@ module RuneBlog::REPL
|
|
199
234
|
end
|
200
235
|
|
201
236
|
def cmd_remove_post(arg, testing = false)
|
202
|
-
puts "arg = #{arg.inspect} is a #{arg.class}"
|
203
237
|
reset_output
|
204
238
|
args = arg.split
|
205
239
|
args.each do |x|
|
@@ -211,14 +245,12 @@ puts "arg = #{arg.inspect} is a #{arg.class}"
|
|
211
245
|
@out
|
212
246
|
end
|
213
247
|
|
214
|
-
#-- FIXME affects linking, building, publishing...
|
215
|
-
|
216
248
|
def cmd_edit_post(arg, testing = false)
|
217
249
|
reset_output
|
218
250
|
id = get_integer(arg)
|
219
251
|
# Simplify this
|
220
252
|
tag = "#{'%04d' % id}"
|
221
|
-
files = Find.find(@blog.root+"/drafts").to_a
|
253
|
+
files = ::Find.find(@blog.root+"/drafts").to_a
|
222
254
|
files = files.grep(/#{tag}-.*lt3/)
|
223
255
|
files = files.map {|f| File.basename(f) }
|
224
256
|
if files.size > 1
|
@@ -238,6 +270,13 @@ puts "arg = #{arg.inspect} is a #{arg.class}"
|
|
238
270
|
draft = "#{@blog.root}/drafts/#{file}"
|
239
271
|
result = edit_file(draft)
|
240
272
|
@blog.generate_post(draft)
|
273
|
+
rescue => err
|
274
|
+
out = "/tmp/blog#{rand(100)}.txt"
|
275
|
+
File.open(out, "w") do |f|
|
276
|
+
f.puts err
|
277
|
+
f.puts err.backtrace.join("\n")
|
278
|
+
end
|
279
|
+
puts "Error: See #{out}"
|
241
280
|
end
|
242
281
|
|
243
282
|
def cmd_list_views(arg, testing = false)
|
@@ -321,7 +360,10 @@ puts "arg = #{arg.inspect} is a #{arg.class}"
|
|
321
360
|
|
322
361
|
def cmd_ssh(arg, testing = false)
|
323
362
|
pub = @blog.view.publisher
|
324
|
-
|
363
|
+
puts
|
364
|
+
system!("tputs clear; ssh #{pub.user}@#{pub.server}")
|
365
|
+
sleep 0.1
|
366
|
+
cmd_clear(nil)
|
325
367
|
end
|
326
368
|
|
327
369
|
def cmd_INVALID(arg, testing = false)
|
@@ -384,6 +426,5 @@ puts "arg = #{arg.inspect} is a #{arg.class}"
|
|
384
426
|
puts unless testing
|
385
427
|
@out
|
386
428
|
end
|
387
|
-
|
388
429
|
end
|
389
430
|
|
data/lib/runeblog.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'date'
|
2
|
+
require 'find'
|
2
3
|
|
3
4
|
require 'logging'
|
4
5
|
|
@@ -42,6 +43,15 @@ class RuneBlog
|
|
42
43
|
|
43
44
|
include Helpers
|
44
45
|
|
46
|
+
def _tmp_error(err) # FIXME move to helpers
|
47
|
+
out = "/tmp/blog#{rand(100)}.txt"
|
48
|
+
File.open(out, "w") do |f|
|
49
|
+
f.puts err
|
50
|
+
f.puts err.backtrace.join("\n")
|
51
|
+
end
|
52
|
+
puts "Error: See #{out}"
|
53
|
+
end
|
54
|
+
|
45
55
|
def self.create_new_blog_repo(dir = ".blogs")
|
46
56
|
log!(enter: __method__, args: [dir])
|
47
57
|
raise ArgumentError unless dir.is_a?(String) && ! dir.empty?
|
@@ -53,7 +63,7 @@ class RuneBlog
|
|
53
63
|
end
|
54
64
|
|
55
65
|
def self.create(root = ".blogs")
|
56
|
-
log!(enter: __method__, args: [root])
|
66
|
+
log!(enter: __method__, args: [root], level: 1)
|
57
67
|
# Crude - FIXME later - # What views are there? Publishing, etc.
|
58
68
|
self.blog = self # Weird. Like a singleton - dumbass circular dependency?
|
59
69
|
root = Dir.pwd/root
|
@@ -63,13 +73,13 @@ class RuneBlog
|
|
63
73
|
create_dirs(:drafts, :views, :posts)
|
64
74
|
new_sequence
|
65
75
|
end
|
66
|
-
# put_config(root: root)
|
67
76
|
x = OpenStruct.new
|
68
77
|
x.root, x.current_view, x.editor = root, "test_view", "/usr/bin/vim " # dumb - FIXME later
|
69
78
|
write_config(x, root/ConfigFile)
|
70
79
|
@blog = self.new(root)
|
71
|
-
@blog.create_view("test_view")
|
72
80
|
@blog
|
81
|
+
rescue => err
|
82
|
+
_tmp_error(err)
|
73
83
|
end
|
74
84
|
|
75
85
|
def self.open(root = ".blogs")
|
@@ -78,6 +88,8 @@ class RuneBlog
|
|
78
88
|
self.blog = self # Weird. Like a singleton - dumbass circular dependency?
|
79
89
|
root = Dir.pwd/root
|
80
90
|
blog = self.new(root)
|
91
|
+
rescue => err
|
92
|
+
_tmp_error(err)
|
81
93
|
end
|
82
94
|
|
83
95
|
def initialize(root_dir = ".blogs") # always assumes existing blog
|
@@ -101,11 +113,13 @@ class RuneBlog
|
|
101
113
|
end
|
102
114
|
|
103
115
|
def _deploy_local(dir)
|
104
|
-
log!(enter: __method__, args: [dir])
|
116
|
+
log!(enter: __method__, args: [dir], level: 1)
|
105
117
|
Dir.chdir(dir) do
|
106
118
|
views = _retrieve_metadata(:views)
|
107
119
|
views.each {|v| system!("cp *html #@root/views/#{v}/remote") }
|
108
120
|
end
|
121
|
+
rescue => err
|
122
|
+
_tmp_error(err)
|
109
123
|
end
|
110
124
|
|
111
125
|
def _retrieve_metadata(key)
|
@@ -129,19 +143,23 @@ class RuneBlog
|
|
129
143
|
raise "Too many #{key} instances in metadata.txt!"
|
130
144
|
end
|
131
145
|
return result
|
146
|
+
rescue => err
|
147
|
+
_tmp_error(err)
|
132
148
|
end
|
133
149
|
|
134
150
|
def process_post(sourcefile)
|
135
|
-
log!(enter: __method__, args: [dir])
|
151
|
+
log!(enter: __method__, args: [dir], level: 2)
|
136
152
|
nslug = sourcefile.sub(/.lt3/, "")
|
137
153
|
dir = @root/:posts/nslug
|
138
154
|
create_dir(dir)
|
139
155
|
xlate cwd: dir, src: sourcefile # , debug: true
|
140
156
|
_deploy_local(dir)
|
157
|
+
rescue => err
|
158
|
+
_tmp_error(err)
|
141
159
|
end
|
142
160
|
|
143
161
|
def inspect
|
144
|
-
log!(enter: __method__)
|
162
|
+
log!(enter: __method__, level: 3)
|
145
163
|
str = "blog: "
|
146
164
|
ivars = ["@root", "@sequence"] # self.instance_variables
|
147
165
|
ivars.each do |iv|
|
@@ -152,30 +170,32 @@ class RuneBlog
|
|
152
170
|
end
|
153
171
|
|
154
172
|
def view?(name)
|
155
|
-
log!(enter: __method__, args: [name])
|
173
|
+
log!(enter: __method__, args: [name], level: 3)
|
156
174
|
raise ArgumentError unless name.is_a?(String) && ! name.empty?
|
157
175
|
views.any? {|x| x.name == name }
|
158
176
|
end
|
159
177
|
|
160
178
|
def view(name = nil)
|
161
|
-
log!(enter: __method__, args: [name])
|
179
|
+
log!(enter: __method__, args: [name], level: 3)
|
162
180
|
raise ArgumentError unless name.nil? || (name.is_a?(String) && ! name.empty?)
|
163
181
|
name.nil? ? @view : str2view(name)
|
164
182
|
end
|
165
183
|
|
166
184
|
def str2view(str)
|
167
|
-
log!(enter: __method__, args: [str])
|
185
|
+
log!(enter: __method__, args: [str], level: 3)
|
168
186
|
raise ArgumentError unless str.is_a?(String) && ! str.empty?
|
169
187
|
@views.find {|x| x.name == str }
|
170
188
|
end
|
171
189
|
|
172
190
|
def _set_publisher
|
173
|
-
log!(enter: __method__)
|
191
|
+
log!(enter: __method__, level: 3)
|
174
192
|
@view.publisher = RuneBlog::Publishing.new(@view.to_s) # FIXME refactor
|
193
|
+
rescue => err
|
194
|
+
_tmp_error(err)
|
175
195
|
end
|
176
196
|
|
177
197
|
def view=(arg)
|
178
|
-
log!(enter: __method__, args: [arg])
|
198
|
+
log!(enter: __method__, args: [arg], level: 2)
|
179
199
|
case arg
|
180
200
|
when RuneBlog::View
|
181
201
|
@view = arg
|
@@ -188,22 +208,24 @@ class RuneBlog
|
|
188
208
|
else
|
189
209
|
raise CantAssignView(arg.class.to_s)
|
190
210
|
end
|
211
|
+
rescue => err
|
212
|
+
_tmp_error(err)
|
191
213
|
end
|
192
214
|
|
193
215
|
def get_sequence
|
194
|
-
log!(enter: __method__)
|
216
|
+
log!(enter: __method__, level: 3)
|
195
217
|
File.read(@root/:sequence).to_i
|
196
218
|
end
|
197
219
|
|
198
220
|
def next_sequence
|
199
|
-
log!(enter: __method__)
|
221
|
+
log!(enter: __method__, level: 3)
|
200
222
|
@sequence += 1
|
201
223
|
dump(@sequence, @root/:sequence)
|
202
224
|
@sequence
|
203
225
|
end
|
204
226
|
|
205
227
|
def viewdir(v = nil) # delete?
|
206
|
-
log!(enter: __method__, args: [v])
|
228
|
+
log!(enter: __method__, args: [v], level: 3)
|
207
229
|
v = str2view(v) if v.is_a?(String)
|
208
230
|
raise ArgumentError unless v.nil? || v.is_a?(RuneBlog::View)
|
209
231
|
v ||= @view
|
@@ -211,17 +233,17 @@ class RuneBlog
|
|
211
233
|
end
|
212
234
|
|
213
235
|
def self.exist?
|
214
|
-
log!(enter: __method__)
|
236
|
+
log!(enter: __method__, level: 3)
|
215
237
|
Dir.exist?(DotDir) && File.exist?(DotDir/ConfigFile)
|
216
238
|
end
|
217
239
|
|
218
240
|
def mark_last_published(str)
|
219
|
-
log!(enter: __method__, args: [str])
|
241
|
+
log!(enter: __method__, args: [str], level: 2)
|
220
242
|
dump(str, "#{self.view.dir}/last_published")
|
221
243
|
end
|
222
244
|
|
223
245
|
def add_view(view_name)
|
224
|
-
log!(enter: __method__, args: [view_name])
|
246
|
+
log!(enter: __method__, args: [view_name], level: 2)
|
225
247
|
view = RuneBlog::View.new(view_name)
|
226
248
|
@view = view # current view
|
227
249
|
@views << view # all views
|
@@ -229,15 +251,17 @@ class RuneBlog
|
|
229
251
|
end
|
230
252
|
|
231
253
|
def make_empty_view_tree(view_name)
|
232
|
-
log!(enter: __method__, args: [view_name])
|
254
|
+
log!(enter: __method__, args: [view_name], level: 2)
|
233
255
|
Dir.chdir(@root) do
|
234
256
|
cmd = "cp -r #{RuneBlog::Path}/../empty_view views/#{view_name}"
|
235
257
|
system!(cmd)
|
236
258
|
end
|
259
|
+
rescue => err
|
260
|
+
_tmp_error(err)
|
237
261
|
end
|
238
262
|
|
239
263
|
def check_valid_new_view(view_name)
|
240
|
-
log!(enter: __method__, args: [view_name])
|
264
|
+
log!(enter: __method__, args: [view_name], level: 3)
|
241
265
|
raise ArgumentError unless view_name.is_a?(String)
|
242
266
|
raise ArgumentError if view_name.empty?
|
243
267
|
names = self.views.map(&:to_s)
|
@@ -249,11 +273,13 @@ class RuneBlog
|
|
249
273
|
end
|
250
274
|
|
251
275
|
def create_view(view_name)
|
252
|
-
log!(enter: __method__, args: [view_name])
|
276
|
+
log!(enter: __method__, args: [view_name], level: 2)
|
253
277
|
check_valid_new_view(view_name)
|
254
278
|
make_empty_view_tree(view_name)
|
255
279
|
add_view(view_name)
|
256
280
|
mark_last_published("Initial creation")
|
281
|
+
rescue => err
|
282
|
+
_tmp_error(err)
|
257
283
|
end
|
258
284
|
|
259
285
|
def delete_view(name, force = false)
|
@@ -267,7 +293,7 @@ class RuneBlog
|
|
267
293
|
end
|
268
294
|
|
269
295
|
def view_files
|
270
|
-
log!(enter: __method__)
|
296
|
+
log!(enter: __method__, level: 2)
|
271
297
|
vdir = self.view.dir
|
272
298
|
files = [vdir/"index.html"]
|
273
299
|
files += posts.map {|x| vdir/x }
|
@@ -275,7 +301,7 @@ class RuneBlog
|
|
275
301
|
end
|
276
302
|
|
277
303
|
def post_lookup(postid) # side-effect?
|
278
|
-
log!(enter: __method__, args: [postid])
|
304
|
+
log!(enter: __method__, args: [postid], level: 2)
|
279
305
|
slug = title = date = teaser_text = nil
|
280
306
|
|
281
307
|
dir_posts = @vdir/:posts
|
@@ -287,10 +313,12 @@ class RuneBlog
|
|
287
313
|
postdir = post.first
|
288
314
|
vp = RuneBlog::ViewPost.new(self.view, postdir)
|
289
315
|
vp
|
316
|
+
rescue => err
|
317
|
+
_tmp_error(err)
|
290
318
|
end
|
291
319
|
|
292
320
|
def index_entry(slug)
|
293
|
-
log!(enter: __method__, args: [slug])
|
321
|
+
log!(enter: __method__, args: [slug], level: 2)
|
294
322
|
id = slug.to_i
|
295
323
|
text = nil
|
296
324
|
@theme = @view.dir/"themes/standard"
|
@@ -302,28 +330,37 @@ class RuneBlog
|
|
302
330
|
vp.nslug, vp.aslug, vp.title, vp.date, vp.teaser_text
|
303
331
|
path = vp.path
|
304
332
|
url = aslug + ".html"
|
333
|
+
# puts "--- vp = #{[vp.nslug, vp.aslug, vp.title, vp.date, vp.teaser_text].inspect}"; gets
|
305
334
|
date = ::Date.parse(date)
|
306
335
|
date = date.strftime("%B %e<br><div style='float: right'>%Y</div>")
|
307
336
|
text = interpolate(@_post_entry, binding)
|
308
337
|
text
|
338
|
+
rescue => err
|
339
|
+
_tmp_error(err)
|
309
340
|
end
|
310
341
|
|
311
342
|
def collect_recent_posts(file)
|
312
|
-
log!(enter: __method__, args: [file])
|
343
|
+
log!(enter: __method__, args: [file], level: 3)
|
313
344
|
posts = nil
|
314
345
|
dir_posts = @vdir/:posts
|
315
346
|
entries = Dir.entries(dir_posts)
|
316
347
|
posts = entries.grep(/^\d\d\d\d/).map {|x| dir_posts/x }
|
317
348
|
posts.select! {|x| File.directory?(x) }
|
318
349
|
# directories that start with four digits
|
319
|
-
posts = posts.sort
|
350
|
+
posts = posts.sort do |a, b|
|
351
|
+
ai = a.index(/\d\d\d\d-/)
|
352
|
+
bi = b.index(/\d\d\d\d-/)
|
353
|
+
na = a[ai..(ai+3)].to_i
|
354
|
+
nb = b[bi..(bi+3)].to_i
|
355
|
+
nb <=> na
|
356
|
+
end # sort descending
|
320
357
|
posts = posts[0..19] # return 20 at most
|
321
358
|
text = <<-HTML
|
322
359
|
<html>
|
323
360
|
<head><link rel="stylesheet" href="etc/blog.css"></head>
|
324
361
|
<body>
|
325
362
|
HTML
|
326
|
-
wanted = [
|
363
|
+
wanted = [8, posts.size].min # estimate how many we want?
|
327
364
|
enum = posts.each
|
328
365
|
wanted.times do
|
329
366
|
postid = File.basename(enum.next)
|
@@ -332,28 +369,30 @@ class RuneBlog
|
|
332
369
|
end
|
333
370
|
text << "</body></html>"
|
334
371
|
File.write(@vdir/:remote/file, text)
|
372
|
+
rescue => err
|
373
|
+
_tmp_error(err)
|
335
374
|
end
|
336
375
|
|
337
|
-
def create_new_post(title, testing = false, teaser: nil, body: nil,
|
338
|
-
|
376
|
+
def create_new_post(title, testing = false, teaser: nil, body: nil,
|
377
|
+
pubdate: Time.now.strftime("%Y-%m-%d"), views: [])
|
378
|
+
log!(enter: __method__, args: [title, testing, teaser, body, views], level: 1, stderr: true)
|
339
379
|
meta = nil
|
340
380
|
views = views + [self.view.to_s]
|
381
|
+
views.uniq!
|
341
382
|
Dir.chdir(@root/:posts) do
|
342
|
-
post = Post.create(title: title, teaser: teaser, body: body, views: views)
|
383
|
+
post = Post.create(title: title, teaser: teaser, body: body, pubdate: pubdate, views: views)
|
343
384
|
post.edit unless testing
|
344
385
|
post.build
|
345
386
|
meta = post.meta
|
346
387
|
end
|
347
388
|
return meta.num
|
348
389
|
rescue => err
|
349
|
-
|
350
|
-
puts err.backtrace.join("\n")
|
390
|
+
_tmp_error(err)
|
351
391
|
end
|
352
392
|
|
353
393
|
def edit_initial_post(file, testing = false)
|
354
|
-
log!(enter: __method__, args: [file, testing])
|
394
|
+
log!(enter: __method__, args: [file, testing], level: 3)
|
355
395
|
debug "=== edit_initial_post #{file.inspect} => #{sourcefile}"
|
356
|
-
sourcefile = @root/:drafts/file
|
357
396
|
result = system!("#@editor #{sourcefile} +8") unless testing
|
358
397
|
raise EditorProblem(sourcefile) unless result
|
359
398
|
process_post(sourcefile)
|
@@ -363,20 +402,20 @@ class RuneBlog
|
|
363
402
|
end
|
364
403
|
|
365
404
|
def posts
|
366
|
-
log!(enter: __method__)
|
405
|
+
log!(enter: __method__, level: 3)
|
367
406
|
dir = self.view.dir/:posts
|
368
407
|
posts = Dir.entries(dir).grep(/^\d{4}/)
|
369
408
|
posts
|
370
409
|
end
|
371
410
|
|
372
411
|
def drafts
|
373
|
-
log!(enter: __method__)
|
412
|
+
log!(enter: __method__, level: 3)
|
374
413
|
dir = @root/:drafts
|
375
414
|
drafts = Dir.entries(dir).grep(/^\d{4}.*/)
|
376
415
|
end
|
377
416
|
|
378
417
|
def change_view(view)
|
379
|
-
log!(enter: __method__, args: [view])
|
418
|
+
log!(enter: __method__, args: [view], level: 3)
|
380
419
|
raise ArgumentError unless view.is_a?(String) || view.is_a?(RuneBlog::View)
|
381
420
|
x = OpenStruct.new
|
382
421
|
x.root, x.current_view, x.editor = @root, view.to_s, @editor # dumb - FIXME later
|
@@ -389,40 +428,38 @@ class RuneBlog
|
|
389
428
|
raise ArgumentError unless view.is_a?(String) || view.is_a?(RuneBlog::View)
|
390
429
|
@vdir = @root/:views/view
|
391
430
|
collect_recent_posts("recent.html")
|
431
|
+
rescue => err
|
432
|
+
_tmp_error(err)
|
392
433
|
end
|
393
434
|
|
394
435
|
def generate_view(view) # huh?
|
395
436
|
log!(enter: __method__, args: [view])
|
396
|
-
# generate_index(view) # recent posts (recent.html)
|
397
437
|
vdir = @root/:views/view
|
398
438
|
@theme = @root/:views/view/:themes/:standard
|
399
439
|
xlate cwd: vdir/"themes/standard/etc",
|
400
440
|
src: "blog.css.lt3", copy: vdir/"remote/etc/blog.css" # , debug: true
|
401
441
|
xlate cwd: vdir/"themes/standard",
|
402
442
|
src: "blog/generate.lt3", dst: vdir/:remote/"index.html"
|
403
|
-
generate_index(view) # recent posts (recent.html)
|
404
|
-
# ^ HERE
|
405
443
|
copy("#{vdir}/assets/*", "#{vdir}/remote/assets/")
|
406
444
|
rescue => err
|
407
|
-
|
408
|
-
puts err.backtrace.join("\n")
|
409
|
-
print "Pause... "
|
410
|
-
gets
|
445
|
+
_tmp_error(err)
|
411
446
|
end
|
412
447
|
|
413
448
|
def _get_views(draft)
|
414
|
-
log!(enter: __method__, args: [draft])
|
449
|
+
log!(enter: __method__, args: [draft], level: 2)
|
415
450
|
# FIXME dumb code
|
416
451
|
view_line = File.readlines(draft).grep(/^.views /)
|
417
452
|
raise "More than one .views call!" if view_line.size > 1
|
418
453
|
raise "No .views call!" if view_line.size < 1
|
419
454
|
view_line = view_line.first
|
420
455
|
views = view_line[7..-1].split
|
421
|
-
views
|
456
|
+
views.uniq
|
457
|
+
rescue => err
|
458
|
+
_tmp_error(err)
|
422
459
|
end
|
423
460
|
|
424
461
|
def _copy_get_dirs(draft, view)
|
425
|
-
log!(enter: __method__, args: [draft, view])
|
462
|
+
log!(enter: __method__, args: [draft, view], level: 2)
|
426
463
|
fname = File.basename(draft)
|
427
464
|
noext = fname.sub(/.lt3$/, "")
|
428
465
|
vdir = @root/:views/view
|
@@ -432,21 +469,24 @@ class RuneBlog
|
|
432
469
|
viewdir, slugdir, aslug = vdir, dir, noext[5..-1]
|
433
470
|
theme = viewdir/:themes/:standard
|
434
471
|
[noext, viewdir, slugdir, aslug, theme]
|
472
|
+
rescue => err
|
473
|
+
_tmp_error(err)
|
435
474
|
end
|
436
475
|
|
437
476
|
def _post_metadata(draft, pdraft)
|
438
|
-
log!(enter: __method__, args: [draft, pdraft])
|
477
|
+
log!(enter: __method__, args: [draft, pdraft], level: 2)
|
439
478
|
# FIXME store this somewhere
|
440
479
|
fname = File.basename(draft) # 0001-this-is-a-post.lt3
|
441
480
|
nslug = fname.sub(/.lt3$/, "") # 0001-this-is-a-post
|
442
481
|
aslug = nslug.sub(/\d\d\d\d-/, "") # this-is-a-post
|
443
|
-
pnum = nslug[0..3]
|
482
|
+
pnum = nslug[0..3] # 0001
|
444
483
|
Dir.chdir(pdraft) do
|
445
484
|
excerpt = File.read("teaser.txt")
|
446
485
|
date = _retrieve_metadata(:date)
|
447
486
|
longdate = ::Date.parse(date).strftime("%B %e, %Y")
|
448
487
|
title = _retrieve_metadata(:title)
|
449
488
|
tags = _retrieve_metadata(:tags)
|
489
|
+
# FIXME simplify
|
450
490
|
vars = <<~LIVE
|
451
491
|
.set post.num = #{pnum}
|
452
492
|
.heredoc post.aslug
|
@@ -467,10 +507,12 @@ class RuneBlog
|
|
467
507
|
LIVE
|
468
508
|
File.open(pdraft/"vars.lt3", "w") {|f| f.puts vars }
|
469
509
|
end
|
510
|
+
rescue => err
|
511
|
+
_tmp_error(err)
|
470
512
|
end
|
471
513
|
|
472
514
|
def copy_widget_html(view)
|
473
|
-
log!(enter: __method__)
|
515
|
+
log!(enter: __method__, level: 2)
|
474
516
|
vdir = @root/:views/view
|
475
517
|
remote = vdir/:remote
|
476
518
|
wdir = vdir/:themes/:standard/:widgets
|
@@ -481,12 +523,15 @@ class RuneBlog
|
|
481
523
|
create_dirs(rem)
|
482
524
|
files = Dir[w/"*"]
|
483
525
|
files = files.select {|x| x =~ /(html|css)$/ }
|
484
|
-
|
526
|
+
tag = File.basename(w)
|
527
|
+
files.each {|file| system!("cp #{file} #{rem}", show: (tag == "zzz")) }
|
485
528
|
end
|
529
|
+
rescue => err
|
530
|
+
_tmp_error(err)
|
486
531
|
end
|
487
532
|
|
488
|
-
def _handle_post(draft, view)
|
489
|
-
log!(enter: __method__, args: [draft,
|
533
|
+
def _handle_post(draft, view_name = self.view.to_s)
|
534
|
+
log!(enter: __method__, args: [draft, view_name], level: 2)
|
490
535
|
# break into separate methods?
|
491
536
|
|
492
537
|
fname = File.basename(draft) # 0001-this-is-a-post.lt3
|
@@ -494,55 +539,34 @@ class RuneBlog
|
|
494
539
|
aslug = nslug.sub(/\d\d\d\d-/, "") # this-is-a-post
|
495
540
|
ahtml = aslug + ".html" # this-is-a-post.html
|
496
541
|
pdraft = @root/:posts/nslug
|
497
|
-
remote = @root/:views/
|
498
|
-
@theme = @root/:views/
|
542
|
+
remote = @root/:views/view_name/:remote
|
543
|
+
@theme = @root/:views/view_name/:themes/:standard
|
499
544
|
# Step 1...
|
500
545
|
create_dirs(pdraft)
|
501
|
-
xlate cwd: pdraft, src: draft, dst: "guts.html"
|
546
|
+
xlate cwd: pdraft, src: draft, dst: "guts.html", debug: true
|
502
547
|
_post_metadata(draft, pdraft)
|
503
548
|
# Step 2...
|
504
|
-
vposts = @root/:views/
|
549
|
+
vposts = @root/:views/view_name/:posts
|
505
550
|
copy!(pdraft, vposts) # ??
|
506
551
|
# Step 3..
|
507
552
|
copy(pdraft/"guts.html", @theme/:post)
|
508
553
|
copy(pdraft/"vars.lt3", @theme/:post)
|
509
554
|
# Step 4...
|
510
|
-
xlate cwd: @theme/:post, src: "generate.lt3",
|
511
|
-
dst: remote/ahtml, copy: @theme/:post
|
555
|
+
xlate cwd: @theme/:post, src: "generate.lt3", force: true,
|
556
|
+
dst: remote/ahtml, copy: @theme/:post, debug: true
|
512
557
|
xlate cwd: @theme/:post, src: "permalink.lt3",
|
513
558
|
dst: remote/:permalink/ahtml # , debug: true
|
514
|
-
copy_widget_html(
|
559
|
+
copy_widget_html(view_name)
|
560
|
+
rescue => err
|
561
|
+
_tmp_error(err)
|
515
562
|
end
|
516
563
|
|
517
564
|
def generate_post(draft)
|
518
|
-
log!(enter: __method__, args: [draft])
|
565
|
+
log!(enter: __method__, args: [draft], level: 1)
|
519
566
|
views = _get_views(draft)
|
520
|
-
views.each
|
521
|
-
|
522
|
-
|
523
|
-
# ^ HERE
|
524
|
-
end
|
525
|
-
end
|
526
|
-
|
527
|
-
def OLD_index_entry(view, meta)
|
528
|
-
log!(enter: __method__, args: [view, meta])
|
529
|
-
debug "=== index_entry #{view.to_s.inspect} #{meta.num} #{meta.title.inspect}"
|
530
|
-
check_meta(meta, "index_entry1")
|
531
|
-
raise ArgumentError unless view.is_a?(String) || view.is_a?(RuneBlog::View)
|
532
|
-
check_meta(meta, "index_entry2")
|
533
|
-
self.make_slug(meta)
|
534
|
-
check_meta(meta, "index_entry3")
|
535
|
-
# FIXME clean up and generalize
|
536
|
-
ref = view/meta.slug/"index.html"
|
537
|
-
<<-HTML
|
538
|
-
<font size=-1>#{meta.date} </font> <br>
|
539
|
-
<font size=+2 color=blue><a href=../#{ref} style="text-decoration: none">#{meta.title}</font></a>
|
540
|
-
<br>
|
541
|
-
<font size=+1>#{meta.teaser} </font>
|
542
|
-
<a href=../#{ref} style="text-decoration: none">Read more...</a>
|
543
|
-
<br>
|
544
|
-
<hr>
|
545
|
-
HTML
|
567
|
+
views.each {|view| _handle_post(draft, view) }
|
568
|
+
rescue => err
|
569
|
+
_tmp_error(err)
|
546
570
|
end
|
547
571
|
|
548
572
|
def rebuild_post(file)
|
@@ -556,12 +580,11 @@ class RuneBlog
|
|
556
580
|
@views_dirty.flatten!
|
557
581
|
@views_dirty.uniq!
|
558
582
|
rescue => err
|
559
|
-
|
560
|
-
getch
|
583
|
+
_tmp_error(err)
|
561
584
|
end
|
562
585
|
|
563
586
|
def remove_post(num)
|
564
|
-
log!(enter: __method__, args: [num])
|
587
|
+
log!(enter: __method__, args: [num], level: 1)
|
565
588
|
raise ArgumentError unless num.is_a?(Integer)
|
566
589
|
# FIXME update original draft .views
|
567
590
|
tag = prefix(num)
|
@@ -578,7 +601,7 @@ class RuneBlog
|
|
578
601
|
end
|
579
602
|
|
580
603
|
def undelete_post(num)
|
581
|
-
log!(enter: __method__, args: [num])
|
604
|
+
log!(enter: __method__, args: [num], level: 1)
|
582
605
|
raise ArgumentError unless num.is_a?(Integer)
|
583
606
|
files = Find.find(@root/:views).to_a
|
584
607
|
tag = prefix(num)
|
@@ -594,14 +617,14 @@ class RuneBlog
|
|
594
617
|
end
|
595
618
|
|
596
619
|
def delete_draft(num)
|
597
|
-
log!(enter: __method__, args: [num])
|
620
|
+
log!(enter: __method__, args: [num], level: 1)
|
598
621
|
raise ArgumentError unless num.is_a?(Integer)
|
599
622
|
tag = prefix(num)
|
600
623
|
system!("rm -rf #@root/drafts/#{tag}-*")
|
601
624
|
end
|
602
625
|
|
603
626
|
def make_slug(meta)
|
604
|
-
log!(enter: __method__, args: [meta])
|
627
|
+
log!(enter: __method__, args: [meta], level: 3)
|
605
628
|
raise ArgumentError unless meta.title.is_a?(String)
|
606
629
|
label = '%04d' % meta.num # FIXME can do better
|
607
630
|
slug0 = meta.title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
|
@@ -609,6 +632,5 @@ class RuneBlog
|
|
609
632
|
meta.slug = str
|
610
633
|
str
|
611
634
|
end
|
612
|
-
|
613
635
|
end
|
614
636
|
|