Top Level Namespace

Defined Under Namespace

Modules: PathSep Classes: OpenStruct, OpenVar, RuneBlog

Constant Summary collapse

LEXT =
".lt3"

Instance Method Summary collapse

Instance Method Details

#_blank(url) ⇒ Object



888
889
890
# File 'lib/liveblog.rb', line 888

def _blank(url)
  %[href='#{url}' target='blank']
end

#_card_generic(card_title:, middle:, extra: "") ⇒ Object



865
866
867
868
869
870
871
872
873
874
875
876
877
878
# File 'lib/liveblog.rb', line 865

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



818
819
820
# File 'lib/liveblog.rb', line 818

def _errout(*args)
  ::STDERR.puts *args
end

#_get_arg(name, args) ⇒ Object

really belongs in livetext



169
170
171
172
173
174
175
176
# File 'lib/liveblog.rb', line 169

def _get_arg(name, args)  # really belongs in livetext
  raise "(#{name}) Expected an array" unless args.is_a? Array
  raise "(#{name}) Expected an arg" if args.empty?
  raise "(#{name}) Too many args: #{args.inspect}" if args.size > 1
  val = args[0]
  raise "Expected an argument '#{name}'" if val.nil?
  val
end

#_handle_standard_widget(tag) ⇒ Object



613
614
615
616
617
618
619
620
621
622
# File 'lib/liveblog.rb', line 613

def _handle_standard_widget(tag)
  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) ⇒ Object

helper methods



806
807
808
809
810
811
812
813
814
815
816
# File 'lib/liveblog.rb', line 806

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



860
861
862
863
# File 'lib/liveblog.rb', line 860

def _interpolate(str, context)   # FIXME move this later
  wrapped = "%[" + str.dup + "]"  # could fail...
  eval(wrapped, context)
end

#_load_local(widget) ⇒ Object



584
585
586
587
588
589
590
591
592
593
594
595
# File 'lib/liveblog.rb', line 584

def _load_local(widget)
  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")
  exit
end

#_main(url) ⇒ Object



884
885
886
# File 'lib/liveblog.rb', line 884

def _main(url)
  %[href="javascript: void(0)" onclick="javascript:open_main('#{url}')"]
end

#_make_class_name(app) ⇒ Object



574
575
576
577
578
579
580
581
582
# File 'lib/liveblog.rb', line 574

def _make_class_name(app)
  if app =~ /[-_]/
    words = app.split(/[-_]/)
    name = words.map(&:capitalize).join
  else
    name = app.capitalize
  end
  return name
end

#_make_navbar(orient = :horiz) ⇒ Object



760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
# File 'lib/liveblog.rb', line 760

def _make_navbar(orient = :horiz)
  vdir = @blog.view.dir
  title = _var(:blog)

  extra = ""
  extra = "navbar-expand-lg" if orient == :horiz

  start = "       <!-- FIXME weird bug here!!! -->\n   <nav class=\"navbar \#{extra} navbar-light bg-light\">\n      <ul class=\"navbar-nav mr-auto\">\n  HTML\n  finish = <<-HTML\n      </ul>\n    </nav>\n  HTML\n\n  name = (orient == :horiz) ? \"navbar.html\" : \"vnavbar.html\"\n\n  html_file = @blog.root/:views/@blog.view/\"themes/standard/banner\"/name\n  output = File.new(html_file, \"w\")\n  output.puts start\n  lines = _read_navbar_data\n  lines = [\"index  Home\"] + lines  unless _args.include?(\"nohome\")\n  lines.each do |line|\n    basename, cdata = line.chomp.strip.split(\" \", 2)\n    full = :banner/basename+\".html\"\n    href_main = _main(full)\n    if basename == \"index\"  # special case\n      output.puts %[<li class=\"nav-item active\"> <a class=\"nav-link\" href=\"index.html\">\#{cdata}<span class=\"sr-only\">(current)</span></a> </li>]\n    else\n      dir = @blog.root/:views/@blog.view/\"themes/standard/banner\"\n      xlate cwd: dir, src: basename, dst: vdir/\"remote/banner\"/basename+\".html\" # , debug: true\n      output.puts %[<li class=\"nav-item\"> <a class=\"nav-link\" \#{href_main}>\#{cdata}</a> </li>]\n    end\n  end\n  output.puts finish\n  output.close\n  return File.read(html_file)\nend\n"

