Sha256: d50036d71b8fb602e4ab10b1cd176d3bdb1d5e1e8e752d835494264545ff0c53

Contents?: true

Size: 1.47 KB

Versions: 6

Compression:

Stored size: 1.47 KB

Contents

# This example tries Nokogiri (used in Shoes 4)
require 'nokogiri'

class Comic
  attr_reader :rss, :title

  def initialize(body)
    @rss = Nokogiri::XML(body)
    @title = @rss.at("//channel/title").inner_text
  end

  def items
    @rss.search("//channel/item")
  end

  def latest_image
    @rss.search("//channel/item").first.inner_html.scan(/src="([^"]+\.\w+)"/).first
  end
end

Shoes.app width: 800, height: 600 do
  background "#555"

  @title = "Web Funnies"
  @feeds = [
    "http://xkcd.com/rss.xml",
    # No longer contains images
    #"http://feedproxy.google.com/DilbertDailyStrip?format=xml",
    # debug
    #"http://www.smbc-comics.com/rss.php",
    #"http://www.daybydaycartoon.com/index.xml",
    #"http://www.questionablecontent.net/QCRSS.xml",
    #"http://indexed.blogspot.com/feeds/posts/default?alt=rss"
    ]

  stack margin: 10 do
    title strong(@title), align: "center", stroke: "#DFA", margin: 0
    para "(loaded from RSS feeds)", align: "center", stroke: "#DFA",
      margin: 0

    @feeds.each do |feed|
      download feed do |dl|
        stack width: "100%", margin: 10, border: 1 do
          # Fall back to Shoes 3 syntax if necessary
          body = dl.respond_to?(:read) ? dl.read : dl.response.body
          c = Comic.new body
          stack margin_right: gutter do
            background "#333", curve: 4
            caption c.title, stroke: "#CD9", margin: 4
          end
          image c.latest_image.first, margin: 8
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
scarpe-0.4.0 examples/legacy/not_checked/shoes-contrib/basic/funnies.rb
scarpe-0.3.0 examples/legacy/not_checked/shoes-contrib/basic/funnies.rb
scarpe-0.2.2 examples/legacy/not_checked/expert/funnies.rb
lacci-0.2.1 examples/legacy/not_checked/expert/funnies.rb
scarpe-0.2.1 examples/legacy/not_checked/expert/funnies.rb
scarpe-0.2.0 examples/legacy/not_checked/expert/funnies.rb