empty_view/themes/standard/widgets/pinned/pinned.rb in runeblog-0.2.53 vs empty_view/themes/standard/widgets/pinned/pinned.rb in runeblog-0.2.54
- old
+ new
@@ -2,12 +2,92 @@
class ::RuneBlog::Widget
class Pinned
def initialize(repo)
@blog = repo
+ @self = "pinned"
end
+def _html_body(file, css = nil) # FIXME
+ file.puts "<html>"
+ if css
+ file.puts " <head>"
+ file.puts " <style>\n#{css}\n </style>"
+ file.puts " </head>"
+ end
+ file.puts " <body>"
+ yield
+ file.puts " </body>\n</html>"
+end
+
def build
+@tmp = File.new("/tmp/debug-out", "w")
+ posts = nil
+ Dir.chdir(@blog.root/:posts) { posts = Dir["*"] }
+ lines = File.readlines("list.data")
+ hash = {}
+ @links = []
+ lines.each do |x|
+ num, title = x.chomp.split(" ", 2)
+ hash[num] = title
+ pre = '%04d' % num
+ nslug = posts.grep(/#{pre}-/).first
+ name = nslug[5..-1]
+ link = name+".html"
+ @links << [title, link]
+ end
+ write_main
+ write_card
+ end
+
+ def write_main
+ tag = "pinned"
+ card_title = "Pinned posts" # FIXME
+# setvar "card.title", card_title
+ css = "* { font-family: verdana }"
+ mainfile = "#@self-main"
+ File.open("#{mainfile}.html", "w") do |f|
+ _html_body(f, css) do
+ f.puts "<h1>#{card_title}</h1><br><hr>"
+ @links.each do |title, file|
+ title = title.gsub(/\\/, "") # kludge
+ css = "color: #8888FF; text-decoration: none; font-size: 21px"
+ f.puts %[<a style="#{css}" href="../../#{file}">#{title}</a> <br>]
+ end
+ end
+ end
+ end
+
+ def write_card
+ tag = "pinned"
+ url = :widgets/tag/tag+"-main.html"
+ card_title = "Pinned posts" # FIXME
+ cardfile = "#@self-card"
+ File.open("#{cardfile}.html", "w") do |f|
+ f.puts <<-EOS
+ <div class="card mb-3">
+ <div class="card-body">
+ <h5 class="card-title">
+ <button type="button" class="btn btn-primary" data-toggle="collapse" data-target="##{tag}">+</button>
+ <a href="javascript: void(0)"
+ onclick="javascript:open_main('#{url}')"
+ style="text-decoration: none; color: black"> #{card_title}</a>
+ </h5>
+ <div class="collapse" id="#{tag}">
+ EOS
+ @links.each do |title, file|
+ url2 = file
+ url_ref = %[href="javascript: void(0)" onclick="javascript:open_main('#{url2}')"]
+ anchor = %[<a #{url_ref}>#{title}</a>]
+ wrapper = %[<li class="list-group-item">#{anchor}</li>]
+ f.puts wrapper
+ end
+ f.puts <<-EOS
+ </div>
+ </div>
+ </div>
+ EOS
+ end
end
def edit_menu
end