Class: RuneBlog::Widget::Pinned

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

Instance Method Summary collapse

Constructor Details

#initialize(repo) ⇒ Pinned

Returns a new instance of Pinned.



7
8
9
10
11
# File 'lib/widgets/pinned/pinned.rb', line 7

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

Instance Method Details

#_html_body(file, css = nil) ⇒ Object

FIXME



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

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

#buildObject



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

def build
  dir = @blog.root/:posts
  posts = nil
  Dir.chdir(dir) { 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
    meta = nil
    Dir.chdir(dir/nslug) { meta =  }
    pubdate = meta.pubdate
    name = nslug[5..-1]
    link = name+".html"
    @links << [pubdate, title, link]
  end
  write_main
  write_card
end

#edit_menuObject



105
106
# File 'lib/widgets/pinned/pinned.rb', line 105

def edit_menu
end

#read_metadataObject



13
14
15
16
17
18
# File 'lib/widgets/pinned/pinned.rb', line 13

def 
  meta = read_pairs!("metadata.txt")
  meta.views = meta.views.split
  meta.tags  = meta.tags.split
  meta
end

#refreshObject



108
109
# File 'lib/widgets/pinned/pinned.rb', line 108

def refresh
end

#write_cardObject



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/widgets/pinned/pinned.rb', line 73

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
      <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 |pubdate, 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

#write_mainObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/widgets/pinned/pinned.rb', line 54

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 "<!-- #{@lines.inspect} in #{Dir.pwd} -->"
      f.puts "<h1>#{card_title}</h1><br><hr>"
      @links.each do |pubdate, title, file| 
        title = title.gsub(/\\/, "")  # kludge
        css = "color: #8888FF; text-decoration: none; font-size: 21px" 
        f.puts "<!-- pubdate = #{pubdate.inspect} -->"
        f.puts %[#{pubdate} <a style="#{css}" href="../../#{file}">#{title}</a> <br>]
      end
    end
  end
end