runeblog 0.2.46 → 0.2.51

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,7 +11,7 @@ class RuneBlog::Post
11
11
 
12
12
  def self.files(num, root)
13
13
  log!(enter: __method__, args: [num, root], level: 3)
14
- files = Find.find(root).to_a
14
+ files = ::Find.find(root).to_a
15
15
  result = files.grep(/#{prefix(num)}-/)
16
16
  result
17
17
  end
@@ -22,7 +22,6 @@ class RuneBlog::Post
22
22
  raise NoBlogAccessor if RuneBlog.blog.nil?
23
23
  # "post" is a slug
24
24
  pdir = RuneBlog.blog.view.dir/post
25
- verify(Dir.exist?(pdir) => "Directory #{pdir} not found")
26
25
  meta = nil
27
26
  Dir.chdir(pdir) do
28
27
  meta = read_config("metadata.txt")
@@ -63,8 +62,8 @@ class RuneBlog::Post
63
62
  end
64
63
 
65
64
  def self.create(title:, teaser:, body:, pubdate: Time.now.strftime("%Y-%m-%d"),
66
- views:[])
67
- log!(enter: __method__, args: [title, teaser, body, pubdate, views])
65
+ views:[], file: nil)
66
+ log!(enter: __method__, args: [title, teaser, body, pubdate, views], stderr: true)
68
67
  post = self.new
69
68
  # NOTE: This is the ONLY place next_sequence is called!
70
69
  num = post.meta.num = post.blog.next_sequence
@@ -73,27 +72,29 @@ class RuneBlog::Post
73
72
  post.meta.title, post.meta.teaser, post.meta.body, post.meta.pubdate =
74
73
  title, teaser, body, pubdate
75
74
  post.meta.views = [post.blog.view.to_s] + views
76
- # STDERR.puts "Post.create: views = #{views.inspect}"
77
75
  post.meta.tags = []
78
76
  post.blog.make_slug(post.meta) # adds to meta
79
77
 
80
78
  # create_draft
81
79
  viewhome = post.blog.view.publisher.url
82
80
  meta = post.meta
83
- text = RuneBlog.post_template(num: meta.num, title: meta.title, date: meta.pubdate,
84
- view: meta.view, teaser: meta.teaser, body: meta.body,
85
- views: meta.views, tags: meta.tags, home: viewhome)
86
- srcdir = post.blog.root/:drafts + "/"
87
- vpdir = post.blog.root/:drafts + "/"
88
- fname = meta.slug + ".lt3"
89
- post.draft = srcdir + fname
90
- dump(text, post.draft)
81
+ if file.nil?
82
+ text = RuneBlog.post_template(num: meta.num, title: meta.title, date: meta.pubdate,
83
+ view: meta.view, teaser: meta.teaser, body: meta.body,
84
+ views: meta.views, tags: meta.tags, home: viewhome)
85
+ srcdir = post.blog.root/:drafts + "/"
86
+ vpdir = post.blog.root/:drafts + "/"
87
+ fname = meta.slug + ".lt3"
88
+ post.draft = srcdir + fname
89
+ dump(text, post.draft)
90
+ else
91
+ dump(File.read(file), post.draft)
92
+ end
91
93
  return post
92
94
  end
93
95
 
94
96
  def edit
95
97
  log!(enter: __method__)
96
- verify(File.exist?(@draft) => "File #{@draft} not found")
97
98
  result = system!("vi #@draft +8") # TODO improve this
98
99
  raise EditorProblem(draft) unless result
99
100
  nil
@@ -128,6 +129,9 @@ class RuneBlog::ViewPost
128
129
  lines = File.readlines(mdfile)
129
130
  @title = lines.grep(/title:/).first[7..-1].chomp
130
131
  @date = lines.grep(/pubdate:/).first[9..-1].chomp
132
+ # print "-- date = #{@date.inspect} "; gets
133
+ rescue => err
134
+ STDERR.puts "--- #{err}\n #{err.backtrace.join("\n ")}"
131
135
  end
132
136
 
133
137
  def get_dirs
@@ -43,7 +43,6 @@ class RuneBlog::Publishing
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
@@ -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
- STDSCR.clear
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
- system!("tput clear")
20
+ sleep 0.1
21
+ cmd_clear(nil)
22
+ sleep 0.1
22
23
  exit
