Class: NoticeSys::SearchQueryView
- Inherits:
-
Object
- Object
- NoticeSys::SearchQueryView
- Defined in:
- lib/noticesys.rb
Instance Method Summary collapse
-
#initialize(basepath, db_basepath, css_url, weblet, static_urlbase, urlbase) ⇒ SearchQueryView
constructor
A new instance of SearchQueryView.
- #render(q, referer) ⇒ Object
Constructor Details
#initialize(basepath, db_basepath, css_url, weblet, static_urlbase, urlbase) ⇒ SearchQueryView
Returns a new instance of SearchQueryView.
507 508 509 510 511 512 513 |
# File 'lib/noticesys.rb', line 507 def initialize(basepath, db_basepath, css_url, weblet, static_urlbase, urlbase) @basepath, @css_url, @static_urlbase = basepath, css_url, static_urlbase @db_basepath, @w, @urlbase = db_basepath, weblet, urlbase @card = CardView.new(@w) end |
Instance Method Details
#render(q, referer) ⇒ Object
515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 |
# File 'lib/noticesys.rb', line 515 def render(q, referer) users = Dir.glob(File.join(@basepath, 'u', '*')).map do |x| File.basename(x) end topics = users.map do |topic| topicpath = File.join(@basepath, 'u', topic) topic_db_path = File.join(@db_basepath, 'u', topic) db_filepath = File.join(topic_db_path, "notices.db") db = RecordxSqlite.new(db_filepath, table: 'notices') dx = Dynarex.new(File.join(topicpath, 'feed.xml')) [topic, OpenStruct.new(title: dx.title, image: dx.image, bio: dx.bio, db: db)] end.to_h #return topics.inspect rows = topics.flat_map do |topic, r| a = r.db.all.select {|x| x.description =~ /#{q.gsub('$',"\\$")}/i} a.map do |rx| link = "%s/%s/status/%s" % [@urlbase, topic, rx.noticeid] OpenStruct.new(rx.to_h.merge({topic: topic, title: r.title, image: r.image, link: link})) end end #return rows.inspect s = '' notices = rows.sort_by {|x| -(x.id.to_i)}.take(20).map do |rx| 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 #rx.description 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") #desc = rx.description.gsub(/<\/?p>/,'').gsub('<','<').gsub('>','>') topic = rx.topic title, image, bio = i(title image bio).map do |x| topics[topic].method(x).call end 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 = title, image, bio @w.render :notice, binding end #return notices.inspect s += if notices.any? then notices.join else "<p>No results for #{q}</p>" end #ref = @env["HTTP_REFERER"] ref = referer ref = '../' if ref =~ /(?:status\/\d+|search)/ svg = @w.render 'svg/backarrow', binding back = ref ? "<a href='#{ref}'>#{svg}</a>" : "<a href='/'>#{svg}</a>" @w.render :search_pg, binding end |