yapra 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +12 -0
- data/Manifest.txt +11 -2
- data/PostInstall.txt +0 -7
- data/README.txt +2 -1
- data/bin/yapra +35 -21
- data/fixtures/config/habu_like.yml +43 -0
- data/fixtures/config/mixed_type.yml +18 -0
- data/fixtures/config/pragger_like.yml +12 -0
- data/fixtures/legacy_plugin/legacy_test_plugin.rb +4 -0
- data/lib/yapra/config.rb +5 -3
- data/lib/yapra/legacy_plugin/advance_mode_registry.rb +14 -3
- data/lib/yapra/legacy_plugin/base.rb +1 -0
- data/lib/yapra/legacy_plugin/compatible_mode_registry.rb +12 -2
- data/lib/yapra/legacy_plugin/registry_factory.rb +7 -0
- data/lib/yapra/pipeline.rb +21 -0
- data/lib/yapra/plugin/base.rb +4 -0
- data/lib/yapra/plugin/erb_applier.rb +1 -1
- data/lib/yapra/plugin/mechanize_base.rb +4 -4
- data/lib/yapra/runtime.rb +16 -0
- data/lib/yapra/version.rb +1 -1
- data/lib/yapra.rb +2 -0
- data/lib-plugins/yapra/plugin/config/agent.rb +13 -13
- data/lib-plugins/yapra/plugin/config/basic_auth.rb +9 -9
- data/lib-plugins/yapra/plugin/config/web_post.rb +11 -11
- data/lib-plugins/yapra/plugin/feed/custom.rb +17 -12
- data/lib-plugins/yapra/plugin/feed/load.rb +10 -0
- data/lib-plugins/yapra/plugin/filter/apply_template.rb +52 -0
- data/lib-plugins/yapra/plugin/filter/entry_full_text.rb +16 -16
- data/lib-plugins/yapra/plugin/publish/file_download.rb +28 -77
- data/lib-plugins/yapra/plugin/publish/gmail.rb +16 -16
- data/lib-plugins/yapra/plugin/publish/imap.rb +88 -34
- data/lib-plugins/yapra/plugin/publish/on_memory_download.rb +86 -0
- data/lib-plugins/yapra/plugin/test/append_entry.rb +11 -11
- data/plugins/Filter/grep.rb +24 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/yapra/config_spec.rb +72 -0
- data/spec/yapra/legacy_plugin/base_spec.rb +33 -0
- data/spec/yapra/legacy_plugin/registry_factory_spec.rb +19 -0
- data/spec/yapra_spec.rb +7 -3
- data/website/index.txt +3 -3
- metadata +15 -13
- data/website/index.html +0 -115
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'yapra/plugin/base'
|
2
|
+
|
3
|
+
module Yapra::Plugin::Filter
|
4
|
+
# = Filter::ApplyTemplate -- Yuanying
|
5
|
+
#
|
6
|
+
# apply template and set to attribute.
|
7
|
+
#
|
8
|
+
# example:
|
9
|
+
#
|
10
|
+
# - module: Filter::ApplyTemplate
|
11
|
+
# config:
|
12
|
+
# content_encoded: '<div><%= title %></div>'
|
13
|
+
#
|
14
|
+
class ApplyTemplate < Yapra::Plugin::Base
|
15
|
+
def run(data)
|
16
|
+
regexp = nil
|
17
|
+
if config['regexp']
|
18
|
+
regexp = Regexp.new(config['regexp'])
|
19
|
+
else
|
20
|
+
regexp = /^(https?|ftp)(:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)$/
|
21
|
+
end
|
22
|
+
|
23
|
+
data.map! do |item|
|
24
|
+
url = item
|
25
|
+
if item.respond_to?('link')
|
26
|
+
url = item.link
|
27
|
+
end
|
28
|
+
|
29
|
+
if regexp =~ url
|
30
|
+
unless(item.instance_of?(RSS::RDF::Item))
|
31
|
+
new_item = RSS::RDF::Item.new
|
32
|
+
new_item.title = item.title rescue item.to_s
|
33
|
+
new_item.date = item.date rescue Time.now
|
34
|
+
new_item.description = item.description rescue item.to_s
|
35
|
+
new_item.link = item.link rescue '#'
|
36
|
+
item = new_item
|
37
|
+
end
|
38
|
+
|
39
|
+
if plugin_config
|
40
|
+
plugin_config.each do |k, template|
|
41
|
+
value = apply_template template, binding
|
42
|
+
set_attribute_to item, k, value
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
item
|
47
|
+
end
|
48
|
+
|
49
|
+
data
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -1,21 +1,21 @@
|
|
1
|
-
## Filter::EntryFullText -- Yuanying
|
2
|
-
##
|
3
|
-
## get the entry full text from page with WWW::Mechanize.
|
4
|
-
##
|
5
|
-
## - module: Filter::EntryFullText
|
6
|
-
## config:
|
7
|
-
## regexp: http://www\.pixiv\.net/*
|
8
|
-
## extract_xpath:
|
9
|
-
## title: '//title/text()'
|
10
|
-
## dc_creator: "//div[@id='profile']/div/text()"
|
11
|
-
## author: "//div[@id='profile']/div/text()"
|
12
|
-
## description: "//div[@id='content2']"
|
13
|
-
## apply_template_after_extracted:
|
14
|
-
## content_encoded: '<div><%= title %></div>'
|
15
|
-
##
|
16
1
|
require 'yapra/plugin/mechanize_base'
|
17
2
|
|
18
3
|
module Yapra::Plugin::Filter
|
4
|
+
# Filter::EntryFullText -- Yuanying
|
5
|
+
#
|
6
|
+
# get the entry full text from page with WWW::Mechanize.
|
7
|
+
#
|
8
|
+
# - module: Filter::EntryFullText
|
9
|
+
# config:
|
10
|
+
# regexp: http://www\.pixiv\.net/*
|
11
|
+
# extract_xpath:
|
12
|
+
# title: '//title/text()'
|
13
|
+
# dc_creator: "//div[@id='profile']/div/text()"
|
14
|
+
# author: "//div[@id='profile']/div/text()"
|
15
|
+
# description: "//div[@id='content2']"
|
16
|
+
# apply_template_after_extracted:
|
17
|
+
# content_encoded: '<div><%= title %></div>'
|
18
|
+
|
19
19
|
class EntryFullText < Yapra::Plugin::MechanizeBase
|
20
20
|
def run(data)
|
21
21
|
regexp = nil
|
@@ -34,9 +34,9 @@ module Yapra::Plugin::Filter
|
|
34
34
|
end
|
35
35
|
|
36
36
|
if regexp =~ url
|
37
|
+
logger.debug "Process: #{url}"
|
37
38
|
page = agent.get(url)
|
38
39
|
sleep wait
|
39
|
-
logger.info "Process: #{url}"
|
40
40
|
|
41
41
|
unless(item.instance_of?(RSS::RDF::Item))
|
42
42
|
new_item = RSS::RDF::Item.new
|
@@ -1,72 +1,34 @@
|
|
1
|
-
|
2
|
-
##
|
3
|
-
## download file with WWW::Mechanize.
|
4
|
-
##
|
5
|
-
## example:
|
6
|
-
##
|
7
|
-
## - module: Publish::FileDownload
|
8
|
-
## config:
|
9
|
-
## regexp: http://www\.yahoo\.co\.jp/*
|
10
|
-
## dir: '/Users/yuanying/Downloads/'
|
11
|
-
## auto_suffix: true
|
12
|
-
## before_hook: "agent.get('http://www.yahoo.co.jp/'); sleep 1"
|
13
|
-
## url:
|
14
|
-
## attribute: link
|
15
|
-
## replace: index(\d*?)\.html
|
16
|
-
## to: file\1.zip
|
17
|
-
## filename:
|
18
|
-
## attribute: title
|
19
|
-
## replace: 'Yahoo'
|
20
|
-
## to: ''
|
21
|
-
## referrer:
|
22
|
-
## attribute: link
|
23
|
-
## replace: 'zip'
|
24
|
-
## to: 'html'
|
25
|
-
##
|
26
|
-
require 'yapra/plugin/mechanize_base'
|
1
|
+
require 'yapra/plugin/publish/on_memory_download'
|
27
2
|
|
28
3
|
module Yapra::Plugin::Publish
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
4
|
+
# = Publish::FileDownload -- Yuanying
|
5
|
+
#
|
6
|
+
# download file with WWW::Mechanize.
|
7
|
+
#
|
8
|
+
# example:
|
9
|
+
#
|
10
|
+
# - module: Publish::FileDownload
|
11
|
+
# config:
|
12
|
+
# regexp: http://www\.yahoo\.co\.jp/*
|
13
|
+
# dir: '/Users/yuanying/Downloads/'
|
14
|
+
# auto_suffix: true
|
15
|
+
# before_hook: "agent.get('http://www.yahoo.co.jp/'); sleep 1"
|
16
|
+
# url:
|
17
|
+
# attribute: link
|
18
|
+
# replace: index(\d*?)\.html
|
19
|
+
# to: file\1.zip
|
20
|
+
# filename:
|
21
|
+
# attribute: title
|
22
|
+
# replace: 'Yahoo'
|
23
|
+
# to: ''
|
24
|
+
# referrer:
|
25
|
+
# attribute: link
|
26
|
+
# replace: 'zip'
|
27
|
+
# to: 'html'
|
28
|
+
#
|
29
|
+
class FileDownload < Yapra::Plugin::Publish::OnMemoryDownload
|
52
30
|
|
53
31
|
protected
|
54
|
-
def construct_data(config, item, original=nil)
|
55
|
-
if config && config['attribute']
|
56
|
-
if item.respond_to?(config['attribute'])
|
57
|
-
original = item.__send__(config['attribute'])
|
58
|
-
end
|
59
|
-
elsif config
|
60
|
-
original = item
|
61
|
-
end
|
62
|
-
|
63
|
-
if original && config && config['replace']
|
64
|
-
original = original.gsub(config['replace'], config['to'] || Time.now.to_s)
|
65
|
-
end
|
66
|
-
|
67
|
-
original
|
68
|
-
end
|
69
|
-
|
70
32
|
def discover_extensions page
|
71
33
|
require 'mime/types'
|
72
34
|
types = MIME::Types[page.content_type]
|
@@ -80,19 +42,8 @@ module Yapra::Plugin::Publish
|
|
80
42
|
logger.warn 'require mime-types is failed.'
|
81
43
|
end
|
82
44
|
|
83
|
-
def
|
84
|
-
dir = config['dir']
|
45
|
+
def save config, item, page
|
85
46
|
filename = construct_data(config['filename'], item)
|
86
|
-
|
87
|
-
if config['before_hook']
|
88
|
-
eval(config['before_hook'])
|
89
|
-
end
|
90
|
-
page = agent.get(url, referrer)
|
91
|
-
logger.info "Download: #{url}"
|
92
|
-
if config['after_hook']
|
93
|
-
eval(config['after_hook'])
|
94
|
-
end
|
95
|
-
|
96
47
|
filename = page.filename unless filename
|
97
48
|
|
98
49
|
if config['auto_suffix']
|
@@ -1,23 +1,23 @@
|
|
1
|
-
# module: Publish::Gmail -- Yuanying
|
2
|
-
#
|
3
|
-
# publish entry to imap mail.
|
4
|
-
#
|
5
|
-
# example:
|
6
|
-
#
|
7
|
-
# - module: Publish::Gmail
|
8
|
-
# config:
|
9
|
-
# username: username
|
10
|
-
# password: password
|
11
|
-
# wait: 1
|
12
|
-
# mail:
|
13
|
-
# subject_prefix: '[Yapra]'
|
14
|
-
# from: 'test@example.com'
|
15
|
-
# to: 'test2@example.com'
|
16
|
-
#
|
17
1
|
require 'net/imap'
|
18
2
|
require 'yapra/plugin/publish/imap'
|
19
3
|
|
20
4
|
module Yapra::Plugin::Publish
|
5
|
+
# = module: Publish::Gmail -- Yuanying
|
6
|
+
#
|
7
|
+
# publish entry to imap mail.
|
8
|
+
#
|
9
|
+
# example:
|
10
|
+
#
|
11
|
+
# - module: Publish::Gmail
|
12
|
+
# config:
|
13
|
+
# username: username
|
14
|
+
# password: password
|
15
|
+
# wait: 1
|
16
|
+
# mail:
|
17
|
+
# subject_prefix: '[Yapra]'
|
18
|
+
# from: 'test@example.com'
|
19
|
+
# to: 'test2@example.com'
|
20
|
+
#
|
21
21
|
class Gmail < Yapra::Plugin::Publish::Imap
|
22
22
|
protected
|
23
23
|
def create_imap server, port, usessl
|
@@ -1,26 +1,28 @@
|
|
1
|
-
# module: Publish::Imap -- Yuanying
|
2
|
-
#
|
3
|
-
# publish entry to imap mail.
|
4
|
-
#
|
5
|
-
# example:
|
6
|
-
#
|
7
|
-
# - module: Publish::Imap
|
8
|
-
# config:
|
9
|
-
# username: username
|
10
|
-
# password: password
|
11
|
-
# imap_server: imap.gmail.com
|
12
|
-
# port: 993
|
13
|
-
# ssl: on
|
14
|
-
# wait: 1
|
15
|
-
# mail:
|
16
|
-
# subject_prefix: '[Yapra]'
|
17
|
-
# from: 'test@example.com'
|
18
|
-
# to: 'test2@example.com'
|
19
|
-
#
|
20
1
|
require 'net/imap'
|
2
|
+
require 'yapra/version'
|
21
3
|
require 'yapra/plugin/base'
|
22
4
|
|
23
5
|
module Yapra::Plugin::Publish
|
6
|
+
# = module: Publish::Imap -- Yuanying
|
7
|
+
#
|
8
|
+
# publish entry to imap mail.
|
9
|
+
#
|
10
|
+
# example:
|
11
|
+
#
|
12
|
+
# - module: Publish::Imap
|
13
|
+
# config:
|
14
|
+
# username: username
|
15
|
+
# password: password
|
16
|
+
# imap_server: imap.gmail.com
|
17
|
+
# port: 993
|
18
|
+
# ssl: on
|
19
|
+
# wait: 1
|
20
|
+
# mail:
|
21
|
+
# subject_prefix: '[Yapra]'
|
22
|
+
# from_template: <%=item.author%> <test@example.com>
|
23
|
+
# #from: 'test@example.com'
|
24
|
+
# to: 'test2@example.com'
|
25
|
+
#
|
24
26
|
class Imap < Yapra::Plugin::Base
|
25
27
|
def run(data)
|
26
28
|
username = config['username']
|
@@ -39,26 +41,28 @@ module Yapra::Plugin::Publish
|
|
39
41
|
to = config['mail']['to'] || 'me@localhost'
|
40
42
|
|
41
43
|
imap = create_imap server, port, usessl
|
42
|
-
logger.
|
44
|
+
logger.debug(imap.greeting)
|
43
45
|
|
44
46
|
imap.login(username, password)
|
47
|
+
logger.info('imap login was succeed.')
|
45
48
|
imap.examine(mailbox)
|
46
49
|
data.each do |item|
|
47
50
|
date = item.date || item.dc_date || Time.now
|
48
51
|
content = item.content_encoded || item.description || 'from Yapra.'
|
49
52
|
content = [content].pack('m')
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
53
|
+
if config['mail']['from_template']
|
54
|
+
from = apply_template(config['mail']['from_template'], binding)
|
55
|
+
end
|
56
|
+
if config['mail']['to_template']
|
57
|
+
to = apply_template(config['mail']['to_template'], binding)
|
58
|
+
end
|
59
|
+
subject = (subject_prefix + item.title).gsub(/\n/, '').chomp
|
60
|
+
logger.debug("try append item: #{subject}")
|
61
|
+
boundary = "----_____====#{Time.now.to_i}--BOUDARY"
|
62
|
+
attachments = create_attachments(item, config)
|
63
|
+
imap.append(mailbox, apply_template(mail_template, binding), nil, date)
|
64
|
+
# puts apply_template(mail_template, binding)
|
59
65
|
|
60
|
-
#{content}
|
61
|
-
EOF
|
62
66
|
sleep wait
|
63
67
|
end
|
64
68
|
imap.disconnect
|
@@ -71,12 +75,62 @@ EOF
|
|
71
75
|
logger.debug("server: #{server}:#{port}, usessl = #{usessl}")
|
72
76
|
Net::IMAP.new(server, port, usessl)
|
73
77
|
end
|
78
|
+
|
74
79
|
def encode_field field
|
75
|
-
|
76
|
-
|
80
|
+
field.gsub(/[^\x01-\x7f]*/) {|x|
|
81
|
+
x.scan(/.{1,10}/).map {|y|
|
77
82
|
"=?UTF-8?B?" + y.to_a.pack('m').chomp + "?="
|
78
83
|
}.join("\n ")
|
79
|
-
|
84
|
+
}
|
85
|
+
end
|
86
|
+
|
87
|
+
def create_attachments item, config
|
88
|
+
attachments = []
|
89
|
+
attachment_attributes = config['mail']['attachments']
|
90
|
+
if attachment_attributes.kind_of?(String)
|
91
|
+
file = item.__send__(attachment_attributes)
|
92
|
+
attachments << file if file.kind_of?(WWW::Mechanize::File)
|
93
|
+
elsif attachment_attributes.kind_of?(Array)
|
94
|
+
attachment_attributes.each do |atc|
|
95
|
+
file = item.__send__(atc)
|
96
|
+
attachments << file if file.kind_of?(WWW::Mechanize::File)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
attachments
|
100
|
+
end
|
101
|
+
|
102
|
+
def mail_template
|
103
|
+
return <<EOT
|
104
|
+
From: <%=encode_field(from) %>
|
105
|
+
To: <%=encode_field(to) %>
|
106
|
+
Date: <%=date.rfc2822 %>
|
107
|
+
MIME-Version: 1.0
|
108
|
+
X-Mailer: Yapra <%=Yapra::VERSION::STRING %>
|
109
|
+
Subject: <%=encode_field(subject) %>
|
110
|
+
Content-Type: multipart/mixed; boundary="<%=boundary -%>"
|
111
|
+
|
112
|
+
This is a multi-part message in MIME format.
|
113
|
+
|
114
|
+
--<%=boundary %>
|
115
|
+
Content-type: text/html; charset=UTF-8
|
116
|
+
Content-transfer-encoding: base64
|
117
|
+
|
118
|
+
<%=content %>
|
119
|
+
|
120
|
+
--<%=boundary %>
|
121
|
+
<% attachments.each do |file| -%>
|
122
|
+
Content-Type: <%=file.header['Content-Type'] %>;
|
123
|
+
name="<%=encode_field(file.filename) %>"
|
124
|
+
Content-Disposition: attachment;
|
125
|
+
filename="<%=encode_field(file.filename) %>"
|
126
|
+
Content-Transfer-Encoding: base64
|
127
|
+
|
128
|
+
<%=[file.body].pack('m') -%>
|
129
|
+
|
130
|
+
--<%=boundary %>
|
131
|
+
|
132
|
+
<% end -%>
|
133
|
+
EOT
|
80
134
|
end
|
81
135
|
end
|
82
136
|
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'yapra/plugin/mechanize_base'
|
2
|
+
|
3
|
+
module Yapra::Plugin::Publish
|
4
|
+
# = Publish::OnMemoryDownload -- Yuanying
|
5
|
+
#
|
6
|
+
# download web resource and set to item attribute.
|
7
|
+
#
|
8
|
+
# example:
|
9
|
+
#
|
10
|
+
# - module: Publish::OnMemoryDownload
|
11
|
+
# config:
|
12
|
+
# regexp: http://www\.yahoo\.co\.jp/*
|
13
|
+
# attribute: binary_image
|
14
|
+
# before_hook: "agent.get('http://www.yahoo.co.jp/'); sleep 1"
|
15
|
+
# url:
|
16
|
+
# attribute: link
|
17
|
+
# replace: index(\d*?)\.html
|
18
|
+
# to: file\1.zip
|
19
|
+
# referrer:
|
20
|
+
# attribute: link
|
21
|
+
# replace: 'zip'
|
22
|
+
# to: 'html'
|
23
|
+
#
|
24
|
+
class OnMemoryDownload < Yapra::Plugin::MechanizeBase
|
25
|
+
def run(data)
|
26
|
+
regexp = nil
|
27
|
+
if config['regexp']
|
28
|
+
regexp = Regexp.new(config['regexp'])
|
29
|
+
else
|
30
|
+
regexp = /^(https?|ftp)(:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)$/
|
31
|
+
end
|
32
|
+
|
33
|
+
wait = config['wait'] || 3
|
34
|
+
|
35
|
+
data.each do |item|
|
36
|
+
url = construct_data(config['url'], item, item.respond_to?('link') ? item.link : item)
|
37
|
+
|
38
|
+
if regexp =~ url
|
39
|
+
logger.debug "Download start: #{url}"
|
40
|
+
referrer = construct_data(config['referrer'], item)
|
41
|
+
download(item, url, referrer)
|
42
|
+
sleep wait
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
data
|
47
|
+
end
|
48
|
+
|
49
|
+
protected
|
50
|
+
def construct_data(config, item, original=nil)
|
51
|
+
if config && config['attribute']
|
52
|
+
if item.respond_to?(config['attribute'])
|
53
|
+
original = item.__send__(config['attribute'])
|
54
|
+
end
|
55
|
+
elsif config
|
56
|
+
original = item
|
57
|
+
end
|
58
|
+
|
59
|
+
if original && config && config['replace']
|
60
|
+
original = original.gsub(config['replace'], config['to'] || Time.now.to_s)
|
61
|
+
end
|
62
|
+
|
63
|
+
original
|
64
|
+
end
|
65
|
+
|
66
|
+
def save config, item, page
|
67
|
+
set_attribute_to item, config['attribute'], page
|
68
|
+
end
|
69
|
+
|
70
|
+
def download(item, url, referrer)
|
71
|
+
if config['before_hook']
|
72
|
+
eval(config['before_hook'])
|
73
|
+
end
|
74
|
+
|
75
|
+
dir = config['dir']
|
76
|
+
|
77
|
+
page = agent.get(url, referrer)
|
78
|
+
|
79
|
+
save(config, item, page)
|
80
|
+
|
81
|
+
if config['after_hook']
|
82
|
+
eval(config['after_hook'])
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -1,17 +1,17 @@
|
|
1
|
-
# module: Test::AppendEntry -- Yuanying
|
2
|
-
#
|
3
|
-
# append entry to data array.
|
4
|
-
#
|
5
|
-
# example:
|
6
|
-
#
|
7
|
-
# - module: Test::AppendEntry
|
8
|
-
# config:
|
9
|
-
# title: 'title'
|
10
|
-
# description: 'description.'
|
11
|
-
#
|
12
1
|
require 'yapra/plugin/base'
|
13
2
|
|
14
3
|
module Yapra::Plugin::Test
|
4
|
+
# module: Test::AppendEntry -- Yuanying
|
5
|
+
#
|
6
|
+
# append entry to data array.
|
7
|
+
#
|
8
|
+
# example:
|
9
|
+
#
|
10
|
+
# - module: Test::AppendEntry
|
11
|
+
# config:
|
12
|
+
# title: 'title'
|
13
|
+
# description: 'description.'
|
14
|
+
|
15
15
|
class AppendEntry < Yapra::Plugin::Base
|
16
16
|
def run(data)
|
17
17
|
item = RSS::RDF::Item.new
|
@@ -0,0 +1,24 @@
|
|
1
|
+
## Filter input by given regular expression -- IKeJI
|
2
|
+
##
|
3
|
+
## Filter input by given regular expression.
|
4
|
+
## The test will be done with the result of to_s method of the input.
|
5
|
+
## invert option will invert results(-v option of UNIX grep command).
|
6
|
+
##
|
7
|
+
## - module: grep
|
8
|
+
## config:
|
9
|
+
## regex: "[あ-ん]"
|
10
|
+
## invert: false
|
11
|
+
|
12
|
+
def grep(config,data)
|
13
|
+
regex = Regexp.new(config["regex"])
|
14
|
+
invert = config["invert"] || false
|
15
|
+
attribute = config['attribute']
|
16
|
+
|
17
|
+
data.select do |i|
|
18
|
+
if attribute
|
19
|
+
invert ^ (regex =~ i.__send__(attribute).to_s)
|
20
|
+
else
|
21
|
+
invert ^ (regex =~ i.to_s)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,72 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
require 'yapra/config'
|
5
|
+
|
6
|
+
describe Yapra::Config do
|
7
|
+
|
8
|
+
it 'should create logger from env setting' do
|
9
|
+
config = Yapra::Config.new(YAML.load_file(File.join($fixture_dir, 'config', 'pragger_like.yml')))
|
10
|
+
config.env.update({
|
11
|
+
'log' => {
|
12
|
+
'out' => 'stderr',
|
13
|
+
'level' => 'debug'
|
14
|
+
}
|
15
|
+
})
|
16
|
+
logger = config.create_logger
|
17
|
+
logger.should be_debug
|
18
|
+
end
|
19
|
+
|
20
|
+
describe 'which is initialized by pragger like config file' do
|
21
|
+
before do
|
22
|
+
@config = Yapra::Config.new(YAML.load_file(File.join($fixture_dir, 'config', 'pragger_like.yml')))
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should have empty env.' do
|
26
|
+
@config.env.should == {}
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should have one pipeline command which is named "default".' do
|
30
|
+
@config.should have(1).pipeline_commands
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should have pipeline command named "default"' do
|
34
|
+
@config.pipeline_commands.should have_key('default')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'which is initialized by python habu like config file' do
|
39
|
+
before do
|
40
|
+
@habu_like_file = YAML.load_file(File.join($fixture_dir, 'config', 'habu_like.yml'))
|
41
|
+
@config = Yapra::Config.new(@habu_like_file)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should have env hash from habu_like_config_file "global" section.' do
|
45
|
+
@config.env.should == @habu_like_file['global']
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should have pipeline_commands from habu_like_config_file "pipeline" section.' do
|
49
|
+
@config.pipeline_commands.should == @habu_like_file['pipeline']
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe 'which is initialized by mixed type config file' do
|
54
|
+
before do
|
55
|
+
@mixed_type_file = YAML.load_file(File.join($fixture_dir, 'config', 'mixed_type.yml'))
|
56
|
+
@config = Yapra::Config.new(@mixed_type_file)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should have env hash from mixed_type "global" section.' do
|
60
|
+
@config.env.should == @mixed_type_file['global']
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should have one pipeline command which is named "default".' do
|
64
|
+
@config.should have(1).pipeline_commands
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should have pipeline command named "default"' do
|
68
|
+
@config.pipeline_commands.should have_key('default')
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper.rb'
|
2
|
+
|
3
|
+
require 'yapra/legacy_plugin/base'
|
4
|
+
|
5
|
+
describe Yapra::LegacyPlugin::Base do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@pipeline = mock('pipeline', :null_object => true)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'which is initialized by "fixtures/legacy_test_plugin.rb"' do
|
12
|
+
before do
|
13
|
+
@path = File.join($fixture_dir, 'legacy_plugin', 'legacy_test_plugin.rb')
|
14
|
+
@plugin = Yapra::LegacyPlugin::Base.new(@pipeline, @path)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should have _yapra_run_method named "legacy_test_plugin".' do
|
18
|
+
@plugin._yapra_run_method.should == 'legacy_test_plugin'
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should have plugin source.' do
|
22
|
+
@plugin.source.should == File.read(@path)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should recieve message "legacy_test_plugin" when _yapra_run_as_legacy_plugin is called.' do
|
26
|
+
config = mock('config')
|
27
|
+
data = []
|
28
|
+
@plugin.stub!(:legacy_test_plugin).and_return(:default_value)
|
29
|
+
@plugin.should_receive(:legacy_test_plugin).with(config, data)
|
30
|
+
@plugin._yapra_run_as_legacy_plugin(config, data)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper.rb'
|
2
|
+
|
3
|
+
require 'yapra/legacy_plugin/registry_factory'
|
4
|
+
|
5
|
+
describe Yapra::LegacyPlugin::RegistryFactory do
|
6
|
+
before do
|
7
|
+
@pipeline = mock('pipeline', :null_object => true)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should create advance mode registry from string "advance"' do
|
11
|
+
factory = Yapra::LegacyPlugin::RegistryFactory.new([], 'advance')
|
12
|
+
factory.create(@pipeline).class.should == Yapra::LegacyPlugin::AdvanceModeRegistry
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should create compatible mode registry from string "compatible"' do
|
16
|
+
factory = Yapra::LegacyPlugin::RegistryFactory.new([], 'compatible')
|
17
|
+
factory.create(@pipeline).class.should == Yapra::LegacyPlugin::CompatibleModeRegistry
|
18
|
+
end
|
19
|
+
end
|