class NoticeSys::CardView

Public Class Methods

new(weblet) click to toggle source
# File lib/noticesys.rb, line 144
def initialize(weblet)
  
  @w = weblet
  
end

Public Instance Methods

render(dx, rx, card) click to toggle source
# File lib/noticesys.rb, line 150
def render(dx, rx, card)
  
  card2 = case card.keys.first 
  when :images
  
    card[:images].map.with_index do |img, i|
    
      href = [dx.link.sub(/\/$/,''), rx.topic, 'status', rx.id, 
              'photo', (i+1).to_s ].join('/')
      url, align = img[:url], img[:align]
      "<a href='%s'><div class='top-crop %s'><img class='img1' src='%s'/></div></a>" % [href, align, url]
      
    end.join
    
  when :summary_large_image

    h2 = card[:summary_large_image]

    rawdesc = h2[:desc]

    desc = rawdesc.length > 147 ? rawdesc[0..147] + '...' : rawdesc
    site = h2[:url][/https?:\/\/([^\/]+)/,1].sub(/^www\./,'')
    title = h2[:title]
    img = h2[:img]
    url = h2[:url]    

    @w.render('card', binding)

  when :summary

    h2 = card[:summary]

    rawdesc = h2[:desc]

    desc = rawdesc.length > 95 ? rawdesc[0..95] + '...' : rawdesc
    site = h2[:url][/https?:\/\/([^\/]+)/,1].sub(/^www\./,'')
    title = h2[:title].length > 46 ? h2[:title][0..46] + '...' :  h2[:title]
    img = h2[:img]
    url = h2[:url]
    
    img_element = if img then 
      "<img src='#{img}'>"
    else
      @w.render('svg/article')
    end

    @w.render('card2', binding)    
  
  end
end