runeblog 0.2.53 → 0.2.58

Sign up to get free protection for your applications and to get access to all the features.
data/bin/blog CHANGED
@@ -9,9 +9,6 @@ require 'repl'
9
9
 
10
10
  include RuneBlog::REPL
11
11
 
12
- errfile = File.new("stderr.out", "w")
13
- STDERR.reopen(errfile)
14
-
15
12
  def get_started
16
13
  puts
17
14
  puts fx(<<-TEXT, :bold)
@@ -35,7 +32,53 @@ rescue => err
35
32
  puts err
36
33
  end
37
34
 
38
- ###
35
+ def cmdline_preview
36
+ _need_view
37
+ local = @blog.view.local_index
38
+ result = system("open #{local}")
39
+ end
40
+
41
+ def cmdline_publish
42
+ abort "Nor implemented yet"
43
+ _need_view
44
+ end
45
+
46
+ def cmdline_browse
47
+ abort "Nor implemented yet"
48
+ _need_view
49
+ end
50
+
51
+ def _need_view
52
+ @view = ARGV[1]
53
+ abort "Need 'view' parameter" if @view.nil?
54
+ abort "No such view '#{view}'" unless @blog.view?(@view)
55
+ end
56
+
57
+ def cmdline_rebuild
58
+ _need_view
59
+ puts "Generating view..."
60
+ @blog.generate_view(@view)
61
+ puts "Generating index..."
62
+ @blog.generate_index(@view)
63
+ end
64
+
65
+ def handle_cmdline
66
+ cmd = ARGV[0]
67
+ @blog = RuneBlog.new
68
+ abort "No blog found" if @blog.nil?
69
+
70
+ case cmd
71
+ when "rebuild"; cmdline_rebuild
72
+ when "publish"; cmdline_publish
73
+ when "preview"; cmdline_preview
74
+ when "browse"; cmdline_browse
75
+ else
76
+ puts "Command '#{cmd}' is unknown"
77
+ end
78
+ exit
79
+ end
80
+
81
+ ### Main
39
82
 
40
83
  major, minor = RUBY_VERSION.split(".").values_at(0,1)
41
84
  ver = major.to_i*10 + minor.to_i
@@ -43,6 +86,11 @@ abort "Need Ruby 2.4 or greater" unless ver >= 24
43
86
 
44
87
  include RuneBlog::Helpers # for try_read_config
45
88
 
89
+ handle_cmdline unless ARGV.empty?
90
+
91
+ errfile = File.new("stderr.out", "w")
92
+ STDERR.reopen(errfile)
93
+
46
94
  # read a .rubytext file here?? Call it something else?
47
95
  home = ENV['HOME']
48
96
  @fg, @bg = try_read_config("#{home}/.rubytext", fg: Blue, bg: White)
@@ -0,0 +1,4 @@
1
+ <div style="text-align: center; color: white; background: #101035">
2
+ <h1>Around Austin</h1><br>
3
+ The view from downtown...
4
+ </div>
@@ -0,0 +1,4 @@
1
+ <div style="text-align: center; color: white; background: #101035">
2
+ <h1>Around Austin</h1><br>
3
+ The view from downtown...
4
+ </div>
@@ -14,22 +14,7 @@
14
14
  .include blog/head.lt3
15
15
  <body>
16
16
 
17
- .set color = #101035
18
-
19
- . FIXME
20
- <table width=100% bgcolor=$color>
21
- <tr>
22
- <td width=30% bgcolor=$color>
23
- <div style="text-align: center; color: white">
24
- <h1>Around Austin</h1><br>
25
- The view from downtown...
26
- </div>
27
- </td>
28
- <td><img src=assets/austin-pano.jpg width=100%></img>
29
- </tr>
30
- </table>
31
-
32
- $.include navbar/navbar.lt3
17
+ $.banner text: top.html image: austin-pano.jpg // navbar
33
18
  <div class="content container-fluid mt-4">
34
19
  <div class="row">
35
20
  $.include blog/index.lt3
@@ -8,9 +8,10 @@
8
8
  .recent_posts
9
9
 
10
10
  .sidebar
11
- ad
12
11
  links
13
- news
12
+ ad
13
+ pinned
14
14
  pages
15
+ news
15
16
  .end
16
17
 
@@ -8,8 +8,10 @@
8
8
  . not needed.
9
9
  . --------------------------------------------------
10
10
 
