runeblog 0.1.4 → 0.1.5

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: a9aa3949ffe64a27b284103eb9cd968ce4d6353a24db6b8b812b84ae934d80a9
4
- data.tar.gz: a1facc32a0e2f1c18c4679df5243c669d3a7491157ce795e9461383428a8285d
3
+ metadata.gz: d272238c762b72c9ba74c352a35a08e67a2798dce78765a7a7ab026faa2530a7
4
+ data.tar.gz: d7c789ccf2b890f908672d735a7cf9d753ac2cac6f3ad3e3a7706caadc850889
5
5
  SHA512:
6
- metadata.gz: b1ce2fb7692cf799413f9cbb4820e23d566c02707abd7537f659ec4d7999ef854178c41a343c6afa8153183168143345d7c6d961dcaea096934e6e05c8011313
7
- data.tar.gz: 340f345a6d3c93887294fe9e1914eadc365701586ac61b18c6c0ca0fdcb8281c3abf5cacea0638e39d613a58aa58be27dc3111d7179fd982e4d7862483c20ae0
6
+ metadata.gz: 82485c5e3efff0b30855979c9c7a8f9b18059e13ba2a0b1ba15972a10fb746a71722ff94e9263b86807fdd9fe392317b84b984b55224dfbc0057c799dd558144
7
+ data.tar.gz: 40e3575de330a8418d8fe5b39b0eaae911b09936ff91b53649148771e0f8ee3e872816809f97475c2f3da0d8352b548b29c662c0794abb890d10986f788862ab
data/bin/blog CHANGED
@@ -30,8 +30,8 @@ def mainloop
30
30
  cmd.chomp!
31
31
  return if cmd.empty? # CR does nothing
32
32
  meth, params = RuneBlog::REPL.choose_method(cmd)
33
- str = send(meth, params)
34
- puts str unless str.nil?
33
+ old, str = send(meth, params)
34
+ puts str if old && ! str.nil?
35
35
  rescue => err
36
36
  puts err
37
37
  end
@@ -39,7 +39,7 @@ end
39
39
 
40
40
  ###########
41
41
 
42
- RubyText.start(log: "blogcmd.txt", scroll: true, fg: Blue, bg: White)
42
+ RubyText.start(log: "blogcmd.txt", fg: Blue, bg: White)
43
43
  RubyText.set(:_echo)
44
44
 
45
45
  X.stdscr.keypad(true)
@@ -66,8 +66,11 @@ if cmd.nil? # REPL
66
66
  # system("tput smcup") # see: tput rmcup in cmd_quit
67
67
 
68
68
  puts fx("\n RuneBlog", :bold), fx(" v #{RuneBlog::VERSION}", Red)
69
- puts
70
69
  loop { mainloop }
70
+ # STDSCR.clear
71
+ RubyText.stop
72
+ system("tput clear")
73
+ puts
71
74
  else # one command
72
75
  file = File.open("/dev/tty")
73
76
  STDIN.reopen(file) # avoid ARGF dumbness
data/lib/helpers-repl.rb CHANGED
@@ -149,14 +149,12 @@ module RuneBlog::REPL
149
149
 
150
150
  def ask(prompt, meth = :to_s)
151
151
  print prompt
152
- STDOUT.flush
153
- STDIN.gets.chomp.send(meth)
152
+ gets.chomp.send(meth)
154
153
  end
155
154
 
156
155
  def yesno(prompt, meth = :to_s)
157
156
  print prompt
158
- STDOUT.flush
159
- STDIN.gets.chomp.upcase[0] == "Y"
157
+ gets.chomp.upcase[0] == "Y"
160
158
  end
161
159
 
162
160
  def reset_output(initial = "")
data/lib/repl.rb CHANGED
@@ -2,22 +2,35 @@ require 'runeblog'
2
2
  require 'ostruct'
3
3
  require 'helpers-repl' # FIXME structure
4
4
 
5
- make_exception(:PublishError, "Error during publishing")
6
- make_exception(:EditorProblem, "Could not edit $1")
5
+ make_exception(:PublishError, "Error during publishing")
6
+ # make_exception(:EditorProblem, "Could not edit $1")
7
7
 
8
8
  module RuneBlog::REPL
