bwkfanboy 1.4.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. data/.gitignore +4 -0
  2. data/Gemfile +7 -0
  3. data/Gemfile.lock +51 -0
  4. data/Procfile +1 -0
  5. data/README.rdoc +40 -77
  6. data/Rakefile +13 -48
  7. data/bin/bwkfanboy +47 -166
  8. data/bin/bwkfanboy_generate +7 -19
  9. data/bin/bwkfanboy_parse +21 -17
  10. data/bwkfanboy.gemspec +40 -0
  11. data/config.ru +3 -0
  12. data/doc/NEWS.rdoc +21 -79
  13. data/doc/plugin.rdoc +63 -79
  14. data/etc/bwkfanboy.yaml +2 -0
  15. data/etc/sinatra.rb +34 -0
  16. data/lib/bwkfanboy/cliconfig.rb +141 -0
  17. data/lib/bwkfanboy/cliutils.rb +114 -0
  18. data/lib/bwkfanboy/fetch.rb +22 -24
  19. data/lib/bwkfanboy/generator.rb +78 -0
  20. data/lib/bwkfanboy/home.rb +53 -0
  21. data/lib/bwkfanboy/meta.rb +5 -2
  22. data/lib/bwkfanboy/plugin.rb +247 -0
  23. data/lib/bwkfanboy/plugin_skeleton.erb +19 -23
  24. data/lib/bwkfanboy/server.rb +73 -0
  25. data/lib/bwkfanboy/utils.rb +39 -129
  26. data/plugins/bwk.rb +25 -0
  27. data/plugins/econlib.rb +22 -0
  28. data/plugins/freebsd-ports-update.rb +73 -0
  29. data/plugins/inc.rb +29 -0
  30. data/plugins/test.rb +29 -0
  31. data/public/.gitattributes +1 -0
  32. data/public/favicon.ico +0 -0
  33. data/public/jquery-1.7.2.min.js +0 -0
  34. data/public/list.js +111 -0
  35. data/public/loading.gif +0 -0
  36. data/public/style.css +54 -0
  37. data/shotgun.rb +20 -0
  38. data/test/example/.gitattributes +1 -0
  39. data/test/example/.gitignore +1 -0
  40. data/test/example/02/plugins/bwk.html +0 -0
  41. data/test/{plugins → example/02/plugins}/empty.rb +0 -0
  42. data/test/example/02/plugins/garbage.rb +1 -0
  43. data/test/example/02/plugins/inc.html +0 -0
  44. data/test/helper.rb +30 -27
  45. data/test/helper_cliutils.rb +34 -0
  46. data/test/test_cli.rb +86 -0
  47. data/test/test_fetch.rb +49 -18
  48. data/test/test_generate.rb +43 -16
  49. data/test/test_home.rb +33 -0
  50. data/test/test_plugin.rb +141 -0
  51. data/test/test_server.rb +21 -32
  52. data/views/list.haml +38 -0
  53. metadata +223 -110
  54. data/bin/bwkfanboy_fetch +0 -13
  55. data/bin/bwkfanboy_server +0 -126
  56. data/doc/README.erb +0 -114
  57. data/doc/README.rdoc +0 -141
  58. data/doc/TODO +0 -7
  59. data/doc/bwkfanboy_fetch.rdoc +0 -4
  60. data/doc/bwkfanboy_generate.rdoc +0 -7
  61. data/doc/bwkfanboy_parse.rdoc +0 -7
  62. data/doc/bwkfanboy_server.rdoc +0 -35
  63. data/doc/rakefile.rb +0 -59
  64. data/lib/bwkfanboy/generate.rb +0 -63
  65. data/lib/bwkfanboy/parser.rb +0 -156
  66. data/lib/bwkfanboy/plugins/bwk.rb +0 -33
  67. data/lib/bwkfanboy/plugins/econlib.rb +0 -34
  68. data/lib/bwkfanboy/plugins/freebsd-ports-update.rb +0 -76
  69. data/lib/bwkfanboy/plugins/inc.rb +0 -37
  70. data/lib/bwkfanboy/schema.js +0 -39
  71. data/test/popen4.sh +0 -4
  72. data/test/rake_git.rb +0 -36
  73. data/test/semis/Rakefile +0 -35
  74. data/test/semis/bwk.html +0 -393
  75. data/test/semis/bwk.json +0 -82
  76. data/test/semis/econlib.html +0 -21
  77. data/test/semis/inc.html +0 -1067
  78. data/test/semis/links.txt +0 -4
  79. data/test/test_parse.rb +0 -27
  80. data/test/xml-clean.sh +0 -8
  81. data/web/bwkfanboy.cgi +0 -36
