| 1 | $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", "plugin"))) |
|---|
| 2 | require 'erb' |
|---|
| 3 | |
|---|
| 4 | # FIXME PluginFake in under construction. |
|---|
| 5 | class PluginFake |
|---|
| 6 | include ERB::Util |
|---|
| 7 | |
|---|
| 8 | attr_reader :conf |
|---|
| 9 | attr_accessor :mode, :date |
|---|
| 10 | |
|---|
| 11 | def initialize |
|---|
| 12 | @conf = Config.new |
|---|
| 13 | @mode = "" |
|---|
| 14 | @date = nil |
|---|
| 15 | @header_procs = [] |
|---|
| 16 | end |
|---|
| 17 | |
|---|
| 18 | def add_conf_proc( key, label, genre=nil, &block ) |
|---|
| 19 | # XXX Do we need to verify add_* called?? |
|---|
| 20 | end |
|---|
| 21 | |
|---|
| 22 | def add_header_proc( block = Proc::new ) |
|---|
| 23 | @header_procs << block |
|---|
| 24 | end |
|---|
| 25 | |
|---|
| 26 | def header_proc |
|---|
| 27 | r = [] |
|---|
| 28 | @header_procs.each do |proc| |
|---|
| 29 | r << proc.call |
|---|
| 30 | end |
|---|
| 31 | r.join.chomp |
|---|
| 32 | end |
|---|
| 33 | |
|---|
| 34 | class Config |
|---|
| 35 | |
|---|
| 36 | attr_accessor :index, :html_title |
|---|
| 37 | |
|---|
| 38 | def initialize |
|---|
| 39 | @options = {} |
|---|
| 40 | @options2 = {} |
|---|
| 41 | @index = './' |
|---|
| 42 | @html_title = '' |
|---|
| 43 | end |
|---|
| 44 | |
|---|
| 45 | def []( key ) |
|---|
| 46 | @options[key] |
|---|
| 47 | end |
|---|
| 48 | |
|---|
| 49 | def []=( key, val ) |
|---|
| 50 | @options2[key] = @options[key] = val |
|---|
| 51 | end |
|---|
| 52 | |
|---|
| 53 | def delete( key ) |
|---|
| 54 | @options.delete( key ) |
|---|
| 55 | @options2.delete( key ) |
|---|
| 56 | end |
|---|
| 57 | |
|---|
| 58 | def base_url |
|---|
| 59 | begin |
|---|
| 60 | if @options['base_url'].length > 0 then |
|---|
| 61 | return @options['base_url'] |
|---|
| 62 | end |
|---|
| 63 | rescue |
|---|
| 64 | end |
|---|
| 65 | end |
|---|
| 66 | end |
|---|
| 67 | end |
|---|
| 68 | |
|---|
| 69 | def fake_plugin( name_sym, base=nil, &block ) |
|---|
| 70 | plugin = PluginFake.new |
|---|
| 71 | yield plugin if block_given? |
|---|
| 72 | |
|---|
| 73 | file_path = plugin_path( name_sym, base ) |
|---|
| 74 | plugin_name = File.basename( file_path, ".rb" ) |
|---|
| 75 | |
|---|
| 76 | plugin.instance_eval do |
|---|
| 77 | eval( File.read( file_path ), binding, |
|---|
| 78 | "(#{File.basename(file_path)})", 1 ) |
|---|
| 79 | end |
|---|
| 80 | plugin_sym = plugin_name.to_sym |
|---|
| 81 | if plugin.class.private_method_defined?( plugin_sym ) |
|---|
| 82 | plugin.__send__( :public, plugin_sym ) |
|---|
| 83 | end |
|---|
| 84 | |
|---|
| 85 | plugin |
|---|
| 86 | end |
|---|
| 87 | |
|---|
| 88 | def plugin_path( plugin_sym, base=nil ) |
|---|
| 89 | paths = [] |
|---|
| 90 | paths << ( base ? base : "plugin" ) |
|---|
| 91 | paths << "#{plugin_sym.to_s}.rb" |
|---|
| 92 | File.expand_path( File.join( paths )) |
|---|
| 93 | end |
|---|
| 94 | |
|---|
| 95 | def anchor( s ) |
|---|
| 96 | if /^([\-\d]+)#?([pct]\d*)?$/ =~ s then |
|---|
| 97 | if $2 then |
|---|
| 98 | "?date=#$1##$2" |
|---|
| 99 | else |
|---|
| 100 | "?date=#$1" |
|---|
| 101 | end |
|---|
| 102 | else |
|---|
| 103 | "" |
|---|
| 104 | end |
|---|
| 105 | end |
|---|