Class: RuneBlog::Widget::News
- Inherits:
-
Object
- Object
- RuneBlog::Widget::News
- Defined in:
- lib/widgets/news/news.rb
Instance Method Summary collapse
- #_html_body(file, css = nil) ⇒ Object
- #build ⇒ Object
- #edit_menu ⇒ Object
-
#initialize(repo) ⇒ News
constructor
A new instance of News.
- #refresh ⇒ Object
- #write_card ⇒ Object
- #write_main ⇒ Object
Constructor Details
Instance Method Details
#_html_body(file, css = nil) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/widgets/news/news.rb', line 19 def _html_body(file, css = nil) 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 |
#build ⇒ Object
14 15 16 17 |
# File 'lib/widgets/news/news.rb', line 14 def build write_main write_card end |
#edit_menu ⇒ Object
82 83 |
# File 'lib/widgets/news/news.rb', line 82 def end |
#refresh ⇒ Object
85 86 |
# File 'lib/widgets/news/news.rb', line 85 def refresh end |
#write_card ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/widgets/news/news.rb', line 50 def write_card cardfile = "#{Type}-card" url = "widgets/#{Type}/#{Type}-main.html" 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="##{Type}">+</button> <a href="javascript: void(0)" onclick="javascript:open_main('#{url}')" style="text-decoration: none; color: black"> #{Title}</a> </h5> <div class="collapse" id="#{Type}"> EOS @data.each do |file, frameable, title| case frameable when "yes"; url_ref = _main(file) # remote, frameable when "no"; url_ref = _blank(file) # remote, not frameable end 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 |
#write_main ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/widgets/news/news.rb', line 31 def write_main mainfile = "#{Type}-main" css = "body { font-family: verdana }" File.open("#{mainfile}.html", "w") do |f| _html_body(f, css) do f.puts "<h1>#{Title}</h1><br><hr>" @data.each do |file, frameable, title| title = title.gsub(/\\/, "") # kludge case frameable when "yes"; url_ref = "href = '#{file}'" when "no"; url_ref = %[href='#{file}' target='blank'] end css = "color: #8888FF; text-decoration: none; font-size: 21px" f.puts %[<a style="#{css}" #{url_ref}>#{title}</a> <br>] end end end end |