runeblog 0.0.43 → 0.0.45

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: b3fbf51af336c1442a5aa62e13df695d2c2cd318
4
- data.tar.gz: 4fa03ce9ff83cc6144cc580f346733b5b8d34916
3
+ metadata.gz: f1e459ba25edc955fe31efb2e59f314c3049347c
4
+ data.tar.gz: 5eb31fa2ca94d0caa3980fb846a90ba8bad6ecbf
5
5
  SHA512:
6
- metadata.gz: 30001b22c7851778c22b3cb7be20c5af16563e89408308f42d6813dfd70d8ddd3c384dc2a7d35feac71aa6bae8631cf938051b3f11254a28d3fe119134e2514f
7
- data.tar.gz: 902447ebf5221a2130df2a1f504ab07bc086aee612af57479183e04042f963a8ef1edf9b5a041f5ae8d69b7eefd0bccc1bca24e9b9ef1effd5756dbbb32aa909
6
+ metadata.gz: ea2bf26873cceedfc76cf85f8ac8721b8140877aa33781f8b2b9ecfcd5e4f81505528a4e2cf32cfc2cc63abde263778842bf692092de56aff79352018e8fcd42
7
+ data.tar.gz: e2c050a292b68017a1ec0bbd5bbb97bae042ca7bc9f2c414e9b608b89d24f52e5e4c089d3ab6ab0635eee228ae10df7cc804a2de1d809a528d2469a60541d128
data/bin/blog CHANGED
@@ -3,212 +3,47 @@
3
3
  $: << "./lib"
4
4
 
5
5
  require 'repl'
6
+ require 'blogcmds'
6
7
 
7
8
  trap("INT") { }
8
9
 
9
10
  include RuneBlog::REPL
10
11
 
11
- def execute_command
12
- case @meth
13
- when :help, :quit, :new_post, :list_views, :relink, :rebuild, :version,
14
- :list_posts, :list_drafts, :do_nothing, :deploy, :open_remote, :open_local
15
- self.send(@meth)
16
- when Object
17
- self.send(@meth, @arg)
18
- end
19
- puts unless @meth == :do_nothing
20
- end
21
-
22
- def expected(nw = 1)
23
- save = @cmd
24
- @cmd = nil
25
- raise "Unexpected '#{@words[nw]}'" unless @words.size == nw
26
- @cmd = save
27
- end
28
-
29
- def need_arg(nw = 1)
30
- save = @cmd
31
- @cmd = nil
32
- raise "Unexpected '#{@words[nw+1]}'" if @words[nw+1]
33
- raise "Need an arg here" unless @words[nw]
34
- @cmd = save
35
- @words[nw]
36
- end
37
-
38
- def do_nothing
39
- end
40
-
41
- def expect_w(meth)
42
- @meth = meth
43
- expected(1)
44
- end
45
-
46
- def expect_w_arg(meth, optional = false)
47
- raise "Too many arguments" if @words.size > 2
48
- @meth = meth
49
- @arg = optional ? @words[1] : need_arg(1)
50
- end
51
-
52
- def handle_open
53
- case @words.size
54
- when 1
55
- @meth = :open_local
56
- when 2
57
- if @words[1] == "remote"
58
- @meth = :open_remote
59
- else
60
- raise "Don't know '#{@words[1]}'"
61
- end
62
- else
63
- raise "Don't understand '#{@words.join(' ')}'"
64
- end
65
- end
66
-
67
- def handle_list
68
- case @words[1]
69
- when "views"
70
- @meth = :list_views
71
- expected(2)
72
- when "posts"
73
- @meth = :list_posts
74
- expected(2)
75
- when "drafts"
76
- @meth = :list_drafts
77
- expected(2)
78
- else
79
- @cmd = nil
80
- raise "Unknown #{@words[1]}"
81
- end
82
- end
83
-
84
- def handle_new
85
- case @words[1]
86
- when "view"
87
- @meth = :new_view
88
- expected(2)
89
- @arg = need_arg(2)
90
- when "post"
91
- @meth = :new_post
92
- expected(2)
93
- else
94
- @cmd = nil
95
- raise "Unknown '#{@words[1]}'"
96
- end
97
- end
98
-
99
- def handle_change
100
- case @words[2]
101
- when "view"
102
- raise "Too many arguments" if @words.size > 3
103
- @meth = :change_view
104
- @arg = need_arg(2)
105
- else
106
- raise "Unknown '#{@words[1]}'"
107
- end
108
- end
109
-
110
- def handle_multi_rm
111
- raise "Need at least one arg" unless @words.size >= 2
112
- @arg = @words[1..-1].join(" ")
113
- @meth = :remove_multiple_posts
114
- end
115
-
116
- def parse_cmd(str)
117
- @cmd = str
118
- @arg = ""
119
- if @cmd == ""
120
- @meth = :do_nothing
121
- return @cmd
122
- end
123
-
124
- @words = @cmd.split
125
- case @words.first
126
- when "h", "help"; expect_w(:help)
127
- when "q", "quit"; expect_w(:quit)
128
- when "p", "post"; expect_w(:new_post)
129
- when "lsv"; expect_w(:list_views)
130
- when "lsp"; expect_w(:list_posts)
131
- when "lsd"; expect_w(:list_drafts)
132
- when "relink"; expect_w(:relink)
133
- when "rebuild"; expect_w(:rebuild)
134
- when "deploy"; expect_w(:deploy)
135
- when "version"; expect_w(:version)
136
- when "cv"; expect_w_arg(:change_view, true)
137
- when "rm"; expect_w_arg(:remove_post)
138
- when "kill"; handle_multi_rm
139
- when "e", "edit"; expect_w_arg(:edit_post)
140
- when "open"; handle_open
141
- when "list"; handle_list
142
- when "new"; handle_new
143
- when "change"; handle_change
144
- else
145
- @cmd = nil
146
- raise "Unknown '#{@words[0]}'"
147
- end
148
- @cmd
149
- end
150
-
151
12
  def get_argv
