runeblog 0.0.55 → 0.0.56

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3230f2f1ce1ac7d38765560c832a5acb40189b47
4
- data.tar.gz: c6692b68329296918053f618ff0efc909cd33c8e
3
+ metadata.gz: b0591507ef7d41996c99c71b941f0c19db8b5367
4
+ data.tar.gz: 72f6b28977828e4ad7817517559b957254f9ccf5
5
5
  SHA512:
6
- metadata.gz: 4934899d445ad1064a16e4e8c60c7122721b58b9d838dbee718c41c3680a0305f8b0ee5d34731d4e7a98d4cceb839fcb9fc87f0d006d8842dd15947e9966e53c
7
- data.tar.gz: 3cc0e19544bb1ebb3907096182c10af03c75322057813a03e9cd993644542af26ab14da6152c00af72561a146590c78c5522ade8d904fe39b7314b219ad7c111
6
+ metadata.gz: 0a3e0557200eb79f38b34a92172b4bcc33b62f633f6fed4e6865d0c466331614f6e4d50c34327f8310ff4fdc8c60715d21de2e9068c71221320907c8f407f33c
7
+ data.tar.gz: 03bb6bf9cf326e75e406ea698ddb48e08d2b58a5f27c8d2c40d7b50ba9a641ab93115f4afbd4371ec14f94e0c4cd1c7be9f69513ab37ed77f64abbd5bd7960a6
data/data/VERSION CHANGED
@@ -1 +1 @@
1
- RuneBlog v 0.0.55 2018-09-10
1
+ RuneBlog v 0.0.56 2018-09-10
data/lib/helpers-repl.rb CHANGED
@@ -74,17 +74,17 @@ module RuneBlog::REPL
74
74
  result = m ? m.to_a : nil
75
75
  next unless result
76
76
  found = meth
77
- params = m[1..-1]
77
+ params = m[1]
78
78
  end
79
79
  meth = found || :cmd_INVALID
80
80
  params = cmd if meth == :cmd_INVALID
81
- [meth, params.first]
81
+ [meth, params]
82
82
  end
83
83
 
84
84
  def error(err)
85
85
  str = "\n Error: #{red(err)}"
86
86
  puts str
87
- puts err.backtrace
87
+ puts err.backtrace[0]
88
88
  end
89
89
 
90
90
  def ask(prompt, meth = :to_s)
@@ -124,23 +124,6 @@ module RuneBlog::REPL
124
124
  red(slug[0..3])+blue(slug[4..-1])
125
125
  end
126
126
 
127
- ### process_post
128
-
129
- def process_post(file)
130
- @main ||= Livetext.new
131
- @main.main.output = File.new("/tmp/WHOA","w")
132
- path = @root + "/src/#{file}"
133
- @meta = @main.process_file(path, binding)
134
- raise "process_file returned nil" if @meta.nil?
135
-
136
- slug = @blog.make_slug(@meta.title, @blog.sequence)
137
- slug = file.sub(/.lt3$/, "")
138
- @meta.slug = slug
139
- @meta
140
- rescue => err
141
- error(err)
142
- end
143
-
144
127
  ### reload_post
145
128
 
146
129
  def reload_post(file)
@@ -153,7 +136,7 @@ module RuneBlog::REPL
153
136
  error(err)
154
137
  end
155
138
 
156
- ### posting
139
+ ## posting
157
140
 
158
141
  def posting(view, meta)
159
142
  # FIXME clean up and generalize
@@ -170,31 +153,6 @@ module RuneBlog::REPL
170
153
  HTML
171
154
  end
172
155
 
173
- ### generate_index
174
-
175
- def generate_index(view)
176
- # Gather all posts, create list
177
- vdir = "#@root/views/#{view}"
178
- posts = Dir.entries(vdir).grep /^\d\d\d\d/
179
- posts = posts.sort.reverse
180
-
181
- # Add view header/trailer
182
- head = File.read("#{vdir}/custom/blog_header.html") rescue RuneBlog::BlogHeader
183
- tail = File.read("#{vdir}/custom/blog_trailer.html") rescue RuneBlog::BlogTrailer
184
- @bloghead = interpolate(head)
185
- @blogtail = interpolate(tail)
186
-
187
- # Output view
188
- posts.map! {|post| YAML.load(File.read("#{vdir}/#{post}/metadata.yaml")) }
189
- File.open("#{vdir}/index.html", "w") do |f|
190
- f.puts @bloghead
191
- posts.each {|post| f.puts posting(view, post) }
192
- f.puts @blogtail
193
- end
194
- rescue => err
195
- error(err)
196
- end
197
-
198
156
  ### create_dir
