runeblog 0.3.05 → 0.3.06

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4c6fa9176107c58120ebb4753221228bfe0d031f08f21a20dc2f7f86d6b2c6af
4
- data.tar.gz: c3bf5183cbeddb2cc3c9022695fcd9aa9ba50cf0e5364afd4632fac8a837e315
3
+ metadata.gz: 70bd6e1889a61c19c606616bcb0a4ace993b9f7cb7c993a9e4c2c41e7f47a7f9
4
+ data.tar.gz: c178b2630acfadbeddbbd51dc050bf41cf636372421fdda3b9003991f31c2b26
5
5
  SHA512:
6
- metadata.gz: 0bb8f0fb6b1a59ac69eabdcb0c50a20bf20308e4155fb1d305be5a19ab8eece7ffa7aecdbff3d4cfc48000dbbb891c3a2777068608a1e28750d8751b39a39af8
7
- data.tar.gz: 113a34a9fba90a9f8b9d9bc47cab433b00359a0c8f159b8fbf807e7609b50056ebf4e0e368d6b369256083a7a6c25316dd2c710297ea4bbccfa7fadd85bbf458
6
+ metadata.gz: 6c736c15fe20f800cc6393e5ad008983c0cb15eb2e90b1db60ac02361fb3ff65fc526266009d15f9ab1b99324055388bf52c9d487101e2ce6ce3dab1f3b1ba97
7
+ data.tar.gz: 7eb2bc828f8969fd15524ec4a010de4ecda475e636dc6fd0b8e4cbc0736def5aaf504db801440059644d1080423807f5abc078e79047d9b19cb8c4b79e336e26
@@ -22,16 +22,10 @@ module RuneBlog::Helpers
22
22
  dir = @root/:views/self.view/:settings
23
23
  end
24
24
  file = dir/"features.txt"