152
13
  return nil if ARGV.size == 0
153
- @cmd = ARGV[0..1].join(" ")
154
- @arg = ARGV[2]
155
- @cmd
156
- end
157
-
158
- def help
159
- puts <<-EOS
160
-
161
- Commands:
162
-
163
- h, help This message
164
- q, quit Exit the program
165
-
166
- change view VIEW Change current view
167
- new view Create a new view
168
- list views List all views available
169
- lsv Same as: list views
170
-
171
- p, post Create a new post
172
- new post Same as post (create a post)
173
- lsp, list posts List posts in current view
174
- lsd, list drafts List all posts regardless of view
175
-
176
- rm ID Remove a post
177
- edit ID Edit a post
178
-
179
- open Look at current (local) view in browser
180
- open remote Look at current (deployed) view in browser
181
- relink Regenerate index for all views
182
- rebuild Regenerate all posts and relink
183
- deploy Deploy (current view)
184
- EOS
14
+ cmd = ARGV[0..1].join(" ")
15
+ arg = ARGV[2]
16
+ [cmd, arg]
185
17
  end
186
18
 
187
19
  ###########
188
20
 
189
21
  STDOUT.sync = true
190
22
 
191
- @cmd = get_argv
23
+ cmd, arg = get_argv
192
24
 
193
25
  read_config
194
26
 
195
27
  puts red("\n RuneBlog v #{RuneBlog::VERSION}")
196
28
 
197
- if @cmd.nil? # REPL
29
+ if cmd.nil? # REPL
198
30
  puts
199
31
  loop do
200
32
  print red("blog> ")
201
33
  begin
202
- parse_cmd(gets.chomp)
34
+ cmd = gets.chomp
35
+ meth, params = Command.choose_method(cmd)
203
36
  rescue => err
204
37
  puts err
205
38
  next
206
39
  end
207
- execute_command
40
+ send(meth, params)
208
41
  end
209
42
  else # one command
43
+ raise "Not working right now"
210
44
  file = File.open("/dev/tty")
211
45
  STDIN.reopen(file) # avoid ARGF dumbness
