runeblog 0.2.90 → 0.2.95

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/bin/blog +10 -7
  3. data/{lib → empty_view/config}/exper/2svg.lt3 +0 -0
  4. data/{lib → empty_view/config}/exper/gen_svg.rb +0 -0
  5. data/empty_view/config/exper/meta.html +10 -0
  6. data/{lib → empty_view/config}/exper/s2.html +0 -0
  7. data/{lib → empty_view/config}/exper/varmint.rb +0 -0
  8. data/empty_view/config/facebook/facebook.rb +37 -0
  9. data/empty_view/config/facebook/fb.html +10 -0
  10. data/empty_view/config/facebook/fb.js +13 -0
  11. data/empty_view/config/reddit/config.txt +6 -0
  12. data/empty_view/config/reddit/notes.txt +4 -0
  13. data/empty_view/config/reddit/reddit_post_url.py +34 -0
  14. data/empty_view/config/reddit/redpost.rb +43 -0
  15. data/empty_view/config/reddit/the-graffiti-wall.html +91 -0
  16. data/empty_view/config/twitter/tw.html +12 -0
  17. data/empty_view/config/twitter/tw.js +5 -0
  18. data/{lib/exper/fbtw.rb → empty_view/config/twitter/twitter.rb} +1 -23
  19. data/empty_view/themes/standard/{blog → banner}/banner.lt3 +0 -0
  20. data/empty_view/themes/standard/banner/{about.lt3 → navbar/about.lt3} +0 -0
  21. data/empty_view/themes/standard/banner/{contact.lt3 → navbar/contact.lt3} +0 -0
  22. data/empty_view/themes/standard/banner/navbar/faq.lt3 +1 -0
  23. data/empty_view/themes/standard/banner/{list.data → navbar/list.data} +0 -0
  24. data/empty_view/themes/standard/blog/generate.lt3 +1 -1
  25. data/empty_view/themes/standard/global.lt3 +1 -1
  26. data/empty_view/themes/standard/post/generate.lt3 +1 -1
  27. data/empty_view/themes/standard/post/index.lt3 +8 -8
  28. data/empty_view/themes/standard/widgets/links/links.rb +1 -1
  29. data/empty_view/themes/standard/widgets/news/news.rb +1 -1
  30. data/empty_view/themes/standard/widgets/pages/pages.rb +2 -2
  31. data/empty_view/themes/standard/widgets/pinned/pinned.rb +1 -1
  32. data/lib/helpers-blog.rb +30 -63
  33. data/lib/helpers-repl.rb +3 -13
  34. data/lib/liveblog.rb +56 -42
  35. data/lib/lowlevel.rb +73 -0
  36. data/lib/publish.rb +6 -22
  37. data/lib/repl.rb +25 -16
  38. data/lib/runeblog.rb +46 -15
  39. data/lib/runeblog_version.rb +1 -17
  40. metadata +24 -16
  41. data/empty_view/remote/banner/austin-pano.jpg +0 -0
  42. data/empty_view/themes/standard/banner/faq.lt3 +0 -1
  43. data/lib/default.rb +0 -31
  44. data/lib/exper/callout.js +0 -10
  45. data/lib/exper/fbtw-js +0 -48
@@ -9,7 +9,7 @@ class ::RuneBlog::Widget
9
9
  def initialize(repo)
10
10
  @blog = repo
11
11
  @datafile = input = "list.data"
12
- @lines = File.readlines(input)
12
+ @lines = _get_data(@datafile)
13
13
  end
14
14
 
15
15
  def build
@@ -7,7 +7,7 @@ class ::RuneBlog::Widget
7
7
  def initialize(repo)
8
8
  @blog = repo
9
9
  @datafile = "list.data"
10
- lines = File.readlines(@datafile)
10
+ lines = _get_data(@datafile)
11
11
  @data = lines.map {|line| line.chomp.split(/, */) }
12
12
  end
13
13
 