#_parse_colon_args(args, hash) ⇒ Object

really belongs in livetext



156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/liveblog.rb', line 156

def _parse_colon_args(args, hash)  # really belongs in livetext
  h2 = hash.dup
  e = args.each
  loop do
    arg = e.next.chop.to_sym
    raise "_parse_args: #{arg} is unknown" unless hash.keys.include?(arg)
    h2[arg] = e.next
  end
  h2 = h2.reject {|k,v| v.nil? }
  h2.each_pair {|k, v| raise "#{k} has no value" if v.empty? }
  h2
end

#_passthru(line) ⇒ Object



822
823
824
825
826
827
# File 'lib/liveblog.rb', line 822

def _passthru(line)
  return if line.nil?
  line = _format(line)
  _out line + "\n"
  _out "<p>" if line.empty? && ! @_nopara
end

#_passthru_noline(line) ⇒ Object



829
830
831
832
833
834
# File 'lib/liveblog.rb', line 829

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



845
846
847
848
849
850
851
852
853
854
855
856
857
858
# File 'lib/liveblog.rb', line 845

def _post_lookup(postid)    # side-effect
  # .. = templates, ../.. = views/thisview
  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) }

  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

#_read_navbar_dataObject



87
88
89
90
91
# File 'lib/liveblog.rb', line 87

def _read_navbar_data
  dir = @blog.root/:views/@blog.view/"themes/standard/banner/"
  datafile = dir/"list.data"
  File.readlines(datafile)
end

#_svg_title(*args) ⇒ Object



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
207
208
209
210
211
212
213
214
215
216
217
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
# File 'lib/liveblog.rb', line 178

def _svg_title(*args)
  width    = 330
  height   = 100
  bgcolor  = "blue"
  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 = {}
  loop do
    arg = e.next
    arg = arg.chop
    case arg   # can give runtime error if arg missing
      when "width";    width    = e.next
      when "height";   height   = e.next
      when "bgcolor";  bgcolor  = e.next
      when "style";    style    = e.next
      when "size";     size     = e.next
      when "font";     font     = e.next
      when "color";    color    = e.next
      when "xy";       xy       = e.next
      when "align";    align    = e.next
      when "style2";   style2   = e.next
      when "size2";    size2    = e.next
      when "font2";    font2    = e.next
      when "color2";   color2   = e.next
      when "xy2";      xy2      = e.next
      when "align2";   align2   = e.next
    end
  end
  x, y = xy.split(",")
  x2, y2 = xy2.split(",")
  hash["x"]       = x
  hash["y"]       = y
  hash["x2"]      = x2
  hash["y2"]      = y2
  hash["width"]   = width
  hash["height"]  = height
  hash["bgcolor"] = bgcolor
  hash["style"]   = style
  hash["size"]    = size
  hash["font"]    = font
  hash["color"]   = color
  hash["xy"]      = xy
  hash["align"]   = align
  hash["style2"]  = style2
  hash["size2"]   = size2
  hash["font2"]   = font2
  hash["color2"]  = color2
  hash["align2"]  = align2
  result = "    <svg width=\"\#{width}\" height=\"\#{height}\"\n         viewBox=\"0 0 \#{width} \#{height}\">\n      <style>\n        .title    { font: \#{style} \#{size} \#{font}; fill: \#{color} }\n        .subtitle { font: \#{style2} \#{size2} \#{font2}; fill: \#{color2} }\n      </style>\n      <rect x=\"10\" y=\"10\" rx=\"10\" ry=\"10\" width=\"\#{width-20}\" height=\"\#{height-20}\" fill=\"\#{bgcolor}\"/>\n      <text text-anchor=\"\#{align}\"  x=\"\#{x}\" y=\"\#{y}\" class=\"title\">\#{Livetext::Vars[:blog]} </text>\n      <text text-anchor=\"\#{align2}\" x=\"\#{x2}\" y=\"\#{y2}\" class=\"subtitle\">\#{Livetext::Vars[\"blog.desc\"]} </text>\n    </svg>\n  HTML\n  [result, hash]\nend\n"

#_var(name) ⇒ Object