199
157
 
200
158
  def create_dir(dir)
@@ -203,22 +161,6 @@ module RuneBlog::REPL
203
161
  raise "Can't create #{dir}" unless result
204
162
  end
205
163
 
206
- ### link_post_view
207
-
208
- def link_post_view(view)
209
- # Create dir using slug (index.html, metadata?)
210
- vdir = @blog.viewdir(view)
211
- dir = vdir + @meta.slug + "/"
212
- create_dir(dir + "assets")
213
- File.write("#{dir}/metadata.yaml", @meta.to_yaml)
214
- template = File.read(vdir + "custom/post_template.html")
215
- post = interpolate(template)
216
- File.write(dir + "index.html", post)
217
- generate_index(view)
218
- rescue => err
219
- error(err)
220
- end
221
-
222
164
  ### find_asset
223
165
 
224
166
  # def find_asset(asset) # , views)
@@ -253,23 +195,6 @@ module RuneBlog::REPL
253
195
  # list.each {|asset| puts "#{asset} => #{find_asset(asset, views)}" }
254
196
  # end
255
197
 
256
- ### publish_post
257
-
258
- def publish_post(meta)
259
- puts " #{colored_slug(meta.slug)}"
260
- # First gather the views
261
- views = meta.views
262
- print " Views: "
263
- views.each do |view|
264
- print "#{view} "
265
- link_post_view(view)
266
- end
267
- # assets = find_all_assets(@meta.assets, views)
268
- puts
269
- rescue => err
270
- error(err)
271
- end
272
-
273
198
  ### rebuild_post
274
199
 
275
200
  def rebuild_post(file)
data/lib/repl.rb CHANGED
@@ -1,43 +1,22 @@
1
1
  require 'runeblog'
2
-
3
2
  require 'ostruct'
4
-
5
- =begin
6
- Instance vars in original code:
7
- @bloghead
8
- @blogtail
9
- @config
10
- @date
11
- @deploy
12
- @fname
13
- @main
14
- @meta
15
- @root
16
- @sequence
17
- @slug
18
- @template
19
- @title
20
- @today
21
- @view
22
- =end
23
-
24
3
  require 'helpers-repl' # FIXME structure
25
4
 
26
5
  module RuneBlog::REPL
27
6
 
28
7
  def cmd_quit(arg)
29
- raise "Glitch: #{__callee__} Got an argument" if arg != []
8
+ raise "Glitch: #{__callee__} got arg #{arg.inspect}" unless arg.nil?
30
9
  puts "\n "
31
10
  exit
32
11
  end
33
12
 
34
13
  def cmd_version(arg)
35
- raise "Glitch: #{__callee__} Got an argument" if arg != []
14
+ raise "Glitch: #{__callee__} got arg #{arg.inspect}" unless arg.nil?
36
15
  return "\n " + RuneBlog::VERSION
37
16
  end
38
17
 
39
18
  def new_blog!(arg) # FIXME weird?
40
- raise "Glitch: #{__callee__} Got an argument" if arg != []
19
+ raise "Glitch: #{__callee__} got arg #{arg.inspect}" unless arg.nil?
41
20
  return if RuneBlog.exist?
42
21
  yn = yesno(red(" No .blog found. Create new blog? "))
43
22
  RuneBlog.create_new_blog if yn
@@ -46,7 +25,6 @@ module RuneBlog::REPL
46
25
  end
47
26
 
48
27
  def open_blog # Crude - FIXME later
49
- # new_blog!([]) unless RuneBlog.exist?
50
28
  @blog = RuneBlog.new
51
29
  @view = @blog.view # current view
52
30
  @sequence = @blog.sequence
