runeblog 0.0.65 → 0.0.66

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/data/VERSION +1 -1
  3. data/lib/repl.rb +35 -9
  4. data/lib/runeblog.rb +146 -34
  5. data/test/repl.rb +9 -7
  6. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 337899305625d6e47d1651fc7f5c74cbe01d9dac
4
- data.tar.gz: c115cf315621933d753bfdb663e7030506354df5
3
+ metadata.gz: adf4312a5e7a32552ee91aa3915429723f9ffbd6
4
+ data.tar.gz: 157c726b6db5384507a8813df016f25f729d4574
5
5
  SHA512:
6
- metadata.gz: f653637ca0fbbc59f34faf72b263546befc886a3bb10ec3569de9c4209bee45a30c7e267af30f297d5701b76e201955d48827cb87258e9695cd91012ddb348d2
7
- data.tar.gz: f56f552eb2475dd785d00b3ec2cb16b3bfa166a5bdc46adfcbbd3d19e908d8412d6db09a5a8322b6062c3519409c79f52e3f8801fee1236072dc0cddafa9abde
6
+ metadata.gz: 3eaf87eec7fd56c1efc5fd586f0fd154667c353b63890e9807500bd992cd138c9a55b3d1d5ae8b5659fc2de018a48adf0cbaef3371476881afbb4fbfe6f7c453
7
+ data.tar.gz: 58d33fe4ad47f8b0aaaa3e657b8a6a01755b6612dd8c65679cddf6cf61e58650d59ff0d2bb1a2ec321858fb0d12347d117632a2a5fb4b2d985dd11d3438685df
data/data/VERSION CHANGED
@@ -1 +1 @@
1
- RuneBlog v 0.0.65 2018-09-27
1
+ RuneBlog v 0.0.66 2018-09-28
data/lib/repl.rb CHANGED
@@ -34,7 +34,7 @@ module RuneBlog::REPL
34
34
  def cmd_preview(arg)
35
35
  reset_output
36
36
  check_empty(arg)
37
- local = @blog.viewdir(@blog.view) + "/index.html"
37
+ local = @blog.view.index
38
38
  result = system("open #{local}")
39
39
  raise CantOpen, local unless result
40
40
  rescue => err
@@ -42,6 +42,36 @@ module RuneBlog::REPL
42
42
  end
43
43
 
44
44
  def cmd_deploy(arg) # FIXME non-string return expected in caller?
45
+ reset_output
46
+ check_empty(arg)
47
+ @blog.view.deploy
48
+ user, server, sroot, spath = *@deploy[@blog.view]
49
+ if files.empty? # FIXME baloney
50
+ output! "No files to deploy"
51
+ return @out
52
+ end
53
+
54
+ output "Files:"
55
+ files.each {|f| output " #{f}\n" }
56
+ output_newline
57
+ dir = "#{sroot}/#{spath}"
58
+ # FIXME - may or may not already exist
59
+ result = system("ssh root@#{server} mkdir #{dir}")
60
+ # ^ needs -c??
61
+
62
+ cmd = "scp -r #{files.join(' ')} root@#{server}:#{dir} >/dev/null 2>&1"
63
+ output! "Deploying #{files.size} files...\n"
64
+ result = system(cmd)
65
+ raise "Problem occurred in deployment" unless result
66
+
67
+ File.write("#{vdir}/last_deployed", files)
68
+ output! "...finished.\n"
69
+ @out
70
+ rescue => err
71
+ error(err)
72
+ end
73
+
74
+ def old_cmd_deploy(arg) # FIXME non-string return expected in caller?
45
75
  # TBD clunky FIXME
46
76
  reset_output
47
77
  check_empty(arg)
@@ -110,19 +140,15 @@ module RuneBlog::REPL
110
140
  output "#{@blog.view}"
111
141
  return @out
112
142
  else
113
- list = @blog.views.grep /^#{arg}/
114
- if list.size == 1
115
- @blog.view = list.first
116
- output! "View: #{@blog.view}\n" if arg != @blog.view
117
- else
118
- output! "view #{arg.inspect} does not exist\n"
143
+ if @blog.view?(arg)
144
+ @blog.view = arg
145
+ output! "View: #{@blog.view}\n"
119
146
  end
120
147
  end
121
148
  @out
122
149
  rescue => err
123
150
  error(err)
124
151
  end
125
-
126
152
  def cmd_new_view(arg)
127
153
  reset_output
128
154
  @blog.create_view(arg)
@@ -219,7 +245,7 @@ module RuneBlog::REPL
219
245
  check_empty(arg)
220
246
  reset_output
221
247
  posts = @blog.posts # current view
222
- output @blog.view + ":\n"
248
+ output @blog.view.name + ":\n"
223
249
  if posts.empty?