@@ -4,12 +4,12 @@
4
4
 
5
5
  class ::RuneBlog::Widget
6
6
  class Pages
7
- Type, Title = "pages", "Pages"
7
+ Type, Title = "pages", "My Pages"
8
8
 
9
9
  def initialize(repo)
10
10
  @blog = repo
11
11
  @datafile = "list.data"
12
- @lines = File.readlines(@datafile)
12
+ @lines = _get_data(@datafile)
13
13
  @data = @lines.map {|x| x.chomp.split(/, */, 2) }
14
14
  end
15
15
 
@@ -7,7 +7,7 @@ class ::RuneBlog::Widget
7
7
  def initialize(repo)
8
8
  @blog = repo
9
9
  @datafile = "list.data"
10
- @lines = File.exist?(@datafile) ? File.readlines(@datafile) : []
10
+ @lines = _get_data?(@datafile)
11
11
  end
12
12
 
13
13
  def _html_body(file, css = nil) # FIXME
@@ -3,20 +3,15 @@ require 'fileutils'
3
3
 
4
4
  require 'processing'
5
5
 
6
- module RuneBlog::Helpers
6
+ require 'lowlevel'
7
7
 
8
- def copy(src, dst)
9
- log!(enter: __method__, args: [src, dst], level: 2)
10
- cmd = "cp #{src} #{dst} 2>/dev/null"
11
- rc = system!(cmd)
12
- puts " Failed: #{cmd} - from #{caller[0]}" unless rc
13
- end
8
+ module RuneBlog::Helpers
14
9
 
15
- def copy!(src, dst)
16
- log!(enter: __method__, args: [src, dst], level: 2)
17
- cmd = "cp -r #{src} #{dst} 2>/dev/null"
18
- rc = system!(cmd)
19
- puts " Failed: #{cmd} - from #{caller[0]}" unless rc
10
+ def quit_RubyText
11
+ return unless defined? RubyText
12
+ sleep 6
13
+ RubyText.stop
14
+ exit
20
15
  end
21
16
 
22
17
  def get_repo_config
@@ -31,11 +26,16 @@ module RuneBlog::Helpers
31
26
  end
32
27
 
33
28
  def copy_data(tag, dest)
34
- data = RuneBlog::Path + "/../data" # files kept inside gem
29
+ data = RuneBlog::Path + "/../data" # files kept inside gem
30
+ extra = RuneBlog::Path + "/../config" # files kept inside gem
31
+ # FIXME names are confusing
35
32
  case tag
36
- when :config; files = %w[ROOT VIEW EDITOR universal.lt3 global.lt3]
33
+ when :config
34
+ files = %w[ROOT VIEW EDITOR universal.lt3 global.lt3]
35
+ files.each {|file| copy(data + "/" + file, dest) }
36
+ when :extra
37
+ copy!(extra, dest)
37
38
  end
38
- files.each {|file| copy(data + "/" + file, dest) }
39
39
  end
40
40
 
41
41
  def read_vars(file)
@@ -54,8 +54,7 @@ module RuneBlog::Helpers
54
54
  puts "Can't read vars file '#{file}': #{err}"
55
55
  puts err.backtrace.join("\n")
56
56
  puts "dir = #{Dir.pwd}"
57
- sleep 6; RubyText.stop
58
- exit
57
+ stop_RubyText
59
58
  end
60
59
 
61
60
  def read_config(file, *syms)
@@ -81,8 +80,7 @@ module RuneBlog::Helpers
81
80
  puts "Can't read config file '#{file}': #{err}"
82
81
  puts err.backtrace.join("\n")
83
82
  puts "dir = #{Dir.pwd}"
84
- sleep 6; RubyText.stop
85
- exit
83
+ stop_RubyText
86
84
  end
87
85
 
88
86
  def try_read_config(file, hash)
@@ -100,32 +98,33 @@ module RuneBlog::Helpers
100
98
  end
101
99
  end
102
100
 