11
- .navbar2
12
- index Home
11
+ .nopara
12
+ .mixin liveblog
13
+
14
+ .navbar
13
15
  about About
14
16
  contact Contact
15
17
  faq FAQ
@@ -0,0 +1,19 @@
1
+ . --------------------------------------------------
2
+ . This defines the content of the navigation bar.
3
+ . The first one is a special case.
4
+ . The others are understood to refer to .lt3 files
5
+ . such as navbar/about.lt3 (which is processed into
6
+ . HTML).
7
+ . The title may be more than one word. Quotes are
8
+ . not needed.
9
+ . --------------------------------------------------
10
+
11
+ .nopara
12
+ .mixin liveblog
13
+
14
+ .vnavbar
15
+ about About
16
+ contact Contact
17
+ faq FAQ
18
+ .end
19
+
@@ -12,22 +12,59 @@ class ::RuneBlog::Widget
12
12
 
13
13
  def build
14
14
  input = "list.data"
15
- lines = File.readlines(input)
16
- data = lines.map! {|x| x.chomp.split(/, */, 3) }
15
+ @lines = File.readlines(input)
16
+ write_main
17
+ write_card
18
+ end
19
+
20
+ def write_main
21
+ @data = @lines.map! {|x| x.chomp.split(/, */, 3) }
17
22
  css = "* { font-family: verdana }"
18
23
  card_title = "External Links" # FIXME
19
24
  File.open("#{Type}-main.html", "w") do |f|
20
25
  _html_body(f, css) do
21
26
  f.puts "<h1>#{card_title}</h1><br><hr>"
22
27
  url_ref = nil
23
- data.each do |url, frameable, title|
28
+ @data.each do |url, frameable, title|
24
29
  url_ref = (frameable == "yes") ? "href = '#{url}'" : _blank(url)
25
30
  css = "color: #8888FF; text-decoration: none; font-size: 21px" # ; font-family: verdana"