25
- lines = File.readlines(file)
26
- lines.each do |line|
27
- line = line.strip
28
- line.sub!(/ #.*/, "") # trailing
29
- next if line =~ /^ *#/ # leading
30
- next if line.empty?
31
- name, status = line.split
32
- hash[name] = (status == "1") # enabled
33
- end
34
- @features = hash
25
+ pairs = read_pairs(file)
26
+ enabled = {}
27
+ pairs.each {|k,v| enabled[k] = (v == "1") }
28
+ @features = enabled
35
29
  end
36
30
 
37
31
  def get_repo_config
@@ -72,47 +66,6 @@ module RuneBlog::Helpers
72
66
  stop_RubyText rescue nil
73
67
  end
74
68
 
75
- def read_config(file, *syms)
76
- log!(enter: __method__, args: [file, *syms], level: 3)
77
- lines = File.readlines(file).map(&:chomp)
78
- obj = ::OpenStruct.new
79
- skip = ["\n", "#", "."]
80
- lines.each do |line|
81
- next if skip.include?(line[0])
82
- key, val = line.split(/: +/, 2)
83
- obj.send(key+"=", val)
84
- end
85
- return obj if syms.empty?
86
-
87
- vals = []
88
- if syms.empty?
89
- vals = obj.to_hash.values
90
- else
91
- syms.each {|sym| vals << obj.send(sym) }
92
- end
93
- return vals
94
- rescue => err
95
- puts "Can't read config file '#{file}': #{err}"
96
- puts err.backtrace.join("\n")
97
- puts "dir = #{Dir.pwd}"
98
- stop_RubyText
99
- end
100
-
101
- def try_read_config(file, hash)
102
- log!(enter: __method__, args: [file, hash], level: 3)
103
- return hash.values unless File.exist?(file)
104
- vals = read_config(file, *hash.keys)
105
- vals
106
- end
107
-
108
- def write_config(obj, file)
109
- log!(enter: __method__, args: [obj, file], level: 2)
110
- hash = obj.to_h
111
- File.open(file, "w") do |out|
112
- hash.each_pair {|key, val| out.puts "#{key}: #{val}" }
113
- end
114
- end
115
-
116
69
  def retrieve_views # read from filesystem
117
70
  log!(enter: __method__, level: 3)
118
71
  dirs = subdirs("#@root/views/").sort
@@ -775,9 +775,9 @@ end
775
775
  def _write_metadata
776
776
  File.write("teaser.txt", @meta.teaser)
777
777
  fields = [:num, :title, :date, :pubdate, :views, :tags, :pinned]
778
- fname2 = "metadata.txt"
779
- f2 = File.open(fname2, "w") do |f2|
780
- fields.each {|fld| f2.puts "#{fld}: #{@meta.send(fld)}" }
778
+ fname = "metadata.txt"
779
+ File.open(fname, "w") do |f|
780
+ fields.each {|fld| f.puts "#{'%8s' % fld} #{@meta.send(fld)}" }
781
781
  end
782
782
  end
783
783
 
@@ -789,9 +789,8 @@ def _post_lookup(postid) # side-effect
789
789
  posts = Dir.entries(dir_posts).grep(/^\d\d\d\d/).map {|x| dir_posts/x }
790
790
  posts.select! {|x| File.directory?(x) }
791
791
 
792
- post = posts.select {|x| File.basename(x).to_i == postid }
793
- raise "Error: More than one post #{postid}" if post.size > 1
794
- postdir = post.first
792
+ posts = posts.select {|x| File.basename(x).to_i == postid }
793
+ postdir = exactly_one(posts)
795
794
  vp = RuneBlog::ViewPost.new(@blog.view, postdir)
796
795
  vp
797
796
  end
@@ -2,7 +2,7 @@
2
2
  def _tmp_error(err)
3
3
  out = "/tmp/blog#{rand(100)}.txt"
4
4
  File.open(out, "w") do |f|
5
- f.puts err + "\n--------"
5
+ f.puts err.to_s + "\n--------"
6
6
  f.puts err.backtrace.join("\n")
7
7
  end
8
8
  puts "Error: See #{out}"
@@ -28,22 +28,40 @@
28
28
  end
29
29
 
30
30
  def _get_data?(file) # File need not exist
31
- if File.exist?(file)
32
- _get_data(file)
33
- else
34
- []
35
- end
31
+ File.exist?(file) ? _get_data(file) : []
36
32
  end
37
33
 
38
34
  def _get_data(file)
39
35
  lines = File.readlines(file)
40
- lines.reject! {|line| line[0] == "-" } # allow rejection of lines
41
36
  lines = lines.map do |line|
42
- line.sub(/ *# .*$/, "") # allow trailing comments
37
+ line = line.chomp.strip
38
+ line.sub(/ *# .*$/, "") # allow leading/trailing comments
43
39
  end
40
+ lines.reject! {|x| x.empty? }
44
41
  lines
45
42
  end
46
43
 
44
+ def read_pairs(file) # returns a hash
45
+ lines = _get_data(file)
46
+ hash = {}
47
+ lines.each do |line|
48
+ key, val = line.split(" ", 2)
49
+ hash[key] = val
50
+ end
51
+ hash
52
+ end
53
+
54
+ def read_pairs!(file) # returns an openstruct
55
+ lines = _get_data(file)
56
+ obj = OpenStruct.new
57
+ lines.each do |line|
58
+ key, val = line.split(" ", 2)
59
+ val ||= ""
60
+ obj.send("#{key}=", val)
61
+ end
62
+ obj
63
+ end
64
+
47
65
  def copy(src, dst)
48
66
  log!(enter: __method__, args: [src, dst], level: 2)
49
67
  cmd = "cp #{src} #{dst} 2>/dev/null"
@@ -74,9 +92,15 @@
74
92
  end
75
93
 
76
94
  def error(err)
77
- log!(str: err, enter: __method__, args: [err], level: 2)
95
+ # log!(str: err, enter: __method__, args: [err], level: 2)
78
96
  str = "\n Error: #{err}"
79
97
  puts str
80
98
  puts err.backtrace.join("\n")
81
99
  end
82
100
 
101
+ def exactly_one(list)
102
+ raise "List: Zero instances" if list.empty?
103
+ raise "List: More than one instance" if list.size > 1
104
+ list.first
105
+ end
106
+
@@ -13,41 +13,20 @@ class RuneBlog::Post
13
13
  log!(enter: __method__, args: [post], level: 3)
14
14
  raise "Doesn't work right now"
15
15
  raise NoBlogAccessor if RuneBlog.blog.nil?
16
- # "post" is a slug
16
+ # "post" is a slug?
17
17
  pdir = RuneBlog.blog.root/:drafts/post
18
18
  meta = nil
19
19
  Dir.chdir(pdir) do
20
- meta = read_config("metadata.txt")
21
- meta.date = Date.parse(meta.date)
22
- meta.views = meta.views.split
23
- meta.tags = meta.tags.split
24
- meta.teaser = File.read("teaser.txt")
20
+ # meta = read_config("metadata.txt")
21
+ # meta.date = Date.parse(meta.date)
22
+ # meta.views = meta.views.split
23
+ # meta.tags = meta.tags.split
24
+ # meta.teaser = File.read("teaser.txt")
25
25
  # meta.body = File.read("body.txt")
26
26
  end
27
27
  meta
28
28
  end
29
29
 
30
- def write_metadata(meta) # FIXME ???
31
- log!(enter: __method__, args: [meta], level: 3)
32
- debug "=== write_metadata:"
33
- debug "-----\n#{meta.inspect}\n-----"
34
- fname2 = "metadata.txt"
35
- hash = meta.to_h
36
-
37
- File.write("teaser.txt", hash[:teaser])
38
- hash.delete(:teaser)
39
- hash.delete(:body)
40
-
41
- hash[:views] = hash[:views].join(" ")
42
- hash[:tags] = hash[:tags].join(" ")
43
-
44
- fields = [:num, :title, :date, :pubdate, :views, :tags]
45
-
46
- f2 = File.new(fname2, "w")
47
- fields.each {|fld| f2.puts "#{fld}: #{hash[fld]}" }
48
- f2.close
49
- end
50
-
51
30
  def initialize
52
31
  log!(enter: __method__, level: 3)
53
32
  @blog = RuneBlog.blog || raise(NoBlogAccessor)
@@ -87,10 +66,9 @@ class RuneBlog::Post
87
66
  end
88
67
 
89
68
  def edit
90
- log!(enter: __method__)
91
- result = system!("vi #@draft +8") # TODO improve this
92
- raise EditorProblem(draft) unless result
93
- nil
69
+ # log!(enter: __method__)
70
+ edit_file(@draft, vim: "+8")
71
+ build
94
72
  rescue => err
95
73
  error(err)
96
74
  end
@@ -99,8 +77,8 @@ class RuneBlog::Post
99
77
  log!(enter: __method__)
100
78
  post = self
101
79
  views = post.meta.views
102
- text = File.read(@draft)
103
80
  @blog.generate_post(@draft)
81
+ @blog.generate_index(@blog.view)
104
82
  end
105
83
  end
106
84
 
@@ -184,12 +162,12 @@ class RuneBlog::ViewPost
184
162
  @aslug = @nslug[5..-1]
185
163
  fname = "#{postdir}/teaser.txt" # ???
186
164
  @teaser_text = File.read(fname).chomp
187
- # FIXME dumb hacks...
188
- mdfile = postdir/"metadata.txt"
189
- lines = File.readlines(mdfile)
190
- @title = lines.grep(/title:/).first[7..-1].chomp
191
- @date = lines.grep(/pubdate:/).first[9..-1].chomp
192
- # print "-- date = #{@date.inspect} "; gets
165
+
166
+ Dir.chdir(postdir) do
167
+ meta = @blog.read_metadata
168
+ @title = meta.title
169
+ @date = meta.pubdate
170
+ end
193
171
  rescue => err
194
172
  STDERR.puts "--- #{err}\n #{err.backtrace.join("\n ")}"
195
173
  end
@@ -8,31 +8,31 @@ make_exception(:EditorProblem, "Could not edit $1")
8
8
 
9
9
  module RuneBlog::REPL
10
10
  def edit_file(file, vim: "")
11
- STDSCR.saveback
11
+ # STDSCR.saveback
12
12
  ed = @blog.editor
13
13
  params = vim if ed =~ /vim$/
14
14
  result = system!("#{@blog.editor} #{file} #{params}")
15
15
  raise EditorProblem(file) unless result
16
- STDSCR.restback
16
+ # STDSCR.restback
17
17
  cmd_clear
18
18
  end
19
19
 
20
20
  def cmd_quit
21
21
  STDSCR.rows.times { puts " "*(STDSCR.cols-1) }
22
22
  # FIXME please?
23
- sleep 0.1
23
+ # sleep 0.1
24
24
  STDSCR.clear
25
25
  sleep 0.1
26
26
  RubyText.stop
27
27
  sleep 0.1
28
28
  system("clear")
29
- sleep 0.1
29
+ # sleep 0.1
30
30
  exit
31
31
  end
32
32
 
33
33
  def cmd_clear
34
34
  STDSCR.rows.times { puts " "*(STDSCR.cols-1) }
35
- sleep 0.1
35
+ # sleep 0.1
36
36
  STDSCR.clear
37
37
  end
38
38
 
@@ -223,9 +223,9 @@ module RuneBlog::REPL
223
223
  def cmd_rebuild
224
224
  debug "Starting cmd_rebuild..."
225
225
  puts
226
+ regen_posts
226
227
  @blog.generate_view(@blog.view)
227
228
  @blog.generate_index(@blog.view)
228
- regen_posts
229
229
  rescue => err
230
230
  _tmp_error(err)
231
231
  end
@@ -301,22 +301,8 @@ module RuneBlog::REPL
301
301
  tag = "#{'%04d' % id}"
302
302
  files = ::Find.find(@blog.root/:drafts).to_a
303
303
  files = files.grep(/#{tag}-.*lt3/)
304
- files = files.map {|f| File.basename(f) }
305
- if files.size > 1
306
- msg = "Multiple files: #{files}"
307
- puts msg
308
- return [false, msg]
309
- end
310
- if files.empty?
311
- msg = "\n Can't edit post #{id}"
312
- puts msg
313
- return [false, msg]
314
- end
315
-
316
- file = files.first
317
- draft = @blog.root/:drafts/file
318
- vim_params = '-c G'
319
- result = edit_file(draft)
304
+ draft = exactly_one(files)
305
+ result = edit_file(draft, vim: '-c$')
320
306
  @blog.generate_post(draft)
321
307
  rescue => err
322
308
  _tmp_error(err)
@@ -189,11 +189,20 @@ class RuneBlog
189
189
  _generate_settings
190
190
  end
191
191
 
192
+ # FIXME reconcile with _get_draft data
193
+
194
+ def read_metadata
195
+ meta = read_pairs!("metadata.txt")
196
+ meta.views = meta.views.split
197
+ meta.tags = meta.tags.split
198
+ meta
199
+ end
200
+
192
201
  def _deploy_local(dir)
193
202
  log!(enter: __method__, args: [dir], level: 1)
194
203
  Dir.chdir(dir) do
195
- views = _retrieve_metadata(:views)
196
- views.each do |v|
204
+ meta = read_metadata
205
+ meta.views.each do |v|
197
206
  next unless _check_view?(v)
198
207
  system!("cp *html #@root/views/#{v}/remote", show: true)
199
208
  end
@@ -202,33 +211,6 @@ class RuneBlog
202
211
  _tmp_error(err)
203
212
  end
204
213
 
205
- # FIXME reconcile with _get_draft data
206
-
207
- def _retrieve_metadata(key)
208
- key = key.to_s
209
- lines = File.readlines("metadata.txt")
210
- lines = lines.grep(/^#{key}: /)
211
- case lines.size
212
- when 0
213
- result = nil # not found
214
- when 1
215
- front = "#{key}: "
216
- n = front.size
217
- str = lines.first.chomp[n..-1]
218
- case key
219
- when "views", "tags" # plurals
220
- result = str.split
221
- else
222
- result = str
223
- end
224
- else
225
- raise "Too many #{key} instances in metadata.txt!"
226
- end
227
- return result
228
- rescue => err
229
- _tmp_error(err)
230
- end
231
-
232
214
  def process_post(sourcefile)
233
215
  log!(enter: __method__, args: [sourcefile], level: 2)
234
216
  nslug = sourcefile.sub(/.lt3/, "")
@@ -401,9 +383,8 @@ class RuneBlog
401
383
  posts = Dir.entries(dir_posts).grep(/^\d\d\d\d/).map {|x| dir_posts/x }
402
384
  posts.select! {|x| File.directory?(x) }
403
385
 
404
- post = posts.select {|x| File.basename(x).to_i == postid }
405
- raise "Error: More than one post #{postid}" if post.size > 1
406
- postdir = post.first
386
+ posts = posts.select {|x| File.basename(x).to_i == postid }
387
+ postdir = exactly_one(posts)
407
388
  vp = RuneBlog::ViewPost.new(self.view, postdir)
408
389
  vp
409
390
  rescue => err
@@ -563,34 +544,10 @@ class RuneBlog
563
544
  # _tmp_error(err)
564
545
  end
565
546
 
566
- def _get_draft_data(num, sym)
567
- tag = prefix(num)
568
- front = @blog.root/:drafts/tag
569
- files = Dir[front + "*"]
570
- raise "No draft #{num} found" if files.empty?
571
- raise "Too many files found for #{num}!" if files.size > 1
572
- file = files.first
573
- lines = File.readlines(file)
574
- case sym
575
- when :views
576
- view_line = lines.grep(/^.views /)
577
- raise "More than one .views call in #{draft}" if view_line.size > 1
578
- raise "No .views call in #{draft}" if view_line.size < 1
579
- view_line = view_line.first
580
- views = view_line[7..-1].split
581
- return views.uniq
582
- else
583
- raise "Unknown symbol #{sym.inspect}"
584
- end
585
- end
586
-
587
547
  def _get_views(draft)
588
548
  log!(enter: __method__, args: [draft], level: 2)
589
549
  # FIXME dumb code
590
- view_line = File.readlines(draft).grep(/^.views /)
591
- raise "More than one .views call in #{draft}" if view_line.size > 1
592
- raise "No .views call in #{draft}" if view_line.size < 1
593
- view_line = view_line.first
550
+ view_line = exactly_one(File.readlines(draft).grep(/^.views /))
594
551
  views = view_line[7..-1].split
595
552
  views.uniq
596
553
  rescue => err
@@ -621,10 +578,11 @@ class RuneBlog
621
578
  pnum = nslug[0..3] # 0001
622
579
  Dir.chdir(pdraft) do
623
580
  excerpt = File.read("teaser.txt")
624
- date = _retrieve_metadata(:date)
581
+ meta = read_metadata
582
+ date = meta.date
625
583
  longdate = ::Date.parse(date).strftime("%B %e, %Y")
626
- title = _retrieve_metadata(:title)
627
- tags = _retrieve_metadata(:tags)
584
+ title = meta.title
585
+ tags = meta.tags
628
586
  # FIXME simplify
629
587
  vars = <<~LIVE
630
588
  .set post.num = #{pnum}
@@ -3,7 +3,7 @@ if !defined?(RuneBlog::Path)
3
3
  # if ! (Object.constants.include?(:RuneBlog) && RuneBlog.constants.include?(:Path))
4
4
 
5
5
  class RuneBlog
6
- VERSION = "0.3.05"
6
+ VERSION = "0.3.06"
7
7
 
8
8
  path = Gem.find_files("runeblog").grep(/runeblog-/).first
9
9
  Path = File.dirname(path)
@@ -46,5 +46,4 @@ def prefix(num)
46
46
  "#{'%04d' % num.to_i}"
47
47
  end
48
48
 
49
-
50
49
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: runeblog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.05
4
+ version: 0.3.06
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hal Fulton