runeblog 0.0.23 → 0.0.24
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/data/VERSION +1 -1
- data/lib/runeblog.rb +83 -48
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf6ffaa36c7cdc9f9f49eabc32a276911e06564f
|
4
|
+
data.tar.gz: 62daf126e9eda16f40fee3085fa035b71eaf38cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c830d2bea8e9e68408f7afe5b4e5b70e9638c4dacadec86803eff0e46e765aeb90ef59d3e8a2841f4363045b4fe2097f1abb851d0f2cfe8c65b17cf0956ca76
|
7
|
+
data.tar.gz: 35c2713ecc18a9303fc6727efa97a1a91f74d0e39e6eeacdc82000ad575917b64121e99d43de4ed4a0701fbf73b7c8442d24892697db01b763fb11a9694c4f53
|
data/data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
RuneBlog v 0.0.
|
1
|
+
RuneBlog v 0.0.24 2017-05-09
|
data/lib/runeblog.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
|
2
2
|
class RuneBlog
|
3
|
-
VERSION = "0.0.
|
3
|
+
VERSION = "0.0.24"
|
4
4
|
|
5
5
|
Path = File.expand_path(File.join(File.dirname(__FILE__)))
|
6
6
|
DefaultData = Path + "/../data"
|
@@ -11,6 +11,36 @@ class RuneBlog
|
|
11
11
|
PostTrailer = File.read(DefaultData + "/post_trailer.html") rescue "not found"
|
12
12
|
end
|
13
13
|
|
14
|
+
class RuneBlog::Config
|
15
|
+
attr_reader :root, :views, :view, :sequence
|
16
|
+
|
17
|
+
def initialize(cfg_file = ".blog")
|
18
|
+
# What views are there? Deployment, etc.
|
19
|
+
# Crude - FIXME later
|
20
|
+
new_blog! unless File.exist?(cfg_file)
|
21
|
+
|
22
|
+
lines = File.readlines(cfg_file).map {|x| x.chomp }
|
23
|
+
@root = lines[0]
|
24
|
+
@view = lines[1]
|
25
|
+
dirs = Dir.entries("#@root/views/") - %w[. ..]
|
26
|
+
dirs.reject! {|x| ! File.directory?("#@root/views/#{x}") }
|
27
|
+
@root = root
|
28
|
+
@views = dirs
|
29
|
+
@sequence = File.read(root + "/sequence").to_i
|
30
|
+
end
|
31
|
+
|
32
|
+
def next_sequence
|
33
|
+
@sequence += 1
|
34
|
+
File.open("#@root/sequence", "w") {|f| f.puts @sequence }
|
35
|
+
@sequence
|
36
|
+
end
|
37
|
+
|
38
|
+
def viewdir(v)
|
39
|
+
@root + "/views/#{v}/"
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
14
44
|
require 'find'
|
15
45
|
require 'yaml'
|
16
46
|
require 'rubygems'
|
@@ -38,6 +68,10 @@ def interpolate(str)
|
|
38
68
|
eval wrap
|
39
69
|
end
|
40
70
|
|
71
|
+
def colored_slug(slug)
|
72
|
+
red(slug[0..3])+blue(slug[4..-1])
|
73
|
+
end
|
74
|
+
|
41
75
|
|
42
76
|
### ask
|
43
77
|
|
@@ -77,18 +111,10 @@ def new_blog!
|
|
77
111
|
end
|
78
112
|
end
|
79
113
|
|
80
|
-
### next_sequence
|
81
|
-
|
82
|
-
def next_sequence
|
83
|
-
@config.sequence += 1
|
84
|
-
File.open("#{@config.root}/sequence", "w") {|f| f.puts @config.sequence }
|
85
|
-
@config.sequence
|
86
|
-
end
|
87
|
-
|
88
114
|
### make_slug
|
89
115
|
|
90
116
|
def make_slug(title, seq=nil)
|
91
|
-
num = '%04d' % (seq || next_sequence) # FIXME can do better
|
117
|
+
num = '%04d' % (seq || @config.next_sequence) # FIXME can do better
|
92
118
|
slug = title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
|
93
119
|
"#{num}-#{slug}"
|
94
120
|
end
|
@@ -96,20 +122,14 @@ end
|
|
96
122
|
### read_config
|
97
123
|
|
98
124
|
def read_config
|
99
|
-
cfg_file = ".blog"
|
100
|
-
@config = OpenStruct.new
|
101
|
-
# What views are there? Deployment, etc.
|
102
125
|
# Crude - FIXME later
|
126
|
+
cfg_file = ".blog"
|
103
127
|
new_blog! unless File.exist?(cfg_file)
|
128
|
+
@config = RuneBlog::Config.new(".blog")
|
104
129
|
|
105
|
-
|
106
|
-
|
107
|
-
@
|
108
|
-
dirs = Dir.entries("#{root}/views/") - %w[. ..]
|
109
|
-
dirs.reject! {|x| ! File.directory?("#{root}/views/#{x}") }
|
110
|
-
@config.root = root
|
111
|
-
@config.views = dirs
|
112
|
-
@config.sequence = File.read(root + "/sequence").to_i
|
130
|
+
@view = @config.view # current view
|
131
|
+
@sequence = @config.sequence
|
132
|
+
@root = @config.root
|
113
133
|
end
|
114
134
|
|
115
135
|
### create_empty_post
|
@@ -131,14 +151,23 @@ EOS
|
|
131
151
|
|
132
152
|
@slug = make_slug(@title)
|
133
153
|
@fname = @slug + ".lt3"
|
134
|
-
File.open("
|
154
|
+
File.open("#@root/src/#@fname", "w") {|f| f.puts @template }
|
135
155
|
@fname
|
136
156
|
end
|
137
157
|
|
138
158
|
### edit_post
|
139
159
|
|
140
160
|
def edit_post(file)
|
141
|
-
system("vi
|
161
|
+
system("vi #@root/src/#{file} +8 ")
|
162
|
+
end
|
163
|
+
|
164
|
+
def deploy(view)
|
165
|
+
# TBD clunky FIXME
|
166
|
+
deployment = @config.viewdir(view) + "deploy"
|
167
|
+
lines = File.readlines(deployment)
|
168
|
+
user, server, dir = *lines
|
169
|
+
files =
|
170
|
+
cmd = "scp #{files.join(' ')} root@#{server}:#{dir}"
|
142
171
|
end
|
143
172
|
|
144
173
|
### process_post
|
@@ -146,8 +175,8 @@ end
|
|
146
175
|
def process_post(file)
|
147
176
|
@main ||= Livetext.new
|
148
177
|
@main.main.output = File.new("/tmp/WHOA","w")
|
149
|
-
|
150
|
-
path = @
|
178
|
+
# puts " Processing: #{Dir.pwd} :: #{file}"
|
179
|
+
path = @root + "/src/#{file}"
|
151
180
|
@meta = @main.process_file(path)
|
152
181
|
@meta.slug = make_slug(@meta.title, @config.sequence)
|
153
182
|
@meta.slug = file.sub(/.lt3$/, "")
|
@@ -184,7 +213,7 @@ end
|
|
184
213
|
|
185
214
|
def generate_index(view)
|
186
215
|
# Gather all posts, create list
|
187
|
-
vdir = "
|
216
|
+
vdir = "#@root/views/#{view}"
|
188
217
|
posts = Dir.entries(vdir).grep /^\d\d\d\d/
|
189
218
|
posts = posts.sort.reverse
|
190
219
|
|
@@ -207,18 +236,18 @@ end
|
|
207
236
|
|
208
237
|
def link_post_view(view)
|
209
238
|
# Create dir using slug (index.html, metadata?)
|
210
|
-
vdir =
|
211
|
-
dir =
|
239
|
+
vdir = @config.viewdir(view)
|
240
|
+
dir = vdir + @meta.slug + "/"
|
212
241
|
cmd = "mkdir -p #{dir}" #-- FIXME what if this exists??
|
213
|
-
|
242
|
+
# puts " Running: #{cmd}"
|
214
243
|
system(cmd)
|
215
244
|
File.write("#{dir}/metadata.yaml", @meta.to_yaml)
|
216
245
|
# Add header/trailer to post index
|
217
|
-
head = File.read("
|
218
|
-
tail = File.read("
|
246
|
+
head = File.read(vdir + "custom/post_header.html") rescue RuneBlog::PostHeader
|
247
|
+
tail = File.read(vdir + "custom/post_trailer.html") rescue RuneBlog::PostTrailer
|
219
248
|
@posthead = interpolate(head)
|
220
249
|
@posttail = interpolate(tail)
|
221
|
-
File.open("
|
250
|
+
File.open(dir + "index.html", "w") do |f|
|
222
251
|
f.puts @posthead
|
223
252
|
f.puts @meta.body
|
224
253
|
f.puts @posttail
|
@@ -229,17 +258,23 @@ end
|
|
229
258
|
### link_post
|
230
259
|
|
231
260
|
def link_post(meta)
|
261
|
+
puts " #{colored_slug(meta.slug)}"
|
232
262
|
# First gather the views
|
233
263
|
views = meta.views
|
234
|
-
|
264
|
+
print " Views: "
|
265
|
+
views.each do |view|
|
266
|
+
print "#{view} "
|
267
|
+
link_post_view(view)
|
268
|
+
end
|
269
|
+
puts
|
235
270
|
end
|
236
271
|
|
237
272
|
### rebuild
|
238
273
|
|
239
274
|
def rebuild
|
240
|
-
|
275
|
+
puts
|
276
|
+
files = Dir.entries("#@root/src/").grep /\d\d\d\d.*.lt3$/
|
241
277
|
files.map! {|f| File.basename(f) }
|
242
|
-
files.each {|f| p f }
|
243
278
|
files = files.sort.reverse
|
244
279
|
files.each do |file|
|
245
280
|
reload_post(file)
|
@@ -268,13 +303,13 @@ end
|
|
268
303
|
def publish_post
|
269
304
|
# Grab destination data
|
270
305
|
# scp changed files over
|
271
|
-
|
306
|
+
# puts " Publish: Not implemented yet"
|
272
307
|
end
|
273
308
|
|
274
309
|
### list_views
|
275
310
|
|
276
311
|
def list_views
|
277
|
-
|
312
|
+
abort "Config file not read" unless @config
|
278
313
|
puts
|
279
314
|
@config.views.each {|v| puts " #{v}" }
|
280
315
|
end
|
@@ -299,13 +334,13 @@ def new_view(arg = nil)
|
|
299
334
|
arg ||= ask("New view: ") # check validity later
|
300
335
|
raise "view #{arg} already exists" if @config.views.include?(arg)
|
301
336
|
|
302
|
-
dir = @
|
303
|
-
cmd = "mkdir -p #{dir}
|
337
|
+
dir = @root + "/views/" + arg + "/"
|
338
|
+
cmd = "mkdir -p #{dir + 'custom'}"
|
304
339
|
system(cmd)
|
305
|
-
File.write("
|
306
|
-
File.write("
|
307
|
-
File.write("
|
308
|
-
File.write("
|
340
|
+
File.write(dir + "custom/blog_header.html", RuneBlog::BlogHeader)
|
341
|
+
File.write(dir + "custom/blog_trailer.html", RuneBlog::BlogTrailer)
|
342
|
+
File.write(dir + "custom/post_header.html", RuneBlog::PostHeader)
|
343
|
+
File.write(dir + "custom/post_trailer.html", RuneBlog::PostTrailer)
|
309
344
|
@config.views << arg
|
310
345
|
end
|
311
346
|
|
@@ -320,7 +355,7 @@ def import(arg = nil)
|
|
320
355
|
@title = grep.sub(/^.title /, "")
|
321
356
|
@slug = make_slug(@title)
|
322
357
|
@fname = @slug + ".lt3"
|
323
|
-
system("cp #{name}
|
358
|
+
system("cp #{name} #@root/src/#@fname")
|
324
359
|
edit_post(@fname)
|
325
360
|
process_post(@fname)
|
326
361
|
if publish?
|
@@ -339,7 +374,7 @@ def new_post
|
|
339
374
|
|
340
375
|
file = create_empty_post
|
341
376
|
edit_post(file)
|
342
|
-
# file = @
|
377
|
+
# file = @root + "/src/" + file
|
343
378
|
process_post(file) #- FIXME handle each view
|
344
379
|
if publish?
|
345
380
|
link_post(@meta)
|
@@ -354,7 +389,7 @@ end
|
|
354
389
|
def remove_post(arg)
|
355
390
|
id = Integer(arg) rescue raise("'#{arg}' is not an integer")
|
356
391
|
tag = "#{'%04d' % id}-"
|
357
|
-
files = Find.find(
|
392
|
+
files = Find.find(@root).to_a
|
358
393
|
files = files.grep(/#{tag}/)
|
359
394
|
if files.empty?
|
360
395
|
puts red("\n No such post found")
|
@@ -378,7 +413,7 @@ end
|
|
378
413
|
### list_posts
|
379
414
|
|
380
415
|
def list_posts
|
381
|
-
dir =
|
416
|
+
dir = @config.viewdir(@view)
|
382
417
|
Dir.chdir(dir) do
|
383
418
|
posts = Dir.entries(".").grep(/^0.*/)
|
384
419
|
puts
|
@@ -396,7 +431,7 @@ end
|
|
396
431
|
### list_drafts
|
397
432
|
|
398
433
|
def list_drafts
|
399
|
-
dir = "
|
434
|
+
dir = "#@root/src"
|
400
435
|
Dir.chdir(dir) do
|
401
436
|
posts = Dir.entries(".").grep(/^0.*.lt3/)
|
402
437
|
puts
|
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.
|
4
|
+
version: 0.0.24
|
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-
|
11
|
+
date: 2017-05-09 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
|