runeblog 0.0.14 → 0.0.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/bin/blog +95 -8
  3. data/data/VERSION +1 -1
  4. data/lib/runeblog.rb +25 -5
  5. metadata +2 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a8e69d2af4ba58065485485a894e2247a2b94480
4
- data.tar.gz: 0d125197fd42dc3183b023828908d3ff147d2170
3
+ metadata.gz: d8a23e918f61dd880293c774b4c2cf02f24e8e6d
4
+ data.tar.gz: 0ba2d8b67bc2417df7b11a5cf49bc3fe95cb89b5
5
5
  SHA512:
6
- metadata.gz: f0d85a3bc232cd3bb3944bd60650b63cd4a588f7956add29ed8f2bbd1741d40ef252242e0103e1a7b156efee4b39d72bbd17927424730e8b30ca3e1124181e4b
7
- data.tar.gz: d3ef5e6078ce545b6487219ee61b3ca56ffd1be7039e11b709ef9fe7060e740a7570124652ac4c6b30eb5e7c5d4a593e69e4f7953546ce2e30635bc07ac49c5b
6
+ metadata.gz: fbfc48c5affa14e9de261bc11e046bfc904e943fd99a83e0221470f3c194b9e0f74b93c4f5be227f127aed3e7b494cc06f68df9e3131617f52afdc7d239f22dd
7
+ data.tar.gz: 02ed71f16fe0f7a564a20d170e1c516033f17079550fbabf347ddb6e153524ee6a8f9c6cb048e03e1fa1db628465d326e7b51257d83204179d7a3110d4a2d206
data/bin/blog CHANGED
@@ -4,6 +4,8 @@ $: << "./lib"
4
4
 
5
5
  require 'runeblog'
6
6
 
7
+ trap("INT") { }
8
+
7
9
  def execute_command
8
10
  case @cmd
9
11
  when "h", "help"; help
@@ -24,6 +26,95 @@ def execute_command
24
26
  puts
25
27
  end
26
28
 
29
+ def check(boolean, msg)
30
+ abort msg unless boolean
31
+ end
32
+
33
+ def expected(nw = 1)
34
+ abort "Unexpected '#{@words[nw]}'" unless @words.size == nw
35
+ end
36
+
37
+ def need_arg(nw = 1)
38
+ abort "Unexpected '#{@words[nw+1]}'" if @words[nw+1]
39
+ abort "Need an arg here" unless @words[nw]
40
+ @words[nw]
41
+ end
42
+
43
+ # when "lsv", "list views"; list_views
44
+ # when "list posts", "lsp"; list_posts
45
+ # when "new view"; new_view(@arg)
46
+ # when "new post"; new_post # same as above
47
+ # when "change view"; change_view(@arg)
48
+ # when "import post"; import(@arg)
49
+
50
+ def parse_cmd
51
+ @cmd = gets.chomp
52
+ @arg = ""
53
+ @words = @cmd.split
54
+ case @words.first
55
+ when "h", "help"
56
+ @meth = :help
57
+ expected(1)
58
+ when "q", "quit"
59
+ @meth = :quit
60
+ expected(1)
61
+ when "p", "post"
62
+ @meth = :new_post
63
+ expected(1)
64
+ when "lsv"
65
+ @meth = :list_views
66
+ expected(1)
67
+ when "lsp"
68
+ @meth = :list_posts
69
+ expected(1)
70
+ when "relink"
71
+ @meth = :relink
72
+ expected(1)
73
+ when "rebuild"
74
+ @meth = :rebuild
75
+ expected(1)
76
+ when "version"
77
+ @meth = :version
78
+ expected(1)
79
+ when "cv"
80
+ @meth = :change_view
81
+ @arg = need_arg(1)
82
+ when "list"
83
+ case @words[1]
84
+ when "views"
85
+ @meth = :list_views
86
+ expected(2)
87
+ when "posts"
88
+ @meth = :list_posts
89
+ expected(2)
90
+ else
91
+ raise "Unknown #{@words[1]}"
92
+ end
93
+ when "new"
94
+ case @words[1]
95
+ when "view"
96
+ @meth = :new_view
97
+ expected(2)
98
+ @arg = need_arg(2)
99
+ when "post"
100
+ @meth = :new_post
101
+ expected(2)
102
+ else
103
+ raise "Unknown '#{@words[1]}'"
104
+ end
105
+ else
106
+ raise "Unknown '#{@words[0]}'"
107
+ end
108
+ @cmd
109
+ end
110
+
111
+ def get_argv
112
+ return nil if ARGV.size == 0
113
+ @cmd = ARGV[0..1].join(" ")
114
+ @arg = ARGV[2]
115
+ @cmd
116
+ end
117
+
27
118
  def help
