Class: NoticeSys::StatusView
- Inherits:
-
Object
- Object
- NoticeSys::StatusView
- Includes:
- RXFRead
- Defined in:
- lib/noticesys.rb
Instance Method Summary collapse
-
#initialize(basepath, xslfile, css_url, weblet) ⇒ StatusView
constructor
A new instance of StatusView.
- #render(topic, rawid, referer) ⇒ Object
Constructor Details
#initialize(basepath, xslfile, css_url, weblet) ⇒ StatusView
Returns a new instance of StatusView.
207 208 209 210 211 212 213 |
# File 'lib/noticesys.rb', line 207 def initialize(basepath, xslfile, css_url, weblet) @basepath, @xslfile, @css_url = basepath, xslfile, css_url @w = weblet @card = CardView.new(@w) end |
Instance Method Details
#render(topic, rawid, referer) ⇒ Object
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
# File 'lib/noticesys.rb', line 215 def render(topic, rawid, referer) id = rawid[0..9].to_i filepath = File.join(@basepath, 'u', topic) a = [Time.at(id).strftime("%Y/%b/%-d").downcase, rawid] xmlfile = File.join(filepath, "%s/%s/index.xml" % a) xslfile = File.join(@basepath, "/xsl/notices/#{topic}.xsl") unless FileX.exists? xslfile then xslfile = @xslfile end dx = Dynarex.new(File.join(filepath, 'feed.xml')) s = FileX.read(xmlfile) doc = Rexle.new(s.force_encoding("UTF-8")) doc.root.element('summary/title').text = dx.title e = doc.root.element('summary/image') if e.nil? then e = Rexle::Element.new 'image' doc.root.element('summary').add e end doc.root.element('summary/image').text = dx.image # remove the card from the description desc = doc.root.element('body/description') desc.xpath('img|div').each(&:delete) doc = Nokogiri::XML(doc.root.xml) xslt = Nokogiri::XSLT(FileX.read(xslfile)) s = xslt.transform(doc) doc = Rexle.new(s.to_s) rx = Kvx.new(xmlfile) rawcard = rx.card card2, = if rawcard and rawcard.length > 10 then card = JSON.parse(rawcard, symbolize_names: true) if card.is_a? Hash then type = card.keys.first h = card[type] #img = h[:img].sub(/small(?=\.\w+$)/,'large') img = h[:img] = @w.render(:meta, binding) [@card.render(dx, rx, card), ] end else '<span/>' end e = doc.root.at_css '#notice' desc = e.at_css '#desc' desc.add Rexle.new(card2).root ref = referer svg = @w.render 'svg/backarrow', binding back = if ref then "<div id='back'><a href='#{ref}' title='back'>#{svg}</a></div>" else "<div id='back'><a href='/' title='back'>#{svg}</a></div>" end @w.render :status, binding end |