23
24
  end
24
25
 
@@ -36,7 +37,77 @@ module RuneBlog::REPL
36
37
  @out
37
38
  end
38
39
 
39
- def cmd_pages(arg, testing = false)
40
+ def cmd_config(arg, testing = false)
41
+ list = ["global.lt3", "blog/generate.lt3", " head.lt3", " index.lt3",
42
+ " post_entry.lt3", "etc/blog.css.lt3", " externals.lt3",
43
+ "post/generate.lt3", " head.lt3", " index.lt3",
44
+ " permalink.lt3"]
45
+ name = ["global.lt3", "blog/generate.lt3", "blog/head.lt3", "blog/index.lt3",
46
+ "blog/post_entry.lt3", "etc/blog.css.lt3", "blog/externals.lt3",
47
+ "post/generate.lt3", "post/head.lt3", "post/index.lt3",
48
+ "post/permalink.lt3"]
49
+ dir = @blog.view.dir/"themes/standard/"
50
+ num, str = STDSCR.menu(title: "Edit file:", items: list)
51
+ target = name[num]
52
+ edit_file(dir/target)
53
+ end
54
+
55
+ def cmd_manage(arg, testing = false)
56
+ case arg
57
+ when "pages"; _manage_pages(nil, testing = false)
58
+ when "links"; _manage_links(nil, testing = false)
59
+ when "navbar"; _manage_navbar(nil, testing = false)
60
+ # when "pinned"; _manage_pinned(nil, testing = false) # ditch this??
61
+ else
62
+ puts "#{arg} is unknown"
63
+ end
64
+ end
65
+
66
+ def _manage_pinned(arg, testing = false) # cloned from manage_links
67
+ check_empty(arg)
68
+ dir = @blog.view.dir/"themes/standard/widgets/pinned"
69
+ data = dir/"list.data"
70
+ edit_file(data)
71
+ end
72
+
73
+ def _manage_navbar(arg, testing = false) # cloned from manage_pages
74
+ puts "Got to #{__method__}"
75
+ check_empty(arg)
76
+ dir = @blog.view.dir/"themes/standard/navbar"
77
+ files = Dir.entries(dir) - %w[. .. navbar.lt3]
78
+ new_item = " [New item] "
79
+ main_file = "[ navbar.lt3 ]"
80
+ files = [main_file] + files + [new_item]
81
+ num, fname = STDSCR.menu(title: "Edit navbar:", items: files)
82
+ return if fname.nil?
83
+ case fname
84
+ when new_item
85
+ print "Page title: "
86
+ title = RubyText.gets
87
+ title.chomp!
88
+ print "File name (.lt3): "
89
+ fname = RubyText.gets
90
+ fname << ".lt3" unless fname.end_with?(".lt3")
91
+ new_file = dir/fname
92
+ File.open(new_file, "w") do |f|
93
+ f.puts "<h1>#{title}</h1>\n\n\n "
94
+ f.puts ".backlink"
95
+ end
96
+ edit_file(new_file)
97
+ when main_file
98
+ edit_file(main_file[2..-3])
99
+ else
100
+ edit_file(dir/fname)
101
+ end
102
+ end
103
+
104
+ def _manage_links(arg, testing = false)
105
+ dir = @blog.view.dir/"themes/standard/widgets/links"
106
+ data = dir/"list.data"
107
+ edit_file(data)
108
+ end
109
+
110
+ def _manage_pages(arg, testing = false)
40
111
  check_empty(arg)
41
112
  dir = @blog.view.dir/"themes/standard/widgets/pages"
42
113
  # Assume child files already generated (and list.data??)
@@ -99,6 +170,13 @@ module RuneBlog::REPL
99
170
  result = system!("open #{local}")
100
171
  raise CantOpen(local) unless result
101
172
  @out
173
+ rescue => err
174
+ out = "/tmp/blog#{rand(100)}.txt"
175
+ File.open(out, "w") do |f|
176
+ f.puts err
177
+ f.puts err.backtrace.join("\n")
178
+ end
179
+ puts "Error: See #{out}"
102
180
  end
103
181
 
104
182
  def cmd_publish(arg, testing = false)
@@ -136,6 +214,13 @@ module RuneBlog::REPL
136
214
  output! "...finished.\n"
