runeblog 0.0.85 → 0.0.86

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/runeblog.rb +25 -5
  3. data/lib/version.rb +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 08c941c930b749a00a51599199cf83f8d072d736
4
- data.tar.gz: 341352d2e1678bc543a502b7b8abce7d32e7b0cd
3
+ metadata.gz: f561cb43b171a92ba7b8d6156e2496b7c94cdd73
4
+ data.tar.gz: 0d719b8f5233062fb540ec8f6127fb774524369c
5
5
  SHA512:
6
- metadata.gz: 9faa908cc4cda8fc8c5371378d44ddae7e0d71ba978f2cb392130763e688d3c0c5c73fc4f51a513e236edcb168fcd3124b3b25ba28c34a3372cd945a01a5fa14
7
- data.tar.gz: 6422b5a0347c8ed089a20af0987a963f34221d738e6cf01f7d8be12c0733cdc08bd258f368c42c4d8345f0aa74de548f379dd28cf9e1d30a4d555217c18b5baa
6
+ metadata.gz: e58e6e714a115c0820616b411862acec32b13815f5ca0d387623f7cd0f103545150ee3429aad747906a01f2f843742e1d908b845cfb238c5e471e68b8f2f88f5
7
+ data.tar.gz: a93184f843dcc8069bbbb28807bc77846d68996c3a985e68db93a8316460d4cf5dd86bdc2bd36395d57ff858bd12b235e32b84ad6e61505499f3a946daab3d8a
@@ -27,7 +27,10 @@ class RuneBlog
27
27
  include Helpers
28
28
 
29
29
  def self.create_new_blog(dir)
30
- new_dotfile(root: Dir.pwd + "/" + dir)
30
+ raise ArgumentError unless dir.is_a?(String) && ! dir.empty?
31
+ root_dir = Dir.pwd + "/" + dir
32
+ raise "Already exists" if Dir.exist?(root_dir)
33
+ new_dotfile(root: root_dir)
31
34
  create_dir(dir)
32
35
  Dir.chdir(dir) do
33
36
  create_dir("views")
@@ -52,14 +55,17 @@ class RuneBlog
52
55
  end
53
56
 
54
57
  def view?(name)
58
+ raise ArgumentError unless name.is_a?(String) && ! name.empty?
55
59
  views.any? {|x| x.name == name }
56
60
  end
57
61
 
58
62
  def view(name = nil)
63
+ raise ArgumentError unless name.nil? || (name.is_a?(String) && ! name.empty?)
59
64
  name.nil? ? @view : str2view(name)
60
65
  end
61
66
 
62
67
  def str2view(str)
68
+ raise ArgumentError unless str.is_a?(String) && ! str.empty?
63
69
  @views.find {|x| x.name == str }
64
70
  end
65
71
 
@@ -88,6 +94,7 @@ class RuneBlog
88
94
  end
89
95
 
90
96
  def viewdir(v = nil)
97
+ raise ArgumentError unless v.nil? || v.is_a?(RuneBlog::View)
91
98
  v ||= @view
92
99
  @root + "/views/#{v}/"
93
100
  end
@@ -97,10 +104,12 @@ class RuneBlog
97
104
  end
98
105
 
99
106
  def create_view(arg)
107
+ raise ArgumentError unless arg.is_a?(String) && ! arg.empty?
100
108
  names = self.views.map(&:to_s)
101
109
  raise "view #{arg} already exists" if names.include?(arg)
102
110
 
103
111
  dir = "#@root/views/#{arg}/"
112
+ raise "Can't happen: #{fir} exists already" if Dir.exist?(dir)
104
113
  create_dir(dir)
105
114
  up = Dir.pwd
106
115
  Dir.chdir(dir)
@@ -118,6 +127,7 @@ class RuneBlog
118
127
  end
119
128
 
120
129
  def delete_view(name, force = false)
130
+ raise ArgumentError unless name.is_a?(String) && ! name.empty?
121
131
  if force
122
132
  system("rm -rf #@root/views/#{name}")
123
133
  @views -= [str2view(name)]
@@ -133,6 +143,7 @@ class RuneBlog
133
143
  end
134
144
 
135
145
  def files_by_id(id)
146
+ raise ArgumentError unless id.is_a?(Integer)
136
147
  files = Find.find(self.view.dir).to_a
137
148
  tag = "#{'%04d' % id}"