103
- def get_views # read from filesystem
101
+ def retrieve_views # read from filesystem
104
102
  log!(enter: __method__, level: 3)
105
103
  dirs = subdirs("#@root/views/").sort
106
104
  dirs.map {|name| RuneBlog::View.new(name) }
107
105
  end
108
106
 
109
- def write_repo_config(root: "#{Dir.pwd}/.blogs", view: "#{root}/data/VIEW", editor: "/usr/local/bin/vim")
107
+ def write_repo_config(root: "#{Dir.pwd}/.blogs", view: nil, editor: "/usr/local/bin/vim")
108
+ view ||= File.read("#{root}/data/VIEW").chomp rescue "[no view]"
110
109
  File.write(root + "/data/ROOT", root + "\n")
111
110
  File.write(root + "/data/VIEW", view.to_s + "\n")
112
111
  File.write(root + "/data/EDITOR", editor + "\n")
113
112
  end
114
113
 
115
- def new_dotfile(root: ".blogs", current_view: "test_view", editor: "vi")
116
- log!(enter: __method__, args: [root, current_view, editor], level: 3)
117
- root = Dir.pwd + "/" + root
118
- x = OpenStruct.new
119
- x.root, x.current_view, x.editor = root, current_view, editor
120
- write_config(x, root + "/" + RuneBlog::ConfigFile)
121
- write_repo_config
122
- end
114
+ # def new_dotfile(root: ".blogs", current_view: "test_view", editor: "vi")
115
+ # log!(enter: __method__, args: [root, current_view, editor], level: 3)
116
+ # root = Dir.pwd + "/" + root
117
+ # x = OpenStruct.new
118
+ # x.root, x.current_view, x.editor = root, current_view, editor
119
+ # write_config(x, root + "/" + RuneBlog::ConfigFile)
120
+ # write_repo_config
121
+ # end
123
122
 
124
123
  def new_sequence
125
124
  log!(enter: __method__, level: 3)
126
- dump(0, "sequence")
125
+ dump(0, "data/sequence")
127
126
  version_info = "#{RuneBlog::VERSION}\nBlog created: #{Time.now.to_s}"
128
- dump(version_info, "VERSION")
127
+ dump(version_info, "data/VERSION")
129
128
  end
130
129
 
131
130
  def subdirs(dir)
@@ -147,38 +146,6 @@ module RuneBlog::Helpers
147
146
  files
148
147
  end
149
148
 
150
- def create_dirs(*dirs)
151
- log!(enter: __method__, args: [*dirs], level: 3)
152
- dirs.each do |dir|
153
- dir = dir.to_s # symbols allowed
154
- next if Dir.exist?(dir)
155
- cmd = "mkdir -p #{dir} >/dev/null"
156
- result = system!(cmd)
157
- raise CantCreateDir(dir) unless result
158
- end
159
- end
160
-
161
- def interpolate(str, bind)
162
- log!(enter: __method__, args: [str, bind], level: 3)
163
- wrap = "<<-EOS\n#{str}\nEOS"
164
- eval wrap, bind
165
- end
166
-
167
- def error(err) # Hmm, this is duplicated
168
- log!(str: "duplicated method", enter: __method__, args: [err], level: 2)
169
- str = "\n Error: #{err}"
170
- puts str
171
- puts err.backtrace.join("\n")
172
- end
173
-
174
- def dump(obj, name)
175
- log!(enter: __method__, args: [obj, name], level: 3)
176
- File.write(name, obj)
177
- end
178
149
  end
179
150
 
180
- def dump(obj, name) # FIXME scope
181
- log!(str: "scope problem", enter: __method__, args: [obj, name], level: 3)
182
- File.write(name, obj)
183
- end
184
151
 
@@ -109,26 +109,16 @@ module RuneBlog::REPL
109
109
  end
110
110
  meth = found || :cmd_INVALID
111
111
  params = cmd if meth == :cmd_INVALID