224
250
  output! "No posts\n"
225
251
  else
data/lib/runeblog.rb CHANGED
@@ -20,7 +20,11 @@ def error(err) # FIXME - this is duplicated
20
20
  end
21
21
 
22
22
  class RuneBlog
23
- VERSION = "0.0.65"
23
+ VERSION = "0.0.66"
24
+
25
+ class << self
26
+ attr_accessor :blog
27
+ end
24
28
 
25
29
  Path = File.expand_path(File.join(File.dirname(__FILE__)))
26
30
  DefaultData = Path + "/../data/views/_default"
@@ -34,7 +38,7 @@ class RuneBlog
34
38
  PostTemplate = File.read(PostTemplatePath) rescue "not found"
35
39
 
36
40
  attr_reader :root, :views, :sequence
37
- attr_accessor :view # FIXME
41
+ attr_accessor :view # overridden
38
42
 
39
43
  def self.create_new_blog
40
44
  #-- what if data already exists?
@@ -48,22 +52,51 @@ class RuneBlog
48
52
  File.open("data/VERSION", "a") {|f| f.puts "\nBlog created: " + Time.now.to_s }
49
53
  end
50
54
 
55
+ def get_config(file)
56
+ lines = File.readlines(file).map(&:chomp)
57
+ root, view_name = *lines
58
+ end
59
+
51
60
  def initialize(cfg_file = ".blog") # assumes existing blog
52
- # What views are there? Deployment, etc.
53
- # Crude - FIXME later
61
+ # Crude - FIXME later - What views are there? Deployment, etc.
62
+ self.class.blog = self # Weird. Like a singleton - dumbass circular dependency?
63
+ @root, view_name = get_config(cfg_file)
64
+ @views = subdirs("#@root/views/").sort.map {|name| RuneBlog::View.new(name) }
65
+ @view = str2view(view_name)
66
+ @sequence = get_sequence
67
+ end
54
68
 
55
- lines = File.readlines(cfg_file).map {|x| x.chomp }
56
- @root = lines[0]
57
- @view = lines[1]
58
- dirs = subdirs("#@root/views/")
59
- @root = root
60
- @views = dirs
61
- @sequence = File.read(root + "/sequence").to_i
69
+ def view?(name)
70
+ views.any? {|x| x.name == name }
71
+ end
72
+
73
+ def view
74
+ @view
75
+ end
76
+
77
+ def str2view(str)
78
+ @views.find {|x| x.name == str }
79
+ end
80
+
81
+ def view=(arg)
82
+ case arg
83
+ when RuneBlog::View
84
+ @view = arg
85
+ when String
86
+ new_view = str2view(arg)
87
+ raise "Can't find view #{arg}" if new_view.nil?
88
+ @view = new_view
89
+ else
90
+ raise "#{arg.inspect} was not a View or a String"
91
+ end
92
+ end
93
+
94
+ def get_sequence
95
+ File.read(root + "/sequence").to_i
62
96
  end
63
97
 
64
98
  def next_sequence
65
- @sequence += 1
66
- File.open("#@root/sequence", "w") {|f| f.puts @sequence }
99
+ File.write("#@root/sequence", @sequence += 1)
67
100
  @sequence
68
101
  end
69
102
 
@@ -76,7 +109,8 @@ class RuneBlog
76
109
  end
77
110
 
78
111
  def create_view(arg)
79
- raise "view #{arg} already exists" if self.views.include?(arg)
112
+ names = self.views.map(&:to_s)
113
+ raise "view #{arg} already exists" if names.include?(arg)
80
114
 
81
115
  dir = @root + "/views/" + arg + "/"
82
116
  create_dir(dir + 'custom')
@@ -87,13 +121,13 @@ class RuneBlog
87
121
  File.write(dir + "custom/blog_trailer.html", RuneBlog::BlogTrailer)
88
122
  File.write(dir + "custom/post_template.html", RuneBlog::PostTemplate)
89
123
  File.write(dir + "last_deployed", "Initial creation")
90
- self.views << arg
124
+ @views << RuneBlog::View.new(arg)
91
125
  end
92
126
 
93
127
  def delete_view(name, force = false)
94
128
  if force
95
129
  system("rm -rf #@root/views/#{name}")
96
- @views -= [name]
130
+ @views -= [str2view(name)]
97
131
  end
98
132
  end
99
133
 
@@ -109,6 +143,7 @@ class RuneBlog
109
143
  # meh
110
144
  files = ["#{vdir}/index.html"]
111
145
  files += Dir.entries(vdir).grep(/^\d\d\d\d/).map {|x| "#{vdir}/#{x}" }
146
+ # Huh?
112
147
  files.reject! {|f| File.mtime(f) < File.mtime("#{vdir}/last_deployed") }
