runeblog 0.2.54 → 0.2.59

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,3 @@
1
+ about About
2
+ contact Contact
3
+ faq FAQ
@@ -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,9 @@
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
+ .say Hello
18
+ $.banner text: top.html image: austin-pano.jpg // navbar
19
+ .say Hello again
33
20
  <div class="content container-fluid mt-4">
34
21
  <div class="row">
35
22
  $.include blog/index.lt3
@@ -8,8 +8,8 @@
8
8
  .recent_posts
9
9
 
10
10
  .sidebar
11
- ad
12
11
  links
12
+ ad
13
13
  pinned
14
14
  pages
15
15
  news
@@ -4,30 +4,43 @@ require 'liveblog'
4
4
 
5
5
  class ::RuneBlog::Widget
6
6
  class Links
7
- Type = "links"
7
+ Type, Title = "links", "External links"
8
8
 
9
9
  def initialize(repo)
10
10
  @blog = repo
11
+ @datafile = input = "list.data"
12
+ @lines = File.readlines(input)
11
13
  end
12
14
 
13
15
  def build
14
- input = "list.data"
15
- @lines = File.readlines(input)
16
16
  write_main
17
17
  write_card
18
18
  end
19
19
 
20
+ def _html_body(file, css = nil)
21
+ file.puts "<html>"
22
+ if css
23
+ file.puts " <head>"
24
+ file.puts " <style>\n#{css}\n </style>"
25
+ file.puts " </head>"
26
+ end
27
+ file.puts " <body>"
28
+ yield
29
+ file.puts " </body>\n</html>"
30
+ end
31
+
20
32
  def write_main
21
33
  @data = @lines.map! {|x| x.chomp.split(/, */, 3) }
22
34
  css = "* { font-family: verdana }"
23
- card_title = "External Links" # FIXME
35
+ card_title = Title
24
36
  File.open("#{Type}-main.html", "w") do |f|
25
37
  _html_body(f, css) do
26
38
  f.puts "<h1>#{card_title}</h1><br><hr>"
27
39
  url_ref = nil
28
40
  @data.each do |url, frameable, title|
