runeblog 0.0.48 → 0.0.50

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: acf9dddd4d4831cf3be7477a5dfa9835cf9bc02f
4
- data.tar.gz: 4a55905bf1eaf9b00b3aa0cdcf17d352c99a3108
3
+ metadata.gz: c3b39c7785709eb2bf8872755d2e4a78a243778e
4
+ data.tar.gz: e1487a5a7159e43fae8259f2fd445095fa214d3a
5
5
  SHA512:
6
- metadata.gz: e5a6c7faf63b9e3564df736b747637d7f0d2256cf8f1f59a660fb268151151b7dfd26161e159b5bb89dcd5b2d2768a3e0ff64ccd2efce2b8ceeb7ec22ba3302e
7
- data.tar.gz: 2ac106c905e58b85948a2adb85b636a0bb9e1ca72bee6d2bf192b83a214508cb34a680211aaf2ae1b5d28227edcb93c8c9223948ad5771ede2ef979ad064c945
6
+ metadata.gz: 603def138fc3cb6b3257f35d8d24542bb4cc7b857667208d9268a4d328385448030aa4344f8867058f723fca93581d3ed33aca44a9f4208429e673828db2f49f
7
+ data.tar.gz: 7ab37aaf0445c51cfc7fcefd0228b5ca9c55c355bd5c1b681fad39019952585c082eb05b181d68ea60d76d8f41407489d14564acf60ec703e905719886cff586
data/data/VERSION CHANGED
@@ -1 +1 @@
1
- RuneBlog v 0.0.48 2018-08-30
1
+ RuneBlog v 0.0.50 2018-09-01
data/lib/prettiness.rb ADDED
@@ -0,0 +1,29 @@
1
+
2
+ # Reopening...
3
+
4
+ module RuneBlog::REPL
5
+ def clear
6
+ puts "\e[H\e[2J" # clear screen
7
+ end
8
+
9
+ def red(text)
10
+ "\e[31m#{text}\e[0m"
11
+ end
12
+
13
+ def blue(text)
14
+ "\e[34m#{text}\e[0m"
15
+ end
16
+
17
+ def bold(str)
18
+ "\e[1m#{str}\e[22m"
19
+ end
20
+
21
+ def interpolate(str)
22
+ wrap = "<<-EOS\n#{str}\nEOS"
23
+ eval wrap
24
+ end
25
+
26
+ def colored_slug(slug)
27
+ red(slug[0..3])+blue(slug[4..-1])
28
+ end
29
+ end
data/lib/repl.rb CHANGED
@@ -21,12 +21,15 @@ require 'ostruct'
21
21
  @view
22
22
  =end
23
23
 
24
+ require 'prettiness' # FIXME structure
25
+
24
26
  module RuneBlog::REPL
25
27
 
26
28
  ### error
27
29
 
28
30
  def error(err)
29
31
  str = "\n Error: #{red(err)}"
32
+ puts str
30
33
  puts err.backtrace
31
34
  end
32
35
 
@@ -70,16 +73,6 @@ module RuneBlog::REPL
70
73
  error(err)
71
74
  end
72
75
 
73
- ### make_slug
74
-
75
- # What to do with this?
76
-
77
- def make_slug(title, seq=nil)
78
- num = '%04d' % (seq || @blog.next_sequence) # FIXME can do better
79
- slug = title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
80
- "#{num}-#{slug}"
81
- end
82
-
83
76
  ### open_blog
84
77
 
85
78
  def open_blog # Crude - FIXME later
@@ -93,37 +86,13 @@ module RuneBlog::REPL
93
86
  error(err)
94
87
  end
95
88
 
96
- ### create_empty_post
97
-
98
- def create_empty_post
99
- @template = <<-EOS
100
- .mixin liveblog
101
-
102
- .title #@title
103
- .pubdate #@date
104
- .views #@view
105
-
106
- .teaser
107
- Teaser goes here.
108
- .end
109
- Remainder of post goes here.
110
- EOS
111
-
112
- @slug = make_slug(@title)
113
- @fname = @slug + ".lt3"
114
- File.open("#@root/src/#@fname", "w") {|f| f.puts @template }
115
- @fname
116
- rescue => err
117
- error(err)
118
- end
119
-
120
89
  ### edit_initial_post
121
90
 
122
91
  def edit_initial_post(file)
123
92
  result = system("vi #@root/src/#{file} +8 ")
124
93
  raise "Problem editing #@root/src/#{file}" unless result
125
94
  rescue => err
126
- error(err, __LINE__, __FILE__)
95
+ error(err)
127
96
  end
128
97
 
129
98
  ### browse
