runeblog 0.2.2 → 0.2.8

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.
@@ -6,6 +6,7 @@ class RuneBlog::Default
6
6
  def RuneBlog.post_template(num: 0, title: "No title", date: nil, view: "test_view",
7
7
  teaser: "No teaser", body: "No body", tags: ["untagged"],
8
8
  views: [], back: "javascript:history.go(-1)", home: "no url")
9
+ log!(enter: __method__, args: [num, title, date, view, teaser, body, tags, views, back, home])
9
10
  viewlist = (views + [view.to_s]).join(" ")
10
11
  taglist = ".tags " + tags.join(" ")
11
12
  <<-TEXT
@@ -20,6 +20,7 @@ end
20
20
  # Refactor, move stuff elsewhere?
21
21
 
22
22
  def make_exception(sym, str)
23
+ log!(enter: __method__, args: [sym, str])
23
24
  return if Object.constants.include?(sym)
24
25
  Object.const_set(sym, StandardError.dup)
25
26
  define_method(sym) do |*args|
@@ -30,10 +31,12 @@ def make_exception(sym, str)
30
31
  end
31
32
 
32
33
  def prefix(num)
34
+ log!(enter: __method__, args: [num])
33
35
  "#{'%04d' % num.to_i}"
34
36
  end
35
37
 
36
38
  def check_meta(meta, where = "")
39
+ log!(enter: __method__, args: [meta, where])
37
40
  str = "--- #{where}\n"
38
41
  str << "\ncheck_meta: \n" + caller.join("\n") + "\n meta = #{meta.inspect}\n"
39
42
  str << " title missing!\n" unless meta.title
@@ -46,12 +49,14 @@ def check_meta(meta, where = "")
46
49
  end
47
50
 
48
51
  def verify(hash)
52
+ log!(enter: __method__, args: [hash])
49
53
  hash.each_pair do |expr, msg|
50
54
  puts "<< #{msg}" unless expr
51
55
  end
52
56
  end
53
57
 
54
58
  def assure(hash) # really the same as verify for now...
59
+ log!(enter: __method__, args: [hash])
55
60
  hash.each_pair do |expr, msg|
56
61
  puts "<< #{msg}" unless expr
57
62
  end
@@ -6,39 +6,52 @@ require 'fileutils'
6
6
  module RuneBlog::Helpers
7
7
 
8
8
  def copy(src, dst)
9
- if src =~ /\*/
10
- system("cp #{src} #{dst}")
11
- else
12
- FileUtils.cp(src, dst)
13
- end
9
+ log!(enter: __method__, args: [src, dst])
10
+ cmd = "cp #{src} #{dst} 2>/dev/null"
11
+ # puts "\n--- pwd = #{Dir.pwd} \n Trying: #{cmd}"
12
+ # if src =~ /\*/
13
+ rc = system(cmd)
14
+ puts " FROM #{caller[0]}" unless rc
15
+ exit unless rc
16
+ # else
17
+ # FileUtils.cp(src, dst)
18
+ # end
14
19
  end
15
20
 
16
21
  def copy!(src, dst)
17
- if src =~ /\*/
18
- system("cp -r #{src} #{dst}")
19
- else
20
- FileUtils.cp_r(src, dst)
21
- end
22
+ log!(enter: __method__, args: [src, dst])
23
+ cmd = "cp -r #{src} #{dst} 2>/dev/null"
24
+ # puts "\n--- pwd = #{Dir.pwd} \n Trying: #{cmd}"
25
+ # if src =~ /\*/
26
+ rc = system(cmd)
27
+ puts " FROM #{caller[0]}" unless rc
28
+ exit unless rc
29
+ # else
30
+ # FileUtils.cp_r(src, dst)
31
+ # end
22
32
  end
23
33
 
24
34
  def stale?(src, dst)
35
+ log!(enter: __method__, args: [src, dst])
25
36
  return true unless File.exist?(dst)
26
37
  return true if File.mtime(src) > File.mtime(dst)
27
38
  return false
28
39
  end
29
40
 
30
41
  def livetext(src, dst=nil)
42
+ log!(enter: __method__, args: [src, dst])
31
43
  src << ".lt3" unless src.end_with?(".lt3")
32
44
  if dst
33
45
  dst << ".html" unless dst.end_with?(".html")
34
46
  else
35
47
  dst = src.sub(/.lt3$/, "")
36
48
  end
37
- return unless stale?(src, dst)
49
+ # return unless stale?(src, dst)
38
50
  system("livetext #{src} >#{dst}")