29
- url_ref = (frameable == "yes") ? "href = '#{url}'" : _blank(url)
30
- css = "color: #8888FF; text-decoration: none; font-size: 21px" # ; font-family: verdana"
41
+ url_ref = "href = '#{url}'"
42
+ url_ref << " target=blank" if frameable == "yes"
43
+ css = "color: #8888FF; text-decoration: none; font-size: 21px"
31
44
  f.puts %[<a style="#{css}" #{url_ref}>#{title}</a> <br>]
32
45
  end
33
46
  end
@@ -38,7 +51,7 @@ class ::RuneBlog::Widget
38
51
  tag = "links"
39
52
  url = :widgets/tag/tag+"-main.html"
40
53
  card_title = "External links" # FIXME
41
- cardfile = "#@self-card"
54
+ cardfile = "#{Type}-card"
42
55
  File.open("#{cardfile}.html", "w") do |f|
43
56
  f.puts <<-EOS
44
57
  <div class="card mb-3">
@@ -52,6 +65,7 @@ class ::RuneBlog::Widget
52
65
  <div class="collapse" id="#{tag}">
53
66
  EOS
54
67
  @data.each do |url2, frameable, title|
68
+ f.puts "<!-- #{[url2, frameable, title].inspect} -->"
55
69
  main_ref = %[href="javascript: void(0)" onclick="javascript:open_main('#{url2}')"]
56
70
  tab_ref = %[href="#{url2}"]
57
71
  url_ref = (frameable == "yes") ? main_ref : tab_ref
@@ -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"
10
+ lines = File.readlines(@datafile)
11
+ @data = lines.map {|line| line.chomp.split(/, */) }
7
12
  end
8
13
 
9
14
  def build
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,13 @@
4
4
 
5
5
  class ::RuneBlog::Widget
6
6
  class Pages
7
+ Type, Title = "pages", "Pages"
8
+
7
9
  def initialize(repo)
8
10
  @blog = repo
11
+ @datafile = "list.data"
12
+ @lines = File.readlines(@datafile)
13
+ @data = @lines.map {|x| x.chomp.split(/, */, 2) }
9
14
  end
10
15
 
11
16
  def build
@@ -13,10 +18,72 @@ class ::RuneBlog::Widget
13
18
  children = Dir["*.lt3"] - ["pages.lt3"]
14
19
  children.each do |child|
15
20
  dest = child.sub(/.lt3$/, ".html")
16
- xlate src: child, dst: dest # , debug: true
21
+ xlate src: child, dst: dest
22
+ end
23
+ write_main
24
+ write_card
25
+ end
26
+
27
+ def _html_body(file, css = nil)
28
+ file.puts "<html>"
29
+ if css
30
+ file.puts " <head>"
31
+ file.puts " <style>\n#{css}\n </style>"
32
+ file.puts " </head>"
33
+ end
34
+ file.puts " <body>"
35
+ yield
36
+ file.puts " </body>\n</html>"
37
+ end
38
+
39
+ def write_main
40
+ css = "* { font-family: verdana }"
41
+ card_title = Title
42
+ File.open("#{Type}-main.html", "w") do |f|
43
+ _html_body(f, css) do
44
+ f.puts "<h1>#{card_title}</h1><br><hr>"
45
+ url_ref = nil
46
+ @data.each do |url, title|
47
+ url_ref = "href = '#{url}'"
48
+ css = "color: #8888FF; text-decoration: none; font-size: 21px"
49
+ f.puts %[<a style="#{css}" #{url_ref}>#{title}</a> <br>]
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+ def write_card
56
+ tag = Type
57
+ url = :widgets/tag/tag+"-main.html"
58
+ card_title = "Pages" # FIXME
59
+ cardfile = "#{Type}-card"
60
+ File.open("#{cardfile}.html", "w") do |f|
61
+ f.puts <<-EOS
62
+ <div class="card mb-3">
63
+ <div class="card-body">
64
+ <h5 class="card-title">
65
+ <button type="button" class="btn btn-primary" data-toggle="collapse" data-target="##{tag}">+</button>
66
+ <a href="javascript: void(0)"
67
+ onclick="javascript:open_main('#{url}')"
68
+ style="text-decoration: none; color: black">#{card_title}</a>
69
+ </h5>
70
+ <div class="collapse" id="#{tag}">
71
+ EOS
72
+ @data.each do |url2, title|
73
+ f.puts "<!-- #{[url2, title].inspect} -->"
74
+ url3 = :widgets/tag/url2
75
+ f.puts "<!-- url3 = #{url3.inspect} -->"
76
+ url_ref = %[href="javascript: void(0)" onclick="javascript:open_main('#{url3}')"]
77
+ anchor = %[<a #{url_ref}>#{title}</a>]
78
+ wrapper = %[<li class="list-group-item">#{anchor}</li>]
79
+ f.puts wrapper
80
+ end
81
+ f.puts <<-EOS
82
+ </div>
83
+ </div>
84
+ </div>
85
+ EOS
17
86
  end
18
- # build mainfile
19
- # build cardfile
20
87
  end
21
88
 
22
89
  def edit_menu
@@ -2,31 +2,35 @@
2
2
 
3
3
  class ::RuneBlog::Widget
4
4
  class Pinned
5
+ Type, Title = "pinned", "Pinned posts"
6
+
5
7
  def initialize(repo)
6
8
  @blog = repo
7
- @self = "pinned"
9
+ @datafile = "list.data"
10
+ # f = File.new("/tmp/mehhh", "w")
11
+ @lines = File.exist?(@datafile) ? File.readlines(@datafile) : []
12
+ # f.puts #{@lines.inspect} in #{Dir.pwd}"
13
+ File.open("/tmp/mehhh", "w") {|f| f.puts "#{@lines.inspect} in #{Dir.pwd}" }
8
14
  end
9
15
 
10
- def _html_body(file, css = nil) # FIXME
11
- file.puts "<html>"
12
- if css
13
- file.puts " <head>"
14
- file.puts " <style>\n#{css}\n </style>"
15
- file.puts " </head>"
16
- end
17
- file.puts " <body>"
18
- yield
19
- file.puts " </body>\n</html>"
20
- end
16
+ def _html_body(file, css = nil) # FIXME
17
+ file.puts "<html>"
18
+ if css
19
+ file.puts " <head>"
20
+ file.puts " <style>\n#{css}\n </style>"
21
+ file.puts " </head>"
22
+ end
23
+ file.puts " <body>"
24
+ yield
25
+ file.puts " </body>\n</html>"
26
+ end
21
27
 
22
28
  def build
23
- @tmp = File.new("/tmp/debug-out", "w")
24
29
  posts = nil
25
30
  Dir.chdir(@blog.root/:posts) { posts = Dir["*"] }
26
- lines = File.readlines("list.data")
27
31
  hash = {}
28
32
  @links = []
29
- lines.each do |x|
33
+ @lines.each do |x|
30
34
  num, title = x.chomp.split(" ", 2)
31
35
  hash[num] = title
32
36
  pre = '%04d' % num
@@ -40,13 +44,13 @@ end
40
44
  end
41
45
 
42
46
  def write_main
43
- tag = "pinned"
44
- card_title = "Pinned posts" # FIXME
45
- # setvar "card.title", card_title
47
+ tag = Type
48
+ card_title = Title
46
49
  css = "* { font-family: verdana }"
47
- mainfile = "#@self-main"
50
+ mainfile = "#{tag}-main"
48
51
  File.open("#{mainfile}.html", "w") do |f|
49
52
  _html_body(f, css) do
53
+ f.puts "<!-- #{@lines.inspect} in #{Dir.pwd} -->"
50
54
  f.puts "<h1>#{card_title}</h1><br><hr>"
51
55
  @links.each do |title, file|
52
56
  title = title.gsub(/\\/, "") # kludge
@@ -58,10 +62,10 @@ end
58
62
  end
59
63
 
60
64
  def write_card
61
- tag = "pinned"
65
+ tag = Type
62
66
  url = :widgets/tag/tag+"-main.html"
63
- card_title = "Pinned posts" # FIXME
64
- cardfile = "#@self-card"
67
+ card_title = Title
68
+ cardfile = "#{tag}-card"
65
69
  File.open("#{cardfile}.html", "w") do |f|
66
70
  f.puts <<-EOS
67
71
  <div class="card mb-3">