runeblog 0.1.76 → 0.1.78

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,11 +1,13 @@
1
- require 'helpers-blog'
2
- # require 'runeblog'
1
+ # require 'helpers-blog'
2
+ require 'runeblog'
3
3
  require 'global'
4
4
 
5
5
  class RuneBlog::Post
6
6
 
7
7
  attr_reader :num, :title, :date, :views, :num, :slug
8
8
 
9
+ attr_accessor :meta, :blog, :draft
10
+
9
11
  include RuneBlog::Helpers
10
12
 
11
13
  def self.files(num, root)
@@ -15,6 +17,7 @@ class RuneBlog::Post
15
17
  end
16
18
 
17
19
  def self.load(post)
20
+ raise "Doesn't work right now"
18
21
  raise NoBlogAccessor if RuneBlog.blog.nil?
19
22
  # "post" is a slug
20
23
  pdir = RuneBlog.blog.view.dir + "/" + post
@@ -22,8 +25,8 @@ class RuneBlog::Post
22
25
  meta = nil
23
26
  Dir.chdir(pdir) do
24
27
  verify(File.exist?("metadata.txt") => "metadata.txt not found",
25
- File.exist?("teaser.txt") => "teaser.txt not found",
26
- File.exist?("body.txt") => "body.txt not found")
28
+ File.exist?("teaser.txt") => "teaser.txt not found")
29
+ # File.exist?("body.txt") => "body.txt not found")
27
30
  meta = read_config("metadata.txt")
28
31
  verify(meta.date => "meta.date is nil",
29
32
  meta.views => "meta.views is nil",
@@ -32,26 +35,20 @@ class RuneBlog::Post
32
35
  meta.views = meta.views.split
33
36
  meta.tags = meta.tags.split
34
37
  meta.teaser = File.read("teaser.txt")
35
- meta.body = File.read("body.txt")
38
+ # meta.body = File.read("body.txt")
36
39
  end
37
40
  meta
38
41
  end
39
42
 
40
- def create_post_subtree(viewname = nil)
41
- # FIXME Doesn't really do anything - refactor
42
- debug "=== create_post_subtree #{viewname.inspect} pwd = #{Dir.pwd}"
43
- # We are INSIDE views/myview/000n-mytitle dir now - FIXME later? how did that happen?
44
- create_dir("assets")
45
- end
46
-
47
- def write_metadata(meta)
43
+ def write_metadata(meta) # FIXME ???
48
44
  debug "=== write_metadata:"
49
45
  debug "-----\n#{meta.inspect}\n-----"
50
46
  fname2 = "metadata.txt"
51
47
  hash = meta.to_h
52
48
 
53
49
  File.write("teaser.txt", hash[:teaser])
54
- File.write("body.txt", hash[:body])
50
+ # STDERR.puts ">>>> #{__method__}: writing #{@live.body.size} bytes to #{Dir.pwd}/body.txt"
51
+ # File.write("body.txt", hash[:body])
55
52
  hash.delete(:teaser)
56
53
  hash.delete(:body)
57
54
 
@@ -67,48 +64,36 @@ class RuneBlog::Post
67
64
 
68
65
  def initialize
69
66
  @blog = RuneBlog.blog || raise(NoBlogAccessor)
67
+ @meta = OpenStruct.new
70
68
  end
71
69
 
72
- def self.create(title, teaser = "", body = "")
73
- debug "=== Post.create #{title.inspect} pwd = #{Dir.pwd}"
70
+ def self.create(title:, teaser:, body:, pubdate: Time.now.strftime("%Y-%m-%d"),
71
+ other_views:[])
74
72
  post = self.new
75
- post.new_metadata(title.chomp, teaser.chomp, body.chomp)
76
- post.create_draft
77
- post.create_post_subtree
78
- # post.build is not called here! It is called
79
- # in runeblog.rb:create_new_post AFTER post.edit
80
- post
81
- end
82
-
83
- def new_metadata(title, teaser = nil, body = nil)
84
- verify(title.is_a?(String) => "Title #{title.inspect} is not a string")
85
- meta = OpenStruct.new
86
- meta.title = title
87
- meta.teaser ||= teaser
88
- meta.body ||= body
89
- meta.pubdate = Time.now.strftime("%Y-%m-%d")
90
- meta.date = meta.pubdate # fix later
91
- meta.views = [@blog.view.to_s]
92
- meta.tags = []
93
73
  # ONLY place next_sequence is called!
94
- meta.num = @blog.next_sequence
95
- @blog.make_slug(meta) # adds to meta
96
- @meta = meta
97
- end
98
-
99
- def create_draft
100
- # FIXME obsolete
101
- # STDERR.puts "-- create_draft: teaser = #{@meta.teaser.inspect} body = #{@meta.body.inspect}"
102
- viewhome = @blog.view.publisher.url
103
- html = RuneBlog.post_template(title: @meta.title, date: @meta.pubdate,
104
- view: @meta.view, teaser: @meta.teaser, body: @meta.body,
105
- views: @meta.views, tags: @meta.tags, home: viewhome)
106
- srcdir = "#{@blog.root}/drafts/"
74
+ num = post.meta.num = post.blog.next_sequence
75
+
76
+ # new_metadata
77
+ post.meta.title, post.meta.teaser, post.meta.body, post.meta.pubdate =
78
+ title, teaser, body, pubdate
79
+ post.meta.views = [post.blog.view.to_s] + other_views
80
+ post.meta.tags = []
81
+ post.blog.make_slug(post.meta) # adds to meta
82
+
83
+ # create_draft
84
+ viewhome = post.blog.view.publisher.url
85
+ meta = post.meta
86
+ text = RuneBlog.post_template(num: meta.num, title: meta.title, date: meta.pubdate,
87
+ view: meta.view, teaser: meta.teaser, body: meta.body,
88
+ views: meta.views, tags: meta.tags, home: viewhome)
89
+ srcdir = "#{post.blog.root}/drafts/"
90
+ vpdir = "#{post.blog.root}/drafts/"
107
91
  verify(Dir.exist?(srcdir) => "#{srcdir} not found",
108
- @meta.slug.is_a?(String) => "slug #{@meta.slug.inspect} is invalid")
109
- fname = @meta.slug + ".lt3"
110
- @draft = srcdir + fname
111
- dump(html, @draft)
92
+ meta.slug.is_a?(String) => "slug #{meta.slug.inspect} is invalid")
93
+ fname = meta.slug + ".lt3"
94
+ post.draft = srcdir + fname
95
+ dump(text, post.draft)
96
+ return post
112
97
  end
