runeblog 0.0.57 → 0.0.58

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
  SHA1:
3
- metadata.gz: e7f2f60b13ad6aefe511291f1260123897d98b25
4
- data.tar.gz: 25ac133e889d49fe12d83423932999991e09d9c1
3
+ metadata.gz: d32821f8f0c5a59dd18a91b23edbb0927ca5bcb3
4
+ data.tar.gz: e5cb288cad3ac1781b09ea671b44c22d6c022281
5
5
  SHA512:
6
- metadata.gz: 0ab9961f32dfea28d846998705d8639bd1b0fdc5d012d59a38e269e921a78d31b4fe9176e1565c850544ee8e9e80fe4042e1ed31e18609d1c50bdc3dc16c4cac
7
- data.tar.gz: 2552eb7707a890943181eab668dfec92e03360eafd5d1483701960328083f486c851eec3a5583028b44cd46aff57e450831e254f248ef7a91990c4dc2c541162
6
+ metadata.gz: 23ef8da1f243feda7aae4b2c3dd75dacd7aa6de42ced265b1c016f6a2ed2f8adf971a2a381c295cc3183ad45dd185d56323c4b7549faf867da3c82cbb789b4a2
7
+ data.tar.gz: 3f85f7fdcb768c77c34a0d92b3dd10a8c2917601e1fc6226edad0214887b3e1ccf2398d27a4cdb4dece15d9645eb9c510a9a61ca682feb1e30bd4afc09ebccc3
data/bin/blog CHANGED
@@ -32,6 +32,7 @@ if cmd.nil? # REPL
32
32
  cmd = gets
33
33
  cmd_quit([]) if cmd.nil? # ^D
34
34
  cmd.chomp!
35
+ next if cmd.empty? # CR does nothing
35
36
  meth, params = RuneBlog::REPL.choose_method(cmd)
36
37
  str = send(meth, params)
37
38
  puts str unless str.nil?
data/data/VERSION CHANGED
@@ -1 +1 @@
1
- RuneBlog v 0.0.57 2018-09-10
1
+ RuneBlog v 0.0.58 2018-09-13
data/lib/helpers-repl.rb CHANGED
@@ -99,6 +99,64 @@ module RuneBlog::REPL
99
99
  STDIN.gets.chomp.upcase[0] == "Y"
100
100
  end
101
101
 
102
+ def reset_output(initial = "")
103
+ @out ||= ""
104
+ @out.replace initial
105
+ end
106
+
107
+ def flush_output(initial = "")
108
+ @out ||= ""
109
+ puts @out
110
+ reset_output
111
+ end
112
+
113
+ def output(str) # \n and indent
114
+ @out ||= ""
115
+ @out << "\n " + str
116
+ end
117
+
118
+ def outstr(str) # \n and indent
119
+ @out ||= ""
120
+ @out << str
121
+ end
122
+
123
+ def output!(str) # red, \n and indent
124
+ @out ||= ""
125
+ @out << "\n " + red(str)
126
+ end
127
+
128
+ def output_newline(n = 1)
129
+ @out ||= ""
130
+ n.times { @out << "\n" }
131
+ end
132
+
133
+ FileNotFound = StandardError.dup
134
+ CantOpen = StandardError.dup
135
+ CantDelete = StandardError.dup
136
+
137
+ def check_empty(arg)
138
+ raise "Glitch: #{caller[0]} got arg #{arg.inspect}" unless arg.nil?
139
+ end
140
+
141
+ def get_integer(arg)
142
+ Integer(arg)
143
+ rescue
144
+ raise ArgumentError, "'#{arg}' is not an integer"
145
+ end
146
+
147
+ def check_file_exists(file)
148
+ raise FileNotFound, file unless File.exist?(file)
149
+ end
150
+
151
+ def error_cant_delete(files)
152
+ case files
153
+ when String
154
+ raise CantDelete, "Error deleting #{files}"
155
+ when Array
156
+ raise CantDelete, "Error deleting: \n#{files.join("\n")}"
157
+ end
158
+ end
159
+
102
160
  def clear
103
161
  puts "\e[H\e[2J" # clear screen
104
162
  end
data/lib/repl.rb CHANGED
@@ -5,63 +5,49 @@ require 'helpers-repl' # FIXME structure
5
5
  module RuneBlog::REPL
6
6
 
7
7
  def cmd_quit(arg)
8
- raise "Glitch: #{__callee__} got arg #{arg.inspect}" unless arg.nil?
9
- puts "\n "
10
- exit
8
+ check_empty(arg)
9
+ abort "\n "
11
10
  end
12
11
 
13
12
  def cmd_version(arg)
