runeblog 0.0.29 → 0.0.30

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/bin/blog +3 -1
  3. data/data/VERSION +1 -1
  4. data/lib/repl.rb +428 -0
  5. data/lib/runeblog.rb +1 -424
  6. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2c82a9c5e7df6b702d233dfb00327811b395e010
4
- data.tar.gz: 18512ccba91d2c1edf35dd66cdd74ea2518b8a7e
3
+ metadata.gz: ca084cb0f44eb31904d67f7383c9f0283c0c2808
4
+ data.tar.gz: 35ba1e215e33565207549b71f50f10e414de0d64
5
5
  SHA512:
6
- metadata.gz: 4386f8ec0aa09faeda0649193e7af2e9e514b50b124446d459a66dec4aef542b6515df95d7475401e7a99c947b02e9ae72efeef21a5a488233e99712207618b5
7
- data.tar.gz: 3717b99dfbd2eb7352912f5f5b72eead0ccd7a76e6c4f7a8eada1a57b16745d698c6c6f03c62d50394c188ed729d2b5164f4e1b1964f26176b0ee4af01e70902
6
+ metadata.gz: 8f638fde1609ad5b567a2989d434de1f542c72bced11a6177acb87cdb69188734d2ac785f38f6919201836d772f3e2d9d1f653cd85e69e344b49f9f06b7d5af6
7
+ data.tar.gz: a8e4b677be56cbfb942fef36cfac5c92fa0fc08b08086fc69be7b9bd8e596cd0dfc79fd78c3ac2adaa155f7e24ede32594a4c54a04020586fd81ceac3aea2a5d
data/bin/blog CHANGED
@@ -2,10 +2,12 @@
2
2
 
3
3
  $: << "./lib"
4
4
 
5
- require 'runeblog'
5
+ require 'repl'
6
6
 
7
7
  trap("INT") { }
8
8
 
9
+ include RuneBlog::REPL
10
+
9
11
  def execute_command
10
12
  case @meth
11
13
  when :help, :quit, :new_post, :list_views, :relink, :rebuild, :version,