46
+ meth, params = Command.choose_method(cmd)
212
47
  parse_cmd(ARGV.join(" "))
213
48
  execute_command
214
49
  end
data/data/VERSION CHANGED
@@ -1 +1 @@
1
- RuneBlog v 0.0.43 2018-07-31
1
+ RuneBlog v 0.0.45 2018-08-27
data/lib/blogcmds.rb ADDED
@@ -0,0 +1,95 @@
1
+ # help
2
+ # list views
3
+ # new view $viewname
4
+
5
+ class Command
6
+ Patterns =
7
+ {"help" => :cmd_help,
8
+ "h" => :cmd_help,
9
+
10
+ "list views" => :cmd_list_views,
11
+ "lsv" => :cmd_list_views,
12
+
13
+ "new view $name" => :cmd_new_view,
14
+
15
+ "new post" => :cmd_new_post,
16
+ "p" => :cmd_new_post,
17
+ "post" => :cmd_new_post,
18
+
19
+ "change view $name" => :cmd_change_views,
20
+ "cv $name" => :cmd_change_views,
21
+
22
+ "list posts" => :cmd_list_posts,
23
+ "lsp" => :cmd_list_posts,
24
+
25
+ "list drafts" => :cmd_list_drafts,
26
+ "lsd" => :cmd_list_drafts,
27
+
28
+ "rm $postid" => :cmd_remove_post,
29
+
30
+ "edit $postid" => :cmd_edit_post,
31
+ "ed $postid" => :cmd_edit_post,
32
+ "e $postid" => :cmd_edit_post,
33
+
34
+ "preview" => :cmd_preview,
35
+
36
+ "pre" => :cmd_preview,
37
+
38
+ "browse" => :cmd_browse,
39
+
40
+ "relink" => :cmd_relink,
41
+
42
+ "rebuild" => :cmd_rebuild,
43
+
44
+ "deploy" => :cmd_deploy,
45
+
46
+ "q" => :cmd_quit,
47
+ "quit" => :cmd_quit
48
+ }
49
+
50
+ Regexes = {}
51
+ Patterns.each_pair do |pat, meth|
52
+ rx = "^" + pat
53
+ rx.gsub!(/ /, " +")
54
+ rx.gsub!(/\$(\w+) */) { " *(?<#{$1}>\\w+)" }
55
+ rx << "$"
56
+ rx = Regexp.new(rx)
57
+ Regexes[rx] = meth
58
+ end
59
+
60
+ def self.choose_method(cmd)
61
+ found = nil
62
+ params = []
63
+ Regexes.each_pair do |rx, meth|
64
+ m = cmd.match(rx)
65
+ result = m ? m.to_a : nil
66
+ next unless result
67
+ found = meth
68
+ params = m[1..-1]
69
+ end
70
+ meth = found || :cmd_INVALID
71
+ params = cmd if meth == :cmd_INVALID
72
+ [meth, params]
73
+ end
74
+ end
75
+
76
+ # test_cmds = [
77
+ # "fake cmd foo bar",
78
+ # "help",
79
+ # "h",
80
+ # "list views",
81
+ # "lsv",
82
+ # "new view foo",
83
+ # "not valid",
84
+ # "help invalid",
85
+ # "new view",
86
+ # "new view too many args"]
87
+ #
88
+ # loop do
89
+ # print "\nCmd = "
90
+ # cmd = gets.chomp.strip
91
+ # meth, params = Command.choose_method(cmd)
92
+ # puts " Calling: #{meth}(#{params.inspect})"
93
+ # end
94
+
95
+
data/lib/repl.rb CHANGED
@@ -48,20 +48,23 @@ module RuneBlog::REPL
48
48
 
49
49
  ### quit
50
50
 
51
- def quit
51
+ def cmd_quit(arg)
52
+ raise "Glitch: Got an argument" if arg != []
52
53
  puts
53
54
  exit
54
55
  end
55
56
 
56
57
  ### version
57
58
 
58
- def version
59
+ def cmd_version(arg)
60
+ raise "Glitch: Got an argument" if arg != []
59
61
  puts "\n " + RuneBlog::VERSION