@@ -0,0 +1,4 @@
1
+ pkg
2
+ html
3
+ .bundle
4
+ vendor
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ # -*-ruby-*-
2
+ source 'https://rubygems.org'
3
+
4
+ gem "thin", "~> 1.3.1"
5
+
6
+ # Specify your gem's dependencies in bwkfanboy.gemspec
7
+ gemspec
@@ -0,0 +1,51 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bwkfanboy (2.0.0)
5
+ haml (~> 3.1.4)
6
+ msgpack (~> 0.4.6)
7
+ nokogiri (~> 1.5.2)
8
+ open4 (~> 1.1.0)
9
+ rake (~> 0.9.2.2)
10
+ rdoc (~> 3.12)
11
+ sinatra (~> 1.3.2)
12
+
13
+ GEM
14
+ remote: https://rubygems.org/
15
+ specs:
16
+ daemons (1.1.8)
17
+ eventmachine (0.12.10)
18
+ fakefs (0.4.0)
19
+ haml (3.1.4)
20
+ json (1.6.6)
21
+ minitest (2.12.1)
22
+ msgpack (0.4.6)
23
+ nokogiri (1.5.2)
24
+ open4 (1.1.0)
25
+ rack (1.4.1)
26
+ rack-protection (1.2.0)
27
+ rack
28
+ rack-test (0.6.1)
29
+ rack (>= 1.0)
30
+ rake (0.9.2.2)
31
+ rdoc (3.12)
32
+ json (~> 1.4)
33
+ sinatra (1.3.2)
34
+ rack (~> 1.3, >= 1.3.6)
35
+ rack-protection (~> 1.2)
36
+ tilt (~> 1.3, >= 1.3.3)
37
+ thin (1.3.1)
38
+ daemons (>= 1.0.9)
39
+ eventmachine (>= 0.12.6)
40
+ rack (>= 1.0.0)
41
+ tilt (1.3.3)
42
+
43
+ PLATFORMS
44
+ ruby
45
+
46
+ DEPENDENCIES
47
+ bwkfanboy!
48
+ fakefs (~> 0.4.0)
49
+ minitest (~> 2.12.1)
50
+ rack-test (~> 0.6.1)
51
+ thin (~> 1.3.1)
@@ -0,0 +1 @@
1
+ web: bundle exec rackup config.ru -p $PORT
@@ -1,15 +1,17 @@
1
1
  = About
2
2
 
3
+ A live example: http://bwkfanboy.herokuapp.com
4
+
3
5
  bwkfanboy is a converter from a raw HTML to an Atom feed. You can use it
4
6
  to watch sites that do not provide its own feed.
5
7
 
6
8
  The converter is not a magick tool: you'll need to write a plugin (in
7
- Ruby) for each site you want to watch. bwkfanboy gives guidelines and
8
- general assistance.
9
+ Ruby) for an each site you want to watch. bwkfanboy gives guidelines and
10
+ a general assistance.
9
11
 