138
149
  result = files.grep(/#{tag}-/)
@@ -171,14 +182,17 @@ class RuneBlog
171
182
  end
172
183
 
173
184
  def change_view(view)
185
+ raise ArgumentError unless view.is_a?(String) || view.is_a?(RuneBlog::View)
174
186
  x = OpenStruct.new
175
- x.root, x.current_view, x.editor = @root, view, @editor # dumb - FIXME later
176
- write_config(x, DotDir + "/config")
187
+ x.root, x.current_view, x.editor = @root, view.to_s, @editor # dumb - FIXME later
188
+ write_config(x, ConfigFile)
177
189
  self.view = view # error checking?
178
190
  end
179
191
 
180
192
  def process_post(file)
193
+ raise ArgumentError unless file.is_a?(String)
181
194
  path = @root + "/src/#{file}"
195
+ raise "File not found: #{path}" unless File.exist?(path)
182
196
  livetext = Livetext.new(STDOUT) # (nil)
183
197
  @meta = livetext.process_file(path, binding)
184
198
  raise "process_file returned nil" if @meta.nil?
@@ -200,6 +214,7 @@ class RuneBlog
200
214
  end
201
215
 
202
216
  def link_post_view(view)
217
+ raise ArgumentError unless view.is_a?(String) || view.is_a?(RuneBlog::View)
203
218
  # Create dir using slug (index.html, metadata?)
204
219
  vdir = self.viewdir(view)
205
220
  dir = vdir + @meta.slug + "/"
@@ -217,6 +232,7 @@ class RuneBlog
217
232
  end
218
233
 
219
234
  def generate_index(view)
235
+ raise ArgumentError unless view.is_a?(String) || view.is_a?(RuneBlog::View)
220
236
  # Gather all posts, create list
221
237
  vdir = "#@root/views/#{view}"
222
238
  posts = Dir.entries(vdir).grep /^\d{4}/
@@ -247,6 +263,7 @@ class RuneBlog
247
263
  end
248
264
 
249
265
  def index_entry(view, meta)
266
+ raise ArgumentError unless view.is_a?(String) || view.is_a?(RuneBlog::View)
250
267
  # FIXME clean up and generalize
251
268
  ref = "#{view}/#{meta.slug}/index.html"
252
269
  <<-HTML
@@ -262,6 +279,7 @@ class RuneBlog
262
279
  end
263
280
 
264
281
  def rebuild_post(file)
282
+ raise ArgumentError unless file.is_a?(String)
265
283
  @meta = process_post(file)
266
284
  publish_post(@meta) # FIXME ??
267
285
  rescue => err
@@ -269,6 +287,7 @@ class RuneBlog
269
287
  end
270
288
 
271
289
  def remove_post(num)
290
+ raise ArgumentError unless num.is_a?(Integer)
272
291
  list = files_by_id(num)
273
292
  return nil if list.empty?
274
293
  dest = list.map {|f| f.sub(/(?<num>\d{4}-)/, "_\\k<num>") }
@@ -281,23 +300,24 @@ class RuneBlog
281
300
  end
282
301
 
283
302
  def delete_draft(num)
303
+ raise ArgumentError unless num.is_a?(Integer)
284
304
  tag = "#{'%04d' % num.to_i}"
285
305
  system("rm -rf #@root/src/#{tag}-*")
286
306
  end
287
307
 
288
308
  def post_exists?(num)
309
+ raise ArgumentError unless num.is_a?(Integer)
289
310
  list = files_by_id(num)
290
311
  list.empty? ? nil : list
291
312
  end
292
313
 
293
314
  def make_slug(title, postnum = nil)
315
+ raise ArgumentError unless title.is_a?(String)
294
316
  postnum ||= self.next_sequence
295
317
  num = '%04d' % postnum # FIXME can do better
296
318
  slug = title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
297
319
  [postnum, "#{num}-#{slug}"]
298
320
  end
299
321
 
300
- private
301
-
302
322
  end
303
323
 
@@ -1,6 +1,6 @@
1
1
 
2
2
  class RuneBlog
3
- VERSION = "0.0.85"
3
+ VERSION = "0.0.86"
4
4
 
5
5
  Path = File.expand_path(File.join(File.dirname(__FILE__)))
6
6
  end
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.85
4
+ version: 0.0.86
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-18 00:00:00.000000000 Z
11
+ date: 2018-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: livetext