112
- # puts "choose: #{[meth, params].inspect}"
113
112
  [meth, params]
114
113
  end
115
114
 
116
- def error(err) # Hmm, this is duplicated
117
- str = "\n Error: #{err}"
118
- puts str
119
- puts err.backtrace.join("\n")
120
- end
121
-
122
115
  def ask(prompt, meth = :to_s)
123
116
  print prompt
124
- str = gets
125
- str.chomp!
126
- str.send(meth)
117
+ gets.chomp.send(meth)
127
118
  end
128
119
 
129
- def yesno(prompt, meth = :to_s)
130
- print prompt
131
- gets.chomp.upcase[0] == "Y"
120
+ def ask!(prompt, meth = :to_s)
121
+ ask(fx(prompt, :bold), meth)
132
122
  end
133
123
 
134
124
  def reset_output(initial = "")
@@ -7,6 +7,9 @@ require 'runeblog'
7
7
  require 'pathmagic'
8
8
  require 'processing'
9
9
 
10
+ # top = Livetext::Path + "/../plugin/liveblog/"
11
+ # eval(File.read("#{top}/testing.rb"))
12
+
10
13
 
11
14
  def init_liveblog # FIXME - a lot of this logic sucks
12
15
  dir = Dir.pwd.sub(/\.blogs.*/, "")
@@ -42,23 +45,59 @@ def post
42
45
  _out " <!-- Post number #{@meta.num} -->\n "
43
46
  end
44
47
 
48
+ def _got_python?
49
+ # Dumb - fix later - check up front as needed
50
+ # Should also check for praw lib
51
+ str = `which python3`
52
+ str.length > 0
53
+ end
54
+
55
+ def _reddit_post_url(vdir, title, url)
56
+ _got_python?
57
+ tmpfile = "/tmp/reddit-post-url.txt"
58
+ File.open(tmpfile, "w") do |tmp|
59
+ tmp.puts "[Post] " + title
60
+ tmp.puts url
61
+ end
62
+ rid = nil
63
+ Dir.chdir(vdir/:config) { rid = `python3 reddit/reddit_post_url.py` }
64
+ system("rm #{tmpfile}")
65
+ rid # returns reddit id
66
+ end
67
+
45
68
  def post_trailer
46
69
  perma = _var("publish.proto") + "://" + _var("publish.server") +
47
- "/" + _var("publish.path") + "/permalink/" + _var("post.aslug") +
70
+ "/" + _var("publish.path") + "/" + _var("post.aslug") +
48
71
  ".html"
49
72
  tags = _var("post.tags")
50
- if tags.empty?
51
- taglist = ""
52
- else
53
- taglist = "Tags: #{tags}"
73
+ taglist = tags.empty? ? "" : "Tags: #{tags}"
74
+
75
+ reddit_enabled = false # FIXME
76
+ reddit_txt = ""
77
+ if reddit_enabled
78
+ vdir = @blog.root/:views/@blog.view
79
+ nslug = "#{_var("post.num")}-#{_var("post.aslug")}"
80
+ rid_file = vdir/:posts/nslug/"reddit.id"
81
+ rid = File.exist?(rid_file) ? File.read(rid_file).chomp : nil
82
+ if rid.nil?
83
+ title = _var("title")
84
+ rid = _reddit_post_url(vdir, title, perma)
85
+ dump(rid, rid_file)
86
+ end
87
+ reddit_txt = <<~HTML
88
+ <hr>
89
+ <script src='https://redditjs.com/post.js'
90
+ data-url="#{rid}" data-width=800 ></script>
91
+ HTML
92
+ # damned syntax highlighting </>
54
93
  end
55
94
  _out <<~HTML
56
95
  <table width=100%><tr>
57
96
  <td width=10%><a style="text-decoration: none" href="javascript:history.go(-1)">[Back]</a></td>
58
97
  <td width=10%><a style="text-decoration: none" href="#{perma}"> [permalink] </a></td>