14
- raise "Glitch: #{__callee__} got arg #{arg.inspect}" unless arg.nil?
15
- return "\n " + RuneBlog::VERSION
16
- end
17
-
18
- def new_blog!(arg) # FIXME weird?
19
- raise "Glitch: #{__callee__} got arg #{arg.inspect}" unless arg.nil?
20
- return if RuneBlog.exist?
21
- yn = yesno(red(" No .blog found. Create new blog? "))
22
- RuneBlog.create_new_blog if yn
23
- rescue => err
24
- error(err)
25
- end
26
-
27
- def open_blog # Crude - FIXME later
28
- @blog = RuneBlog.new
29
- @view = @blog.view # current view
30
- @sequence = @blog.sequence
31
- @root = @blog.root
32
- @blog
33
- rescue => err
34
- error(err)
13
+ reset_output
14
+ check_empty(arg)
15
+ output RuneBlog::VERSION
16
+ return @out
35
17
  end
36
18
 
37
19
  def cmd_browse
38
- raise "Glitch: #{__callee__} got arg #{arg.inspect}" unless arg.nil?
20
+ reset_output
21
+ check_empty(arg)
39
22
  @deploy ||= {}
40
23
  return puts red("\n Deploy first.") unless @deploy[@view]
41
24
 
42
25
  lines = @deploy[@view]
43
26
  user, server, sroot, spath = *lines
44
- result = system("open 'http://#{server}/#{spath}'")
45
- raise "Problem opening http://#{server}/#{spath}" unless result
27
+ url = "http://#{server}/#{spath}"
28
+ result = system("open '#{url}'")
29
+ raise CantOpen, url unless result
46
30
  nil
47
31
  rescue => err
48
32
  error(err)
49
33
  end
50
34
 
51
35
  def cmd_open_local
52
- result = system("open #{@blog.viewdir(@view)}/index.html")
53
- raise "Problem opening #{@blog.viewdir(@view)}/index.html" unless result
54
- nil
36
+ reset_output
37
+ local = @blog.viewdir(@view) + "/index.html"
38
+ result = system("open #{local}")
39
+ raise CantOpen, local unless result
55
40
  rescue => err
56
41
  error(err)
57
42
  end
58
43
 
59
44
  def cmd_deploy(arg) # FIXME non-string return expected in caller?
60
45
  # TBD clunky FIXME
61
- raise "Glitch: #{__callee__} got arg #{arg.inspect}" unless arg.nil?
46
+ reset_output
47
+ check_empty(arg)
62
48
  @deploy ||= {}
63
49
  deployment = @blog.viewdir(@view) + "deploy"
64
- raise "File '#{deployment}' not found" unless File.exist?(deployment)
50
+ check_file_exists(deployment)
65
51
 
66
52
  lines = File.readlines(deployment).map {|x| x.chomp }
67
53
  @deploy[@view] = lines
@@ -75,27 +61,28 @@ module RuneBlog::REPL
75
61
  return nil
76
62
  end
77
63
 
78
- out = "\n Files:"
79
- files.each {|f| out << (" " + f + "\n") }
80
- out << "\n"
64
+ output "Files:"
65
+ files.each {|f| output " #{f}\n" }
66
+ output_newline
81
67
  dir = "#{sroot}/#{spath}"
82
68
  # FIXME - may or may not already exist
83
69
  result = system("ssh root@#{server} mkdir #{dir}")
84
70
 
85
71
  cmd = "scp -r #{files.join(' ')} root@#{server}:#{dir} >/dev/null 2>&1"
86
- out << red("\n Deploying #{files.size} files...\n")
72
+ output! "Deploying #{files.size} files...\n"
87
73
  result = system(cmd)
88
74
  raise "Problem occurred in deployment" unless result
89
75
 
90
76
  File.write("#{vdir}/last_deployed", files)
91
- out << red("finished.\n")
92
- out
77
+ output! "...finished.\n"
78
+ @out
93
79
  rescue => err
94
80
  error(err)
95
81
  end
96
82
 
97
83
  def cmd_rebuild(arg)
98
- raise "Glitch: #{__callee__} got arg #{arg.inspect}" unless arg.nil?
84
+ reset_output
85
+ check_empty(arg)
99
86
  puts
100
87
  files = Dir.entries("#@root/src/").grep /\d\d\d\d.*.lt3$/
101
88
  files.map! {|f| File.basename(f) }
@@ -107,7 +94,8 @@ module RuneBlog::REPL
107
94
  end
108
95
 
109
96
  def cmd_relink(arg)
110
- raise "Glitch: #{__callee__} got arg #{arg.inspect}" unless arg.nil?
97
+ reset_output
98
+ check_empty(arg)
111
99
  @blog.views.each {|view| generate_index(view) }
112
100
  nil
113
101
  rescue => err
@@ -115,34 +103,36 @@ module RuneBlog::REPL
115
103
  end