@@ -193,8 +162,9 @@ Remainder of post goes here.
193
162
  @meta = @main.process_file(path, binding)
194
163
  raise "process_file returned nil" if @meta.nil?
195
164
 
196
- @meta.slug = make_slug(@meta.title, @blog.sequence)
197
- @meta.slug = file.sub(/.lt3$/, "")
165
+ slug = @blog.make_slug(@meta.title, @blog.sequence)
166
+ slug = file.sub(/.lt3$/, "")
167
+ @meta.slug = slug
198
168
  @meta
199
169
  rescue => err
200
170
  error(err)
@@ -204,7 +174,7 @@ Remainder of post goes here.
204
174
 
205
175
  def reload_post(file)
206
176
  @main ||= Livetext.new
207
- @main.main.output = File.new("/tmp/WHOA","w")
177
+ @main.main.output = File.new("/tmp/WHOA","w") # FIXME srsly?
208
178
  @meta = process_post(file)
209
179
  @meta.slug = file.sub(/.lt3$/, "")
210
180
  @meta
@@ -215,6 +185,7 @@ Remainder of post goes here.
215
185
  ### posting
216
186
 
217
187
  def posting(view, meta)
188
+ # FIXME clean up and generalize
218
189
  ref = "#{view}/#{meta.slug}/index.html"
219
190
  <<-HTML
220
191
  <br>
@@ -427,7 +398,7 @@ Remainder of post goes here.
427
398
  name = arg
428
399
  grep = `grep ^.title #{name}`
429
400
  @title = grep.sub(/^.title /, "")
430
- @slug = make_slug(@title)
401
+ @slug = @blog.make_slug(@title)
431
402
  @fname = @slug + ".lt3"
432
403
  result = system("cp #{name} #@root/src/#@fname")
433
404
  raise "Could not copy #{name} to #@root/src/#@fname" unless result
@@ -448,9 +419,8 @@ Remainder of post goes here.
448
419
  @today = Time.now.strftime("%Y%m%d")
449
420
  @date = Time.now.strftime("%Y-%m-%d")
450
421
 
451
- file = create_empty_post
422
+ file = @blog.create_new_post(@title, @date, @view)
452
423
  edit_initial_post(file)
453
- # file = @root + "/src/" + file
454
424
  process_post(file) #- FIXME handle each view
455
425
  publish_post(@meta) # if publish?
456
426
  rescue => err
@@ -601,29 +571,4 @@ Remainder of post goes here.
601
571
  EOS
602
572
  end
603
573
 
604
- def clear
605
- puts "\e[H\e[2J" # clear screen
606
- end
607
-
608
- def red(text)
609
- "\e[31m#{text}\e[0m"
610
- end
611
-
612
- def blue(text)
613
- "\e[34m#{text}\e[0m"
614
- end
615
-
616
- def bold(str)
617
- "\e[1m#{str}\e[22m"
618
- end
619
-
620
- def interpolate(str)
621
- wrap = "<<-EOS\n#{str}\nEOS"
622
- eval wrap
623
- end
624
-
625
- def colored_slug(slug)
626
- red(slug[0..3])+blue(slug[4..-1])
627
- end
628
-
629
574
  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.48"
6
+ VERSION = "0.0.50"
7
7
 
8
8
  Path = File.expand_path(File.join(File.dirname(__FILE__)))
9
9
  DefaultData = Path + "/../data"
@@ -57,26 +57,32 @@ class RuneBlog
57
57
  File.exist?(".blog")
58
58
  end
59
59
 
60
- # def self.create_new_post(title, date, view)
61
- # @template = <<-EOS
62
- # .mixin liveblog
63
- #
64
- # .title #{title}
65
- # .pubdate #{date}
66
- # .views #{view}
67
- #
68
- # .teaser
69
- # Teaser goes here.
70
- # .end
71
- # Remainder of post goes here.
72
- # EOS
73
- #
74
- # @slug = make_slug(title)
75
- # @fname = @slug + ".lt3"
76
- # File.open("#@root/src/#@fname", "w") {|f| f.puts @template }
77
- # @fname
78
- # rescue => err
79
- # error(err, __LINE__, __FILE__)
80
- # end
60
+ def create_new_post(title, date, view)
61
+ @template = <<-EOS
62
+ .mixin liveblog
63
+
64
+ .title #{title}
65
+ .pubdate #{date}
66
+ .views #{view}
67
+
68
+ .teaser
69
+ Teaser goes here.
70
+ .end
71
+ Remainder of post goes here.
72
+ EOS
73
+
74
+ @slug = make_slug(title)
75
+ @fname = @slug + ".lt3"
76
+ File.open("#@root/src/#@fname", "w") {|f| f.puts @template }
77
+ @fname
78
+ rescue => err
79
+ error(err)
80
+ end
81
+
82
+ def make_slug(title, seq=nil)
83
+ num = '%04d' % (seq || self.next_sequence) # FIXME can do better
84
+ slug = title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
85
+ "#{num}-#{slug}"
86
+ end
81
87
 
