# Custom code for 'pinned' widget class ::RuneBlog::Widget class Pinned Type, Title = "pinned", "Pinned posts" def initialize(repo) @blog = repo @datafile = "list.data" @lines = File.exist?(@datafile) ? File.readlines(@datafile) : [] end def _html_body(file, css = nil) # FIXME file.puts "" if css file.puts " " file.puts " " file.puts " " end file.puts " " yield file.puts " \n" end def build posts = nil Dir.chdir(@blog.root/:posts) { posts = Dir["*"] } 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 = Type card_title = Title css = "body { font-family: verdana }" mainfile = "#{tag}-main" File.open("#{mainfile}.html", "w") do |f| _html_body(f, css) do f.puts "" f.puts "

#{card_title}



" @links.each do |title, file| title = title.gsub(/\\/, "") # kludge css = "color: #8888FF; text-decoration: none; font-size: 21px" f.puts %[#{title}
] end end end end def write_card tag = Type url = :widgets/tag/tag+"-main.html" card_title = Title cardfile = "#{tag}-card" File.open("#{cardfile}.html", "w") do |f| f.puts <<-EOS
#{card_title}
EOS @links.each do |title, file| url2 = file url_ref = %[href="javascript: void(0)" onclick="javascript:open_main('#{url2}')"] anchor = %[#{title}] wrapper = %[
  • #{anchor}
  • ] f.puts wrapper end f.puts <<-EOS
    EOS end end def edit_menu end def refresh end end end