runeblog 0.0.62 → 0.0.63

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: 853cc1fbf7aa876a9b64fd5610ed7ded80605015
4
- data.tar.gz: 37eac8d1a538f3b2b8f960adf8e42528e9ca998c
3
+ metadata.gz: be9dde18efd8f52b1115c2c07337c594207c64c3
4
+ data.tar.gz: 1c36e3cdf18c43de3dbb0867f60b9abdc0de8a09
5
5
  SHA512:
6
- metadata.gz: 877f1dc5b92237f4e3064652917643a0360857bf449c818717ece811b7c94ae025a5a62798eb48391b90f48cf17510184c992d142350469fe2dcad6e643b073c
7
- data.tar.gz: eadaa9244ba181f48aa50d28db84145b5eeba71c6c4ddbe028d3cca38c6ab998b853a107b93a71975d10ca78b6d490599839de38cf6b1a9d93d4dac8cb158b94
6
+ metadata.gz: 97b396fc32bb61ce2d7e174cf9a65194d8222ecae94bb98a4fd7d15ca3a3c43ece1babe7e71d2f0cfc4451a33d3ad4b885bfe76ebbb2c79cee3d69773b718674
7
+ data.tar.gz: 2b34bbd321ca613ae0cf1100ceed94998a284c553fd1128c73ea0a96451840f709a91d48fdcf22875680b1ab27dc4b95b2f73a9f3e2cd718917c8406e425a822
data/bin/blog CHANGED
@@ -21,7 +21,7 @@ STDOUT.sync = true
21
21
 
22
22
  cmd, arg = get_argv
23
23
 
24
- @blog = open_blog
24
+ @blog = RuneBlog.new
25
25
 
26
26
  puts red("\n RuneBlog v #{RuneBlog::VERSION}")
27
27
 
data/data/VERSION CHANGED
@@ -1 +1 @@
1
- RuneBlog v 0.0.62 2018-09-18
1
+ RuneBlog v 0.0.63 2018-09-20
data/lib/helpers-repl.rb CHANGED
@@ -173,23 +173,10 @@ module RuneBlog::REPL
173
173
  "\e[1m#{str}\e[22m"
174
174
  end
175
175
 
176
- def interpolate(str)
177
- wrap = "<<-EOS\n#{str}\nEOS"
178
- eval wrap
179
- end
180
-
181
176
  def colored_slug(slug)
182
177
  red(slug[0..3])+blue(slug[4..-1])
183
178
  end
184
179
 
185
- ### create_dir
186
-
187
- def create_dir(dir)
188
- cmd = "mkdir -p #{dir} >/dev/null 2>&1"
189
- result = system(cmd)
190
- raise "Can't create #{dir}" unless result
191
- end
192
-
193
180
  def import(arg = nil)
194
181
  # open_blog unless @blog
195
182
 
data/lib/repl.rb CHANGED
@@ -35,7 +35,7 @@ module RuneBlog::REPL
35
35
 
36
36
  def cmd_open_local
37
37
  reset_output
38
- local = @blog.viewdir(@view) + "/index.html"
38
+ local = @blog.viewdir(@blog.view) + "/index.html"
39
39
  result = system("open #{local}")
40
40
  raise CantOpen, local unless result
41
41
  rescue => err
@@ -46,8 +46,8 @@ module RuneBlog::REPL
46
46
  # TBD clunky FIXME
47
47
  reset_output
48
48
  check_empty(arg)
49
- user, server, sroot, spath = *@deploy[@view]
50
- if files.empty?
49
+ user, server, sroot, spath = *@deploy[@blog.view]
50
+ if files.empty? # FIXME baloney
51
51
  output! "No files to deploy"
52
52
  return @out
53
53
  end
@@ -76,10 +76,7 @@ module RuneBlog::REPL
76
76
  reset_output
77
77
  check_empty(arg)
78
78
  puts
