1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
|
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), '../../misc/plugin'))
require File.dirname(__FILE__) + "/../spec_helper"
require 'erb'
# FIXME PluginFake in under construction.
class PluginFake
include ERB::Util
attr_reader :conf
attr_accessor :mode, :date
def initialize
@conf = Config.new
@mode = ""
@date = nil
@header_procs = []
@footer_procs = []
@update_procs = []
@conf_procs = []
@body_enter_procs = []
@body_leave_procs = []
@content_procs = {}
end
def add_conf_proc( key, label, genre=nil, &block )
@conf_procs << block
end
def add_header_proc( &block )
@header_procs << block if block_given?
end
def add_footer_proc( &block )
@footer_procs << block if block_given?
end
def add_update_proc( &block )
@update_procs << block if block_given?
end
def add_content_proc( key, &block )
@content_procs[key] = block if block_given?
end
def conf_proc
r = []
@conf_procs.each do |proc|
r << proc.call
end
r.join.chomp
end
def header_proc
r = []
@header_procs.each do |proc|
r << proc.call
end
r.join.chomp
end
def footer_proc
r = []
@footer_procs.each do |proc|
r << proc.call
end
r.join.chomp
end
def add_body_enter_proc( &block )
@body_enter_procs << block if block_given?
end
def body_enter_proc( date )
r = []
@body_enter_procs.each do |proc|
r << proc.call( date )
end
r.join.chomp
end
def add_body_leave_proc( &block )
@body_leave_procs << block if block_given?
end
def body_leave_proc( date )
r = []
@body_leave_procs.each do |proc|
r << proc.call( date )
end
r.join.chomp
end
def content_proc( key, date )
@content_procs[key].call( date )
end
class Config
attr_accessor :index, :update, :author_name, :author_mail, :index_page,
:html_title, :theme, :css, :date_format, :referer_table, :options, :cgi,
:plugin_path, :lang, :style, :description, :html_lang,
:io_class
def initialize
@cgi = CGIFake.new
@options = {}
@options2 = {}
@index = './'
@html_title = ''
@io_class = DummyIO
bot = ["bot", "spider", "antenna", "crawler", "moget", "slurp"]
bot += @options['bot'] || []
@bot = Regexp::new( "(#{bot.uniq.join( '|' )})", true )
end
def []( key )
@options[key]
end
def []=( key, val )
@options2[key] = @options[key] = val
end
def delete( key )
@options.delete( key )
@options2.delete( key )
end
def base_url
begin
if @options['base_url'].length > 0 then
return @options['base_url']
end
rescue
end
end
def mobile_agent?
@cgi.mobile_agent?
end
def bot?
@bot =~ @cgi.user_agent
end
end
def smartphone?
false
end
alias iphone? smartphone?
end
class CGIFake
attr_accessor :user_agent
def initialize
@user_agent = ""
end
def mobile_agent?
false
end
def smartphone?
false
end
end
class DummyIO
def self.plugin_open(conf); nil; end
def self.plugin_close(storage); end
def self.plugin_transaction(storage, plugin); end
end
def fake_plugin( name_sym, cgi=nil, base=nil, &block )
plugin = PluginFake.new
yield plugin if block_given?
file_path = plugin_path( name_sym, base )
plugin_name = File.basename( file_path, ".rb" )
plugin.instance_eval do
eval( File.read( file_path ), binding,
"(#{File.basename(file_path)})", 1 )
end
plugin_sym = plugin_name.to_sym
if plugin.class.private_method_defined?( plugin_sym )
plugin.__send__( :public, plugin_sym )
end
plugin
end
def plugin_path( plugin_sym, base=nil )
paths = []
paths << ( base ? base : File.join(TDiary.root, "misc/plugin") )
paths << "#{plugin_sym.to_s}.rb"
File.expand_path( File.join( paths ))
end
def anchor( s )
if /^([\-\d]+)#?([pct]\d*)?$/ =~ s then
if $2 then
"?date=#$1##$2"
else
"?date=#$1"
end
else
""
end
end
|