39
51
  end
40
52
 
41
53
  def get_root
54
+ log!(enter: __method__)
42
55
  if $_blog
43
56
  if $_blog.root
44
57
  puts "0. Returned: #{$_blog.root}/"
@@ -54,7 +67,7 @@ module RuneBlog::Helpers
54
67
  end
55
68
 
56
69
  def read_config(file, *syms)
57
- # puts "dir = #{Dir.pwd}"
70
+ log!(enter: __method__, args: [file, *syms])
58
71
  lines = File.readlines(file).map(&:chomp)
59
72
  obj = ::OpenStruct.new
60
73
  lines.each do |line|
@@ -79,6 +92,7 @@ module RuneBlog::Helpers
79
92
  end
80
93
 
81
94
  def try_read_config(file, hash)
95
+ log!(enter: __method__, args: [file, hash])
82
96
  return hash.values unless File.exist?(file)
83
97
  vals = read_config(file, *hash.keys)
84
98
  # STDERR.puts vals.inspect
@@ -86,6 +100,7 @@ module RuneBlog::Helpers
86
100
  end
87
101
 
88
102
  def put_config(root:, view:"test_view", editor: "/usr/local/bin/vim")
103
+ log!(enter: __method__, args: [root, view, editor])
89
104
  Dir.mkdir(root) unless Dir.exist?(root)
90
105
  Dir.chdir(root) do
91
106
  File.open("config", "w") do |cfg|
@@ -97,6 +112,7 @@ def put_config(root:, view:"test_view", editor: "/usr/local/bin/vim")
97
112
  end
98
113
 
99
114
  def write_config(obj, file)
115
+ log!(enter: __method__, args: [obj, file])
100
116
  hash = obj.to_h
101
117
  # Dir.chdir(::Home)
102
118
  # puts "--- wc: pwd = #{Dir.pwd}"
@@ -108,6 +124,7 @@ end
108
124
  end
109
125
 
110
126
  def get_views # read from filesystem
127
+ log!(enter: __method__)
111
128
  # Dir.chdir(::Home) do
