Class: RuneBlog
Overview
Defined Under Namespace
Modules: Helpers, REPL
Classes: Default, Post, Publishing, View, ViewPost, Widget
Constant Summary
collapse
- DotDir =
".blogs"
- ConfigFile =
"config"
- Themes =
RuneBlog::Path/"../themes"
- VERSION =
"0.3.27"
- Path =
File.dirname(path)
Class Attribute Summary collapse
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
-
#_check_view?(view) ⇒ Boolean
-
#_copy_get_dirs(draft, view) ⇒ Object
-
#_deploy_local(dir) ⇒ Object
-
#_generate_global ⇒ Object
-
#_generate_settings(view = nil) ⇒ Object
-
#_get_views(draft) ⇒ Object
-
#_handle_post(draft, view_name = self.view.to_s) ⇒ Object
-
#_post_metadata(draft, pdraft) ⇒ Object
-
#_set_publisher ⇒ Object
-
#_sorted_posts ⇒ Object
-
#add_view(view_name) ⇒ Object
-
#all_drafts ⇒ Object
-
#change_view(view) ⇒ Object
-
#check_valid_new_view(view_name) ⇒ Object
-
#collect_recent_posts(file = "recent.html") ⇒ Object
-
#complete_file(name, vars, hash) ⇒ Object
-
#copy_widget_html(view) ⇒ Object
-
#create_new_post(title, testing = false, teaser: nil, body: nil, pubdate: Time.now.strftime("%Y-%m-%d"), views: []) ⇒ Object
-
#create_view(view_name) ⇒ Object
-
#delete_draft(num) ⇒ Object
-
#delete_view(name, force = false) ⇒ Object
-
#drafts ⇒ Object
-
#generate_index(view) ⇒ Object
-
#generate_post(draft, force = false) ⇒ Object
-
#generate_view(view) ⇒ Object
-
#get_sequence ⇒ Object
-
#import_legacy_post(file, oldfile, testing = false) ⇒ Object
-
#index_entry(slug) ⇒ Object
-
#initialize(root_rel = ".blogs") ⇒ RuneBlog
constructor
always assumes existing blog.
-
#inspect ⇒ Object
-
#make_empty_view_tree(view_name) ⇒ Object
-
#make_slug(meta) ⇒ Object
-
#mark_last_published(str) ⇒ Object
-
#next_sequence ⇒ Object
-
#post_lookup(postid) ⇒ Object
-
#posts ⇒ Object
-
#process_post(sourcefile) ⇒ Object
-
#read_metadata ⇒ Object
FIXME reconcile with _get_draft data.
-
#remove_post(num) ⇒ Object
-
#str2view(str) ⇒ Object
def view(name = nil) log!(enter: __method__, args: [name], level: 3) return @view if name.nil?.
-
#undelete_post(num) ⇒ Object
-
#view?(name) ⇒ Boolean
-
#view_files ⇒ Object
-
#viewdir(v = nil) ⇒ Object
check_error, check_integer, check_nonempty_string, check_view_parameter, confirm
Methods included from Helpers
copy_data, find_draft_slugs, get_all_widgets, get_repo_config, get_widget, new_sequence, quit_RubyText, read_features, read_vars, retrieve_views, subdirs, write_features, write_repo_config
Constructor Details
#initialize(root_rel = ".blogs") ⇒ RuneBlog
always assumes existing blog
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
# File 'lib/runeblog.rb', line 131
def initialize(root_rel = ".blogs") log!(enter: "initialize", args: [root_rel])
self.class.blog = self
@root = Dir.pwd/root_rel
get_repo_config
read_features @views = retrieve_views
self.view = File.read(@root/"data/VIEW").chomp
md = Dir.pwd.match(%r[.*/views/(.*?)/])
if md
@view_name = md[1]
@view = str2view(@view_name)
end
@sequence = get_sequence
@post_views = []
@post_tags = []
rescue => err
puts "Error - see stdout.txt"
STDERR.puts err.inspect
STDERR.puts err&.backtrace
sleep 3
end
|
Class Attribute Details
.blog ⇒ Object
Returns the value of attribute blog.
56
57
58
|
# File 'lib/runeblog.rb', line 56
def blog
@blog
end
|
Instance Attribute Details
#dirty_views ⇒ Object
Returns the value of attribute dirty_views.
66
67
68
|
# File 'lib/runeblog.rb', line 66
def dirty_views
@dirty_views
end
|
#editor ⇒ Object
Returns the value of attribute editor.
62
63
64
|
# File 'lib/runeblog.rb', line 62
def editor
@editor
end
|
#features ⇒ Object
Returns the value of attribute features.
62
63
64
|
# File 'lib/runeblog.rb', line 62
def features
@features
end
|
#post ⇒ Object
Returns the value of attribute post.
64
65
66
|
# File 'lib/runeblog.rb', line 64
def post
@post
end
|
#post_tags ⇒ Object
Returns the value of attribute post_tags.
66
67
68
|
# File 'lib/runeblog.rb', line 66
def post_tags
@post_tags
end
|
#post_views ⇒ Object
Returns the value of attribute post_views.
66
67
68
|
# File 'lib/runeblog.rb', line 66
def post_views
@post_views
end
|
#root ⇒ Object
Returns the value of attribute root.
62
63
64
|
# File 'lib/runeblog.rb', line 62
def root
@root
end
|
#sequence ⇒ Object
Returns the value of attribute sequence.
61
62
63
|
# File 'lib/runeblog.rb', line 61
def sequence
@sequence
end
|
#view ⇒ Object
63
64
65
|
# File 'lib/runeblog.rb', line 63
def view
@view
end
|
#views ⇒ Object
Returns the value of attribute views.
61
62
63
|
# File 'lib/runeblog.rb', line 61
def views
@views
end
|
Class Method Details
.create_new_blog_repo(root_rel = ".blogs") ⇒ Object
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/runeblog.rb', line 97
def self.create_new_blog_repo(root_rel = ".blogs")
log!(enter: __method__, args: [root_rel])
check_nonempty_string(root_rel)
repo_root = Dir.pwd/root_rel
check_error(BlogRepoAlreadyExists) { Dir.exist?(repo_root) }
create_dirs(repo_root)
Dir.chdir(repo_root) do
create_dirs(:data, :config, :widgets, :drafts, :views, :posts) get_all_widgets("widgets")
new_sequence
end
unless File.exist?(repo_root/"data/VIEW")
copy_data(repo_root/:data)
end
write_repo_config(root: repo_root)
self.blog = blog = self.new
blog
rescue => err
puts "Can't create blog repo: '#{repo_root}' - #{err}"
puts err.backtrace.join("\n")
end
|
.exist? ⇒ Boolean
343
344
345
346
|
# File 'lib/runeblog.rb', line 343
def self.exist?
log!(enter: __method__, level: 3)
Dir.exist?(DotDir)
end
|
.open(root_rel = ".blogs") ⇒ Object
123
124
125
126
127
128
129
|
# File 'lib/runeblog.rb', line 123
def self.open(root_rel = ".blogs")
raise "Not impl"
log!(enter: __method__, args: [root_rel])
blog = self.new(root_rel)
rescue => err
_tmp_error(err)
end
|
.post_template(num: 0, title: "No title", date: nil, view: "test_view", teaser: "No teaser", body: "No body", tags: ["untagged"], views: [], back: "javascript:history.go(-1)", home: "no url") ⇒ Object
This will all become much more generic later.
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/runeblog.rb', line 73
def RuneBlog.post_template(num: 0, title: "No title", date: nil, view: "test_view",
teaser: "No teaser", body: "No body", tags: ["untagged"],
views: [], back: "javascript:history.go(-1)", home: "no url")
log!(enter: __method__, args: [num, title, date, view, teaser, body, tags, views, back, home], level: 3)
viewlist = (views + [view.to_s]).join(" ")
taglist = ".tags " + tags.join(" ")
<<~TEXT
.post #{num}
.title #{title}
.pubdate #{date}
.views #{viewlist}
#{taglist}
.teaser
#{teaser}
.end
#{body}
TEXT
end
|
Instance Method Details
#_check_view?(view) ⇒ Boolean
721
722
723
724
725
|
# File 'lib/runeblog.rb', line 721
def _check_view?(view)
flag = self.view?(view)
puts " Warning: '#{view}' is not a view" unless flag
flag
end
|
#_copy_get_dirs(draft, view) ⇒ Object
610
611
612
613
614
615
616
617
618
619
620
621
622
623
|
# File 'lib/runeblog.rb', line 610
def _copy_get_dirs(draft, view)
log!(enter: __method__, args: [draft, view], level: 2)
fname = File.basename(draft)
noext = fname.sub(/.lt3$/, "")
vdir = @root/:views/view
dir = vdir/:posts/noext
Dir.mkdir(dir) unless Dir.exist?(dir)
system!("cp #{draft} #{dir}")
viewdir, slugdir, aslug = vdir, dir, noext[5..-1]
theme = viewdir/:themes/:standard
[noext, viewdir, slugdir, aslug, theme]
rescue => err
_tmp_error(err)
end
|
#_deploy_local(dir) ⇒ Object
230
231
232
233
234
235
236
237
238
239
240
241
|
# File 'lib/runeblog.rb', line 230
def _deploy_local(dir)
log!(enter: __method__, args: [dir], level: 1)
Dir.chdir(dir) do
meta = read_metadata
meta.views.each do |v|
next unless _check_view?(v)
system!("cp *html #@root/views/#{v}/remote", show: true)
end
end
rescue => err
_tmp_error(err)
end
|
#_generate_global ⇒ Object
208
209
210
211
212
213
214
215
216
217
218
|
# File 'lib/runeblog.rb', line 208
def _generate_global
vars = read_vars("#@root/data/universal.lt3")
gfile = "#@root/data/global.lt3"
hash = {/AUTHOR/ => "univ.author",
/SITE/ => "univ.site",
/FONT/ => "font.family",
/CHARSET/ => :charset,
/LOCALE/ => :locale}
complete_file(gfile, vars, hash)
_generate_settings
end
|
#_generate_settings(view = nil) ⇒ Object
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
# File 'lib/runeblog.rb', line 170
def _generate_settings(view = nil)
vars = read_vars("#@root/data/universal.lt3")
hash = {/AUTHOR/ => "view.author",
/SITE/ => "view.site",
/FONT/ => "font.family",
/CHARSET/ => :charset,
/LOCALE/ => :locale}
if view
settings = @root/view/"settings"
fname = settings/"features.txt"
complete_file(settings/"view.txt",
/AUTHOR/ => "view.author",
/TITLE/ => "view.title",
/SUBTITLE/ => "view.subtitle",
/SITE/ => "view.site")
complete_file(settings/"publish.txt",
/USER/ => "publish.user",
/SERVER/ => "publish.server",
/DOCROOT/ => "publish.docroot",
/PATH/ => "publish.path",
/PROTO/ => "publish.proto")
complete_file(settings/"recent.txt", {})
end
end
|
#_get_views(draft) ⇒ Object
600
601
602
603
604
605
606
607
608
|
# File 'lib/runeblog.rb', line 600
def _get_views(draft)
log!(enter: __method__, args: [draft], level: 2)
view_line = exactly_one(File.readlines(draft).grep(/^.views /), ".view line")
views = view_line[7..-1].split
views.uniq
rescue => err
_tmp_error(err)
end
|
#_handle_post(draft, view_name = self.view.to_s) ⇒ Object
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
|
# File 'lib/runeblog.rb', line 680
def _handle_post(draft, view_name = self.view.to_s)
log!(enter: __method__, args: [draft, view_name], level: 2)
return unless _check_view?(view_name)
fname = File.basename(draft) nslug = fname.sub(/.lt3$/, "") aslug = nslug.sub(/\d\d\d\d-/, "") ahtml = aslug + ".html" pdraft = @root/:posts/nslug
remote = @root/:views/view_name/:remote
@theme = @root/:views/view_name/:themes/:standard
pmeta = @root/:views/view_name/:posts/nslug
create_dirs(pdraft) @view.globals ||= {}
args = {cwd: pdraft, src: draft, debug: true, dst: "guts.html",
mix: "liveblog", vars: @view.globals}
preprocess cwd: pdraft, src: draft, debug: true,
dst: "guts.html", mix: "liveblog", vars: @view.globals
hash = _post_metadata(draft, pdraft)
hash[:CurrentPost] = pmeta
vposts = @root/:views/view_name/:posts copy!(pdraft, vposts) copy(pdraft/"guts.html", vposts/nslug) preprocess cwd: pmeta, src: "../../themes/standard/post/generate.lt3",
force: true, vars: hash, debug: true,
dst: remote/ahtml, call: ".nopara"
FileUtils.rm_f(remote/"published")
timelog("Generated", remote/"history")
copy_widget_html(view_name)
rescue => err
puts "Error - see stdout.txt"
STDERR.puts err.inspect
STDERR.puts err&.backtrace
end
|
#_post_metadata(draft, pdraft) ⇒ Object
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
|
# File 'lib/runeblog.rb', line 625
def _post_metadata(draft, pdraft)
log!(enter: __method__, args: [draft, pdraft], level: 2)
fname = File.basename(draft) nslug = fname.sub(/.lt3$/, "") aslug = nslug.sub(/\d\d\d\d-/, "") pnum = nslug[0..3] hash = {}
Dir.chdir(pdraft) do
excerpt = File.read("teaser.txt")
meta = read_metadata
date = meta.date
longdate = ::Date.parse(date).strftime("%B %e, %Y")
title = meta.title
tags = meta.tags
addvar(hash, "post.num" => pnum,
"post.aslug" => aslug,
"post.date" => date,
title: title.chomp,
teaser: excerpt.chomp,
longdate: longdate,
"post.nslug" => pnum + "-" + aslug,
"post.tags" => tags.join(" "))
end
hash
rescue => err
_tmp_error(err)
end
|
#_set_publisher ⇒ Object
287
288
289
290
291
292
|
# File 'lib/runeblog.rb', line 287
def _set_publisher
log!(enter: __method__, level: 3)
@view.publisher = RuneBlog::Publishing.new(@view.to_s) rescue => err
_tmp_error(err)
end
|
#_sorted_posts ⇒ Object
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
|
# File 'lib/runeblog.rb', line 453
def _sorted_posts
posts = nil
dir_posts = @vdir/:posts
entries = Dir.entries(dir_posts)
posts = entries.grep(/^\d\d\d\d/).map {|x| dir_posts/x }
posts.select! {|x| File.directory?(x) }
posts = posts.sort do |a, b|
ai = a.index(/\d\d\d\d-/)
bi = b.index(/\d\d\d\d-/)
na = a[ai..(ai+3)].to_i
nb = b[bi..(bi+3)].to_i
nb <=> na
end return posts[0..19] end
|
#add_view(view_name) ⇒ Object
353
354
355
356
357
358
359
360
|
# File 'lib/runeblog.rb', line 353
def add_view(view_name)
log!(enter: __method__, args: [view_name], level: 2)
view = RuneBlog::View.new(view_name)
self.view = view File.write(@root/"data/VIEW", view_name)
@views << view view
end
|
#all_drafts ⇒ Object
551
552
553
554
555
556
|
# File 'lib/runeblog.rb', line 551
def all_drafts
log!(enter: __method__, level: 3)
dir = @root/:drafts
drafts = Dir.entries(dir).grep(/^\d{4}.*/)
drafts.sort
end
|
#change_view(view) ⇒ Object
558
559
560
561
562
563
564
|
# File 'lib/runeblog.rb', line 558
def change_view(view)
log!(enter: __method__, args: [view], level: 3)
check_view_parameter(view)
File.write(@root/"data/VIEW", view)
self.view = view end
|
#check_valid_new_view(view_name) ⇒ Object
374
375
376
377
378
379
380
381
|
# File 'lib/runeblog.rb', line 374
def check_valid_new_view(view_name)
log!(enter: __method__, args: [view_name], level: 3)
check_nonempty_string(view_name)
vdir = @root/:views/view_name
check_error(ViewAlreadyExists, view_name) { self.views.map(&:to_s).include?(view_name) }
check_error(DirAlreadyExists, view_name) { Dir.exist?(vdir) }
return true
end
|
#collect_recent_posts(file = "recent.html") ⇒ Object
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
|
# File 'lib/runeblog.rb', line 470
def collect_recent_posts(file = "recent.html")
log!(enter: __method__, args: [file], level: 3)
vars = self.view.globals
text = <<-HTML
<html>
<head><link rel="stylesheet" href="etc/blog.css"></head>
<body style="background-color: #{vars["recent.bgcolor"]}">
HTML
posts = _sorted_posts
if posts.size > 0
wanted = [vars["recent.count"].to_i, posts.size].min
enum = posts.each
entries = []
wanted.times do
postid = File.basename(enum.next)
postid = postid.to_i
entry = index_entry(postid)
entries << entry
text << entry
end
else
text << <<-HTML
<svg width="95%" height="75%" viewBox="0 0 95% 95%">
<style> .huge { font: italic 90px sans-serif; fill: white } </style>
<rect x="0" y="0" rx="50" ry="50" width="95%" height="95%" fill="lightblue"/>
<text x="120" y="250" class=huge>No posts</text>
<text x="120" y="350" class=huge>here yet</text>
</svg>
HTML
end
text << "</body></html>"
File.write(@vdir/:remote/file, text)
return posts.size
rescue => err
_tmp_error(err)
end
|
#complete_file(name, vars, hash) ⇒ Object
157
158
159
160
161
162
163
164
165
166
167
168
|
# File 'lib/runeblog.rb', line 157
def complete_file(name, vars, hash)
debugging = vars.nil?
return if hash.empty?
text = File.read(name)
if vars.nil? vars = {}
hash.values.each {|val| vars[val] = val }
end
hash.each_pair {|key, var| text.gsub!(key, vars[var]) }
File.write(name, text)
end
|
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
|
# File 'lib/runeblog.rb', line 655
def copy_widget_html(view)
log!(enter: __method__, level: 2)
log! str: "=== cwh cp 1"
vdir = @root/:views/view
remote = vdir/:remote
wdir = vdir/:widgets
widgets = Dir[wdir/"*"].select {|w| File.directory?(w) }
log! str: "=== cwh cp 2"
widgets.each do |w|
dir = File.basename(w)
rem = w.sub(/widgets/, "remote/widgets")
log! str: "=== cwh cp 3 w = #{w.inspect}"
create_dirs(rem)
files = Dir[w/"*"]
tag = File.basename(w)
log! str: "=== cwh cp 4 tag = #{tag.inspect}"
files.each {|file| system!("cp #{file} #{rem}", show: true) }
log! str: "=== cwh cp 5 tag was #{tag.inspect}"
end
log! str: "=== cwh cp 6"
rescue => err
_tmp_error(err)
end
|
#create_new_post(title, testing = false, teaser: nil, body: nil, pubdate: Time.now.strftime("%Y-%m-%d"), views: []) ⇒ Object
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
|
# File 'lib/runeblog.rb', line 508
def create_new_post(title, testing = false, teaser: nil, body: nil,
pubdate: Time.now.strftime("%Y-%m-%d"), views: [])
log!(enter: __method__, args: [title, testing, teaser, body, views], level: 1, stderr: true)
meta = nil
views = views + [self.view.to_s]
views.uniq!
Dir.chdir(@root/"posts") do
post = Post.create(title: title, teaser: teaser, body: body, pubdate: pubdate, views: views)
post.edit unless testing
post.build
meta = post.meta
end
return meta.num
rescue => err
_tmp_error(err)
end
|
#create_view(view_name) ⇒ Object
383
384
385
386
387
388
389
390
391
392
393
|
# File 'lib/runeblog.rb', line 383
def create_view(view_name)
log!(enter: __method__, args: [view_name], level: 2)
make_empty_view_tree(view_name)
add_view(view_name)
mark_last_published("Initial creation")
system("cp #@root/data/global.lt3 #@root/views/#{view_name}/data/global.lt3")
@view.get_globals(true)
rescue => err
_tmp_error(err)
end
|
#delete_draft(num) ⇒ Object
773
774
775
776
777
778
|
# File 'lib/runeblog.rb', line 773
def delete_draft(num)
log!(enter: __method__, args: [num], level: 1)
check_integer(num)
tag = prefix(num)
system!("rm -rf #@root/drafts/#{tag}-*")
end
|
#delete_view(name, force = false) ⇒ Object
395
396
397
398
399
400
401
402
403
|
# File 'lib/runeblog.rb', line 395
def delete_view(name, force = false)
log!(enter: __method__, args: [name, force])
check_nonempty_string(name)
if force
vname = @root/:views/name
system!("rm -rf #{vname}")
@views -= [str2view(name)]
end
end
|
#drafts ⇒ Object
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
|
# File 'lib/runeblog.rb', line 535
def drafts
log!(enter: __method__, level: 3)
curr_drafts = self.all_drafts
list = []
curr_drafts.each do |draft|
postdir = @root/:views/self.view/:posts/draft.sub(/.lt3$/, "")
next unless Dir.exist?(postdir)
meta = nil
Dir.chdir(postdir) { meta = read_metadata }
list << draft if meta.views.include?(self.view.to_s)
end
curr_drafts
end
|
#generate_index(view) ⇒ Object
566
567
568
569
570
571
572
573
574
|
# File 'lib/runeblog.rb', line 566
def generate_index(view)
log!(enter: __method__, args: [view], pwd: true, dir: true)
check_view_parameter(view)
@vdir = @root/:views/view
num = collect_recent_posts
return num
rescue => err
_tmp_error(err)
end
|
#generate_post(draft, force = false) ⇒ Object
727
728
729
730
731
732
733
734
735
736
737
738
|
# File 'lib/runeblog.rb', line 727
def generate_post(draft, force = false)
log!(enter: __method__, args: [draft], level: 1)
views = _get_views(draft)
views.each do |view|
_handle_post(draft, view)
end
slug = File.basename(draft).sub(/.lt3$/, "")
postdir = self.view.dir/"remote/post/"/slug
rescue => err
_tmp_error(err)
end
|
#generate_view(view) ⇒ Object
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
|
# File 'lib/runeblog.rb', line 576
def generate_view(view) log!(enter: __method__, args: [view])
vdir = @root/:views/view
@theme = @root/:views/view/:themes/:standard
@data = @root/:views/view/:data
depend = [vdir/"remote/etc/blog.css.lt3", @data/"global.lt3",
@theme/"blog/head.lt3",
@theme/"blog/index.lt3"] preprocess cwd: vdir/"themes/standard/etc", src: "blog.css.lt3",
copy: vdir/"remote/etc/", call: [".nopara"], strip: true , vars: @view.globals
preprocess cwd: vdir/"themes/standard", deps: depend, force: true,
src: "blog/generate.lt3", dst: vdir/:remote/"index.html",
call: ".nopara" , vars: @view.globals
copy!("#{vdir}/themes/standard/banner/*", "#{vdir}/remote/banner/") copy("#{vdir}/assets/*", "#{vdir}/remote/assets/")
copy_widget_html(view)
rescue => err
STDERR.puts err
STDERR.puts err.backtrace.join("\n")
end
|
#get_sequence ⇒ Object
322
323
324
325
|
# File 'lib/runeblog.rb', line 322
def get_sequence
log!(enter: __method__, level: 3)
File.read(@root/"data/sequence").to_i
end
|
#import_legacy_post(file, oldfile, testing = false) ⇒ Object
525
526
|
# File 'lib/runeblog.rb', line 525
def import_legacy_post(file, oldfile, testing = false)
end
|
#index_entry(slug) ⇒ Object
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
|
# File 'lib/runeblog.rb', line 429
def index_entry(slug)
log!(enter: __method__, args: [slug], level: 2)
id = slug.to_i
text = nil
@theme = @view.dir/"themes/standard"
post_entry_name = @theme/"blog/post_entry.lt3"
depend = [post_entry_name]
html = "/tmp/post_entry.html"
preprocess src: post_entry_name, dst: html,
call: ".nopara", vars: @view.globals @_post_entry = File.read(html)
vp = post_lookup(id)
nslug, aslug, title, date, teaser_text =
vp.nslug, vp.aslug, vp.title, vp.date, vp.teaser_text
path = vp.path
url = aslug + ".html"
date = ::Date.parse(date)
date = date.strftime("%B %e<br><div style='float: right'>%Y</div>")
text = interpolate(@_post_entry, binding)
text
rescue => err
_tmp_error(err)
end
|
#inspect ⇒ Object
256
257
258
259
260
261
262
263
264
265
|
# File 'lib/runeblog.rb', line 256
def inspect
log!(enter: __method__, level: 3)
str = "blog: "
ivars = ["@root", "@sequence"] ivars.each do |iv|
val = self.instance_variable_get(iv)
str << "#{iv}: #{val} "
end
str
end
|
#make_empty_view_tree(view_name) ⇒ Object
362
363
364
365
366
367
368
369
370
371
372
|
# File 'lib/runeblog.rb', line 362
def make_empty_view_tree(view_name)
log!(enter: __method__, args: [view_name], level: 2)
Dir.chdir(@root) do
cmd = "cp -r #{RuneBlog::Path}/../empty_view views/#{view_name}"
system!(cmd)
cmd = "cp -r widgets views/#{view_name}"
system!(cmd)
end
rescue => err
_tmp_error(err)
end
|
#make_slug(meta) ⇒ Object
780
781
782
783
784
785
786
787
788
|
# File 'lib/runeblog.rb', line 780
def make_slug(meta)
log!(enter: __method__, args: [meta], level: 3)
check_nonempty_string(meta.title)
label = '%04d' % meta.num slug0 = meta.title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
str = "#{label}-#{slug0}"
meta.slug = str
str
end
|
#mark_last_published(str) ⇒ Object
348
349
350
351
|
# File 'lib/runeblog.rb', line 348
def mark_last_published(str)
log!(enter: __method__, args: [str], level: 2)
dump(str, "#{self.view.dir}/last_published")
end
|
#next_sequence ⇒ Object
327
328
329
330
331
332
|
# File 'lib/runeblog.rb', line 327
def next_sequence
log!(enter: __method__, level: 3)
@sequence += 1
dump(@sequence, @root/"data/sequence")
@sequence
end
|
#post_lookup(postid) ⇒ Object
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
|
# File 'lib/runeblog.rb', line 413
def post_lookup(postid) log!(enter: __method__, args: [postid], level: 2)
slug = title = date = teaser_text = nil
dir_posts = @vdir/:posts
posts = Dir.entries(dir_posts).grep(/^\d\d\d\d/).map {|x| dir_posts/x }
posts.select! {|x| File.directory?(x) }
posts = posts.select {|x| File.basename(x).to_i == postid }
postdir = exactly_one(posts, posts.join("/"))
vp = RuneBlog::ViewPost.new(self.view, postdir)
vp
rescue => err
_tmp_error(err)
end
|
#posts ⇒ Object
528
529
530
531
532
533
|
# File 'lib/runeblog.rb', line 528
def posts
log!(enter: __method__, level: 3)
dir = self.view.dir/:posts
posts = Dir.entries(dir).grep(/^\d{4}/)
posts.sort
end
|
#process_post(sourcefile) ⇒ Object
243
244
245
246
247
248
249
250
251
252
253
254
|
# File 'lib/runeblog.rb', line 243
def process_post(sourcefile)
log!(enter: __method__, args: [sourcefile], level: 2)
nslug = sourcefile.sub(/.lt3/, "")
dir = @root/:posts/nslug
create_dirs(dir)
preprocess cwd: dir, src: @root/:drafts/sourcefile, dst: @root/:posts/sourcefile.sub(/.lt3/, ".html"), mix: "liveblog", vars: @view.globals _deploy_local(dir)
rescue => err
_tmp_error(err)
end
|
FIXME reconcile with _get_draft data
#remove_post(num) ⇒ Object
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
|
# File 'lib/runeblog.rb', line 740
def remove_post(num)
log!(enter: __method__, args: [num], level: 1)
check_integer(num)
tag = prefix(num)
files = Find.find(self.view.dir).to_a
list = files.select {|x| File.directory?(x) and x =~ /#{tag}/ }
return nil if list.empty?
dest = list.map {|f| f.sub(/(?<num>\d{4}-)/, "_\\k<num>") }
list.each.with_index do |src, i|
cmd = "mv #{src} #{dest[i]} 2>/dev/null"
system!(cmd)
end
true
end
|
#str2view(str) ⇒ Object
def view(name = nil)
log!(enter: __method__, args: [name], level: 3)
return @view if name.nil?
check_nonempty_string(name)
return str2view(name)
end
281
282
283
284
285
|
# File 'lib/runeblog.rb', line 281
def str2view(str)
log!(enter: __method__, args: [str], level: 3)
check_nonempty_string(str) @views.find {|x| x.name == str }
end
|
#undelete_post(num) ⇒ Object
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
|
# File 'lib/runeblog.rb', line 757
def undelete_post(num)
log!(enter: __method__, args: [num], level: 1)
check_integer(num)
files = Find.find(@root/:views).to_a
tag = prefix(num)
list = files.select {|x| File.directory?(x) and x =~ /_#{tag}/ }
return nil if list.empty?
dest = list.map {|f| f.sub(/_(?<num>\d{4}-)/, "\\k<num>") }
list.each.with_index do |src, i|
cmd = "mv #{src} #{dest[i]} 2>/dev/null"
system!(cmd)
end
true
end
|
#view?(name) ⇒ Boolean
267
268
269
270
271
|
# File 'lib/runeblog.rb', line 267
def view?(name)
log!(enter: __method__, args: [name], level: 3)
check_nonempty_string(name)
views.any? {|x| x.name == name }
end
|
#view_files ⇒ Object
405
406
407
408
409
410
411
|
# File 'lib/runeblog.rb', line 405
def view_files
log!(enter: __method__, level: 2)
vdir = self.view.dir
files = [vdir/"index.html"]
files += posts.map {|x| vdir/x }
files.reject! {|f| File.mtime(f) < File.mtime(vdir/:last_published) }
end
|
#viewdir(v = nil) ⇒ Object
334
335
336
337
338
339
340
341
|
# File 'lib/runeblog.rb', line 334
def viewdir(v = nil) log!(enter: __method__, args: [v], level: 3)
return @view if v.nil?
check_nonempty_string(v)
dir = @root/:views/v
puts "Dir = #{dir}" return dir
end
|