Top Level Namespace
Defined Under Namespace
Modules: PathSep Classes: RuneBlog
Constant Summary collapse
- LEXT =
".lt3"
Instance Method Summary collapse
- #_blank(url) ⇒ Object
- #_card_generic(card_title:, middle:, extra: "") ⇒ Object
- #_errout(*args) ⇒ Object
-
#_html_body(file, css = nil) ⇒ Object
helper methods.
-
#_interpolate(str, context) ⇒ Object
FIXME move this later.
- #_local_tag?(tag) ⇒ Boolean
- #_main(url) ⇒ Object
- #_passthru(line) ⇒ Object
- #_passthru_noline(line) ⇒ Object
-
#_post_lookup(postid) ⇒ Object
side-effect.
-
#_var(name) ⇒ Object
FIXME scope issue!.
- #_widget_card(url, tag) ⇒ Object
- #_widget_main(url, tag) ⇒ Object
- #_write_card(cardfile, mainfile, pairs, card_title, tag, relative: true) ⇒ Object
- #_write_main(mainfile, pairs, card_title, tag) ⇒ Object
- #_write_metadata ⇒ Object
-
#assure(hash) ⇒ Object
really the same as verify for now…
- #backlink ⇒ Object
- #card1 ⇒ Object
- #card2 ⇒ Object
- #card_iframe ⇒ Object
-
#categories ⇒ Object
does nothing right now.
- #check_meta(meta, where = "") ⇒ Object
-
#dump(obj, name) ⇒ Object
FIXME scope.
- #finalize ⇒ Object
-
#h1 ⇒ Object
Move elsewhere later!.
- #h2 ⇒ Object
- #h3 ⇒ Object
- #h4 ⇒ Object
- #h5 ⇒ Object
- #h6 ⇒ Object
-
#head ⇒ Object
Does NOT output <head> tags.
- #hr ⇒ Object
-
#image ⇒ Object
primitive so far.
-
#init_liveblog ⇒ Object
errfile = File.new(“/tmp/liveblog.out”, “w”) STDERR.reopen(errfile).
-
#inset ⇒ Object
inset.
- #list ⇒ Object
- #list! ⇒ Object
- #log!(str: "", enter: nil, args: [], pwd: false, dir: false) ⇒ Object
-
#make_exception(sym, str) ⇒ Object
Refactor, move stuff elsewhere?.
- #make_main_links ⇒ Object
-
#meta ⇒ Object
newer stuff…
- #navbar ⇒ Object
- #pin ⇒ Object
-
#post ⇒ Object
“dot” commands.
- #prefix(num) ⇒ Object
- #pubdate ⇒ Object
- #quote ⇒ Object
-
#recent_posts ⇒ Object
side-effect.
- #script ⇒ Object
- #sidebar ⇒ Object
- #stale?(src, dst, force = false) ⇒ Boolean
- #style ⇒ Object
- #stylesheet ⇒ Object
- #system!(str) ⇒ Object
- #tag_cloud ⇒ Object
- #tags ⇒ Object
- #teaser ⇒ Object
- #title ⇒ Object
- #verify(hash) ⇒ Object
- #views ⇒ Object
- #write_post ⇒ Object
- #xlate(cwd: Dir.pwd, src:, dst: (strip = true; src.sub(/.lt3$/,"")), copy: nil, debug: false, force: false) ⇒ Object
Instance Method Details
#_blank(url) ⇒ Object
678 679 680 |
# File 'lib/liveblog.rb', line 678 def _blank(url) %[href='#{url}' target='blank'] end |
#_card_generic(card_title:, middle:, extra: "") ⇒ Object
655 656 657 658 659 660 661 662 663 664 665 666 667 668 |
# File 'lib/liveblog.rb', line 655 def _card_generic(card_title:, middle:, extra: "") front = " <div class=\"card \#{extra} mb-3\">\n <div class=\"card-body\">\n <h5 class=\"card-title\">\#{card_title}</h5>\n HTML\n\n tail = <<-HTML\n </div>\n </div>\n HTML\n text = front + middle + tail\n _out text + \"\\n \"\nend\n" |
#_errout(*args) ⇒ Object
608 609 610 |
# File 'lib/liveblog.rb', line 608 def _errout(*args) ::STDERR.puts *args end |
#_html_body(file, css = nil) ⇒ Object
helper methods
513 514 515 516 517 518 519 520 521 522 523 |
# File 'lib/liveblog.rb', line 513 def _html_body(file, css = nil) file.puts "<html>" if css file.puts " <head>" file.puts " <style>\n#{css}\n </style>" file.puts " </head>" end file.puts " <body>" yield file.puts " </body>\n</html>" end |
#_interpolate(str, context) ⇒ Object
FIXME move this later
650 651 652 653 |
# File 'lib/liveblog.rb', line 650 def _interpolate(str, context) # FIXME move this later wrapped = "%[" + str.dup + "]" # could fail... eval(wrapped, context) end |
#_local_tag?(tag) ⇒ Boolean
571 572 573 574 575 576 577 578 579 580 |
# File 'lib/liveblog.rb', line 571 def _local_tag?(tag) case tag.to_sym when :pages true when :news, :links false else true # Hmmm... end end |
#_main(url) ⇒ Object
674 675 676 |
# File 'lib/liveblog.rb', line 674 def _main(url) %[href="javascript: void(0)" onclick="javascript:open_main('#{url}')"] end |
#_passthru(line) ⇒ Object
612 613 614 615 616 617 |
# File 'lib/liveblog.rb', line 612 def _passthru(line) return if line.nil? line = _format(line) _out line + "\n" _out "<p>" if line.empty? && ! @_nopara end |
#_passthru_noline(line) ⇒ Object
619 620 621 622 623 624 |
# File 'lib/liveblog.rb', line 619 def _passthru_noline(line) return if line.nil? line = _format(line) _out line _out "<p>" if line.empty? && ! @_nopara end |
#_post_lookup(postid) ⇒ Object
side-effect
635 636 637 638 639 640 641 642 643 644 645 646 647 648 |
# File 'lib/liveblog.rb', line 635 def _post_lookup(postid) # side-effect # .. = templates, ../.. = views/thisview slug = title = date = = 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) } post = posts.select {|x| File.basename(x).to_i == postid } raise "Error: More than one post #{postid}" if post.size > 1 postdir = post.first vp = RuneBlog::ViewPost.new(@blog.view, postdir) vp end |
#_var(name) ⇒ Object
FIXME scope issue!
670 671 672 |
# File 'lib/liveblog.rb', line 670 def _var(name) # FIXME scope issue! ::Livetext::Vars[name] || "[:#{name} is undefined]" end |
#_widget_card(url, tag) ⇒ Object
686 687 688 689 |
# File 'lib/liveblog.rb', line 686 def (url, tag) url2 = :widgets/tag/url %[href="#{url2}"] end |
#_widget_main(url, tag) ⇒ Object
682 683 684 |
# File 'lib/liveblog.rb', line 682 def (url, tag) %[href="#{url}"] end |
#_write_card(cardfile, mainfile, pairs, card_title, tag, relative: true) ⇒ Object
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 |
# File 'lib/liveblog.rb', line 525 def _write_card(cardfile, mainfile, pairs, card_title, tag, relative: true) log!(str: "Creating #{cardfile}.html", pwd: true) url = mainfile url = :widgets/tag/mainfile + ".html" File.open("#{cardfile}.html", "w") do |f| f.puts " <div class=\"card mb-3\">\n <div class=\"card-body\">\n <h5 class=\"card-title\">\n <button type=\"button\" class=\"btn btn-primary\" data-toggle=\"collapse\" data-target=\"#\#{tag}\">+</button>\n <a href=\"javascript: void(0)\" \n onclick=\"javascript:open_main('\#{url}')\" \n style=\"text-decoration: none; color: black\"> \#{card_title}</a>\n </h5>\n <div class=\"collapse\" id=\"\#{tag}\">\n EOS\n log!(str: \"Writing data pairs to \#{cardfile}.html\", pwd: true)\n local = _local_tag?(tag)\n pairs.each do |file, title| \n url = file\n yesno = \"yes\"\n yesno, title = title.split(/, */) if title =~ /^[yes|no]/ # FIXME please!\n\n case [yesno, local]\n when [\"yes\", false] # can iframe, remote file\n url_ref = \"href='\#{file}'\"\n when [\"yes\", true] # can iframe, local file\n url_ref = _widget_card(file, tag)\n when [\"no\", false] # CAN'T iframe, remote file\n url_ref = _blank(file)\n when [\"no\", true] # CAN'T iframe, local file (possible?)\n url_ref = _blank(file)\n end\n\n anchor = %[<a \#{url_ref}>\#{title}</a>]\n wrapper = %[<li class=\"list-group-item\">\#{anchor}</li>]\n f.puts wrapper\n end\n f.puts <<-EOS\n </div>\n </div>\n </div>\n EOS\n end\nend\n" |
#_write_main(mainfile, pairs, card_title, tag) ⇒ Object
582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 |
# File 'lib/liveblog.rb', line 582 def _write_main(mainfile, pairs, card_title, tag) log!(str: "Creating #{mainfile}.html", pwd: true) local = _local_tag?(tag) File.open("#{mainfile}.html", "w") do |f| _html_body(f) do f.puts "<h1>#{card_title}</h1>" pairs.each do |file, title| yesno = "yes" yesno, title = title.split(/, */) if title =~ /^[yes|no]/ # FIXME please! case [yesno, local] when ["yes", false] # can iframe, remote file url_ref = "href='#{file}'" when ["yes", true] # can iframe, local file url_ref = (file, tag) when ["no", false] # CAN'T iframe, remote file url_ref = _blank(file) when ["no", true] # CAN'T iframe, local file (possible?) url_ref = _blank(file) end css = "color: #8888FF; text-decoration: none; font-size: 24px; font-family: verdana" f.puts %[<a style="#{css}" #{url_ref}>#{title}</a> <br>] end end end end |
#_write_metadata ⇒ Object
626 627 628 629 630 631 632 633 |
# File 'lib/liveblog.rb', line 626 def File.write("teaser.txt", .) fields = [:num, :title, :date, :pubdate, :views, :tags] fname2 = "metadata.txt" f2 = File.open(fname2, "w") do |f2| fields.each {|fld| f2.puts "#{fld}: #{@meta.send(fld)}" } end end |
#assure(hash) ⇒ Object
really the same as verify for now…
71 72 73 74 75 76 |
# File 'lib/global.rb', line 71 def assure(hash) # really the same as verify for now... log!(enter: __method__, args: [hash]) hash.each_pair do |expr, msg| puts "<< #{msg}" unless expr end end |
#backlink ⇒ Object
36 37 38 |
# File 'lib/liveblog.rb', line 36 def backlink _out %[<br><a href="javascript:history.go(-1)">[Back]</a>] end |
#card1 ⇒ Object
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 |
# File 'lib/liveblog.rb', line 403 def card1 title, lines = _data, _body lines.map!(&:chomp) card_text = lines[0] url, classname, cdata = lines[1].split(",", 4) main = _main(url) middle = " <p class=\"card-text\">\#{card_text}</p>\n <a \#{main} class=\"\#{classname}\">\#{cdata}</a>\n HTML\n\n _card_generic(card_title: title, middle: middle, extra: \"bg-dark text-white\")\nend\n" |
#card2 ⇒ Object
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 |
# File 'lib/liveblog.rb', line 419 def card2 str = _data file, card_title = str.chomp.split(" ", 2) card_title = %[<a #{_main(file)} style="text-decoration: none; color: black">#{card_title}</a>] # FIXME is this wrong?? open = " <div class=\"card mb-3\">\n <div class=\"card-body\">\n <h5 class=\"card-title\">\#{card_title}</h5>\n <ul class=\"list-group list-group-flush\">\n HTML\n _out open\n _body do |line|\n url, cdata = line.chomp.split(\",\", 3)\n main = _main(url)\n _out %[<li class=\"list-group-item\"><a \#{main}}\">\#{cdata}</a> </li>]\n end\n close = %[ </ul>\\n </div>\\n </div>]\n _out close\nend\n" |
#card_iframe ⇒ Object
343 344 345 346 347 348 349 350 351 352 353 354 355 356 |
# File 'lib/liveblog.rb', line 343 def card_iframe title, lines = _data, _body lines.map!(&:chomp) url = lines[0].chomp stuff = lines[1..-1].join(" ") # FIXME later middle = " <iframe src=\"\#{url}\" \#{stuff} \n style=\"border: 0\" \#{stuff}\n frameborder=\"0\" scrolling=\"no\">\n </iframe>\n HTML\n\n _card_generic(card_title: title, middle: middle, extra: \"bg-dark text-white\")\nend\n" |
#categories ⇒ Object
does nothing right now
47 48 |
# File 'lib/liveblog.rb', line 47 def categories # does nothing right now end |
#check_meta(meta, where = "") ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/global.rb', line 51 def (, where = "") log!(enter: __method__, args: [, where]) str = "--- #{where}\n" str << "\ncheck_meta: \n" + caller.join("\n") + "\n meta = #{meta.inspect}\n" str << " title missing!\n" unless .title str << " title missing! (empty)" if .title && .title.empty? str << " num missing!\n" unless .num if str =~ /missing!/ debug str raise str end end |
#dump(obj, name) ⇒ Object
FIXME scope
161 162 163 164 |
# File 'lib/helpers-blog.rb', line 161 def dump(obj, name) # FIXME scope log!(str: "scope problem", enter: __method__, args: [obj, name]) File.write(name, obj) end |
#finalize ⇒ Object
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/liveblog.rb', line 201 def finalize # FIXME simplify this! unless puts @live.body return end if @blog.nil? return end @slug = @blog.make_slug() slug_dir = @slug @postdir = @blog.view.dir/:posts/slug_dir write_post end |
#h1 ⇒ Object
Move elsewhere later!
57 |
# File 'lib/liveblog.rb', line 57 def h1; _passthru "<h1>#{@_data}</h1>"; end |
#h2 ⇒ Object
58 |
# File 'lib/liveblog.rb', line 58 def h2; _passthru "<h2>#{@_data}</h2>"; end |
#h3 ⇒ Object
59 |
# File 'lib/liveblog.rb', line 59 def h3; _passthru "<h3>#{@_data}</h3>"; end |
#h4 ⇒ Object
60 |
# File 'lib/liveblog.rb', line 60 def h4; _passthru "<h4>#{@_data}</h4>"; end |
#h5 ⇒ Object
61 |
# File 'lib/liveblog.rb', line 61 def h5; _passthru "<h5>#{@_data}</h5>"; end |
#h6 ⇒ Object
62 |
# File 'lib/liveblog.rb', line 62 def h6; _passthru "<h6>#{@_data}</h6>"; end |
#head ⇒ Object
Does NOT output <head> tags
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'lib/liveblog.rb', line 218 def head # Does NOT output <head> tags args = _args args.each do |inc| self.data = inc _include end # Depends on vars: title, desc, host defaults = {} defaults = { "charset" => %[<meta charset="utf-8">], "http-equiv" => %[<meta http-equiv="X-UA-Compatible" content="IE=edge">], "title" => %[<title>\n #{_var(:blog)} | #{_var("blog.desc")}\n </title>], "generator" => %[<meta name="generator" content="Runeblog v #@version">], "og:title" => %[<meta property="og:title" content="#{_var(:blog)}">], "og:locale" => %[<meta property="og:locale" content="#{_var(:locale)}">], "description" => %[<meta name="description" content="#{_var("blog.desc")}">], "og:description" => %[<meta property="og:description" content="#{_var("blog.desc")}">], "linkc" => %[<link rel="canonical" href="#{_var(:host)}">], "og:url" => %[<meta property="og:url" content="#{_var(:host)}">], "og:site_name" => %[<meta property="og:site_name" content="#{_var(:blog)}">], "style" => %[<link rel="stylesheet" href="etc/blog.css">], "feed" => %[<link type="application/atom+xml" rel="alternate" href="#{_var(:host)}/feed.xml" title="#{_var(:blog)}">], "favicon" => %[<link rel="shortcut icon" type="image/x-icon" href="../etc/favicon.ico">\n <link rel="apple-touch-icon" href="../etc/favicon.ico">] } result = {} lines = _body lines.each do |line| line.chomp word, remain = line.split(" ", 2) case word when "viewport" result["viewport"] = %[<meta name="viewport" content="#{remain}">] when "script" # FIXME this is broken file = remain text = File.read(file) result["script"] = Livetext.new.transform(text) when "style" result["style"] = %[<link rel="stylesheet" href="('/etc/#{remain}')">] # Later: allow other overrides when ""; break else if defaults[word] result[word] = %[<meta property="#{word}" content="#{remain}">] else puts "Unknown tag '#{word}'" end end end hash = defaults.dup.update(result) # FIXME collisions? hash.each_value {|x| _out " " + x } _out "<body>" end |
#hr ⇒ Object
64 |
# File 'lib/liveblog.rb', line 64 def hr; _passthru "<hr>"; end |
#image ⇒ Object
primitive so far
153 154 155 156 157 158 159 |
# File 'lib/liveblog.rb', line 153 def image # primitive so far _debug "img: huh? <img src=#{_args.first}></img>" fname = _args.first path = :assets/fname _out "<img src=#{path}></img>" _optional_blank_line end |
#init_liveblog ⇒ Object
errfile = File.new(“/tmp/liveblog.out”, “w”) STDERR.reopen(errfile)
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/liveblog.rb', line 12 def init_liveblog # FIXME - a lot of this logic sucks here = Dir.pwd dir = here loop { dir = Dir.pwd; break if File.exist?("config"); Dir.chdir("..") } Dir.chdir(here) # here??? or dir?? @blog = RuneBlog.new(dir) @root = @blog.root @view = @blog.view @view_name = @blog.view.name @vdir = @blog.view.dir @version = RuneBlog::VERSION @theme = @vdir/:themes/:standard end |
#inset ⇒ Object
inset
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/liveblog.rb', line 107 def inset lines = _body box = "" lines.each do |line| line = line.dup if line[0] == "/" # Only into inset line[0] = ' ' box << line.dup + " " line.replace(" ") end if line[0] == "|" # Into inset and body line[0] = ' ' box << line.dup + " " end _passthru(line) end lr = _args.first wide = _args[1] || "25" _passthru "<div style='float:#{lr}; width: #{wide}%; padding:8px; padding-right:12px; font-family:verdana'>" _passthru '<b><i>' _passthru box _passthru_noline '</i></b></div>' _optional_blank_line end |
#list ⇒ Object
66 67 68 69 70 71 |
# File 'lib/liveblog.rb', line 66 def list _out "<ul>" _body {|line| _out "<li>#{line}</li>" } _out "</ul>" _optional_blank_line end |
#list! ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/liveblog.rb', line 73 def list! _out "<ul>" lines = _body.each loop do line = lines.next line = _format(line) if line[0] == " " _out line else _out "<li>#{line}</li>" end end _out "</ul>" _optional_blank_line end |
#log!(str: "", enter: nil, args: [], pwd: false, dir: false) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/logging.rb', line 5 def log!(str: "", enter: nil, args: [], pwd: false, dir: false) return unless $logging time = Time.now.strftime("%H:%M:%S") meth = "" meth = "#{enter}" if enter para = "(#{args.inspect[1..-2]})" source = caller[0].sub(/.*\//, " in ").sub(/:/, " line ").sub(/:.*/, "") source = "in #{source} (probably liveblog.rb)" if source.include? "(eval)" str = " ... #{str}" unless str.empty? indent = " "*12 $log.puts "#{time} #{meth}#{para}" $log.puts "#{indent} #{str} " unless str.empty? $log.puts "#{indent} #{source}" $log.puts "#{indent} pwd = #{Dir.pwd} " if pwd if dir files = (Dir.entries('.') - %w[. ..]).join(" ") $log.puts "#{indent} dir/* = #{files}" end # $log.puts "#{indent} livetext params = #{livedata.inpect} " unless livedata.nil? $log.puts $log.close $log = File.new("/tmp/runeblog.log","a") end |
#make_exception(sym, str) ⇒ Object
Refactor, move stuff elsewhere?
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/global.rb', line 22 def make_exception(sym, str) log!(enter: __method__, args: [sym, str]) return if Object.constants.include?(sym) Object.const_set(sym, StandardError.dup) define_method(sym) do |*args| msg = str args.each.with_index {|arg, i| msg.sub!("$#{i+1}", arg) } Object.class_eval(sym.to_s).new(msg) end end |
#make_main_links ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/liveblog.rb', line 90 def make_main_links log!(enter: __method__) # FIXME remember strings may not be safe line = _data.chomp tag, card_title = *line.split(" ", 2) cardfile, mainfile = "#{tag}-card", "#{tag}-main" input = "list.data" log!(str: "Reading #{input}", pwd: true) pairs = File.readlines(input).map {|line| line.chomp.split(/, */, 2) } _write_main(mainfile, pairs, card_title, tag) = false # (tag != "news") # FIXME kludge!!! _write_card(cardfile, mainfile, pairs, card_title, tag, relative: ) log!(str: "...returning from method", pwd: true) end |
#meta ⇒ Object
newer stuff…
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
# File 'lib/liveblog.rb', line 273 def args = _args enum = args.each str = "<meta" arg = enum.next loop do if arg.end_with?(":") str << " " << arg[0..-2] << "=" a2 = enum.next str << %["#{a2}"] else STDERR.puts "=== meta error?" end arg = enum.next end str << ">" _out str end |
#navbar ⇒ Object
465 466 467 468 469 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 507 |
# File 'lib/liveblog.rb', line 465 def vdir = @blog.view.dir title = _var(:blog) open = " <nav class=\"navbar navbar-expand-lg navbar-light bg-light\">\n <a class=\"navbar-brand\" href=\"index.html\">\#{title}</a>\n <button class=\"navbar-toggler\" \n type=\"button\" \n data-toggle=\"collapse\" \n data-target=\"#navbarSupportedContent\"\n aria-controls=\"navbarSupportedContent\" \n aria-expanded=\"false\" \n aria-label=\"Toggle navigation\">\n <span class=\"navbar-toggler-icon\"></span>\n </button>\n <div class=\"collapse navbar-collapse pull-right\" \n id=\"navbarSupportedContent\">\n <ul class=\"navbar-nav mr-auto\">\n HTML\n close = <<-HTML\n </ul>\n </div>\n </nav>\n HTML\n\n first = true\n _out open\n lines = _body\n lines.each do |line|\n basename, cdata = line.chomp.strip.split(\" \", 2)\n full = :navbar/basename+\".html\"\n href_main = _main(full)\n if first\n first = false # hardcode this part??\n _out %[<li class=\"nav-item active\"> <a class=\"nav-link\" href=\"index.html\">\#{cdata}<span class=\"sr-only\">(current)</span></a> </li>]\n else\n xlate cwd: \"navbar\", src: basename, dst: vdir/\"remote/navbar\"/basename+\".html\" # , debug: true\n _out %[<li class=\"nav-item\"> <a class=\"nav-link\" \#{href_main}>\#{cdata}</a> </li>]\n end\n end\n _out close\nend\n" |
#pin ⇒ Object
175 176 177 178 179 180 181 |
# File 'lib/liveblog.rb', line 175 def pin raise "'post' was not called" unless _debug "data = #{_args}" # verify only already-specified views? .pinned = _args.dup _optional_blank_line end |
#post ⇒ Object
“dot” commands
30 31 32 33 34 |
# File 'lib/liveblog.rb', line 30 def post = OpenStruct.new .num = _args[0] _out " <!-- Post number #{@meta.num} -->\n " end |
#prefix(num) ⇒ Object
46 47 48 49 |
# File 'lib/global.rb', line 46 def prefix(num) log!(enter: __method__, args: [num]) "#{'%04d' % num.to_i}" end |
#pubdate ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/liveblog.rb', line 141 def pubdate raise "'post' was not called" unless _debug "data = #@_data" # Check for discrepancy? match = /(\d{4}).(\d{2}).(\d{2})/.match @_data junk, y, m, d = match.to_a y, m, d = y.to_i, m.to_i, d.to_i .date = ::Date.new(y, m, d) .pubdate = "%04d-%02d-%02d" % [y, m, d] _optional_blank_line end |
#quote ⇒ Object
40 41 42 43 44 45 |
# File 'lib/liveblog.rb', line 40 def quote _passthru "<blockquote>" _passthru _body _passthru "</blockquote>" _optional_blank_line end |
#recent_posts ⇒ Object
side-effect
292 293 294 295 296 297 298 299 300 |
# File 'lib/liveblog.rb', line 292 def recent_posts # side-effect _out " <div class=\"col-lg-9 col-md-9 col-sm-9 col-xs-12\">\n <iframe id=\"main\" style=\"width: 100vw; height: 100vh; position: relative;\" \n src='recent.html' width=100% frameborder=\"0\" allowfullscreen>\n </iframe>\n </div>\n HTML\nend\n" |
#script ⇒ Object
335 336 337 338 339 340 341 |
# File 'lib/liveblog.rb', line 335 def script lines = _body url = lines[0] integ = lines[1] cross = lines[2] || "anonymous" _out %[<script src="#{url}" integrity="#{integ}" crossorigin="#{cross}"></script>] end |
#sidebar ⇒ Object
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 |
# File 'lib/liveblog.rb', line 302 def if _args.include? "off" _body { } # iterate, do nothing return end _out %[<div class="col-lg-3 col-md-3 col-sm-3 col-xs-12">] _body do |token| tag = token.chomp.strip.downcase wtag = :widgets/tag raise "Can't find #{wtag}" unless Dir.exist?(wtag) tcard = "#{tag}-card.html" if File.exist?(wtag/"SUBFILES") children = Dir[wtag/"*.lt3"] - [wtag/tag+".lt3"] children.each do |child| dest = child.sub(/.lt3$/, ".html") xlate src: child, dst: dest # , debug: true end end xlate cwd: wtag, src: tag, dst: tcard # , debug: true _include_file wtag/tcard end _out %[</div>] end |
#stale?(src, dst, force = false) ⇒ Boolean
4 5 6 7 8 9 10 11 |
# File 'lib/xlate.rb', line 4 def stale?(src, dst, force = false) log!(enter: __method__, args: [src, dst]) raise "Source #{src} not found in #{Dir.pwd}" unless File.exist?(src) return true if force return true unless File.exist?(dst) return true if File.mtime(src) > File.mtime(dst) return false end |
#style ⇒ Object
50 51 52 53 |
# File 'lib/liveblog.rb', line 50 def style fname = _args[0] _passthru %[<link rel="stylesheet" href="???/etc/#{fname}')">] end |
#stylesheet ⇒ Object
327 328 329 330 331 332 333 |
# File 'lib/liveblog.rb', line 327 def stylesheet lines = _body url = lines[0] integ = lines[1] cross = lines[2] || "anonymous" _out %[<link rel="stylesheet" href="#{url}" integrity="#{integ}" crossorigin="#{cross}"></link>] end |
#system!(str) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/global.rb', line 33 def system!(str) log!(enter: __method__, args: [str]) rc = system(str) if rc return rc else STDERR.puts "FAILED: #{str.inspect}" STDERR.puts "\ncaller = \n#{caller.join("\n ")}\n" return rc end rc end |
#tag_cloud ⇒ Object
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 |
# File 'lib/liveblog.rb', line 442 def tag_cloud title = _data title = "Tag Cloud" if title.empty? open = " <div class=\"card mb-3\">\n <div class=\"card-body\">\n <h5 class=\"card-title\">\n <button type=\"button\" class=\"btn btn-primary\" data-toggle=\"collapse\" data-target=\"#tag-cloud\">+</button>\n \#{title}\n </h5>\n <div class=\"collapse\" id=\"tag-cloud\">\n HTML\n _out open\n _body do |line|\n line.chomp!\n url, classname, cdata = line.split(\",\", 3)\n main = _main(url)\n _out %[<a \#{main} class=\"\#{classname}\">\#{cdata}</a>]\n end\n close = %[ </div>\\n </div>\\n </div>]\n _out close\nend\n" |
#tags ⇒ Object
161 162 163 164 165 166 |
# File 'lib/liveblog.rb', line 161 def raise "'post' was not called" unless _debug "args = #{_args}" . = _args.dup || [] _optional_blank_line end |
#teaser ⇒ Object
193 194 195 196 197 198 199 |
# File 'lib/liveblog.rb', line 193 def raise "'post' was not called" unless . = _body_text setvar :teaser, . _out . + "\n" # FIXME end |
#title ⇒ Object
132 133 134 135 136 137 138 139 |
# File 'lib/liveblog.rb', line 132 def title raise "'post' was not called" unless title = @_data.chomp .title = title setvar :title, title _out %[<h1 class="post-title">#{title}</h1><br>] _optional_blank_line end |
#verify(hash) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/global.rb', line 64 def verify(hash) log!(enter: __method__, args: [hash]) hash.each_pair do |expr, msg| puts "<< #{msg}" unless expr end end |
#views ⇒ Object
168 169 170 171 172 173 |
# File 'lib/liveblog.rb', line 168 def views raise "'post' was not called" unless _debug "data = #{_args}" .views = _args.dup _optional_blank_line end |
#write_post ⇒ Object
183 184 185 186 187 188 189 190 191 |
# File 'lib/liveblog.rb', line 183 def write_post raise "'post' was not called" unless .views = .views.join(" ") if .views.is_a? Array . = ..join(" ") if ..is_a? Array rescue => err puts "err = #{err}" puts err.backtrace.join("\n") end |
#xlate(cwd: Dir.pwd, src:, dst: (strip = true; src.sub(/.lt3$/,"")), copy: nil, debug: false, force: false) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/xlate.rb', line 13 def xlate(cwd: Dir.pwd, src:, dst: (strip = true; src.sub(/.lt3$/,"")), copy: nil, debug: false, force: false) src += LEXT unless src.end_with?(LEXT) dst += ".html" unless dst.end_with?(".html") || strip indent = " "*12 Dir.chdir(cwd) do if debug STDERR.puts "#{indent} -- xlate #{src} >#{dst}" STDERR.puts "#{indent} in: #{Dir.pwd}" STDERR.puts "#{indent} from: #{caller[0]}" STDERR.puts "#{indent} copy: #{copy}" if copy end if stale?(src, dst, force) # do nothing else STDERR.puts "#{indent} -- ^ Already up to date!" if debug return end rc = system!("livetext #{src} >#{dst}") STDERR.puts "...completed (shell returned #{rc})" if debug system!("cp #{dst} #{copy}") if copy end end |