113
148
  end
114
149
 
@@ -120,7 +155,7 @@ class RuneBlog
120
155
  end
121
156
 
122
157
  def create_new_post(title, testing = false)
123
- post = RuneBlog::Post.new(title, @view)
158
+ post = RuneBlog::Post.new(title, @view.to_s)
124
159
  post.edit unless testing
125
160
  post.publish
126
161
  post.num
@@ -137,8 +172,9 @@ class RuneBlog
137
172
  end
138
173
 
139
174
  def posts
140
- dir = self.viewdir(@view)
175
+ dir = self.view.dir
141
176
  posts = Dir.entries(dir).grep(/^0.*/)
177
+ posts
142
178
  end
143
179
 
144
180
  def drafts
@@ -147,7 +183,7 @@ class RuneBlog
147
183
  end
148
184
 
149
185
  def change_view(view)
150
- @view = view # error checking?
186
+ self.view = view # error checking?
151
187
  end
152
188
 
153
189
  def process_post(file)
@@ -202,7 +238,7 @@ class RuneBlog
202
238
  posts.map! {|post| YAML.load(File.read("#{vdir}/#{post}/metadata.yaml")) }
203
239
  File.open("#{vdir}/index.html", "w") do |f|
204
240
  f.puts @bloghead
205
- posts.each {|post| f.puts posting(view, post) }
241
+ posts.each {|post| f.puts index_entry(view, post) }
206
242
  f.puts @blogtail
207
243
  end
208
244
  rescue => err
@@ -213,7 +249,7 @@ class RuneBlog
213
249
  self.views.each {|view| generate_index(view) }
214
250
  end
215
251
 
216
- def posting(view, meta)
252
+ def index_entry(view, meta)
217
253
  # FIXME clean up and generalize
218
254
  ref = "#{view}/#{meta.slug}/index.html"
219
255
  <<-HTML
@@ -226,8 +262,6 @@ class RuneBlog
226
262
  <br><br>
227
263
  <hr>
228
264
  HTML
229
- text = File.read(self.viewdir(view) + "custom/post_template.html")
230
- interpolate(text)
231
265
  end
232
266
 
233
267
  def rebuild_post(file)
@@ -273,12 +307,90 @@ end
273
307
 
274
308
  #######
275
309
 
276
- class RuneBlog::Post
310
+ class RuneBlog::Deployment
311
+ attr_reader :user, :server, :root, :path
277
312
 
278
- class << self
279
- attr_accessor :blog
313
+ def initialize(user, server, root, path, protocol = "http")
314
+ @blog = RuneBlog.blog
315
+ @user, @server, @root, @path =
316
+ user, server, root, path
317
+ end
318
+
319
+ def url
320
+ url = "#{protocol}://#{@server}/#{@path}"
321
+ end
322
+
323
+ def deploy(files)
324
+ reset_output
325
+ dir = "#@root/#@path"
326
+ result = system("ssh -c #@user@#@server mkdir #{dir}")
327
+ list = files.join(' ')
328
+ cmd = "scp -r #{list} root@#{server}:#{dir} >/dev/null 2>&1"
329
+ output! "Deploying #{files.size} files...\n"
330
+ result = system(cmd)
331
+ raise "Problem occurred in deployment" unless result
332
+
333
+ File.write("#{@blog.view.dir}/last_deployed", files)
334
+ output! "...finished.\n"
335
+ @out
336
+ end
337
+ end
338
+
339
+ #######
340
+
341
+ class RuneBlog::View
342
+ attr_reader :name, :state
343
+ attr_accessor :deploy
344
+
345
+ def initialize(name)
346
+ raise "RuneBlog.blog is not set!" if RuneBlog.blog.nil?
347
+ @blog = RuneBlog.blog
348
+ @name = name
349
+ # How read deployment info??
350
+ end
351
+
352
+ def dir
353
+ @blog.root + "/views/#@name/"
354
+ end
355
+
356
+ def index
357
+ dir + "index.html"
358
+ end
359
+
360
+ def to_s
361
+ @name
362
+ end
363
+
364
+ def files(recent = false)
365
+ vdir = dir()
366
+ files = [index()]
367
+ others = Dir.entries(vdir).grep(/^\d\d\d\d/)
368
+ files += others.map {|x| "#{vdir}/#{x}" }
369
+ files.reject! {|f| recent?(f) } if recent
370
+ files
280
371
  end
281
372
 