@@ -56,16 +34,8 @@ module RuneBlog::REPL
56
34
  error(err)
57
35
  end
58
36
 
59
- def edit_initial_post(file)
60
- result = system("vi #@root/src/#{file} +8 ")
61
- raise "Problem editing #@root/src/#{file}" unless result
62
- nil
63
- rescue => err
64
- error(err)
65
- end
66
-
67
37
  def cmd_browse
68
- raise "Glitch: #{__callee__} Got an argument" if arg != []
38
+ raise "Glitch: #{__callee__} got arg #{arg.inspect}" unless arg.nil?
69
39
  @deploy ||= {}
70
40
  return puts red("\n Deploy first.") unless @deploy[@view]
71
41
 
@@ -88,7 +58,7 @@ module RuneBlog::REPL
88
58
 
89
59
  def cmd_deploy(arg) # FIXME non-string return expected in caller?
90
60
  # TBD clunky FIXME
91
- raise "Glitch: #{__callee__} Got an argument" if arg != []
61
+ raise "Glitch: #{__callee__} got arg #{arg.inspect}" unless arg.nil?
92
62
  @deploy ||= {}
93
63
  deployment = @blog.viewdir(@view) + "deploy"
94
64
  raise "File '#{deployment}' not found" unless File.exist?(deployment)
@@ -125,7 +95,7 @@ module RuneBlog::REPL
125
95
  end
126
96
 
127
97
  def cmd_rebuild(arg)
128
- raise "Glitch: #{__callee__} Got an argument" if arg != []
98
+ raise "Glitch: #{__callee__} got arg #{arg.inspect}" unless arg.nil?
129
99
  puts
130
100
  files = Dir.entries("#@root/src/").grep /\d\d\d\d.*.lt3$/
131
101
  files.map! {|f| File.basename(f) }
@@ -137,7 +107,7 @@ module RuneBlog::REPL
137
107
  end
138
108
 
139
109
  def cmd_relink(arg)
140
- raise "Glitch: #{__callee__} Got an argument" if arg != []
110
+ raise "Glitch: #{__callee__} got arg #{arg.inspect}" unless arg.nil?
141
111
  @blog.views.each {|view| generate_index(view) }
142
112
  nil
143
113
  rescue => err
@@ -146,7 +116,7 @@ module RuneBlog::REPL
146
116
 
147
117
  def cmd_list_views(arg)
148
118
  abort "Config file not read" unless @blog
149
- raise "Glitch: #{__callee__} Got an argument" if arg != []
119
+ raise "Glitch: #{__callee__} got arg #{arg.inspect}" unless arg.nil?
150
120
  out = "\n"
151
121
  @blog.views.each {|v| out << " #{v}\n" }
152
122
  out
@@ -155,11 +125,10 @@ module RuneBlog::REPL
155
125
  end
156
126
 
157
127
  def cmd_change_view(arg)
158
- if arg.empty?
128
+ if arg.nil?
159
129
  return "\n #{@blog.view}"
160
130
  else
161
131
  out = ""
162
- arg = arg.first
163
132
  list = @blog.views.grep /^#{arg}/
164
133
  if list.size == 1
165
134
  @view = @blog.view = list.first
@@ -174,7 +143,6 @@ module RuneBlog::REPL
174
143
  end
175
144
 
176
145
  def cmd_new_view(arg)
177
- arg = arg.first
178
146
  @blog ||= open_blog
179
147
  arg ||= ask("New view: ") # check validity later
180
148
  raise "view #{arg} already exists" if @blog.views.include?(arg)
@@ -182,6 +150,7 @@ module RuneBlog::REPL
182
150
  dir = @root + "/views/" + arg + "/"
183
151
  create_dir(dir + 'custom')
184
152
  create_dir(dir + 'assets')
153
+ File.open(dir + "deploy") { } # FIXME
185
154
 
186
155
  # Something more like this? RuneBlog.new_view(arg)
187
156
  File.write(dir + "custom/blog_header.html", RuneBlog::BlogHeader)
@@ -193,23 +162,16 @@ module RuneBlog::REPL
193
162
  end
194
163
 
195
164
  def cmd_new_post(arg)
