kelredd-media-rss 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc ADDED
@@ -0,0 +1,38 @@
1
+ = MediaRss
2
+
3
+ == Description
4
+
5
+ A gem to provide some classes for generating media-rss.
6
+
7
+ == Installation
8
+
9
+ sudo gem install kelredd-media-rss --source http://gems.github.com
10
+
11
+ == Usage
12
+
13
+ require 'media_rss'
14
+
15
+ == License
16
+
17
+ Copyright (c) 2009 Kelly Redding
18
+
19
+ Permission is hereby granted, free of charge, to any person
20
+ obtaining a copy of this software and associated documentation
21
+ files (the "Software"), to deal in the Software without
22
+ restriction, including without limitation the rights to use,
23
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
24
+ copies of the Software, and to permit persons to whom the
25
+ Software is furnished to do so, subject to the following
26
+ conditions:
27
+
28
+ The above copyright notice and this permission notice shall be
29
+ included in all copies or substantial portions of the Software.
30
+
31
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
33
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
35
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
36
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
37
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
38
+ OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,40 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+ require 'rake/testtask'
4
+
5
+ require 'lib/media_rss/version'
6
+
7
+ task :default => :test
8
+
9
+ spec = Gem::Specification.new do |s|
10
+ s.name = 'media-rss'
11
+ s.version = MediaRss::Version.to_s
12
+ s.has_rdoc = true
13
+ s.extra_rdoc_files = %w(README.rdoc)
14
+ s.rdoc_options = %w(--main README.rdoc)
15
+ s.summary = "A gem to provide some classes for generating media-rss."
16
+ s.author = 'Kelly Redding'
17
+ s.email = 'kelly@kelredd.com'
18
+ s.homepage = ''
19
+ s.files = %w(README.rdoc Rakefile) + Dir.glob("{lib,test}/**/*")
20
+ # s.executables = ['media-rss']
21
+
22
+ s.add_dependency('nokogiri')
23
+ end
24
+
25
+ Rake::GemPackageTask.new(spec) do |pkg|
26
+ pkg.gem_spec = spec
27
+ end
28
+
29
+ Rake::TestTask.new do |t|
30
+ t.libs << 'test'
31
+ t.test_files = FileList["test/**/*_test.rb"]
32
+ t.verbose = true
33
+ end
34
+
35
+ desc 'Generate the gemspec to serve this Gem from Github'
36
+ task :github do
37
+ file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
38
+ File.open(file, 'w') {|f| f << spec.to_ruby }
39
+ puts "Created gemspec: #{file}"
40
+ end
data/lib/media_rss.rb ADDED
@@ -0,0 +1,16 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ require 'media_rss/models'
4
+ require 'media_rss/builder'
5
+
6
+ module MediaRss
7
+
8
+ @@configuration = {}
9
+ def self.configure(opts = {})
10
+ @@configuration = opts || {}
11
+ end
12
+ def self.configuration
13
+ @@configuration
14
+ end
15
+
16
+ end
@@ -0,0 +1,3 @@
1
+ Dir[File.join(File.dirname(__FILE__), "builder" ,"*.rb")].each do |file|
2
+ require file
3
+ end
@@ -0,0 +1,27 @@
1
+ require 'nokogiri' unless defined?(Nokogiri)
2
+
3
+ module MediaRss
4
+ module Builder
5
+
6
+ class Base
7
+ def initialize(object)
8
+ @builder = Nokogiri::XML::Builder.new
9
+ end
10
+
11
+ def build
12
+ @builder.rss({
13
+ :version => "2.0",
14
+ :'xmlns:media' => "http://search.yahoo.com/mrss",
15
+ :'xmlns:atom' => "http://www.w3.org/2005/Atom"
16
+ }) do |builder|
17
+ yield builder
18
+ end
19
+ end
20
+
21
+ def to_rss
22
+ @builder.to_xml
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ require File.join([File.dirname(__FILE__), 'base.rb'])
2
+
3
+ module MediaRss
4
+ module Builder
5
+
6
+ class Channel < MediaRss::Builder::Base
7
+
8
+ def initialize(channel)
9
+ super(channel)
10
+ @channel = channel
11
+ build do |builder|
12
+ builder.channel {
13
+ builder.send('atom:icon', @channel.icon.to_s)
14
+ builder.title @channel.title.to_s
15
+ builder.link @channel.link.to_s
16
+ builder.description @channel.description.to_s
17
+ @channel.items.each do |item|
18
+ Item.build(builder, item)
19
+ end
20
+ }
21
+ end
22
+ end
23
+
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,18 @@
1
+ module MediaRss
2
+ module Builder
3
+
4
+ class HtmlHeaderLink
5
+
6
+ attr_reader :url, :options
7
+ def initialize(url, opts={})
8
+ @url = url
9
+ @options = opts || {}
10
+ @options[:title] ||= 'media rss'
11
+ end
12
+
13
+ def to_s
14
+ "<link rel=\"alternate\" href=\"#{@url.to_s}\" type=\"application/rss+xml\" title=\"#{@options[:title]}\" />"
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,22 @@
1
+ require File.join([File.dirname(__FILE__), 'base.rb'])
2
+
3
+ module MediaRss
4
+ module Builder
5
+
6
+ class Item
7
+
8
+ def self.build(builder, item)
9
+ builder.item {
10
+ builder.title item.title.to_s
11
+ builder.link item.link.to_s
12
+ builder.guid item.guid.to_s
13
+ builder.send('media:description', item.description.to_s)
14
+ builder.send('media:thumbnail', :url => item.thumb.to_s, :type => item.thumb_type.to_s)
15
+ builder.send('media:content', :url => item.content.to_s, :type => item.content_type.to_s)
16
+ }
17
+ end
18
+
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ Dir[File.join(File.dirname(__FILE__), "models" ,"*.rb")].each do |file|
2
+ require file
3
+ end
@@ -0,0 +1,17 @@
1
+ module MediaRss
2
+
3
+ class Channel
4
+
5
+ attr_accessor :title, :icon, :link, :description, :items
6
+
7
+ def initialize(title, opts = {})
8
+ @title = title
9
+ @icon = opts[:icon]
10
+ @link = opts[:link]
11
+ @description = opts[:description]
12
+ @items = []
13
+ end
14
+
15
+ end
16
+
17
+ end
@@ -0,0 +1,12 @@
1
+ require File.join([File.dirname(__FILE__), 'channel.rb'])
2
+
3
+ module MediaRss
4
+
5
+ class Feed < ::Array
6
+ def self.default_channel(title, ops = {})
7
+ opts[:icon] ||= MediaRss.congiguration[:default_icon]
8
+ Channel.new(title, opts)
9
+ end
10
+ end
11
+
12
+ end
@@ -0,0 +1,22 @@
1
+ module MediaRss
2
+
3
+ class Item
4
+
5
+ attr_accessor :title, :link, :guid, :description, :thumb, :thumb_type, :content, :content_type
6
+
7
+ def initialize(title, opts = {})
8
+ @title = title
9
+ @link = opts[:link]
10
+ @guid = opts[:guid]
11
+ @description = opts[:description]
12
+ @thumb = opts[:thumb]
13
+ @thumb_type = opts[:thumb_type]
14
+ @thumb_type ||= MediaRss.configuration[:default_thumb_type]
15
+ @thumb_type ||= 'image/jpeg'
16
+ @content = opts[:content]
17
+ @content_type = opts[:content_type]
18
+ end
19
+
20
+ end
21
+
22
+ end
@@ -0,0 +1,13 @@
1
+ module MediaRss
2
+ module Version
3
+
4
+ MAJOR = 0
5
+ MINOR = 0
6
+ TINY = 1
7
+
8
+ def self.to_s # :nodoc:
9
+ [MAJOR, MINOR, TINY].join('.')
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,10 @@
1
+ # http://sneaq.net/textmate-wtf
2
+ $:.reject! { |e| e.include? 'TextMate' }
3
+
4
+ require 'rubygems'
5
+ require 'test/unit'
6
+ require 'matchy'
7
+ require 'context'
8
+ require 'mocha'
9
+
10
+ require File.dirname(__FILE__) + '/../lib/media_rss'
@@ -0,0 +1,13 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class MediaRssTest < Test::Unit::TestCase
4
+
5
+ describe "An instance of the MediaRss class" do
6
+
7
+ it "should flunk" do
8
+ flunk "Please provide some tests"
9
+ end
10
+
11
+ end
12
+
13
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kelredd-media-rss
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kelly Redding
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-06-18 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: nokogiri
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description:
26
+ email: kelly@kelredd.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README.rdoc
33
+ files:
34
+ - README.rdoc
35
+ - Rakefile
36
+ - lib/media_rss
37
+ - lib/media_rss/builder
38
+ - lib/media_rss/builder/base.rb
39
+ - lib/media_rss/builder/channel.rb
40
+ - lib/media_rss/builder/html_header_link.rb
41
+ - lib/media_rss/builder/item.rb
42
+ - lib/media_rss/builder.rb
43
+ - lib/media_rss/models
44
+ - lib/media_rss/models/channel.rb
45
+ - lib/media_rss/models/feed.rb
46
+ - lib/media_rss/models/item.rb
47
+ - lib/media_rss/models.rb
48
+ - lib/media_rss/version.rb
49
+ - lib/media_rss.rb
50
+ - test/test_helper.rb
51
+ - test/unit
52
+ - test/unit/media_rss_test.rb
53
+ has_rdoc: true
54
+ homepage: ""
55
+ post_install_message:
56
+ rdoc_options:
57
+ - --main
58
+ - README.rdoc
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: "0"
66
+ version:
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: "0"
72
+ version:
73
+ requirements: []
74
+
75
+ rubyforge_project:
76
+ rubygems_version: 1.2.0
77
+ signing_key:
78
+ specification_version: 2
79
+ summary: A gem to provide some classes for generating media-rss.
80
+ test_files: []
81
+