9
9
 
10
+ def edit_file(file)
11
+ result = system("#{blog.editor} #{file}")
12
+ raise EditorProblem(file) unless result
13
+ STDSCR.clear
14
+ end
15
+
10
16
  def cmd_quit(arg)
11
17
  check_empty(arg)
12
- system("tput rmcup")
18
+ # system("tput rmcup")
19
+ RubyText.stop
13
20
  abort "\n "
14
21
  end
15
22
 
23
+ def cmd_clear(arg)
24
+ check_empty(arg)
25
+ STDSCR.cwin.clear
26
+ STDSCR.cwin.refresh
27
+ end
28
+
16
29
  def cmd_version(arg)
17
30
  reset_output
18
31
  check_empty(arg)
19
32
  output RuneBlog::VERSION
20
- return @out
33
+ [true, @out]
21
34
  end
22
35
 
23
36
  def cmd_config(arg)
@@ -29,7 +42,7 @@ module RuneBlog::REPL
29
42
  "custom/post_template.html"]
30
43
  puts "\nEdit which file?" # FIXME use @out for testing later
31
44
  fname = dumb_menu(items)
32
- system("#{@blog.editor} #{dir}/#{fname}")
45
+ edit_file("#{dir}/#{fname}")
33
46
  end
34
47
 
35
48
  def cmd_browse(arg)
@@ -39,7 +52,7 @@ module RuneBlog::REPL
39
52
  # FIXME Bad logic here.
40
53
  if url.nil?
41
54
  output! "Publish first."
42
- return @out
55
+ return [true, @out]
43
56
  end
44
57
  result = system("open '#{url}'")
45
58
  raise CantOpen(url) unless result
@@ -59,13 +72,13 @@ module RuneBlog::REPL
59
72
  check_empty(arg)
60
73
  unless @blog.view.can_publish?
61
74
  output! "Can't publish without entries in #{@blog.view.name}/publish"
62
- return @out
75
+ return [true, @out]
63
76
  end
64
77
  @blog.view.publish
65
78
  user, server, sroot, spath = *@publish[@blog.view]
66
79
  if files.empty? # FIXME baloney
67
80
  output! "No files to publish"
68
- return @out
81
+ return [true, @out]
69
82
  end
70
83
 
71
84
  output "Files:"
@@ -83,7 +96,7 @@ module RuneBlog::REPL
83
96
 
84
97
  dump(files, "#{vdir}/last_published")
85
98
  output! "...finished.\n"
86
- @out
99
+ return [true, @out]
87
100
  end
88
101
 
89
102
  def cmd_rebuild(arg)
@@ -107,14 +120,14 @@ module RuneBlog::REPL
107
120
  # Simplify this
108
121
  if arg.nil?
109
122
  output bold(@blog.view)
110
- return @out
123
+ return [true, @out]
111
124
  else
112
125
  if @blog.view?(arg)
113
126
  @blog.view = arg # reads config
114
127
  output red("View: ") + bold(@blog.view.name.to_s) # FIXME?
115
128
  end
116
129
  end
117
- @out
130
+ return [true, @out]
118
131
  end
119
132
 
120
133
  def cmd_new_view(arg)
@@ -133,6 +146,7 @@ module RuneBlog::REPL
133
146
  meta = OpenStruct.new
134
147
  meta.title = title
135
148
  @blog.create_new_post(meta)
149
+ STDSCR.clear
136
150
  nil
137
151
  end
138
152
 
@@ -144,7 +158,7 @@ module RuneBlog::REPL
144
158
  ret = cmd_remove_post(x.to_i, false)
145
159
  output ret
146
160
  end
147
- @out
161
+ return [true, @out]
148
162
  end
149
163
 
150
164
  #-- FIXME affects linking, building, publishing...
@@ -154,11 +168,8 @@ module RuneBlog::REPL
154
168
  reset_output
155
169
  id = get_integer(arg)
156
170
  result = @blog.remove_post(id)
157
- if result.nil?
158
- output! "Post #{id} not found"
159
- return @out
160
- end
161
- @out
171
+ output! "Post #{id} not found" if result.nil?
172
+ return [true, @out]
162
173
  end
163
174
 
