runeblog 0.3.21 → 0.3.26

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,11 +1,18 @@
1
1
 
2
2
  def _tmp_error(err)
3
+ STDERR.puts err
4
+ STDERR.puts err.backtrace.join("\n") if err.respond_to?(:backtrace)
5
+ log!(str: "#{err} - see also stderr.out")
6
+ log!(str: err.backtrace.join("\n")) if err.respond_to?(:backtrace)
7
+ return
8
+
3
9
  out = "/tmp/blog#{rand(100)}.txt"
4
10
  File.open(out, "w") do |f|
5
11
  f.puts err.to_s + "\n--------"
6
12
  f.puts err.backtrace.join("\n")
7
13
  end
8
14
  puts "Error: See #{out}"
15
+ # sleep 3
9
16
  end
10
17
 
11
18
  def dump(obj, name)
@@ -20,6 +27,7 @@
20
27
  log!(enter: __method__, args: [str], level: 2)
21
28
  STDERR.puts str if show
22
29
  rc = system(str)
30
+ STDERR.puts " rc = #{rc.inspect}" if show
23
31
  return rc if rc
24
32
  STDERR.puts "FAILED: #{str.inspect}"
25
33
  STDERR.puts "\ncaller = \n#{caller.join("\n ")}\n"
@@ -32,10 +40,12 @@
32
40
  end
33
41
 
34
42
  def _get_data?(file) # File need not exist
43
+ log!(enter: __method__, args: [file], level: 2)
35
44
  File.exist?(file) ? _get_data(file) : []
36
45
  end
37
46
 
38
47
  def _get_data(file)
48
+ log!(enter: __method__, args: [file], level: 2)
39
49
  lines = File.readlines(file)
40
50
  lines = lines.map do |line|
41
51
  line = line.chomp.strip
@@ -46,6 +56,7 @@
46
56
  end
47
57
 
48
58
  def read_pairs(file) # returns a hash
59
+ log!(enter: __method__, args: [file], level: 2)
49
60
  lines = _get_data(file)
50
61
  hash = {}
51
62
  lines.each do |line|
@@ -57,6 +68,7 @@
57
68
  end
58
69
 
59
70
  def read_pairs!(file) # returns an openstruct
71
+ log!(enter: __method__, args: [file], level: 2)
60
72
  lines = _get_data(file)
61
73
  obj = OpenStruct.new
62
74
  lines.each do |line|
@@ -97,27 +109,32 @@
97
109
  end
98
110
 
99
111
  def error(err)
100
- # log!(str: err, enter: __method__, args: [err], level: 2)
101
- str = "\n Error: #{err}"
112
+ log!(str: err, enter: __method__, args: [err], level: 2)
113
+ str = "\n Error... #{err}"
102
114
  puts str
103
115
  puts err.backtrace.join("\n")
104
116
  end
105
117
 
106
- def find_item(list)
118
+ def find_item(list, &block)
119
+ log!(enter: __method__, args: [list], level: 2)
107
120
  list2 = list.select(&block)
108
- exactly_one(list2)
121
+ exactly_one(list2, list.join("/"))
109
122
  end
110
123
 
111
124
  def find_item!(list, &block)
125
+ log!(enter: __method__, args: [list], level: 2)
126
+ list2 = list.select(&block)
112
127
  list2 = list.select(&block)
113
- item = exactly_one(list2)
128
+ item = exactly_one(list2, list.join("/"))
114
129
  n = list.index(&block)
115
130
  [n, item]
116
131
  end
117
132
 
118
- def exactly_one(list)
119
- raise "List: Zero instances" if list.empty?
120
- raise "List: More than one instance" if list.size > 1
133
+ def exactly_one(list, tag = nil, &block)
134
+ log!(enter: __method__, args: [list], level: 2)
135
+ list2 = list.select(&block)
136
+ raise "List: Zero instances #{"- #{tag}" if tag}" if list.empty?
137
+ raise "List: More than one instance #{"- #{tag}" if tag}" if list.size > 1
121
138
  list.first
122
139
  end
123
140
 