10
- (Plugins from version 1.1.4 are *incompatible* with the 0.1.x
11
- series. Please reread in doc/plugin.rdoc the example of the skeleton
12
- plugin.)
12
+ <b> Version 2.0.0 was rewritten form scratch. Plugins from previous
13
+ versions will not work.</b> See http://github.com/gromnitsky/bwkfanboy_old
14
+ repo for old versions.
13
15
 
14
16
  = Included Plugins
15
17
 
@@ -23,30 +25,36 @@ plugin.)
23
25
 
24
26
  = Installation
25
27
 
26
- The easiest way is to type:
28
+ Install bundler:
29
+
30
+ # gem install bundler
31
+
32
+ Install all dependencies. You have 2 choices:
33
+
34
+ 1. Usual via
35
+
36
+ # bundle install
37
+
38
+ 2. Or only for this program
27
39
 
28
- # gem install bwkfanboy
40
+ % bundle install --path vendor/bundle
29
41
 
30
- Beware that plugins above are usually updated more frequently than the
31
- whole gem on rubygems.org, so grab the source before struggling with a
32
- particular plugin.
42
+ You'll have to prefix other commands with 'bundle exec' though.
33
43
 
34
- If the setup with <tt>gem install ...</tt> fails, go to
35
- https://rubygems.org/gems/bwkfanboy and click 'Download' link, save the
36
- file and run:
44
+ Run application:
37
45
 
38
- # gem install -l /where/is/your/bwkfanboy-x.y.z.gem
46
+ % rackup -E production
39
47
 
48
+ Point a browser to http://127.0.0.1:9292
49
+
50
+
40
51
  = Architecture
41
52
 
42
53
  == Plugins
43
54
 
44
- The plugin is a Ruby class +Page+ that inherits Bwkfanboy::Parse parent,
45
- overriding 1 method.
46
-
47
55
  Plugins can be in system
48
56
 
49
- `gem env gemdir`/gems/bwkfanboy-x.y.z/lib/bwkfanboy/plugins
57
+ `gem env gemdir`/gems/bwkfanboy-x.y.z/plugins
50
58
 
51
59
  or user's home
52
60
 
@@ -56,86 +64,41 @@ directory.
56
64
 
57
65
  == Pipeline
58
66
 
59
- The program consists of 4 parts:
67
+ The program consists of 3 parts:
60
68
 
61
69
  0. *bwkfanboy* script that takes 1 parameter: the name of a file in
62
- plugins directories (without the .rb suffix). So, for example to get
70
+ plugin directories (without the .rb suffix). So, for example to get
63
71
  an atom feed from dailyprincetonian.com, you type:
64
72
 
65
73
  % bwkfanboy bwk
66
74
 
67
75
  and it will load
68
- <tt>/usr/local/lib/ruby/gems/1.9/gems/bwkfanboy-0.0.1/lib/bwkfanboy/plugins/bwk.rb</tt>
76
+ <tt>/usr/local/lib/ruby/gems/1.9/gems/bwkfanboy-2.0.0/plugins/bwk.rb</tt>
69
77
  file on my FreeBSD machine, fetch and parse the html from
70
78
  dailyprincetonian.com and generate the required feed, dumping it to
71
79
  stdout.
72
80
 
73
- The script is just a convenient wrapper for 3 separate utils.
74
-
75
- 1. *bwkfanboy_fetch*
81
+ The script is just a convenient wrapper for 2 separate
82
+ utils below. (Although it doesn't executes them, but uses their internal
83
+ api.)
76
84
 
77
- Reads 1 line from stdin for the URL to fetch from. The result will be
78
- dumped to stdout.
85
+ 1. *bwkfanboy_parse*
79
86
 
80
- 2. *bwkfanboy_parse*
87
+ Takes 1 parameter: a plugin name.
81
88
 
82
- Takes 1 parameter: <em>a full path</em> to a plugin file.
89
+ This util reads stdin, expecting it to be a html, parses it and
90
+ dumps the result to stdout as MessagePack object in UTF-8.
83
91
 