FIXME scope issue!



880
881
882
# File 'lib/liveblog.rb', line 880

def _var(name)  # FIXME scope issue!
  ::Livetext::Vars[name] || "[:#{name} is undefined]"
end

#_write_metadataObject



836
837
838
839
840
841
842
843
# File 'lib/liveblog.rb', line 836

def 
  File.write("teaser.txt", @meta.teaser)
  fields = [:num, :title, :date, :pubdate, :views, :tags, :pinned]
  fname2 = "metadata.txt"
  f2 = File.open(fname2, "w") do |f2| 
    fields.each {|fld| f2.puts "#{fld}: #{@meta.send(fld)}" }
  end
end


78
79
80
# File 'lib/liveblog.rb', line 78

def backlink
  _out %[<br><a href="javascript:history.go(-1)">[Back]</a>]
end


93
94
95
96
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/liveblog.rb', line 93

def banner
  count = 0
  span = 1
  bg = "white"  # outside loop
  wide = nil
  high = 250
  str2 = ""
  lines = _body.to_a

  lines.each do |line|
    count += 1
    tag, *data = line.split
    data ||= []
    case tag
      when "width"
        wide = data[0]
      when "height"
        high = data[0]
      when "bgcolor"
        bg = data[0] || "white"
      when "image"
        image = data[0] || "banner.jpg"
        image = "banner"/image
        wide = data[0]
        width = wide ? "width=#{wide}" : "" 
        str2 << "      <td colspan=#{span}><img src=#{image} #{width} height=#{high}></img></td>" + "\n"
      when "svg_title"
        stuff, hash = _svg_title(*data)
STDERR.puts hash.inspect
        wide = hash["width"]
        str2 << "      <td colspan=#{span} width=#{wide}>#{stuff}</td>" + "\n"
      when "text"
        data[0] ||= "top.html"
        file = "banner"/data[0]
        str2 << "<td colspan=#{span}>" + File.read(file) + "</td>" + "\n"
      when "navbar"
        dir = @blog.root/:views/@blog.view/"themes/standard/banner/" + "\n"
        _make_navbar  # horiz is default
        stuff = File.read("banner/navbar.html")
        str2 << "<td colspan=#{span}><div style='text-align: center'>#{stuff}</div></td>" + "\n"
      when "vnavbar"
        dir = @blog.root/:views/@blog.view/"themes/standard/banner/"
        _make_navbar(:vert)
        file = "banner/vnavbar.html"
        str2 << "<td colspan=#{span}>" + File.read(file) + "</td>" + "\n"
      when "break"
         span = count - 1
         str2 << "  </tr>\n  <tr>"  + "\n"
    else
      str2 << "        '#{tag}' isn't known" + "\n"
    end
  end
  _out "<table width=100% height=#{high} bgcolor=##{bg}>"
  _out "  <tr>"
  _out str2
  _out "  </tr>"
  _out "</table>"
rescue => err
  STDERR.puts "err = #{err}"
  STDERR.puts err.backtrace.join("\n")
  gets
end

#categoriesObject

does nothing right now



300
301
# File 'lib/liveblog.rb', line 300

def categories   # does nothing right now
end

#codeObject



82
83
84
85
# File 'lib/liveblog.rb', line 82

def code
  lines = _body_text
  _out "<font size=+1><pre>\n#{lines}\n</pre></font>"
end

#dropcapObject

“dot” commands



29
30
31
32
33
34
35
36
37
# File 'lib/liveblog.rb', line 29

def dropcap
  # 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) ⇒ Object

FIXME scope



113
114
115
116
# File 'lib/helpers-blog.rb', line 113

def dump(obj, name)      # FIXME scope
  log!(str: "scope problem", enter: __method__, args: [obj, name], level: 3)
  File.write(name, obj)
end

#faqObject



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/liveblog.rb', line 64