137
215
  end
138
216
  return @out
217
+ rescue => err
218
+ out = "/tmp/blog#{rand(100)}.txt"
219
+ File.open(out, "w") do |f|
220
+ f.puts err
221
+ f.puts err.backtrace.join("\n")
222
+ end
223
+ puts "Error: See #{out}"
139
224
  end
140
225
 
141
226
  def cmd_rebuild(arg, testing = false)
@@ -146,6 +231,13 @@ module RuneBlog::REPL
146
231
  @blog.generate_view(@blog.view)
147
232
  @blog.generate_index(@blog.view)
148
233
  @out
234
+ rescue => err
235
+ out = "/tmp/blog#{rand(100)}.txt"
236
+ File.open(out, "w") do |f|
237
+ f.puts err
238
+ f.puts err.backtrace.join("\n")
239
+ end
240
+ puts "Error: See #{out}"
149
241
  end
150
242
 
151
243
  def cmd_change_view(arg, testing = false)
@@ -173,24 +265,40 @@ module RuneBlog::REPL
173
265
 
174
266
  def cmd_new_view(arg, testing = false)
175
267
  reset_output
268
+ if arg.nil?
269
+ arg = ask("\nFilename: ")
270
+ puts
271
+ end
176
272
  @blog.create_view(arg)
177
273
  edit_file(@blog.view.dir/"themes/standard/global.lt3")
178
274
  @blog.change_view(arg)
179
275
  @out
180
276
  rescue ViewAlreadyExists
181
277
  puts 'Blog already exists'
278
+ rescue => err
279
+ out = "/tmp/blog#{rand(100)}.txt"
280
+ File.open(out, "w") do |f|
281
+ f.puts err
282
+ f.puts err.backtrace.join("\n")
283
+ end
284
+ puts "Error: See #{out}"
182
285
  end
183
286
 
184
287
  def cmd_new_post(arg, testing = false)
185
288
  reset_output
186
289
  check_empty(arg)
187
290
  title = ask("\nTitle: ")
291
+ puts
188
292
  @blog.create_new_post(title)
189
293
  # STDSCR.clear
190
294
  @out
191
295
  rescue => err
192
- puts err
193
- puts err.backtrace.join("\n")
296
+ out = "/tmp/blog#{rand(100)}.txt"
297
+ File.open(out, "w") do |f|
298
+ f.puts err
299
+ f.puts err.backtrace.join("\n")
300
+ end
301
+ puts "Error: See #{out}"
194
302
  end
195
303
 
196
304
  def _remove_post(arg, testing=false)
@@ -200,7 +308,6 @@ module RuneBlog::REPL
200
308
  end
201
309
 
202
310
  def cmd_remove_post(arg, testing = false)
203
- puts "arg = #{arg.inspect} is a #{arg.class}"
204
311
  reset_output
205
312
  args = arg.split
206
313
  args.each do |x|
@@ -212,14 +319,12 @@ puts "arg = #{arg.inspect} is a #{arg.class}"
212
319
  @out
213
320
  end
214
321
 
215
- #-- FIXME affects linking, building, publishing...
216
-
217
322
  def cmd_edit_post(arg, testing = false)
218
323
  reset_output
219
324
  id = get_integer(arg)
220
325
  # Simplify this
221
326
  tag = "#{'%04d' % id}"
