runeblog 0.0.81 → 0.0.82
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/default.rb +17 -2
- data/lib/deploy.rb +20 -8
- data/lib/helpers-blog.rb +25 -0
- data/lib/post.rb +6 -16
- data/lib/repl.rb +2 -32
- data/lib/runeblog.rb +24 -15
- data/lib/version.rb +1 -1
- data/lib/view.rb +2 -12
- data/test/general.rb +12 -3
- data/test/make_blog.rb +1 -0
- 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: e2691b40f636554604986a978b477b1696171cf2
|
4
|
+
data.tar.gz: 2cef5f6ebc60afc93e125453b6614589e3f6a420
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e2850ad2ae3f999e155214e9bfd76ad83d5dd814f23cbb711a5aafb5d08524453da8bdacba4f0d747f6a1a35249f57c5467633a89351dcee47fd6381eeaf58e
|
7
|
+
data.tar.gz: 50fc4ef26de135a92fa08f860be97fb04999fe2bbe15ef21ba44683a4de9fa853fa6bfb54c4410cfc04b6483acca62748e9bfb4804d8babd04057464c666e89d
|
data/lib/default.rb
CHANGED
@@ -30,10 +30,25 @@ BlogHeader = <<-TEXT
|
|
30
30
|
TEXT
|
31
31
|
|
32
32
|
BlogTrailer = <<-TEXT
|
33
|
-
<!-- no trailer -->
|
33
|
+
<!-- no blog trailer -->
|
34
34
|
TEXT
|
35
35
|
|
36
|
-
PostTemplate = <<-'TEXT'
|
36
|
+
PostTemplate = <<-'TEXT' # interpolate later
|
37
|
+
.mixin liveblog
|
38
|
+
|
39
|
+
.title #@title
|
40
|
+
.pubdate #@date
|
41
|
+
.views #@view
|
42
|
+
.tags
|
43
|
+
|
44
|
+
.teaser
|
45
|
+
#{@meta.teaser}
|
46
|
+
.end
|
47
|
+
#{@meta.remainder}
|
48
|
+
TEXT
|
49
|
+
|
50
|
+
|
51
|
+
TeaserTemplate = <<-'TEXT' # interpolate later
|
37
52
|
<html>
|
38
53
|
|
39
54
|
<body>
|
data/lib/deploy.rb
CHANGED
@@ -2,15 +2,27 @@ require 'helpers-blog'
|
|
2
2
|
require 'runeblog'
|
3
3
|
|
4
4
|
class RuneBlog::Deployment
|
5
|
-
attr_reader :user, :server, :
|
5
|
+
attr_reader :user, :server, :docroot, :path
|
6
6
|
|
7
7
|
BadRemoteLogin = Exception.new("Can't login remotely")
|
8
8
|
BadRemotePerms = Exception.new("Bad remote permissions")
|
9
9
|
|
10
|
-
def initialize(
|
10
|
+
def initialize(*params)
|
11
11
|
@blog = RuneBlog.blog
|
12
|
-
|
13
|
-
|
12
|
+
# Clunky...
|
13
|
+
if params.size == 1 && params[0].is_a?(OpenStruct)
|
14
|
+
obj = params[0]
|
15
|
+
array = obj.to_h.values_at(:user, :server, :docroot,
|
16
|
+
:path, :proto)
|
17
|
+
@user, @server, @docroot, @path, @proto = *array
|
18
|
+
else
|
19
|
+
@user, @server, @docroot, @path, @proto = *obj
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_h
|
24
|
+
{user: @user, server: @server, docroot: @docroot,
|
25
|
+
path: @path, proto: @proto}
|
14
26
|
end
|
15
27
|
|
16
28
|
def url
|
@@ -19,7 +31,7 @@ class RuneBlog::Deployment
|
|
19
31
|
|
20
32
|
def deploy(files)
|
21
33
|
reset_output
|
22
|
-
dir = "#@
|
34
|
+
dir = "#@docroot/#@path"
|
23
35
|
result = system("ssh #@user@#@server -x mkdir #{dir}")
|
24
36
|
list = files.join(' ')
|
25
37
|
cmd = "scp -r #{list} #@user@##server:#{dir} >/dev/null 2>&1"
|
@@ -40,11 +52,11 @@ class RuneBlog::Deployment
|
|
40
52
|
end
|
41
53
|
|
42
54
|
def remote_permissions?
|
43
|
-
dir = "#@
|
55
|
+
dir = "#@docroot/#@path"
|
44
56
|
temp = "#@path/__only_testing"
|
45
|
-
try1 = system("ssh -o BatchMode=yes -o ConnectTimeout=
|
57
|
+
try1 = system("ssh -o BatchMode=yes -o ConnectTimeout=1 #@user@#@server -x mkdir -p #{temp} >/dev/null 2>&1")
|
46
58
|
return nil unless try1
|
47
|
-
try2 = system("ssh -o BatchMode=yes -o ConnectTimeout=
|
59
|
+
try2 = system("ssh -o BatchMode=yes -o ConnectTimeout=1 #@user@#@server -x rmdir #{temp} >/dev/null 2>&1")
|
48
60
|
return nil unless try2
|
49
61
|
true
|
50
62
|
end
|
data/lib/helpers-blog.rb
CHANGED
@@ -15,3 +15,28 @@ def error(err) # FIXME - this is duplicated
|
|
15
15
|
puts err.backtrace # [0]
|
16
16
|
end
|
17
17
|
|
18
|
+
def read_config(file, *syms)
|
19
|
+
lines = File.readlines(file).map(&:chomp)
|
20
|
+
obj = OpenStruct.new
|
21
|
+
lines.each do |line|
|
22
|
+
key, val = line.split(" ", 2)
|
23
|
+
key = key[0..-2] # remove colon
|
24
|
+
obj.send(key+"=", val)
|
25
|
+
end
|
26
|
+
@deployer = RuneBlog::Deployment.new(obj)
|
27
|
+
obj
|
28
|
+
rescue => err
|
29
|
+
puts "Something hit the fan: #{err}"
|
30
|
+
puts err.backtrace
|
31
|
+
exit
|
32
|
+
end
|
33
|
+
|
34
|
+
def write_config(obj, file)
|
35
|
+
hash = obj.to_h
|
36
|
+
File.open(file, "w") do |f|
|
37
|
+
hash.each_pair do |key, val|
|
38
|
+
f.puts "#{key}: #{val}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
data/lib/post.rb
CHANGED
@@ -18,22 +18,12 @@ class RuneBlog::Post
|
|
18
18
|
@title = meta.title
|
19
19
|
@view = @blog.str2view(view_name)
|
20
20
|
@num, @slug = make_slug
|
21
|
-
date = Time.now.strftime("%Y-%m-%d")
|
22
|
-
template =
|
23
|
-
|
24
|
-
|
25
|
-
.title #@title
|
26
|
-
.pubdate #{date}
|
27
|
-
.views #@view
|
28
|
-
|
29
|
-
.teaser
|
30
|
-
#{meta.teaser}
|
31
|
-
.end
|
32
|
-
#{meta.remainder}
|
33
|
-
EOS
|
34
|
-
|
21
|
+
@date = Time.now.strftime("%Y-%m-%d")
|
22
|
+
template = RuneBlog::Default::PostTemplate
|
23
|
+
@meta = meta
|
24
|
+
html = interpolate(template)
|
35
25
|
@draft = "#{@blog.root}/src/#@slug.lt3"
|
36
|
-
File.write(@draft,
|
26
|
+
File.write(@draft, html)
|
37
27
|
end
|
38
28
|
|
39
29
|
def edit
|
@@ -72,7 +62,7 @@ class RuneBlog::Post
|
|
72
62
|
File.write("metadata.yaml", @meta.to_yaml)
|
73
63
|
File.write("teaser.txt", @meta.teaser)
|
74
64
|
File.write("remainder.txt", @meta.remainder)
|
75
|
-
template = RuneBlog::Default::
|
65
|
+
template = RuneBlog::Default::TeaserTemplate
|
76
66
|
text = interpolate(template)
|
77
67
|
File.write("index.html", text)
|
78
68
|
end
|
data/lib/repl.rb
CHANGED
@@ -72,36 +72,6 @@ module RuneBlog::REPL
|
|
72
72
|
error(err)
|
73
73
|
end
|
74
74
|
|
75
|
-
def old_cmd_deploy(arg) # FIXME non-string return expected in caller?
|
76
|
-
# TBD clunky FIXME
|
77
|
-
reset_output
|
78
|
-
check_empty(arg)
|
79
|
-
user, server, sroot, spath = *@deploy[@blog.view]
|
80
|
-
if files.empty? # FIXME baloney
|
81
|
-
output! "No files to deploy"
|
82
|
-
return @out
|
83
|
-
end
|
84
|
-
|
85
|
-
output "Files:"
|
86
|
-
files.each {|f| output " #{f}\n" }
|
87
|
-
output_newline
|
88
|
-
dir = "#{sroot}/#{spath}"
|
89
|
-
# FIXME - may or may not already exist
|
90
|
-
result = system("ssh root@#{server} mkdir #{dir}")
|
91
|
-
# ^ needs -c??
|
92
|
-
|
93
|
-
cmd = "scp -r #{files.join(' ')} root@#{server}:#{dir} >/dev/null 2>&1"
|
94
|
-
output! "Deploying #{files.size} files...\n"
|
95
|
-
result = system(cmd)
|
96
|
-
raise "Problem occurred in deployment" unless result
|
97
|
-
|
98
|
-
File.write("#{vdir}/last_deployed", files)
|
99
|
-
output! "...finished.\n"
|
100
|
-
@out
|
101
|
-
rescue => err
|
102
|
-
error(err)
|
103
|
-
end
|
104
|
-
|
105
75
|
def cmd_rebuild(arg)
|
106
76
|
reset_output
|
107
77
|
check_empty(arg)
|
@@ -156,8 +126,8 @@ module RuneBlog::REPL
|
|
156
126
|
@blog.create_view(arg)
|
157
127
|
resp = yesno("Add deployment info now? ")
|
158
128
|
@blog.view.deployer = ask_deployment_info
|
159
|
-
@blog.view.
|
160
|
-
|
129
|
+
write_config(@blog.view.deployer, @blog.view.dir + "/deploy") # change this?
|
130
|
+
# read_config(@blog.view.dir + "/deploy") # unnessary?
|
161
131
|
nil
|
162
132
|
rescue => err
|
163
133
|
error(err)
|
data/lib/runeblog.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
+
require 'pp'
|
2
|
+
|
1
3
|
require 'find'
|
2
4
|
require 'yaml' # get rid of YAML later
|
3
5
|
require 'livetext'
|
4
6
|
require 'skeleton'
|
7
|
+
require 'helpers-blog'
|
5
8
|
require 'default'
|
6
9
|
require 'view'
|
7
10
|
require 'deploy'
|
@@ -20,7 +23,9 @@ class RuneBlog
|
|
20
23
|
attr_accessor :view # overridden
|
21
24
|
|
22
25
|
def self.create_new_blog(dir = "data")
|
23
|
-
|
26
|
+
x = OpenStruct.new
|
27
|
+
x.root, x.current_view, x.editor = dir, "no_default", "vi"
|
28
|
+
write_config(x, ".blog")
|
24
29
|
create_dir(dir)
|
25
30
|
Dir.chdir(dir) do
|
26
31
|
create_dir("views")
|
@@ -31,15 +36,12 @@ class RuneBlog
|
|
31
36
|
end
|
32
37
|
end
|
33
38
|
|
34
|
-
def get_config(file)
|
35
|
-
lines = File.readlines(file).map(&:chomp)
|
36
|
-
root, view_name = *lines
|
37
|
-
end
|
38
|
-
|
39
39
|
def initialize(cfg_file = ".blog") # assumes existing blog
|
40
40
|
# Crude - FIXME later - What views are there? Deployment, etc.
|
41
41
|
self.class.blog = self # Weird. Like a singleton - dumbass circular dependency?
|
42
|
-
|
42
|
+
obj = read_config(cfg_file)
|
43
|
+
vals = obj.to_h.values_at(:root, :current_view, :editor)
|
44
|
+
@root, view_name, @editor = *vals
|
43
45
|
@views = subdirs("#@root/views/").sort.map {|name| RuneBlog::View.new(name) }
|
44
46
|
@view = str2view(view_name)
|
45
47
|
@sequence = get_sequence
|
@@ -61,12 +63,13 @@ class RuneBlog
|
|
61
63
|
case arg
|
62
64
|
when RuneBlog::View
|
63
65
|
@view = arg
|
66
|
+
raise "Problem here?"
|
64
67
|
@view.read_config
|
65
68
|
when String
|
66
69
|
new_view = str2view(arg)
|
67
70
|
raise "Can't find view #{arg}" if new_view.nil?
|
68
71
|
@view = new_view
|
69
|
-
@view.read_config
|
72
|
+
@view.deployer = read_config(@view.dir + "/deploy")
|
70
73
|
else
|
71
74
|
raise "#{arg.inspect} was not a View or a String"
|
72
75
|
end
|
@@ -123,7 +126,7 @@ class RuneBlog
|
|
123
126
|
vdir = @blog.viewdir(@view)
|
124
127
|
# meh
|
125
128
|
files = ["#{vdir}/index.html"]
|
126
|
-
files += Dir.entries(vdir).grep(/^\d
|
129
|
+
files += Dir.entries(vdir).grep(/^\d{4}/).map {|x| "#{vdir}/#{x}" }
|
127
130
|
# Huh?
|
128
131
|
files.reject! {|f| File.mtime(f) < File.mtime("#{vdir}/last_deployed") }
|
129
132
|
end
|
@@ -148,7 +151,7 @@ class RuneBlog
|
|
148
151
|
end
|
149
152
|
|
150
153
|
def edit_initial_post(file)
|
151
|
-
result = system("
|
154
|
+
result = system("#@editor #@root/src/#{file} +8")
|
152
155
|
raise "Problem editing #@root/src/#{file}" unless result
|
153
156
|
nil
|
154
157
|
rescue => err
|
@@ -167,7 +170,9 @@ class RuneBlog
|
|
167
170
|
end
|
168
171
|
|
169
172
|
def change_view(view)
|
170
|
-
|
173
|
+
x = OpenStruct.new
|
174
|
+
x.root, x.current_view, x.editor = @root, view, @editor # dumb - FIXME later
|
175
|
+
write_config(x, ".blog")
|
171
176
|
self.view = view # error checking?
|
172
177
|
end
|
173
178
|
|
@@ -210,7 +215,7 @@ class RuneBlog
|
|
210
215
|
def generate_index(view)
|
211
216
|
# Gather all posts, create list
|
212
217
|
vdir = "#@root/views/#{view}"
|
213
|
-
posts = Dir.entries(vdir).grep /^\d
|
218
|
+
posts = Dir.entries(vdir).grep /^\d{4}/
|
214
219
|
posts = posts.sort.reverse
|
215
220
|
|
216
221
|
# Add view header/trailer
|
@@ -262,8 +267,11 @@ class RuneBlog
|
|
262
267
|
def remove_post(num)
|
263
268
|
list = files_by_id(num)
|
264
269
|
return nil if list.empty?
|
265
|
-
|
266
|
-
|
270
|
+
dest = list.map {|f| f.sub(/(?<num>\d{4}-)/, "_\\k<num>") }
|
271
|
+
list.each.with_index do |src, i|
|
272
|
+
cmd = "mv #{src} #{dest[i]} 2>/dev/null"
|
273
|
+
system(cmd)
|
274
|
+
end
|
267
275
|
# FIXME - update index/etc
|
268
276
|
true
|
269
277
|
end
|
@@ -288,6 +296,7 @@ class RuneBlog
|
|
288
296
|
private
|
289
297
|
|
290
298
|
def subdirs(dir)
|
299
|
+
raise Exception.new("hell") if dir == "/views/"
|
291
300
|
dirs = Dir.entries(dir) - %w[. ..]
|
292
301
|
dirs.reject! {|x| ! File.directory?("#@root/views/#{x}") }
|
293
302
|
dirs
|
@@ -296,7 +305,7 @@ class RuneBlog
|
|
296
305
|
end
|
297
306
|
|
298
307
|
def find_src_slugs
|
299
|
-
files = Dir.entries("#@root/src/").grep /\d
|
308
|
+
files = Dir.entries("#@root/src/").grep /\d{4}.*.lt3$/
|
300
309
|
files.map! {|f| File.basename(f) }
|
301
310
|
files = files.sort.reverse
|
302
311
|
files
|
data/lib/version.rb
CHANGED
data/lib/view.rb
CHANGED
@@ -9,7 +9,8 @@ class RuneBlog::View
|
|
9
9
|
raise "RuneBlog.blog is not set!" if RuneBlog.blog.nil?
|
10
10
|
@blog = RuneBlog.blog
|
11
11
|
@name = name
|
12
|
-
|
12
|
+
dep_file = @blog.root + "/views/#@name/deploy"
|
13
|
+
@deployer = read_config(dep_file)
|
13
14
|
end
|
14
15
|
|
15
16
|
def dir
|
@@ -48,16 +49,5 @@ class RuneBlog::View
|
|
48
49
|
File.mtime(file) < File.mtime("#{dir()}/last_deployed")
|
49
50
|
end
|
50
51
|
|
51
|
-
def read_config
|
52
|
-
file = self.dir + "/deploy"
|
53
|
-
lines = File.readlines(file).map(&:chomp)
|
54
|
-
user, server, root, path, proto = *lines
|
55
|
-
@deploy = RuneBlog::Deployment.new(user, server, root, path, proto)
|
56
|
-
end
|
57
|
-
|
58
|
-
def write_config
|
59
|
-
file = @blog.view.dir + "/deploy"
|
60
|
-
File.open(file, "w") {|f| f.puts [@user, @server, @root, @path, @proto] }
|
61
|
-
end
|
62
52
|
end
|
63
53
|
|
data/test/general.rb
CHANGED
@@ -191,7 +191,10 @@ class TestREPL < Minitest::Test
|
|
191
191
|
end
|
192
192
|
|
193
193
|
def test_016_can_deploy
|
194
|
-
|
194
|
+
x = OpenStruct.new
|
195
|
+
x.user, x.server, x.docroot, x.docroot, x.path, x.proto =
|
196
|
+
"root", "rubyhacker.com", "/var/www", "whatever", "http"
|
197
|
+
dep = RuneBlog::Deployment.new(x)
|
195
198
|
result = dep.remote_login?
|
196
199
|
assert result == true, "Valid login doesn't work"
|
197
200
|
result = dep.remote_permissions?
|
@@ -199,13 +202,19 @@ class TestREPL < Minitest::Test
|
|
199
202
|
end
|
200
203
|
|
201
204
|
def test_017_cannot_deploy_wrong_user
|
202
|
-
|
205
|
+
x = OpenStruct.new
|
206
|
+
x.user, x.server, x.docroot, x.docroot, x.path, x.proto =
|
207
|
+
"bad_user", "rubyhacker.com", "/var/www", "whatever", "http"
|
208
|
+
dep = RuneBlog::Deployment.new(x)
|
203
209
|
result = dep.remote_login?
|
204
210
|
assert result.nil?, "Expected to detect login error (bad user)"
|
205
211
|
end
|
206
212
|
|
207
213
|
def test_018_cannot_deploy_bad_server
|
208
|
-
|
214
|
+
x = OpenStruct.new
|
215
|
+
x.user, x.server, x.docroot, x.docroot, x.path, x.proto =
|
216
|
+
"root", "nonexistent123.com", "/var/www", "whatever", "http"
|
217
|
+
dep = RuneBlog::Deployment.new(x)
|
209
218
|
result = dep.remote_login?
|
210
219
|
assert result.nil?, "Expected to detect login error (bad server)"
|
211
220
|
end
|
data/test/make_blog.rb
CHANGED
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.82
|
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-10-
|
11
|
+
date: 2018-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: livetext
|