79
- # Simplify this
80
- files = Dir.entries("#@root/src/").grep /\d\d\d\d.*.lt3$/
81
- files.map! {|f| File.basename(f) }
82
- files = files.sort.reverse
79
+ files = @blog.find_src_slugs
83
80
  files.each {|file| rebuild_post(file) }
84
81
  nil
85
82
  rescue => err
@@ -89,7 +86,7 @@ module RuneBlog::REPL
89
86
  def cmd_relink(arg)
90
87
  reset_output
91
88
  check_empty(arg)
92
- @blog.views.each {|view| generate_index(view) }
89
+ @blog.relink
93
90
  nil
94
91
  rescue => err
95
92
  error(err)
@@ -98,7 +95,6 @@ module RuneBlog::REPL
98
95
  def cmd_list_views(arg)
99
96
  reset_output("\n")
100
97
  check_empty(arg)
101
- abort "Config file not read" unless @blog
102
98
  @blog.views.each do |v|
103
99
  v = bold(v) if v == @blog.view
104
100
  outstr " #{v}\n"
@@ -110,15 +106,15 @@ module RuneBlog::REPL
110
106
 
111
107
  def cmd_change_view(arg)
112
108
  reset_output
113
- # Simlify this
109
+ # Simplify this
114
110
  if arg.nil?
115
111
  output "#{@blog.view}"
116
112
  return @out
117
113
  else
118
114
  list = @blog.views.grep /^#{arg}/
119
115
  if list.size == 1
120
- @view = @blog.view = list.first
121
- output! "View: #{@view}\n" if arg != @view
116
+ @blog.view = list.first
117
+ output! "View: #{@blog.view}\n" if arg != @blog.view
122
118
  else
123
119
  output! "view #{arg.inspect} does not exist\n"
124
120
  end
@@ -130,9 +126,8 @@ module RuneBlog::REPL
130
126
 
131
127
  def cmd_new_view(arg)
132
128
  reset_output
133
- arg ||= ask("New view: ") # check validity later
134
129
  @blog.create_view(arg)
135
- return nil
130
+ nil
136
131
  rescue => err
137
132
  error(err)
138
133
  end
@@ -140,9 +135,9 @@ module RuneBlog::REPL
140
135
  def cmd_new_post(arg)
141
136
  reset_output
142
137
  check_empty(arg)
143
- @title = ask("Title: ")
144
- @blog.create_new_post(@title)
145
- return nil
138
+ title = ask("Title: ")
139
+ @blog.create_new_post(title)
140
+ nil
146
141
  rescue => err
147
142
  error(err)
148
143
  end
@@ -150,10 +145,11 @@ module RuneBlog::REPL
150
145
  def cmd_kill(arg)
151
146
  reset_output
152
147
  args = arg.split
153
- args.each {|x| cmd_remove_post([x], false) }
154
- return nil
148
+ args.each {|x| cmd_remove_post(x, false) }
149
+ nil
155
150
  rescue => err
156
151
  error(err)
152
+ puts err.backtrace
157
153
  end
158
154
 
159
155
  #-- FIXME affects linking, building, deployment...
@@ -161,8 +157,8 @@ module RuneBlog::REPL
161
157
  def cmd_remove_post(arg, safe=true)
162
158
  reset_output
163
159
  id = get_integer(arg)
164
- files = @blog.files_by_id(id)
165
- if files.empty?
160
+ files = @blog.post_exists?(id)
161
+ if files.nil?
166
162
  output! "No such post found (#{id})"
167
163
  return @out
168
164
  end
@@ -175,25 +171,26 @@ module RuneBlog::REPL
175
171
  ques.sub!(/\?/, " all these?") if files.size > 1
176
172
  yes = yesno red(ques)
177
173
  if yes
178
- result = system("rm -rf #{files.join(' ')}")
179
- error_cant_delete(files) unless result
174
+ @blog.remove_post(id)
180
175
  output! "Deleted\n"
181
176
  else
182
177
  output! "No action taken\n"
