w3m-autopagerize 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/w3m-autopagerize-server.rb +10 -17
  2. data/readme.org +0 -3
  3. metadata +2 -2
@@ -1,8 +1,8 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  # (executable-interpret "ruby19 /m/home/rubikitch/w3m/cgi-bin/w3m-autopagerize/test-w3m-autopagerize.rb --no-use-color ")
3
- # (executable-interpret "rm -f /log/w3m-autopagerize.log; w3m-autopagerize-server.rb -r")
3
+ # (executable-interpret "rm -f /log/w3m-autopagerize.log; ../bin/w3m-autopagerize-server -r")
4
4
  $start_time = Time.now
5
- #Encoding.default_internal = "UTF-8"
5
+ Encoding.default_external = "ASCII-8BIT" if RUBY_VERSION >= "1.9"
6
6
  require 'kconv'
7
7
  require 'uri'
8
8
  require 'rubygems'
@@ -194,7 +194,6 @@ $content_cache = Hash.new do |h,url|
194
194
  header, source = get_header_and_content(url)
195
195
  $logger.debug "cache miss: source is html? = #{source =~ /<body/i and true}"
196
196
  charset = normalize_charset(header[/charset=(.+)$/,1] || Kconv.guess(source))
197
- source.force_encoding("ASCII-8BIT")
198
197
  h[url] = [source, charset]
199
198
  end
200
199
 
@@ -213,9 +212,9 @@ end
213
212
  ###########################################################################
214
213
  def get_header_and_content(url)
215
214
  output = `w3m #$W3M_EXTRA_OPTIONS -dump_both -o accept_encoding='gzip' "#{url}"`
216
- header, source = output.force_encoding("ASCII-8BIT").split(/\n\n/, 2)
215
+ header, source = output.split(/\n\n/, 2)
217
216
  open(TMPFILE,"wb"){|f| f.write source}
218
- source = File.zread(TMPFILE).force_encoding "ASCII-8BIT"
217
+ source = File.zread(TMPFILE)
219
218
  [header, source]
220
219
  ensure
221
220
  File.unlink TMPFILE if File.exist? TMPFILE
@@ -225,7 +224,7 @@ def get_content(url)
225
224
  if url =~ /^https?:/
226
225
  get_header_and_content(url)[1]
227
226
  else # local file
228
- File.zread(File.expand_path(url)).force_encoding "ASCII-8BIT"
227
+ File.zread(File.expand_path(url))
229
228
  end
230
229
  end
231
230
 
@@ -240,13 +239,6 @@ def reinit
240
239
  $SITEINFO = []
241
240
  end
242
241
 
243
- # unless "".respond_to? :force_encoding # for ruby 1.8
244
- # class String
245
- # def force_encoding(args); self end
246
- # def encoding; Kconv.guess(self) end
247
- # end
248
- # end
249
-
250
242
  ###########################################################################
251
243
  # Entry Points #
252
244
  ###########################################################################
@@ -289,12 +281,13 @@ class Server
289
281
  else
290
282
  errmsg = ""
291
283
  end
284
+ html_piece
292
285
  # BUG: Nokogiri emits superfluous &#13;.
293
286
  html_piece.gsub! /&#13;/, '' # hack
294
287
  # BUG: w3m cannot handle <script />, so replace it with <script></script>
295
288
  html_piece.gsub! %r!(<script.+?)/>!, '\1></script>' # hack
296
289
  %w[location title prev_url sitedata.pageElement sitedata.nextLink errmsg html_piece].each do |e|
297
- # $logger.debug "#{__method__}: #{e}.encoding = #{eval('e').to_s.encoding}"
290
+ $logger.debug "#{__method__}: #{e}.encoding = #{eval("#{e}.encoding rescue nil")}"
298
291
  end
299
292
  html = %{<html>
300
293
  <head><base href="#{location}" />#{title}
@@ -334,14 +327,14 @@ class Server
334
327
  $logger.debug "#{method}: W3M_SOURCEFILE = #{srcfile}" if srcfile
335
328
  $client = client
336
329
 
337
- src = File.zread(srcfile).force_encoding("ASCII-8BIT") if srcfile
330
+ src = File.zread(srcfile) if srcfile
338
331
  if url =~ /^file:.*\/cgi-bin\// # from Local CGI
339
- url = src.force_encoding("ASCII-8BIT")[%r!<base href=['"](.+?)['"]!, 1] # '"
332
+ url = src[%r!<base href=['"](.+?)['"]!, 1] # '"
340
333
  $logger.info "#{method}: base url=#{url}"
341
334
  else # from W3M_SOURCEFILE
342
335
  $logger.debug "#{method}: set $content_cache[#{url.inspect}] from W3M_SOURCEFILE"
343
336
  $logger.debug "#{method}: source is html? = #{src =~ /<body/i and true}"
344
- $content_cache[url] = [src.force_encoding("ASCII-8BIT"), normalize_charset(charset)] if src
337
+ $content_cache[url] = [src, normalize_charset(charset)] if src
345
338
  end
346
339
  [ src, url ]
347
340
  end
data/readme.org CHANGED
@@ -1,14 +1,11 @@
1
1
  #+TITLE: AutoPagerize for w3m
2
2
  #+AUTHOR: rubikitch
3
3
  #+EMAIL: rubikitch@ruby-lang.org
4
- #+DATE: 2009-01-30
5
4
  #+LANGUAGE: en
6
5
  #+OPTIONS: H:3 num:t toc:t \n:nil @:t ::t |:t ^:t -:t f:t *:t TeX:t LaTeX:nil skip:nil d:nil todo:t pri:nil tags:not-in-toc
7
6
  #+INFOJS_OPT: view:nil toc:nil ltoc:t mouse:underline buttons:0 path:http://orgmode.org/org-info.js
8
7
  #+EXPORT_SELECT_TAGS: export
9
8
  #+EXPORT_EXCLUDE_TAGS: noexport
10
- #+LINK_UP:
11
- #+LINK_HOME:
12
9
  AutoPagerize for w3m http://rubikitchrb.rubyforge.org/
13
10
 
14
11
  Copyright (c) 2009 rubikitch <rubikitch@ruby-lang.org> http://www.rubyist.net/~rubikitch/
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: w3m-autopagerize
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - rubikitch
@@ -23,7 +23,7 @@ dependencies:
23
23
  version: "0"
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
- name: json_pure
26
+ name: json
27
27
  type: :runtime
28
28
  version_requirement:
29
29
  version_requirements: !ruby/object:Gem::Requirement