196
- raise "Glitch: #{__callee__} Got an argument" if arg != []
197
- open_blog unless @blog
165
+ raise "Glitch: #{__callee__} got arg #{arg.inspect}" unless arg.nil?
166
+ open_blog unless @blog # duh?
198
167
  @title = ask("Title: ")
199
- @today = Time.now.strftime("%Y%m%d")
200
- @date = Time.now.strftime("%Y-%m-%d")
201
-
202
- file = @blog.create_new_post(@title, @date, @view)
203
- edit_initial_post(file)
204
- process_post(file) #- FIXME handle each view
205
- publish_post(@meta)
206
- nil
168
+ @blog.create_new_post(@title)
207
169
  rescue => err
208
170
  error(err)
209
171
  end
210
172
 
211
173
  def cmd_kill(arg)
212
- args = arg.first.split
174
+ args = arg.split
213
175
  args.each {|x| cmd_remove_post([x], false) }
214
176
  nil
215
177
  rescue => err
@@ -220,7 +182,6 @@ module RuneBlog::REPL
220
182
 
221
183
  def cmd_remove_post(arg, safe=true)
222
184
  out = ""
223
- arg = arg.first
224
185
  id = Integer(arg) rescue raise("'#{arg}' is not an integer")
225
186
  tag = "#{'%04d' % id}"
226
187
  files = Find.find(@root).to_a
@@ -258,7 +219,6 @@ module RuneBlog::REPL
258
219
  #-- FIXME affects linking, building, deployment...
259
220
 
260
221
  def cmd_edit_post(arg)
261
- arg = arg.first
262
222
  id = Integer(arg) rescue raise("'#{arg}' is not an integer")
263
223
  tag = "#{'%04d' % id}"
264
224
  files = Find.find(@root+"/src").to_a
@@ -278,7 +238,7 @@ module RuneBlog::REPL
278
238
  end
279
239
 
280
240
  def cmd_list_posts(arg)
281
- raise "Glitch: #{__callee__} Got an argument" if arg != []
241
+ raise "Glitch: #{__callee__} got arg #{arg.inspect}" unless arg.nil?
282
242
  out = ""
283
243
  @view = @blog.view
284
244
  dir = @blog.viewdir(@view)
@@ -297,7 +257,7 @@ module RuneBlog::REPL
297
257
  end
298
258
 
299
259
  def cmd_list_drafts(arg)
300
- raise "Glitch: #{__callee__} Got an argument" if arg != []
260
+ raise "Glitch: #{__callee__} got arg #{arg.inspect}" unless arg.nil?
301
261
  out = ""
302
262
  dir = "#@root/src"
303
263
  Dir.chdir(dir) do
@@ -319,7 +279,7 @@ module RuneBlog::REPL
319
279
  end
320
280
 
321
281
  def cmd_help(arg)
322
- raise "Glitch: #{__callee__} Got an argument" if arg != []
282
+ raise "Glitch: #{__callee__} got arg #{arg.inspect}" unless arg.nil?
323
283
  out = <<-EOS
324
284
 
325
285
  Commands:
data/lib/runeblog.rb CHANGED
@@ -3,7 +3,7 @@ require 'yaml'
3
3
  require 'livetext'
4
4
 
5
5
  class RuneBlog
6
- VERSION = "0.0.55"
6
+ VERSION = "0.0.56"
7
7
 
8
8
  Path = File.expand_path(File.join(File.dirname(__FILE__)))
9
9
  DefaultData = Path + "/../data"
@@ -56,7 +56,9 @@ class RuneBlog
56
56
  File.exist?(".blog")
57
57
  end
58
58
 
59
- def create_new_post(title, date, view)
59
+ def create_new_post(title, view=nil)
60
+ view ||= @view
61
+ date = Time.now.strftime("%Y-%m-%d")
60
62
  @template = <<-EOS
61
63
  .mixin liveblog
62
64
 
@@ -73,7 +75,84 @@ EOS
73
75
  @slug = make_slug(title)
74
76
  @fname = @slug + ".lt3"
75
77
  File.open("#@root/src/#@fname", "w") {|f| f.puts @template }