data/data/VERSION CHANGED
@@ -1 +1 @@
1
- RuneBlog v 0.0.29 2017-05-10
1
+ RuneBlog v 0.0.30 2017-05-11
data/lib/repl.rb ADDED
@@ -0,0 +1,428 @@
1
+ require 'runeblog'
2
+
3
+ module RuneBlog::REPL
4
+
5
+ def clear
6
+ puts "\e[H\e[2J" # clear screen
7
+ end
8
+
9
+ def red(text)
10
+ "\e[31m#{text}\e[0m"
11
+ end
12
+
13
+ def blue(text)
14
+ "\e[34m#{text}\e[0m"
15
+ end
16
+
17
+ def bold(str)
18
+ "\e[1m#{str}\e[22m"
19
+ end
20
+
21
+ def interpolate(str)
22
+ wrap = "<<-EOS\n#{str}\nEOS"
23
+ eval wrap
24
+ end
25
+
26
+ def colored_slug(slug)
27
+ red(slug[0..3])+blue(slug[4..-1])
28
+ end
29
+
30
+
31
+ ### ask
32
+
33
+ def ask(prompt, meth = :to_s)
34
+ print prompt
35
+ STDOUT.flush
36
+ STDIN.gets.chomp.send(meth)
37
+ end
38
+
39
+ ### quit
40
+
41
+ def quit
42
+ puts
43
+ exit
44
+ end
45
+
46
+ ### version
47
+
48
+ def version
49
+ puts "\n " + RuneBlog::VERSION
50
+ end
51
+
52
+ ### new_blog!
53
+
54
+ def new_blog!
55
+ unless File.exist?(".blog")
56
+ yn = ask(red(" No .blog found. Create new blog? "))
57
+ if yn.upcase == "Y"
58
+ #-- what if data already exists?
59
+ system("cp -r #{RuneBlog::DefaultData} .")
60
+ File.open(".blog", "w") do |f|
61
+ f.puts "data"
62
+ f.puts "no_default"
63
+ end
64
+ File.open("data/VERSION", "a") {|f| f.puts "\nBlog created: " + Time.now.to_s }
65
+ end
66
+ end
67
+ end
68
+
69
+ ### make_slug
70
+
71
+ def make_slug(title, seq=nil)
72
+ num = '%04d' % (seq || @config.next_sequence) # FIXME can do better
73
+ slug = title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
74
+ "#{num}-#{slug}"
75
+ end
76
+
77
+ ### read_config
78
+
79
+ def read_config
80
+ # Crude - FIXME later
81
+ cfg_file = ".blog"
82
+ new_blog! unless File.exist?(cfg_file)
83
+ @config = RuneBlog::Config.new(".blog")
84
+
85
+ @view = @config.view # current view
86
+ @sequence = @config.sequence
87
+ @root = @config.root
88
+ end
89
+
90
+ ### create_empty_post
91
+
92
+ def create_empty_post
93
+ @template = <<-EOS
94
+ .mixin liveblog
95
+
96
+ .liveblog_version
97
+
98
+ .title #@title
99
+ .pubdate #@date
100
+ .views #@view
101
+
102
+ Teaser goes here.
103
+ .readmore
104
+ Remainder of post goes here.
105
+ EOS
106
+
107
+ @slug = make_slug(@title)
108
+ @fname = @slug + ".lt3"
109
+ File.open("#@root/src/#@fname", "w") {|f| f.puts @template }
110
+ @fname
111
+ end
112
+
113
+ ### edit_post
114
+
115
+ def edit_post(file)
116
+ system("vi #@root/src/#{file} +8 ")
117
+ end
118
+
119
+ ### open_remote
120
+
121
+ def open_remote
122
+ @deploy ||= {}
123
+ unless @deploy[@view]
124
+ puts red("\n Deploy first.")
125
+ return
126
+ end
127
+ lines = @deploy[@view]
128
+ user, server, sroot, spath = *lines
129
+ system("open 'http://#{server}/#{spath}'")
130
+ end
131
+
132
+ ### open_local
133
+
134
+ def open_local
135
+ system("open #{@config.viewdir(@view)}/index.html")
136
+ end
137
+
138
+ def deploy
139
+ # TBD clunky FIXME
140
+ @deploy ||= {}
141
+ deployment = @config.viewdir(@view) + "deploy"
142
+ lines = File.readlines(deployment).map {|x| x.chomp }
143
+ @deploy[@view] = lines
144
+ user, server, sroot, spath = *lines
145
+ vdir = @config.viewdir(@view)
146
+ files = ["#{vdir}/index.html"]
147
+ files += Dir.entries(vdir).grep(/^\d\d\d\d/).map {|x| "#{vdir}/#{x}" }
148
+ files.reject! {|f| File.mtime(f) < File.mtime("#{vdir}/last_deployed") }
149
+ puts "\n Files:"
150
+ files.each {|f| puts " " + f }
151
+ puts
152
+ dir = "#{sroot}/#{spath}"
153
+ cmd = "scp -r #{files.join(' ')} root@#{server}:#{dir} >/dev/null 2>&1"
154
+ print red("\n Deploying #{files.size} files... ")
155
+ # puts cmd
156
+ system(cmd)
157
+ File.write("#{vdir}/last_deployed", files)
158
+ puts red("finished.")
159
+ end
160
+
161
+ ### process_post
162
+
163
+ def process_post(file)
164
+ @main ||= Livetext.new
165
+ @main.main.output = File.new("/tmp/WHOA","w")
166
+ # puts " Processing: #{Dir.pwd} :: #{file}"
167
+ path = @root + "/src/#{file}"
168
+ @meta = @main.process_file(path)
169
+ @meta.slug = make_slug(@meta.title, @config.sequence)
170
+ @meta.slug = file.sub(/.lt3$/, "")
171
+ @meta
172
+ end
173
+
174
+ ### reload_post
175
+
176
+ def reload_post(file)
177
+ @main ||= Livetext.new
178
+ @main.main.output = File.new("/tmp/WHOA","w")
179
+ @meta = process_post(file)
180
+ @meta.slug = file.sub(/.lt3$/, "")
181
+ @meta
182
+ end
183
+
184
+ ### posting
185
+
186
+ def posting(view, meta)
187
+ ref = "#{view}/#{meta.slug}/index.html"
188
+ <<-HTML
189
+ <br>
190
+ <font size=+1>#{meta.pubdate}&nbsp;&nbsp;</font>
191
+ <font size=+2 color=blue><a href=../#{ref} style="text-decoration: none">#{meta.title}</font></a>
192
+ <br>
193
+ #{meta.teaser}
194
+ <a href=../#{ref} style="text-decoration: none">Read more...</a>
195
+ <br><br>
196
+ <hr>
197
+ HTML
198
+ end
199
+
200
+ ### generate_index
201
+
202
+ def generate_index(view)
203
+ # Gather all posts, create list
204
+ vdir = "#@root/views/#{view}"
205
+ posts = Dir.entries(vdir).grep /^\d\d\d\d/
206
+ posts = posts.sort.reverse
207
+
208
+ # Add view header/trailer
209
+ head = File.read("#{vdir}/custom/blog_header.html") rescue RuneBlog::BlogHeader
210
+ tail = File.read("#{vdir}/custom/blog_trailer.html") rescue RuneBlog::BlogTrailer
211
+ @bloghead = interpolate(head)
212
+ @blogtail = interpolate(tail)
213
+
214
+ # Output view
215
+ posts.map! {|post| YAML.load(File.read("#{vdir}/#{post}/metadata.yaml")) }
216
+ File.open("#{vdir}/index.html", "w") do |f|
217
+ f.puts @bloghead
218
+ posts.each {|post| f.puts posting(view, post) }
219
+ f.puts @blogtail
220
+ end
221
+ end
222
+
223
+ ### link_post_view
224
+
225
+ def link_post_view(view)
226
+ # Create dir using slug (index.html, metadata?)
227
+ vdir = @config.viewdir(view)
228
+ dir = vdir + @meta.slug + "/"
229
+ cmd = "mkdir -p #{dir}" #-- FIXME what if this exists??
230
+ system(cmd)
231
+ File.write("#{dir}/metadata.yaml", @meta.to_yaml)
232
+ template = File.read(vdir + "custom/post_template.html")
233
+ post = interpolate(template)
234
+ File.write(dir + "index.html", post)
235
+ generate_index(view)
236
+ end
237
+
238
+ ### link_post
239
+
240
+ def link_post(meta)
241
+ puts " #{colored_slug(meta.slug)}"
242
+ # First gather the views
243
+ views = meta.views
244
+ print " Views: "
245
+ views.each do |view|
246
+ print "#{view} "
247
+ link_post_view(view)
248
+ end
249
+ puts
250
+ end
251
+
252
+ ### rebuild
253
+
254
+ def rebuild
255
+ puts
256
+ files = Dir.entries("#@root/src/").grep /\d\d\d\d.*.lt3$/
257
+ files.map! {|f| File.basename(f) }
258
+ files = files.sort.reverse
259
+ files.each do |file|
260
+ reload_post(file)
261
+ link_post(@meta)
262
+ publish_post
263
+ end
264
+ end
265
+
266
+ ### relink
267
+
268
+ def relink
269
+ @config.views.each do |view|
270
+ generate_index(view)
271
+ end
272
+ end
273
+
274
+ ### publish?
275
+
276
+ def publish?
277
+ yn = ask(red(" Publish? y/n "))
278
+ yn.upcase == "Y"
279
+ end
280
+
281
+ ### publish_post
282
+
283
+ def publish_post
284
+ # Grab destination data
285
+ # scp changed files over
286
+ # puts " Publish: Not implemented yet"
287
+ end
288
+
289
+ ### list_views
290
+
291
+ def list_views
292
+ abort "Config file not read" unless @config
293
+ puts
294
+ @config.views.each {|v| puts " #{v}" }
295
+ end
296
+
297
+ ### change_view
298
+
299
+ def change_view(arg = nil)
300
+ if arg.nil?
301
+ puts "\n #@view"
302
+ elsif @config.views.include?(arg)
303
+ @view = arg
304
+ else
305
+ puts "view #{arg.inspect} does not exist"
306
+ end
307
+ end
308
+
309
+ ### new_view
310
+
311
+ def new_view(arg = nil)
312
+ arg = nil if arg == ""
313
+ read_config unless @config
314
+ arg ||= ask("New view: ") # check validity later
315
+ raise "view #{arg} already exists" if @config.views.include?(arg)
316
+
317
+ dir = @root + "/views/" + arg + "/"
318
+ cmd = "mkdir -p #{dir + 'custom'}"
319
+ system(cmd)
320
+ File.write(dir + "custom/blog_header.html", RuneBlog::BlogHeader)
321
+ File.write(dir + "custom/blog_trailer.html", RuneBlog::BlogTrailer)
322
+ File.write(dir + "last_deployed", "Initial creation")
323
+ @config.views << arg
324
+ end
325
+
326
+ ### import
327
+
328
+ def import(arg = nil)
329
+ read_config unless @config
330
+ arg = nil if arg == ""
331
+ arg ||= ask("Filename: ") # check validity later
332
+ name = arg
333
+ grep = `grep ^.title #{name}`
334
+ @title = grep.sub(/^.title /, "")
335
+ @slug = make_slug(@title)
336
+ @fname = @slug + ".lt3"
337
+ system("cp #{name} #@root/src/#@fname")
338
+ edit_post(@fname)
339
+ process_post(@fname)
340
+ if publish?
341
+ link_post(@meta)
342
+ publish_post
343
+ end
344
+ end
345
+
346
+ ### new_post
347
+
348
+ def new_post
349
+ read_config unless @config
350
+ @title = ask("Title: ")
351
+ @today = Time.now.strftime("%Y%m%d")
352
+ @date = Time.now.strftime("%Y-%m-%d")
353
+
354
+ file = create_empty_post
355
+ edit_post(file)
356
+ # file = @root + "/src/" + file
357
+ process_post(file) #- FIXME handle each view
358
+ if publish?
359
+ link_post(@meta)
360
+ publish_post
361
+ end
362
+ end
363
+
364
+ ### remove_post
365
+
366
+ #-- FIXME affects linking, building, deployment...
367
+
368
+ def remove_post(arg)
369
+ id = Integer(arg) rescue raise("'#{arg}' is not an integer")
370
+ tag = "#{'%04d' % id}-"
371
+ files = Find.find(@root).to_a
372
+ files = files.grep(/#{tag}/)
373
+ if files.empty?
374
+ puts red("\n No such post found")
375
+ return
376
+ end
377
+ puts
378
+ files.each {|f| puts " #{f}" }
379
+ ques = files.size > 1 ? "\n Delete all these? " : "\n Delete? "
380
+ yn = ask red(ques)
381
+ if yn.downcase == "y" #-- maybe implement trash later?
382
+ system("rm -rf #{files.join(' ')}")
383
+ puts red("\n Deleted")
384
+ else
385
+ puts red("\n No action taken")
386
+ end
387
+ rescue => err
388
+ puts err
389
+ puts
390
+ end
391
+
392
+ ### list_posts
393
+
394
+ def list_posts
395
+ dir = @config.viewdir(@view)
396
+ Dir.chdir(dir) do
397
+ posts = Dir.entries(".").grep(/^0.*/)
398
+ puts
399
+ if posts.empty?
400
+ puts " No posts"
401
+ else
402
+ posts.each {|post| puts " #{colored_slug(post)}" }
403
+ end
404
+ end
405
+ rescue
406
+ puts "Oops? cwd = #{Dir.pwd} dir = #{dir}"
407
+ exit
408
+ end
409
+
410
+ ### list_drafts
411
+
412
+ def list_drafts
413
+ dir = "#@root/src"
414
+ Dir.chdir(dir) do
415
+ posts = Dir.entries(".").grep(/^0.*.lt3/)
416
+ puts
417
+ if posts.empty?
418
+ puts " No posts"
419
+ else
420
+ posts.each {|post| puts " #{colored_slug(post.sub(/.lt3$/, ""))}" }
421
+ end
422
+ end
423
+ rescue
424
+ puts "Oops? cwd = #{Dir.pwd} dir = #{dir}"
425
+ exit
426
+ end
427
+
428
+ end
data/lib/runeblog.rb CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  class RuneBlog
3
- VERSION = "0.0.29"
3
+ VERSION = "0.0.30"
4
4
 
5
5
  Path = File.expand_path(File.join(File.dirname(__FILE__)))
6
6
  DefaultData = Path + "/../data"
@@ -45,426 +45,3 @@ require 'rubygems'
45
45
  require 'ostruct'
46
46
  require 'livetext'
47
47
 
48
- def clear
49
- puts "\e[H\e[2J" # clear screen
50
- end
51
-
52
- def red(text)
53
- "\e[31m#{text}\e[0m"
54
- end
55
-
56
- def blue(text)
57
- "\e[34m#{text}\e[0m"
58
- end
59
-
60
- def bold(str)
61
- "\e[1m#{str}\e[22m"
62
- end
63
-
64
- def interpolate(str)
65
- wrap = "<<-EOS\n#{str}\nEOS"
66
- eval wrap
67
- end
68
-
69
- def colored_slug(slug)
70
- red(slug[0..3])+blue(slug[4..-1])
71
- end
72
-
73
-
74
- ### ask
75
-
76
- def ask(prompt, meth = :to_s)
77
- print prompt
78
- STDOUT.flush
79
- STDIN.gets.chomp.send(meth)
80
- end
81
-
82
- ### quit
83
-
84
- def quit
85
- puts
86
- exit
87
- end
88
-
89
- ### version
90
-
91
- def version
92
- puts "\n " + RuneBlog::VERSION
93
- end
94
-
95
- ### new_blog!
96
-
97
- def new_blog!
98
- unless File.exist?(".blog")
99
- yn = ask(red(" No .blog found. Create new blog? "))
100
- if yn.upcase == "Y"
101
- #-- what if data already exists?
102
- system("cp -r #{RuneBlog::DefaultData} .")
103
- File.open(".blog", "w") do |f|
104
- f.puts "data"
105
- f.puts "no_default"
106
- end
107
- File.open("data/VERSION", "a") {|f| f.puts "\nBlog created: " + Time.now.to_s }
108
- end
109
- end
110
- end
111
-
112
- ### make_slug
113
-
114
- def make_slug(title, seq=nil)
115
- num = '%04d' % (seq || @config.next_sequence) # FIXME can do better
116
- slug = title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
117
- "#{num}-#{slug}"
118
- end
119
-
120
- ### read_config
121
-
122
- def read_config
123
- # Crude - FIXME later
124
- cfg_file = ".blog"
125
- new_blog! unless File.exist?(cfg_file)
126
- @config = RuneBlog::Config.new(".blog")
127
-
128
- @view = @config.view # current view
129
- @sequence = @config.sequence
130
- @root = @config.root
131
- end
132
-
133
- ### create_empty_post
134
-
135
- def create_empty_post
136
- @template = <<-EOS
137
- .mixin liveblog
138
-
139
- .liveblog_version
140
-
141
- .title #@title
142
- .pubdate #@date
143
- .views #@view
144
-
145
- Teaser goes here.
146
- .readmore
147
- Remainder of post goes here.
148
- EOS
149
-
150
- @slug = make_slug(@title)
151
- @fname = @slug + ".lt3"
152
- File.open("#@root/src/#@fname", "w") {|f| f.puts @template }
153
- @fname
154
- end
155
-
156
- ### edit_post
157
-
158
- def edit_post(file)
159
- system("vi #@root/src/#{file} +8 ")
160
- end
161
-
162
- ### open_remote
163
-
164
- def open_remote
165
- @deploy ||= {}
166
- unless @deploy[@view]
167
- puts red("\n Deploy first.")
168
- return
169
- end
170
- lines = @deploy[@view]
171
- user, server, sroot, spath = *lines
172
- system("open 'http://#{server}/#{spath}'")
173
- end
174
-
175
- ### open_local
176
-
177
- def open_local
178
- system("open #{@config.viewdir(@view)}/index.html")
179
- end
180
-
181
- def deploy
182
- # TBD clunky FIXME
183
- @deploy ||= {}
184
- deployment = @config.viewdir(@view) + "deploy"
185
- lines = File.readlines(deployment).map {|x| x.chomp }
186
- @deploy[@view] = lines
187
- user, server, sroot, spath = *lines
188
- vdir = @config.viewdir(@view)
189
- files = ["#{vdir}/index.html"]
190
- files += Dir.entries(vdir).grep(/^\d\d\d\d/).map {|x| "#{vdir}/#{x}" }
191
- files.reject! {|f| File.mtime(f) < File.mtime("#{vdir}/last_deployed") }
192
- puts "\n Files:"
193
- files.each {|f| puts " " + f }
194
- puts
195
- dir = "#{sroot}/#{spath}"
196
- cmd = "scp -r #{files.join(' ')} root@#{server}:#{dir} >/dev/null 2>&1"
197
- print red("\n Deploying #{files.size} files... ")
198
- # puts cmd
199
- system(cmd)
200
- File.write("#{vdir}/last_deployed", files)
201
- puts red("finished.")
202
- end
203
-
204
- ### process_post
205
-
206
- def process_post(file)
207
- @main ||= Livetext.new
208
- @main.main.output = File.new("/tmp/WHOA","w")
209
- # puts " Processing: #{Dir.pwd} :: #{file}"
210
- path = @root + "/src/#{file}"
211
- @meta = @main.process_file(path)
212
- @meta.slug = make_slug(@meta.title, @config.sequence)
213
- @meta.slug = file.sub(/.lt3$/, "")
214
- @meta
215
- end
216
-
217
- ### reload_post
218
-
219
- def reload_post(file)
220
- @main ||= Livetext.new
221
- @main.main.output = File.new("/tmp/WHOA","w")
222
- @meta = process_post(file)
223
- @meta.slug = file.sub(/.lt3$/, "")
224
- @meta
225
- end
226
-
227
- ### posting
228
-
229
- def posting(view, meta)
230
- ref = "#{view}/#{meta.slug}/index.html"
231
- <<-HTML
232
- <br>
233
- <font size=+1>#{meta.pubdate}&nbsp;&nbsp;</font>
234
- <font size=+2 color=blue><a href=../#{ref} style="text-decoration: none">#{meta.title}</font></a>
235
- <br>
236
- #{meta.teaser}
237
- <a href=../#{ref} style="text-decoration: none">Read more...</a>
238
- <br><br>
239
- <hr>
240
- HTML
241
- end
242
-
243
- ### generate_index
244
-
245
- def generate_index(view)
246
- # Gather all posts, create list
247
- vdir = "#@root/views/#{view}"
248
- posts = Dir.entries(vdir).grep /^\d\d\d\d/
249
- posts = posts.sort.reverse
250
-
251
- # Add view header/trailer
252
- head = File.read("#{vdir}/custom/blog_header.html") rescue RuneBlog::BlogHeader
253
- tail = File.read("#{vdir}/custom/blog_trailer.html") rescue RuneBlog::BlogTrailer
254
- @bloghead = interpolate(head)
255
- @blogtail = interpolate(tail)
256
-
257
- # Output view
258
- posts.map! {|post| YAML.load(File.read("#{vdir}/#{post}/metadata.yaml")) }
259
- File.open("#{vdir}/index.html", "w") do |f|
260
- f.puts @bloghead
261
- posts.each {|post| f.puts posting(view, post) }
262
- f.puts @blogtail
263
- end
264
- end
265
-
266
- ### link_post_view
267
-
268
- def link_post_view(view)
269
- # Create dir using slug (index.html, metadata?)
270
- vdir = @config.viewdir(view)
271
- dir = vdir + @meta.slug + "/"
272
- cmd = "mkdir -p #{dir}" #-- FIXME what if this exists??
273
- system(cmd)
274
- File.write("#{dir}/metadata.yaml", @meta.to_yaml)
275
- template = File.read(vdir + "custom/post_template.html")
276
- post = interpolate(template)
277
- File.write(dir + "index.html", post)
278
- generate_index(view)
279
- end
280
-
281
- ### link_post
282
-
283
- def link_post(meta)
284
- puts " #{colored_slug(meta.slug)}"
285
- # First gather the views
286
- views = meta.views
287
- print " Views: "
288
- views.each do |view|
289
- print "#{view} "
290
- link_post_view(view)
291
- end
292
- puts
293
- end
294
-
295
- ### rebuild
296
-
297
- def rebuild
298
- puts
299
- files = Dir.entries("#@root/src/").grep /\d\d\d\d.*.lt3$/
300
- files.map! {|f| File.basename(f) }
301
- files = files.sort.reverse
302
- files.each do |file|
303
- reload_post(file)
304
- link_post(@meta)
305
- publish_post
306
- end
307
- end
308
-
309
- ### relink
310
-
311
- def relink
312
- @config.views.each do |view|
313
- generate_index(view)
314
- end
315
- end
316
-
317
- ### publish?
318
-
319
- def publish?
320
- yn = ask(red(" Publish? y/n "))
321
- yn.upcase == "Y"
322
- end
323
-
324
- ### publish_post
325
-
326
- def publish_post
327
- # Grab destination data
328
- # scp changed files over
329
- # puts " Publish: Not implemented yet"
330
- end
331
-
332
- ### list_views
333
-
334
- def list_views
335
- abort "Config file not read" unless @config
336
- puts
337
- @config.views.each {|v| puts " #{v}" }
338
- end
339
-
340
- ### change_view
341
-
342
- def change_view(arg = nil)
343
- if arg.nil?
344
- puts "\n #@view"
345
- elsif @config.views.include?(arg)
346
- @view = arg
347
- else
348
- puts "view #{arg.inspect} does not exist"
349
- end
350
- end
351
-
352
- ### new_view
353
-
354
- def new_view(arg = nil)
355
- arg = nil if arg == ""
356
- read_config unless @config
357
- arg ||= ask("New view: ") # check validity later
358
- raise "view #{arg} already exists" if @config.views.include?(arg)
359
-
360
- dir = @root + "/views/" + arg + "/"
361
- cmd = "mkdir -p #{dir + 'custom'}"
362
- system(cmd)
363
- File.write(dir + "custom/blog_header.html", RuneBlog::BlogHeader)
364
- File.write(dir + "custom/blog_trailer.html", RuneBlog::BlogTrailer)
365
- File.write(dir + "last_deployed", "Initial creation")
366
- @config.views << arg
367
- end
368
-
369
- ### import
370
-
371
- def import(arg = nil)
372
- read_config unless @config
373
- arg = nil if arg == ""
374
- arg ||= ask("Filename: ") # check validity later
375
- name = arg
376
- grep = `grep ^.title #{name}`
377
- @title = grep.sub(/^.title /, "")
378
- @slug = make_slug(@title)
379
- @fname = @slug + ".lt3"
380
- system("cp #{name} #@root/src/#@fname")
381
- edit_post(@fname)
382
- process_post(@fname)
383
- if publish?
384
- link_post(@meta)
385
- publish_post
386
- end
387
- end
388
-
389
- ### new_post
390
-
391
- def new_post
392
- read_config unless @config
393
- @title = ask("Title: ")
394
- @today = Time.now.strftime("%Y%m%d")
395
- @date = Time.now.strftime("%Y-%m-%d")
396
-
397
- file = create_empty_post
398
- edit_post(file)
399
- # file = @root + "/src/" + file
400
- process_post(file) #- FIXME handle each view
401
- if publish?
402
- link_post(@meta)
403
- publish_post
404
- end
405
- end
406
-
407
- ### remove_post
408
-
409
- #-- FIXME affects linking, building, deployment...
410
-
411
- def remove_post(arg)
412
- id = Integer(arg) rescue raise("'#{arg}' is not an integer")
413
- tag = "#{'%04d' % id}-"
414
- files = Find.find(@root).to_a
415
- files = files.grep(/#{tag}/)
416
- if files.empty?
417
- puts red("\n No such post found")
418
- return
419
- end
420
- puts
421
- files.each {|f| puts " #{f}" }
422
- ques = files.size > 1 ? "\n Delete all these? " : "\n Delete? "
423
- yn = ask red(ques)
424
- if yn.downcase == "y" #-- maybe implement trash later?
425
- system("rm -rf #{files.join(' ')}")
426
- puts red("\n Deleted")
427
- else
428
- puts red("\n No action taken")
429
- end
430
- rescue => err
431
- puts err
432
- puts
433
- end
434
-
435
- ### list_posts
436
-
437
- def list_posts
438
- dir = @config.viewdir(@view)
439
- Dir.chdir(dir) do
440
- posts = Dir.entries(".").grep(/^0.*/)
441
- puts
442
- if posts.empty?
443
- puts " No posts"
444
- else
445
- posts.each {|post| puts " #{colored_slug(post)}" }
446
- end
447
- end
448
- rescue
449
- puts "Oops? cwd = #{Dir.pwd} dir = #{dir}"
450
- exit
451
- end
452
-
453
- ### list_drafts
454
-
455
- def list_drafts
456
- dir = "#@root/src"
457
- Dir.chdir(dir) do
458
- posts = Dir.entries(".").grep(/^0.*.lt3/)
459
- puts
460
- if posts.empty?
461
- puts " No posts"
462
- else
463
- posts.each {|post| puts " #{colored_slug(post.sub(/.lt3$/, ""))}" }
464
- end
465
- end
466
- rescue
467
- puts "Oops? cwd = #{Dir.pwd} dir = #{dir}"
468
- exit
469
- end
470
-
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.29
4
+ version: 0.0.30
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hal Fulton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-10 00:00:00.000000000 Z
11
+ date: 2017-05-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A blog system based on Ruby and Livetext
14
14
  email: rubyhacker@gmail.com
@@ -26,6 +26,7 @@ files:
26
26
  - data/views/_default/custom/blog_trailer.html
27
27
  - data/views/_default/custom/post_template.html
28
28
  - data/views/_default/last_deployed
29
+ - lib/repl.rb
29
30
  - lib/runeblog.rb
30
31
  - runeblog.gemspec
31
32
  homepage: https://github.com/Hal9000/runeblog