84
- This util reads stdin, expecting it to be a xhtml, parses it and
85
- dumps the result to stdout in JSON-formatted object.
92
+ 2. *bwkfanboy_generate*
86
93
 
87
- 3. *bwkfanboy_generate*
88
-
89
- Reads stdin expecting it to be a proper JSON-formatted object.
94
+ Reads stdin expecting it to be a proper MessagePack object.
90
95
 
91
96
  The result will be an Atom feed dumped to stdout in UTF-8.
92
97
 
93
98
  So, without the wrapper all this together looks like:
94
99
 
95
- % echo http://example.org | bwkfanboy_fetch |
96
- bwkfanboy_parse /path/to/my/plugin.rb | bwkfanboy_generate
97
-
98
- == Log
99
-
100
- All utils write to <tt>/tmp/bwkfanboy/USER/log/general.log</tt> file if
101
- permissions allows it.
100
+ % curl http://example.org | bwkfanboy_parse myplugin | bwkfanboy_generate
102
101
 
103
102
  == HTTP
104
103
 
105
- There are 2 method to get an Atom feed via HTTP:
106
-
107
- 1. <tt>web/bwkfanboy.cgi</tt> (from the program tarball), which you may
108
- copy to your Apache cgi directory and run it. This prohibits you from
109
- using HOME directory for your own plugins. Also the cgi script
110
- requires some manual editing (setting 1 variable in it) before even
111
- you can start utilizing it.
112
-
113
- 2. Small *bwkfanboy_server* HTTP server. It can run from any user and
114
- thus is able to inherit env variables for discovering your HOME
115
- directory. Read doc/bwkfanboy_server.rdoc to know how to operate it.
116
-
117
- = License
118
-
119
- (The MIT License)
120
-
121
- Copyright (c) 2010 Alexander Gromnitsky.
122
-
123
- Permission is hereby granted, free of charge, to any person obtaining
124
- a copy of this software and associated documentation files (the
125
- 'Software'), to deal in the Software without restriction, including
126
- without limitation the rights to use, copy, modify, merge, publish,
127
- distribute, sublicense, and/or sell copies of the Software, and to
128
- permit persons to whom the Software is furnished to do so, subject to
129
- the following conditions:
130
-
131
- The above copyright notice and this permission notice shall be
132
- included in all copies or substantial portions of the Software.
133
-
134
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
135
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
136
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
137
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
138
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
139
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
140
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
141
-
104
+ bwkfanboy includes a small sinatra app. See the installation phase.
data/Rakefile CHANGED
@@ -1,59 +1,24 @@
1
1
  # -*-ruby-*-
2
2
 
3
- require 'rake'
4
- require 'rake/gempackagetask'
5
3
  require 'rake/clean'
6
- require 'rake/rdoctask'
7
4
  require 'rake/testtask'
8
- require 'json'
5
+ require 'bundler/gem_tasks'
6
+ gem 'rdoc'
7
+ require 'rdoc/task'
9
8
 
10
- require_relative 'test/rake_git'
11
- require_relative 'doc/rakefile'
9
+ task default: [:test]
12
10
 