76
- @fname
78
+ edit_initial_post(@fname) # How eliminate for testing?
79
+ process_post(@fname) #- FIXME handle each view
80
+ publish_post(@meta)
81
+ rescue => err
82
+ error(err)
83
+ end
84
+
85
+ def edit_initial_post(file)
86
+ result = system("vi #@root/src/#{file} +8 ")
87
+ raise "Problem editing #@root/src/#{file}" unless result
88
+ nil
89
+ rescue => err
90
+ error(err)
91
+ end
92
+
93
+ def process_post(file)
94
+ @main ||= Livetext.new
95
+ @main.main.output = File.new("/tmp/WHOA","w")
96
+ path = @root + "/src/#{file}"
97
+ @meta = @main.process_file(path, binding)
98
+ raise "process_file returned nil" if @meta.nil?
99
+
100
+ slug = self.make_slug(@meta.title, self.sequence)
101
+ slug = file.sub(/.lt3$/, "")
102
+ @meta.slug = slug
103
+ @meta
104
+ rescue => err
105
+ error(err)
106
+ end
107
+
108
+ def publish_post(meta)
109
+ puts " #{colored_slug(meta.slug)}"
110
+ # First gather the views
111
+ views = meta.views
112
+ print " Views: "
113
+ views.each do |view|
114
+ print "#{view} "
115
+ link_post_view(view)
116
+ end
117
+ # assets = find_all_assets(@meta.assets, views)
118
+ puts
119
+ rescue => err
120
+ error(err)
121
+ end
122
+
123
+ def link_post_view(view)
124
+ # Create dir using slug (index.html, metadata?)
125
+ vdir = self.viewdir(view)
126
+ dir = vdir + @meta.slug + "/"
127
+ create_dir(dir + "assets")
128
+ File.write("#{dir}/metadata.yaml", @meta.to_yaml)
129
+ template = File.read(vdir + "custom/post_template.html")
130
+ post = interpolate(template)
131
+ File.write(dir + "index.html", post)
132
+ generate_index(view)
133
+ rescue => err
134
+ error(err)
135
+ end
136
+
137
+ def generate_index(view)
138
+ # Gather all posts, create list
139
+ vdir = "#@root/views/#{view}"
140
+ posts = Dir.entries(vdir).grep /^\d\d\d\d/
141
+ posts = posts.sort.reverse
142
+
143
+ # Add view header/trailer
144
+ head = File.read("#{vdir}/custom/blog_header.html") rescue RuneBlog::BlogHeader
145
+ tail = File.read("#{vdir}/custom/blog_trailer.html") rescue RuneBlog::BlogTrailer
146
+ @bloghead = interpolate(head)
147
+ @blogtail = interpolate(tail)
148
+
149
+ # Output view
150
+ posts.map! {|post| YAML.load(File.read("#{vdir}/#{post}/metadata.yaml")) }
151
+ File.open("#{vdir}/index.html", "w") do |f|
152
+ f.puts @bloghead
153
+ posts.each {|post| f.puts posting(view, post) }
154
+ f.puts @blogtail
155
+ end
77
156
  rescue => err
78
157
  error(err)
79
158
  end
data/test/repl.rb CHANGED
@@ -13,14 +13,14 @@ class TestREPL < Minitest::Test
13
13
  end
14
14
 
15
15
  def test_001_cmd_help
16
- out = cmd_help([])
16
+ out = cmd_help(nil)
17
17
  assert out.is_a?(String), "Expected a string returned"
18
18
  lines = out.split("\n").length
19
19
  assert lines > 25, "Expecting lengthy help message"
20
20
  end
21
21
 
22
22
  def test_002_cmd_version
23
- out = cmd_version([])
23
+ out = cmd_version(nil)
24
24
  assert out.is_a?(String), "Expected a string returned"
25
25
  lines = out.split("\n")[1]
26
26
  assert lines =~ /\d+\.\d+\.\d+/m,
@@ -28,27 +28,27 @@ class TestREPL < Minitest::Test
28
28
  end
29
29
 
30
30
  def test_003_list_views
31
- out = cmd_list_views([])
31
+ out = cmd_list_views(nil)
32
32
  assert out.is_a?(String), "Expected a string returned"
33
33
  lines = out.split("\n").length