113
98
 
114
99
  def edit
@@ -120,32 +105,31 @@ class RuneBlog::Post
120
105
  error(err)
121
106
  end
122
107
 
123
- def build
124
- debug "=== build"
125
- views = @meta.views
108
+ def build # THIS CODE WILL GO AWAY
109
+ post = self
110
+ views = post.meta.views
126
111
  text = File.read(@draft)
127
- # STDERR.puts "-- build: draft = #{@draft.inspect}"
128
- livetext = Livetext.new(STDOUT)
129
- Livetext.parameters = [@blog, @meta.num, livetext]
130
- meta = livetext.process_text(text)
131
- raise RuneBlog::LivetextError(@draft) if meta.nil?
132
112
 
133
- meta.num = File.basename(@draft).to_i
134
- # FIXME what if title changes? slug should change?
135
- meta.views = views # FIXME
113
+ @blog.generate_post(@draft)
114
+ return
136
115
 
137
- meta.views.each do |view_name|
116
+ STDERR.puts "-- Post#build starts in #{Dir.pwd} ..."
117
+
118
+ @meta.views.each do |view_name|
138
119
  # Create dir using slug (index.html, metadata?)
139
- vdir = "#{@blog.root}/views/#{view_name}/"
140
- dir = vdir + meta.slug + "/"
141
- create_dir(dir) unless Dir.exist?(dir)
142
- Dir.chdir(dir) do
143
- create_post_subtree(view_name) # unless existing??
144
- system("cp body.txt index.html")
145
- @blog.generate_index(view_name)
120
+ dir = "#{@blog.root}/views/#{view_name}/posts/"
121
+ pdir = dir + meta.slug + "/"
122
+ create_dir(pdir) unless Dir.exist?(pdir)
123
+ Dir.chdir(pdir) do
124
+ title_name = pdir + (meta.slug + ".lt3").sub(/^\d{4}-/, "")
125
+ dump(text, title_name)
126
+ cmd = "livetext #{title_name} >#{title_name.sub(/.lt3$/, ".html")}"
127
+ STDERR.puts "--- In #{pdir}"
128
+ STDERR.puts "--- cmd = #{cmd}\n "
129
+ system(cmd)
146
130
  end