13
- spec = Gem::Specification.new {|i|
14
- i.name = "bwkfanboy"
15
- i.summary = "#{i.name} is a converter from a raw HTML to an Atom feed. You can use it to watch sites that do not provide its own feed."
16
- i.description = i.summary
17
- i.version = `bin/#{i.name} -V`
18
- i.author = 'Alexander Gromnitsky'
19
- i.email = 'alexander.gromnitsky@gmail.com'
20
- i.homepage = "http://github.com/gromnitsky/#{i.name}"
21
- i.platform = Gem::Platform::RUBY
22
- i.required_ruby_version = '>= 1.9.2'
23
- i.files = git_ls('.')
24
-
25
- i.executables = FileList['bin/*'].gsub(/^bin\//, '')
26
-
27
- i.test_files = FileList['test/test_*.rb']
28
-
29
- i.rdoc_options << '-m' << 'doc/README.rdoc' << '-x' << 'plugins'
30
- i.extra_rdoc_files = FileList['doc/*.rdoc']
31
-
32
- i.add_dependency('open4', '>= 1.0.1')
33
- i.add_dependency('activesupport', '>= 3.0.5')
34
- i.add_dependency('nokogiri', '>= 1.4.4')
35
- i.add_dependency('jsonschema', '>= 2.0.1')
36
-
37
- i.add_development_dependency('git', '>= 1.2.5')
38
- }
39
-
40
- Rake::GemPackageTask.new(spec).define
41
-
42
- task gen_mydocs: ['mydocs:default'] do
43
- spec.extra_rdoc_files.concat(MyDocs::RDOC_RELATIVE)
44
- end
45
-
46
- task default: [:gen_mydocs, :repackage]
47
- task doc: [:gen_mydocs, :rdoc]
48
- task clobber: ['mydocs:clean']
49
-
50
- Rake::RDocTask.new do |i|
51
- i.rdoc_files = FileList['doc/*', 'lib/**/*.rb']
52
- i.rdoc_files.exclude("lib/**/plugins")
53
- i.main = 'doc/README.rdoc'
11
+ RDoc::Task.new('html') do |i|
12
+ i.main = 'README.rdoc'
13
+ i.rdoc_files = FileList['README.rdoc', 'doc/*', 'lib/**/*.rb']
14
+ # i.rdoc_files.exclude("lib/**/some-nasty-staff")
54
15
  end
55
16
 
56
17
  Rake::TestTask.new do |i|
57
18
  i.test_files = FileList['test/test_*.rb']
58
- i.libs << '.'
19
+ end
20
+
21
+ desc "Insert all 'requires' to speedup reload"
22
+ task :shotgunreq do
23
+ sh "git grep 'require ' -- '*.rb' | awk -F: '{print $2}' | grep -v test | sort | uniq > shotgun.rb"
59
24
  end
@@ -1,185 +1,66 @@
1
1
  #!/usr/bin/env ruby
2
- # -*-ruby-*-
3
2
 
4
- # This program is executed by bin/bwkfanboy_server to do all dirty work:
5
- # fetch HTML, parse it and generate a pretty Atom feed.
6
- #
7
- # It is a wrapper which you can utilize for such common tasks as listing
8
- # all available plugins.
9
- #
10
- # Type:
11
- #
12
- # % bwkfanboy -h
13
- #
14
- # to get some basic help--read about Bwkfanboy module.
3
+ require_relative '../lib/bwkfanboy/home'
4
+ require_relative '../lib/bwkfanboy/utils'
5
+ include Bwkfanboy
15
6
 
16
- require 'shellwords'
17
- require_relative '../lib/bwkfanboy/parser'
7
+ ### main
18
8
 
19
- $conf = {
20
- mode: 'fast',
21
- skeleton_name: 'bwkfanboy_plugin_skeleton.rb',
22
- skeleton: Bwkfanboy::Utils.gem_dir_system() + '/plugin_skeleton.erb',
23
- debug: false,
24
- banner: "Usage: #{File.basename($0)} [options] plugin-name"
25
- }
26
-
27
- class Plugin # :nodoc: all
28
- attr_reader :name, :path
29
-
30
- def initialize(name)
31
- @name = name
32
- @path = nil
33
- end
34
-
35
- def dirs()
36
- # try to create user's home plugin directory
37
- begin
38
- ['~/.bwkfanboy', '~/.bwkfanboy/plugins'].each {|i|
39
- Dir.mkdir(File.expand_path(i))
40
- }
41
- rescue
42
- # empty
43
- end
44
-
45
- r = []
46
- dirs = ['~/.bwkfanboy/plugins', "#{Bwkfanboy::Utils.gem_dir_system}/plugins"]
47
- begin
48
- # this will fail for user's home directory under Apache CGI
49
- # environment
50
- dirs.map! {|i| File.expand_path(i) }
51
- rescue
52
- end
53
- dirs.each {|i|
54
- if File.readable?(i) then
55
- r << i
56
- else
57
- Bwkfanboy::Utils.warnx("directory #{i} isn't readable");
58
- end
59
- }
60
-
61
- if r.length == 0 then
62
- Bwkfanboy::Utils.errx(1, "no dirs for plugins found: #{dirs.join(' ')}")
63
- end
64
- return r
65
- end
66
-
67
- def load(opt)
68
- abort($conf[:banner]) unless (@name && @name !~ /^\s*$/)
9
+ mode = nil
10
+ $home = Home.new {|loader, o|
11
+ loader.conf[:banner] = "#{File.basename $0} [options] plugin [opt1 opt2 ...]"
69
12
 
70
- dirs.each {|i|
71
- files = Dir.glob("#{i}/*.rb")
72
- if (@path = files.index("#{i}/#{@name}.rb")) then
73
- @path = files[@path]
74
- break
75
- end
76
- }
77
- Bwkfanboy::Utils.errx(1, "no such plugin '#{@name}'") if ! @path
78
- Bwkfanboy::Utils.plugin_load(@path, Bwkfanboy::Meta::PLUGIN_CLASS)
79
-
80
- pn = Page.new(opt)
81
- pn.check()
82
- return pn
83
- end
84
-
85
- end # class
86
-
87
- # ----------------------------------------------------------------------
13
+ o.on('-l', 'List all plugins.') {
14
+ mode = :list
15
+ }
16
+ o.on('-i', 'Show some info about the plugin.') {
17
+ mode = :info
18
+ }
19
+ o.on('-s FILE', 'Write to the FILE a skeleton for a plugin.') {|i|
20
+ mode = :template
21
+ loader.conf[:skeleton] = i
22
+ loader.conf[:template] = (CliUtils::DIR_LIB_SRC + 'plugin_skeleton.erb').to_s
23
+ }
88
24
 
89
- o = Bwkfanboy::Utils.cl_parse(ARGV, $conf[:banner]) # create OptionParser object
90
- o.on('-i', 'Show some info about the plugin') { |i| $conf[:mode] = 'info' }
91
- o.on('-l', 'List all plugins') { |i| $conf[:mode] = 'list' }
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
25
  }
97
- o.on('-O', '(ignore this) Execute all bwkfanboy_* utils in a pipe') { |i| $conf[:mode] = 'pipe' }
98
- o.on('-D', '(ignore this) Use URI_DEBUG const instead URI in plugins') { |i| $conf[:debug] = true }
99
- Bwkfanboy::Utils.cl_parse(ARGV, $conf[:banner], o) # run cl parser
100
26
 
101
- plugin = Plugin.new(ARGV[0])
102
- opt = Bwkfanboy::Utils.plugin_opts(ARGV)
27
+ if !mode
28
+ CliUtils.errx EX_USAGE, $home.conf[:banner] unless BH.all_set?(ARGV[0])
29
+ end
103
30
 
104
- case $conf[:mode]
105
- when 'template'
106
- require 'erb'
107
- require 'digest/md5'
108
- require 'etc'
31
+ case mode
32
+ when :list
33
+ list = PluginInfo.getList $home.conf[:plugins_path]
34
+ list.each {|idx|
35
+ puts idx.keys.first + ':'
36
+ idx[idx.keys.first].each {|file|
37
+ puts "\t#{file}"
38
+ }
39
+ }
109
40
 
110
- t = ERB.new(File.read($conf[:skeleton]))
111
- t.filename = $conf[:skeleton] # to report errors relative to this file
41
+ when :info
112
42
  begin
113
- md5_system = Digest::MD5.hexdigest(t.result(binding))
114
- rescue Exception
115
- Bwkfanboy::Utils.errx(1, "cannot read the template: #{$!}")
43
+ r = PluginInfo.about $home.conf[:plugins_path], ARGV[0], ARGV[1..-1]
44
+ rescue PluginException
45
+ CliUtils.errx EX_DATAERR, $!.to_s
116
46
  end
117
47
 
118
- if ! File.exists?($conf[:skeleton_name])
119
- # write a skeleton
120
- begin
121
- File.open($conf[:skeleton_name], 'w+') { |fp| fp.puts t.result(binding) }
122
- rescue
123
- Bwkfanboy::Utils.errx(1, "cannot write the skeleton: #{$!}")
124
- end
125
- elsif
126
- # warn a careless user
127
- if md5_system != Digest::MD5.file($conf[:skeleton_name]).hexdigest
128
- Bwkfanboy::Utils.errx(1, "#{$conf[:skeleton_name]} already exists")
129
- end
130
- end
131
-
132
- when 'list'
133
- plugin.dirs().each {|i|
134
- puts "#{i}:"
135
- Dir.glob("#{i}/*.rb").each {|j|
136
- puts "\t#{File.basename(j, '.rb')}"
137
- }
48
+ r.each {|key, val|
49
+ next if key == 'uri'
50
+ puts "%-9s : %s" % [key.upcase, val]
138
51
  }
139
- when 'path'
140
- plugin.dirs().each {|i| puts i}
141
- when 'info'
142
- plugin.load(opt).dump_info
143
- when 'version'
144
- puts Bwkfanboy::Meta::VERSION
145
- when 'pipe'
146
- pn = plugin.load(opt)
147
- cmd = "./bwkfanboy_fetch | ./bwkfanboy_parse '#{plugin.path}' #{opt.size != 0 ? Shellwords.join(opt) : ''} | ./bwkfanboy_generate"
148
- if Bwkfanboy::Utils.cfg[:verbose] >= 2 then
149
- puts (!$conf[:debug] ? pn.uri() : pn.class::Meta::URI_DEBUG)
150
- puts cmd
151
- exit 0
152
- end
153
-
154
- # go to the directory with current script
155
- Dir.chdir(File.dirname(File.expand_path($0)))
156
-
157
- pipe = IO.popen(cmd, 'w+')
158
- pipe.puts (!$conf[:debug] ? pn.uri : pn.class::Meta::URI_DEBUG)
159
- pipe.close_write
160
- while line = pipe.gets
161
- puts line
162
- end
163
- pipe.close
52
+ puts "URI : #{r['uri'].size}\n\n"
53
+ r['uri'].each {|idx| puts idx }
164
54
 
165
- else
166
- # a 'new', faster way
167
- pn = plugin.load(opt)
168
55
 
169
- require_relative '../lib/bwkfanboy/fetch'
170
- require_relative '../lib/bwkfanboy/generate'
56
+ when :template
57
+ exit EX_CANTCREAT unless Utils.skeletonCreate $home.conf[:template], "#{$home.conf[:skeleton]}.rb"
171
58
 
172
- # 1. fetch & parse
173
- pn = Page.new(opt)
174
- Bwkfanboy::Fetch.cat(!$conf[:debug] ? pn.uri() : pn.class::Meta::URI_DEBUG) {|stream|
175
- pn.parse(stream)
176
- }
177
-
178
- if Bwkfanboy::Utils.cfg[:verbose] >= 2 then
179
- pn.dump()
180
- exit 0
59
+ else
60
+ begin
61
+ puts Utils.atom($home.conf[:plugins_path], ARGV[0], ARGV[1..-1])
62
+ rescue FetchException, PluginException, GeneratorException
63
+ CliUtils.errx EX_DATAERR, $!.to_s
181
64
  end
182
-
183
- # 2.generate
184
- puts Bwkfanboy::Generate.atom(JSON.parse(pn.to_json))
65
+
185
66
  end