222
- files = Find.find(@blog.root+"/drafts").to_a
327
+ files = ::Find.find(@blog.root+"/drafts").to_a
223
328
  files = files.grep(/#{tag}-.*lt3/)
224
329
  files = files.map {|f| File.basename(f) }
225
330
  if files.size > 1
@@ -239,6 +344,13 @@ puts "arg = #{arg.inspect} is a #{arg.class}"
239
344
  draft = "#{@blog.root}/drafts/#{file}"
240
345
  result = edit_file(draft)
241
346
  @blog.generate_post(draft)
347
+ rescue => err
348
+ out = "/tmp/blog#{rand(100)}.txt"
349
+ File.open(out, "w") do |f|
350
+ f.puts err
351
+ f.puts err.backtrace.join("\n")
352
+ end
353
+ puts "Error: See #{out}"
242
354
  end
243
355
 
244
356
  def cmd_list_views(arg, testing = false)
@@ -322,7 +434,10 @@ puts "arg = #{arg.inspect} is a #{arg.class}"
322
434
 
323
435
  def cmd_ssh(arg, testing = false)
324
436
  pub = @blog.view.publisher
325
- system!("ssh #{pub.user}@#{pub.server}")
437
+ puts
438
+ system!("tputs clear; ssh #{pub.user}@#{pub.server}")
439
+ sleep 0.1
440
+ cmd_clear(nil)
326
441
  end
327
442
 
328
443
  def cmd_INVALID(arg, testing = false)
@@ -352,7 +467,7 @@ puts "arg = #{arg.inspect} is a #{arg.class}"
352
467
  list views List all views available
353
468
  lsv Same as: list views
354
469
 
355
- * config Edit the publish file or the templates
470
+ config Edit various system files
356
471
  * customize (BUGGY) Change set of tags, extra views
357
472
 
358
473
  p, post Create a new post
@@ -385,6 +500,5 @@ puts "arg = #{arg.inspect} is a #{arg.class}"
385
500
  puts unless testing
386
501
  @out
387
502
  end
388
-
389
503
  end
390
504
 
@@ -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?
@@ -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
@@ -104,8 +116,16 @@ class RuneBlog
104
116
  log!(enter: __method__, args: [dir], level: 1)
105
117
  Dir.chdir(dir) do
106
118
  views = _retrieve_metadata(:views)
107
- views.each {|v| system!("cp *html #@root/views/#{v}/remote") }
119
+ views.each do |v|
120
+ unless @blog.view?(v)
121
+ puts "Warning: '#{v}' is not a view"
122
+ next
123
+ end
124
+ system!("cp *html #@root/views/#{v}/remote")
125
+ end
108
126
  end
127
+ rescue => err
128
+ _tmp_error(err)
109
129
  end
110
130
 
111
131
  def _retrieve_metadata(key)
@@ -129,6 +149,8 @@ class RuneBlog
129
149
  raise "Too many #{key} instances in metadata.txt!"
130
150
  end
131
151
  return result
152
+ rescue => err
153
+ _tmp_error(err)
132
154
  end
133
155
 
134
156
  def process_post(sourcefile)
@@ -136,8 +158,11 @@ class RuneBlog
136
158
  nslug = sourcefile.sub(/.lt3/, "")
137
159
  dir = @root/:posts/nslug
138
160
  create_dir(dir)
161
+ # FIXME dependencies?
139
162
  xlate cwd: dir, src: sourcefile # , debug: true
140
163
  _deploy_local(dir)
164
+ rescue => err
165
+ _tmp_error(err)
141
166
  end
142
167
 
143
168
  def inspect
@@ -172,6 +197,8 @@ class RuneBlog
172
197
  def _set_publisher
173
198
  log!(enter: __method__, level: 3)
174
199
  @view.publisher = RuneBlog::Publishing.new(@view.to_s) # FIXME refactor
200
+ rescue => err
201
+ _tmp_error(err)
175
202
  end
176
203
 
177
204
  def view=(arg)
@@ -188,6 +215,8 @@ class RuneBlog
188
215
  else
189
216
  raise CantAssignView(arg.class.to_s)
190
217
  end
218
+ rescue => err
219
+ _tmp_error(err)
191
220
  end
192
221
 
193
222
  def get_sequence
@@ -234,6 +263,8 @@ class RuneBlog
234
263
  cmd = "cp -r #{RuneBlog::Path}/../empty_view views/#{view_name}"
235
264
  system!(cmd)
236
265
  end
266
+ rescue => err
267
+ _tmp_error(err)
237
268
  end
238
269
 
239
270
  def check_valid_new_view(view_name)
@@ -252,10 +283,10 @@ class RuneBlog
252
283
  log!(enter: __method__, args: [view_name], level: 2)
253
284
  check_valid_new_view(view_name)
254
285
  make_empty_view_tree(view_name)
255
- # STDERR.puts "Made empty tree!"
256
- # system("bash")
257
286
  add_view(view_name)
258
287
  mark_last_published("Initial creation")
288
+ rescue => err
289
+ _tmp_error(err)
259
290
  end
260
291
 
261
292
  def delete_view(name, force = false)
@@ -289,6 +320,8 @@ class RuneBlog
289
320
  postdir = post.first
290
321
  vp = RuneBlog::ViewPost.new(self.view, postdir)
291
322
  vp
323
+ rescue => err
324
+ _tmp_error(err)
292
325
  end
293
326
 
294
327
  def index_entry(slug)
@@ -297,17 +330,21 @@ class RuneBlog
297
330
  text = nil
298
331
  @theme = @view.dir/"themes/standard"
299
332
  post_entry_name = @theme/"blog/post_entry.lt3"
300
- xlate src: post_entry_name, dst: "/tmp/post_entry.html" # , debug: true
333
+ depend = [post_entry_name]
334
+ xlate src: post_entry_name, dst: "/tmp/post_entry.html", deps: depend # , debug: true
301
335
  @_post_entry ||= File.read("/tmp/post_entry.html")
302
336
  vp = post_lookup(id)
303
337
  nslug, aslug, title, date, teaser_text =
304
338
  vp.nslug, vp.aslug, vp.title, vp.date, vp.teaser_text
305
339
  path = vp.path
306
340
  url = aslug + ".html"
341
+ # puts "--- vp = #{[vp.nslug, vp.aslug, vp.title, vp.date, vp.teaser_text].inspect}"; gets
307
342
  date = ::Date.parse(date)
308
343
  date = date.strftime("%B %e<br><div style='float: right'>%Y</div>")
309
344
  text = interpolate(@_post_entry, binding)
310
345
  text
346
+ rescue => err
347
+ _tmp_error(err)
311
348
  end
312
349
 
313
350
  def collect_recent_posts(file)
@@ -318,14 +355,20 @@ class RuneBlog
318
355
  posts = entries.grep(/^\d\d\d\d/).map {|x| dir_posts/x }
319
356
  posts.select! {|x| File.directory?(x) }
320
357
  # directories that start with four digits
321
- posts = posts.sort {|a, b| b.to_i <=> a.to_i } # sort descending
358
+ posts = posts.sort do |a, b|
359
+ ai = a.index(/\d\d\d\d-/)
360
+ bi = b.index(/\d\d\d\d-/)
361
+ na = a[ai..(ai+3)].to_i
362
+ nb = b[bi..(bi+3)].to_i
363
+ nb <=> na
364
+ end # sort descending
322
365
  posts = posts[0..19] # return 20 at most
323
366
  text = <<-HTML
324
367
  <html>
325
368
  <head><link rel="stylesheet" href="etc/blog.css"></head>
326
369
  <body>
327
370
  HTML
328
- wanted = [5, posts.size].min # estimate how many we want?
371
+ wanted = [8, posts.size].min # estimate how many we want?
329
372
  enum = posts.each
330
373
  wanted.times do
331
374
  postid = File.basename(enum.next)
@@ -334,13 +377,16 @@ class RuneBlog
334
377
  end
335
378
  text << "</body></html>"
336
379
  File.write(@vdir/:remote/file, text)
380
+ rescue => err
381
+ _tmp_error(err)
337
382
  end
338
383
 
339
384
  def create_new_post(title, testing = false, teaser: nil, body: nil,
340
385
  pubdate: Time.now.strftime("%Y-%m-%d"), views: [])
341
- log!(enter: __method__, args: [title, testing, teaser, body, views], level: 1)
386
+ log!(enter: __method__, args: [title, testing, teaser, body, views], level: 1, stderr: true)
342
387
  meta = nil
343
388
  views = views + [self.view.to_s]
389
+ views.uniq!
344
390
  Dir.chdir(@root/:posts) do
345
391
  post = Post.create(title: title, teaser: teaser, body: body, pubdate: pubdate, views: views)
346
392
  post.edit unless testing
@@ -349,14 +395,12 @@ class RuneBlog
349
395
  end
350
396
  return meta.num
351
397
  rescue => err
352
- puts err
353
- puts err.backtrace.join("\n")
398
+ _tmp_error(err)
354
399
  end
355
400
 
356
401
  def edit_initial_post(file, testing = false)
357
402
  log!(enter: __method__, args: [file, testing], level: 3)
358
403
  debug "=== edit_initial_post #{file.inspect} => #{sourcefile}"
359
- sourcefile = @root/:drafts/file
360
404
  result = system!("#@editor #{sourcefile} +8") unless testing
361
405
  raise EditorProblem(sourcefile) unless result
362
406
  process_post(sourcefile)
@@ -392,25 +436,24 @@ class RuneBlog
392
436
  raise ArgumentError unless view.is_a?(String) || view.is_a?(RuneBlog::View)
393
437
  @vdir = @root/:views/view
394
438
  collect_recent_posts("recent.html")
439
+ rescue => err
440
+ _tmp_error(err)
395
441
  end
396
442
 
397
443
  def generate_view(view) # huh?
398
444
  log!(enter: __method__, args: [view])
399
- # generate_index(view) # recent posts (recent.html)
400
445
  vdir = @root/:views/view
401
446
  @theme = @root/:views/view/:themes/:standard
402
- xlate cwd: vdir/"themes/standard/etc",
447
+ depend = [vdir/"remote/etc/blog.css", @theme/"global.lt3",
448
+ @theme/"blog/head.lt3", @theme/"navbar/navbar.lt3",
449
+ @theme/"blog/index.lt3"] # FIXME what about assets?
450
+ xlate cwd: vdir/"themes/standard/etc", deps: depend,
403
451
  src: "blog.css.lt3", copy: vdir/"remote/etc/blog.css" # , debug: true
404
- xlate cwd: vdir/"themes/standard",
452
+ xlate cwd: vdir/"themes/standard", deps: depend,
405
453
  src: "blog/generate.lt3", dst: vdir/:remote/"index.html"
406
- # generate_index(view) # recent posts (recent.html)
407
- # ^ HERE
408
454
  copy("#{vdir}/assets/*", "#{vdir}/remote/assets/")
409
455
  rescue => err
410
- puts err
411
- puts err.backtrace.join("\n")
412
- print "Pause... "
413
- gets
456
+ _tmp_error(err)
414
457
  end
415
458
 
416
459
  def _get_views(draft)
@@ -421,7 +464,9 @@ class RuneBlog
421
464
  raise "No .views call!" if view_line.size < 1
422
465
  view_line = view_line.first
423
466
  views = view_line[7..-1].split
424
- views
467
+ views.uniq
468
+ rescue => err
469
+ _tmp_error(err)
425
470
  end
426
471
 
427
472
  def _copy_get_dirs(draft, view)
@@ -435,6 +480,8 @@ class RuneBlog
435
480
  viewdir, slugdir, aslug = vdir, dir, noext[5..-1]
436
481
  theme = viewdir/:themes/:standard
437
482
  [noext, viewdir, slugdir, aslug, theme]
483
+ rescue => err
484
+ _tmp_error(err)
438
485
  end
439
486
 
440
487
  def _post_metadata(draft, pdraft)
@@ -450,6 +497,7 @@ class RuneBlog
450
497
  longdate = ::Date.parse(date).strftime("%B %e, %Y")
451
498
  title = _retrieve_metadata(:title)
452
499
  tags = _retrieve_metadata(:tags)
500
+ # FIXME simplify
453
501
  vars = <<~LIVE
454
502
  .set post.num = #{pnum}
455
503
  .heredoc post.aslug
@@ -470,6 +518,8 @@ class RuneBlog
470
518
  LIVE
471
519
  File.open(pdraft/"vars.lt3", "w") {|f| f.puts vars }
472
520
  end
521
+ rescue => err
522
+ _tmp_error(err)
473
523
  end
474
524
 
475
525
  def copy_widget_html(view)
@@ -484,15 +534,15 @@ class RuneBlog
484
534
  create_dirs(rem)
485
535
  files = Dir[w/"*"]
486
536
  files = files.select {|x| x =~ /(html|css)$/ }
487
- # files.each {|f| STDERR.puts " #{f.inspect}" }
488
537
  tag = File.basename(w)
489
- # STDERR.puts "--- tag: #{tag.inspect}"
490
538
  files.each {|file| system!("cp #{file} #{rem}", show: (tag == "zzz")) }
491
539
  end
540
+ rescue => err
541
+ _tmp_error(err)
492
542
  end
493
543
 
494
- def _handle_post(draft, view)
495
- log!(enter: __method__, args: [draft, view], level: 2)
544
+ def _handle_post(draft, view_name = self.view.to_s)
545
+ log!(enter: __method__, args: [draft, view_name], level: 2)
496
546
  # break into separate methods?
497
547
 
498
548
  fname = File.basename(draft) # 0001-this-is-a-post.lt3
@@ -500,55 +550,43 @@ class RuneBlog
500
550
  aslug = nslug.sub(/\d\d\d\d-/, "") # this-is-a-post
501
551
  ahtml = aslug + ".html" # this-is-a-post.html
502
552
  pdraft = @root/:posts/nslug
503
- remote = @root/:views/view/:remote
504
- @theme = @root/:views/view/:themes/:standard
553
+ remote = @root/:views/view_name/:remote
554
+ @theme = @root/:views/view_name/:themes/:standard
505
555
  # Step 1...
506
556
  create_dirs(pdraft)
507
- xlate cwd: pdraft, src: draft, dst: "guts.html"
557
+ # FIXME dependencies?
558
+ xlate cwd: pdraft, src: draft, dst: "guts.html" # , debug: true
508
559
  _post_metadata(draft, pdraft)
509
560
  # Step 2...
510
- vposts = @root/:views/view/:posts
561
+ vposts = @root/:views/view_name/:posts
511
562
  copy!(pdraft, vposts) # ??
512
563
  # Step 3..
513
564
  copy(pdraft/"guts.html", @theme/:post)
514
565
  copy(pdraft/"vars.lt3", @theme/:post)
515
566
  # Step 4...
516
- xlate cwd: @theme/:post, src: "generate.lt3",
517
- dst: remote/ahtml, copy: @theme/:post # , debug: true
567
+ # FIXME dependencies?
568
+ xlate cwd: @theme/:post, src: "generate.lt3", force: true,
569
+ dst: remote/ahtml, copy: @theme/:post # , debug: true
570
+ # FIXME dependencies?
518
571
  xlate cwd: @theme/:post, src: "permalink.lt3",
519
572
  dst: remote/:permalink/ahtml # , debug: true
520
- copy_widget_html(view)
573
+ copy_widget_html(view_name)
574
+ rescue => err
575
+ _tmp_error(err)
521
576
  end
522
577
 
523
578
  def generate_post(draft)
524
579
  log!(enter: __method__, args: [draft], level: 1)
525
580
  views = _get_views(draft)
526
581
  views.each do |view|
582
+ unless self.view?(view)
583
+ puts "Warning: '#{view}' is not a view"
584
+ next
585
+ end
527
586
  _handle_post(draft, view)
528
- # generate_view(view) # FIXME leads to inefficiency?
529
- # ^ HERE
530
587
  end
531
- end
532
-
533
- def OLD_index_entry(view, meta)
534
- log!(enter: __method__, args: [view, meta])
535
- debug "=== index_entry #{view.to_s.inspect} #{meta.num} #{meta.title.inspect}"
536
- check_meta(meta, "index_entry1")
537
- raise ArgumentError unless view.is_a?(String) || view.is_a?(RuneBlog::View)
538
- check_meta(meta, "index_entry2")
539
- self.make_slug(meta)
540
- check_meta(meta, "index_entry3")
541
- # FIXME clean up and generalize
542
- ref = view/meta.slug/"index.html"
543
- <<-HTML
544
- <font size=-1>#{meta.date}&nbsp;&nbsp;</font> <br>
545
- <font size=+2 color=blue><a href=../#{ref} style="text-decoration: none">#{meta.title}</font></a>
546
- <br>
547
- <font size=+1>#{meta.teaser}&nbsp;&nbsp;</font>
548
- <a href=../#{ref} style="text-decoration: none">Read more...</a>
549
- <br>
550
- <hr>
551
- HTML
588
+ rescue => err
589
+ _tmp_error(err)
552
590
  end
553
591
 
554
592
  def rebuild_post(file)
@@ -562,8 +600,7 @@ class RuneBlog
562
600
  @views_dirty.flatten!
563
601
  @views_dirty.uniq!
564
602
  rescue => err
565
- error(err)
566
- getch
603
+ _tmp_error(err)
567
604
  end
568
605
 
569
606
  def remove_post(num)
@@ -615,6 +652,5 @@ class RuneBlog
615
652
  meta.slug = str
616
653
  str
617
654
  end
618
-
619
655
  end
620
656