@@ -18,16 +18,9 @@ top_help = proc { RubyText.splash(RuneBlog::REPL::Help.gsub(/[{}]/, " ")) }
18
18
  # dir = @blog.view.dir/"themes/standard/"
19
19
 
20
20
  std = "themes/standard"
21
+ data = "." # CHANGED
21
22
 
22
23
  Menu.top_config = {
23
- "Variables (general)" => edit("#{std}/global.lt3"),
24
- " View-specific" => edit("settings/view.txt"),
25
- " Recent posts" => edit("settings/recent.txt"),
26
- " Publishing" => edit("settings/publish.txt"),
27
- "Configuration: enable/disable" => edit("settings/features.txt"),
28
- " Reddit" => edit("config/reddit/credentials.txt"),
29
- " Facebook" => edit("config/facebook/credentials.txt"),
30
- " Twitter" => edit("config/twitter/credentials.txt"),
31
24
  "View: generator" => edit("#{std}/blog/generate.lt3"),
32
25
  " HEAD info" => edit("#{std}/blog/head.lt3"),
33
26
  " Layout " => edit("#{std}/blog/index.lt3"),
@@ -38,6 +31,14 @@ Menu.top_config = {
38
31
  "Generator for a post" => edit("#{std}/post/generate.lt3"),
39
32
  " HEAD info for post" => edit("#{std}/post/head.lt3"),
40
33
  " Content for post" => edit("#{std}/post/index.lt3"),
34
+ "Variables (general)" => edit("#{data}/global.lt3"),
35
+ " View-specific" => edit("settings/view.txt"),
36
+ " Recent posts" => edit("settings/recent.txt"),
37
+ " Publishing" => edit("settings/publish.txt"),
38
+ "Configuration: enable/disable" => edit("settings/features.txt"),
39
+ " Reddit" => edit("config/reddit/credentials.txt"),
40
+ " Facebook" => edit("config/facebook/credentials.txt"),
41
+ " Twitter" => edit("config/twitter/credentials.txt"),
41
42
  "Global CSS" => edit("#{std}/etc/blog.css.lt3"),
42
43
  "External JS/CSS (Bootstrap, etc.)" => edit("/etc/externals.lt3")
43
44
  }
@@ -2,7 +2,7 @@ require 'rubytext'
2
2
 
3
3
  RubyText.start
4
4
 
5
- # IdeaL A special sub-environment for creating a post
5
+ # Idea: A special sub-environment for creating a post
6
6
  #
7
7
  # 1. Display: view, post number, date
8
8
  # 2. Menu?
@@ -15,44 +15,43 @@ RubyText.start
15
15
  # 9. - Quit
16
16
  # Edit body after save/quit
17
17
 
18
+ def ask(prompt) # elsewhere?
19
+ print prompt
20
+ str = gets
21
+ str.chomp! if str
22
+ str
23
+ end
24
+
18
25
  def enter_title
19
- STDSCR.puts __method__
20
- r = STDSCR.rows / 2 - 3
21
- @win = RubyText.window(1, 30, r: r, c: 30, border: false, bg: White, fg: Black)
22
- @win.home
23
- str = @win.gets
24
- STDSCR.puts str.inspect
25
- [__method__, 0]
26
+ puts __method__
27
+ str = ask("Title: ")
28
+ puts str.inspect
26
29
  end
27
30
 
28
31
  def edit_teaser
29
- STDSCR.puts __method__
30
- [__method__, 1]
32
+ puts __method__
33
+ str = ask("Teaser: ")
34
+ puts str.inspect
31
35
  end
32
36
 
33
37
  def add_views
34
- STDSCR.puts __method__
35
- [__method__, 2]
38
+ puts __method__
36
39
  end
37
40
 
38
41
  def add_tags
39
- STDSCR.puts __method__
40
- [__method__, 3]
42
+ puts __method__
41
43
  end
42
44
 
43
45
  def import_assets
44
- STDSCR.puts __method__
45
- [__method__, 4]
46
+ puts __method__
46
47
  end
47
48
 
48
49
  def save_post
49
- STDSCR.puts __method__
50
- [__method__, 5]
50
+ puts __method__
51
51
  end
52
52
 
53
53
  def quit_post
54
- STDSCR.puts __method__
55
- [__method__, 6]
54
+ puts __method__
56
55
  end
57
56
 
58
57
  items = {
@@ -65,9 +64,19 @@ items = {
65
64
  "Quit" => proc { quit_post }
66
65
  }
67
66
 
68
- curr = 0
69
- loop do
70
- str, curr = STDSCR.menu(c: 10, items: items, curr: curr, sticky: true)
71
- break if curr.nil?
72
- STDSCR.puts "str = #{str} curr = #{curr}"
73
- end
67
+ enter_title
68
+ edit_teaser
69
+ add_views
70
+ add_tags
71
+ import_assets
72
+ save_post
73
+ quit_post
74
+
75
+ # getch
76
+
77
+ # curr = 0
78
+ # loop do
79
+ # str, curr = menu(c: 10, items: items, curr: curr, sticky: true)
80
+ # break if curr.nil?
81
+ # puts "str = #{str} curr = #{curr}"
82
+ # end
@@ -66,7 +66,7 @@ class RuneBlog::Post
66
66
  end
67
67
 
68
68
  def edit
69
- # log!(enter: __method__)
69
+ log!(enter: __method__)
70
70
  edit_file(@draft, vim: "+8")
71
71
  build
72
72
  rescue => err
@@ -169,7 +169,8 @@ class RuneBlog::ViewPost
169
169
  @date = meta.pubdate
170
170
  end
171
171
  rescue => err
172
- STDERR.puts "--- #{err}\n #{err.backtrace.join("\n ")}"
172
+ STDERR.puts "--- #{err}"
173
+ STDERR.puts " #{err.backtrace.join("\n ")}" if err.respond_to?(:backtrace)
173
174
  end
174
175
 
175
176
  def get_dirs
@@ -21,9 +21,10 @@ def stale?(src, dst, deps, force = false)
21
21
  end
22
22
 
23
23
  def preprocess(cwd: Dir.pwd, src:,
24
- dst: nil, strip: false,
25
- deps: [], copy: nil, debug: false, force: false,
26
- mix: [], call: [], vars: {})
24
+ dst: nil, strip: false,
25
+ deps: [], copy: nil, debug: false, force: false,
26
+ mix: [], call: [],
27
+ vars: {})
27
28
  src += LEXT unless src.end_with?(LEXT)
28
29
  if strip
29
30
  dst = File.basename(src).sub(/.lt3$/,"")
@@ -31,6 +32,7 @@ def preprocess(cwd: Dir.pwd, src:,
31
32
  dst += ".html" unless dst.end_with?(".html")
32
33
  end
33
34
  sp = " "*12
35
+
34
36
  Dir.chdir(cwd) do
35
37
  if debug
36
38
  STDERR.puts "#{sp} -- preprocess "
@@ -40,20 +42,44 @@ def preprocess(cwd: Dir.pwd, src:,
40
42
  STDERR.puts "#{sp} from: #{caller[0]}"
41
43
  STDERR.puts "#{sp} copy: #{copy}" if copy
42
44
  STDERR.puts "#{sp} vars: #{vars.inspect}" unless vars == {}
45
+ STDERR.flush
43
46
  end
44
47
  stale = stale?(src, dst, deps, force)
48
+ STDERR.puts <<~EOF if debug
49
+ STALE = #{stale}
50
+ cwd = #{cwd.inspect}
51
+ src = #{src.inspect}
52
+ dst = #{dst.inspect}
53
+ strip = #{strip.inspect}
54
+ deps = #{deps.inspect}
55
+ copy = #{copy.inspect}
56
+ debug = #{debug.inspect}
57
+ force = #{force.inspect}
58
+ mix = #{mix.inspect}
59
+ call = #{call.inspect}
60
+ vars = #{vars.inspect}
61
+ EOF
45
62
  if stale
46
63
  live = Livetext.customize(mix: "liveblog", call: call, vars: vars)
64
+ log!(str: "Calling xform_file... src = #{src} pwd = #{Dir.pwd}")
47
65
  out = live.xform_file(src)
48
66
  File.write(dst, out)
49
67
  system!("cp #{dst} #{copy}") if copy
50
68
  end
51
69
  puts "#{sp} -- ^ Already up to date!" if debug && ! stale
52
70
  end
71
+ rescue => err
72
+ msg = err.to_s
73
+ msg << err.backtrace.join("\n") if err.respond_to?(:backtrace)
74
+ STDERR.puts msg
75
+ STDERR.flush
76
+ log!(str: msg)
53
77
  end
54
78
 
55
79
  def get_live_vars(src)
56
80
  live = Livetext.customize(call: [".nopara"])
81
+ # puts "glv: src = #{src.inspect}"
82
+ # STDERR.puts "glv: src = #{src.inspect}"
57
83
  live.xform_file(src)
58
84
  live
59
85
  end
@@ -14,7 +14,9 @@ class RuneBlog::Publishing
14
14
  def initialize(view)
15
15
  log!(enter: __method__, args: [view.to_s])
16
16
  @blog = RuneBlog.blog
17
- dir = @blog.root/:views/view/"themes/standard/"
17
+ dir0 = @blog.root/:views/view/"themes/standard/"
18
+ # CHANGED
19
+ dir = @blog.root/:views/view/:data
18
20
  gfile = dir/"global.lt3"
19
21
  return unless File.exist?(gfile) # FIXME Hackish as hell
20
22
 
@@ -176,7 +176,10 @@ module RuneBlog::REPL
176
176
  result = system!("open #{local}")
177
177
  raise CantOpen(local) unless result
178
178
  rescue => err
179
- _tmp_error(err)
179
+ msg = err.to_s
180
+ msg << "\n" << err.backtrace.join("\n") if err.respond_to?(:backtrace)
181
+ puts msg
182
+ log!(str: msg)
180
183
  end
181
184
 
182
185
  def cmd_publish
@@ -206,14 +209,14 @@ module RuneBlog::REPL
206
209
 
207
210
  def regen_posts
208
211
  drafts = @blog.drafts # current view
209
- puts " Regenerating posts..." unless drafts.empty?
212
+ log! str: "=== Regenerating posts..." unless drafts.empty?
210
213
  drafts.each do |draft|
211
214
  orig = @blog.root/:drafts/draft
212
215
  postdir = @blog.root/:posts/draft.sub(/.lt3$/, "")
213
216
  content = postdir/"/guts.html"
214
217
  next if fresh?(orig, content)
215
218
 
216
- # puts "Calling generate_post(#{orig})"
219
+ log! str: "=== Calling generate_post(#{orig})"
217
220
  @blog.generate_post(orig) # rebuild post
218
221
  Dir.chdir(postdir) do
219
222
  meta = @blog.read_metadata
@@ -225,14 +228,14 @@ module RuneBlog::REPL
225
228
  end
226
229
 
227
230
  def cmd_rebuild
228
- debug "Starting cmd_rebuild..."
231
+ log! str: "=== Starting cmd_rebuild..."
229
232
  puts
230
233
  regen_posts
231
- puts " Generating view..."
234
+ log! str: "=== Generating view..."
232
235
  @blog.generate_view(@blog.view)
233
- puts " Generating index..."
236
+ log! str: "=== Generating index..."
234
237
  @blog.generate_index(@blog.view)
235
- puts " ...finished!"
238
+ log! str: "=== ...finished!"
236
239
  rescue => err
237
240
  _tmp_error(err)
238
241
  end
@@ -248,8 +251,9 @@ module RuneBlog::REPL
248
251
  end
249
252
  n = viewnames.values.find_index(@blog.view.name)
250
253
  name = @blog.view.name
251
- k, name = STDSCR.menu(title: "Views", items: viewnames, curr: n)
254
+ k, name = STDSCR.menu(title: "Views", items: viewnames, curr: n, wrap: true)
252
255
  return if name.nil?
256
+ log! str: "cv Setting to #{name.inspect}"
253
257
  @blog.view = name
254
258
  # puts "\n ", fx(name, :bold), "\n"
255
259
  return
@@ -261,19 +265,40 @@ module RuneBlog::REPL
261
265
  end
262
266
  end
263
267
 
268
+ # move to helpers
269
+ def modify_view_global(view_name)
270
+ gfile = "#{@blog.root}/views/#{view_name}/data/global.lt3"
271
+ lines = File.readlines(gfile).map(&:chomp)
272
+ vars = <<~EOF
273
+ .variables
274
+ View #{view_name}
275
+ ViewDir #{@blog.root}/views/#{view_name}
276
+ .end
277
+
278
+ EOF
279
+ # lines.insert(5, vars)
280
+ text = lines.join("\n")
281
+ File.write(gfile, text)
282
+ end
283
+
284
+ def modify_view_settings(name:, title:, subtitle:, domain:)
285
+ vfile = "#{@blog.root}/views/#{name}/settings/view.txt"
286
+ hash = {/VIEW_NAME/ => name,
287
+ /VIEW_TITLE/ => title,
288
+ /VIEW_SUBTITLE/ => subtitle,
289
+ /VIEW_DOMAIN/ => domain}
290
+ @blog.complete_file(vfile, nil, hash)
291
+ end
292
+
264
293
  def cmd_new_view(arg)
265
294
  view_name = ask!(" Filename: ")
266
295
  @blog.create_view(view_name) # call change_view??
267
296
  title = ask!(" View title: ")
268
297
  subtitle = ask!(" Subtitle : ")
269
298
  domain = ask!(" Domain : ")
270
-
271
- vfile = "#{@blog.root}/views/#{view_name}/settings/view.txt"
272
- hash = {/VIEW_NAME/ => view_name,
273
- /VIEW_TITLE/ => title,
274
- /VIEW_SUBTITLE/ => subtitle,
275
- /VIEW_DOMAIN/ => domain}
276
- @blog.complete_file(vfile, nil, hash)
299
+ modify_view_global(view_name)
300
+ modify_view_settings(name: view_name, title: title, subtitle: subtitle,
301
+ domain: domain)
277
302
  @blog.change_view(view_name)
278
303
  end
279
304
 
@@ -283,11 +308,13 @@ module RuneBlog::REPL
283
308
  puts
284
309
  end
285
310
  @blog.create_view(arg)
286
- text = File.read("#{@blog.root}/data/global.lt3")
287
- File.write("#{@blog.root}/views/#{@blog.view}/themes/standard/global.lt3",
311
+ lines = File.read("#{@blog.root}/data/global.lt3")
312
+ # File.write("#{@blog.root}/views/#{@blog.view}/themes/standard/global.lt3",
313
+ File.write("#{@blog.root}/views/#{@blog.view}/data/global.lt3",
288
314
  text.gsub(/VIEW_NAME/, @blog.view.to_s))
289
315
  vim_params = '-c ":set hlsearch" -c ":hi Search ctermfg=2 ctermbg=6" +/"\(VIEW_.*\|SITE.*\)"'
290
- edit_file(@blog.view.dir/"themes/standard/global.lt3", vim: vim_params)
316
+ # edit_file(@blog.view.dir/"themes/standard/global.lt3", vim: vim_params)
317
+ edit_file(@blog.view.dir/"data/global.lt3", vim: vim_params)
291
318
  @blog.change_view(arg)
292
319
  rescue ViewAlreadyExists
293
320
  puts 'Blog already exists'
@@ -328,7 +355,7 @@ module RuneBlog::REPL
328
355
  tag = "#{'%04d' % id}"
329
356
  files = ::Find.find(@blog.root/:drafts).to_a
330
357
  files = files.grep(/#{tag}-.*lt3/)
331
- draft = exactly_one(files)
358
+ draft = exactly_one(files, files.join("/"))
332
359
  result = edit_file(draft, vim: '-c$')
333
360
  @blog.generate_post(draft)
334
361
  rescue => err