def faq
  @faq_count ||= 0
  _out "<br>" if @faq_count == 0
  @faq_count += 1
  ques = _data.chomp
  ans  = _body_text
  id = "faq#@faq_count"
  _out %[&nbsp;<a data-toggle="collapse" href="##{id}" role="button" aria-expanded="false" aria-controls="collapseExample"><font size=+3>&#8964;</font></a>]
  _out %[&nbsp;<b>#{ques}</b>]
  _out %[<div class="collapse" id="#{id}"><br><font size=+1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#{ans}</font></div>\n]
  _out "<br>" unless @faq_count == 1
  _optional_blank_line
end

#finalizeObject



473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
# File 'lib/liveblog.rb', line 473

def finalize
STDERR.puts :final1
  return unless @meta
STDERR.puts :final2
  return @meta if @blog.nil?
STDERR.puts :final3

  @slug = @blog.make_slug(@meta)
STDERR.puts :final4
  slug_dir = @slug
  @postdir = @blog.view.dir/:posts/slug_dir
STDERR.puts :final5
  write_post
STDERR.puts :final6
  @meta
end

#h1Object

Move elsewhere later!



310
# File 'lib/liveblog.rb', line 310

def h1; _passthru "<h1>#{@_data}</h1>"; end

#h2Object



311
# File 'lib/liveblog.rb', line 311

def h2; _passthru "<h2>#{@_data}</h2>"; end

#h3Object



312
# File 'lib/liveblog.rb', line 312

def h3; _passthru "<h3>#{@_data}</h3>"; end

#h4Object



313
# File 'lib/liveblog.rb', line 313

def h4; _passthru "<h4>#{@_data}</h4>"; end

#h5Object



314
# File 'lib/liveblog.rb', line 314

def h5; _passthru "<h5>#{@_data}</h5>"; end

#h6Object



315
# File 'lib/liveblog.rb', line 315

def h6; _passthru "<h6>#{@_data}</h6>"; end

#headObject

Does NOT output <head> tags



490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
# File 'lib/liveblog.rb', line 490

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">],
# ^ FIXME
               "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 }
end

#hnavbarObject



752
753
754
# File 'lib/liveblog.rb', line 752

def hnavbar
  str = _make_navbar  # horiz is default
end

#hrObject



317
# File 'lib/liveblog.rb', line 317

def hr; _passthru "<hr>"; end

#imageObject

primitive so far



396
397
398
399
400
401
402
# File 'lib/liveblog.rb', line 396

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_liveblogObject

FIXME - a lot of this logic sucks



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/liveblog.rb', line 11

def init_liveblog    # FIXME - a lot of this logic sucks
  here = Dir.pwd
  dir = here
# loop { dir = Dir.pwd; break if File.exist?("data/ROOT"); Dir.chdir("..") }
  Dir.chdir(here)     #  here??? or dir??
  @blog = RuneBlog.new(dir)
  @root = @blog.root
  @view = @blog.view
  @view_name = @blog.view.name unless @view.nil?
  @vdir = @blog.view.dir rescue "NONAME"
  @version = RuneBlog::VERSION
  @theme = @vdir/:themes/:standard
end

#insetObject

inset



344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
# File 'lib/liveblog.rb', line 344

def inset
  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

#listObject



319
320
321
322
323
324
# File 'lib/liveblog.rb', line 319

def list
  _out "<ul>"
  _body {|line| _out "<li>#{line}</li>" }
  _out "</ul>"
  _optional_blank_line
end

#list!Object



326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
# File 'lib/liveblog.rb', line 326

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, level: 0, stderr: false) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# 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) ⇒ 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], level: 3)
  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

#metaObject

newer stuff…



545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
# File 'lib/liveblog.rb', line 545

def meta
  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


756
757
758
# File 'lib/liveblog.rb', line 756

def navbar
  str = _make_navbar  # horiz is default
end

#newer?(f1, f2) ⇒ Boolean



4
5
6
# File 'lib/xlate.rb', line 4

def newer?(f1, f2)
  File.mtime(f1) > File.mtime(f2)
end

#outlog(str = "", stderr: false) ⇒ Object



5
6
7
8
# File 'lib/logging.rb', line 5

def outlog(str = "", stderr: false)
  $log.puts str
  STDERR.puts str if stderr
end

#pinObject



418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
# File 'lib/liveblog.rb', line 418

def pin
  raise "'post' was not called" unless @meta
  _debug "data = #{_args}"  # verify only valid views?
  pinned = @_args
  @meta.pinned = pinned
  pinned.each do |pinview|
    dir = @blog.root/:views/pinview/"themes/standard/widgets/pinned/"
    datafile = dir/"list.data"
    if File.exist?(datafile)
      pins = File.readlines(datafile)
    else
      pins = []
    end
    pins << "#{@meta.num} #{@meta.title}\n"
    pins.uniq!
    File.open(datafile, "w") do |outfile|
      pins.each {|pin| outfile.puts pin }
    end
  end
  _optional_blank_line
  pinned_rebuild    # FIXME experimental
rescue => err
  STDERR.puts "err = #{err}"
  STDERR.puts err.backtrace.join("\n")
  gets
end

#pinned_rebuildObject



597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
# File 'lib/liveblog.rb', line 597

def pinned_rebuild
  view = @blog.view
  view = _args[0] unless _args.empty?
  Dir.chdir(@blog.root/:views/view/"themes/standard/") do
    wtag = "widgets/pinned"
    code = _load_local("pinned")
    if code 
      Dir.chdir(wtag) do 
        widget = code.new(@blog)
        widget.build
      end
      # _include_file wtag/"pinned-card.html"
    end
  end
end

#postObject



39
40
41
42
43
# File 'lib/liveblog.rb', line 39

def post
  @meta = OpenStruct.new
  @meta.num = _args[0]
  _out "  <!-- Post number #{@meta.num} -->\n "
end

#post_trailerObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/liveblog.rb', line 45

def post_trailer
  perma = _var("publish.proto") + "://" + _var("publish.server") +
          "/" + _var("publish.path") + "/permalink/" + _var("post.aslug") + 
          ".html"
  tags = _var("post.tags")
  if tags.empty?
    taglist = ""
  else
    taglist = "Tags: #{tags}"
  end
  _out "  <table width=100%><tr>\n    <td width=10%><a style=\"text-decoration: none\" href=\"javascript:history.go(-1)\">[Back]</a></td>\n    <td width=10%><a style=\"text-decoration: none\" href=\"\#{perma}\"> [permalink] </a></td>\n    <td width=80% align=right><font size=-3>\#{taglist}</font></td></tr></table>\n  HTML\n  # damned syntax highlighting\nend\n"

#prefix(num) ⇒ Object



47
48
49
50
# File 'lib/global.rb', line 47

def prefix(num)
  log!(enter: __method__, args: [num], level: 3)
  "#{'%04d' % num.to_i}"
end

#prerprocess(cwd: Dir.pwd, src:, dst: (strip = true; File.basename(src).sub(/.lt3$/,"")), deps: [], copy: nil, debug: false, force: false) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/xlate.rb', line 19

def prerprocess(cwd: Dir.pwd, src:, 
          dst: (strip = true; File.basename(src).sub(/.lt3$/,"")), 
          deps: [], 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
      puts "#{indent} -- xlate #{src} >#{dst}"
      puts "#{indent}      in:   #{Dir.pwd}"
      puts "#{indent}      from: #{caller[0]}"
      puts "#{indent}      copy: #{copy}" if copy
    end
    stale = stale?(src, dst, deps, force)
    if stale
      rc = system("livetext #{src} >#{dst}")
      puts "...completed (shell returned #{rc})" if debug
      system!("cp #{dst} #{copy}") if copy
    else
      puts "#{indent} -- ^ Already up to date!" if debug
      return
    end
  end
end

#pubdateObject



384
385
386
387
388
389
390
391
392
393
394
# File 'lib/liveblog.rb', line 384

def pubdate
  raise "'post' was not called" 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

#quoteObject



293
294
295
296
297
298
# File 'lib/liveblog.rb', line 293

def quote
  _passthru "<blockquote>"
  _passthru _body.join(" ")
  _passthru "</blockquote>"
  _optional_blank_line
end

#recent_postsObject

side-effect



564
565
566
567
568
569
570
571
572
# File 'lib/liveblog.rb', line 564

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: 70vw; height: 100vh; position: relative;\" \n       src='recent.html' width=100% frameborder=\"0\" allowfullscreen>\n      </iframe>\n    </div>\n  HTML\nend\n"

#scriptObject



676
677
678
679
680
681
682
# File 'lib/liveblog.rb', line 676

def script
  lines = _body
  url = lines[0]
  integ = lines[1]
  cross = lines[2] || "anonymous"
  _out %[<script src="#{url}" integrity="#{integ}" crossorigin="#{cross}"></script>]
end


624
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
654
655
656
657
658
659
660
661
662
663
664
665
666
# File 'lib/liveblog.rb', line 624

def sidebar
  _debug "--- handling sidebar\r"
  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">]

  standard = %w[pinned pages links news]

  _body do |token|
    tag = token.chomp.strip.downcase
    wtag = :widgets/tag
    raise "Can't find #{wtag}" unless Dir.exist?(wtag)
    tcard = "#{tag}-card.html"

    case
      when standard.include?(tag)
        _handle_standard_widget(tag)
      when tag == "ad"
        num = rand(1..4)
        img = "widgets/ad/ad#{num}.png"
        src, dst = img, @root/:views/@view_name/"remote/widgets/ad/"
        system!("cp #{src} #{dst}")   # , show: true)
        File.open(wtag/"vars.lt3", "w") do |f| 
          f.puts ".set ad.image = #{img}"
        end
        xlate cwd: wtag, src: tag, dst: tcard, force: true # , deps: depend # , debug: true
    end

    _include_file wtag/tcard
#   depend = %w[card.css main.css custom.rb local.rb] 
#   depend += ["#{wtag}.lt3", "#{wtag}.rb"]
#   depend.map! {|x| @blog.view.dir/"themes/standard/widgets"/wtag/x }
# _debug "--- call xlate #{tag} src = #{tag}  dst = #{tcard}\r"
  end
  _out %[</div>]
rescue => err
  puts "err = #{err}"
  puts err.backtrace.join("\n")
  exit
end

#stale?(src, dst, deps, force = false) ⇒ Boolean



8
9
10
11
12
13
14
15
16
17
# File 'lib/xlate.rb', line 8

def stale?(src, dst, deps, force = false)
  meh = File.new("/tmp/dammit-#{src.gsub(/\//, "-")}", "w")
  log!(enter: __method__, args: [src, dst], level: 3)
  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 newer?(src, dst)
  deps.each {|dep| return true if newer?(dep, dst) }
  return false
end

#styleObject



303
304
305
306
# File 'lib/liveblog.rb', line 303

def style
  fname = _args[0]
  _passthru %[<link rel="stylesheet" href="???/etc/#{fname}')">]
end

#stylesheetObject



668
669
670
671
672
673
674
# File 'lib/liveblog.rb', line 668

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

#svg_title_SOONObject



253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# File 'lib/liveblog.rb', line 253

def svg_title_SOON
  tstyle = tsize = tfont = tcolor = txy = talign = nil
  t2style = t2size = t2font = t2color = t2xy = t2align = nil
  wide, high, hue = 450, 150, "white"
  _body do |line|
    count += 1
    tag, *data = line.split
    data ||= []
    title_params = {style: nil, size: "", font: "sans-serif", color: "white",
                    xy: "5,5", align: "left"}
    case tag
      when "title";   
        hash = _parse_colon_args(data, title_params)
        tstyle, tsize, tfont, tcolor, txy, talign = 
          hash.values_at(:tstyle, :tsize, :tfont, :tcolor, :txy, :talign)
        tx, ty = txy.split(",")
      when "title2";  
        hash = _parse_colon_args(data, title_params)
        t2style, t2size, t2font, t2color, t2xy, t2align =
          hash.values_at(:t2style, :t2size, :t2font, :t2color, :t2xy, :t2align)
        t2x, t2y = t2xy.split(",")
      when "width";   wide = _get_arg(:width, data)
      when "height";  high = _get_arg(:height, data)
      when "bgcolor"; hue  = _get_arg(:bgcolor, data)
    end
  end
  "    <svg width=\"\#{wide}\" height=\"\#{high}\"\n         viewBox=\"0 0 \#{wide} \#{high}\">\n      <style>\n        .title    { font: \#{tstyle} \#{tsize} \#{tfont}; fill: \#{tcolor} }\n        .subtitle { font: \#{t2style} \#{t2size} \#{t2font}; fill: \#{t2color} }\n      </style>\n      <rect x=\"0\" y=\"0\" rx=\"10\" ry=\"10\" width=\"\#{wide}\" height=\"\#{height}\" fill=\"\#{bgcolor}\"/>\n      <text text-anchor=\"\#{talign}\"  x=\"\#{tx}\" y=\"\#{tx}\" class=\"title\">$blog </text>\n      <text text-anchor=\"\#{t2align}\" x=\"\#{t2x}\" y=\"\#{t2y}\" class=\"subtitle\">$blog.desc </text>\n    </svg>\n  HTML\nend\n"

#system!(str, show: false) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/global.rb', line 33

def system!(str, show: false)
  log!(enter: __method__, args: [str], level: 2)
  STDERR.puts str if show
  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_cloudObject



725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
# File 'lib/liveblog.rb', line 725

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"

#tagsObject



404
405
406
407
408
409
# File 'lib/liveblog.rb', line 404

def tags
  raise "'post' was not called" unless @meta
  _debug "args = #{_args}"
  @meta.tags = _args.dup || []
  _optional_blank_line
end

#teaserObject



459
460
461
462
463
464
465
466
467
468
469
470
471
# File 'lib/liveblog.rb', line 459

def teaser
  raise "'post' was not called" unless @meta
  text = _body_text
  @meta.teaser = text
  setvar :teaser, @meta.teaser
  if _args[0] == "dropcap"   # FIXME doesn't work yet!
    letter, remain = text[0], text[1..-1]
    _out %[<div class='mydrop'>#{letter}</div>]
    _out %[<div style="padding-top: 1px">#{remain}] + "\n"
  else
    _out @meta.teaser + "\n"
  end
end

#titleObject



375
376
377
378
379
380
381
382
# File 'lib/liveblog.rb', line 375

def title
  raise "'post' was not called" unless @meta
  title = @_data.chomp
  @meta.title = title
  setvar :title, title
  # FIXME refactor -- just output variables for a template
  _optional_blank_line
end

#viewsObject



411
412
413
414
415
416
# File 'lib/liveblog.rb', line 411

def views
  raise "'post' was not called" unless @meta
  _debug "data = #{_args}"
  @meta.views = _args.dup
  _optional_blank_line
end

#vnavbarObject



748
749
750
# File 'lib/liveblog.rb', line 748

def vnavbar
  str = _make_navbar(:vert)
end

#write_postObject



445
446
447
448
449
450
451
452
453
454
455
456
457
# File 'lib/liveblog.rb', line 445

def write_post
STDERR.puts :wp1
  raise "'post' was not called" unless @meta
STDERR.puts :wp2
  @meta.views = @meta.views.join(" ") if @meta.views.is_a? Array
  @meta.tags  = @meta.tags.join(" ") if @meta.tags.is_a? Array
STDERR.puts :wp3
  
STDERR.puts :wp4
rescue => err
  puts "err = #{err}"
  puts err.backtrace.join("\n")
end

#xlate(cwd: Dir.pwd, src:, dst: (strip = true; File.basename(src).sub(/.lt3$/,"")), deps: [], copy: nil, debug: false, force: false) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/xlate.rb', line 44

def xlate(cwd: Dir.pwd, src:, 
          dst: (strip = true; File.basename(src).sub(/.lt3$/,"")), 
          deps: [], 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
      puts "#{indent} -- xlate #{src} >#{dst}"
      puts "#{indent}      in:   #{Dir.pwd}"
      puts "#{indent}      from: #{caller[0]}"
      puts "#{indent}      copy: #{copy}" if copy
    end
    stale = stale?(src, dst, deps, force)
    if stale
      rc = system("livetext #{src} >#{dst}")
      puts "...completed (shell returned #{rc})" if debug
      system!("cp #{dst} #{copy}") if copy
    else
      puts "#{indent} -- ^ Already up to date!" if debug
      return
    end
  end
end

#xlate!(cwd: Dir.pwd, src:, copy: nil, debug: false, force: false) ⇒ Object



69
70
71
72
73
# File 'lib/xlate.rb', line 69

def xlate!(cwd: Dir.pwd, src:, copy: nil, debug: false, force: false)
  output = "/tmp/xlate-#{File.basename(src).sub(/.lt3$/, "")}"
  xlate cwd: cwd, src: src, dst: output, debug: debug, force: force
  File.read(output + ".html")  # return all content as string
end