mashfeed 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
File without changes
File without changes
@@ -0,0 +1,36 @@
1
+ CHANGELOG.txt
2
+ History.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ bin/mashfeed
7
+ examples/standalone_test.txt
8
+ lib/mashfeed.rb
9
+ lib/mashfeed/context.rb
10
+ lib/mashfeed/dsl.rb
11
+ lib/mashfeed/entry.rb
12
+ lib/mashfeed/plugin.rb
13
+ lib/mashfeed/statement.rb
14
+ lib/mashfeed/version.rb
15
+ plugins/export/feed/init.rb
16
+ plugins/export/lingr/init.rb
17
+ plugins/export/print/init.rb
18
+ plugins/filter/grep/init.rb
19
+ plugins/import/feed/init.rb
20
+ plugins/import/feed/test/data/rss_2.0.xml
21
+ plugins/import/feed/test/feed_test.rb
22
+ plugins/test/data/init.rb
23
+ plugins/test/data/test/data_test.rb
24
+ plugins/test/data/test/test_helper.rb
25
+ plugins/test/output_global_variant/init.rb
26
+ plugins/test/output_global_variant/test/output_global_variant_test.rb
27
+ plugins/test/output_global_variant/test/test_helper.rb
28
+ plugins/test/prefix/init.rb
29
+ plugins/test/prefix/test/prefix_test.rb
30
+ plugins/test/prefix/test/test_helper.rb
31
+ test/context_test.rb
32
+ test/entry_test.rb
33
+ test/mashfeed_test.rb
34
+ test/plugin_base_test.rb
35
+ test/statement_test.rb
36
+ test/test_helper.rb
@@ -0,0 +1,4 @@
1
+ README for mashfeed
2
+ ===================
3
+
4
+ Please check http://mashfeed.com/
@@ -0,0 +1,79 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/clean'
4
+ require 'rake/testtask'
5
+ require 'rake/packagetask'
6
+ require 'rake/gempackagetask'
7
+ require 'rake/rdoctask'
8
+ require 'rake/contrib/rubyforgepublisher'
9
+ require 'active_support'
10
+ require 'fileutils'
11
+ require 'hoe'
12
+ include FileUtils
13
+ require File.join(File.dirname(__FILE__), 'lib', 'mashfeed', 'version')
14
+
15
+ NAME = "mashfeed"
16
+ PKG_VERSION = "0.0.1"
17
+ AUTHOR = "mashfeed developers team"
18
+ EMAIL = "info@mashfeed.com"
19
+ DESCRIPTION = "feed aggregator framework and plugins"
20
+ GEM_NAME = NAME
21
+ RUBYFORGE_PROJECT = NAME
22
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
23
+
24
+ REV = nil # UNCOMMENT IF REQUIRED: File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
25
+ VERS = ENV['VERSION'] || (Mashfeed::VERSION::STRING + (REV ? ".#{REV}" : ""))
26
+ CLEAN.include ['**/.*.sw?', '*.gem', '.config']
27
+ RDOC_OPTS = ['--quiet', '--title', "mashfeed documentation",
28
+ "--opname", "index.html",
29
+ "--line-numbers",
30
+ "--main", "README",
31
+ "--inline-source"]
32
+
33
+ class Hoe
34
+ def extra_deps
35
+ @extra_deps.reject { |x| Array(x).first == 'hoe' }
36
+ end
37
+ end
38
+
39
+ # Generate all the Rake tasks
40
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
41
+ hoe = Hoe.new(GEM_NAME, VERS) do |p|
42
+ p.author = AUTHOR
43
+ p.description = DESCRIPTION
44
+ p.email = EMAIL
45
+ p.summary = DESCRIPTION
46
+ p.url = HOMEPATH
47
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
48
+ p.test_globs = ["test/**/*_test.rb"]
49
+ p.clean_globs = CLEAN #An array of file patterns to delete on clean.
50
+
51
+ p. extra_deps << ['activesupport', '>= 1.3.1']
52
+ p. extra_deps << ['feedtools', '>= 0.2.26']
53
+ # == Optional
54
+ #p.changes - A description of the release's latest changes.
55
+ #p.extra_deps - An array of rubygem dependencies.
56
+ #p.spec_extras - A hash of extra values to set in the gemspec.
57
+ end
58
+
59
+ Rake::TestTask.new('test:core') do |t|
60
+ t.libs << 'test'
61
+ t.pattern = 'test/*_test.rb'
62
+ t.verbose = true
63
+ end
64
+
65
+ Rake::TestTask.new('test:plugins') do |t|
66
+ t.libs << 'test'
67
+ name = ENV['name'] || ENV['TEST']
68
+ t.pattern = name.blank? ? 'plugins/**/test/*_test.rb' : ('plugins/%s/test/*_test.rb' % [Inflector::underscore(name)])
69
+ t.verbose = true
70
+ end
71
+
72
+ task :test do
73
+ Rake::Task['test:plugins'].invoke
74
+ end
75
+
76
+ desc 'Update Manifest.txt'
77
+ task :update_manifest => :clean do
78
+ sh "find . -type f | sed -e 's%./%%' | grep -v \".svn\" | grep -v \".log\" | grep -v \".cache\" | sort > Manifest.txt"
79
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ $:.push 'lib'
3
+ require 'mashfeed'
4
+ require 'optparse'
5
+
6
+ ARGV.options do |opt|
7
+ opt.on('-l PATH', '--log-file=PATH', 'description of -a') {|v| @log_file = v}
8
+ opt.parse!
9
+ end
10
+ Mashfeed::Plugin::Base.logger = Mashfeed::Context::DSL.logger = Logger.new(@log_file || STDOUT)
11
+ (ARGV.empty? ? [nil] : ARGV).each do |recipe_file|
12
+ context = Mashfeed::Context::DSL.new.execute(recipe_file.blank? ? STDIN.read : IO.read(recipe_file))
13
+ context.execute
14
+ end
@@ -0,0 +1,7 @@
1
+ flow do
2
+ plugin 'Test::Data'
3
+ plugin 'Test::Prefix' do
4
+ prefix 'load'
5
+ end
6
+ plugin 'Export::Print'
7
+ end
@@ -0,0 +1,15 @@
1
+ # Copyright (c) 2007 dara, masuidrive
2
+
3
+ require 'rubygems'
4
+ require 'active_support'
5
+ require 'rss/1.0'
6
+ require 'rss/2.0'
7
+ require 'rss/maker'
8
+ require 'logger'
9
+
10
+ require 'mashfeed/version'
11
+ require 'mashfeed/entry'
12
+ require 'mashfeed/plugin'
13
+ require 'mashfeed/statement'
14
+ require 'mashfeed/context'
15
+ require 'mashfeed/dsl'
@@ -0,0 +1,33 @@
1
+ module Mashfeed
2
+ class Context
3
+ attr_reader :statements
4
+
5
+ def initialize(statements=[])
6
+ @statements = statements
7
+ end
8
+
9
+ def execute
10
+ last_num = -1
11
+ while not @statements.empty?
12
+ @statements = @statements.collect{ |statement| execute_statement(statement) }
13
+ @statements.delete(nil)
14
+ raise "Infinity loop!" if last_num==@statements.size
15
+ last_num = @statements.size
16
+ end
17
+ true
18
+ end
19
+
20
+ # execute a statment and pass entries to next statements
21
+ def execute_statement(statement)
22
+ if statement.input_entries.size >= statement.inputs.size
23
+ result = statement.execute
24
+ @statements.each do |next_statement|
25
+ (next_statement.input_entries << result) if next_statement.inputs.include?(statement)
26
+ end
27
+ nil
28
+ else
29
+ statement
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,82 @@
1
+ module Mashfeed
2
+ class Context::DSL
3
+ cattr_accessor :logger
4
+
5
+ def initialize
6
+ end
7
+
8
+ # make statements from recipe
9
+ def execute(recipe)
10
+ @statements, @stack = [], []
11
+ instance_eval(recipe)
12
+ @statements.delete(nil)
13
+ Context.new(@statements.uniq)
14
+ end
15
+
16
+ # block statement super class
17
+ class Block
18
+ attr_accessor :context_dsl, :parent_block, :child_statements
19
+
20
+ def initialize(context_dsl, parent_block, *args)
21
+ @context_dsl, @parent_block, @child_statements = context_dsl, parent_block, []
22
+ end
23
+
24
+ def execute(recipe)
25
+ before_execute(recipe) if respond_to?(:before_execute)
26
+ recipe.call unless recipe.nil?
27
+ statement = self.to_statement
28
+ after_execute(statement) if respond_to?(:after_execute)
29
+ statement
30
+ end
31
+
32
+ def to_statement
33
+ raise "Need override"
34
+ end
35
+ end
36
+
37
+ # make plugin statement
38
+ class PluginBlock < Block
39
+ def initialize(context_dsl, parent_block, name)
40
+ super
41
+ @statement = Statement.new(Mashfeed::Plugin[name.to_s].new)
42
+ end
43
+
44
+ # delegating of @statement
45
+ def method_missing(name, *args)
46
+ @statement.send(name, *args)
47
+ end
48
+
49
+ def to_statement
50
+ @statement
51
+ end
52
+ end
53
+
54
+ # automatic stepping to next statement
55
+ class FlowBlock < Block
56
+ def after_execute(statement)
57
+ input_statements = child_statements.clone
58
+ child_statements[1..-1].each do |statement|
59
+ input_statement = input_statements.shift
60
+ statement.inputs = [input_statement] if statement.inputs.empty? && !input_statement.nil?
61
+ end
62
+ end
63
+
64
+ def to_statement
65
+ @child_statements.last
66
+ end
67
+ end
68
+
69
+ # create block or delegate to block
70
+ def method_missing(name, *args, &recipe)
71
+ block_name = Inflector::camelize(Inflector::underscore(name.to_s))+"Block"
72
+ return @stack.last.send(name, *args) unless self.class.const_defined?(block_name)
73
+ block = self.class.const_get(block_name).new(self, @stack.last, *args)
74
+ @stack.push block
75
+ statement = block.execute(recipe)
76
+ @stack.pop
77
+ @statements << statement
78
+ @stack.last.child_statements << statement unless @stack.last.nil?
79
+ statement
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,23 @@
1
+ module Mashfeed
2
+ class Entry
3
+ def initialize(data=nil)
4
+ @data_ = {}
5
+ return if data.nil?
6
+ if data.is_a?(Hash)
7
+ data.each_pair do |key, value|
8
+ @data_[key.to_s] = value
9
+ end
10
+ else
11
+ [:title, :link, :description, :time, :author, :comments, :guid, :enclosure, :source, :categories].each do |field|
12
+ @data_[field.to_s] = data.send(field) if data.respond_to?(field)
13
+ end
14
+ end
15
+ end
16
+
17
+ def method_missing(name, *argv)
18
+ @data_ ||= {}
19
+ name_ = (/^(.+)=$/.match(name.to_s)).to_a[1]
20
+ name_.nil? ? @data_[name.to_s] : (@data_[name_]=argv.first)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,78 @@
1
+ # Abstract Plugin
2
+ module Mashfeed
3
+ module Plugin
4
+
5
+ class Base
6
+ def self.inheritable_accessor(*syms)
7
+ syms.each do |sym|
8
+ class_eval <<-__EOM__
9
+ def self.#{sym}(#{sym}=nil)
10
+ #{sym}.nil? ? read_inheritable_attribute(:#{sym}) : write_inheritable_attribute(:#{sym}, #{sym})
11
+ end
12
+ def self.#{sym}=(#{sym})
13
+ write_inheritable_attribute(:#{sym}, #{sym})
14
+ end
15
+ __EOM__
16
+ end
17
+ end
18
+ inheritable_accessor :author, :description
19
+ cattr_accessor :logger
20
+
21
+ # set plugin's option
22
+ def self.option(name, options={})
23
+ write_inheritable_attribute(:options, self.options.merge(name.to_s => options))
24
+ class_eval <<-__EOM__
25
+ def #{name}(val=nil); val.nil? ? @params["#{name}"] : @params["#{name}"]=val ;end
26
+ def #{name}=(val); @params["#{name}"] = val;end
27
+ __EOM__
28
+ end
29
+
30
+ # get this plugin options
31
+ def self.options
32
+ read_inheritable_attribute(:options) || {}
33
+ end
34
+
35
+ # preset default options
36
+ def initialize(params={})
37
+ @params = {}
38
+ self.class.options.each_pair{|k, v| @params[k] = v[:default] }
39
+ params.each_pair{|k, v| @params[k.to_s] = v }
40
+ end
41
+
42
+ # need override
43
+ def execute(items=[])
44
+ items
45
+ end
46
+ end
47
+
48
+ # plugin load path
49
+ @@path = File.join(File.dirname(__FILE__), '..', '..', 'plugins')
50
+ mattr_accessor :path
51
+
52
+ # name to plugin class
53
+ def self.[](name)
54
+ eval("::Mashfeed::Plugin::%s" % Inflector::camelize(Inflector::underscore(name)))
55
+ end
56
+
57
+ # plugin automatic loader
58
+ def self.const_missing(name)
59
+ module_eval "module #{name}; extend Loader; end; #{name}"
60
+ end
61
+
62
+ # plugin loader
63
+ module Loader
64
+ def const_missing(name)
65
+ plugin_name = [self.name.gsub(/Mashfeed::Plugin::/,''), name].join('::')
66
+ filename = File.join(Mashfeed::Plugin.path, Inflector::underscore(plugin_name), 'init.rb')
67
+ eval(<<-__EOM__) unless File.exist?(filename)
68
+ module #{self.name}::#{name}
69
+ extend ::Mashfeed::Plugin::Loader
70
+ end
71
+ #{self.name}::#{name}
72
+ __EOM__
73
+ Mashfeed::Plugin.module_eval(File.read(filename), filename)
74
+ eval([self.name,name].join('::'))
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,23 @@
1
+ module Mashfeed
2
+ class Statement
3
+ attr_accessor :inputs, :input_entries
4
+ attr_reader :plugin
5
+
6
+ def initialize(plugin, inputs=[])
7
+ @plugin, @inputs, @input_entries = plugin, inputs, []
8
+ end
9
+
10
+ def input(*statements)
11
+ @inputs += statements
12
+ end
13
+
14
+ def execute(items=nil)
15
+ @plugin.execute(items || self.input_entries.flatten)
16
+ end
17
+
18
+ # unknow methods delegate to @plugin
19
+ def method_missing(name, *args)
20
+ @plugin.send(name, *args)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,9 @@
1
+ module Mashfeed #:nodoc:
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 0
5
+ TINY = 1
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
@@ -0,0 +1,25 @@
1
+ class Export::Feed < Mashfeed::Plugin::Base
2
+ option :title, :default=>""
3
+ option :link, :default=>"http://example.com/"
4
+ option :description, :default=>""
5
+ option :about, :default=>""
6
+ option :filename, :description=>"Path to output file. If omitted, stdout is used.", :default=>nil
7
+ def execute(items)
8
+ rss = RSS::Maker.make("1.0") do |maker|
9
+ maker.channel.title = title
10
+ maker.channel.description = description
11
+ maker.channel.about = about
12
+ maker.channel.link = link
13
+ items.each do |i|
14
+ item = maker.items.new_item
15
+ item.title = i.title rescue i.to_s
16
+ item.link = i.link rescue make.channel.link
17
+ item.description = i.description rescue i.to_s
18
+ item.date = i.time rescue Time.now
19
+ end
20
+ end
21
+
22
+ (filename ? open(filename,"w") : STDOUT).write(rss)
23
+ items
24
+ end
25
+ end
@@ -0,0 +1,83 @@
1
+ require 'json'
2
+ require 'net/http'
3
+ Net::HTTP.version_1_2
4
+
5
+ module LingrLib
6
+ class LingrError < Exception; end
7
+ class Lingr
8
+ def initialize(api_key, room_id, nickname)
9
+ @host = "www.lingr.com"
10
+ @api_key = api_key
11
+ @session = nil
12
+ @ticket = nil
13
+ @counter = nil
14
+ session_create
15
+ room_enter(room_id, nickname)
16
+ end
17
+ def session_create
18
+ response = call("session/create", "api_key"=>@api_key)
19
+ @session = response["session"]
20
+ end
21
+ def session_destroy
22
+ response = call("session/destroy")
23
+ @session = nil
24
+ end
25
+ def room_enter(room_id, nickname)
26
+ response = call("room/enter", "id"=>room_id, "nickname"=>nickname)
27
+ @counter = response["room"]["counter"]
28
+ @ticket = response["ticket"]
29
+ end
30
+ def say(message)
31
+ call "room/say", "ticket"=>@ticket, "message"=>message
32
+ end
33
+ def observe
34
+ begin
35
+ response = call("room/observe",
36
+ "ticket"=>@ticket,
37
+ "counter"=>@counter,
38
+ :get=>true)
39
+ @counter = response["counter"]
40
+ return response
41
+ rescue Timeout::Error
42
+ return nil
43
+ end
44
+ end
45
+
46
+ def call(name, args={})
47
+ uri = "/api/" + name
48
+ query = {"format"=>"json"}
49
+ query["session"] = @session if @session
50
+ query.update(args)
51
+ query_string = query.map{|x|x.join("=")}.join("&")
52
+ res = nil
53
+ Net::HTTP.start(@host) { |http|
54
+ if query.delete(:get)
55
+ res = http.get(uri+"?"+query_string)
56
+ else
57
+ res = http.post(uri, query_string)
58
+ end
59
+ }
60
+ response = JSON.parse(res.body)
61
+
62
+ if response["status"] == "fail"
63
+ raise LingrError.new(response["error"]["message"])
64
+ end
65
+ response
66
+ end
67
+ end
68
+ end
69
+
70
+ class Export::Lingr < Mashfeed::Plugin::Base
71
+ option :apikey, :description=>"lingr API key (obtained from http://www.lingr.com/developers/api)"
72
+ option :room, :description=>"room id"
73
+ option :nickname, :description=>"nickname", :default=>"mashfeed_"+Time.now.to_i.to_s
74
+ def execute(items)
75
+ lingr = LingrLib::Lingr.new(apikey,room,nickname)
76
+ items.each do |item|
77
+ lingr.say item.title rescue item.to_s
78
+ end
79
+ lingr.session_destroy
80
+ items
81
+ end
82
+ end
83
+
@@ -0,0 +1,7 @@
1
+ class Export::Print < Mashfeed::Plugin::Base
2
+ require 'pp'
3
+ def execute(items)
4
+ pp items
5
+ items
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ class Filter::Grep < Mashfeed::Plugin::Base
2
+ option :regexp, :description=>"Regexp pattern", :default=>""
3
+ option :invert, :description=>"Invert selection", :default=>false
4
+ def execute(items)
5
+ re = Regexp.new(regexp)
6
+ items.select {|item|
7
+ invert ? (re !~ item.to_s) : (re =~ item.to_s)
8
+ }
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ require 'feed_tools'
2
+ class Import::Feed < Mashfeed::Plugin::Base
3
+ option :url, :description=>"URL of the RSS source", :default=>nil
4
+ def execute(items)
5
+ feed = FeedTools::Feed.open(url)
6
+ feed.items.sort_by{|x| x.time}.map {|item| Mashfeed::Entry.new(item)}
7
+ end
8
+ end
@@ -0,0 +1,23 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <rss version="2.0">
3
+ <channel>
4
+ <title>www.example.com</title>
5
+ <link>http://www.example.com/</link>
6
+ <description>description</description>
7
+
8
+ <item>
9
+ <title>title 1</title>
10
+ <link>http://www.example.com/article1.html</link>
11
+ <description>description 1</description>
12
+ <pubDate>Sun, 04 Mar 2007 02:26:58 GMT</pubDate>
13
+ </item>
14
+
15
+ <item>
16
+ <title>title 2</title>
17
+ <link>http://www.example.com/article2.html</link>
18
+ <description>description 2</description>
19
+ <pubDate>Sun, 04 Mar 2007 02:26:59 GMT</pubDate>
20
+ </item>
21
+
22
+ </channel>
23
+ </rss>
@@ -0,0 +1,25 @@
1
+ require 'fileutils'
2
+ require 'test/unit'
3
+ require FileUtils.pwd + '/lib/mashfeed'
4
+
5
+ class FeedTest < Test::Unit::TestCase
6
+ def setup
7
+ @plugin = Mashfeed::Plugin::Import::Feed.new
8
+ end
9
+ def test_rss_input
10
+ @plugin.url = "file://"+File.expand_path(File.dirname(__FILE__) + '/data/rss_2.0.xml')
11
+ items = @plugin.execute(@items1)
12
+
13
+ assert_equal(2, items.size)
14
+
15
+ assert_equal("title 1", items[0].title)
16
+ assert_equal("http://www.example.com/article1.html", items[0].link)
17
+ assert_equal("description 1", items[0].description)
18
+ assert_equal(Time.parse('Sun Mar 04 02:26:58 GMT 2007'), items[0].time)
19
+
20
+ assert_equal("title 2", items[1].title)
21
+ assert_equal("http://www.example.com/article2.html", items[1].link)
22
+ assert_equal("description 2", items[1].description)
23
+ assert_equal(Time.parse('Sun Mar 04 02:26:59 GMT 2007'), items[1].time)
24
+ end
25
+ end
@@ -0,0 +1,15 @@
1
+ class Test::Data < Mashfeed::Plugin::Base
2
+ author 'no name'
3
+ description 'no description'
4
+ option :link, :description => 'Item URL', :default => 'no url'
5
+ option :title, :description => 'Item title', :default => 'no title'
6
+ option :description, :description => 'Item description', :default => 'no description'
7
+
8
+ def execute(items)
9
+ item = Mashfeed::Entry.new
10
+ item.link = link
11
+ item.title = title
12
+ item.description = self.description
13
+ (items || []) + [item]
14
+ end
15
+ end
@@ -0,0 +1,41 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class DataTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @data1 = Mashfeed::Plugin::Test::Data.new
7
+ @data2 = Mashfeed::Plugin::Test::Data.new(:title => 'Title', :link => 'Url', :description => 'Description')
8
+ end
9
+
10
+ def test_data1
11
+ items = @data1.execute([])
12
+ assert_equal 1, items.size
13
+ item = items.first
14
+ assert_equal 'no title', item.title
15
+ assert_equal 'no url', item.link
16
+ assert_equal 'no description', item.description
17
+ end
18
+
19
+ def test_data2
20
+ items = @data2.execute([])
21
+ assert_equal 1, items.size
22
+ item = items.first
23
+ assert_equal 'Title', item.title
24
+ assert_equal 'Url', item.link
25
+ assert_equal 'Description', item.description
26
+ end
27
+
28
+ def test_data3
29
+ items = @data2.execute(@data1.execute([]))
30
+ assert_equal 2, items.size
31
+ item = items.first
32
+ assert_equal 'no title', item.title
33
+ assert_equal 'no url', item.link
34
+ assert_equal 'no description', item.description
35
+ item = items.last
36
+ assert_equal 'Title', item.title
37
+ assert_equal 'Url', item.link
38
+ assert_equal 'Description', item.description
39
+ end
40
+
41
+ end
@@ -0,0 +1,4 @@
1
+ require 'fileutils'
2
+ require 'test/unit'
3
+ require FileUtils.pwd + '/lib/mashfeed'
4
+ Mashfeed::Plugin::Base.logger = Logger.new('log/test.log')
@@ -0,0 +1,9 @@
1
+ class Test::OutputGlobalVariant < Mashfeed::Plugin::Base
2
+ author 'no name'
3
+ description 'no description'
4
+
5
+ def execute(items)
6
+ logger.debug "OutputGlobalVariant %d items" % items.size
7
+ $results = items
8
+ end
9
+ end
@@ -0,0 +1,33 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class OutputGlobalVariantTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @items1 = [Mashfeed::Entry.new(:title => 'title', :link => 'url', :description => 'description')]
7
+ @plugin = Mashfeed::Plugin::Test::OutputGlobalVariant.new
8
+ end
9
+
10
+ def test_plugin1
11
+ items = @plugin.execute(@items1)
12
+ assert_equal 1, items.size
13
+ item = items.first
14
+ assert_equal 'title', item.title
15
+ assert_equal 'url', item.link
16
+ assert_equal 'description', item.description
17
+ assert_equal 1, $results.size
18
+ item = $results.first
19
+ assert_equal 'title', item.title
20
+ assert_equal 'url', item.link
21
+ assert_equal 'description', item.description
22
+ end
23
+
24
+ def test_plugin2
25
+ items = @plugin.execute(@items1)
26
+ assert_equal 1, items.size
27
+ assert_equal 1, $results.size
28
+ items = @plugin.execute([])
29
+ assert_equal 0, items.size
30
+ assert_equal 0, $results.size
31
+ end
32
+
33
+ end
@@ -0,0 +1,4 @@
1
+ require 'fileutils'
2
+ require 'test/unit'
3
+ require FileUtils.pwd + '/lib/mashfeed'
4
+ Mashfeed::Plugin::Base.logger = Logger.new('log/test.log')
@@ -0,0 +1,11 @@
1
+ class Test::Prefix < Mashfeed::Plugin::Base
2
+ author 'no name'
3
+ description 'no description'
4
+ option :prefix, :description => "prefix of title", :default => 'TEST'
5
+
6
+ def execute(items)
7
+ items.each do |item|
8
+ item.title = "[%s]%s" % [prefix, (item.title || '')]
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,56 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class PrefixTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @items1 = [Mashfeed::Entry.new(:title => 'title', :link => 'url', :description => 'description')]
7
+ @items2 = [Mashfeed::Entry.new(:title => 'title1', :link => 'url1', :description => 'description1'), Mashfeed::Entry.new(:title => 'title2', :link => 'url2', :description => 'description2')]
8
+ @prefix1 = Mashfeed::Plugin::Test::Prefix.new
9
+ @prefix2 = Mashfeed::Plugin::Test::Prefix.new(:prefix => 'example')
10
+ end
11
+
12
+ def test_prefix1
13
+ items = @prefix1.execute(@items1)
14
+ assert_equal 1, items.size
15
+ item = items.first
16
+ assert_equal '[TEST]title', item.title
17
+ assert_equal 'url', item.link
18
+ assert_equal 'description', item.description
19
+ end
20
+
21
+ def test_prefix2
22
+ items = @prefix1.execute(@items2)
23
+ assert_equal 2, items.size
24
+ item = items.first
25
+ assert_equal '[TEST]title1', item.title
26
+ assert_equal 'url1', item.link
27
+ assert_equal 'description1', item.description
28
+ item = items.last
29
+ assert_equal '[TEST]title2', item.title
30
+ assert_equal 'url2', item.link
31
+ assert_equal 'description2', item.description
32
+ end
33
+
34
+ def test_prefix1
35
+ items = @prefix2.execute(@items1)
36
+ assert_equal 1, items.size
37
+ item = items.first
38
+ assert_equal '[example]title', item.title
39
+ assert_equal 'url', item.link
40
+ assert_equal 'description', item.description
41
+ end
42
+
43
+ def test_prefix4
44
+ items = @prefix2.execute(@items2)
45
+ assert_equal 2, items.size
46
+ item = items.first
47
+ assert_equal '[example]title1', item.title
48
+ assert_equal 'url1', item.link
49
+ assert_equal 'description1', item.description
50
+ item = items.last
51
+ assert_equal '[example]title2', item.title
52
+ assert_equal 'url2', item.link
53
+ assert_equal 'description2', item.description
54
+ end
55
+
56
+ end
@@ -0,0 +1,4 @@
1
+ require 'fileutils'
2
+ require 'test/unit'
3
+ require FileUtils.pwd + '/lib/mashfeed'
4
+ Mashfeed::Plugin::Base.logger = Logger.new('log/test.log')
@@ -0,0 +1,138 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class ContextTest < Test::Unit::TestCase
4
+ def test_load
5
+ recipe = <<-__EOR__
6
+ flow do
7
+ plugin 'Test::Data'
8
+ plugin 'Test::Prefix' do
9
+ prefix 'load'
10
+ end
11
+ plugin 'test/output_global_variant'
12
+ end
13
+ __EOR__
14
+ context = Mashfeed::Context::DSL.new.execute(recipe)
15
+ assert_equal 3, context.statements.size
16
+ context.execute
17
+ assert_equal 1, $results.size
18
+ assert_equal "[load]no title", $results.first.title
19
+ end
20
+
21
+ def test_multi_inputs_using_flow1
22
+ recipe = <<-__EOR__
23
+ flow do
24
+ plugin 'Test::Data' do
25
+ title 'test1'
26
+ end
27
+ plugin 'Test::Data' do
28
+ title 'test2'
29
+ end
30
+ plugin 'test/data' do
31
+ title 'test3'
32
+ end
33
+ plugin 'Test::Prefix' do
34
+ prefix 'load'
35
+ end
36
+ plugin 'test/output_global_variant'
37
+ end
38
+ __EOR__
39
+ context = Mashfeed::Context::DSL.new.execute(recipe)
40
+ assert_equal 5, context.statements.size
41
+ context.execute
42
+ assert_equal 3, $results.size
43
+ assert_equal "[load]test1", $results[0].title
44
+ assert_equal "[load]test2", $results[1].title
45
+ assert_equal "[load]test3", $results[2].title
46
+ end
47
+
48
+ def test_multi_inputs_using_input1
49
+ recipe = <<-__EOR__
50
+ data1 = plugin('Test::Data') do
51
+ title 'test1'
52
+ end
53
+ data2 = plugin('Test::Data') do
54
+ title 'test2'
55
+ end
56
+ data3 = plugin('Test::Data') do
57
+ title 'test3'
58
+ end
59
+ flow do
60
+ plugin 'Test::Prefix' do
61
+ input data1
62
+ input data2
63
+ prefix 'load'
64
+ end
65
+ plugin 'test/output_global_variant'
66
+ end
67
+ __EOR__
68
+ context = Mashfeed::Context::DSL.new.execute(recipe)
69
+ assert_equal 5, context.statements.size
70
+ context.execute
71
+ assert_equal 2, $results.size
72
+ titles = $results.collect { |item| item.title }
73
+ assert titles.include?("[load]test1")
74
+ assert titles.include?("[load]test2")
75
+ end
76
+
77
+ def test_multi_inputs_using_input2
78
+ recipe = <<-__EOR__
79
+ data1 = flow do
80
+ plugin('Test::Data') do
81
+ title 'test1'
82
+ end
83
+ plugin('Test::Data') do
84
+ title 'test2'
85
+ end
86
+ end
87
+ data2 = plugin('Test::Data') do
88
+ title 'test3'
89
+ end
90
+ flow do
91
+ plugin 'Test::Prefix' do
92
+ input data1
93
+ input data2
94
+ prefix 'load'
95
+ end
96
+ plugin 'test/output_global_variant'
97
+ end
98
+ __EOR__
99
+ context = Mashfeed::Context::DSL.new.execute(recipe)
100
+ assert_equal 5, context.statements.size
101
+ context.execute
102
+ assert_equal 3, $results.size
103
+ titles = $results.collect { |item| item.title }
104
+ assert_equal titles[0], "[load]test1"
105
+ assert_equal titles[1], "[load]test2"
106
+ assert_equal titles[2], "[load]test3"
107
+ end
108
+
109
+ def test_multi_inputs_using_flow2
110
+ recipe = <<-__EOR__
111
+ flow do
112
+ flow do
113
+ plugin('Test::Data') do
114
+ title 'test1'
115
+ end
116
+ plugin('Test::Data') do
117
+ title 'test2'
118
+ end
119
+ end
120
+ plugin('Test::Data') do
121
+ title 'test3'
122
+ end
123
+ plugin 'Test::Prefix' do
124
+ prefix 'load'
125
+ end
126
+ plugin 'test/output_global_variant'
127
+ end
128
+ __EOR__
129
+ context = Mashfeed::Context::DSL.new.execute(recipe)
130
+ assert_equal 5, context.statements.size
131
+ context.execute
132
+ assert_equal 3, $results.size
133
+ titles = $results.collect { |item| item.title }
134
+ assert_equal titles[0], "[load]test1"
135
+ assert_equal titles[1], "[load]test2"
136
+ assert_equal titles[2], "[load]test3"
137
+ end
138
+ end
@@ -0,0 +1,26 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class EntryTest < Test::Unit::TestCase
4
+
5
+ def test_rss_entry
6
+ item = RSS::RDF::Item.new
7
+ item.link = "http://example.com/article.html"
8
+ item.title = "Sample Article"
9
+ def item.dummy; "DUMMY"; end
10
+ assert_equal "DUMMY", item.dummy
11
+ entry = Mashfeed::Entry.new(item)
12
+ assert_equal "http://example.com/article.html", entry.link
13
+ assert_equal "Sample Article", entry.title
14
+ assert_nil entry.dummy
15
+ end
16
+
17
+ def test_rss_hash
18
+ item = { :dummy => "DUMMY", :title => "Sample Hash Article", :link => "http://example.com/hash_article.html", :body => "no body" }
19
+ entry = Mashfeed::Entry.new(item)
20
+ assert_equal "http://example.com/hash_article.html", entry.link
21
+ assert_equal "Sample Hash Article", entry.title
22
+ assert_equal "no body", entry.body
23
+ assert_equal "DUMMY", entry.dummy
24
+ end
25
+
26
+ end
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class MashfeedTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def test_truth
9
+ assert true
10
+ end
11
+ end
@@ -0,0 +1,21 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class UnitTest1Plugin < Mashfeed::Plugin::Base
4
+ author 'nobody'
5
+ description 'no message'
6
+ end
7
+
8
+ class PluginBaseTest < Test::Unit::TestCase
9
+
10
+ def setup
11
+ end
12
+
13
+ def test_cattr
14
+ assert_equal 'nobody', UnitTest1Plugin.author
15
+ assert_equal 'no message', UnitTest1Plugin.description
16
+ end
17
+
18
+ def test_truth
19
+ assert true
20
+ end
21
+ end
@@ -0,0 +1,43 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class StatementTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @items = [Mashfeed::Entry.new(:link => "http://example.com/article.html", :title => "Sample Article")]
7
+ end
8
+
9
+ def test_plugin
10
+ assert_kind_of Mashfeed::Plugin::Base, plugin = Mashfeed::Plugin::Test::Prefix.new
11
+ assert_respond_to plugin, :execute
12
+ assert_kind_of Array, result = plugin.execute(@items)
13
+ assert_equal 1, result.length
14
+ assert_equal "[TEST]Sample Article", result.first.title
15
+ end
16
+
17
+ def test_plugin_with_option
18
+ assert_kind_of Mashfeed::Plugin::Base, plugin = Mashfeed::Plugin::Test::Prefix.new
19
+ assert_respond_to plugin, :prefix
20
+ assert_respond_to plugin, :prefix=
21
+ assert_equal 1, Mashfeed::Plugin::Test::Prefix.options.size
22
+ plugin.prefix = 'example'
23
+ assert_kind_of Array, result = plugin.execute(@items)
24
+ assert_equal 1, result.length
25
+ assert_equal "[example]Sample Article", result.first.title
26
+ end
27
+
28
+ def test_point
29
+ point = Mashfeed::Statement.new(Mashfeed::Plugin::Test::Prefix.new)
30
+ assert_kind_of Array, result = point.execute(@items)
31
+ assert_equal "[TEST]Sample Article", result.first.title
32
+ end
33
+
34
+ def test_point_dup
35
+ point2 = Mashfeed::Statement.new(Mashfeed::Plugin::Test::Prefix.new)
36
+ point2.prefix = 'example'
37
+ point1 = Mashfeed::Statement.new(Mashfeed::Plugin::Test::Prefix.new)
38
+ assert_kind_of Array, result = point1.execute(@items)
39
+ assert_kind_of Array, result = point2.execute(result)
40
+ assert_equal "[example][TEST]Sample Article", result.first.title
41
+ end
42
+
43
+ end
@@ -0,0 +1,4 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/mashfeed'
3
+
4
+ Mashfeed::Plugin::Base.logger = Mashfeed::Context::DSL.logger = Logger.new('log/test.log')
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.0
3
+ specification_version: 1
4
+ name: mashfeed
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.0.1
7
+ date: 2007-03-12 00:00:00 +09:00
8
+ summary: feed aggregator framework and plugins
9
+ require_paths:
10
+ - lib
11
+ email: info@mashfeed.com
12
+ homepage: http://mashfeed.rubyforge.org
13
+ rubyforge_project: mashfeed
14
+ description: feed aggregator framework and plugins
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - mashfeed developers team
31
+ files:
32
+ - CHANGELOG.txt
33
+ - History.txt
34
+ - Manifest.txt
35
+ - README.txt
36
+ - Rakefile
37
+ - bin/mashfeed
38
+ - examples/standalone_test.txt
39
+ - lib/mashfeed.rb
40
+ - lib/mashfeed/context.rb
41
+ - lib/mashfeed/dsl.rb
42
+ - lib/mashfeed/entry.rb
43
+ - lib/mashfeed/plugin.rb
44
+ - lib/mashfeed/statement.rb
45
+ - lib/mashfeed/version.rb
46
+ - plugins/export/feed/init.rb
47
+ - plugins/export/lingr/init.rb
48
+ - plugins/export/print/init.rb
49
+ - plugins/filter/grep/init.rb
50
+ - plugins/import/feed/init.rb
51
+ - plugins/import/feed/test/data/rss_2.0.xml
52
+ - plugins/import/feed/test/feed_test.rb
53
+ - plugins/test/data/init.rb
54
+ - plugins/test/data/test/data_test.rb
55
+ - plugins/test/data/test/test_helper.rb
56
+ - plugins/test/output_global_variant/init.rb
57
+ - plugins/test/output_global_variant/test/output_global_variant_test.rb
58
+ - plugins/test/output_global_variant/test/test_helper.rb
59
+ - plugins/test/prefix/init.rb
60
+ - plugins/test/prefix/test/prefix_test.rb
61
+ - plugins/test/prefix/test/test_helper.rb
62
+ - test/context_test.rb
63
+ - test/entry_test.rb
64
+ - test/mashfeed_test.rb
65
+ - test/plugin_base_test.rb
66
+ - test/statement_test.rb
67
+ - test/test_helper.rb
68
+ test_files:
69
+ - test/context_test.rb
70
+ - test/entry_test.rb
71
+ - test/mashfeed_test.rb
72
+ - test/plugin_base_test.rb
73
+ - test/statement_test.rb
74
+ rdoc_options: []
75
+
76
+ extra_rdoc_files: []
77
+
78
+ executables:
79
+ - mashfeed
80
+ extensions: []
81
+
82
+ requirements: []
83
+
84
+ dependencies: []
85
+