class NoticeSys::HashtagQueryView
Public Class Methods
new(basepath, css_url, weblet, static_urlbase, urlbase)
click to toggle source
# File lib/noticesys.rb, line 397 def initialize(basepath, css_url, weblet, static_urlbase, urlbase) @basepath, @css_url, @static_urlbase = basepath, css_url, static_urlbase @w, @urlbase = weblet, urlbase @card = CardView.new(@w) end
Public Instance Methods
render(q, referer)
click to toggle source
# File lib/noticesys.rb, line 405 def render(q, referer) #q = args.first dbpath = File.join(@basepath, '/hashtag/index.db') db = RecordxSqlite.new(dbpath, table: 'hashtags') a = db.find_all_by_tag q topics = a.map(&:topic).uniq.map do |topic| topicpath = File.join(@basepath, 'u', topic) filepath = File.join(topicpath, "notices.db") db = RecordxSqlite.new(filepath, table: 'notices') dx = Dynarex.new(File.join(topicpath, 'feed.xml')) [topic, OpenStruct.new(title: dx.title, image: dx.image, db: db)] end.to_h rows = a.map do |x| r = topics[x.topic] rx = r.db.find x.noticeid link = "%s/%s/status/%s" % [@urlbase, x.topic, x.noticeid] OpenStruct.new(rx.to_h.merge({topic: x.topic, title: r.title, image: r.image, bio: r.bio, link: link})) end s = '' notices = rows.sort_by {|x| -(x.id.to_i)}.take(20).map do |rx| next unless rx.description card2 = '' rawcard = rx.to_h[:card] card2 = if rawcard and rawcard.length > 10 then card = JSON.parse(rawcard, symbolize_names: true) if card.is_a? Hash then @card.render(dx, rx, card) end else '' end t2 = Time.at rx.id.to_s[0..9].to_i relative_time = Unichron.new(t2).elapsed d = t2.strftime("%I:%M%p %b %d %Y") description = if rx.description.length > 1 then doc = Rexle.new "<node>%s</node>" % rx.description.gsub(/<\/?p>/,'') doc.root.xpath('img|div').each(&:delete) "<p>%s</p>" % doc.root.xml else '' end utitle, uimage, ubio = rx.title, rx.image, rx.bio @w.render :notice, binding end s += if notices.any? then notices.compact.join else "<p>No results for #{q}</p>" end ref = referer ref = '../' if ref =~ /(?:status|hashtag)\/\d+/ svg = @w.render 'svg/backarrow', binding back = ref ? "<a href='#{ref}'>#{svg}</a>" : '' @w.render :search_pg, binding end