26
31
  f.puts %[<a style="#{css}" #{url_ref}>#{title}</a> <br>]
27
32
  end
28
33
  end
29
34
  end
30
- # remember -card also
35
+ end
36
+
37
+ def write_card
38
+ tag = "links"
39
+ url = :widgets/tag/tag+"-main.html"
40
+ card_title = "External links" # FIXME
41
+ cardfile = "#{Type}-card"
42
+ File.open("#{cardfile}.html", "w") do |f|
43
+ f.puts <<-EOS
44
+ <div class="card mb-3">
45
+ <div class="card-body">
46
+ <h5 class="card-title">
47
+ <button type="button" class="btn btn-primary" data-toggle="collapse" data-target="##{tag}">+</button>
48
+ <a href="javascript: void(0)"
49
+ onclick="javascript:open_main('#{url}')"
50
+ style="text-decoration: none; color: black"> #{card_title}</a>
51
+ </h5>
52
+ <div class="collapse" id="#{tag}">
53
+ EOS
54
+ @data.each do |url2, frameable, title|
55
+ main_ref = %[href="javascript: void(0)" onclick="javascript:open_main('#{url2}')"]
56
+ tab_ref = %[href="#{url2}"]
57
+ url_ref = (frameable == "yes") ? main_ref : tab_ref
58
+ anchor = %[<a #{url_ref}>#{title}</a>]
59
+ wrapper = %[<li class="list-group-item">#{anchor}</li>]
60
+ f.puts wrapper
61
+ end
62
+ f.puts <<-EOS
63
+ </div>
64
+ </div>
65
+ </div>
66
+ EOS
67
+ end
31
68
  end
32
69
 
33
70
  def edit_menu
@@ -2,11 +2,81 @@
2
2
 
3
3
  class ::RuneBlog::Widget
4
4
  class News
5
+ Type, Title = "news", "News"
6
+
5
7
  def initialize(repo)
6
8
  @blog = repo
9
+ @datafile = "list.data"
7
10
  end
8
11
 
9
12
  def build
13
+ lines = File.readlines(@datafile)
14
+ @data = lines.map {|line| line.chomp.split(/, */) }
15
+ write_main
16
+ write_card
17
+ end
18
+
19
+ def _html_body(file, css = nil)
20
+ file.puts "<html>"
21
+ if css
22
+ file.puts " <head>"
23
+ file.puts " <style>\n#{css}\n </style>"
24
+ file.puts " </head>"
25
+ end
26
+ file.puts " <body>"
27
+ yield
28
+ file.puts " </body>\n</html>"
29
+ end
30
+
31
+ def write_main
32
+ mainfile = "#{Type}-main"
33
+ css = "* { font-family: verdana }"
34
+ File.open("#{mainfile}.html", "w") do |f|
35
+ _html_body(f, css) do
36
+ f.puts "<h1>#{Title}</h1><br><hr>"
37
+ @data.each do |file, frameable, title|
38
+ title = title.gsub(/\\/, "") # kludge
39
+ case frameable
40
+ when "yes"; url_ref = "href = '#{file}'"
41
+ when "no"; url_ref = %[href='#{file}' target='blank']
42
+ end
43
+ css = "color: #8888FF; text-decoration: none; font-size: 21px"
44
+ f.puts %[<a style="#{css}" #{url_ref}>#{title}</a> <br>]
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ def write_card
51
+ cardfile = "#{Type}-card"
52
+ url = "widgets/#{Type}/#{Type}-main.html"
53
+ File.open("#{cardfile}.html", "w") do |f|
54
+ f.puts <<-EOS
55
+ <div class="card mb-3">
56
+ <div class="card-body">
57
+ <h5 class="card-title">
58
+ <button type="button" class="btn btn-primary" data-toggle="collapse" data-target="##{Type}">+</button>
59
+ <a href="javascript: void(0)"
60
+ onclick="javascript:open_main('#{url}')"
61
+ style="text-decoration: none; color: black"> #{Title}</a>
62
+ </h5>
63
+ <div class="collapse" id="#{Type}">
64
+ EOS
65
+ @data.each do |file, frameable, title|
66
+ case frameable
67
+ when "yes"; url_ref = _main(file) # remote, frameable
68
+ when "no"; url_ref = _blank(file) # remote, not frameable
69
+ end
70
+ anchor = %[<a #{url_ref}>#{title}</a>]
71
+ wrapper = %[<li class="list-group-item">#{anchor}</li>]
72
+ f.puts wrapper
73
+ end
74
+ f.puts <<-EOS
75
+ </div>
76
+ </div>
77
+ </div>
78
+ EOS
79
+ end
10
80
  end
11
81
 
12
82
  def edit_menu
@@ -4,8 +4,11 @@
4
4
 
5
5
  class ::RuneBlog::Widget
6
6
  class Pages
7
+ Type = "pages"
8
+
7
9
  def initialize(repo)
8
10
  @blog = repo
11
+ @datafile = "list.data"
9
12
  end
10
13
 
11
14
  def build
@@ -15,8 +18,59 @@ class ::RuneBlog::Widget
15
18
  dest = child.sub(/.lt3$/, ".html")
16
19
  xlate src: child, dst: dest # , debug: true
17
20
  end
18
- # build mainfile
19
- # build cardfile
21
+ @lines = File.readlines(@datafile)
22
+ write_main
23
+ write_card
24
+ end
25
+
26
+ def write_main
27
+ @data = @lines.map! {|x| x.chomp.split(/, */, 3) }
28
+ css = "* { font-family: verdana }"
29
+ card_title = "Pages" # FIXME
30
+ File.open("#{Type}-main.html", "w") do |f|
31
+ _html_body(f, css) do
32
+ f.puts "<h1>#{card_title}</h1><br><hr>"
33
+ url_ref = nil
34
+ @data.each do |url, frameable, title|
35
+ url_ref = (frameable == "yes") ? "href = '#{url}'" : _blank(url)
36
+ css = "color: #8888FF; text-decoration: none; font-size: 21px" # ; font-family: verdana"
37
+ f.puts %[<a style="#{css}" #{url_ref}>#{title}</a> <br>]
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ def write_card
44
+ tag = Type
45
+ url = :widgets/tag/tag+"-main.html"
46
+ card_title = "Pages" # FIXME
47
+ cardfile = "#{Type}-card"
48
+ File.open("#{cardfile}.html", "w") do |f|
49
+ f.puts <<-EOS
50
+ <div class="card mb-3">
51
+ <div class="card-body">
52
+ <h5 class="card-title">
53
+ <button type="button" class="btn btn-primary" data-toggle="collapse" data-target="##{tag}">+</button>
54
+ <a href="javascript: void(0)"
55
+ onclick="javascript:open_main('#{url}')"
56
+ style="text-decoration: none; color: black"> #{card_title}</a>
57
+ </h5>
58
+ <div class="collapse" id="#{tag}">
59
+ EOS
60
+ @data.each do |url2, frameable, title|
61
+ main_ref = %[href="javascript: void(0)" onclick="javascript:open_main('#{url2}')"]
62
+ tab_ref = %[href="#{url2}"]
63
+ url_ref = (frameable == "yes") ? main_ref : tab_ref
64
+ anchor = %[<a #{url_ref}>#{title}</a>]
65
+ wrapper = %[<li class="list-group-item">#{anchor}</li>]
66
+ f.puts wrapper
67
+ end
68
+ f.puts <<-EOS
69
+ </div>
70
+ </div>
71
+ </div>
72
+ EOS
73
+ end
20
74
  end
21
75
 
22
76
  def edit_menu
@@ -4,9 +4,90 @@ class ::RuneBlog::Widget
4
4
  class Pinned
5
5
  def initialize(repo)
6
6
  @blog = repo
7
+ @self = "pinned"
8
+ @datafile = "list.data"
7
9
  end
8
10
 
11
+ def _html_body(file, css = nil) # FIXME
12
+ file.puts "<html>"
13
+ if css
14
+ file.puts " <head>"
15
+ file.puts " <style>\n#{css}\n </style>"
16
+ file.puts " </head>"
17
+ end
18
+ file.puts " <body>"
19
+ yield
20
+ file.puts " </body>\n</html>"
21
+ end
22
+
9
23
  def build
24
+ @tmp = File.new("/tmp/debug-out", "w")
25
+ posts = nil
26
+ Dir.chdir(@blog.root/:posts) { posts = Dir["*"] }
27
+ lines = File.exist?(@datafile) ? File.readlines(@datafile) : []
28
+ hash = {}
29
+ @links = []
30
+ lines.each do |x|
31
+ num, title = x.chomp.split(" ", 2)
32
+ hash[num] = title
33
+ pre = '%04d' % num
34
+ nslug = posts.grep(/#{pre}-/).first
35
+ name = nslug[5..-1]
36
+ link = name+".html"
37
+ @links << [title, link]
38
+ end
39
+ write_main
40
+ write_card
41
+ end
42
+
43
+ def write_main
44
+ tag = "pinned"
45
+ card_title = "Pinned posts" # FIXME
46
+ # setvar "card.title", card_title
47
+ css = "* { font-family: verdana }"
48
+ mainfile = "#@self-main"
49
+ File.open("#{mainfile}.html", "w") do |f|
50
+ _html_body(f, css) do
51
+ f.puts "<h1>#{card_title}</h1><br><hr>"
52
+ @links.each do |title, file|
53
+ title = title.gsub(/\\/, "") # kludge
54
+ css = "color: #8888FF; text-decoration: none; font-size: 21px"
55
+ f.puts %[<a style="#{css}" href="../../#{file}">#{title}</a> <br>]
56
+ end
57
+ end
58
+ end
59
+ end
60
+
61
+ def write_card
62
+ tag = "pinned"
63
+ url = :widgets/tag/tag+"-main.html"
64
+ card_title = "Pinned posts" # FIXME
65
+ cardfile = "#@self-card"
66
+ File.open("#{cardfile}.html", "w") do |f|
67
+ f.puts <<-EOS
68
+ <div class="card mb-3">
69
+ <div class="card-body">
70
+ <h5 class="card-title">
71
+ <button type="button" class="btn btn-primary" data-toggle="collapse" data-target="##{tag}">+</button>
72
+ <a href="javascript: void(0)"
73
+ onclick="javascript:open_main('#{url}')"
74
+ style="text-decoration: none; color: black"> #{card_title}</a>
75
+ </h5>
76
+ <div class="collapse" id="#{tag}">
77
+ EOS
78
+ @links.each do |title, file|
79
+ url2 = file
80
+ url_ref = %[href="javascript: void(0)" onclick="javascript:open_main('#{url2}')"]
81
+ anchor = %[<a #{url_ref}>#{title}</a>]
82
+ wrapper = %[<li class="list-group-item">#{anchor}</li>]
83
+ f.puts wrapper
84
+ end
85
+ f.puts <<-EOS
86
+ </div>
87
+ </div>
88
+ </div>
89
+ EOS
90
+ end
10
91
  end
11
92
 
12
93
  def edit_menu