class Object
Constants
- Already_publish
- Already_runeblog
- LEXT
- LIVE
- Menu
Public Instance Methods
_blank(url)
click to toggle source
# File lib/liveblog.rb, line 907 def _blank(url) log!(enter: __method__) %[href='#{url}' target='blank'] end
_card_generic(card_title:, middle:, extra: "")
click to toggle source
# File lib/liveblog.rb, line 881 def _card_generic(card_title:, middle:, extra: "") log!(enter: __method__) front = <<-HTML <div class="card #{extra} mb-3"> <div class="card-body"> <h5 class="card-title">#{card_title}</h5> HTML tail = <<-HTML </div> </div> HTML text = front + middle + tail _out text + "\n " end
_errout(*args)
click to toggle source
# File lib/liveblog.rb, line 825 def _errout(*args) log!(enter: __method__) ::STDERR.puts *args end
_get_data(file)
click to toggle source
# File lib/lowlevel.rb, line 47 def _get_data(file) log!(enter: __method__, args: [file], level: 2) lines = File.readlines(file) lines = lines.map do |line| line = line.chomp.strip line.sub(/ *# .*$/, "") # allow leading/trailing comments end lines.reject! {|x| x.empty? } lines end
_get_data?(file)
click to toggle source
# File lib/lowlevel.rb, line 42 def _get_data?(file) # File need not exist log!(enter: __method__, args: [file], level: 2) File.exist?(file) ? _get_data(file) : [] end
_got_python?()
click to toggle source
# File lib/liveblog.rb, line 68 def _got_python? log!(enter: __method__) # Dumb - fix later - check up front as needed # Should also check for praw lib str = `which python3` str.length > 0 end
_handle_standard_widget(tag)
click to toggle source
# File lib/liveblog.rb, line 612 def _handle_standard_widget(tag) log!(enter: __method__) wtag = "../../widgets"/tag code = _load_local(tag) if code Dir.chdir(wtag) do widget = code.new(@blog) widget.build end end end
_html_body(file, css = nil) { || ... }
click to toggle source
helper methods
# File lib/liveblog.rb, line 812 def _html_body(file, css = nil) log!(enter: __method__) 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
_load_local(widget)
click to toggle source
# File lib/liveblog.rb, line 597 def _load_local(widget) log!(enter: __method__) Dir.chdir("../../widgets/#{widget}") do rclass = _make_class_name(widget) found = (require("./#{widget}") if File.exist?("#{widget}.rb")) code = found ? ::RuneBlog::Widget.class_eval(rclass) : nil code end rescue => err STDERR.puts err.to_s STDERR.puts err.backtrace.join("\n") if err.respond_to?(:backtrace) sleep 6; RubyText.stop exit end
_main(url)
click to toggle source
# File lib/liveblog.rb, line 902 def _main(url) log!(enter: __method__) %[href="javascript: void(0)" onclick="javascript:open_main('#{url}')"] end
_make_class_name(app)
click to toggle source
# File lib/liveblog.rb, line 586 def _make_class_name(app) log!(enter: __method__) if app =~ /[-_]/ words = app.split(/[-_]/) name = words.map(&:capitalize).join else name = app.capitalize end return name end
_passthru(line)
click to toggle source
# File lib/liveblog.rb, line 830 def _passthru(line) log!(enter: __method__) return if line.nil? line = _format(line) _out line + "\n" _out "<p>" if line.empty? && ! @_nopara end
_passthru_noline(line)
click to toggle source
# File lib/liveblog.rb, line 838 def _passthru_noline(line) log!(enter: __method__) return if line.nil? line = _format(line) _out line _out "<p>" if line.empty? && ! @_nopara end
_post_lookup(postid)
click to toggle source
# File lib/liveblog.rb, line 856 def _post_lookup(postid) # side-effect log!(enter: __method__) # .. = templates, ../.. = views/thisview slug = title = date = teaser_text = nil view = @blog.view vdir = view.dir rescue "NONAME" setvar("View", view.name) setvar("ViewDir", @blog.root/:views/view.name) tmp = File.new("/tmp/PL-#{Time.now.to_i}.txt", "w") tmp.puts "_post_lookup: blog.view = #{@blog.view.inspect}" tmp.puts "_post_lookup: vdir = #{vdir}" 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) } tmp.puts "_post_lookup: postid = #{postid}" tmp.puts "_post_lookup: posts = \n#{posts.inspect}" tmp.close posts = posts.select {|x| File.basename(x).to_i == postid } postdir = exactly_one(posts, posts.inspect) vp = RuneBlog::ViewPost.new(@blog.view, postdir) vp end
_reddit_post_url(vdir, date, title, url)
click to toggle source
# File lib/liveblog.rb, line 76 def _reddit_post_url(vdir, date, title, url) log!(enter: __method__) _got_python? tmpfile = "/tmp/reddit-post-url.txt" File.open(tmpfile, "w") do |tmp| tmp.puts "[#{date}] #{title}" tmp.puts url end rid = nil Dir.chdir(vdir/:config) { rid = `python3 reddit/reddit_post_url.py` } system("rm #{tmpfile}") rid # returns reddit id end
_svg_title(*args)
click to toggle source
# File lib/liveblog.rb, line 250 def _svg_title(*args) log!(enter: __method__) width = "95%" height = 90 bgcolor = "black" style = nil size = "" font = "sans-serif" color = "white" xy = "5,5" align = "center" style2 = nil size2 = "" font2 = "sans-serif" color2 = "white" xy2 = "5,5" align2 = "center" e = args.each hash = {} # TODO get rid of hash?? valid = %w[width height bgcolor style size font color xy align style2 size2 font2 color2 xy2 align2] os = OpenStruct.new loop do arg = e.next arg = arg.chop raise "Don't know '#{arg}'" unless valid.include?(arg) os.send(arg+"=", e.next) end x, y = xy.split(",") x2, y2 = xy2.split(",") names = %w[x y x2 y2] + valid names.each {|name| hash[name] = os.send(name) } result = <<~HTML <svg width="#{width}" height="#{height}" viewBox="0 0 #{width} #{height}"> <defs> <linearGradient id="grad1" x1="100%" y1="100%" x2="0%" y2="100%"> <stop offset="0%" style="stop-color:rgb(198,198,228);stop-opacity:1" /> <stop offset="100%" style="stop-color:rgb(30,30,50);stop-opacity:1" /> </linearGradient> </defs> <style> .title { font: #{style} #{size} #{font}; fill: #{color} } .subtitle { font: #{style2} #{size2} #{font2}; fill: #{color2} } </style> <rect x="10" y="10" rx="10" ry="10" width="#{width}" height="#{height}" fill="url(#grad1)"/> <text text-anchor="#{align}" x="#{x}" y="#{y}" class="title">#{Livetext::Vars["view.title"]} </text> <text text-anchor="#{align2}" x="#{x2}" y="#{y2}" class="subtitle">#{Livetext::Vars["view.subtitle"]} </text> </svg> <!-- ^ how does syntax highlighting get messed up? </svg> --> HTML [result, hash] end
_tmp_error(err)
click to toggle source
# File lib/lowlevel.rb, line 2 def _tmp_error(err) STDERR.puts err STDERR.puts err.backtrace.join("\n") if err.respond_to?(:backtrace) log!(str: "#{err} - see also stderr.out") log!(str: err.backtrace.join("\n")) if err.respond_to?(:backtrace) return out = "/tmp/blog#{rand(100)}.txt" File.open(out, "w") do |f| f.puts err.to_s + "\n--------" f.puts err.backtrace.join("\n") end puts "Error: See #{out}" # sleep 3 end
_var(name)
click to toggle source
# File lib/liveblog.rb, line 897 def _var(name) # FIXME scope issue! log!(enter: __method__) ::Livetext::Vars[name] || "[:#{name} is undefined]" end
_write_metadata()
click to toggle source
# File lib/liveblog.rb, line 846 def _write_metadata log!(enter: __method__) File.write("teaser.txt", @meta.teaser) fields = [:num, :title, :date, :pubdate, :views, :tags, :pinned] fname = "metadata.txt" File.open(fname, "w") do |f| fields.each {|fld| f.puts "#{'%8s' % fld} #{@meta.send(fld)}" } end end
add_views()
click to toggle source
# File lib/newpost.rb, line 37 def add_views puts __method__ end
addvar(vars, hash)
click to toggle source
# File lib/lowlevel.rb, line 141 def addvar(vars, hash) hash.each_pair do |k, v| vars[k.to_s] = v vars[k.to_sym] = v end vars end
ask(prompt)
click to toggle source
Idea: A special sub-environment for creating a post 1. Display: view, post number, date 2. Menu? 3. - Edit/enter title 4. - Edit teaser 5. - Add views 6. - Add tags 7. - Import assets 8. - Save 9. - Quit
Edit body after save/quit
# File lib/newpost.rb, line 18 def ask(prompt) # elsewhere? print prompt str = gets str.chomp! if str str end
backlink()
click to toggle source
# File lib/liveblog.rb, line 166 def backlink log!(enter: __method__) _out %[<br><a href="javascript:history.go(-1)">[Back]</a>] end
categories()
click to toggle source
# File lib/liveblog.rb, line 314 def categories # does nothing right now log!(enter: __method__) end
code()
click to toggle source
# File lib/liveblog.rb, line 171 def code log!(enter: __method__) lines = _body # _text _out "<font size=+1><pre>\n#{lines}\n</pre></font>" end
copy(src, dst)
click to toggle source
# File lib/lowlevel.rb, line 82 def copy(src, dst) log!(enter: __method__, args: [src, dst], level: 2) cmd = "cp #{src} #{dst} 2>/dev/null" system!(cmd) end
copy!(src, dst)
click to toggle source
# File lib/lowlevel.rb, line 88 def copy!(src, dst) log!(enter: __method__, args: [src, dst], level: 2) cmd = "cp -r #{src} #{dst} 2>/dev/null" system!(cmd) end
create_dirs(*dirs)
click to toggle source
# File lib/lowlevel.rb, line 94 def create_dirs(*dirs) log!(enter: __method__, args: [*dirs], level: 3) dirs.each do |dir| dir = dir.to_s # symbols allowed next if Dir.exist?(dir) cmd = "mkdir -p #{dir} >/dev/null" result = system!(cmd) raise CantCreateDir(dir) unless result end end
dropcap()
click to toggle source
“dot” commands
# File lib/liveblog.rb, line 49 def dropcap log!(enter: __method__) # Bad form: adds another HEAD text = _data _out " " letter = text[0] remain = text[1..-1] _out %[<div class='mydrop'>#{letter}</div>] _out %[<div style="padding-top: 1px">#{remain}] end
dump(obj, name)
click to toggle source
# File lib/lowlevel.rb, line 18 def dump(obj, name) File.write(name, obj) end
edit(str)
click to toggle source
# File lib/menus.rb, line 8 def edit(str) proc { edit_file(str) } end
enter_title()
click to toggle source
# File lib/newpost.rb, line 25 def enter_title puts __method__ str = ask("Title: ") puts str.inspect end
error(err)
click to toggle source
# File lib/lowlevel.rb, line 111 def error(err) log!(str: err, enter: __method__, args: [err], level: 2) str = "\n Error... #{err}" puts str puts err.backtrace.join("\n") end
exactly_one(list, tag = nil, &block)
click to toggle source
# File lib/lowlevel.rb, line 133 def exactly_one(list, tag = nil, &block) log!(enter: __method__, args: [list], level: 2) list2 = list.select(&block) raise "List: Zero instances #{"- #{tag}" if tag}" if list.empty? raise "List: More than one instance #{"- #{tag}" if tag}" if list.size > 1 list.first end
faq()
click to toggle source
# File lib/liveblog.rb, line 151 def faq log!(enter: __method__) @faq_count ||= 0 _out "<br>" if @faq_count == 0 @faq_count += 1 ques = _data.chomp ans = _body.join("\n") id = "faq#@faq_count" _out %[ <a data-toggle="collapse" href="##{id}" role="button" aria-expanded="false" aria-controls="collapseExample"><font size=+3>⌄</font></a>] _out %[ <b>#{ques}</b>] _out %[<div class="collapse" id="#{id}"><br><font size=+1> #{ans}</font></div>\n] _out "<br>" # unless @faq_count == 1 _optional_blank_line end
finalize()
click to toggle source
# File lib/liveblog.rb, line 487 def finalize log!(str: "Now exiting livetext processing...") return unless @meta return @meta if @blog.nil? @slug = @blog.make_slug(@meta) slug_dir = @slug @postdir = @blog.view.dir/:posts/slug_dir write_post @meta end
find_item(list, &block)
click to toggle source
# File lib/lowlevel.rb, line 118 def find_item(list, &block) log!(enter: __method__, args: [list], level: 2) list2 = list.select(&block) exactly_one(list2, list.join("/")) end
find_item!(list, &block)
click to toggle source
# File lib/lowlevel.rb, line 124 def find_item!(list, &block) log!(enter: __method__, args: [list], level: 2) list2 = list.select(&block) list2 = list.select(&block) item = exactly_one(list2, list.join("/")) n = list.index(&block) [n, item] end
get_live_vars(src)
click to toggle source
# File lib/processing.rb, line 79 def get_live_vars(src) live = Livetext.customize(call: [".nopara"]) # puts "glv: src = #{src.inspect}" # STDERR.puts "glv: src = #{src.inspect}" live.xform_file(src) live end
h1()
click to toggle source
Move elsewhere later!
# File lib/liveblog.rb, line 326 def h1; _passthru "<h1>#{@_data}</h1>"; end
h2()
click to toggle source
# File lib/liveblog.rb, line 327 def h2; _passthru "<h2>#{@_data}</h2>"; end
h3()
click to toggle source
# File lib/liveblog.rb, line 328 def h3; _passthru "<h3>#{@_data}</h3>"; end
h4()
click to toggle source
# File lib/liveblog.rb, line 329 def h4; _passthru "<h4>#{@_data}</h4>"; end
h5()
click to toggle source
# File lib/liveblog.rb, line 330 def h5; _passthru "<h5>#{@_data}</h5>"; end
h6()
click to toggle source
# File lib/liveblog.rb, line 331 def h6; _passthru "<h6>#{@_data}</h6>"; end
head()
click to toggle source
# File lib/liveblog.rb, line 499 def head # Does NOT output <head> tags log!(enter: __method__) 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("view.title")} | #{_var("view.subtitle")}\n </title>], "generator" => %[<meta name="generator" content="Runeblog v #@version">], "og:title" => %[<meta property="og:title" content="#{_var("view.title")}">], "og:locale" => %[<meta property="og:locale" content="#{_var(:locale)}">], "description" => %[<meta name="description" content="#{_var("view.subtitle")}">], "og:description" => %[<meta property="og:description" content="#{_var("view.subtitle")}">], "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("view.title")}">], # "style" => %[<link rel="stylesheet" href="etc/blog.css">], # ^ FIXME "feed" => %[<link type="application/atom+xml" rel="alternate" href="#{_var(:host)}/feed.xml" title="#{_var("view.title")}">], "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 } end
hr()
click to toggle source
# File lib/liveblog.rb, line 333 def hr; _passthru "<hr>"; end
import_assets()
click to toggle source
# File lib/newpost.rb, line 45 def import_assets puts __method__ end
init_liveblog()
click to toggle source
top = Livetext::Path + “/../plugin/liveblog/” eval(File.read(“#{top}/testing.rb”))
# File lib/liveblog.rb, line 14 def init_liveblog # FIXME - a lot of this logic sucks log!(enter: __method__) dir = Dir.pwd.sub(/\.blogs.*/, "") @blog = nil Dir.chdir(dir) { @blog = RuneBlog.new } @root = @blog.root @view = @blog.view @view_name = @blog.view.name unless @view.nil? @vdir = @blog.view.dir rescue "NONAME" setvar("View", @view_name) setvar("ViewDir", @blog.root/:views/@view_name) @version = RuneBlog::VERSION @theme = @vdir/:themes/:standard @reddit_comments = "" @reddit_enabled = @blog.features["reddit"] if @reddit_enabled @reddit_comments = <<~HTML <a href="#reddit_comments"> <img src="assets/reddit-logo.png" width=24 height=24 alt="Scroll to reddit comments"></img> </a> HTML end log!(str: "End of init_liveblog") rescue => err STDERR.puts "err = #{err}" STDERR.puts err.backtrace.join("\n") if err.respond_to?(:backtrace) end
inset()
click to toggle source
inset
# File lib/liveblog.rb, line 370 def inset log!(enter: __method__) lines = _body box = "" output = [] lines.each do |line| line = line case line[0] when "/" # Only into inset line[0] = ' ' box << line line.replace(" ") when "|" # Into inset and body line[0] = ' ' box << line output << line else # Only into body output << line end end lr = _args.first wide = _args[1] || "25" stuff = "<div style='float:#{lr}; width: #{wide}%; padding:8px; padding-right:12px'>" stuff << '<b><i>' + box + '</i></b></div>' _out "</p>" # kludge!! nopara 0.upto(2) {|i| _passthru output[i] } _passthru stuff 3.upto(output.length-1) {|i| _passthru output[i] } _out "<p>" # kludge!! para _optional_blank_line end
interpolate(str, bind)
click to toggle source
# File lib/lowlevel.rb, line 105 def interpolate(str, bind) log!(enter: __method__, args: [str, bind], level: 3) wrap = "<<-EOS\n#{str}\nEOS" eval wrap, bind end
list()
click to toggle source
# File lib/liveblog.rb, line 343 def list log!(enter: __method__) _out "<ul>" _body {|line| _out "<li>#{line}</li>" } _out "</ul>" _optional_blank_line end
list!()
click to toggle source
# File lib/liveblog.rb, line 351 def list! log!(enter: __method__) _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, level: 0, stderr: false)
click to toggle source
# File lib/logging.rb, line 10 def log!(str: "", enter: nil, args: [], pwd: false, dir: false, level: 0, stderr: false) return unless $logging @err_level ||= ENV['RUNEBLOG_ERROR_LEVEL'] @err_level ||= 0 return if level < @err_level 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 outlog "#{time} #{meth}#{para}" outlog "#{indent} #{str} " unless str.empty? outlog "#{indent} #{source}" outlog "#{indent} pwd = #{Dir.pwd} " if pwd if dir files = (Dir.entries('.') - %w[. ..]).join(" ") outlog "#{indent} dir/* = #{files}" end # outlog "#{indent} livetext params = #{livedata.inpect} " unless livedata.nil? outlog $log.close $log = File.new("/tmp/runeblog.log","a") end
make_exception(sym, str, target_class = Object)
click to toggle source
# File lib/exceptions.rb, line 2 def make_exception(sym, str, target_class = Object) return if target_class.constants.include?(sym) target_class.const_set(sym, StandardError.dup) define_method(sym) do |*args| msg = str.dup args.each.with_index {|arg, i| msg.sub!("%#{i+1}", arg) } target_class.class_eval(sym.to_s).new(msg) end end
meta()
click to toggle source
newer stuff…
# File lib/liveblog.rb, line 555 def meta log!(enter: __method__) 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
newer?(f1, f2)
click to toggle source
# File lib/processing.rb, line 8 def newer?(f1, f2) File.mtime(f1) > File.mtime(f2) end
nlist()
click to toggle source
# File lib/liveblog.rb, line 335 def nlist log!(enter: __method__) _out "<ol>" _body {|line| _out "<li>#{line}</li>" } _out "</ol>" _optional_blank_line end
outlog(str = "", stderr: false)
click to toggle source
# File lib/logging.rb, line 5 def outlog(str = "", stderr: false) $log.puts str STDERR.puts str if stderr end
pin()
click to toggle source
# File lib/liveblog.rb, line 441 def pin log!(enter: __method__) raise NoPostCall unless @meta _debug "data = #{_args}" # verify only valid views? pinned = @_args @meta.pinned = pinned pinned.each do |pinview| dir = @blog.root/:views/pinview/"widgets/pinned/" datafile = dir/"list.data" pins = _get_data?(datafile) pins << "#{@meta.num} #{@meta.title}\n" pins.uniq! File.open(datafile, "w") {|out| pins.each {|pin| out.puts pin } } end _optional_blank_line rescue => err STDERR.puts "err = #{err}" STDERR.puts err.backtrace.join("\n") if err.respond_to?(:backtrace) end
post()
click to toggle source
# File lib/liveblog.rb, line 60 def post log!(enter: __method__) @meta = OpenStruct.new @meta.num = _args[0] setvar("post.num", @meta.num.to_i) _out " <!-- Post number #{@meta.num} -->\n " end
post_toolbar()
click to toggle source
# File lib/liveblog.rb, line 90 def post_toolbar log!(enter: __method__) back_icon = %[<img src="assets/back-icon.png" width=24 height=24 alt="Go back"></img>] back = %[<a style="text-decoration: none" href="javascript:history.go(-1)">#{back_icon}</a>] _out <<~HTML <div align='right'>#{back} #@reddit_comments</div> HTML end
post_trailer()
click to toggle source
# File lib/liveblog.rb, line 99 def post_trailer log!(enter: __method__) # Not called from *inside* a post, therefore no @meta -- # can/must call read_metadata num = _var("post.num").to_i log! str: "post_trailer: num = #{num}" vp = _post_lookup(num) log! str: "post_trailer: lookup = #{vp.num} #{vp.title}" dir = @blog.root/:posts/vp.nslug log! str: " -- dir = #{dir}" meta = Dir.chdir(dir) { @blog.read_metadata } nslug = @blog.make_slug(meta) aslug = nslug[5..-1] proto = _var("publish.proto") server = _var("publish.server") path = _var("publish.path") perma = "#{proto}://#{server}/#{path}/#{aslug}.html" tags = meta.tags taglist = tags.empty? ? "" : "Tags: #{tags}" reddit_txt = "" if @reddit_enabled vdir = @blog.root/:views/@blog.view date = meta.date rid_file = vdir/:posts/nslug/"reddit.id" if File.exist?(rid_file) STDERR.puts " reading #{rid_file}" rid = File.read(rid_file).chomp else STDERR.puts " creating #{rid_file}" title = meta.title rid = _reddit_post_url(vdir, date, title, perma) dump(rid, rid_file) end reddit_txt = <<~HTML <a name='reddit_comments'> <script src='https://redditjs.com/post.js' data-url="#{rid}" data-width=800 ></script> HTML # damned syntax highlighting </> end # STDERR.print "Pausing... "; getch _out <<~HTML #{reddit_txt} <hr> <table width=100%><tr> <td width=10%><a style="text-decoration: none" href="javascript:history.go(-1)">[Back]</a></td> <td width=10%><a style="text-decoration: none" href="#{perma}"> [permalink] </a></td> <td width=80% align=right><font size=-3>#{taglist}</font></td></tr></table> HTML end
prefix(num)
click to toggle source
Refactor, move elsewhere?
# File lib/runeblog_version.rb, line 31 def prefix(num) log!(enter: __method__, args: [num], level: 3) "#{'%04d' % num.to_i}" end
preprocess(cwd: Dir.pwd, src:, dst: nil, strip: false, deps: [], copy: nil, debug: false, force: false, mix: [], call: [], vars: {})
click to toggle source
# File lib/processing.rb, line 23 def preprocess(cwd: Dir.pwd, src:, dst: nil, strip: false, deps: [], copy: nil, debug: false, force: false, mix: [], call: [], vars: {}) src += LEXT unless src.end_with?(LEXT) if strip dst = File.basename(src).sub(/.lt3$/,"") else dst += ".html" unless dst.end_with?(".html") end sp = " "*12 Dir.chdir(cwd) do if debug STDERR.puts "#{sp} -- preprocess " STDERR.puts "#{sp} src: #{src}" STDERR.puts "#{sp} dst: #{dst}" STDERR.puts "#{sp} in: #{Dir.pwd}" STDERR.puts "#{sp} from: #{caller[0]}" STDERR.puts "#{sp} copy: #{copy}" if copy STDERR.puts "#{sp} vars: #{vars.inspect}" unless vars == {} STDERR.flush end stale = stale?(src, dst, deps, force) STDERR.puts <<~EOF if debug STALE = #{stale} cwd = #{cwd.inspect} src = #{src.inspect} dst = #{dst.inspect} strip = #{strip.inspect} deps = #{deps.inspect} copy = #{copy.inspect} debug = #{debug.inspect} force = #{force.inspect} mix = #{mix.inspect} call = #{call.inspect} vars = #{vars.inspect} EOF if stale live = Livetext.customize(mix: "liveblog", call: call, vars: vars) log!(str: "Calling xform_file... src = #{src} pwd = #{Dir.pwd}") out = live.xform_file(src) File.write(dst, out) system!("cp #{dst} #{copy}") if copy end puts "#{sp} -- ^ Already up to date!" if debug && ! stale end rescue => err msg = err.to_s msg << err.backtrace.join("\n") if err.respond_to?(:backtrace) STDERR.puts msg STDERR.flush log!(str: msg) end
pubdate()
click to toggle source
# File lib/liveblog.rb, line 412 def pubdate log!(enter: __method__) raise NoPostCall unless @meta _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 @meta.date = ::Date.new(y, m, d) @meta.pubdate = "%04d-%02d-%02d" % [y, m, d] _optional_blank_line end
quit_post()
click to toggle source
# File lib/newpost.rb, line 53 def quit_post puts __method__ end
quote()
click to toggle source
# File lib/liveblog.rb, line 306 def quote log!(enter: __method__) _passthru "<blockquote>" _passthru _body.join(" ") _passthru "</blockquote>" _optional_blank_line end
read_pairs(file)
click to toggle source
# File lib/lowlevel.rb, line 58 def read_pairs(file) # returns a hash log!(enter: __method__, args: [file], level: 2) lines = _get_data(file) hash = {} lines.each do |line| key, val = line.split(" ", 2) val ||= "" hash[key] = val end hash end
read_pairs!(file)
click to toggle source
# File lib/lowlevel.rb, line 70 def read_pairs!(file) # returns an openstruct log!(enter: __method__, args: [file], level: 2) lines = _get_data(file) obj = OpenStruct.new lines.each do |line| key, val = line.split(" ", 2) val ||= "" obj.send("#{key}=", val) end obj end
recent_posts()
click to toggle source
# File lib/liveblog.rb, line 575 def recent_posts # side-effect log!(enter: __method__) _out <<-HTML <div class="col-lg-9 col-md-9 col-sm-9 col-xs-12"> <iframe id="main" style="width: 70vw; height: 100vh; position: relative;" src='recent.html' width=100% frameborder="0" allowfullscreen> </iframe> </div> HTML end
save_post()
click to toggle source
# File lib/newpost.rb, line 49 def save_post puts __method__ end
script()
click to toggle source
# File lib/liveblog.rb, line 667 def script log!(enter: __method__) lines = _body url = lines[0] integ = lines[1] cross = lines[2] || "anonymous" _out %[<script src="#{url}" integrity="#{integ}" crossorigin="#{cross}"></script>] end
stale?(src, dst, deps, force = false)
click to toggle source
# File lib/processing.rb, line 12 def stale?(src, dst, deps, force = false) meh = File.new("/tmp/dammit-#{src.gsub(/\//, "-")}", "w") log!(enter: __method__, args: [src, dst], level: 3) raise FileNotFound("#{Dir.pwd}/#{src}") unless File.exist?(src) return true if force return true unless File.exist?(dst) return true if newer?(src, dst) deps.each {|dep| return true if newer?(dep, dst) } return false end
style()
click to toggle source
# File lib/liveblog.rb, line 318 def style log!(enter: __method__) fname = _args[0] _passthru %[<link rel="stylesheet" href="???/etc/#{fname}')">] end
stylesheet()
click to toggle source
# File lib/liveblog.rb, line 658 def stylesheet log!(enter: __method__) 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, show: false)
click to toggle source
# File lib/lowlevel.rb, line 26 def system!(str, show: false) log!(enter: __method__, args: [str], level: 2) STDERR.puts str if show rc = system(str) STDERR.puts " rc = #{rc.inspect}" if show return rc if rc STDERR.puts "FAILED: #{str.inspect}" STDERR.puts "\ncaller = \n#{caller.join("\n ")}\n" if defined?(RubyText) sleep 6 RubyText.stop exit end return rc end
tag_cloud()
click to toggle source
# File lib/liveblog.rb, line 717 def tag_cloud log!(enter: __method__) title = _data title = "Tag Cloud" if title.empty? open = <<-HTML <div class="card mb-3"> <div class="card-body"> <h5 class="card-title"> <button type="button" class="btn btn-primary" data-toggle="collapse" data-target="#tag-cloud">+</button> #{title} </h5> <div class="collapse" id="tag-cloud"> HTML _out open _body do |line| line.chomp! url, classname, cdata = line.split(",", 3) main = _main(url) _out %[<a #{main} class="#{classname}">#{cdata}</a>] end close = %[ </div>\n </div>\n </div>] _out close end
timelog(line, file)
click to toggle source
# File lib/lowlevel.rb, line 22 def timelog(line, file) File.open(file, "a") {|f| f.puts "#{Time.now} #{line}" } end
title()
click to toggle source
# File lib/liveblog.rb, line 402 def title log!(enter: __method__) raise NoPostCall unless @meta title = @_data.chomp @meta.title = title setvar :title, title # FIXME refactor -- just output variables for a template _optional_blank_line end
views()
click to toggle source
# File lib/liveblog.rb, line 433 def views log!(enter: __method__) raise NoPostCall unless @meta _debug "data = #{_args}" @meta.views = _args.dup _optional_blank_line end
write_post()
click to toggle source
# File lib/liveblog.rb, line 461 def write_post log!(enter: __method__) raise NoPostCall unless @meta @meta.views = @meta.views.join(" ") if @meta.views.is_a? Array @meta.tags = @meta.tags.join(" ") if @meta.tags.is_a? Array _write_metadata rescue => err puts "err = #{err}" puts err.backtrace.join("\n") if err.respond_to?(:backtrace) end