147
131
  end
148
- meta
132
+ @meta
149
133
  rescue => err
150
134
  p err
151
135
  puts err.backtrace.join("\n")
@@ -1,4 +1,4 @@
1
- require 'helpers-blog'
1
+ # require 'helpers-blog'
2
2
  # require 'runeblog'
3
3
  require 'global'
4
4
 
@@ -39,9 +39,10 @@ module RuneBlog::REPL
39
39
  def cmd_config(arg, testing = false)
40
40
  check_empty(arg)
41
41
  dir = @blog.view.dir
42
+ # FIXME bad path
42
43
  items = ["publish",
43
44
  "themes/standard/blogview.lt3",
44
- "themes/standard/post/index.lt3"]
45
+ "themes/standard/post-index.lt3"]
45
46
  num, fname = STDSCR.menu(title: "Edit file:", items: items)
46
47
  edit_file("#{dir}/#{fname}")
47
48
  end
@@ -248,8 +249,28 @@ module RuneBlog::REPL
248
249
  end
249
250
 
250
251
  file = files.first
251
- result = edit_file("#{@blog.root}/drafts/#{file}")
252
- @blog.rebuild_post(file)
252
+ draft = "#{@blog.root}/drafts/#{file}"
253
+ result = edit_file(draft)
254
+
255
+ STDERR.puts "Calling gp: pwd = #{Dir.pwd} draft = #{draft}"
256
+ puts
257
+
258
+ @blog.generate_post(draft)
259
+ return
260
+
261
+ # NEW code...
262
+ view = @blog.view
263
+ # livetext source > naked post 9999-slug (dir?)
264
+ draft = @blog.root + "/drafts/#{file}"
265
+ # theme = "#{@blog.view.dir}/themes/standard"
266
+ # src = "#{theme}/post-index.lt3"
267
+
268
+ system("cp #{draft} #{src}") # terms are confusing
269
+ file2 = file.sub(/.lt3$/, ".html")
270
+ Dir.chdir(theme) do
271
+ system("livetext index.lt3 >#{file2}")
272
+ end
273
+ # @blog.rebuild_post(file)
253
274
  @out
254
275
  end
255
276
 
@@ -9,14 +9,18 @@ require 'view'
9
9
  require 'publish'
10
10
  require 'post'
11
11
 
12
+ # ::Home = Dir.pwd unless defined?(::Home)
13
+
12
14
  ###
13
15
 
14
16
  class RuneBlog
15
17
 
16
18
  DotDir = ".blogs"
17
- ConfigFile = "#{DotDir}/config"
19
+ ConfigFile = "config"
18
20
  GemData = RuneBlog::Path + "/../data"
19
21
 
22
+ # ::Home = Dir.pwd
23
+
20
24
  make_exception(:FileNotFound, "File $1 was not found")
21
25
  make_exception(:BlogRepoAlreadyExists, "Blog repo $1 already exists")
22
26
  make_exception(:CantAssignView, "$1 is not a view")
@@ -41,34 +45,6 @@ class RuneBlog
41
45
 
42
46
  include Helpers
43
47
 
44
- =begin
45
- timestamps
46
- filename (cf with real file)
47
-
48
- themes
49
- standard
50
- head.lt3
51
- meta.lt3
52
- global.lt3
53
- assets/
54
- blog/
55
- [kill assets?]
56
- sidebar/
57
- ad.lt3
58
- calendar.lt3
59
- news.lt3
60
- tag_cloud.lt3
61
- _postentry
62
- generate.lt3
63
- index.lt3
64
- meta.lt3
65
- navbar.lt3
66
- post/
67
- generate.lt3
68
- head.lt3
69
- index.lt3
70
- =end
71
-
72
48
  def self.create_new_blog_repo(first_view, dir = ".blogs/data")
73
49
  raise ArgumentError unless dir.is_a?(String) && ! dir.empty?
74
50
  root_dir = Dir.pwd + "/" + dir
@@ -89,12 +65,24 @@ class RuneBlog
89
65
  puts err.backtrace.join("\n")
90
66
  end
91
67
 
92
- def initialize # assumes existing blog
68
+ def initialize(top = true) # at top? always assumes existing blog
93
69
  # Crude - FIXME later -
94
70
  # What views are there? Publishing, etc.
95
71
  self.class.blog = self # Weird. Like a singleton - dumbass circular dependency?
96
- @root, @view_name, @editor =
97
- read_config(ConfigFile, :root, :current_view, :editor)
72
+ $_blog = self # Dumber still?
73
+ dir = ""
74
+ unless top
75
+ md = Dir.pwd.match(%r[.*.blogs])
76
+ dir = md[0]
77
+ end
78
+ file = dir.empty? ? ConfigFile : dir + "/" + ConfigFile
79
+ errmsg = "No config file! file = #{file.inspect} dir = #{Dir.pwd}"
80
+ raise errmsg unless File.exist?(file)
81
+ # Hmm. current_view doesn't belong?
82
+ @root, @view_name, @editor = read_config(file, :root, :current_view, :editor)
83
+ md = Dir.pwd.match(%r[.*/views/(.*?)/])
84
+ @view_name = md[1] if md
85
+ # STDERR.puts "---- vname = #@view_name"
98
86
  @views = get_views
99
87
  @view = str2view(@view_name)
100
88
  @sequence = get_sequence
@@ -102,6 +90,17 @@ class RuneBlog
102
90
  @post_tags = []
103
91
  end
104
92
 
93
+ def inspect
94
+ str = "[["
95
+ ivars = ["@root", "@sequence"] # self.instance_variables
96
+ ivars.each do |iv|
97
+ val = self.instance_variable_get(iv)
98
+ str << "#{iv} = #{val} "
99
+ end
100
+ str << "]]"
101
+ str
102
+ end
103
+
105
104
  def view?(name)
106
105
  raise ArgumentError unless name.is_a?(String) && ! name.empty?
107
106
  views.any? {|x| x.name == name }
@@ -117,16 +116,23 @@ class RuneBlog
117
116
  @views.find {|x| x.name == str }
118
117
  end
119
118
 
119
+ def _set_publisher
120
+ file = @view.dir + "/publish"
121
+ @view.publisher = nil
122
+ return unless File.exist?(file)
123
+ @view.publisher = RuneBlog::Publishing.new(read_config(file))
124
+ end
125
+
120
126
  def view=(arg)
121
127
  case arg
122
128
  when RuneBlog::View
123
129
  @view = arg
124
- @view.publisher = RuneBlog::Publishing.new(read_config(@view.dir + "/publish"))
130
+ _set_publisher
125
131
  when String
126
132
  new_view = str2view(arg)
127
133
  raise NoSuchView(arg) if new_view.nil?
128
134
  @view = new_view
129
- @view.publisher = RuneBlog::Publishing.new(read_config(@view.dir + "/publish"))
135
+ _set_publisher
130
136
  else
131
137
  raise CantAssignView(arg.class.to_s)
132
138
  end
@@ -142,7 +148,7 @@ class RuneBlog
142
148
  @sequence
143
149
  end
144
150
 
145
- def viewdir(v = nil)
151
+ def viewdir(v = nil) # delete?
146
152
  v = str2view(v) if v.is_a?(String)
147
153
  raise ArgumentError unless v.nil? || v.is_a?(RuneBlog::View)
148
154
  v ||= @view
@@ -150,11 +156,10 @@ class RuneBlog
150
156
  end
151
157
 
152
158
  def self.exist?
153
- Dir.exist?(DotDir) && File.exist?(ConfigFile)
159
+ Dir.exist?(DotDir) && File.exist?(DotDir + "/" + ConfigFile)
154
160
  end
155
161
 
156
162
  def create_view(arg)
157
- debug "=== create_view #{arg.inspect}"
158
163
  raise ArgumentError unless arg.is_a?(String) && ! arg.empty?
159
164
 
160
165
  names = self.views.map(&:to_s)
@@ -168,11 +173,12 @@ class RuneBlog
168
173
  Dir.chdir(vdir)
169
174
  x = RuneBlog::Default
170
175
  create_dir('themes')
171
- create_dir("generated")
176
+ # create_dir("generated")
172
177
  create_dir('assets')
178
+ create_dir('posts')
173
179
 
174
180
  Dir.chdir("themes") { system("tar zxvf #{GemData}/standard.tgz >/dev/null 2>&1") }
175
- system("cp themes/standard/blog/assets/* assets/")
181
+ # system("cp themes/standard/blog/assets/* assets/")
176
182
 
177
183
  pub = "user: xxx\nserver: xxx\ndocroot: xxx\npath: xxx\nproto: xxx\n"
178
184
  dump(pub, "publish")
@@ -182,9 +188,6 @@ class RuneBlog
182
188
  view = RuneBlog::View.new(arg)
183
189
  self.view = view
184
190
  vdir = self.view.dir
185
- dir0 = "#{vdir}/themes/standard/blog"
186
- dir1 = "#{vdir}/generated"
187
- system("livetext #{dir0}/generate.lt3 >#{dir1}/index.html 2>#{dir1}/errors.txt")
188
191
  dump("Initial creation", "last_published")
189
192
  Dir.chdir(up)
190
193
  @views << view
@@ -200,7 +203,7 @@ class RuneBlog
200
203
  end
201
204
 
202
205
  def view_files
203
- vdir = self.viewdir
206
+ vdir = self.view.dir
204
207
  files = ["#{vdir}/index.html"]
205
208
  files += posts.map {|x| "#{vdir}/#{x}" }
206
209
  # Huh?
@@ -215,14 +218,17 @@ class RuneBlog
215
218
  result
216
219
  end
217
220
 
218
- def create_new_post(title, testing = false, teaser: nil, body: nil)
219
- # STDERR.puts "-- create_new_post: teaser = #{teaser.inspect} body = #{body.inspect}"
221
+ def create_new_post(title, testing = false, teaser: nil, body: nil, other_views: [])
220
222
  save = Dir.pwd
221
223
  Dir.chdir(self.view.dir)
222
- post = Post.create(title, teaser, body)
224
+ # change to create_draft ?
225
+ post = Post.create(title: title, teaser: teaser, body: body, other_views: other_views)
223
226
  post.edit unless testing
224
227
  meta = post.build
225
228
  Dir.chdir(save)
229
+ return meta.num
230
+ Dir.chdir(save)
231
+ meta.num = 999
226
232
  meta.num
227
233
  rescue => err
228
234
  puts err
@@ -240,7 +246,7 @@ class RuneBlog
240
246
  end
241
247
 
242
248
  def posts
243
- dir = self.view.dir
249
+ dir = self.view.dir + "/posts"
244
250
  posts = Dir.entries(dir).grep(/^\d{4}/)
245
251
  posts
246
252
  end
@@ -259,8 +265,6 @@ class RuneBlog
259
265
  end
260
266
 
261
267
  def process_post(file)
262
- # puts " process_post #{file.inspect} pwd = #{Dir.pwd}"
263
- debug "=== process_post #{file.inspect} pwd = #{Dir.pwd}"
264
268
  raise ArgumentError unless file.is_a?(String)
265
269
  path = @root + "/drafts/#{file}"
266
270
  raise FileNotFound(path) unless File.exist?(path)
@@ -275,18 +279,88 @@ class RuneBlog
275
279
  end
276
280
 
277
281
  def generate_index(view)
282
+ # FIXME
278
283
  debug "=== generate_index view = #{view.to_s}"
279
284
  raise ArgumentError unless view.is_a?(String) || view.is_a?(RuneBlog::View)
280
285
 
281
286
  vdir = self.view.dir
282
287
  dir0 = "#{vdir}/themes/standard/blog"
283
- dir1 = "#{vdir}/generated"
284
- system("livetext #{dir0}/generate.lt3 >#{dir1}/index.html 2>#{dir1}/errors.txt")
288
+ # dir1 = "#{vdir}/generated"
289
+ # system("livetext #{dir0}/generate.lt3 >#{dir1}/index.html 2>#{dir1}/errors.txt")
285
290
  rescue => err
286
291
  error(err)
287
292
  exit
288
293
  end
289
294
 
295
+ ######## New code
296
+
297
+ def generate_view(view)
298
+ end
299
+
300
+ # Remember: A post in multiple views will trigger multiple
301
+ # views needing to be rebuilt (and published)
302
+
303
+ # generate a post:
304
+ # given draft 9999-title.lt3
305
+ # create VIEW/posts/9999-title/index.lt3
306
+ # LATER: metadata!! or is it in head?
307
+ # Generate VIEW/posts/9999-title/head.lt3?
308
+ # livetext draft_wrapper_plain.lt3 >generated/posts/plain-title.html # unframed
309
+ # livetext draft_generate.lt3 >generated/posts/real-title.html # framed
310
+ # livetext draft_wrapper_perma.lt3 >generated/posts/perma-title.html # permaframed
311
+ #
312
+ # Generate associated views:
313
+ # livetext ??/recent.lt3 >VIEW/working/recent.html
314
+ # livetext VIEW/blog/generate.lt3 ??
315
+
316
+ def generate_post(draft)
317
+ dir = File.dirname(draft)
318
+ fname = File.basename(draft)
319
+ # STDERR.puts "--- gp01 dir/fname = #{dir} #{fname}"
320
+ # FIXME dumb code
321
+ view_line = File.readlines(draft).grep(/^.views /)
322
+ raise "More than one .views call!" if view_line.size > 1
323
+ raise "No .views call!" if view_line.size < 1
324
+ view_line = view_line.first
325
+
326
+ # STDERR.puts "--- gp01b view_line = #{view_line}"
327
+ views = view_line[7..-1].split
328
+ slug_dir = fname.sub(/.lt3$/, "")
329
+ # STDERR.puts "--- gp02 preloop"
330
+ views.each do |view|
331
+ # STDERR.puts "--- gp03 view = #{view}"
332
+ vdir = "#@root/views/#{view}"
333
+ dir = "#{vdir}/posts/#{slug_dir}/"
334
+ STDERR.puts "--- gp03b vdir = #{vdir} dir = #{dir}"
335
+ Dir.mkdir(dir) unless Dir.exist?(dir)
336
+ puts
337
+ # --- gp04 system: cp /Users/Hal/Dropbox/files/runeblog/.blogs/data/drafts/0007-the-graffiti-wall.lt3
338
+ # /Users/Hal/Dropbox/files/runeblog/.blogs/data/around_austin/posts/0007-the-graffiti-wall.lt3/
339
+ STDERR.puts "--- gp04 system: cp #{draft} #{dir}"
340
+ STDERR.puts
341
+ system("cp #{draft} #{dir}")
342
+ Dir.chdir(dir) do
343
+ STDERR.puts "--- gp05 into #{dir}: livetext #{draft} >#{draft}.html"
344
+ system("livetext #{draft} >#{draft}.html")
345
+ # copy from theme?
346
+ theme = vdir + "/themes/standard"
347
+ files = ["blog-generate.lt3", "blog-index.lt3", "global.lt3", "blog-head.lt3", "meta.lt3", "navbar.lt3"]
348
+ files = files.map {|x| theme + "/" + x }
349
+ STDERR.puts "---- Files = #{files.inspect}"
350
+ files.each do |f|
351
+ STDERR.puts "---- cp #{f} ."
352
+ system("cp #{f} .")
353
+ end
354
+ STDERR.puts "---- Files copied from theme"
355
+ system("livetext blog-generate.lt3 >bgen.html")
356
+ STDERR.puts "---- Files went thru livetext"
357
+ end
358
+ # create framed pure slug (where?)
359
+ end
360
+ end
361
+
362
+ ########
363
+
290
364
  def relink
291
365
  self.views.each {|view| generate_index(view) }
292
366
  end
@@ -369,7 +443,8 @@ class RuneBlog
369
443
  end
370
444
 
371
445
  def make_slug(meta)
372
- check_meta(meta, "makeslug")
446
+ # check_meta(meta, "makeslug")
447
+ # meta.num = 9999 # FIXME
373
448
  raise ArgumentError unless meta.title.is_a?(String)
374
449
  label = '%04d' % meta.num # FIXME can do better
375
450
  slug0 = meta.title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')