runeblog 0.0.91 → 0.0.93
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/deploy.rb +1 -1
- data/lib/helpers-blog.rb +2 -2
- data/lib/helpers-repl.rb +10 -8
- data/lib/post.rb +6 -5
- data/lib/repl.rb +7 -4
- data/lib/runeblog.rb +7 -16
- data/lib/skeleton.rb +10 -0
- data/lib/version.rb +1 -1
- data/lib/view.rb +1 -1
- data/test/general.rb +40 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d401049bff7f80d13c2708674608b2c2c418d77e
|
4
|
+
data.tar.gz: 0a8dead9268c46004a4a31d8977724d119adabeb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0d9364fa2a1dc901ebd178fa7f5b7544ec519ee756dcad417cdcb7542cbed97129f3e2b814025b12e884feb5e9142a74bc03c2f64b9b946d68a5f0771cc4a46
|
7
|
+
data.tar.gz: 4f47211d17dab06700c3afd9f956c3f20b0b9ccd7f6b69d1fcdd2cded31efd6f1d68d2ab47059a102c983b4dca19094c4c63ca8fe8f685a5a639b6215d1c4eb3
|
data/lib/deploy.rb
CHANGED
@@ -37,7 +37,7 @@ class RuneBlog::Deployment
|
|
37
37
|
cmd = "scp -r #{list} #@user@##server:#{dir} >/dev/null 2>&1"
|
38
38
|
output! "Deploying #{files.size} files...\n"
|
39
39
|
result = system(cmd)
|
40
|
-
raise
|
40
|
+
raise DeploymentError unless result
|
41
41
|
|
42
42
|
dump(files, "#{@blog.view.dir}/last_deployed")
|
43
43
|
output! "...finished.\n"
|
data/lib/helpers-blog.rb
CHANGED
@@ -38,7 +38,7 @@ module RuneBlog::Helpers
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def new_dotfile(root: "data", current_view: "no_default", editor: "vi")
|
41
|
-
raise
|
41
|
+
raise BlogAlreadyExists if Dir.exist?(".blog")
|
42
42
|
Dir.mkdir(".blog")
|
43
43
|
x = OpenStruct.new
|
44
44
|
x.root, x.current_view, x.editor = root, current_view, editor
|
@@ -71,7 +71,7 @@ module RuneBlog::Helpers
|
|
71
71
|
return if Dir.exist?(dir) # && File.directory?(dir)
|
72
72
|
cmd = "mkdir -p #{dir} >/dev/null 2>&1"
|
73
73
|
result = system(cmd)
|
74
|
-
raise
|
74
|
+
raise CantCreateDir(dir) unless result
|
75
75
|
end
|
76
76
|
|
77
77
|
def interpolate(str)
|
data/lib/helpers-repl.rb
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
|
2
2
|
# Reopening...
|
3
3
|
|
4
|
+
make_exception(:CantOpen, "Can't open '$1'")
|
5
|
+
make_exception(:CantDelete, "Can't open '$1'")
|
6
|
+
make_exception(:InternalError, "Glitch: $1 got arg '$2'")
|
7
|
+
make_exception(:CantCopy, "Can't copy $1 to $2")
|
8
|
+
|
4
9
|
module RuneBlog::REPL
|
5
10
|
Patterns =
|
6
11
|
{"help" => :cmd_help,
|
@@ -128,12 +133,9 @@ module RuneBlog::REPL
|
|
128
133
|
n.times { @out << "\n" }
|
129
134
|
end
|
130
135
|
|
131
|
-
FileNotFound = StandardError.dup
|
132
|
-
CantOpen = StandardError.dup
|
133
|
-
CantDelete = StandardError.dup
|
134
136
|
|
135
137
|
def check_empty(arg)
|
136
|
-
raise
|
138
|
+
raise InternalError(caller[0], arg.inspect) unless arg.nil?
|
137
139
|
end
|
138
140
|
|
139
141
|
def get_integer(arg)
|
@@ -143,15 +145,15 @@ module RuneBlog::REPL
|
|
143
145
|
end
|
144
146
|
|
145
147
|
def check_file_exists(file)
|
146
|
-
raise FileNotFound
|
148
|
+
raise FileNotFound(file) unless File.exist?(file)
|
147
149
|
end
|
148
150
|
|
149
151
|
def error_cant_delete(files)
|
150
152
|
case files
|
151
153
|
when String
|
152
|
-
raise CantDelete
|
154
|
+
raise CantDelete(files)
|
153
155
|
when Array
|
154
|
-
raise CantDelete
|
156
|
+
raise CantDelete(files.join("\n"))
|
155
157
|
end
|
156
158
|
end
|
157
159
|
|
@@ -186,7 +188,7 @@ module RuneBlog::REPL
|
|
186
188
|
@slug = @blog.make_slug(@title)
|
187
189
|
@fname = @slug + ".lt3"
|
188
190
|
result = system("cp #{name} #@root/src/#@fname")
|
189
|
-
raise
|
191
|
+
raise CantCopy(name, "#@root/src/#@fname") unless result
|
190
192
|
|
191
193
|
edit_initial_post(@fname)
|
192
194
|
process_post(@fname)
|
data/lib/post.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'helpers-blog'
|
2
2
|
require 'runeblog'
|
3
3
|
|
4
|
+
make_exception(:NoBlogAccessor, "Runeblog.blog is not set")
|
5
|
+
|
4
6
|
class RuneBlog::Post
|
5
7
|
|
6
8
|
attr_reader :id, :title, :date, :views, :num, :slug
|
@@ -15,7 +17,7 @@ class RuneBlog::Post
|
|
15
17
|
|
16
18
|
def self.load(post)
|
17
19
|
# FIXME weird logic here
|
18
|
-
raise
|
20
|
+
raise NoBlogAccessor if RuneBlog.blog.nil?
|
19
21
|
pdir = RuneBlog.blog.view.dir + "/" + post
|
20
22
|
meta = nil
|
21
23
|
Dir.chdir(pdir) do
|
@@ -31,7 +33,7 @@ class RuneBlog::Post
|
|
31
33
|
|
32
34
|
def initialize(meta, view_name)
|
33
35
|
# FIXME weird logic here
|
34
|
-
raise
|
36
|
+
raise NoBlogAccessor if RuneBlog.blog.nil?
|
35
37
|
@blog = RuneBlog.blog
|
36
38
|
@title = meta.title
|
37
39
|
@view = @blog.str2view(view_name)
|
@@ -46,7 +48,7 @@ class RuneBlog::Post
|
|
46
48
|
|
47
49
|
def edit
|
48
50
|
result = system("vi #@draft +8")
|
49
|
-
raise
|
51
|
+
raise EditorProblem(draft) unless result
|
50
52
|
nil
|
51
53
|
rescue => err
|
52
54
|
error(err)
|
@@ -55,7 +57,7 @@ class RuneBlog::Post
|
|
55
57
|
def publish
|
56
58
|
livetext = Livetext.new(STDOUT)
|
57
59
|
@meta = livetext.process_file(@draft, binding)
|
58
|
-
raise
|
60
|
+
raise LivetextError(@draft) if @meta.nil?
|
59
61
|
|
60
62
|
@meta.views.each do |view_name| # Create dir using slug (index.html, metadata?)
|
61
63
|
view = @blog.str2view(view_name)
|
@@ -76,7 +78,6 @@ class RuneBlog::Post
|
|
76
78
|
|
77
79
|
def create_post_subtree(vdir)
|
78
80
|
create_dir("assets")
|
79
|
-
# dump(@meta.to_yaml, "metadata.yaml")
|
80
81
|
write_metadata(@meta)
|
81
82
|
template = RuneBlog::Default::TeaserTemplate # FIXME template into custom dir?
|
82
83
|
text = interpolate(template)
|
data/lib/repl.rb
CHANGED
@@ -2,6 +2,9 @@ require 'runeblog'
|
|
2
2
|
require 'ostruct'
|
3
3
|
require 'helpers-repl' # FIXME structure
|
4
4
|
|
5
|
+
make_exception(:DeploymentError, "Error during deployment")
|
6
|
+
make_exception(:EditorProblem, "Could not edit $1")
|
7
|
+
|
5
8
|
module RuneBlog::REPL
|
6
9
|
|
7
10
|
def cmd_quit(arg)
|
@@ -27,7 +30,7 @@ module RuneBlog::REPL
|
|
27
30
|
return @out
|
28
31
|
end
|
29
32
|
result = system("open '#{url}'")
|
30
|
-
raise CantOpen
|
33
|
+
raise CantOpen(url) unless result
|
31
34
|
nil
|
32
35
|
rescue => err
|
33
36
|
error(err)
|
@@ -38,7 +41,7 @@ module RuneBlog::REPL
|
|
38
41
|
check_empty(arg)
|
39
42
|
local = @blog.view.index
|
40
43
|
result = system("open #{local}")
|
41
|
-
raise CantOpen
|
44
|
+
raise CantOpen(local) unless result
|
42
45
|
rescue => err
|
43
46
|
error(err)
|
44
47
|
end
|
@@ -64,7 +67,7 @@ module RuneBlog::REPL
|
|
64
67
|
cmd = "scp -r #{files.join(' ')} root@#{server}:#{dir} >/dev/null 2>&1"
|
65
68
|
output! "Deploying #{files.size} files...\n"
|
66
69
|
result = system(cmd)
|
67
|
-
raise
|
70
|
+
raise DeploymentError unless result
|
68
71
|
|
69
72
|
dump(files, "#{vdir}/last_deployed")
|
70
73
|
output! "...finished.\n"
|
@@ -197,7 +200,7 @@ module RuneBlog::REPL
|
|
197
200
|
|
198
201
|
file = files.first
|
199
202
|
result = system("vi #{@blog.root}/src/#{file}")
|
200
|
-
raise
|
203
|
+
raise EditorProblem(file) unless result
|
201
204
|
|
202
205
|
@blog.rebuild_post(file)
|
203
206
|
nil
|
data/lib/runeblog.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'find'
|
2
|
-
# require 'yaml' # get rid of YAML later
|
3
2
|
require 'livetext'
|
4
3
|
require 'skeleton'
|
5
4
|
require 'helpers-blog'
|
@@ -9,15 +8,6 @@ require 'deploy'
|
|
9
8
|
require 'post'
|
10
9
|
require 'version'
|
11
10
|
|
12
|
-
def make_exception(sym, str)
|
13
|
-
Object.const_set(sym, StandardError.dup)
|
14
|
-
define_method(sym) do |*args|
|
15
|
-
msg = str
|
16
|
-
args.each.with_index {|arg, i| msg.sub!("$#{i+1}", arg) }
|
17
|
-
Object.class_eval(sym.to_s).new(msg)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
11
|
|
22
12
|
###
|
23
13
|
|
@@ -30,9 +20,12 @@ class RuneBlog
|
|
30
20
|
make_exception(:BlogAlreadyExists, "Blog $1 already exists")
|
31
21
|
make_exception(:CantAssignView, "$1 is not a view")
|
32
22
|
make_exception(:ViewAlreadyExists, "View $1 already exists")
|
23
|
+
make_exception(:DirAlreadyExists, "Directory $1 already exists")
|
24
|
+
make_exception(:CantCreateDir, "Can't create directory $1")
|
33
25
|
make_exception(:EditorProblem, "Could not edit $1")
|
34
26
|
make_exception(:NoSuchView, "No such view: $1")
|
35
|
-
|
27
|
+
make_exception(:LivetextError, "Livetext#process_file returned nil for $1")
|
28
|
+
|
36
29
|
class << self
|
37
30
|
attr_accessor :blog
|
38
31
|
include Helpers
|
@@ -129,7 +122,7 @@ class RuneBlog
|
|
129
122
|
raise ViewAlreadyExists(arg) if names.include?(arg)
|
130
123
|
|
131
124
|
dir = "#@root/views/#{arg}/"
|
132
|
-
raise
|
125
|
+
raise DirAlreadyExists(dir) if Dir.exist?(dir)
|
133
126
|
create_dir(dir)
|
134
127
|
up = Dir.pwd
|
135
128
|
Dir.chdir(dir)
|
@@ -213,10 +206,10 @@ class RuneBlog
|
|
213
206
|
def process_post(file)
|
214
207
|
raise ArgumentError unless file.is_a?(String)
|
215
208
|
path = @root + "/src/#{file}"
|
216
|
-
raise
|
209
|
+
raise FileNotFound(path) unless File.exist?(path)
|
217
210
|
livetext = Livetext.new(STDOUT) # (nil)
|
218
211
|
@meta = livetext.process_file(path, binding)
|
219
|
-
raise
|
212
|
+
raise LivetextError(path) if @meta.nil?
|
220
213
|
|
221
214
|
num, slug = self.make_slug(@meta.title, self.sequence)
|
222
215
|
slug = file.sub(/.lt3$/, "")
|
@@ -241,7 +234,6 @@ class RuneBlog
|
|
241
234
|
dir = vdir + @meta.slug + "/"
|
242
235
|
create_dir(dir + "assets")
|
243
236
|
Dir.chdir(dir) do
|
244
|
-
#? dump(@meta.to_yaml, "metadata.yaml")
|
245
237
|
dump(@meta.teaser, "teaser.txt")
|
246
238
|
dump(@meta.body, "body.txt")
|
247
239
|
# FIXME make get_post_template method
|
@@ -271,7 +263,6 @@ class RuneBlog
|
|
271
263
|
@blogtail = interpolate(tail)
|
272
264
|
|
273
265
|
# Output view
|
274
|
-
#? posts.map! {|post| YAML.load(File.read("#{vdir}/#{post}/metadata.yaml")) }
|
275
266
|
posts.map! do |post|
|
276
267
|
meta = nil
|
277
268
|
pdir = vdir + "/" + post
|
data/lib/skeleton.rb
CHANGED
@@ -17,3 +17,13 @@ class RuneBlog
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
+
def make_exception(sym, str)
|
21
|
+
return if Object.constants.include?(sym)
|
22
|
+
Object.const_set(sym, StandardError.dup)
|
23
|
+
define_method(sym) do |*args|
|
24
|
+
msg = str
|
25
|
+
args.each.with_index {|arg, i| msg.sub!("$#{i+1}", arg) }
|
26
|
+
Object.class_eval(sym.to_s).new(msg)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
data/lib/version.rb
CHANGED
data/lib/view.rb
CHANGED
@@ -8,7 +8,7 @@ class RuneBlog::View
|
|
8
8
|
include RuneBlog::Helpers
|
9
9
|
|
10
10
|
def initialize(name)
|
11
|
-
raise
|
11
|
+
raise NoBlogAccessor if RuneBlog.blog.nil?
|
12
12
|
@blog = RuneBlog.blog
|
13
13
|
@name = name
|
14
14
|
dep_file = @blog.root + "/views/#@name/deploy"
|
data/test/general.rb
CHANGED
@@ -43,7 +43,7 @@ class TestREPL < Minitest::Test
|
|
43
43
|
lines = out.split("\n").length
|
44
44
|
assert lines >= 2, "Expecting at least 2 lines"
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
def test_004_change_view!
|
48
48
|
out = cmd_change_view(nil) # no param
|
49
49
|
assert out.is_a?(String), "Expected a string; got: #{out.inspect}"
|
@@ -224,7 +224,45 @@ if File.exist?("testing.deploy")
|
|
224
224
|
assert result.nil?, "Expected to detect login error (bad server)"
|
225
225
|
end
|
226
226
|
|
227
|
-
end
|
227
|
+
end # conditional tests
|
228
|
+
|
229
|
+
def test_019_exception_existing_blog
|
230
|
+
assert_raises(BlogAlreadyExists) { RuneBlog.create_new_blog }
|
231
|
+
end
|
232
|
+
|
233
|
+
def test_020_exception_missing_blog_accessor
|
234
|
+
save = RuneBlog.blog
|
235
|
+
RuneBlog.blog = nil
|
236
|
+
assert_raises(NoBlogAccessor) { RuneBlog::Post.load(1) }
|
237
|
+
RuneBlog.blog = save
|
238
|
+
end
|
239
|
+
|
240
|
+
def test_021_exception_cant_assign_view
|
241
|
+
assert_raises(CantAssignView) { @blog.view = 99 }
|
242
|
+
end
|
243
|
+
|
244
|
+
def test_022_exception_no_such_view
|
245
|
+
assert_raises(NoSuchView) { @blog.view = 'not_a_view_name' }
|
246
|
+
end
|
247
|
+
|
248
|
+
def test_023_exception_view_already_exists
|
249
|
+
assert_raises(ViewAlreadyExists) { @blog.view = 'alpha_view' }
|
250
|
+
end
|
251
|
+
|
252
|
+
def test_024_exception_cant_edit_file
|
253
|
+
assert_raises(EditorProblem) { @blog.edit_initial_post(999) }
|
254
|
+
end
|
255
|
+
|
256
|
+
def xtest_025_exception_livetext_error # FIXME Doesn't work! Change Livetext
|
257
|
+
testfile = "testfile.lt3"
|
258
|
+
path = @blog.root + "/src/" + testfile
|
259
|
+
cmd = "echo .no_such_command > #{path}"
|
260
|
+
p cmd
|
261
|
+
system(cmd)
|
262
|
+
system("ls -l #{path}")
|
263
|
+
assert_raises(LivetextError) { @blog.process_post(testfile) }
|
264
|
+
File.rm(path)
|
265
|
+
end
|
228
266
|
|
229
267
|
# later tests...
|
230
268
|
# new view asks for deployment info and writes it
|