59
98
  <td width=80% align=right><font size=-3>#{taglist}</font></td></tr></table>
99
+ #{reddit_txt}
60
100
  HTML
61
- # damned syntax highlighting
62
101
  end
63
102
 
64
103
  def faq
@@ -85,9 +124,10 @@ def code
85
124
  end
86
125
 
87
126
  def _read_navbar_data
88
- dir = @blog.root/:views/@blog.view/"themes/standard/banner/"
127
+ vdir = @blog.root/:views/@blog.view
128
+ dir = vdir/"themes/standard/banner/navbar/"
89
129
  datafile = dir/"list.data"
90
- File.readlines(datafile)
130
+ _get_data(datafile)
91
131
  end
92
132
 
93
133
  def banner
@@ -97,6 +137,7 @@ def banner
97
137
  high = 250
98
138
  str2 = ""
99
139
  navbar = nil
140
+ vdir = @blog.root/:views/@blog.view
100
141
  lines = _body.to_a
101
142
 
102
143
  lines.each do |line|
@@ -130,15 +171,9 @@ def banner
130
171
  end
131
172
  str2 << "<td>" + File.read(file) + "</td>" + "\n"
132
173
  when "navbar"
133
- dir = @blog.root/:views/@blog.view/"themes/standard/banner/" + "\n"
134
- _make_navbar # horiz is default
135
- file = "banner/navbar.html"
136
- navbar = File.read(file)
174
+ navbar = _make_navbar # horiz is default
137
175
  when "vnavbar"
138
- dir = @blog.root/:views/@blog.view/"themes/standard/banner/"
139
- _make_navbar(:vert)
140
- file = "banner/vnavbar.html"
141
- navbar = File.read(file)
176
+ navbar = _make_navbar(:vert)
142
177
  when "break"
143
178
  str2 << " </tr>\n <tr>" + "\n"
144
179
  else
@@ -347,7 +382,7 @@ def pin
347
382
  pinned.each do |pinview|
348
383
  dir = @blog.root/:views/pinview/"themes/standard/widgets/pinned/"
349
384
  datafile = dir/"list.data"
350
- pins = File.exist?(datafile) ? File.readlines(datafile) : []
385
+ pins = _get_data?(datafile)
351
386
  pins << "#{@meta.num} #{@meta.title}\n"
352
387
  pins.uniq!
353
388
  File.open(datafile, "w") {|out| pins.each {|pin| out.puts pin } }
@@ -502,22 +537,6 @@ rescue => err
502
537
  exit
503
538
  end
504
539
 
505
- # def pinned_rebuild
506
- # view = @blog.view
507
- # view = _args[0] unless _args.empty?
508
- # Dir.chdir(@blog.root/:views/view/"themes/standard/") do
509
- # wtag = "widgets/pinned"
510
- # code = _load_local("pinned")
511
- # if code
512
- # Dir.chdir(wtag) do
513
- # widget = code.new(@blog)
514
- # widget.build
515
- # end
516
- # # _include_file wtag/"pinned-card.html"
517
- # end
518
- # end
519
- # end
520
-
521
540
  def _handle_standard_widget(tag)
522
541
  wtag = :widgets/tag
523
542
  code = _load_local(tag)
@@ -688,20 +707,20 @@ def _make_navbar(orient = :horiz)
688
707
  </td></tr></table>
689
708
  HTML
690
709
 
691
- html_file = @blog.root/:views/@blog.view/"themes/standard/banner"/name
710
+ html_file = @blog.root/:views/@blog.view/"themes/standard/banner/navbar"/name
692
711
  output = File.new(html_file, "w")
693
712
  output.puts start
694
713
  lines = _read_navbar_data
695
714
  lines = ["index Home"] + lines unless _args.include?("nohome")
696
715
  lines.each do |line|
697
716
  basename, cdata = line.chomp.strip.split(" ", 2)