82
88
  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.48
4
+ version: 0.0.50
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-08-30 00:00:00.000000000 Z
11
+ date: 2018-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: livetext
@@ -48,9 +48,7 @@ files:
48
48
  - data/views/_default/deploy
49
49
  - data/views/_default/last_deployed
50
50
  - lib/blogcmds.rb
51
- - lib/newruneblog.rb
52
- - lib/oldrepl.rb
53
- - lib/oldruneblog.rb
51
+ - lib/prettiness.rb
54
52
  - lib/repl.rb
55
53
  - lib/runeblog.rb
56
54
  - runeblog.gemspec
data/lib/newruneblog.rb DELETED
@@ -1,106 +0,0 @@
1
- require 'find'
2
- require 'yaml'
3
- require 'livetext'
4
-
5
- class RuneBlog
6
- VERSION = "0.0.45"
7
-
8
- Path = File.expand_path(File.join(File.dirname(__FILE__)))
9
- DefaultData = Path + "/../data"
10
-
11
- BlogHeaderPath = DefaultData + "/custom/blog_header.html"
12
- BlogTrailerPath = DefaultData + "/custom/blog_trailer.html"
13
-
14
- BlogHeader = File.read(BlogHeaderPath) rescue "not found"
15
- BlogTrailer = File.read(BlogTrailerPath) rescue "not found"
16
- end
17
-
18
- # Continued below...
19
-
20
- class RuneBlog::Config
21
- attr_reader :root, :views, :view, :sequence
22
- attr_writer :view # FIXME
23
-
24
- def self.create(cfg_file = ".blog")
25
- RuneBlog.create_new_blog
26
- end
27
-
28
- def initialize(cfg_file = ".blog")
29
- # What views are there? Deployment, etc.
30
- # Crude - FIXME later
31
-
32
- lines = File.readlines(cfg_file).map {|x| x.chomp }
33
- @root = lines[0]
34
- @view = lines[1]
35
- dirs = Dir.entries("#@root/views/") - %w[. ..]
36
- dirs.reject! {|x| ! File.directory?("#@root/views/#{x}") }
37
- @root = root
38
- @views = dirs
39
- @sequence = File.read(root + "/sequence").to_i
40
- end
41
-
42
- def next_sequence
43
- @sequence += 1
44
- File.open("#@root/sequence", "w") {|f| f.puts @sequence }
45
- @sequence
46
- end
47
-
48
- def viewdir(v)
49
- @root + "/views/#{v}/"
50
- end
51
-
52
- end
53
-
54
- # Reopening...
55
-
56
- class RuneBlog
57
-
58
- def self.exist?
59
- File.exist?(".blog")
60
- end
61
-
62
- def get_config
63
- end
64
-
65
- # def initialize
66
- # # ?
67
- # end
68
-
69
- def self.create_new_blog
70
- #-- what if data already exists?
71
- result = system("cp -r #{RuneBlog::DefaultData} .")
72
- raise "Error copying default data" unless result
73
-
74
- File.open(".blog", "w") do |f|
75
- f.puts "data"
76
- f.puts "no_default"
77
- end
78
- File.open("data/VERSION", "a") {|f| f.puts "\nBlog created: " + Time.now.to_s }
79
- end
80
-
81
- # def self.open_blog
82
- # end
83
-
84
- # def self.create_new_post(title, date, view)
85
- # @template = <<-EOS
86
- # .mixin liveblog
87
- #
88
- # .title #{title}
89
- # .pubdate #{date}
90
- # .views #{view}
91
- #
92
- # .teaser
93
- # Teaser goes here.
94
- # .end
95
- # Remainder of post goes here.
96
- # EOS
97
- #
98
- # @slug = make_slug(title)
99
- # @fname = @slug + ".lt3"
100
- # File.open("#@root/src/#@fname", "w") {|f| f.puts @template }
101
- # @fname
102
- # rescue => err
103
- # error(err, __LINE__, __FILE__)
104
- # end
105
-
106
- end
data/lib/oldrepl.rb DELETED
@@ -1,628 +0,0 @@
1
- require 'runeblog'
2
-
3
- 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
- module RuneBlog::REPL
25
-
26
- ### error
27
-
28
- def error(err, line, file)
29
- str = "\n Error: #{red(err)}"
30
- puts err.backtrace
31
- end
32
-
33
- ### ask
34
-
35
- def ask(prompt, meth = :to_s)
36
- print prompt
37
- STDOUT.flush
38
- STDIN.gets.chomp.send(meth)
39
- end
40
-
41
- def yesno(prompt, meth = :to_s)
42
- print prompt
43
- STDOUT.flush
44
- STDIN.gets.chomp.upcase[0] == "Y"
45
- end
46
-
47
- ### quit
48
-
49
- def cmd_quit(arg)
50
- raise "Glitch: Got an argument" if arg != []
51
- puts "\n "
52
- exit
53
- end
54
-
55
- ### version
56
-
57
- def cmd_version(arg)
58
- raise "Glitch: Got an argument" if arg != []
59
- puts "\n " + RuneBlog::VERSION
60
- end
61
-
62
- ### new_blog!
63
-
64
- def cmd_new_blog!(arg)
65
- raise "Glitch: Got an argument" if arg != []
66
- return if RuneBlog.exist?
67
- yn = yesno(red(" No .blog found. Create new blog? "))
68
- RuneBlog.create_new_blog if yn
69
- rescue => err
70
- error(err)
71
- end
72
-
73
- ### make_slug
74
-
75
- # What to do with this?
76
-
77
- def make_slug(title, seq=nil)
78
- num = '%04d' % (seq || @config.next_sequence) # FIXME can do better
79
- slug = title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
80
- "#{num}-#{slug}"
81
- end
82
-
83
- ### read_config
84
-
85
- def read_config # Crude - FIXME later
86
- cmd_new_blog!([]) unless RuneBlog.exist?
87
- @config = RuneBlog::Config.new
88
- @view = @config.view # current view
89
- @sequence = @config.sequence
90
- @root = @config.root
91
- @config
92
- rescue => err
93
- error(err)
94
- end
95
-
96
- ### create_empty_post
97
-
98
- def create_empty_post
99
- @template = <<-EOS
100
- .mixin liveblog
101
-
102
- .title #@title
103
- .pubdate #@date
104
- .views #@view
105
-
106
- .teaser
107
- Teaser goes here.
108
- .end
109
- Remainder of post goes here.
110
- EOS
111
-
112
- @slug = make_slug(@title)
113
- @fname = @slug + ".lt3"
114
- File.open("#@root/src/#@fname", "w") {|f| f.puts @template }
115
- @fname
116
- rescue => err
117
- error(err)
118
- end
119
-
120
- ### edit_initial_post
121
-
122
- def edit_initial_post(file)
123
- result = system("vi #@root/src/#{file} +8 ")
124
- raise "Problem editing #@root/src/#{file}" unless result
125
- rescue => err
126
- error(err, __LINE__, __FILE__)
127
- end
128
-
129
- ### browse
130
-
131
- def cmd_browse
132
- raise "Glitch: Got an argument" if arg != []
133
- @deploy ||= {}
134
- return puts red("\n Deploy first.") unless @deploy[@view]
135
-
136
- lines = @deploy[@view]
137
- user, server, sroot, spath = *lines
138
- result = system("open 'http://#{server}/#{spath}'")
139
- raise "Problem opening http://#{server}/#{spath}" unless result
140
- rescue => err
141
- error(err)
142
- end
143
-
144
- ### open_local
145
-
146
- def open_local
147
- result = system("open #{@config.viewdir(@view)}/index.html")
148
- raise "Problem opening #{@config.viewdir(@view)}/index.html" unless result
149
- rescue => err
150
- error(err)
151
- end
152
-
153
- def cmd_deploy(arg)
154
- # TBD clunky FIXME
155
- raise "Glitch: Got an argument" if arg != []
156
- @deploy ||= {}
157
- deployment = @config.viewdir(@view) + "deploy"
158
- raise "File '#{deployment}' not found" unless File.exist?(deployment)
159
-
160
- lines = File.readlines(deployment).map {|x| x.chomp }
161
- @deploy[@view] = lines
162
- user, server, sroot, spath = *lines
163
- vdir = @config.viewdir(@view)
164
- files = ["#{vdir}/index.html"]
165
- files += Dir.entries(vdir).grep(/^\d\d\d\d/).map {|x| "#{vdir}/#{x}" }
166
- files.reject! {|f| File.mtime(f) < File.mtime("#{vdir}/last_deployed") }
167
- return puts red("\n No files to deploy") if files.empty?
168
-
169
- puts "\n Files:"
170
- files.each {|f| puts " " + f }
171
- puts
172
- dir = "#{sroot}/#{spath}"
173
- # FIXME - may or may not already exist
174
- result = system("ssh root@#{server} mkdir #{dir}")
175
-
176
- cmd = "scp -r #{files.join(' ')} root@#{server}:#{dir} >/dev/null 2>&1"
177
- print red("\n Deploying #{files.size} files... ")
178
- result = system(cmd)
179
- raise "Problem occurred in deployment" unless result
180
-
181
- File.write("#{vdir}/last_deployed", files)
182
- puts red("finished.")
183
- rescue => err
184
- error(err)
185
- end
186
-
187
- ### process_post
188
-
189
- def process_post(file)
190
- @main ||= Livetext.new
191
- @main.main.output = File.new("/tmp/WHOA","w")
192
- path = @root + "/src/#{file}"
193
- @meta = @main.process_file(path, binding)
194
- raise "process_file returned nil" if @meta.nil?
195
-
196
- @meta.slug = make_slug(@meta.title, @config.sequence)
197
- @meta.slug = file.sub(/.lt3$/, "")
198
- @meta
199
- rescue => err
200
- error(err)
201
- end
202
-
203
- ### reload_post
204
-
205
- def reload_post(file)
206
- @main ||= Livetext.new
207
- @main.main.output = File.new("/tmp/WHOA","w")
208
- @meta = process_post(file)
209
- @meta.slug = file.sub(/.lt3$/, "")
210
- @meta
211
- rescue => err
212
- error(err)
213
- end
214
-
215
- ### posting
216
-
217
- def posting(view, meta)
218
- ref = "#{view}/#{meta.slug}/index.html"
219
- <<-HTML
220
- <br>
221
- <font size=+1>#{meta.pubdate}&nbsp;&nbsp;</font>
222
- <font size=+2 color=blue><a href=../#{ref} style="text-decoration: none">#{meta.title}</font></a>
223
- <br>
224
- #{meta.teaser}
225
- <a href=../#{ref} style="text-decoration: none">Read more...</a>
226
- <br><br>
227
- <hr>
228
- HTML
229
- end
230
-
231
- ### generate_index
232
-
233
- def generate_index(view)
234
- # Gather all posts, create list
235
- vdir = "#@root/views/#{view}"
236
- posts = Dir.entries(vdir).grep /^\d\d\d\d/
237
- posts = posts.sort.reverse
238
-
239
- # Add view header/trailer
240
- head = File.read("#{vdir}/custom/blog_header.html") rescue RuneBlog::BlogHeader
241
- tail = File.read("#{vdir}/custom/blog_trailer.html") rescue RuneBlog::BlogTrailer
242
- @bloghead = interpolate(head)
243
- @blogtail = interpolate(tail)
244
-
245
- # Output view
246
- posts.map! {|post| YAML.load(File.read("#{vdir}/#{post}/metadata.yaml")) }
247
- File.open("#{vdir}/index.html", "w") do |f|
248
- f.puts @bloghead
249
- posts.each {|post| f.puts posting(view, post) }
250
- f.puts @blogtail
251
- end
252
- rescue => err
253
- error(err)
254
- end
255
-
256
- ### create_dir
257
-
258
- def create_dir(dir)
259
- cmd = "mkdir -p #{dir} >/dev/null 2>&1"
260
- result = system(cmd)
261
- raise "Can't create #{dir}" unless result
262
- end
263
-
264
- ### link_post_view
265
-
266
- def link_post_view(view)
267
- # Create dir using slug (index.html, metadata?)
268
- vdir = @config.viewdir(view)
269
- dir = vdir + @meta.slug + "/"
270
- create_dir(dir + "assets")
271
- File.write("#{dir}/metadata.yaml", @meta.to_yaml)
272
- template = File.read(vdir + "custom/post_template.html")
273
- post = interpolate(template)
274
- File.write(dir + "index.html", post)
275
- generate_index(view)
276
- rescue => err
277
- error(err)
278
- end
279
-
280
- ### find_asset
281
-
282
- # def find_asset(asset) # , views)
283
- # # STDERR.puts "repl find_asset: @meta = #{@meta.inspect}"
284
- # views = @meta.views
285
- # views.each do |view|
286
- # vdir = @config.viewdir(view)
287
- # post_dir = "#{vdir}#{@meta.slug}/assets/"
288
- # path = post_dir + asset
289
- # STDERR.puts " Seeking #{path}"
290
- # return path if File.exist?(path)
291
- # end
292
- # views.each do |view|
293
- # dir = @config.viewdir(view) + "/assets/"
294
- # path = dir + asset
295
- # STDERR.puts " Seeking #{path}"
296
- # return path if File.exist?(path)
297
- # end
298
- # top = @root + "/assets/"
299
- # path = top + asset
300
- # STDERR.puts " Seeking #{path}"
301
- # return path if File.exist?(path)
302
- #
303
- # return nil
304
- # end
305
- #
306
- # ### find_all_assets
307
- #
308
- # def find_all_assets(list, views)
309
- # # STDERR.puts "\n Called find_all_assets with #{list.inspect}"
310
- # list ||= []
311
- # list.each {|asset| puts "#{asset} => #{find_asset(asset, views)}" }
312
- # end
313
-
314
- ### publish_post
315
-
316
- def publish_post(meta)
317
- puts " #{colored_slug(meta.slug)}"
318
- # First gather the views
319
- views = meta.views
320
- print " Views: "
321
- views.each do |view|
322
- print "#{view} "
323
- link_post_view(view)
324
- end
325
- # assets = find_all_assets(@meta.assets, views)
326
- puts
327
- rescue => err
328
- error(err)
329
- end
330
-
331
- ### rebuild_post
332
-
333
- def rebuild_post(file)
334
- reload_post(file)
335
- publish_post(@meta) # FIXME ??
336
- rescue => err
337
- error(err)
338
- end
339
-
340
- ### rebuild
341
-
342
- def cmd_rebuild(arg)
343
- raise "Glitch: Got an argument" if arg != []
344
- puts
345
- files = Dir.entries("#@root/src/").grep /\d\d\d\d.*.lt3$/
346
- files.map! {|f| File.basename(f) }
347
- files = files.sort.reverse
348
- files.each {|file| rebuild_post(file) }
349
- rescue => err
350
- error(err)
351
- end
352
-
353
- ### relink
354
-
355
- def cmd_relink(arg)
356
- raise "Glitch: Got an argument" if arg != []
357
- @config.views.each {|view| generate_index(view) }
358
- rescue => err
359
- error(err)
360
- end
361
-
362
- # ### publish?
363
- #
364
- # def publish?
365
- # yn = ask(red(" Publish? y/n "))
366
- # yn.upcase == "Y"
367
- # end
368
-
369
- ### list_views
370
-
371
- def cmd_list_views(arg)
372
- abort "Config file not read" unless @config
373
- raise "Glitch: Got an argument" if arg != []
374
- puts
375
- @config.views.each {|v| puts " #{v}" }
376
- rescue => err
377
- error(err)
378
- end
379
-
380
- ### change_view
381
-
382
- def cmd_change_view(arg)
383
- if arg.empty?
384
- puts "\n #@view"
385
- else
386
- arg = arg.first
387
- list = @config.views.grep /^#{arg}/
388
- if list.size == 1
389
- @view = @config.view = list.first
390
- puts red("\n View: #{@view}") if arg != @view
391
- else
392
- puts "view #{arg.inspect} does not exist"
393
- end
394
- end
395
- rescue => err
396
- error(err)
397
- end
398
-
399
- ### new_view
400
-
401
- def cmd_new_view(arg)
402
- arg = arg.first
403
- read_config unless @config
404
- arg ||= ask("New view: ") # check validity later
405
- raise "view #{arg} already exists" if @config.views.include?(arg)
406
-
407
- dir = @root + "/views/" + arg + "/"
408
- create_dir(dir + 'custom')
409
- create_dir(dir + 'assets')
410
-
411
- # Something more like this? RuneBlog.new_view(arg)
412
- File.write(dir + "custom/blog_header.html", RuneBlog::BlogHeader)
413
- File.write(dir + "custom/blog_trailer.html", RuneBlog::BlogTrailer)
414
- File.write(dir + "last_deployed", "Initial creation")
415
- @config.views << arg
416
- rescue => err
417
- error(err)
418
- end
419
-
420
- ### import
421
-
422
- def import(arg = nil)
423
- read_config unless @config
424
- arg = nil if arg == ""
425
- arg ||= ask("Filename: ") # check validity later
426
- name = arg
427
- grep = `grep ^.title #{name}`
428
- @title = grep.sub(/^.title /, "")
429
- @slug = make_slug(@title)
430
- @fname = @slug + ".lt3"
431
- result = system("cp #{name} #@root/src/#@fname")
432
- raise "Could not copy #{name} to #@root/src/#@fname" unless result
433
-
434
- edit_initial_post(@fname)
435
- process_post(@fname)
436
- publish_post(@meta) # if publish?
437
- rescue => err
438
- error(err)
439
- end
440
-
441
- ### new_post
442
-
443
- def cmd_new_post(arg)
444
- raise "Glitch: Got an argument" if arg != []
445
- read_config unless @config
446
- @title = ask("Title: ")
447
- @today = Time.now.strftime("%Y%m%d")
448
- @date = Time.now.strftime("%Y-%m-%d")
449
-
450
- file = create_empty_post
451
- edit_initial_post(file)
452
- # file = @root + "/src/" + file
453
- process_post(file) #- FIXME handle each view
454
- publish_post(@meta) # if publish?
455
- rescue => err
456
- error(err)
457
- end
458
-
459
- ### remove_multiple_posts
460
-
461
- def remove_multiple_posts(str)
462
- args = str.split
463
- args.each {|arg| remove_post(arg, false) }
464
- end
465
-
466
- ### remove_post
467
-
468
- #-- FIXME affects linking, building, deployment...
469
-
470
- def cmd_remove_post(arg, safe=true)
471
- arg = arg.first
472
- id = Integer(arg) rescue raise("'#{arg}' is not an integer")
473
- tag = "#{'%04d' % id}"
474
- files = Find.find(@root).to_a
475
- files = files.grep(/#{tag}-/)
476
- return puts red("\n No such post found (#{id})") if files.empty?
477
-
478
- if safe
479
- puts
480
- files.each {|f| puts " #{f}" }
481
- ques = files.size > 1 ? "\n Delete all these? " : "\n Delete? "
482
- yn = ask red(ques)
483
- if yn.downcase == "y"
484
- result = system("rm -rf #{files.join(' ')}")
485
- raise "Problem deleting file(s)" unless result
486
- puts red("\n Deleted")
487
- else
488
- puts red("\n No action taken")
489
- end
490
- else
491
- result = system("rm -rf #{files.join(' ')}")
492
- puts red("\n Deleted:")
493
- files.each {|f| puts " #{f}" }
494
- raise "Problem mass-deleting file(s)" unless result
495
- end
496
- rescue => err
497
- puts err
498
- puts err.backtrace
499
- puts
500
- end
501
-
502
- ### edit_post
503
-
504
- #-- FIXME affects linking, building, deployment...
505
-
506
- def cmd_edit_post(arg)
507
- arg = arg.first
508
- id = Integer(arg) rescue raise("'#{arg}' is not an integer")
509
- tag = "#{'%04d' % id}"
510
- files = Find.find(@root+"/src").to_a
511
- files = files.grep(/#{tag}-/)
512
- files = files.map {|f| File.basename(f) }
513
- return puts red("Multiple files: #{files}") if files.size > 1
514
- return puts red("\n No such post found (#{id})") if files.empty?
515
-
516
- file = files.first
517
- result = system("vi #@root/src/#{file}")
518
- raise "Problem editing #{file}" unless result
519
-
520
- rebuild_post(file)
521
- rescue => err
522
- puts err
523
- puts err.backtrace
524
- puts
525
- end
526
-
527
- ### list_posts
528
-
529
- def cmd_list_posts(arg)
530
- raise "Glitch: Got an argument" if arg != []
531
- dir = @config.viewdir(@view)
532
- Dir.chdir(dir) do
533
- posts = Dir.entries(".").grep(/^0.*/)
534
- if posts.empty?
535
- puts "\n " + @view + ":" + red(" No posts")
536
- else
537
- puts "\n " + @view + ":\n "
538
- posts.each {|post| puts " #{colored_slug(post)}" }
539
- end
540
- end
541
- rescue
542
- puts "Oops? cwd = #{Dir.pwd} dir = #{dir}"
543
- puts err.backtrace
544
- exit
545
- end
546
-
547
- ### list_drafts
548
-
549
- def cmd_list_drafts(arg)
550
- raise "Glitch: Got an argument" if arg != []
551
- dir = "#@root/src"
552
- Dir.chdir(dir) do
553
- posts = Dir.entries(".").grep(/^0.*.lt3/)
554
- puts
555
- if posts.empty?
556
- puts red(" No posts")
557
- else
558
- posts.each {|post| puts " #{colored_slug(post.sub(/.lt3$/, ""))}" }
559
- end
560
- end
561
- rescue
562
- puts "Oops? cwd = #{Dir.pwd} dir = #{dir}"
563
- puts err.backtrace
564
- exit
565
- end
566
-
567
- def cmd_INVALID(arg)
568
- puts "\n Command '#{red(arg)}' was not understood."
569
- end
570
-
571
- def cmd_help(arg)
572
- raise "Glitch: Got an argument" if arg != []
573
- puts <<-EOS
574
-
575
- Commands:
576
-
577
- #{red('h, help ')} This message
578
- #{red('q, quit ')} Exit the program
579
- #{red('v, version ')} Print version information
580
-
581
- #{red('change view VIEW ')} Change current view
582
- #{red('cv VIEW ')} Change current view
583
- #{red('new view ')} Create a new view
584
- #{red('list views ')} List all views available
585
- #{red('lsv ')} Same as: list views
586
-
587
- #{red('p, post ')} Create a new post
588
- #{red('new post ')} Same as post (create a post)
589
- #{red('lsp, list posts ')} List posts in current view
590
- #{red('lsd, list drafts ')} List all posts regardless of view
591
-
592
- #{red('rm ID ')} Remove a post
593
- #{red('edit ID ')} Edit a post
594
-
595
- #{red('preview ')} Look at current (local) view in browser
596
- #{red('browse ')} Look at current (deployed) view in browser
597
- #{red('relink ')} Regenerate index for all views
598
- #{red('rebuild ')} Regenerate all posts and relink
599
- #{red('deploy ')} Deploy (current view)
600
- EOS
601
- end
602
-
603
- def clear
604
- puts "\e[H\e[2J" # clear screen
605
- end
606
-
607
- def red(text)
608
- "\e[31m#{text}\e[0m"
609
- end
610
-
611
- def blue(text)
612
- "\e[34m#{text}\e[0m"
613
- end
614
-
615
- def bold(str)
616
- "\e[1m#{str}\e[22m"
617
- end
618
-
619
- def interpolate(str)
620
- wrap = "<<-EOS\n#{str}\nEOS"
621
- eval wrap
622
- end
623
-
624
- def colored_slug(slug)
625
- red(slug[0..3])+blue(slug[4..-1])
626
- end
627
-
628
- end
data/lib/oldruneblog.rb DELETED
@@ -1,106 +0,0 @@
1
- require 'find'
2
- require 'yaml'
3
- require 'livetext'
4
-
5
- class RuneBlog
6
- VERSION = "0.0.45"
7
-
8
- Path = File.expand_path(File.join(File.dirname(__FILE__)))
9
- DefaultData = Path + "/../data"
10
-
11
- BlogHeaderPath = DefaultData + "/custom/blog_header.html"
12
- BlogTrailerPath = DefaultData + "/custom/blog_trailer.html"
13
-
14
- BlogHeader = File.read(BlogHeaderPath) rescue "not found"
15
- BlogTrailer = File.read(BlogTrailerPath) rescue "not found"
16
- end
17
-
18
- # Continued below...
19
-
20
- class RuneBlog::Config
21
- attr_reader :root, :views, :view, :sequence
22
- attr_writer :view # FIXME
23
-
24
- def self.create(cfg_file = ".blog")
25
- RuneBlog.create_new_blog
26
- end
27
-
28
- def initialize(cfg_file = ".blog")
29
- # What views are there? Deployment, etc.
30
- # Crude - FIXME later
31
-
32
- lines = File.readlines(cfg_file).map {|x| x.chomp }
33
- @root = lines[0]
34
- @view = lines[1]
35
- dirs = Dir.entries("#@root/views/") - %w[. ..]
36
- dirs.reject! {|x| ! File.directory?("#@root/views/#{x}") }
37
- @root = root
38
- @views = dirs
39
- @sequence = File.read(root + "/sequence").to_i
40
- end
41
-
42
- def next_sequence
43
- @sequence += 1
44
- File.open("#@root/sequence", "w") {|f| f.puts @sequence }
45
- @sequence
46
- end
47
-
48
- def viewdir(v)
49
- @root + "/views/#{v}/"
50
- end
51
-
52
- end
53
-
54
- # Reopening...
55
-
56
- class RuneBlog
57
-
58
- def self.exist?
59
- File.exist?(".blog")
60
- end
61
-
62
- def get_config
63
- end
64
-
65
- # def initialize
66
- # # ?
67
- # end
68
-
69
- def self.create_new_blog
70
- #-- what if data already exists?
71
- result = system("cp -r #{RuneBlog::DefaultData} .")
72
- raise "Error copying default data" unless result
73
-
74
- File.open(".blog", "w") do |f|
75
- f.puts "data"
76
- f.puts "no_default"
77
- end
78
- File.open("data/VERSION", "a") {|f| f.puts "\nBlog created: " + Time.now.to_s }
79
- end
80
-
81
- # def self.open_blog
82
- # end
83
-
84
- # def self.create_new_post(title, date, view)
85
- # @template = <<-EOS
86
- # .mixin liveblog
87
- #
88
- # .title #{title}
89
- # .pubdate #{date}
90
- # .views #{view}
91
- #
92
- # .teaser
93
- # Teaser goes here.
94
- # .end
95
- # Remainder of post goes here.
96
- # EOS
97
- #
98
- # @slug = make_slug(title)
99
- # @fname = @slug + ".lt3"
100
- # File.open("#@root/src/#@fname", "w") {|f| f.puts @template }
101
- # @fname
102
- # rescue => err
103
- # error(err, __LINE__, __FILE__)
104
- # end
105
-
106
- end