runeblog 0.3.20 → 0.3.25
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/blog +80 -52
- data/data/global.lt3 +3 -3
- data/data/universal.lt3 +2 -0
- data/empty_view/data/GIT_IS_DUMB +0 -0
- data/empty_view/themes/standard/banner/top.lt3 +1 -1
- data/empty_view/themes/standard/blog/generate.lt3 +1 -1
- data/empty_view/themes/standard/etc/blog.css.lt3 +1 -1
- data/empty_view/themes/standard/post/generate.lt3 +2 -2
- data/empty_view/themes/standard/post/permalink.lt3 +1 -1
- data/lib/helpers-blog.rb +5 -4
- data/lib/liveblog.rb +80 -17
- data/lib/lowlevel.rb +25 -8
- data/lib/menus.rb +2 -1
- data/lib/newpost.rb +35 -26
- data/lib/post.rb +3 -2
- data/lib/processing.rb +29 -1
- data/lib/publish.rb +3 -1
- data/lib/repl.rb +63 -27
- data/lib/runeblog.rb +81 -49
- data/lib/runeblog_version.rb +1 -1
- data/lib/view.rb +22 -3
- data/runeblog.gemspec +4 -2
- metadata +30 -9
data/lib/lowlevel.rb
CHANGED
@@ -1,11 +1,18 @@
|
|
1
1
|
|
2
2
|
def _tmp_error(err)
|
3
|
+
STDERR.puts err
|
4
|
+
STDERR.puts err.backtrace.join("\n") if err.respond_to?(:backtrace)
|
5
|
+
log!(str: "#{err} - see also stderr.out")
|
6
|
+
log!(str: err.backtrace.join("\n")) if err.respond_to?(:backtrace)
|
7
|
+
return
|
8
|
+
|
3
9
|
out = "/tmp/blog#{rand(100)}.txt"
|
4
10
|
File.open(out, "w") do |f|
|
5
11
|
f.puts err.to_s + "\n--------"
|
6
12
|
f.puts err.backtrace.join("\n")
|
7
13
|
end
|
8
14
|
puts "Error: See #{out}"
|
15
|
+
# sleep 3
|
9
16
|
end
|
10
17
|
|
11
18
|
def dump(obj, name)
|
@@ -20,6 +27,7 @@
|
|
20
27
|
log!(enter: __method__, args: [str], level: 2)
|
21
28
|
STDERR.puts str if show
|
22
29
|
rc = system(str)
|
30
|
+
STDERR.puts " rc = #{rc.inspect}" if show
|
23
31
|
return rc if rc
|
24
32
|
STDERR.puts "FAILED: #{str.inspect}"
|
25
33
|
STDERR.puts "\ncaller = \n#{caller.join("\n ")}\n"
|
@@ -32,10 +40,12 @@
|
|
32
40
|
end
|
33
41
|
|
34
42
|
def _get_data?(file) # File need not exist
|
43
|
+
log!(enter: __method__, args: [file], level: 2)
|
35
44
|
File.exist?(file) ? _get_data(file) : []
|
36
45
|
end
|
37
46
|
|
38
47
|
def _get_data(file)
|
48
|
+
log!(enter: __method__, args: [file], level: 2)
|
39
49
|
lines = File.readlines(file)
|
40
50
|
lines = lines.map do |line|
|
41
51
|
line = line.chomp.strip
|
@@ -46,6 +56,7 @@
|
|
46
56
|
end
|
47
57
|
|
48
58
|
def read_pairs(file) # returns a hash
|
59
|
+
log!(enter: __method__, args: [file], level: 2)
|
49
60
|
lines = _get_data(file)
|
50
61
|
hash = {}
|
51
62
|
lines.each do |line|
|
@@ -57,6 +68,7 @@
|
|
57
68
|
end
|
58
69
|
|
59
70
|
def read_pairs!(file) # returns an openstruct
|
71
|
+
log!(enter: __method__, args: [file], level: 2)
|
60
72
|
lines = _get_data(file)
|
61
73
|
obj = OpenStruct.new
|
62
74
|
lines.each do |line|
|
@@ -97,27 +109,32 @@
|
|
97
109
|
end
|
98
110
|
|
99
111
|
def error(err)
|
100
|
-
|
101
|
-
str = "\n Error
|
112
|
+
log!(str: err, enter: __method__, args: [err], level: 2)
|
113
|
+
str = "\n Error... #{err}"
|
102
114
|
puts str
|
103
115
|
puts err.backtrace.join("\n")
|
104
116
|
end
|
105
117
|
|
106
|
-
def find_item(list)
|
118
|
+
def find_item(list, &block)
|
119
|
+
log!(enter: __method__, args: [list], level: 2)
|
107
120
|
list2 = list.select(&block)
|
108
|
-
exactly_one(list2)
|
121
|
+
exactly_one(list2, list.join("/"))
|
109
122
|
end
|
110
123
|
|
111
124
|
def find_item!(list, &block)
|
125
|
+
log!(enter: __method__, args: [list], level: 2)
|
126
|
+
list2 = list.select(&block)
|
112
127
|
list2 = list.select(&block)
|
113
|
-
item = exactly_one(list2)
|
128
|
+
item = exactly_one(list2, list.join("/"))
|
114
129
|
n = list.index(&block)
|
115
130
|
[n, item]
|
116
131
|
end
|
117
132
|
|
118
|
-
def exactly_one(list)
|
119
|
-
|
120
|
-
|
133
|
+
def exactly_one(list, tag = nil, &block)
|
134
|
+
log!(enter: __method__, args: [list], level: 2)
|
135
|
+
list2 = list.select(&block)
|
136
|
+
raise "List: Zero instances #{"- #{tag}" if tag}" if list.empty?
|
137
|
+
raise "List: More than one instance #{"- #{tag}" if tag}" if list.size > 1
|
121
138
|
list.first
|
122
139
|
end
|
123
140
|
|
data/lib/menus.rb
CHANGED
@@ -18,9 +18,10 @@ top_help = proc { RubyText.splash(RuneBlog::REPL::Help.gsub(/[{}]/, " ")) }
|
|
18
18
|
# dir = @blog.view.dir/"themes/standard/"
|
19
19
|
|
20
20
|
std = "themes/standard"
|
21
|
+
data = "." # CHANGED
|
21
22
|
|
22
23
|
Menu.top_config = {
|
23
|
-
"Variables (general)" => edit("#{
|
24
|
+
"Variables (general)" => edit("#{data}/global.lt3"),
|
24
25
|
" View-specific" => edit("settings/view.txt"),
|
25
26
|
" Recent posts" => edit("settings/recent.txt"),
|
26
27
|
" Publishing" => edit("settings/publish.txt"),
|
data/lib/newpost.rb
CHANGED
@@ -2,7 +2,7 @@ require 'rubytext'
|
|
2
2
|
|
3
3
|
RubyText.start
|
4
4
|
|
5
|
-
#
|
5
|
+
# Idea: A special sub-environment for creating a post
|
6
6
|
#
|
7
7
|
# 1. Display: view, post number, date
|
8
8
|
# 2. Menu?
|
@@ -15,44 +15,43 @@ RubyText.start
|
|
15
15
|
# 9. - Quit
|
16
16
|
# Edit body after save/quit
|
17
17
|
|
18
|
+
def ask(prompt) # elsewhere?
|
19
|
+
print prompt
|
20
|
+
str = gets
|
21
|
+
str.chomp! if str
|
22
|
+
str
|
23
|
+
end
|
24
|
+
|
18
25
|
def enter_title
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
@win.home
|
23
|
-
str = @win.gets
|
24
|
-
STDSCR.puts str.inspect
|
25
|
-
[__method__, 0]
|
26
|
+
puts __method__
|
27
|
+
str = ask("Title: ")
|
28
|
+
puts str.inspect
|
26
29
|
end
|
27
30
|
|
28
31
|
def edit_teaser
|
29
|
-
|
30
|
-
|
32
|
+
puts __method__
|
33
|
+
str = ask("Teaser: ")
|
34
|
+
puts str.inspect
|
31
35
|
end
|
32
36
|
|
33
37
|
def add_views
|
34
|
-
|
35
|
-
[__method__, 2]
|
38
|
+
puts __method__
|
36
39
|
end
|
37
40
|
|
38
41
|
def add_tags
|
39
|
-
|
40
|
-
[__method__, 3]
|
42
|
+
puts __method__
|
41
43
|
end
|
42
44
|
|
43
45
|
def import_assets
|
44
|
-
|
45
|
-
[__method__, 4]
|
46
|
+
puts __method__
|
46
47
|
end
|
47
48
|
|
48
49
|
def save_post
|
49
|
-
|
50
|
-
[__method__, 5]
|
50
|
+
puts __method__
|
51
51
|
end
|
52
52
|
|
53
53
|
def quit_post
|
54
|
-
|
55
|
-
[__method__, 6]
|
54
|
+
puts __method__
|
56
55
|
end
|
57
56
|
|
58
57
|
items = {
|
@@ -65,9 +64,19 @@ items = {
|
|
65
64
|
"Quit" => proc { quit_post }
|
66
65
|
}
|
67
66
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
67
|
+
enter_title
|
68
|
+
edit_teaser
|
69
|
+
add_views
|
70
|
+
add_tags
|
71
|
+
import_assets
|
72
|
+
save_post
|
73
|
+
quit_post
|
74
|
+
|
75
|
+
# getch
|
76
|
+
|
77
|
+
# curr = 0
|
78
|
+
# loop do
|
79
|
+
# str, curr = menu(c: 10, items: items, curr: curr, sticky: true)
|
80
|
+
# break if curr.nil?
|
81
|
+
# puts "str = #{str} curr = #{curr}"
|
82
|
+
# end
|
data/lib/post.rb
CHANGED
@@ -66,7 +66,7 @@ class RuneBlog::Post
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def edit
|
69
|
-
|
69
|
+
log!(enter: __method__)
|
70
70
|
edit_file(@draft, vim: "+8")
|
71
71
|
build
|
72
72
|
rescue => err
|
@@ -169,7 +169,8 @@ class RuneBlog::ViewPost
|
|
169
169
|
@date = meta.pubdate
|
170
170
|
end
|
171
171
|
rescue => err
|
172
|
-
STDERR.puts "--- #{err}
|
172
|
+
STDERR.puts "--- #{err}"
|
173
|
+
STDERR.puts " #{err.backtrace.join("\n ")}" if err.respond_to?(:backtrace)
|
173
174
|
end
|
174
175
|
|
175
176
|
def get_dirs
|
data/lib/processing.rb
CHANGED
@@ -23,7 +23,8 @@ end
|
|
23
23
|
def preprocess(cwd: Dir.pwd, src:,
|
24
24
|
dst: nil, strip: false,
|
25
25
|
deps: [], copy: nil, debug: false, force: false,
|
26
|
-
mix: [], call: [],
|
26
|
+
mix: [], call: [],
|
27
|
+
vars: {})
|
27
28
|
src += LEXT unless src.end_with?(LEXT)
|
28
29
|
if strip
|
29
30
|
dst = File.basename(src).sub(/.lt3$/,"")
|
@@ -31,6 +32,9 @@ def preprocess(cwd: Dir.pwd, src:,
|
|
31
32
|
dst += ".html" unless dst.end_with?(".html")
|
32
33
|
end
|
33
34
|
sp = " "*12
|
35
|
+
|
36
|
+
|
37
|
+
|
34
38
|
Dir.chdir(cwd) do
|
35
39
|
if debug
|
36
40
|
STDERR.puts "#{sp} -- preprocess "
|
@@ -40,20 +44,44 @@ def preprocess(cwd: Dir.pwd, src:,
|
|
40
44
|
STDERR.puts "#{sp} from: #{caller[0]}"
|
41
45
|
STDERR.puts "#{sp} copy: #{copy}" if copy
|
42
46
|
STDERR.puts "#{sp} vars: #{vars.inspect}" unless vars == {}
|
47
|
+
STDERR.flush
|
43
48
|
end
|
44
49
|
stale = stale?(src, dst, deps, force)
|
50
|
+
STDERR.puts <<~EOF if debug
|
51
|
+
STALE = #{stale}
|
52
|
+
cwd = #{cwd.inspect}
|
53
|
+
src = #{src.inspect}
|
54
|
+
dst = #{dst.inspect}
|
55
|
+
strip = #{strip.inspect}
|
56
|
+
deps = #{deps.inspect}
|
57
|
+
copy = #{copy.inspect}
|
58
|
+
debug = #{debug.inspect}
|
59
|
+
force = #{force.inspect}
|
60
|
+
mix = #{mix.inspect}
|
61
|
+
call = #{call.inspect}
|
62
|
+
vars = #{vars.inspect}
|
63
|
+
EOF
|
45
64
|
if stale
|
46
65
|
live = Livetext.customize(mix: "liveblog", call: call, vars: vars)
|
66
|
+
log!(str: "Calling xform_file... src = #{src} pwd = #{Dir.pwd}")
|
47
67
|
out = live.xform_file(src)
|
48
68
|
File.write(dst, out)
|
49
69
|
system!("cp #{dst} #{copy}") if copy
|
50
70
|
end
|
51
71
|
puts "#{sp} -- ^ Already up to date!" if debug && ! stale
|
52
72
|
end
|
73
|
+
rescue => err
|
74
|
+
msg = err.to_s
|
75
|
+
msg << err.backtrace.join("\n") if err.respond_to?(:backtrace)
|
76
|
+
STDERR.puts msg
|
77
|
+
STDERR.flush
|
78
|
+
log!(str: msg)
|
53
79
|
end
|
54
80
|
|
55
81
|
def get_live_vars(src)
|
56
82
|
live = Livetext.customize(call: [".nopara"])
|
83
|
+
# puts "glv: src = #{src.inspect}"
|
84
|
+
# STDERR.puts "glv: src = #{src.inspect}"
|
57
85
|
live.xform_file(src)
|
58
86
|
live
|
59
87
|
end
|
data/lib/publish.rb
CHANGED
@@ -14,7 +14,9 @@ class RuneBlog::Publishing
|
|
14
14
|
def initialize(view)
|
15
15
|
log!(enter: __method__, args: [view.to_s])
|
16
16
|
@blog = RuneBlog.blog
|
17
|
-
|
17
|
+
dir0 = @blog.root/:views/view/"themes/standard/"
|
18
|
+
# CHANGED
|
19
|
+
dir = @blog.root/:views/view/:data
|
18
20
|
gfile = dir/"global.lt3"
|
19
21
|
return unless File.exist?(gfile) # FIXME Hackish as hell
|
20
22
|
|
data/lib/repl.rb
CHANGED
@@ -176,7 +176,10 @@ module RuneBlog::REPL
|
|
176
176
|
result = system!("open #{local}")
|
177
177
|
raise CantOpen(local) unless result
|
178
178
|
rescue => err
|
179
|
-
|
179
|
+
msg = err.to_s
|
180
|
+
msg << "\n" << err.backtrace.join("\n") if err.respond_to?(:backtrace)
|
181
|
+
puts msg
|
182
|
+
log!(str: msg)
|
180
183
|
end
|
181
184
|
|
182
185
|
def cmd_publish
|
@@ -206,14 +209,14 @@ module RuneBlog::REPL
|
|
206
209
|
|
207
210
|
def regen_posts
|
208
211
|
drafts = @blog.drafts # current view
|
209
|
-
|
212
|
+
log! str: "=== Regenerating posts..." unless drafts.empty?
|
210
213
|
drafts.each do |draft|
|
211
214
|
orig = @blog.root/:drafts/draft
|
212
215
|
postdir = @blog.root/:posts/draft.sub(/.lt3$/, "")
|
213
216
|
content = postdir/"/guts.html"
|
214
217
|
next if fresh?(orig, content)
|
215
218
|
|
216
|
-
|
219
|
+
log! str: "=== Calling generate_post(#{orig})"
|
217
220
|
@blog.generate_post(orig) # rebuild post
|
218
221
|
Dir.chdir(postdir) do
|
219
222
|
meta = @blog.read_metadata
|
@@ -225,28 +228,34 @@ module RuneBlog::REPL
|
|
225
228
|
end
|
226
229
|
|
227
230
|
def cmd_rebuild
|
228
|
-
|
231
|
+
log! str: "=== Starting cmd_rebuild..."
|
229
232
|
puts
|
230
233
|
regen_posts
|
231
|
-
|
234
|
+
log! str: "=== Generating view..."
|
232
235
|
@blog.generate_view(@blog.view)
|
233
|
-
|
236
|
+
log! str: "=== Generating index..."
|
234
237
|
@blog.generate_index(@blog.view)
|
235
|
-
|
238
|
+
log! str: "=== ...finished!"
|
236
239
|
rescue => err
|
237
240
|
_tmp_error(err)
|
238
241
|
end
|
239
242
|
|
240
243
|
def cmd_change_view(arg = nil)
|
241
244
|
if arg.nil?
|
242
|
-
viewnames =
|
243
|
-
|
245
|
+
viewnames = {}
|
246
|
+
@blog.views.each do |v|
|
247
|
+
name = v.to_s
|
248
|
+
title = view2title(name)
|
249
|
+
string = "#{'%-25s' % title} #{name}"
|
250
|
+
viewnames[string] = name
|
251
|
+
end
|
252
|
+
n = viewnames.values.find_index(@blog.view.name)
|
244
253
|
name = @blog.view.name
|
245
|
-
# TODO: Add view description
|
246
254
|
k, name = STDSCR.menu(title: "Views", items: viewnames, curr: n)
|
247
255
|
return if name.nil?
|
256
|
+
log! str: "cv Setting to #{name.inspect}"
|
248
257
|
@blog.view = name
|
249
|
-
|
258
|
+
# puts "\n ", fx(name, :bold), "\n"
|
250
259
|
return
|
251
260
|
else
|
252
261
|
if @blog.view?(arg)
|
@@ -256,19 +265,40 @@ module RuneBlog::REPL
|
|
256
265
|
end
|
257
266
|
end
|
258
267
|
|
268
|
+
# move to helpers
|
269
|
+
def modify_view_global(view_name)
|
270
|
+
gfile = "#{@blog.root}/views/#{view_name}/data/global.lt3"
|
271
|
+
lines = File.readlines(gfile).map(&:chomp)
|
272
|
+
vars = <<~EOF
|
273
|
+
.variables
|
274
|
+
View #{view_name}
|
275
|
+
ViewDir #{@blog.root}/views/#{view_name}
|
276
|
+
.end
|
277
|
+
|
278
|
+
EOF
|
279
|
+
# lines.insert(5, vars)
|
280
|
+
text = lines.join("\n")
|
281
|
+
File.write(gfile, text)
|
282
|
+
end
|
283
|
+
|
284
|
+
def modify_view_settings(name:, title:, subtitle:, domain:)
|
285
|
+
vfile = "#{@blog.root}/views/#{name}/settings/view.txt"
|
286
|
+
hash = {/VIEW_NAME/ => name,
|
287
|
+
/VIEW_TITLE/ => title,
|
288
|
+
/VIEW_SUBTITLE/ => subtitle,
|
289
|
+
/VIEW_DOMAIN/ => domain}
|
290
|
+
@blog.complete_file(vfile, nil, hash)
|
291
|
+
end
|
292
|
+
|
259
293
|
def cmd_new_view(arg)
|
260
294
|
view_name = ask!(" Filename: ")
|
261
295
|
@blog.create_view(view_name) # call change_view??
|
262
296
|
title = ask!(" View title: ")
|
263
297
|
subtitle = ask!(" Subtitle : ")
|
264
298
|
domain = ask!(" Domain : ")
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
/VIEW_TITLE/ => title,
|
269
|
-
/VIEW_SUBTITLE/ => subtitle,
|
270
|
-
/VIEW_DOMAIN/ => domain}
|
271
|
-
@blog.complete_file(vfile, nil, hash)
|
299
|
+
modify_view_global(view_name)
|
300
|
+
modify_view_settings(name: view_name, title: title, subtitle: subtitle,
|
301
|
+
domain: domain)
|
272
302
|
@blog.change_view(view_name)
|
273
303
|
end
|
274
304
|
|
@@ -278,11 +308,13 @@ module RuneBlog::REPL
|
|
278
308
|
puts
|
279
309
|
end
|
280
310
|
@blog.create_view(arg)
|
281
|
-
|
282
|
-
File.write("#{@blog.root}/views/#{@blog.view}/themes/standard/global.lt3",
|
311
|
+
lines = File.read("#{@blog.root}/data/global.lt3")
|
312
|
+
# File.write("#{@blog.root}/views/#{@blog.view}/themes/standard/global.lt3",
|
313
|
+
File.write("#{@blog.root}/views/#{@blog.view}/data/global.lt3",
|
283
314
|
text.gsub(/VIEW_NAME/, @blog.view.to_s))
|
284
315
|
vim_params = '-c ":set hlsearch" -c ":hi Search ctermfg=2 ctermbg=6" +/"\(VIEW_.*\|SITE.*\)"'
|
285
|
-
edit_file(@blog.view.dir/"themes/standard/global.lt3", vim: vim_params)
|
316
|
+
# edit_file(@blog.view.dir/"themes/standard/global.lt3", vim: vim_params)
|
317
|
+
edit_file(@blog.view.dir/"data/global.lt3", vim: vim_params)
|
286
318
|
@blog.change_view(arg)
|
287
319
|
rescue ViewAlreadyExists
|
288
320
|
puts 'Blog already exists'
|
@@ -323,23 +355,26 @@ module RuneBlog::REPL
|
|
323
355
|
tag = "#{'%04d' % id}"
|
324
356
|
files = ::Find.find(@blog.root/:drafts).to_a
|
325
357
|
files = files.grep(/#{tag}-.*lt3/)
|
326
|
-
draft = exactly_one(files)
|
358
|
+
draft = exactly_one(files, files.join("/"))
|
327
359
|
result = edit_file(draft, vim: '-c$')
|
328
360
|
@blog.generate_post(draft)
|
329
361
|
rescue => err
|
330
362
|
_tmp_error(err)
|
331
363
|
end
|
332
364
|
|
365
|
+
def view2title(name) # FIXME: crufty as hell
|
366
|
+
lines = File.readlines(@blog.root/"views/#{name}/settings/view.txt")
|
367
|
+
lines.map!(&:chomp)
|
368
|
+
lines = lines.select {|x| x =~ /^title / && x !~ /VIEW_/ }
|
369
|
+
title = lines.first.split(" ", 2)[1]
|
370
|
+
end
|
371
|
+
|
333
372
|
def cmd_list_views
|
334
373
|
puts
|
335
374
|
@blog.views.each do |v|
|
336
375
|
v = v.to_s
|
376
|
+
title = view2title(v)
|
337
377
|
v = fx(v, :bold) if v == @blog.view.name
|
338
|
-
# FIXME: next 3 lines are crufty as hell
|
339
|
-
lines = File.readlines(@blog.root/"views/#{v}/settings/view.txt")
|
340
|
-
lines.map!(&:chomp)
|
341
|
-
lines = lines.select {|x| x =~ /^title / && x !~ /VIEW_/ }
|
342
|
-
title = lines.first.split(" ", 2)[1]
|
343
378
|
print " ", ('%15s' % v)
|
344
379
|
puts " ", fx(title, Black)
|
345
380
|
end
|
@@ -383,6 +418,7 @@ module RuneBlog::REPL
|
|
383
418
|
base = draft.sub(/.lt3$/, "")
|
384
419
|
dir = @blog.root/:posts/base
|
385
420
|
meta = nil
|
421
|
+
puts "Trying chdir into #{dir}..."
|
386
422
|
Dir.chdir(dir) { meta = @blog.read_metadata }
|
387
423
|
num, title = meta.num, meta.title
|
388
424
|
num = '%4d' % num.to_s
|