60
62
  end
61
63
 
62
64
  ### new_blog!
63
65
 
64
- def new_blog!
66
+ def cmd_new_blog!(arg)
67
+ raise "Glitch: Got an argument" if arg != []
65
68
  unless File.exist?(".blog")
66
69
  yn = ask(red(" No .blog found. Create new blog? "))
67
70
  if yn.upcase == "Y"
@@ -137,9 +140,10 @@ Remainder of post goes here.
137
140
  error(err, __LINE__, __FILE__)
138
141
  end
139
142
 
140
- ### open_remote
143
+ ### browse
141
144
 
142
- def open_remote
145
+ def cmd_browse
146
+ raise "Glitch: Got an argument" if arg != []
143
147
  @deploy ||= {}
144
148
  return puts red("\n Deploy first.") unless @deploy[@view]
145
149
 
@@ -160,8 +164,9 @@ Remainder of post goes here.
160
164
  error(err, __LINE__, __FILE__)
161
165
  end
162
166
 
163
- def deploy
167
+ def cmd_deploy(arg)
164
168
  # TBD clunky FIXME
169
+ raise "Glitch: Got an argument" if arg != []
165
170
  @deploy ||= {}
166
171
  deployment = @config.viewdir(@view) + "deploy"
167
172
  raise "File '#{deployment}' not found" unless File.exist?(deployment)
@@ -348,7 +353,8 @@ Remainder of post goes here.
348
353
 
349
354
  ### rebuild
350
355
 
351
- def rebuild
356
+ def cmd_rebuild(arg)
357
+ raise "Glitch: Got an argument" if arg != []
352
358
  puts
353
359
  files = Dir.entries("#@root/src/").grep /\d\d\d\d.*.lt3$/
354
360
  files.map! {|f| File.basename(f) }
@@ -360,7 +366,8 @@ Remainder of post goes here.
360
366
 
361
367
  ### relink
362
368
 
363
- def relink
369
+ def cmd_relink(arg)
370
+ raise "Glitch: Got an argument" if arg != []
364
371
  @config.views.each {|view| generate_index(view) }
365
372
  rescue => err
366
373
  error(err, __LINE__, __FILE__)
@@ -375,8 +382,9 @@ Remainder of post goes here.
375
382
 
376
383
  ### list_views
377
384
 
378
- def list_views
385
+ def cmd_list_views(arg)
379
386
  abort "Config file not read" unless @config
387
+ raise "Glitch: Got an argument" if arg != []
380
388
  puts
381
389
  @config.views.each {|v| puts " #{v}" }
382
390
  rescue => err
@@ -385,10 +393,11 @@ Remainder of post goes here.
385
393
 
386
394
  ### change_view
387
395
 
388
- def change_view(arg = nil)
389
- if arg.nil?
396
+ def cmd_change_view(arg)
397
+ if arg.empty?
390
398
  puts "\n #@view"
391
399
  else
400
+ arg = arg.first
392
401
  list = @config.views.grep /^#{arg}/
393
402
  if list.size == 1
394
403
  @view = @config.view = list.first
@@ -403,8 +412,8 @@ Remainder of post goes here.
403
412
 
404
413
  ### new_view
405
414
 
406
- def new_view(arg = nil)
407
- arg = nil if arg == ""
415
+ def cmd_new_view(arg)
416
+ arg = arg.first
408
417
  read_config unless @config
409
418
  arg ||= ask("New view: ") # check validity later
410
419
  raise "view #{arg} already exists" if @config.views.include?(arg)
@@ -413,6 +422,7 @@ Remainder of post goes here.
413
422
  create_dir(dir + 'custom')
414
423
  create_dir(dir + 'assets')
415
424
 
425
+ # Something more like this? RuneBlog.new_view(arg)
416
426
  File.write(dir + "custom/blog_header.html", RuneBlog::BlogHeader)
417
427
  File.write(dir + "custom/blog_trailer.html", RuneBlog::BlogTrailer)
418
428
  File.write(dir + "last_deployed", "Initial creation")
@@ -444,7 +454,8 @@ Remainder of post goes here.
444
454
 