183
178
  end
184
179
  else
185
- result = system("rm -rf #{files.join(' ')}")
186
- error_cant_delete(files) unless result
180
+ @blog.remove_post(id)
187
181
  output! "Deleted:\n"
188
182
  files.each {|f| output " #{f}\n" }
189
183
  end
190
184
  @out
191
185
  rescue ArgumentError => err
192
186
  puts err
187
+ puts err.backtrace
193
188
  rescue CantDelete => err
194
189
  puts err
190
+ puts err.backtrace
195
191
  rescue => err
196
192
  error(err)
193
+ puts err.backtrace
197
194
  end
198
195
 
199
196
  #-- FIXME affects linking, building, deployment...
@@ -201,16 +198,16 @@ module RuneBlog::REPL
201
198
  def cmd_edit_post(arg)
202
199
  reset_output
203
200
  id = get_integer(arg)
204
- # Simlify this
201
+ # Simplify this
205
202
  tag = "#{'%04d' % id}"
206
- files = Find.find(@root+"/src").to_a
203
+ files = Find.find(@blog.root+"/src").to_a
207
204
  files = files.grep(/#{tag}-/)
208
205
  files = files.map {|f| File.basename(f) }
209
206
  return red("Multiple files: #{files}") if files.size > 1
210
207
  return red("\n No such post found (#{id})") if files.empty?
211
208
 
212
209
  file = files.first
213
- result = system("vi #@root/src/#{file}")
210
+ result = system("vi #{@blog.root}/src/#{file}")
214
211
  raise "Problem editing #{file}" unless result
215
212
 
216
213
  rebuild_post(file)
@@ -223,7 +220,7 @@ module RuneBlog::REPL
223
220
  check_empty(arg)
224
221
  reset_output
225
222
  posts = @blog.posts # current view
226
- output @view + ":\n"
223
+ output @blog.view + ":\n"
227
224
  if posts.empty?
228
225
  output! "No posts\n"
229
226
  else
@@ -297,30 +294,30 @@ module RuneBlog::REPL
297
294
 
298
295
  ## Funky stuff -- needs to move?
299
296
 
300
- def new_blog!(arg) # FIXME weird?
301
- check_empty(arg)
302
- return if RuneBlog.exist?
303
- yes = yesno(red(" No .blog found. Create new blog? "))
304
- RuneBlog.create_new_blog if yes
305
- rescue => err
306
- error(err)
307
- end
308
-
309
- def open_blog # Crude - FIXME later
310
- @blog = RuneBlog.new
311
- @view = @blog.view # current view
312
- @sequence = @blog.sequence
313
- @root = @blog.root
314
- @deploy ||= {}
315
- @blog.views.each do |view|
316
- deployment = @blog.viewdir(@view) + "deploy"
317
- check_file_exists(deployment)
318
- lines = File.readlines(deployment).map {|x| x.chomp }
319
- @deploy[@view] = lines
320
- end
321
- @blog
322
- rescue => err
323
- error(err)
324
- end
297
+ # def new_blog!(arg) # FIXME weird?
298
+ # check_empty(arg)
299
+ # return if RuneBlog.exist?
300
+ # yes = yesno(red(" No .blog found. Create new blog? "))
301
+ # RuneBlog.create_new_blog if yes
302
+ # rescue => err
303
+ # error(err)
304
+ # end
305
+
306
+ # def open_blog # Crude - FIXME later
307
+ # @blog = RuneBlog.new
308
+ # @view = @blog.view # current view
309
+ # @sequence = @blog.sequence
310
+ # @root = @blog.root
311
+ # @deploy ||= {}
312
+ # @blog.views.each do |view|
313
+ # deployment = @blog.viewdir(@view) + "deploy"
314
+ # check_file_exists(deployment)
315
+ # lines = File.readlines(deployment).map {|x| x.chomp }
316
+ # @deploy[@view] = lines
317
+ # end
318
+ # @blog
319
+ # rescue => err
320
+ # error(err)
321
+ # end
325
322
 
326
323
  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.62"
6
+ VERSION = "0.0.63"
7
7
 
8
8
  Path = File.expand_path(File.join(File.dirname(__FILE__)))
9
9
  DefaultData = Path + "/../data"
@@ -16,8 +16,8 @@ class RuneBlog
16
16
  BlogTrailer = File.read(BlogTrailerPath) rescue "not found"
17
17
  BlogTemplate = File.read(BlogTemplatePath) rescue "not found"
18
18
 
19
- attr_reader :root, :views, :view, :sequence
20
- attr_writer :view # FIXME
19
+ attr_reader :root, :views, :sequence
20
+ attr_accessor :view # FIXME
21
21
 
22
22
  def self.create_new_blog
23
23
  #-- what if data already exists?
@@ -73,6 +73,13 @@ class RuneBlog
73
73
  self.views << arg
74
74
  end
75
75
 
76
+ def delete_view(name, force = false)
77
+ if force
78
+ system("rm -rf #@root/views/#{name}")
79
+ @views -= [name]
80
+ end
81
+ end
82
+
76
83
  def deployment_url
77
84
  return nil unless @deploy[@view]
78
85
  lines = @deploy[@view]
@@ -89,13 +96,14 @@ class RuneBlog
89
96
  end
90
97
 
91
98
  def files_by_id(id)
92
- files = Find.find(@root).to_a
99
+ files = Find.find(self.root).to_a
93
100
  tag = "#{'%04d' % id}"
94
- files.grep(/#{tag}-/)
101
+ result = files.grep(/#{tag}-/)
102
+ result
95
103
  end
96
104
 
97
- def create_new_post(title, view=nil)
98
- view ||= @view
105
+ def create_new_post(title, testing = false)
106
+ view = @view
99
107
  date = Time.now.strftime("%Y-%m-%d")
100
108
  @template = <<-EOS
101
109
  .mixin liveblog
@@ -110,14 +118,15 @@ Teaser goes here.
110
118
  Remainder of post goes here.
111
119
  EOS
112
120
 
113
- @slug = make_slug(title)
121
+ num, @slug = make_slug(title)
114
122
  @fname = @slug + ".lt3"
115
123
  File.open("#@root/src/#@fname", "w") {|f| f.puts @template }
116
- edit_initial_post(@fname) # How eliminate for testing?
117
- process_post(@fname) #- FIXME handle each view
124
+ edit_initial_post(@fname) unless testing
125
+ process_post(@fname) #- FIXME handle each view
118
126
  publish_post(@meta)
127
+ num
119
128
  rescue => err
120
- error(err)
129
+ puts err # error(err)
121
130
  end
122
131
 
123
132
  def edit_initial_post(file)
@@ -149,7 +158,7 @@ EOS
149
158
  @meta = @main.process_file(path, binding)
150
159
  raise "process_file returned nil" if @meta.nil?
151
160
 
152
- slug = self.make_slug(@meta.title, self.sequence)
161
+ num, slug = self.make_slug(@meta.title, self.sequence)
153
162
  slug = file.sub(/.lt3$/, "")
154
163
  @meta.slug = slug
155
164
  @meta
@@ -158,16 +167,12 @@ EOS
158
167
  end
159
168
 
160
169
  def publish_post(meta)
161
- puts " #{colored_slug(meta.slug)}"
170
+ puts " #{colored_slug(meta.slug)}" rescue nil # puts(meta.slug) # FIXME
162
171
  # First gather the views
163
172
  views = meta.views
164
- print " Views: "
165
- views.each do |view|
166
- print "#{view} "
167
- link_post_view(view)
168
- end
173
+ views.each {|view| link_post_view(view) }
169
174
  # assets = find_all_assets(@meta.assets, views)
170
- puts
175
+ nil
171
176
  rescue => err
172
177
  error(err)
173
178
  end
@@ -209,6 +214,10 @@ EOS
209
214
  error(err)
210
215
  end
211
216
 
217
+ def relink
218
+ self.views.each {|view| generate_index(view) }
219
+ end
220
+
212
221
  def reload_post(file)
213
222
  @main ||= Livetext.new
214
223
  @main.main.output = File.new("/tmp/WHOA","w") # FIXME srsly?
@@ -241,10 +250,22 @@ EOS
241
250
  error(err)
242
251
  end
243
252
 
244
- def make_slug(title, seq=nil)
245
- num = '%04d' % (seq || self.next_sequence) # FIXME can do better
253
+ def remove_post(num)
254
+ list = files_by_id(num)
255
+ result = system("rm -rf #{list.join(' ')}")
256
+ error_cant_delete(files) unless result
257
+ end
258
+
259
+ def post_exists?(num)
260
+ list = files_by_id(num)
261
+ list.empty? ? nil : list
262
+ end
263
+
264
+ def make_slug(title, postnum = nil)
265
+ postnum ||= self.next_sequence
266
+ num = '%04d' % postnum # FIXME can do better
246
267
  slug = title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
247
- "#{num}-#{slug}"
268
+ [postnum, "#{num}-#{slug}"]
248
269
  end
249
270
 
250
271
  def subdirs(dir)
@@ -252,4 +273,29 @@ EOS
252
273
  dirs.reject! {|x| ! File.directory?("#@root/views/#{x}") }
253
274
  dirs
254
275
  end
276
+
277
+ def create_dir(dir)
278
+ cmd = "mkdir -p #{dir} >/dev/null 2>&1"
279
+ result = system(cmd)
280
+ raise "Can't create #{dir}" unless result
281
+ end
282
+
283
+ def error(err) # FIXME - this is duplicated
284
+ str = "\n Error: #{err}"
285
+ puts str
286
+ puts err.backtrace # [0]
287
+ end
288
+
289
+ def interpolate(str)
290
+ wrap = "<<-EOS\n#{str}\nEOS"
291
+ eval wrap
292
+ end
293
+
294
+ def find_src_slugs
295
+ files = Dir.entries("#@root/src/").grep /\d\d\d\d.*.lt3$/
296
+ files.map! {|f| File.basename(f) }
297
+ files = files.sort.reverse
298
+ files
299
+ end
300
+
255
301
  end
data/test/repl.rb CHANGED
@@ -8,7 +8,7 @@ class TestREPL < Minitest::Test
8
8
  include RuneBlog::REPL
9
9
 
10
10
  def setup
11
- @blog = open_blog
11
+ @blog = RuneBlog.new
12
12
  end
13
13
 
14
14
  def test_001_cmd_help
@@ -112,5 +112,21 @@ class TestREPL < Minitest::Test
112
112
  assert @blog.views.sort == ["view1", "view2"]
113
113
  end
114
114
 
115
+ def test_011_create_delete_view
116
+ @blog.create_view("anotherview")
117
+ assert @blog.views.sort == ["anotherview", "view1", "view2"], "After create: #{@blog.views.sort.inspect}"
118
+ @blog.delete_view("anotherview", true)
119
+ assert @blog.views.sort == ["view1", "view2"], "After delete: #{@blog.views.sort.inspect}"
120
+ end
121
+
122
+ def test_012_create_remove_post # FIXME - several problems here
123
+ @blog.change_view("view2")
124
+ assert @blog.view == "view2"
125
+ before = @blog.posts.size
126
+ num = @blog.create_new_post("Uninteresting title", true)
127
+ assert @blog.posts.size == before + 1, "Don't see new post"
128
+ @blog.remove_post(num)
129
+ assert @blog.posts.size == before, "Failed to delete post"
130
+ end
115
131
  end
116
132
 
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.62
4
+ version: 0.0.63
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-18 00:00:00.000000000 Z
11
+ date: 2018-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: livetext