Sha256: 75d635f5d7e318e8ff8e8bb903da341caec2f6cdc67778ae2a8fa060a1e1e43d

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

Contents

require 'rubygems'
require 'capcode'
$:.unshift( "../lib" )
require 'capcode/render/xml'

## !! THIS IS JUSTE FOR THIS EXAMPLE !!
class Hash
  def method_missing( id, *a )
    self[id.id2name.to_sym]
  end
end

module Capcode
  class RSS < Route "/rss"
    def get
      @posts = [
        { :title => "Welcome", :body => "This is a RSS example for Capcode!", :iid => 1, :created_at => Time.now() },
        { :title => "Just For Fun", :body => "See more examples on the Capcode Website...", :iid => 2, :created_at => Time.now() },
      ]
      render :xml => :rss_view
    end
  end
end

module Capcode::Views
  def rss_view
    xml? :version => '1.0'
    rss :version => "2.0" do
      channel do
        title "Capcode News"
        description "Capcode Framework."
        link "http://example.com/"
        
        @posts.each do |post|
          item do
            title post.title
            link "http://example.com/posts/#{post.iid}"
            description post.body
            pubDate Time.parse(post.created_at.to_s).rfc822()
            guid "http://example.com/posts/#{post.iid}"
          end
        end
      end
    end
  end
end

Capcode.run()

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
capcode-render-xml-0.1.0 examples/rss.rb