164
175
  #-- FIXME affects linking, building, publishing...
@@ -171,13 +182,11 @@ module RuneBlog::REPL
171
182
  files = Find.find(@blog.root+"/src").to_a
172
183
  files = files.grep(/#{tag}-/)
173
184
  files = files.map {|f| File.basename(f) }
174
- return red("Multiple files: #{files}") if files.size > 1
175
- return red("\n Can't edit post #{id}") if files.empty?
185
+ return [true, "Multiple files: #{files}"] if files.size > 1
186
+ return [true, "\n Can't edit post #{id}"] if files.empty?
176
187
 
177
188
  file = files.first
178
- result = system("vi #{@blog.root}/src/#{file}")
179
- raise EditorProblem(file) unless result
180
-
189
+ result = edit_file("#{@blog.root}/src/#{file}")
181
190
  @blog.rebuild_post(file)
182
191
  nil
183
192
  end
@@ -185,18 +194,15 @@ module RuneBlog::REPL
185
194
  def cmd_list_views(arg)
186
195
  reset_output("\n")
187
196
  check_empty(arg)
188
- debug "curr view = #{@blog.view.name.inspect}"
189
197
  puts
190
198
  @blog.views.each do |v|
191
199
  v = v.to_s
192
200
  v = fx(v, :bold) if v == @blog.view.name
193
- debug "v = #{v.inspect} - #{v.fx.inspect rescue 'no fx'}"
194
201
  print " "
195
202
  puts v
196
203
  end
197
- debug "out = #{@out.inspect}"
198
- @out
199
- ""
204
+ puts
205
+ return [false, @out]
200
206
  end
201
207
 
202
208
  def cmd_list_posts(arg)
@@ -205,14 +211,23 @@ module RuneBlog::REPL
205
211
  posts = @blog.posts # current view
206
212
  str = @blog.view.name + ":\n"
207
213
  output str
214
+ puts
215
+ print " "
216
+ puts fx(str, :bold)
208
217
  if posts.empty?
209
218
  output! bold("No posts")
219
+ puts fx(" No posts", :bold)
210
220
  else
211
221
  posts.each do |post|
212
222
  outstr " #{colored_slug(post)}\n"
223
+ base = post.sub(/.lt3$/, "")
224
+ num, rest = base[0..3], base[4..-1]
225
+ print " "
226
+ puts fx(num, Red), fx(rest, Blue)
213
227
  end
214
228
  end
215
- @out
229
+ puts
230
+ return [false, @out]
216
231
  end
217
232
 
218
233
  def cmd_list_drafts(arg)
@@ -221,18 +236,25 @@ module RuneBlog::REPL
221
236
  drafts = @blog.drafts # current view
222
237
  if drafts.empty?
223
238
  output! "No drafts"
224
- return @out
239
+ puts " No drafts"
240
+ return [true, @out]
225
241
  else
242
+ puts
226
243
  drafts.each do |draft|
227
244
  outstr " #{colored_slug(draft.sub(/.lt3$/, ""))}\n"
245
+ base = draft.sub(/.lt3$/, "")
246
+ num, rest = base[0..3], base[4..-1]
247
+ print " "
248
+ puts fx(num, Red), fx(rest, Blue)
228
249
  end
229
250
  end
230
- @out
251
+ puts
252
+ return [false, @out]
231
253
  end
232
254
 
233
255
  def cmd_INVALID(arg)
234
256
  reset_output "\n Command '#{red(arg)}' was not understood."
235
- return @out
257
+ return [true, @out]
236
258
  end
237
259
 
238
260
  def cmd_help(arg)
@@ -271,7 +293,7 @@ module RuneBlog::REPL
271
293
  #{red('rebuild ')} Regenerate all posts and relink
272
294
  #{red('publish ')} Publish (current view)
273
295
  EOS
274
- @out
296
+ return [true, @out]
275
297
  end
276
298
 
277
299
  end
data/lib/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  class RuneBlog
3
- VERSION = "0.1.4"
3
+ VERSION = "0.1.5"
4
4
 
5
5
  Path = File.expand_path(File.join(File.dirname(__FILE__)))
6
6
  end
data/test/general.rb CHANGED
@@ -3,6 +3,7 @@ $LOAD_PATH << "."
3
3
  require "minitest/autorun"
4
4
 
5
5
  require 'lib/repl'
6
+ require 'rubytext'
6
7
 
7
8
  class TestREPL < Minitest::Test
8
9
  include RuneBlog::REPL
@@ -23,14 +24,14 @@ class TestREPL < Minitest::Test
23
24
  # Note: "Bang" methods depend on the data_test subtree
24
25
 
25
26
  def test_001_cmd_help
26
- out = cmd_help(nil)
27
+ flag, out = cmd_help(nil)
27
28
  assert out.is_a?(String), "Expected a string returned"
28
29
  lines = out.split("\n").length
29
30
  assert lines > 25, "Expecting lengthy help message"
30
31
  end
31
32
 
32
33
  def test_002_cmd_version
33
- out = cmd_version(nil)
34
+ flag, out = cmd_version(nil)
34
35
  assert out.is_a?(String), "Expected a string returned"
35
36
  lines = out
36
37
  assert lines =~ /\d+\.\d+\.\d+/m,
@@ -38,27 +39,27 @@ class TestREPL < Minitest::Test
38
39
  end
39
40
 
40
41
  def test_003_list_views!
41
- out = cmd_list_views(nil)
42
+ flag, out = cmd_list_views(nil)
42
43
  assert out.is_a?(String), "Expected a string returned"
43
44
  lines = out.split("\n").length
44
45
  assert lines >= 2, "Expecting at least 2 lines"
45
46
  end
46
47
 
47
48
  def test_004_change_view!
48
- out = cmd_change_view(nil) # no param
49
+ flag, out = cmd_change_view(nil) # no param
49
50
  assert out.is_a?(String), "Expected a string; got: #{out.inspect}"
50
51
  assert out =~ /alpha_view/m, "Expecting 'alpha_view' as default; got: #{out.inspect}"
51
52
  end
52
53
 
53
54
  def test_005_lsd!
54
- out = cmd_list_drafts(nil)
55
+ flag, out = cmd_list_drafts(nil)
55
56
  assert out.is_a?(String), "Expected a string returned"
56
57
  lines = out.split("\n").length
57
58
  assert lines == 10, "Expecting 10 lines; got #{show_lines(out)}"
58
59
  end
59
60
 
60
61
  def test_006_lsp!
61
- out = cmd_list_posts(nil)
62
+ flag, out = cmd_list_posts(nil)
62
63
  assert out.is_a?(String), "Expected a string returned; got: #{out.inspect}"
63
64
  lines = out.split("\n").length
64
65
  assert lines == 6, "Expecting 6 lines; got #{show_lines(out)}"
@@ -175,16 +176,16 @@ class TestREPL < Minitest::Test
175
176
 
176
177
  def test_014_remove_nonexistent_post!
177
178
  @blog.change_view("alpha_view")
178
- out = cmd_remove_post(99)
179
+ flag, out = cmd_remove_post(99)
179
180
  assert out =~ /Post 99 not found/, "Expected error about nonexistent post, got: #{out}"
180
181
  end
181
182
 
182
183
  def test_015_kill_multiple_posts!
183
184
  @blog.change_view("alpha_view")
184
- out = cmd_list_posts(nil)
185
+ flag, out = cmd_list_posts(nil)
185
186
  before = out.split("\n").length
186
- out = cmd_kill("1 2 7")
187
- out = cmd_list_posts(nil)
187
+ flag, out = cmd_kill("1 2 7")
188
+ flag, out = cmd_list_posts(nil)
188
189
  after = out.split("\n").length
189
190
  expecting = before - 2
190
191
  assert after == expecting, "list_posts saw #{before} posts, now #{after} (not #{expecting})"
@@ -253,7 +254,6 @@ end # conditional tests
253
254
  testfile = "testfile.lt3"
254
255
  path = @blog.root + "/src/" + testfile
255
256
  cmd = "echo .no_such_command > #{path}"
256
- p cmd
257
257
  system(cmd)
258
258
  system("ls -l #{path}")
259
259
  assert_raises(LivetextError) { @blog.process_post(testfile) }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: runeblog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hal Fulton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-10 00:00:00.000000000 Z
11
+ date: 2018-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: livetext