373
+ def deploy
374
+ # ?? @blog.view.deployment.deploy
375
+ # output "Files:"
376
+ # files.each {|f| output " #{f}\n" }
377
+ output_newline
378
+ list = files(true)
379
+ @deployer.deploy(list)
380
+ rescue => err
381
+ error(err)
382
+ end
383
+
384
+ def recent?(file)
385
+ File.mtime(file) < File.mtime("#{dir()}/last_deployed")
386
+ end
387
+ end
388
+
389
+ #######
390
+
391
+
392
+ class RuneBlog::Post
393
+
282
394
  attr_reader :id, :title, :date, :views, :num, :slug
283
395
 
284
396
  def self.files(num, root)
@@ -287,20 +399,19 @@ class RuneBlog::Post
287
399
  result
288
400
  end
289
401
 
290
- def initialize(title, view)
291
- raise "Post.blog is not set!" if RuneBlog::Post.blog.nil?
292
- @blog = RuneBlog::Post.blog
402
+ def initialize(title, view_name)
403
+ raise "RuneBlog.blog is not set!" if RuneBlog.blog.nil?
404
+ @blog = RuneBlog.blog
293
405
  @title = title
294
- @view = view
406
+ @view = @blog.str2view(view_name)
295
407
  @num, @slug = make_slug
296
- ##
297
408
  date = Time.now.strftime("%Y-%m-%d")
298
409
  template = <<-EOS.gsub(/^ */, "")
299
410
  .mixin liveblog
300
411
 
301
412
  .title #{title}
302
413
  .pubdate #{date}
303
- .views #{view}
414
+ .views #@view
304
415
 
305
416
  .teaser
306
417
  Teaser goes here.
@@ -325,8 +436,9 @@ class RuneBlog::Post
325
436
  @meta = livetext.process_file(@draft, binding)
326
437
  raise "process_file returned nil" if @meta.nil?
327
438
 
328
- @meta.views.each do |view| # Create dir using slug (index.html, metadata?)
329
- vdir = @blog.viewdir(view)
439
+ @meta.views.each do |view_name| # Create dir using slug (index.html, metadata?)
440
+ view = @blog.str2view(view_name)
441
+ vdir = view.dir
330
442
  dir = vdir + @slug + "/"
331
443
  Dir.mkdir(dir)
332
444
  Dir.chdir(dir) do
data/test/repl.rb CHANGED
@@ -9,7 +9,6 @@ class TestREPL < Minitest::Test
9
9
 
10
10
  def setup
11
11
  @blog = RuneBlog.new
12
- RuneBlog::Post.blog = @blog
13
12
  end
14
13
 
15
14
  def test_001_cmd_help
@@ -101,28 +100,31 @@ class TestREPL < Minitest::Test
101
100
  end
102
101
 
103
102
  def test_008_current_view
104
- assert @blog.view == "view1", "Current view seems wrong (#{@blog.view}, not view1)"
103
+ assert @blog.view.to_s == "view1", "Current view seems wrong (#{@blog.view}, not view1)"
105
104
  end
106
105
 
107
106
  def test_009_change_view
108
107
  assert @blog.change_view("view2")
109
- assert @blog.view == "view2", "Current view seems wrong (#{@blog.view}, not view2)"
108
+ assert @blog.view.to_s == "view2", "Current view seems wrong (#{@blog.view}, not view2)"
110
109
  end
111
110
 
112
111
  def test_010_accessors
113
- assert @blog.views.sort == ["view1", "view2"]
112
+ sorted_views = @blog.views.map(&:to_s).sort
113
+ assert sorted_views == ["view1", "view2"], "Got: #{sorted_views.inspect}"
114
114
  end
115
115
 
116
116
  def test_011_create_delete_view
117
117
  @blog.create_view("anotherview")
118
- assert @blog.views.sort == ["anotherview", "view1", "view2"], "After create: #{@blog.views.sort.inspect}"
118
+ sorted_views = @blog.views.map(&:to_s).sort
119
+ assert sorted_views == ["anotherview", "view1", "view2"], "After create: #{sorted_views.inspect}"
119
120
  @blog.delete_view("anotherview", true)
120
- assert @blog.views.sort == ["view1", "view2"], "After delete: #{@blog.views.sort.inspect}"
121
+ sorted_views = @blog.views.map(&:to_s).sort
122
+ assert sorted_views == ["view1", "view2"], "After delete: #{sorted_views.inspect}"
121
123
  end
122
124
 
123
125
  def test_012_create_remove_post # FIXME - several problems here
124
126
  @blog.change_view("view2")
125
- assert @blog.view == "view2"
127
+ assert @blog.view.to_s == "view2", "Expected view2"
126
128
  before = @blog.posts.size
127
129
  num = @blog.create_new_post("Uninteresting title", true)
128
130
  assert @blog.posts.size == before + 1, "Don't see new post"
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.65
4
+ version: 0.0.66
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-27 00:00:00.000000000 Z
11
+ date: 2018-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: livetext