bwkfanboy 1.1.4 → 1.2.5
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/bin/bwkfanboy +32 -0
- data/doc/NEWS.rdoc +6 -0
- data/doc/plugin.rdoc +4 -0
- data/lib/bwkfanboy/plugin_skeleton.erb +30 -0
- data/lib/bwkfanboy/plugins/quora.js +2 -0
- data/lib/bwkfanboy/plugins/quora.rb +1 -1
- data/lib/bwkfanboy/utils.rb +1 -1
- data/test/semis/quora.html +12 -8
- data/test/test_server.rb +2 -1
- metadata +5 -4
data/bin/bwkfanboy
CHANGED
@@ -18,6 +18,8 @@ require_relative '../lib/bwkfanboy/parser'
|
|
18
18
|
|
19
19
|
$conf = {
|
20
20
|
mode: 'fast',
|
21
|
+
skeleton_name: 'bwkfanboy_plugin_skeleton.rb',
|
22
|
+
skeleton: Bwkfanboy::Utils.gem_dir_system() + '/plugin_skeleton.erb',
|
21
23
|
debug: false,
|
22
24
|
banner: "Usage: #{File.basename($0)} [options] plugin-name"
|
23
25
|
}
|
@@ -88,6 +90,10 @@ o = Bwkfanboy::Utils.cl_parse(ARGV, $conf[:banner]) # create OptionParser object
|
|
88
90
|
o.on('-i', 'Show some info about the plugin') { |i| $conf[:mode] = 'info' }
|
89
91
|
o.on('-l', 'List all plugins') { |i| $conf[:mode] = 'list' }
|
90
92
|
o.on('-p', 'List all plugins paths') { |i| $conf[:mode] = 'path' }
|
93
|
+
o.on('-t FILE', 'Write to the FILE a skeleton for a plugin') { |i|
|
94
|
+
$conf[:mode] = 'template'
|
95
|
+
$conf[:skeleton_name] = i if i !~ /^\s*$/
|
96
|
+
}
|
91
97
|
o.on('-O', '(ignore this) Execute all bwkfanboy_* utils in a pipe') { |i| $conf[:mode] = 'pipe' }
|
92
98
|
o.on('-D', '(ignore this) Use URI_DEBUG const instead URI in plugins') { |i| $conf[:debug] = true }
|
93
99
|
Bwkfanboy::Utils.cl_parse(ARGV, $conf[:banner], o) # run cl parser
|
@@ -96,6 +102,32 @@ plugin = Plugin.new(ARGV[0])
|
|
96
102
|
opt = Bwkfanboy::Utils.plugin_opts(ARGV)
|
97
103
|
|
98
104
|
case $conf[:mode]
|
105
|
+
when 'template'
|
106
|
+
require 'erb'
|
107
|
+
require 'digest/md5'
|
108
|
+
|
109
|
+
t = ERB.new(File.read($conf[:skeleton]))
|
110
|
+
t.filename = $conf[:skeleton] # to report errors relative to this file
|
111
|
+
begin
|
112
|
+
md5_system = Digest::MD5.hexdigest(t.result(binding))
|
113
|
+
rescue Exception
|
114
|
+
Bwkfanboy::Utils.errx(1, "cannot read the template: #{$!}")
|
115
|
+
end
|
116
|
+
|
117
|
+
if ! File.exists?($conf[:skeleton_name])
|
118
|
+
# write a skeleton
|
119
|
+
begin
|
120
|
+
File.open($conf[:skeleton_name], 'w+') { |fp| fp.puts t.result(binding) }
|
121
|
+
rescue
|
122
|
+
Bwkfanboy::Utils.errx(1, "cannot write the skeleton: #{$!}")
|
123
|
+
end
|
124
|
+
elsif
|
125
|
+
# warn a careless user
|
126
|
+
if md5_system != Digest::MD5.file($conf[:skeleton_name]).hexdigest
|
127
|
+
Bwkfanboy::Utils.errx(1, "#{$conf[:skeleton_name]} already exists")
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
99
131
|
when 'list'
|
100
132
|
plugin.dirs().each {|i|
|
101
133
|
puts "#{i}:"
|
data/doc/NEWS.rdoc
CHANGED
data/doc/plugin.rdoc
CHANGED
@@ -38,6 +38,10 @@ Here is a skeleton of a plugin:
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
+
You can get the skeleton in the current directory by typing:
|
42
|
+
|
43
|
+
% bwkfanboy -t myplugin.rb
|
44
|
+
|
41
45
|
As you see, we are using Nokogiri for HTML parsing. You are not
|
42
46
|
required to use it too--take the parser whatever you like. Nokogiri
|
43
47
|
is nice, because it's able to read a broken HTML and search thought
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# This is a skeleton for a <%= Bwkfanboy::Meta::NAME %> <%= Bwkfanboy::Meta::VERSION %> plugin. To understand how
|
2
|
+
# plugins work please read doc/plugins.rdoc file from <%= Bwkfanboy::Meta::NAME %>'s
|
3
|
+
# distribution.
|
4
|
+
|
5
|
+
require 'nokogiri'
|
6
|
+
|
7
|
+
class Page < Bwkfanboy::Parse
|
8
|
+
module Meta
|
9
|
+
URI = 'http://example.org/news'
|
10
|
+
ENC = 'UTF-8'
|
11
|
+
VERSION = 1
|
12
|
+
COPYRIGHT = '(c) <%= DateTime.now.year %> <%= Etc.getpwuid(Process.euid)[:gecos] %>'
|
13
|
+
TITLE = "News from example.org"
|
14
|
+
CONTENT_TYPE = 'html'
|
15
|
+
end
|
16
|
+
|
17
|
+
def myparse(stream)
|
18
|
+
# read 'stream' IO object and parse it
|
19
|
+
doc = Nokogiri::HTML(stream, nil, Meta::ENC)
|
20
|
+
doc.xpath("XPATH QUERY").each {|i|
|
21
|
+
t = clean(i.xpath("XPATH QUERY").text())
|
22
|
+
l = clean(i.xpath("XPATH QUERY").text())
|
23
|
+
u = date(i.xpath("XPATH QUERY").text())
|
24
|
+
a = clean(i.xpath("XPATH QUERY").text())
|
25
|
+
c = clean(i.xpath("XPATH QUERY").text())
|
26
|
+
|
27
|
+
self << { title: t, link: l, updated: u, author: a, content: c }
|
28
|
+
}
|
29
|
+
end
|
30
|
+
end
|
@@ -86,6 +86,8 @@ function prepare4eval(body) {
|
|
86
86
|
"function HeaderLogo(args) { return arr(arguments) }\n" +
|
87
87
|
"function NavElement(args) { return arr(arguments) }\n" +
|
88
88
|
"function UserFollowLink(args) { return arr(arguments) }\n" +
|
89
|
+
"function FlashClient(args) { return arr(arguments) }\n" +
|
90
|
+
"function AddQuestionLink(args) { return arr(arguments) }\n" +
|
89
91
|
'';
|
90
92
|
var tail = "\n_components;\n";
|
91
93
|
|
@@ -17,7 +17,7 @@ class Page < Bwkfanboy::Parse
|
|
17
17
|
URI = 'http://www.quora.com/#{opt[0]}/answers'
|
18
18
|
URI_DEBUG = '/home/alex/lib/software/alex/bwkfanboy/test/semis/quora.html'
|
19
19
|
ENC = 'UTF-8'
|
20
|
-
VERSION =
|
20
|
+
VERSION = 7
|
21
21
|
COPYRIGHT = "See bwkfanboy's LICENSE file"
|
22
22
|
TITLE = "Last n answers (per-user) from Quora; requires nodejs"
|
23
23
|
CONTENT_TYPE = 'html'
|
data/lib/bwkfanboy/utils.rb
CHANGED
@@ -7,7 +7,7 @@ require 'active_support/core_ext/module/attribute_accessors'
|
|
7
7
|
module Bwkfanboy
|
8
8
|
module Meta
|
9
9
|
NAME = 'bwkfanboy'
|
10
|
-
VERSION = '1.
|
10
|
+
VERSION = '1.2.5'
|
11
11
|
USER_AGENT = "#{NAME}/#{VERSION} (#{RUBY_PLATFORM}; N; #{Encoding.default_external.name}; #{RUBY_ENGINE}; rv:#{RUBY_VERSION}.#{RUBY_PATCHLEVEL})"
|
12
12
|
PLUGIN_CLASS = 'Page'
|
13
13
|
DIR_TMP = "/tmp/#{Meta::NAME}/#{ENV['USER']}"
|