698
- full = :banner/basename+".html"
717
+ full = :banner/:navbar/basename+".html"
699
718
  href_main = _main(full)
700
719
  if basename == "index" # special case
701
720
  output.puts %[#{li1} <a class="nav-link" href="index.html">#{cdata}<span class="sr-only">(current)</span></a> #{li2}]
702
721
  else
703
- dir = @blog.root/:views/@blog.view/"themes/standard/banner"
704
- dest = vdir/"remote/banner"/basename+".html"
722
+ dir = @blog.root/:views/@blog.view/"themes/standard/banner/navbar"
723
+ dest = vdir/"remote/banner/navbar"/basename+".html"
705
724
  preprocess cwd: dir, src: basename, dst: dest, call: ".nopara" # , debug: true
706
725
  output.puts %[#{li1} <a class="nav-link" #{href_main}>#{cdata}</a> #{li2}]
707
726
  end
@@ -770,11 +789,6 @@ def _post_lookup(postid) # side-effect
770
789
  vp
771
790
  end
772
791
 
773
- def _interpolate(str, context) # FIXME move this later
774
- wrapped = "%[" + str.dup + "]" # could fail...
775
- eval(wrapped, context)
776
- end
777
-
778
792
  def _card_generic(card_title:, middle:, extra: "")
779
793
  front = <<-HTML
780
794
  <div class="card #{extra} mb-3">
@@ -0,0 +1,73 @@
1
+
2
+ def dump(obj, name)
3
+ File.write(name, obj)
4
+ end
5
+
6
+ def system!(str, show: false)
7
+ log!(enter: __method__, args: [str], level: 2)
8
+ STDERR.puts str if show
9
+ rc = system(str)
10
+ return rc if rc
11
+ STDERR.puts "FAILED: #{str.inspect}"
12
+ STDERR.puts "\ncaller = \n#{caller.join("\n ")}\n"
13
+ if defined?(RubyText)
14
+ sleep 6
15
+ RubyText.stop
16
+ exit
17
+ end
18
+ return rc
19
+ end
20
+
21
+ def _get_data?(file) # File need not exist
22
+ if File.exist?(file)
23
+ _get_data(file)
24
+ else
25
+ []
26
+ end
27
+ end
28
+
29
+ def _get_data(file)
30
+ lines = File.readlines(file)
31
+ lines.reject! {|line| line[0] == "-" } # allow rejection of lines
32
+ lines = lines.map do |line|
33
+ line.sub(/ *# .*$/, "") # allow trailing comments
34
+ end
35
+ lines
36
+ end
37
+
38
+ def copy(src, dst)
39
+ log!(enter: __method__, args: [src, dst], level: 2)
40
+ cmd = "cp #{src} #{dst} 2>/dev/null"
41
+ system!(cmd)
42
+ end
43
+
44
+ def copy!(src, dst)
45
+ log!(enter: __method__, args: [src, dst], level: 2)
46
+ cmd = "cp -r #{src} #{dst} 2>/dev/null"
47
+ system!(cmd)
48
+ end
49
+
50
+ def create_dirs(*dirs)
51
+ log!(enter: __method__, args: [*dirs], level: 3)
52
+ dirs.each do |dir|
53
+ dir = dir.to_s # symbols allowed
54
+ next if Dir.exist?(dir)
55
+ cmd = "mkdir -p #{dir} >/dev/null"
56
+ result = system!(cmd)
57
+ raise CantCreateDir(dir) unless result
58
+ end
59
+ end
60
+
61
+ def interpolate(str, bind)
62
+ log!(enter: __method__, args: [str, bind], level: 3)
63
+ wrap = "<<-EOS\n#{str}\nEOS"
64
+ eval wrap, bind
65
+ end
66
+
67
+ def error(err)
68
+ log!(str: err, enter: __method__, args: [err], level: 2)
69
+ str = "\n Error: #{err}"
70
+ puts str
71
+ puts err.backtrace.join("\n")
72
+ end
73
+