112
129
  verify(@root => "#@root is nil",
113
130
  Dir.exist?(@root) => "#@root doesn't exist",
@@ -118,6 +135,7 @@ end
118
135
  end
119
136
 
120
137
  def new_dotfile(root: ".blogs", current_view: "test_view", editor: "vi")
138
+ log!(enter: __method__, args: [root, current_view, editor])
121
139
  # raise BlogAlreadyExists if Dir.exist?(".blogs")
122
140
  # Dir.mkdir(".blogs")
123
141
  root = Dir.pwd + "/" + root
@@ -127,12 +145,14 @@ end
127
145
  end
128
146
 
129
147
  def new_sequence
148
+ log!(enter: __method__)
130
149
  dump(0, "sequence")
131
150
  version_info = "#{RuneBlog::VERSION}\nBlog created: #{Time.now.to_s}"
132
151
  dump(version_info, "VERSION")
133
152
  end
134
153
 
135
154
  def subdirs(dir)
155
+ log!(enter: __method__, args: [dir])
136
156
  verify(Dir.exist?(dir) => "Directory #{dir} not found")
137
157
  dirs = Dir.entries(dir) - %w[. ..]
138
158
  dirs.reject! {|x| ! File.directory?("#@root/views/#{x}") }
@@ -140,6 +160,7 @@ end
140
160
  end
141
161
 
142
162
  def find_draft_slugs
163
+ log!(enter: __method__)
143
164
  verify(@root => "#@root is nil",
144
165
  Dir.exist?(@root) => "#@root doesn't exist",
145
166
  Dir.exist?("#@root/drafts") => "#@root/drafts doesn't exist")
@@ -154,6 +175,7 @@ end
154
175
  end
155
176
 
156
177
  def create_dirs(*dirs)
178
+ log!(enter: __method__, args: [*dirs])
157
179
  dirs.each do |dir|
158
180
  dir = dir.to_s # symbols allowed
159
181
  next if Dir.exist?(dir)
@@ -163,24 +185,28 @@ end
163
185
  end
164
186
  end
165
187
 
166
- def interpolate(str, binding)
188
+ def interpolate(str, bind)
189
+ log!(enter: __method__, args: [str, bind])
167
190
  wrap = "<<-EOS\n#{str}\nEOS"
168
- eval wrap, binding
191
+ eval wrap, bind
169
192
  end
170
193
 
171
194
  def error(err) # Hmm, this is duplicated
195
+ log!(str: "duplicated method", enter: __method__, args: [err])
172
196
  str = "\n Error: #{err}"
173
197
  puts str
174
198
  puts err.backtrace.join("\n")
175
199
  end
176
200
 
177
201
  def dump(obj, name)
202
+ log!(enter: __method__, args: [obj, name])
178
203
  File.write(name, obj)
179
204
  end
180
205
 
181
206
  end
182
207
 
183
208
  def dump(obj, name) # FIXME scope
209
+ log!(str: "scope problem", enter: __method__, args: [obj, name])
184
210
  File.write(name, obj)
185
211
  end
186
212
 
@@ -410,15 +410,20 @@ def meta
410
410
  end
411
411
 
412
412
  def recent_posts # side-effect
413
- _out %[<div class="col-lg-9 col-md-9 col-sm-9 col-xs-12">]
414
- all_teasers
415
- _out %[</div>]
413
+ _out <<-HTML
414
+ <div class="col-lg-9 col-md-9 col-sm-9 col-xs-12">
415
+ <iframe id="main" style="width: 100vw; height: 100vh; position: relative;"
416
+ src='recent.html' width=100% frameborder="0" allowfullscreen>
417
+ </iframe>
418
+ </div>
419
+ HTML
416
420
  end
417
421
 
418
422
  def sidebar
419
423
  _out %[<div class="col-lg-3 col-md-3 col-sm-3 col-xs-12">]
420
424
  _args do |token|
421
425
  tag = token.chomp.strip.downcase
426
+ # Doesn't handle "split personality" widgets yet
422
427
  Dir.chdir("widgets/#{tag}") do
423
428
  livetext tag, "card-#{tag}.html"
424
429
  _include_file "card-#{tag}.html"
@@ -443,59 +448,43 @@ def script
443
448
  _out %[<script src="#{url}" integrity="#{integ}" crossorigin="#{cross}"></script>]
444
449
  end
445
450
 
446
-
447
- ### How this next bit works:
448
- ###
449
- ### all_teasers will call _find_recent_posts
450
- ###
451
- ### _find_recent_posts will search higher in the directory structure
452
- ### for where the posts are (0001, 0002, ...) NOTE: This implies you
453
- ### must be in some specific place when this code is run.
454
- ### It returns the 20 most recent posts.
455
- ###
456
- ### all_teasers will then pick a small number of posts and call _teaser
457
-
458
- ### on each one. (The code in _teaser really belongs in a small template
459
- ### somewhere.)
460
- ###
461
-
462
- def _find_recent_posts
463
- @vdir = _var(:FileDir).match(%r[(^.*/views/.*?)/])[1]
464
- posts = nil
465
- dir_posts = @vdir + "/posts"
466
- entries = Dir.entries(dir_posts)
467
- posts = entries.grep(/^\d\d\d\d/).map {|x| dir_posts + "/" + x }
468
- posts.select! {|x| File.directory?(x) }
469
- # directories that start with four digits
470
- posts = posts.sort {|a, b| b.to_i <=> a.to_i } # sort descending
471
- posts[0..19] # return 20 at most
472
- end
473
-
474
- def all_teasers
475
- open = <<-HTML
476
- <section class="posts">
477
- HTML
478
- close = <<-HTML
479
- </section>
480
- HTML
481
-
482
- text = <<-HTML
483
- <html>
484
- <head><link rel="stylesheet" href="etc/blog.css"></head>
485
- <body>
486
- HTML
487
- posts = _find_recent_posts
488
- wanted = [5, posts.size].min # estimate how many we want?
489
- enum = posts.each
490
- wanted.times do
491
- postid = File.basename(enum.next)
492
- postid = postid.to_i
493
- text << _teaser(postid) # side effect! calls _out
494
- end
495
- text << "</body></html>"
496
- File.write("recent.html", text)
497
- _out %[<iframe id="main" style="width: 100vw; height: 100vh; position: relative;" src='recent.html' width=100% frameborder="0" allowfullscreen></iframe>]
498
- end
451
+ # def _find_recent_posts
452
+ # @vdir = _var(:FileDir).match(%r[(^.*/views/.*?)/])[1]
453
+ # posts = nil
454
+ # dir_posts = @vdir + "/posts"
455
+ # entries = Dir.entries(dir_posts)
456
+ # posts = entries.grep(/^\d\d\d\d/).map {|x| dir_posts + "/" + x }
457
+ # posts.select! {|x| File.directory?(x) }
458
+ # # directories that start with four digits
459
+ # posts = posts.sort {|a, b| b.to_i <=> a.to_i } # sort descending
460
+ # posts[0..19] # return 20 at most
461
+ # end
462
+ #
463
+ # def all_teasers
464
+ # open = <<-HTML
465
+ # <section class="posts">
466
+ # HTML
467
+ # close = <<-HTML
468
+ # </section>
469
+ # HTML
470
+ #
471
+ # text = <<-HTML
472
+ # <html>
473
+ # <head><link rel="stylesheet" href="etc/blog.css"></head>
474
+ # <body>
475
+ # HTML
476
+ # posts = _find_recent_posts
477
+ # wanted = [5, posts.size].min # estimate how many we want?
478
+ # enum = posts.each
479
+ # wanted.times do
480
+ # postid = File.basename(enum.next)
481
+ # postid = postid.to_i
482
+ # text << _teaser(postid) # side effect! calls _out
483
+ # end
484
+ # text << "</body></html>"
485
+ # File.write("recent.html", text)
486
+ # _out %[<iframe id="main" style="width: 100vw; height: 100vh; position: relative;" src='recent.html' width=100% frameborder="0" allowfullscreen></iframe>]
487
+ # end
499
488
 
500
489
  def _post_lookup(postid) # side-effect
501
490
  # .. = templates, ../.. = views/thisview
@@ -517,21 +506,21 @@ def _interpolate(str, context) # FIXME move this later
517
506
  eval(wrapped, context)
518
507
  end
519
508
 
520
- def _teaser(slug)
521
- id = slug.to_i
522
- text = nil
523
- post_entry_name = @theme + "blog/post_entry.lt3"
524
- @_post_entry ||= File.read(post_entry_name)
525
- vp = _post_lookup(id)
526
- nslug, aslug, title, date, teaser_text =
527
- vp.nslug, vp.aslug, vp.title, vp.date, vp.teaser_text
528
- path = vp.path
529
- url = "#{path}/#{aslug}.html" # Should be relative to .blogs!! FIXME
530
- date = Date.parse(date)
531
- date = date.strftime("%B %e<br>%Y")
532
- text = _interpolate(@_post_entry, binding)
533
- text
534
- end
509
+ # def _teaser(slug)
510
+ # id = slug.to_i
511
+ # text = nil
512
+ # post_entry_name = @theme + "blog/post_entry.lt3"
513
+ # @_post_entry ||= File.read(post_entry_name)
514
+ # vp = _post_lookup(id)
515
+ # nslug, aslug, title, date, teaser_text =
516
+ # vp.nslug, vp.aslug, vp.title, vp.date, vp.teaser_text
517
+ # path = vp.path
518
+ # url = "#{path}/#{aslug}.html" # Should be relative to .blogs!! FIXME
519
+ # date = Date.parse(date)
520
+ # date = date.strftime("%B %e<br>%Y")
521
+ # text = _interpolate(@_post_entry, binding)
522
+ # text
523
+ # end
535
524
 
536
525
  def _card_generic(card_title:, middle:, extra: "")
537
526
  front = <<-HTML
@@ -0,0 +1,58 @@
1
+ unless self.respond_to?("log!")
2
+ $logging = true
3
+ $log = File.new("/tmp/runeblog.log","w")
4
+
5
+ def log!(str: "", enter: nil, args: [], pwd: false, dir: false)
6
+ return unless $logging
7
+ time = Time.now.strftime("%H:%M:%S")
8
+
9
+ meth = ""
10
+ meth = "#{enter}" if enter
11
+
12
+ para = "(#{args.inspect[1..-2]})"
13
+
14
+ source = caller[0].sub(/.*\//, " in ").sub(/:/, " line ").sub(/:.*/, "")
15
+ source = "in #{source} (probably liveblog.rb)" if source.include? "(eval)"
16
+
17
+ str = " ... #{str}" unless str.empty?
18
+ indent = " "*12
19
+
20
+ $log.puts "#{time} #{meth}#{para}"
21
+ $log.puts "#{indent} #{str} " unless str.empty?
22
+ $log.puts "#{indent} #{source}"
23
+ $log.puts "#{indent} pwd = #{Dir.pwd} " if pwd
24
+ if dir
25
+ files = (Dir.entries('.') - %w[. ..]).join(" ")
26
+ $log.puts "#{indent} dir/* = #{files}"
27
+ end
28
+ # $log.puts "#{indent} livetext params = #{livedata.inpect} " unless livedata.nil?
29
+ $log.puts
30
+ $log.close
31
+ $log = File.new("/tmp/runeblog.log","a")
32
+ end
33
+
34
+ # def log(str: "", enter: nil, args: [], pwd: false, dir: false)
35
+ # return unless $logging
36
+ # time = Time.now.strftime("%H:%M:%S")
37
+ # meth = ""
38
+ # meth = "#{enter}" if enter
39
+ # para = " args: #{args.inspect[1..-2]}"
40
+ # source = caller[0].sub(/.*\//, " in ").sub(/:/, " line ").sub(/:.*/, "")
41
+ # source = " in #{source} (probably liveblog.rb)" if source.include? "(eval)"
42
+ # str = " ... #{str}" unless str.empty?
43
+ # indent = " "*12
44
+ # STDERR.puts "#{time} #{str} #{meth}"
45
+ # STDERR.puts "#{indent} #{source}"
46
+ # STDERR.puts "#{indent} pwd = #{Dir.pwd} " if pwd
47
+ # if dir
48
+ # files = (Dir.entries('.') - %w[. ..]).join(" ")
49
+ # STDERR.puts "#{indent} dir/* = #{files}"
50
+ # end
51
+ # STDERR.puts "#{indent} #{para} " unless args.empty?
52
+ # # STDERR.puts "#{indent} livetext params = #{livedata.inpect} " unless livedata.nil?
53
+ # STDERR.puts
54
+ # # $log.close
55
+ # # $log = File.new("/tmp/runeblog.log","a")
56
+ # end
57
+ end
58
+
@@ -11,12 +11,14 @@ class RuneBlog::Post
11
11
  include RuneBlog::Helpers
12
12
 
13
13
  def self.files(num, root)
14
+ log!(enter: __method__, args: [num, root])
14
15
  files = Find.find(root).to_a
15
16
  result = files.grep(/#{prefix(num)}-/)
16
17
  result
17
18
  end
18
19
 
19
20
  def self.load(post)
21
+ log!(enter: __method__, args: [post])
20
22
  raise "Doesn't work right now"
21
23
  raise NoBlogAccessor if RuneBlog.blog.nil?
22
24
  # "post" is a slug
@@ -41,6 +43,7 @@ class RuneBlog::Post
41
43
  end
42
44
 
43
45
  def write_metadata(meta) # FIXME ???
46
+ log!(enter: __method__, args: [meta])
44
47
  debug "=== write_metadata:"
45
48
  debug "-----\n#{meta.inspect}\n-----"
46
49
  fname2 = "metadata.txt"
@@ -63,12 +66,14 @@ class RuneBlog::Post
63
66
  end
64
67
 
65
68
  def initialize
69
+ log!(enter: __method__)
66
70
  @blog = RuneBlog.blog || raise(NoBlogAccessor)
67
71
  @meta = OpenStruct.new
68
72
  end
69
73
 
70
74
  def self.create(title:, teaser:, body:, pubdate: Time.now.strftime("%Y-%m-%d"),
71
75
  other_views:[])
76
+ log!(enter: __method__, args: [title, teaser, body, pubdate, other_views])
72
77
  post = self.new
73
78
  # ONLY place next_sequence is called!
74
79
  num = post.meta.num = post.blog.next_sequence
@@ -97,6 +102,7 @@ class RuneBlog::Post
97
102
  end
98
103
 
99
104
  def edit
105
+ log!(enter: __method__)
100
106
  verify(File.exist?(@draft) => "File #{@draft} not found")
101
107
  result = system("vi #@draft +8") # TODO improve this
102
108
  raise EditorProblem(draft) unless result
@@ -106,6 +112,7 @@ class RuneBlog::Post
106
112
  end
107
113
 
108
114
  def build
115
+ log!(enter: __method__)
109
116
  post = self
110
117
  views = post.meta.views
111
118
  text = File.read(@draft)
@@ -118,6 +125,7 @@ class RuneBlog::ViewPost
118
125
  :teaser_text
119
126
 
120
127
  def initialize(view, postdir)
128
+ log!(enter: __method__, args: [view, postdir])
121
129
  # Assumes already parsed/processed
122
130
  @blog = RuneBlog.blog || raise(NoBlogAccessor)
123
131
  @path = postdir.dup
@@ -133,6 +141,7 @@ class RuneBlog::ViewPost
133
141
  end
134
142
 
135
143
  def get_dirs
144
+ log!(enter: __method__, args: [view, postdir])
136
145
  fname = File.basename(draft)
137
146
  noext = fname.sub(/.lt3$/, "")
138
147
  vdir = "#@root/views/#{view}"