runeblog 0.2.40 → 0.2.45
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/blog +4 -7
- data/empty_view/themes/standard/blog/post_entry.lt3 +11 -10
- data/empty_view/themes/standard/etc/blog.css.lt3 +6 -1
- 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/post/generate.lt3 +9 -4
- 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 -4
- data/lib/global.rb +8 -7
- data/lib/helpers-blog.rb +15 -15
- data/lib/liveblog.rb +47 -18
- data/lib/logging.rb +17 -8
- data/lib/post.rb +6 -6
- data/lib/publish.rb +4 -4
- data/lib/repl.rb +1 -0
- data/lib/runeblog.rb +77 -47
- data/lib/runeblog_version.rb +1 -1
- data/lib/view.rb +2 -8
- data/lib/xlate.rb +2 -2
- data/test/austin.rb +157 -0
- 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/liveblog.rb
CHANGED
@@ -33,6 +33,25 @@ def post
|
|
33
33
|
_out " <!-- Post number #{@meta.num} -->\n "
|
34
34
|
end
|
35
35
|
|
36
|
+
def post_trailer
|
37
|
+
perma = _var("publish.proto") + "://" + _var("publish.server") +
|
38
|
+
"/" + _var("publish.path") + "/permalink/" + _var("post.aslug") +
|
39
|
+
".html"
|
40
|
+
tags = _var("post.tags")
|
41
|
+
if tags.empty?
|
42
|
+
taglist = ""
|
43
|
+
else
|
44
|
+
taglist = "Tags: #{tags}"
|
45
|
+
end
|
46
|
+
_out <<~HTML
|
47
|
+
<table width=100%><tr>
|
48
|
+
<td width=10%><a style="text-decoration: none" href="javascript:history.go(-1)">[Back]</a></td>
|
49
|
+
<td width=10%><a style="text-decoration: none" href="#{perma}"> [permalink] </a></td>
|
50
|
+
<td width=80% align=right><font size=-3>#{taglist}</font></td></tr></table>
|
51
|
+
HTML
|
52
|
+
# damned syntax highlighting
|
53
|
+
end
|
54
|
+
|
36
55
|
def backlink
|
37
56
|
_out %[<br><a href="javascript:history.go(-1)">[Back]</a>]
|
38
57
|
end
|
@@ -109,17 +128,17 @@ end
|
|
109
128
|
|
110
129
|
|
111
130
|
def make_main_links
|
112
|
-
log!(enter: __method__)
|
131
|
+
log!(enter: __method__, level: 1)
|
113
132
|
# FIXME remember strings may not be safe
|
114
133
|
line = _data.chomp
|
115
134
|
tag, card_title = *line.split(" ", 2)
|
116
135
|
cardfile, mainfile = "#{tag}-card", "#{tag}-main"
|
117
136
|
input = "list.data"
|
118
|
-
log!(str: "Reading #{input}", pwd: true)
|
137
|
+
log!(str: "Reading #{input}", pwd: true, level: 3)
|
119
138
|
pairs = File.readlines(input).map {|line| line.chomp.split(/, */, 2) }
|
120
139
|
_write_main(mainfile, pairs, card_title, tag)
|
121
140
|
_write_card(cardfile, mainfile, pairs, card_title, tag)
|
122
|
-
log!(str: "...returning from method", pwd: true)
|
141
|
+
log!(str: "...returning from method", pwd: true, level: 3)
|
123
142
|
end
|
124
143
|
|
125
144
|
### inset
|
@@ -154,7 +173,8 @@ def title
|
|
154
173
|
title = @_data.chomp
|
155
174
|
@meta.title = title
|
156
175
|
setvar :title, title
|
157
|
-
|
176
|
+
# FIXME refactor -- just output variables for a template
|
177
|
+
# _out %[<h1 class="post-title">#{title}</h1><br>]
|
158
178
|
_optional_blank_line
|
159
179
|
end
|
160
180
|
|
@@ -285,7 +305,6 @@ def head # Does NOT output tags
|
|
285
305
|
hash = defaults.dup.update(result) # FIXME collisions?
|
286
306
|
|
287
307
|
hash.each_value {|x| _out " " + x }
|
288
|
-
_out "<body>"
|
289
308
|
end
|
290
309
|
|
291
310
|
########## newer stuff...
|
@@ -356,16 +375,26 @@ def sidebar
|
|
356
375
|
tcard = "#{tag}-card.html"
|
357
376
|
|
358
377
|
code = _load_local(tag)
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
378
|
+
if code
|
379
|
+
if ["pages", "links"].include? tag
|
380
|
+
Dir.chdir(wtag) do
|
381
|
+
widget = code.new(@blog)
|
382
|
+
widget.build
|
383
|
+
end
|
384
|
+
end
|
385
|
+
end
|
386
|
+
|
387
|
+
if tag == "ad"
|
388
|
+
num = rand(1..4)
|
389
|
+
img = "widgets/ad/ad#{num}.png"
|
390
|
+
src, dst = img, @root/:views/@view_name/"remote/widgets/ad/"
|
391
|
+
system!("cp #{src} #{dst}") # , show: true)
|
392
|
+
File.open(wtag/"vars.lt3", "w") do |f|
|
393
|
+
f.puts ".set ad.image = #{img}"
|
394
|
+
end
|
395
|
+
end
|
396
|
+
|
397
|
+
xlate cwd: wtag, src: tag, dst: tcard # , debug: (tag == "ad")
|
369
398
|
_include_file wtag/tcard
|
370
399
|
end
|
371
400
|
_out %[</div>]
|
@@ -574,7 +603,7 @@ def _html_body(file, css = nil)
|
|
574
603
|
end
|
575
604
|
|
576
605
|
def _write_card(cardfile, mainfile, pairs, card_title, tag)
|
577
|
-
log!(str: "Creating #{cardfile}.html", pwd: true)
|
606
|
+
log!(str: "Creating #{cardfile}.html", pwd: true, level: 2)
|
578
607
|
url = mainfile
|
579
608
|
url = :widgets/tag/mainfile + ".html"
|
580
609
|
File.open("#{cardfile}.html", "w") do |f|
|
@@ -589,7 +618,7 @@ def _write_card(cardfile, mainfile, pairs, card_title, tag)
|
|
589
618
|
</h5>
|
590
619
|
<div class="collapse" id="#{tag}">
|
591
620
|
EOS
|
592
|
-
log!(str: "Writing data pairs to #{cardfile}.html", pwd: true)
|
621
|
+
log!(str: "Writing data pairs to #{cardfile}.html", pwd: true, level: 2)
|
593
622
|
local = _local_tag?(tag)
|
594
623
|
pairs.each do |file, title|
|
595
624
|
url = file
|
@@ -662,7 +691,7 @@ def _write_main_pages(mainfile, pairs, card_title, tag)
|
|
662
691
|
end
|
663
692
|
|
664
693
|
def _write_main(mainfile, pairs, card_title, tag)
|
665
|
-
log!(str: "Creating #{mainfile}.html", pwd: true)
|
694
|
+
log!(str: "Creating #{mainfile}.html", pwd: true, level: 2)
|
666
695
|
|
667
696
|
if tag == "pages" # temporary experiment
|
668
697
|
_write_main_pages(mainfile, pairs, card_title, tag)
|
data/lib/logging.rb
CHANGED
@@ -2,8 +2,17 @@ unless self.respond_to?("log!")
|
|
2
2
|
$logging = true
|
3
3
|
$log = File.new("/tmp/runeblog.log","w")
|
4
4
|
|
5
|
-
def
|
5
|
+
def outlog(str = "", stderr: false)
|
6
|
+
$log.puts str
|
7
|
+
STDERR.puts str if stderr
|
8
|
+
end
|
9
|
+
|
10
|
+
def log!(str: "", enter: nil, args: [], pwd: false, dir: false, level: 0, stderr: false)
|
6
11
|
return unless $logging
|
12
|
+
@err_level ||= ENV['RUNEBLOG_ERROR_LEVEL']
|
13
|
+
@err_level ||= 0
|
14
|
+
return if level < @err_level
|
15
|
+
|
7
16
|
time = Time.now.strftime("%H:%M:%S")
|
8
17
|
|
9
18
|
meth = ""
|
@@ -17,16 +26,16 @@ unless self.respond_to?("log!")
|
|
17
26
|
str = " ... #{str}" unless str.empty?
|
18
27
|
indent = " "*12
|
19
28
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
29
|
+
outlog "#{time} #{meth}#{para}"
|
30
|
+
outlog "#{indent} #{str} " unless str.empty?
|
31
|
+
outlog "#{indent} #{source}"
|
32
|
+
outlog "#{indent} pwd = #{Dir.pwd} " if pwd
|
24
33
|
if dir
|
25
34
|
files = (Dir.entries('.') - %w[. ..]).join(" ")
|
26
|
-
|
35
|
+
outlog "#{indent} dir/* = #{files}"
|
27
36
|
end
|
28
|
-
#
|
29
|
-
|
37
|
+
# outlog "#{indent} livetext params = #{livedata.inpect} " unless livedata.nil?
|
38
|
+
outlog
|
30
39
|
$log.close
|
31
40
|
$log = File.new("/tmp/runeblog.log","a")
|
32
41
|
end
|
data/lib/post.rb
CHANGED
@@ -10,14 +10,14 @@ class RuneBlog::Post
|
|
10
10
|
include RuneBlog::Helpers
|
11
11
|
|
12
12
|
def self.files(num, root)
|
13
|
-
log!(enter: __method__, args: [num, root])
|
13
|
+
log!(enter: __method__, args: [num, root], level: 3)
|
14
14
|
files = Find.find(root).to_a
|
15
15
|
result = files.grep(/#{prefix(num)}-/)
|
16
16
|
result
|
17
17
|
end
|
18
18
|
|
19
19
|
def self.load(post)
|
20
|
-
log!(enter: __method__, args: [post])
|
20
|
+
log!(enter: __method__, args: [post], level: 3)
|
21
21
|
raise "Doesn't work right now"
|
22
22
|
raise NoBlogAccessor if RuneBlog.blog.nil?
|
23
23
|
# "post" is a slug
|
@@ -36,7 +36,7 @@ class RuneBlog::Post
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def write_metadata(meta) # FIXME ???
|
39
|
-
log!(enter: __method__, args: [meta])
|
39
|
+
log!(enter: __method__, args: [meta], level: 3)
|
40
40
|
debug "=== write_metadata:"
|
41
41
|
debug "-----\n#{meta.inspect}\n-----"
|
42
42
|
fname2 = "metadata.txt"
|
@@ -57,7 +57,7 @@ class RuneBlog::Post
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def initialize
|
60
|
-
log!(enter: __method__)
|
60
|
+
log!(enter: __method__, level: 3)
|
61
61
|
@blog = RuneBlog.blog || raise(NoBlogAccessor)
|
62
62
|
@meta = OpenStruct.new
|
63
63
|
end
|
@@ -115,7 +115,7 @@ class RuneBlog::ViewPost
|
|
115
115
|
:teaser_text
|
116
116
|
|
117
117
|
def initialize(view, postdir)
|
118
|
-
log!(enter: __method__, args: [view, postdir])
|
118
|
+
log!(enter: __method__, args: [view, postdir], level: 3)
|
119
119
|
# Assumes already parsed/processed
|
120
120
|
@blog = RuneBlog.blog || raise(NoBlogAccessor)
|
121
121
|
@path = postdir.dup
|
@@ -131,7 +131,7 @@ class RuneBlog::ViewPost
|
|
131
131
|
end
|
132
132
|
|
133
133
|
def get_dirs
|
134
|
-
log!(enter: __method__, args: [view, postdir])
|
134
|
+
log!(enter: __method__, args: [view, postdir], level: 3)
|
135
135
|
fname = File.basename(draft)
|
136
136
|
noext = fname.sub(/.lt3$/, "")
|
137
137
|
vdir = @root/:views/view
|
data/lib/publish.rb
CHANGED
@@ -21,25 +21,25 @@ 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
|
data/lib/repl.rb
CHANGED
data/lib/runeblog.rb
CHANGED
@@ -53,7 +53,7 @@ class RuneBlog
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def self.create(root = ".blogs")
|
56
|
-
log!(enter: __method__, args: [root])
|
56
|
+
log!(enter: __method__, args: [root], level: 1)
|
57
57
|
# Crude - FIXME later - # What views are there? Publishing, etc.
|
58
58
|
self.blog = self # Weird. Like a singleton - dumbass circular dependency?
|
59
59
|
root = Dir.pwd/root
|
@@ -101,7 +101,7 @@ class RuneBlog
|
|
101
101
|
end
|
102
102
|
|
103
103
|
def _deploy_local(dir)
|
104
|
-
log!(enter: __method__, args: [dir])
|
104
|
+
log!(enter: __method__, args: [dir], level: 1)
|
105
105
|
Dir.chdir(dir) do
|
106
106
|
views = _retrieve_metadata(:views)
|
107
107
|
views.each {|v| system!("cp *html #@root/views/#{v}/remote") }
|
@@ -132,7 +132,7 @@ class RuneBlog
|
|
132
132
|
end
|
133
133
|
|
134
134
|
def process_post(sourcefile)
|
135
|
-
log!(enter: __method__, args: [dir])
|
135
|
+
log!(enter: __method__, args: [dir], level: 2)
|
136
136
|
nslug = sourcefile.sub(/.lt3/, "")
|
137
137
|
dir = @root/:posts/nslug
|
138
138
|
create_dir(dir)
|
@@ -141,7 +141,7 @@ class RuneBlog
|
|
141
141
|
end
|
142
142
|
|
143
143
|
def inspect
|
144
|
-
log!(enter: __method__)
|
144
|
+
log!(enter: __method__, level: 3)
|
145
145
|
str = "blog: "
|
146
146
|
ivars = ["@root", "@sequence"] # self.instance_variables
|
147
147
|
ivars.each do |iv|
|
@@ -152,30 +152,30 @@ class RuneBlog
|
|
152
152
|
end
|
153
153
|
|
154
154
|
def view?(name)
|
155
|
-
log!(enter: __method__, args: [name])
|
155
|
+
log!(enter: __method__, args: [name], level: 3)
|
156
156
|
raise ArgumentError unless name.is_a?(String) && ! name.empty?
|
157
157
|
views.any? {|x| x.name == name }
|
158
158
|
end
|
159
159
|
|
160
160
|
def view(name = nil)
|
161
|
-
log!(enter: __method__, args: [name])
|
161
|
+
log!(enter: __method__, args: [name], level: 3)
|
162
162
|
raise ArgumentError unless name.nil? || (name.is_a?(String) && ! name.empty?)
|
163
163
|
name.nil? ? @view : str2view(name)
|
164
164
|
end
|
165
165
|
|
166
166
|
def str2view(str)
|
167
|
-
log!(enter: __method__, args: [str])
|
167
|
+
log!(enter: __method__, args: [str], level: 3)
|
168
168
|
raise ArgumentError unless str.is_a?(String) && ! str.empty?
|
169
169
|
@views.find {|x| x.name == str }
|
170
170
|
end
|
171
171
|
|
172
172
|
def _set_publisher
|
173
|
-
log!(enter: __method__)
|
173
|
+
log!(enter: __method__, level: 3)
|
174
174
|
@view.publisher = RuneBlog::Publishing.new(@view.to_s) # FIXME refactor
|
175
175
|
end
|
176
176
|
|
177
177
|
def view=(arg)
|
178
|
-
log!(enter: __method__, args: [arg])
|
178
|
+
log!(enter: __method__, args: [arg], level: 2)
|
179
179
|
case arg
|
180
180
|
when RuneBlog::View
|
181
181
|
@view = arg
|
@@ -191,19 +191,19 @@ class RuneBlog
|
|
191
191
|
end
|
192
192
|
|
193
193
|
def get_sequence
|
194
|
-
log!(enter: __method__)
|
194
|
+
log!(enter: __method__, level: 3)
|
195
195
|
File.read(@root/:sequence).to_i
|
196
196
|
end
|
197
197
|
|
198
198
|
def next_sequence
|
199
|
-
log!(enter: __method__)
|
199
|
+
log!(enter: __method__, level: 3)
|
200
200
|
@sequence += 1
|
201
201
|
dump(@sequence, @root/:sequence)
|
202
202
|
@sequence
|
203
203
|
end
|
204
204
|
|
205
205
|
def viewdir(v = nil) # delete?
|
206
|
-
log!(enter: __method__, args: [v])
|
206
|
+
log!(enter: __method__, args: [v], level: 3)
|
207
207
|
v = str2view(v) if v.is_a?(String)
|
208
208
|
raise ArgumentError unless v.nil? || v.is_a?(RuneBlog::View)
|
209
209
|
v ||= @view
|
@@ -211,17 +211,17 @@ class RuneBlog
|
|
211
211
|
end
|
212
212
|
|
213
213
|
def self.exist?
|
214
|
-
log!(enter: __method__)
|
214
|
+
log!(enter: __method__, level: 3)
|
215
215
|
Dir.exist?(DotDir) && File.exist?(DotDir/ConfigFile)
|
216
216
|
end
|
217
217
|
|
218
218
|
def mark_last_published(str)
|
219
|
-
log!(enter: __method__, args: [str])
|
219
|
+
log!(enter: __method__, args: [str], level: 2)
|
220
220
|
dump(str, "#{self.view.dir}/last_published")
|
221
221
|
end
|
222
222
|
|
223
223
|
def add_view(view_name)
|
224
|
-
log!(enter: __method__, args: [view_name])
|
224
|
+
log!(enter: __method__, args: [view_name], level: 2)
|
225
225
|
view = RuneBlog::View.new(view_name)
|
226
226
|
@view = view # current view
|
227
227
|
@views << view # all views
|
@@ -229,7 +229,7 @@ class RuneBlog
|
|
229
229
|
end
|
230
230
|
|
231
231
|
def make_empty_view_tree(view_name)
|
232
|
-
log!(enter: __method__, args: [view_name])
|
232
|
+
log!(enter: __method__, args: [view_name], level: 2)
|
233
233
|
Dir.chdir(@root) do
|
234
234
|
cmd = "cp -r #{RuneBlog::Path}/../empty_view views/#{view_name}"
|
235
235
|
system!(cmd)
|
@@ -237,7 +237,7 @@ class RuneBlog
|
|
237
237
|
end
|
238
238
|
|
239
239
|
def check_valid_new_view(view_name)
|
240
|
-
log!(enter: __method__, args: [view_name])
|
240
|
+
log!(enter: __method__, args: [view_name], level: 3)
|
241
241
|
raise ArgumentError unless view_name.is_a?(String)
|
242
242
|
raise ArgumentError if view_name.empty?
|
243
243
|
names = self.views.map(&:to_s)
|
@@ -249,9 +249,11 @@ class RuneBlog
|
|
249
249
|
end
|
250
250
|
|
251
251
|
def create_view(view_name)
|
252
|
-
log!(enter: __method__, args: [view_name])
|
252
|
+
log!(enter: __method__, args: [view_name], level: 2)
|
253
253
|
check_valid_new_view(view_name)
|
254
254
|
make_empty_view_tree(view_name)
|
255
|
+
# STDERR.puts "Made empty tree!"
|
256
|
+
# system("bash")
|
255
257
|
add_view(view_name)
|
256
258
|
mark_last_published("Initial creation")
|
257
259
|
end
|
@@ -267,7 +269,7 @@ class RuneBlog
|
|
267
269
|
end
|
268
270
|
|
269
271
|
def view_files
|
270
|
-
log!(enter: __method__)
|
272
|
+
log!(enter: __method__, level: 2)
|
271
273
|
vdir = self.view.dir
|
272
274
|
files = [vdir/"index.html"]
|
273
275
|
files += posts.map {|x| vdir/x }
|
@@ -275,7 +277,7 @@ class RuneBlog
|
|
275
277
|
end
|
276
278
|
|
277
279
|
def post_lookup(postid) # side-effect?
|
278
|
-
log!(enter: __method__, args: [postid])
|
280
|
+
log!(enter: __method__, args: [postid], level: 2)
|
279
281
|
slug = title = date = teaser_text = nil
|
280
282
|
|
281
283
|
dir_posts = @vdir/:posts
|
@@ -289,8 +291,8 @@ class RuneBlog
|
|
289
291
|
vp
|
290
292
|
end
|
291
293
|
|
292
|
-
def
|
293
|
-
log!(enter: __method__, args: [slug])
|
294
|
+
def index_entry(slug)
|
295
|
+
log!(enter: __method__, args: [slug], level: 2)
|
294
296
|
id = slug.to_i
|
295
297
|
text = nil
|
296
298
|
@theme = @view.dir/"themes/standard"
|
@@ -303,13 +305,13 @@ class RuneBlog
|
|
303
305
|
path = vp.path
|
304
306
|
url = aslug + ".html"
|
305
307
|
date = ::Date.parse(date)
|
306
|
-
date = date.strftime("%B %e<br>%Y")
|
308
|
+
date = date.strftime("%B %e<br><div style='float: right'>%Y</div>")
|
307
309
|
text = interpolate(@_post_entry, binding)
|
308
310
|
text
|
309
311
|
end
|
310
312
|
|
311
313
|
def collect_recent_posts(file)
|
312
|
-
log!(enter: __method__, args: [file])
|
314
|
+
log!(enter: __method__, args: [file], level: 3)
|
313
315
|
posts = nil
|
314
316
|
dir_posts = @vdir/:posts
|
315
317
|
entries = Dir.entries(dir_posts)
|
@@ -328,18 +330,19 @@ class RuneBlog
|
|
328
330
|
wanted.times do
|
329
331
|
postid = File.basename(enum.next)
|
330
332
|
postid = postid.to_i
|
331
|
-
text <<
|
333
|
+
text << index_entry(postid) # side effect! calls _out
|
332
334
|
end
|
333
335
|
text << "</body></html>"
|
334
336
|
File.write(@vdir/:remote/file, text)
|
335
337
|
end
|
336
338
|
|
337
|
-
def create_new_post(title, testing = false, teaser: nil, body: nil,
|
338
|
-
|
339
|
+
def create_new_post(title, testing = false, teaser: nil, body: nil,
|
340
|
+
pubdate: Time.now.strftime("%Y-%m-%d"), views: [])
|
341
|
+
log!(enter: __method__, args: [title, testing, teaser, body, views], level: 1)
|
339
342
|
meta = nil
|
340
343
|
views = views + [self.view.to_s]
|
341
344
|
Dir.chdir(@root/:posts) do
|
342
|
-
post = Post.create(title: title, teaser: teaser, body: body, views: views)
|
345
|
+
post = Post.create(title: title, teaser: teaser, body: body, pubdate: pubdate, views: views)
|
343
346
|
post.edit unless testing
|
344
347
|
post.build
|
345
348
|
meta = post.meta
|
@@ -351,7 +354,7 @@ class RuneBlog
|
|
351
354
|
end
|
352
355
|
|
353
356
|
def edit_initial_post(file, testing = false)
|
354
|
-
log!(enter: __method__, args: [file, testing])
|
357
|
+
log!(enter: __method__, args: [file, testing], level: 3)
|
355
358
|
debug "=== edit_initial_post #{file.inspect} => #{sourcefile}"
|
356
359
|
sourcefile = @root/:drafts/file
|
357
360
|
result = system!("#@editor #{sourcefile} +8") unless testing
|
@@ -363,20 +366,20 @@ class RuneBlog
|
|
363
366
|
end
|
364
367
|
|
365
368
|
def posts
|
366
|
-
log!(enter: __method__)
|
369
|
+
log!(enter: __method__, level: 3)
|
367
370
|
dir = self.view.dir/:posts
|
368
371
|
posts = Dir.entries(dir).grep(/^\d{4}/)
|
369
372
|
posts
|
370
373
|
end
|
371
374
|
|
372
375
|
def drafts
|
373
|
-
log!(enter: __method__)
|
376
|
+
log!(enter: __method__, level: 3)
|
374
377
|
dir = @root/:drafts
|
375
378
|
drafts = Dir.entries(dir).grep(/^\d{4}.*/)
|
376
379
|
end
|
377
380
|
|
378
381
|
def change_view(view)
|
379
|
-
log!(enter: __method__, args: [view])
|
382
|
+
log!(enter: __method__, args: [view], level: 3)
|
380
383
|
raise ArgumentError unless view.is_a?(String) || view.is_a?(RuneBlog::View)
|
381
384
|
x = OpenStruct.new
|
382
385
|
x.root, x.current_view, x.editor = @root, view.to_s, @editor # dumb - FIXME later
|
@@ -400,7 +403,7 @@ class RuneBlog
|
|
400
403
|
src: "blog.css.lt3", copy: vdir/"remote/etc/blog.css" # , debug: true
|
401
404
|
xlate cwd: vdir/"themes/standard",
|
402
405
|
src: "blog/generate.lt3", dst: vdir/:remote/"index.html"
|
403
|
-
|
406
|
+
# generate_index(view) # recent posts (recent.html)
|
404
407
|
# ^ HERE
|
405
408
|
copy("#{vdir}/assets/*", "#{vdir}/remote/assets/")
|
406
409
|
rescue => err
|
@@ -411,7 +414,7 @@ class RuneBlog
|
|
411
414
|
end
|
412
415
|
|
413
416
|
def _get_views(draft)
|
414
|
-
log!(enter: __method__, args: [draft])
|
417
|
+
log!(enter: __method__, args: [draft], level: 2)
|
415
418
|
# FIXME dumb code
|
416
419
|
view_line = File.readlines(draft).grep(/^.views /)
|
417
420
|
raise "More than one .views call!" if view_line.size > 1
|
@@ -422,7 +425,7 @@ class RuneBlog
|
|
422
425
|
end
|
423
426
|
|
424
427
|
def _copy_get_dirs(draft, view)
|
425
|
-
log!(enter: __method__, args: [draft, view])
|
428
|
+
log!(enter: __method__, args: [draft, view], level: 2)
|
426
429
|
fname = File.basename(draft)
|
427
430
|
noext = fname.sub(/.lt3$/, "")
|
428
431
|
vdir = @root/:views/view
|
@@ -435,18 +438,42 @@ class RuneBlog
|
|
435
438
|
end
|
436
439
|
|
437
440
|
def _post_metadata(draft, pdraft)
|
438
|
-
log!(enter: __method__, args: [draft, pdraft])
|
441
|
+
log!(enter: __method__, args: [draft, pdraft], level: 2)
|
442
|
+
# FIXME store this somewhere
|
443
|
+
fname = File.basename(draft) # 0001-this-is-a-post.lt3
|
444
|
+
nslug = fname.sub(/.lt3$/, "") # 0001-this-is-a-post
|
445
|
+
aslug = nslug.sub(/\d\d\d\d-/, "") # this-is-a-post
|
446
|
+
pnum = nslug[0..3] # 0001
|
439
447
|
Dir.chdir(pdraft) do
|
440
448
|
excerpt = File.read("teaser.txt")
|
449
|
+
date = _retrieve_metadata(:date)
|
450
|
+
longdate = ::Date.parse(date).strftime("%B %e, %Y")
|
441
451
|
title = _retrieve_metadata(:title)
|
442
|
-
|
443
|
-
|
452
|
+
tags = _retrieve_metadata(:tags)
|
453
|
+
vars = <<~LIVE
|
454
|
+
.set post.num = #{pnum}
|
455
|
+
.heredoc post.aslug
|
456
|
+
#{aslug}
|
457
|
+
.end
|
458
|
+
.heredoc title
|
459
|
+
#{title.chomp}
|
460
|
+
.end
|
461
|
+
.heredoc post.tags
|
462
|
+
#{tags.join(" ")}
|
463
|
+
.end
|
464
|
+
.heredoc teaser
|
465
|
+
#{excerpt.chomp}
|
466
|
+
.end
|
467
|
+
.heredoc longdate
|
468
|
+
#{longdate}
|
469
|
+
.end
|
470
|
+
LIVE
|
444
471
|
File.open(pdraft/"vars.lt3", "w") {|f| f.puts vars }
|
445
472
|
end
|
446
473
|
end
|
447
474
|
|
448
475
|
def copy_widget_html(view)
|
449
|
-
log!(enter: __method__)
|
476
|
+
log!(enter: __method__, level: 2)
|
450
477
|
vdir = @root/:views/view
|
451
478
|
remote = vdir/:remote
|
452
479
|
wdir = vdir/:themes/:standard/:widgets
|
@@ -457,12 +484,15 @@ class RuneBlog
|
|
457
484
|
create_dirs(rem)
|
458
485
|
files = Dir[w/"*"]
|
459
486
|
files = files.select {|x| x =~ /(html|css)$/ }
|
460
|
-
|
487
|
+
# files.each {|f| STDERR.puts " #{f.inspect}" }
|
488
|
+
tag = File.basename(w)
|
489
|
+
# STDERR.puts "--- tag: #{tag.inspect}"
|
490
|
+
files.each {|file| system!("cp #{file} #{rem}", show: (tag == "zzz")) }
|
461
491
|
end
|
462
492
|
end
|
463
493
|
|
464
494
|
def _handle_post(draft, view)
|
465
|
-
log!(enter: __method__, args: [draft, view])
|
495
|
+
log!(enter: __method__, args: [draft, view], level: 2)
|
466
496
|
# break into separate methods?
|
467
497
|
|
468
498
|
fname = File.basename(draft) # 0001-this-is-a-post.lt3
|
@@ -491,7 +521,7 @@ class RuneBlog
|
|
491
521
|
end
|
492
522
|
|
493
523
|
def generate_post(draft)
|
494
|
-
log!(enter: __method__, args: [draft])
|
524
|
+
log!(enter: __method__, args: [draft], level: 1)
|
495
525
|
views = _get_views(draft)
|
496
526
|
views.each do |view|
|
497
527
|
_handle_post(draft, view)
|
@@ -500,7 +530,7 @@ class RuneBlog
|
|
500
530
|
end
|
501
531
|
end
|
502
532
|
|
503
|
-
def
|
533
|
+
def OLD_index_entry(view, meta)
|
504
534
|
log!(enter: __method__, args: [view, meta])
|
505
535
|
debug "=== index_entry #{view.to_s.inspect} #{meta.num} #{meta.title.inspect}"
|
506
536
|
check_meta(meta, "index_entry1")
|
@@ -537,7 +567,7 @@ class RuneBlog
|
|
537
567
|
end
|
538
568
|
|
539
569
|
def remove_post(num)
|
540
|
-
log!(enter: __method__, args: [num])
|
570
|
+
log!(enter: __method__, args: [num], level: 1)
|
541
571
|
raise ArgumentError unless num.is_a?(Integer)
|
542
572
|
# FIXME update original draft .views
|
543
573
|
tag = prefix(num)
|
@@ -554,7 +584,7 @@ class RuneBlog
|
|
554
584
|
end
|
555
585
|
|
556
586
|
def undelete_post(num)
|
557
|
-
log!(enter: __method__, args: [num])
|
587
|
+
log!(enter: __method__, args: [num], level: 1)
|
558
588
|
raise ArgumentError unless num.is_a?(Integer)
|
559
589
|
files = Find.find(@root/:views).to_a
|
560
590
|
tag = prefix(num)
|
@@ -570,14 +600,14 @@ class RuneBlog
|
|
570
600
|
end
|
571
601
|
|
572
602
|
def delete_draft(num)
|
573
|
-
log!(enter: __method__, args: [num])
|
603
|
+
log!(enter: __method__, args: [num], level: 1)
|
574
604
|
raise ArgumentError unless num.is_a?(Integer)
|
575
605
|
tag = prefix(num)
|
576
606
|
system!("rm -rf #@root/drafts/#{tag}-*")
|
577
607
|
end
|
578
608
|
|
579
609
|
def make_slug(meta)
|
580
|
-
log!(enter: __method__, args: [meta])
|
610
|
+
log!(enter: __method__, args: [meta], level: 3)
|
581
611
|
raise ArgumentError unless meta.title.is_a?(String)
|
582
612
|
label = '%04d' % meta.num # FIXME can do better
|
583
613
|
slug0 = meta.title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
|