Top Level Namespace
Defined Under Namespace
Classes: Server, SiteData
Constant Summary
collapse
- TMPFILE =
Dir.tmpdir + "/w3m-autopagerize.tmp.html"
- DOCTYPE =
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">'
Instance Method Summary
collapse
Instance Method Details
#addstring(url_or_pattern, string) ⇒ Object
131
132
133
134
135
136
|
# File 'lib/w3m-autopagerize-server.rb', line 131
def addstring(url_or_pattern, string)
defnext_(url_or_pattern) {|u,m|
$logger.info "Use addstring for #{url_or_pattern}"
u.to_s + string
}
end
|
#defnext(url_or_pattern, nexturl = nil, &b) ⇒ Object
113
114
115
116
117
118
|
# File 'lib/w3m-autopagerize-server.rb', line 113
def defnext(url_or_pattern, nexturl=nil, &b)
defnext_ url_or_pattern, nexturl do |u,m|
$logger.info "Use defnext for #{url_or_pattern}"
instance_exec(u, m, &b)
end
end
|
#defnext_(url_or_pattern, nexturl = nil, &block) ⇒ Object
120
121
122
123
124
125
126
127
128
|
# File 'lib/w3m-autopagerize-server.rb', line 120
def defnext_(url_or_pattern, nexturl=nil, &block)
sd = SiteData.new
if nexturl
sd.block = lambda{|u,m| nexturl }
else
sd.block = block
end
$SITEINFO << [ url_or_pattern, sd ]
end
|
#get_content(url) ⇒ Object
223
224
225
226
227
228
229
|
# File 'lib/w3m-autopagerize-server.rb', line 223
def get_content(url)
if url =~ /^https?:/
get_header_and_content(url)[1]
else File.zread(File.expand_path(url))
end
end
|
#get_header_and_content(url) ⇒ Object
213
214
215
216
217
218
219
220
221
|
# File 'lib/w3m-autopagerize-server.rb', line 213
def get_header_and_content(url)
output = `w3m #$W3M_EXTRA_OPTIONS -dump_both -o accept_encoding='gzip' "#{url}"`
, source = output.split(/\n\n/, 2)
open(TMPFILE,"wb"){|f| f.write source}
source = File.zread(TMPFILE)
[, source]
ensure
File.unlink TMPFILE if File.exist? TMPFILE
end
|
#increment(url_or_pattern, n = 1) ⇒ Object
138
139
140
141
142
143
144
145
146
147
148
149
150
|
# File 'lib/w3m-autopagerize-server.rb', line 138
def increment(url_or_pattern, n=1)
defnext_(url_or_pattern) {|u,m|
$logger.info "Use increment for #{url_or_pattern}"
url=u.to_s
nextvar = m[1].to_i + n
url[ m.begin(1) ... m.end(1) ] = if m[1] =~ /^0/
format("%0#{m[1].length}d", nextvar)
else
nextvar.to_s
end
url
}
end
|
#normalize_charset(charset) ⇒ Object
231
232
233
234
235
|
# File 'lib/w3m-autopagerize-server.rb', line 231
def normalize_charset(charset)
charset = charset.to_s
charset.downcase == "shift_jis" ? "cp932" : charset
end
|
#reinit ⇒ Object
238
239
240
|
# File 'lib/w3m-autopagerize-server.rb', line 238
def reinit
$SITEINFO = []
end
|
#w3mctl(*strings) ⇒ Object
152
153
154
155
156
157
158
159
160
161
162
163
|
# File 'lib/w3m-autopagerize-server.rb', line 152
def w3mctl(*strings)
strings.each do |str|
if str
if str==true
$client.print "\r\n\r\n"
else
$client.print "W3m-Control: #{str}\r\n"
end
end
end
nil
end
|