116
104
 
117
105
  def cmd_list_views(arg)
106
+ reset_output("\n")
107
+ check_empty(arg)
118
108
  abort "Config file not read" unless @blog
119
- raise "Glitch: #{__callee__} got arg #{arg.inspect}" unless arg.nil?
120
- out = "\n"
121
- @blog.views.each {|v| out << " #{v}\n" }
122
- out
109
+ @blog.views.each {|v| outstr " #{v}\n" }
110
+ @out
123
111
  rescue => err
124
112
  error(err)
125
113
  end
126
114
 
127
115
  def cmd_change_view(arg)
116
+ reset_output
128
117
  if arg.nil?
129
- return "\n #{@blog.view}"
118
+ output "#{@blog.view}"
119
+ return @out
130
120
  else
131
- out = ""
132
121
  list = @blog.views.grep /^#{arg}/
133
122
  if list.size == 1
134
123
  @view = @blog.view = list.first
135
- out << red("\n View: #{@view}\n") if arg != @view
124
+ output! "View: #{@view}\n" if arg != @view
136
125
  else
137
- out << "view #{arg.inspect} does not exist\n"
126
+ output! "view #{arg.inspect} does not exist\n"
138
127
  end
139
128
  end
140
- out
129
+ @out
141
130
  rescue => err
142
131
  error(err)
143
132
  end
144
133
 
145
134
  def cmd_new_view(arg)
135
+ reset_output
146
136
  @blog ||= open_blog
147
137
  arg ||= ask("New view: ") # check validity later
148
138
  raise "view #{arg} already exists" if @blog.views.include?(arg)
@@ -162,7 +152,8 @@ module RuneBlog::REPL
162
152
  end
163
153
 
164
154
  def cmd_new_post(arg)
165
- raise "Glitch: #{__callee__} got arg #{arg.inspect}" unless arg.nil?
155
+ reset_output
156
+ check_empty(arg)
166
157
  open_blog unless @blog # duh?
167
158
  @title = ask("Title: ")
168
159
  @blog.create_new_post(@title)
@@ -171,6 +162,7 @@ module RuneBlog::REPL
171
162
  end
172
163
 
173
164
  def cmd_kill(arg)
165
+ reset_output
174
166
  args = arg.split
175
167
  args.each {|x| cmd_remove_post([x], false) }
176
168
  nil
@@ -181,37 +173,43 @@ module RuneBlog::REPL
181
173
  #-- FIXME affects linking, building, deployment...
182
174
 
183
175
  def cmd_remove_post(arg, safe=true)
184
- out = ""
185
- id = Integer(arg) rescue raise("'#{arg}' is not an integer")
176
+ reset_output
177
+ err = "'#{arg}' is not an integer"
178
+ id = get_integer(arg)
186
179
  tag = "#{'%04d' % id}"
187
180
  files = Find.find(@root).to_a