28
119
  puts <<-EOS
29
120
  Commands:
@@ -49,17 +140,13 @@ end
49
140
 
50
141
  STDOUT.sync = true
51
142
 
52
- @cmd = ARGV[0..1].join(" ")
53
- @arg = ARGV[2]
143
+ @cmd = get_argv
54
144
 
55
- if @cmd.empty? # REPL
145
+ if @cmd.nil? # REPL
56
146
  read_config
57
147
  loop do
58
- print "blog> "
59
- @cmd = gets.chomp.gsub(/ +/, " ") rescue abort("\n")
60
- words = @cmd.split
61
- @cmd = words[0..1].join(" ")
62
- @arg = words[2]
148
+ print red("blog> ")
149
+ @cmd = parse_cmd
63
150
  execute_command
64
151
  end
65
152
  else # one command
data/data/VERSION CHANGED
@@ -1 +1 @@
1
- RuneBlog v 0.0.14 2017-05-05 00:00:00 UTC
1
+ RuneBlog v 0.0.15 2017-05-05 00:00:00 UTC
data/lib/runeblog.rb CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  class RuneBlog
3
- VERSION = "0.0.14"
3
+ VERSION = "0.0.15"
4
4
 
5
5
  Path = File.expand_path(File.join(File.dirname(__FILE__)))
6
6
  DefaultData = Path + "/../data"
@@ -11,6 +11,23 @@ class RuneBlog
11
11
  PostTrailer = File.read(DefaultData + "/post_trailer.html") rescue "not found"
12
12
  end
13
13
 
14
+ def clear
15
+ puts "\e[H\e[2J" # clear screen
16
+ end
17
+
18
+ def red(text)
19
+ "\e[31m#{text}\e[0m"
20
+ end
21
+
22
+ def blue(text)
23
+ "\e[34m#{text}\e[0m"
24
+ end
25
+
26
+ def bold(str)
27
+ "\e[1m#{str}\e[22m"
28
+ end
29
+
30
+
14
31
  # FIXME lots of structure changes
15
32
 
16
33
  require 'yaml'
@@ -255,14 +272,18 @@ end
255
272
 
256
273
  def list_views
257
274
  read_config unless @config
258
- puts @config.views
275
+ puts
276
+ @config.views.each {|v| puts " #{v}" }
259
277
  end
260
278
 
261
279
  ### change_view
262
280
 
263
281
  def change_view(arg = nil)
264
- raise "view #{arg} does not exist" unless @config.views.include?(arg)
265
- @view = arg
282
+ if @config.views.include?(arg)
283
+ @view = arg
284
+ else
285
+ puts "view #{arg.inspect} does not exist"
286
+ end
266
287
  end
267
288
 
268
289
  ### new_view
@@ -331,7 +352,6 @@ def list_posts
331
352
  else
332
353
  posts.each {|post| puts " #{post}" }
333
354
  end
334
- puts
335
355
  end
336
356
  rescue
337
357
  puts "Oops? cwd = #{Dir.pwd} dir = #{dir}"
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.14
4
+ version: 0.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hal Fulton
@@ -48,9 +48,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
48
48
  version: '0'
49
49
  requirements: []
50
50
  rubyforge_project:
51
- rubygems_version: 2.4.2
51
+ rubygems_version: 2.2.2
52
52
  signing_key:
53
53
  specification_version: 4
54
54
  summary: A command-line blogging system
55
55
  test_files: []
56
- has_rdoc: