runeblog 0.3.18 → 0.3.23

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,6 +15,7 @@ require 'publish'
15
15
  require 'post'
16
16
 
17
17
  require 'pathmagic'
18
+ require 'exceptions'
18
19
 
19
20
  ###
20
21
 
@@ -48,19 +49,7 @@ class RuneBlog
48
49
  ConfigFile = "config"
49
50
  Themes = RuneBlog::Path/"../themes"
50
51
 
51
- make_exception(:FileNotFound, "File $1 was not found")
52
- make_exception(:BlogRepoAlreadyExists, "Blog repo $1 already exists")
53
- make_exception(:CantAssignView, "$1 is not a view")
54
- make_exception(:ViewAlreadyExists, "View $1 already exists")
55
- make_exception(:DirAlreadyExists, "Directory $1 already exists")
56
- make_exception(:CantCreateDir, "Can't create directory $1")
57
- make_exception(:EditorProblem, "Could not edit $1")
58
- make_exception(:NoSuchView, "No such view: $1")
59
- make_exception(:NoBlogAccessor, "Runeblog.blog is not set")
60
- make_exception(:ExpectedString, "Expected nonempty string but got $1 ($2)")
61
- make_exception(:ExpectedView, "Expected string or View object but got $1 ($2)")
62
- make_exception(:ExpectedInteger, "Expected integer but got $1 ($2)")
63
-
52
+ include Helpers
64
53
  include ErrorChecks
65
54
 
66
55
  class << self
@@ -72,10 +61,10 @@ class RuneBlog
72
61
  attr_reader :views, :sequence
73
62
  attr_accessor :root, :editor, :features
74
63
  attr_accessor :view # overridden
64
+ attr_accessor :post
75
65
 
76
66
  attr_accessor :post_views, :post_tags, :dirty_views
77
67
 
78
- include Helpers
79
68
 
80
69
  class Default
81
70
 
@@ -108,7 +97,6 @@ class RuneBlog
108
97
  def self.create_new_blog_repo(root_rel = ".blogs")
109
98
  log!(enter: __method__, args: [root_rel])
110
99
  check_nonempty_string(root_rel)
111
- self.blog = self # Weird. Like a singleton - dumbass circular dependency?
112
100
  repo_root = Dir.pwd/root_rel
113
101
  check_error(BlogRepoAlreadyExists) { Dir.exist?(repo_root) }
114
102
 
@@ -124,16 +112,17 @@ class RuneBlog
124
112
  end
125
113
  # copy_data(:extra, repo_root/:config)
126
114
  write_repo_config(root: repo_root)
127
- @blog = self.new
128
- @blog
115
+ # Weird. Like a singleton - dumbass circular dependency?
116
+ self.blog = blog = self.new
117
+ blog
129
118
  rescue => err
130
119
  puts "Can't create blog repo: '#{repo_root}' - #{err}"
131
120
  puts err.backtrace.join("\n")
132
121
  end
133
122
 
134
123
  def self.open(root_rel = ".blogs")
124
+ raise "Not impl"
135
125
  log!(enter: __method__, args: [root_rel])
136
- self.blog = self # Weird. Like a singleton - dumbass circular dependency?
137
126
  blog = self.new(root_rel)
138
127
  rescue => err
139
128
  _tmp_error(err)
@@ -141,10 +130,11 @@ class RuneBlog
141
130
 
142
131
  def initialize(root_rel = ".blogs") # always assumes existing blog
143
132
  log!(enter: "initialize", args: [root_rel])
144
- self.class.blog = self # Weird. Like a singleton - dumbass circular dependency?
133
+ # Weird. Like a singleton - dumbass circular dependency?
134
+ self.class.blog = self
145
135
 
146
136
  @root = Dir.pwd/root_rel
147
- write_repo_config(root: @root) # ?? FIXME
137
+ # write_repo_config(root: @root) # ?? FIXME
148
138
  get_repo_config
149
139
  read_features # top level
150
140
  @views = retrieve_views
@@ -157,6 +147,11 @@ class RuneBlog
157
147
  @sequence = get_sequence
158
148
  @post_views = []
159
149
  @post_tags = []
150
+ rescue => err
151
+ puts "Error - see stdout.txt"
152
+ STDERR.puts err.inspect
153
+ STDERR.puts err.backtrace
154
+ sleep 3
160
155
  end
161
156
 
162
157
  def complete_file(name, vars, hash)
@@ -228,6 +223,7 @@ class RuneBlog
228
223
  meta = read_pairs!("metadata.txt")
229
224
  meta.views = meta.views.split
230
225
  meta.tags = meta.tags.split
226
+ RuneBlog.blog.post = meta
231
227
  meta
232
228
  end
233
229
 
@@ -251,7 +247,7 @@ class RuneBlog
251
247
  create_dirs(dir)
252
248
  # FIXME dependencies?
253
249
  preprocess cwd: dir, src: @root/:drafts/sourcefile, dst: @root/:posts/sourcefile.sub(/.lt3/, ".html"), # ZZZ
254
- mix: "liveblog" # , debug: true
250
+ mix: "liveblog", vars: @view.globals # , debug: true
255
251
  _deploy_local(dir)
256
252
  rescue => err
257
253
  _tmp_error(err)
@@ -274,13 +270,13 @@ class RuneBlog
274
270
  views.any? {|x| x.name == name }
275
271
  end
276
272
 
277
- def view(name = nil)
278
- log!(enter: __method__, args: [name], level: 3)
279
- return @view if name.nil?
280
-
281
- check_nonempty_string(name)
282
- return str2view(name)
283
- end
273
+ # def view(name = nil)
274
+ # log!(enter: __method__, args: [name], level: 3)
275
+ # return @view if name.nil?
276
+ #
277
+ # check_nonempty_string(name)
278
+ # return str2view(name)
279
+ # end
284
280
 
285
281
  def str2view(str)
286
282
  log!(enter: __method__, args: [str], level: 3)
@@ -297,25 +293,28 @@ class RuneBlog
297
293
 
298
294
  def view=(arg)
299
295
  log!(enter: __method__, args: [arg], level: 2)
296
+ if arg == "[no view]"
297
+ @view = nil
298
+ return
299
+ end
300
+ # STDERR.puts "view= #{arg.inspect}"
301
+
300
302
  case arg
301
- when "[no view]"
302
- # puts "Warning: No current view set"
303
- @view = nil
304
303
  when RuneBlog::View
305
304
  @view = arg
306
- read_features(@view)
307
- @view.get_globals
308
- _set_publisher
305
+ @view.get_globals(true)
309
306
  when String
310
307
  new_view = str2view(arg)
308
+ # STDERR.puts "view= new view #{new_view.inspect}"
311
309
  check_error(NoSuchView, arg) { new_view.nil? }
312
310
  @view = new_view
313
- read_features(@view)
314
- @view.get_globals
315
- _set_publisher
316
311
  else
317
312
  raise CantAssignView(arg.class.to_s)
318
313
  end
314
+ read_features(@view)
315
+ @view.get_globals(true)
316
+ _set_publisher
317
+ File.write(@root/"data/VIEW", @view.to_s)
319
318
  rescue => err
320
319
  _tmp_error(err)
321
320
  end
@@ -336,7 +335,9 @@ class RuneBlog
336
335
  log!(enter: __method__, args: [v], level: 3)
337
336
  return @view if v.nil?
338
337
  check_nonempty_string(v)
339
- return @root/:views/v
338
+ dir = @root/:views/v
339
+ puts "Dir = #{dir}" # ; sleep 5
340
+ return dir
340
341
  end
341
342
 
342
343
  def self.exist?
@@ -384,8 +385,9 @@ class RuneBlog
384
385
  make_empty_view_tree(view_name)
385
386
  add_view(view_name)
386
387
  mark_last_published("Initial creation")
387
- system("cp #@root/data/global.lt3 #@root/views/#{view_name}/themes/standard/global.lt3")
388
- @view.get_globals
388
+ # system("cp #@root/data/global.lt3 #@root/views/#{view_name}/themes/standard/global.lt3")
389
+ system("cp #@root/data/global.lt3 #@root/views/#{view_name}/data/global.lt3")
390
+ @view.get_globals(true)
389
391
  rescue => err
390
392
  _tmp_error(err)
391
393
  end
@@ -417,7 +419,7 @@ class RuneBlog
417
419
  posts.select! {|x| File.directory?(x) }
418
420
 
419
421
  posts = posts.select {|x| File.basename(x).to_i == postid }
420
- postdir = exactly_one(posts)
422
+ postdir = exactly_one(posts, posts.join("/"))
421
423
  vp = RuneBlog::ViewPost.new(self.view, postdir)
422
424
  vp
423
425
  rescue => err
@@ -433,7 +435,7 @@ class RuneBlog
433
435
  depend = [post_entry_name]
434
436
  html = "/tmp/post_entry.html"
435
437
  preprocess src: post_entry_name, dst: html,
436
- call: ".nopara" # , deps: depend # , debug: true
438
+ call: ".nopara", vars: @view.globals # , deps: depend # , debug: true
437
439
  @_post_entry = File.read(html)
438
440
  vp = post_lookup(id)
439
441
  nslug, aslug, title, date, teaser_text =
@@ -542,7 +544,8 @@ class RuneBlog
542
544
  # puts [draft, meta.views].inspect
543
545
  list << draft if meta.views.include?(self.view.to_s)
544
546
  end
545
- list.sort
547
+ # list.sort
548
+ curr_drafts
546
549
  end
547
550
 
548
551
  def all_drafts
@@ -574,15 +577,16 @@ class RuneBlog
574
577
  log!(enter: __method__, args: [view])
575
578
  vdir = @root/:views/view
576
579
  @theme = @root/:views/view/:themes/:standard
577
- depend = [vdir/"remote/etc/blog.css.lt3", @theme/"global.lt3",
580
+ @data = @root/:views/view/:data
581
+ depend = [vdir/"remote/etc/blog.css.lt3", @data/"global.lt3",
578
582
  @theme/"blog/head.lt3",
579
583
  # @theme/"navbar/navbar.lt3",
580
584
  @theme/"blog/index.lt3"] # FIXME what about assets?
581
585
  preprocess cwd: vdir/"themes/standard/etc", src: "blog.css.lt3",
582
- copy: vdir/"remote/etc/", call: [".nopara"], strip: true
586
+ copy: vdir/"remote/etc/", call: [".nopara"], strip: true , vars: @view.globals
583
587
  preprocess cwd: vdir/"themes/standard", deps: depend, force: true,
584
588
  src: "blog/generate.lt3", dst: vdir/:remote/"index.html",
585
- call: ".nopara"
589
+ call: ".nopara" , vars: @view.globals
586
590
  copy!("#{vdir}/themes/standard/banner/*", "#{vdir}/remote/banner/") # includes navbar/
587
591
  copy("#{vdir}/assets/*", "#{vdir}/remote/assets/")
588
592
  # rebuild widgets?
@@ -596,7 +600,7 @@ class RuneBlog
596
600
  def _get_views(draft)
597
601
  log!(enter: __method__, args: [draft], level: 2)
598
602
  # FIXME dumb code
599
- view_line = exactly_one(File.readlines(draft).grep(/^.views /))
603
+ view_line = exactly_one(File.readlines(draft).grep(/^.views /), ".view line")
600
604
  views = view_line[7..-1].split
601
605
  views.uniq
602
606
  rescue => err
@@ -634,10 +638,14 @@ class RuneBlog
634
638
  title = meta.title
635
639
  tags = meta.tags
636
640
  # FIXME simplify
637
- addvar(hash, "post.num" => pnum, "post.aslug" => aslug,
638
- "post.date" => date, title: title.chomp,
639
- "post.tags" => tags.join(" "), teaser: excerpt.chomp,
640
- longdate: longdate)
641
+ addvar(hash, "post.num" => pnum,
642
+ "post.aslug" => aslug,
643
+ "post.date" => date,
644
+ title: title.chomp,
645
+ teaser: excerpt.chomp,
646
+ longdate: longdate,
647
+ "post.nslug" => pnum + "-" + aslug,
648
+ "post.tags" => tags.join(" "))
641
649
  end
642
650
  hash
643
651
  rescue => err
@@ -646,19 +654,25 @@ class RuneBlog
646
654
 
647
655
  def copy_widget_html(view)
648
656
  log!(enter: __method__, level: 2)
657
+ log! str: "=== cwh cp 1"
649
658
  vdir = @root/:views/view
650
659
  remote = vdir/:remote
651
660
  wdir = vdir/:widgets
652
661
  widgets = Dir[wdir/"*"].select {|w| File.directory?(w) }
662
+ log! str: "=== cwh cp 2"
653
663
  widgets.each do |w|
654
664
  dir = File.basename(w)
655
665
  rem = w.sub(/widgets/, "remote/widgets")
666
+ log! str: "=== cwh cp 3 w = #{w.inspect}"
656
667
  create_dirs(rem)
657
668
  files = Dir[w/"*"]
658
669
  # files = files.select {|x| x =~ /(html|css)$/ }
659
670
  tag = File.basename(w)
660
- files.each {|file| system!("cp #{file} #{rem}", show: (tag == "zzz")) }
671
+ log! str: "=== cwh cp 4 tag = #{tag.inspect}"
672
+ files.each {|file| system!("cp #{file} #{rem}", show: true) }
673
+ log! str: "=== cwh cp 5 tag was #{tag.inspect}"
661
674
  end
675
+ log! str: "=== cwh cp 6"
662
676
  rescue => err
663
677
  _tmp_error(err)
664
678
  end
@@ -674,22 +688,42 @@ class RuneBlog
674
688
  pdraft = @root/:posts/nslug
675
689
  remote = @root/:views/view_name/:remote
676
690
  @theme = @root/:views/view_name/:themes/:standard
691
+ pmeta = @root/:views/view_name/:posts/nslug
692
+
693
+ log! str: "=== hpost cp 1"
677
694
 
678
695
  create_dirs(pdraft) # Step 1...
696
+ log! str: "=== hpost cp 2"
679
697
  preprocess cwd: pdraft, src: draft, # FIXME dependencies?
680
- dst: "guts.html", mix: "liveblog"
698
+ dst: "guts.html", mix: "liveblog", vars: (@view.globals || {})
699
+ log! str: "=== hpost cp 3"
681
700
  hash = _post_metadata(draft, pdraft)
701
+ log! str: "=== hpost cp 4"
702
+ hash[:CurrentPost] = pmeta
682
703
  vposts = @root/:views/view_name/:posts # Step 2...
704
+ # 5.times { STDERR.puts }
705
+ # STDERR.puts "-- hpost:"
706
+ # hash.each_pair {|k,v| STDERR.puts " #{k}: #{v}" if k.is_a? Symbol }
707
+ # 5.times { STDERR.puts }
683
708
  copy!(pdraft, vposts) # ??
684
- copy(pdraft/"guts.html", @theme/:post) # Step 3...
685
- preprocess cwd: @theme/:post, src: "generate.lt3", # Step 4...
686
- force: true, vars: hash,
687
- dst: remote/ahtml, call: ".nopara"
709
+ copy(pdraft/"guts.html", vposts/nslug) # Step 3...
710
+ # Step 4...
711
+ # preprocess cwd: @theme/:post, src: "generate.lt3",
712
+ log! str: "=== hpost cp 5"
713
+ # @view.dump_globals_stderr
714
+ preprocess cwd: pmeta, src: "../../themes/standard/post/generate.lt3",
715
+ force: true, vars: hash, debug: true,
716
+ dst: remote/ahtml, call: ".nopara"
717
+ log! str: "=== hpost cp 6"
688
718
  FileUtils.rm_f(remote/"published")
719
+ log! str: "=== hpost cp 7"
689
720
  timelog("Generated", remote/"history")
690
721
  copy_widget_html(view_name)
722
+ log! str: "=== hpost cp 8"
691
723
  rescue => err
724
+ log! str: "=== hpost cp 9"
692
725
  _tmp_error(err)
726
+ # puts err.backtrace.join("\n")
693
727
  end
694
728
 
695
729
  def _check_view?(view)
@@ -700,8 +734,11 @@ class RuneBlog
700
734
 
701
735
  def generate_post(draft, force = false)
702
736
  log!(enter: __method__, args: [draft], level: 1)
737
+ log! str: "=== gpost cp 1"
703
738
  views = _get_views(draft)
739
+ log! str: "=== gpost cp 2"
704
740
  views.each {|view| _handle_post(draft, view) }
741
+ log! str: "=== gpost cp 3"
705
742
  # For current view:
706
743
  slug = File.basename(draft).sub(/.lt3$/, "")
707
744
  postdir = self.view.dir/"remote/post/"/slug
@@ -1,9 +1,7 @@
1
1
  if !defined?(RuneBlog::Path)
2
2
 
3
- # if ! (Object.constants.include?(:RuneBlog) && RuneBlog.constants.include?(:Path))
4
-
5
3
  class RuneBlog
6
- VERSION = "0.3.18"
4
+ VERSION = "0.3.23"
7
5
 
8
6
  path = Gem.find_files("runeblog").grep(/runeblog-/).first
9
7
  Path = File.dirname(path)
@@ -28,18 +26,7 @@ class RuneBlog
28
26
  end
29
27
  end
30
28
 
31
- # Refactor, move stuff elsewhere?
32
-
33
- def make_exception(sym, str, target_class = Object)
34
- return if target_class.constants.include?(sym)
35
-
36
- target_class.const_set(sym, StandardError.dup)
37
- define_method(sym) do |*args|
38
- msg = str.dup
39
- args.each.with_index {|arg, i| msg.sub!("$#{i+1}", arg) }
40
- target_class.class_eval(sym.to_s).new(msg)
41
- end
42
- end
29
+ # Refactor, move elsewhere?
43
30
 
44
31
  def prefix(num)
45
32
  log!(enter: __method__, args: [num], level: 3)
@@ -13,17 +13,36 @@ class RuneBlog::View
13
13
  @name = name
14
14
  @publisher = RuneBlog::Publishing.new(name)
15
15
  @can_publish = true # FIXME
16
- @blog.view = self
16
+ # @blog.view = self # NOOOO??
17
17
  get_globals
18
18
  end
19
19
 
20
- def get_globals
21
- gfile = @blog.root/"views/#{name}/themes/standard/global.lt3"
20
+ def dump_globals_stderr
21
+ log!(enter: __method__, args: [list], level: 2)
22
+ list2 = list.select(&block)
23
+ STDERR.puts "-- globals = "
24
+ log!(str: "-- globals = ")
25
+ @globals.each_pair do |k, v|
26
+ msg = sprintf " %-10s %s\n", k, v if k.is_a? Symbol
27
+ STDERR.puts msg
28
+ log!(str: msg)
29
+ end
30
+ STDERR.puts
31
+ log!(str: "")
32
+ end
33
+
34
+ def get_globals(force = false)
35
+ return if @globals && !force
36
+ # gfile = @blog.root/"views/#@name/themes/standard/global.lt3"
37
+ gfile = @blog.root/"views/#@name/data/global.lt3"
22
38
  return unless File.exist?(gfile) # Hackish!! how is View.new called from create_view??
23
39
 
24
40
  live = Livetext.customize(call: ".nopara")
25
41
  live.xform_file(gfile)
42
+ live._setvar("ViewDir", @blog.root/:views/@name)
43
+ live._setvar("View", @name)
26
44
  @globals = live.vars
45
+ # dump_globals_stderr
27
46
  end
28
47
 
29
48
  def dir
@@ -20,8 +20,8 @@ spec = Gem::Specification.new do |s|
20
20
  s.authors = ["Hal Fulton"]
21
21
  s.email = 'rubyhacker@gmail.com'
22
22
  s.executables << "blog"
23
- s.add_runtime_dependency 'livetext', '~> 0.9', '>= 0.9.04'
24
- s.add_runtime_dependency 'rubytext', '~> 0.1', '>= 0.1.22'
23
+ s.add_runtime_dependency 'livetext', '~> 0.9', '>= 0.9.09'
24
+ s.add_runtime_dependency 'rubytext', '~> 0.1', '>= 0.1.23'
25
25
 
26
26
  s.add_development_dependency 'minitest', '~> 5.10', '>= 5.10.0'
27
27
 
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.3.18
4
+ version: 0.3.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hal Fulton
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-06 00:00:00.000000000 Z
11
+ date: 2020-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: livetext
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '0.9'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 0.9.04
22
+ version: 0.9.09
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '0.9'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 0.9.04
32
+ version: 0.9.09
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: rubytext
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -39,7 +39,7 @@ dependencies:
39
39
  version: '0.1'
40
40
  - - ">="
41
41
  - !ruby/object:Gem::Version
42
- version: 0.1.22
42
+ version: 0.1.23
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
@@ -49,7 +49,7 @@ dependencies:
49
49
  version: '0.1'
50
50
  - - ">="
51
51
  - !ruby/object:Gem::Version
52
- version: 0.1.22
52
+ version: 0.1.23
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: minitest
55
55
  requirement: !ruby/object:Gem::Requirement
@@ -109,6 +109,7 @@ files:
109
109
  - empty_view/config/twitter/tw.html
110
110
  - empty_view/config/twitter/tw.js
111
111
  - empty_view/config/twitter/twitter.rb
112
+ - empty_view/data/GIT_IS_DUMB
112
113
  - empty_view/posts/GIT_IS_DUMB
113
114
  - empty_view/remote/assets/GIT_IS_DUMB
114
115
  - empty_view/remote/banner/navbar/GIT_IS_DUMB
@@ -137,18 +138,21 @@ files:
137
138
  - empty_view/themes/standard/etc/blog.css.lt3
138
139
  - empty_view/themes/standard/etc/externals.lt3
139
140
  - empty_view/themes/standard/etc/favicon.ico
141
+ - empty_view/themes/standard/etc/github.css
140
142
  - empty_view/themes/standard/etc/misc.js
141
143
  - empty_view/themes/standard/post/generate.lt3
142
144
  - empty_view/themes/standard/post/head.lt3
143
145
  - empty_view/themes/standard/post/index.lt3
144
146
  - empty_view/themes/standard/post/permalink.lt3
145
147
  - lib/Javascript.stuff
148
+ - lib/exceptions.rb
146
149
  - lib/helpers-blog.rb
147
150
  - lib/helpers-repl.rb
148
151
  - lib/liveblog.rb
149
152
  - lib/logging.rb
150
153
  - lib/lowlevel.rb
151
154
  - lib/menus.rb
155
+ - lib/newpost.rb
152
156
  - lib/pathmagic.rb
153
157
  - lib/post.rb
154
158
  - lib/processing.rb
@@ -232,8 +236,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
232
236
  - !ruby/object:Gem::Version
233
237
  version: '0'
234
238
  requirements: []
235
- rubygems_version: 3.0.4
236
- signing_key:
239
+ rubygems_version: 3.0.8
240
+ signing_key:
237
241
  specification_version: 4
238
242
  summary: A command-line blogging system
239
243
  test_files: []