188
181
  files = files.grep(/#{tag}-/)
189
182
  if files.empty?
190
- out = red("\n No such post found (#{id})")
191
- return out
183
+ output! "No such post found (#{id})"
184
+ return @out
192
185
  end
193
186
 
194
187
  if safe
195
- out << "\n"
196
- files.each {|f| out << " #{f}\n" }
197
- puts out
198
- out = ""
199
- ques = files.size > 1 ? "\n Delete all these?\n " : "\n Delete?\n "
188
+ output_newline
189
+ files.each {|f| outstr " #{f}\n" }
190
+ puts @out # ??
191
+ reset_output
192
+ ques = "\n Delete?\n "
193
+ ques.sub!(/\?/, " all these?") if files.size > 1
200
194
  yn = ask red(ques)
201
195
  if yn.downcase == "y"
202
196
  result = system("rm -rf #{files.join(' ')}")
203
- raise "Problem deleting file(s)" unless result
204
- out << red("\n Deleted\n")
197
+ error_cant_delete(files) unless result
198
+ output! "Deleted\n"
205
199
  else
206
- out << red("\n No action taken\n")
200
+ output! "No action taken\n"
207
201
  end
208
202
  else
209
203
  result = system("rm -rf #{files.join(' ')}")
210
- out << red("\n Deleted:\n")
211
- files.each {|f| out << " #{f}\n" }
212
- raise "Problem mass-deleting file(s)" unless result
204
+ error_cant_delete(files) unless result
205
+ output! "Deleted:\n"
206
+ files.each {|f| output " #{f}\n" }
213
207
  end
214
- out
208
+ @out
209
+ rescue ArgumentError => err
210
+ puts err
211
+ rescue CantDelete => err
212
+ puts err
215
213
  rescue => err
216
214
  error(err)
217
215
  end
@@ -219,7 +217,8 @@ module RuneBlog::REPL
219
217
  #-- FIXME affects linking, building, deployment...
220
218
 
221
219
  def cmd_edit_post(arg)
222
- id = Integer(arg) rescue raise("'#{arg}' is not an integer")
220
+ reset_output
221
+ id = get_integer(arg)
223
222
  tag = "#{'%04d' % id}"
224
223
  files = Find.find(@root+"/src").to_a
225
224
  files = files.grep(/#{tag}-/)
@@ -238,51 +237,56 @@ module RuneBlog::REPL
238
237
  end
239
238
 
240
239
  def cmd_list_posts(arg)
241
- raise "Glitch: #{__callee__} got arg #{arg.inspect}" unless arg.nil?
242
- out = ""
240
+ check_empty(arg)
241
+ reset_output
243
242
  @view = @blog.view
244
243
  dir = @blog.viewdir(@view)
245
244
  Dir.chdir(dir) do
246
245
  posts = Dir.entries(".").grep(/^0.*/)
246
+ output @view + ":\n"
247
247
  if posts.empty?
248
- out << ("\n " + @view + ":" + red(" No posts\n"))
248
+ output! "No posts\n"
249
249
  else
250
- out << ("\n " + @view + ":\n ")
251
- posts.each {|post| out << " #{colored_slug(post)}\n" }
250
+ posts.each {|post| outstr " #{colored_slug(post)}\n" }
252
251
  end
253
252
  end
254
- out
253
+ @out
255
254
  rescue => err
256
255
  error(err)
257
256
  end
258
257
 
259
258
  def cmd_list_drafts(arg)
260
- raise "Glitch: #{__callee__} got arg #{arg.inspect}" unless arg.nil?
261
- out = ""
259
+ check_empty(arg)
260
+ reset_output
262
261
  dir = "#@root/src"
263
262
  Dir.chdir(dir) do
264
263
  posts = Dir.entries(".").grep(/^0.*.lt3/)
265
- out << "\n"
264
+ output_newline
266
265
  if posts.empty?
267
- return red(" No posts")
266
+ output! "No posts"
267
+ return @out
268
268
  else
269
- posts.each {|post| out << " #{colored_slug(post.sub(/.lt3$/, ""))}\n" }
269
+ posts.each do |post|
270
+ str = " #{colored_slug(post.sub(/.lt3$/, ""))}\n"
271
+ outstr str
272
+ end
270
273
  end
271
274
  end
272
- out
275
+ @out
273
276
  rescue => err
274
277
  error(err)
275
278
  end
276
279
 
277
280
  def cmd_INVALID(arg)
278
- return "\n Command '#{red(arg)}' was not understood."
281
+ reset_output "\n Command '#{red(arg)}' was not understood."
282
+ return @out
279
283
  end
280
284
 
281
285
  def cmd_help(arg)
282
- raise "Glitch: #{__callee__} got arg #{arg.inspect}" unless arg.nil?
283
- out = <<-EOS
284
-
285
- Commands:
286
+ reset_output
287
+ check_empty(arg)
288
+ output(<<-EOS)
289
+ Commands:
286
290
 
287
291
  #{red('h, help ')} This message
288
292
  #{red('q, quit ')} Exit the program
@@ -308,7 +312,28 @@ module RuneBlog::REPL
308
312
  #{red('rebuild ')} Regenerate all posts and relink
309
313
  #{red('deploy ')} Deploy (current view)
310
314
  EOS
311
- out
315
+ @out
316
+ end
317
+
318
+ ## Funky stuff -- needs to move?
319
+
320
+ def new_blog!(arg) # FIXME weird?
321
+ check_empty(arg)
322
+ return if RuneBlog.exist?
323
+ yn = yesno(red(" No .blog found. Create new blog? "))
324
+ RuneBlog.create_new_blog if yn
325
+ rescue => err
326
+ error(err)
327
+ end
328
+
329
+ def open_blog # Crude - FIXME later
330
+ @blog = RuneBlog.new
331
+ @view = @blog.view # current view
332
+ @sequence = @blog.sequence
333
+ @root = @blog.root
334
+ @blog
335
+ rescue => err
336
+ error(err)
312
337
  end
313
338
 
314
339
  end
data/lib/runeblog.rb CHANGED
@@ -3,7 +3,7 @@ require 'yaml'
3
3
  require 'livetext'
4
4
 
5
5
  class RuneBlog
6
- VERSION = "0.0.57"
6
+ VERSION = "0.0.58"
7
7
 
8
8
  Path = File.expand_path(File.join(File.dirname(__FILE__)))
9
9
  DefaultData = Path + "/../data"
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.0.57
4
+ version: 0.0.58
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-09-10 00:00:00.000000000 Z
11
+ date: 2018-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: livetext