445
455
  ### new_post
446
456
 
447
- def new_post
457
+ def cmd_new_post(arg)
458
+ raise "Glitch: Got an argument" if arg != []
448
459
  read_config unless @config
449
460
  @title = ask("Title: ")
450
461
  @today = Time.now.strftime("%Y%m%d")
@@ -470,7 +481,8 @@ Remainder of post goes here.
470
481
 
471
482
  #-- FIXME affects linking, building, deployment...
472
483
 
473
- def remove_post(arg, safe=true)
484
+ def cmd_remove_post(arg, safe=true)
485
+ arg = arg.first
474
486
  id = Integer(arg) rescue raise("'#{arg}' is not an integer")
475
487
  tag = "#{'%04d' % id}-"
476
488
  files = Find.find(@root).to_a
@@ -505,7 +517,8 @@ Remainder of post goes here.
505
517
 
506
518
  #-- FIXME affects linking, building, deployment...
507
519
 
508
- def edit_post(arg)
520
+ def cmd_edit_post(arg)
521
+ arg = arg.first
509
522
  id = Integer(arg) rescue raise("'#{arg}' is not an integer")
510
523
  tag = "#{'%04d' % id}-"
511
524
  files = Find.find(@root+"/src").to_a
@@ -527,7 +540,8 @@ Remainder of post goes here.
527
540
 
528
541
  ### list_posts
529
542
 
530
- def list_posts
543
+ def cmd_list_posts(arg)
544
+ raise "Glitch: Got an argument" if arg != []
531
545
  dir = @config.viewdir(@view)
532
546
  Dir.chdir(dir) do
533
547
  posts = Dir.entries(".").grep(/^0.*/)
@@ -546,7 +560,8 @@ Remainder of post goes here.
546
560
 
547
561
  ### list_drafts
548
562
 
549
- def list_drafts
563
+ def cmd_list_drafts(arg)
564
+ raise "Glitch: Got an argument" if arg != []
550
565
  dir = "#@root/src"
551
566
  Dir.chdir(dir) do
552
567
  posts = Dir.entries(".").grep(/^0.*.lt3/)
@@ -563,4 +578,39 @@ Remainder of post goes here.
563
578
  exit
564
579
  end
565
580
 
581
+ def cmd_INVALID(arg)
582
+ puts "\n Command '#{red(arg)}' not understood.\n "
583
+ end
584
+
585
+ def cmd_help(arg)
586
+ raise "Glitch: Got an argument" if arg != []
587
+ puts <<-EOS
588
+
589
+ Commands:
590
+
591
+ h, help This message
592
+ q, quit Exit the program
593
+
594
+ change view VIEW Change current view
595
+ cv VIEW Change current view
596
+ new view Create a new view
597
+ list views List all views available
598
+ lsv Same as: list views
599
+
600
+ p, post Create a new post
601
+ new post Same as post (create a post)
602
+ lsp, list posts List posts in current view
603
+ lsd, list drafts List all posts regardless of view
604
+
605
+ rm ID Remove a post
606
+ edit ID Edit a post
607
+
608
+ preview Look at current (local) view in browser
609
+ browse Look at current (deployed) view in browser
610
+ relink Regenerate index for all views
611
+ rebuild Regenerate all posts and relink
612
+ deploy Deploy (current view)
613
+ EOS
614
+ end
615
+
566
616
  end
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.43"
6
+ VERSION = "0.0.45"
7
7
 
8
8
  Path = File.expand_path(File.join(File.dirname(__FILE__)))
9
9
  DefaultData = Path + "/../data"
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.43
4
+ version: 0.0.45
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-07-31 00:00:00.000000000 Z
11
+ date: 2018-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: livetext
@@ -46,6 +46,7 @@ files:
46
46
  - data/views/_default/custom/blog_trailer.html
47
47
  - data/views/_default/custom/post_template.html
48
48
  - data/views/_default/last_deployed
49
+ - lib/blogcmds.rb
49
50
  - lib/repl.rb
50
51
  - lib/runeblog.rb
51
52
  - runeblog.gemspec