Class: RuneBlog::Widget::Links

Inherits:
Object
  • Object
show all
Defined in:
lib/widgets/links/links.rb

Instance Method Summary collapse

Constructor Details

#initialize(repo) ⇒ Links

Returns a new instance of Links.



9
10
11
12
13
# File 'lib/widgets/links/links.rb', line 9

def initialize(repo)
  @blog = repo
  @datafile = input = "list.data"
  @lines = _get_data(@datafile)
end

Instance Method Details

#_html_body(file, css = nil) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/widgets/links/links.rb', line 20

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

#buildObject



15
16
17
18
# File 'lib/widgets/links/links.rb', line 15

def build
  write_main
  write_card
end

#edit_menuObject



84
85
# File 'lib/widgets/links/links.rb', line 84

def edit_menu
end

#refreshObject



87
88
# File 'lib/widgets/links/links.rb', line 87

def refresh
end

#write_cardObject



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
81
82
# File 'lib/widgets/links/links.rb', line 50

def write_card
  tag = "links"
  url = :widgets/tag/tag+"-main.html"
  card_title = "External links"  # FIXME
  cardfile = "#{Type}-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
    @data.each do |url2, frameable, title|
      f.puts "<!-- #{[url2, frameable, title].inspect} -->"
      main_ref = %[href="javascript: void(0)" onclick="javascript:open_main('#{url2}')"]
      tab_ref  = %[href="#{url2}"]
      url_ref = (frameable == "yes") ? main_ref : tab_ref
      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_mainObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/widgets/links/links.rb', line 32

def write_main
  @data = @lines.map! {|x| x.chomp.split(/, */, 3) }
  css = "body { font-family: verdana }"
  card_title = Title
  File.open("#{Type}-main.html", "w") do |f|     
    _html_body(f, css) do
      f.puts "<h1>#{card_title}</h1><br><hr>"
      url_ref = nil
      @data.each do |url, frameable, title|
        url_ref = "href = '#{url}'"
        url_ref << " target=blank" if frameable == "yes"
        css = "color: #8888FF; text-decoration: none; font-size: 21px"
        f.puts %[<a style="#{css}" #{url_ref}>#{title}</a> <br>]
      end
    end
  end
end