34
34
  assert lines >= 2, "Expecting at least 2 lines"
35
35
  end
36
36
 
37
37
  def test_004_change_view
38
- out = cmd_change_view([]) # no param
39
- assert out.is_a?(String), "Expected a string returned"
38
+ out = cmd_change_view(nil) # no param
39
+ assert out.is_a?(String), "Expected a string; got: #{out.inspect}"
40
40
  assert out =~ /computing/m, "Expecting 'computing' as default; got: #{out.inspect}"
41
41
  end
42
42
 
43
43
  def test_005_lsd
44
- out = cmd_list_drafts([])
44
+ out = cmd_list_drafts(nil)
45
45
  assert out.is_a?(String), "Expected a string returned"
46
46
  lines = out.split("\n").length
47
47
  assert lines >= 15, "Expecting more lines; got: #{out.inspect}"
48
48
  end
49
49
 
50
50
  def test_006_lsp
51
- out = cmd_list_posts([])
51
+ out = cmd_list_posts(nil)
52
52
  assert out.is_a?(String), "Expected a string returned; got: #{out.inspect}"
53
53
  lines = out.split("\n").length
54
54
  assert lines >= 20, "Expecting more lines; got: #{out.inspect}"
@@ -56,10 +56,42 @@ class TestREPL < Minitest::Test
56
56
 
57
57
  def test_007_parser
58
58
  parse_tests = {
59
- "kill 81 82 83" => [:cmd_kill, "81 82 83"],
60
- " kill 81 82 83" => [:cmd_kill, "81 82 83"],
61
- "kill 81 82 83 " => [:cmd_kill, "81 82 83"],
62
- " kill 81 82 83 " => [:cmd_kill, "81 82 83"]
59
+ # Loading/trailing blanks as well
60
+ "kill 81 82 83" => [:cmd_kill, "81 82 83"],
61
+ " kill 81 82 83" => [:cmd_kill, "81 82 83"],
62
+ "kill 81 82 83 " => [:cmd_kill, "81 82 83"],
63
+ " kill 81 82 83 " => [:cmd_kill, "81 82 83"],
64
+ "help" => [:cmd_help, nil],
65
+ "h" => [:cmd_help, nil],
66
+ "version" => [:cmd_version, nil],
67
+ "v" => [:cmd_version, nil],
68
+ "list views" => [:cmd_list_views, nil],
69
+ "lsv" => [:cmd_list_views, nil],
70
+ "new view foobar" => [:cmd_new_view, "foobar"],
71
+ "new post" => [:cmd_new_post, nil],
72
+ "p" => [:cmd_new_post, nil],
73
+ "post" => [:cmd_new_post, nil],
74
+ "change view view2" => [:cmd_change_view, "view2"],
75
+ "cv" => [:cmd_change_view, nil], # 0-arity
76
+ "cv myview" => [:cmd_change_view, "myview"],
77
+ "list posts" => [:cmd_list_posts, nil],
78
+ "lsp" => [:cmd_list_posts, nil],
79
+ "list drafts" => [:cmd_list_drafts, nil],
80
+ "lsd" => [:cmd_list_drafts, nil],
81
+ "rm 999" => [:cmd_remove_post, "999"],
82
+ "kill 101 102 103" => [:cmd_kill, "101 102 103"],
83
+ "edit 104" => [:cmd_edit_post, "104"],
84
+ "ed 105" => [:cmd_edit_post, "105"],
85
+ "e 106" => [:cmd_edit_post, "106"],
86
+ "preview" => [:cmd_preview, nil],
87
+ "pre" => [:cmd_preview, nil],
88
+ "browse" => [:cmd_browse, nil],
89
+ "relink" => [:cmd_relink, nil],
90
+ "rebuild" => [:cmd_rebuild, nil],
91
+ "deploy" => [:cmd_deploy, nil],
92
+ "q" => [:cmd_quit, nil],
93
+ "quit" => [:cmd_quit, nil]
94
+ # Later: too many/few params
63
95
  }
64
96
 
65
97
  parse_tests.each_pair do |cmd, expected|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: runeblog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.55
4
+ version: 0.0.56
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hal Fulton