few 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.md +1 -0
  2. data/bin/few +52 -22
  3. metadata +3 -2
data/README.md CHANGED
@@ -25,6 +25,7 @@ The principles of `few`
25
25
  * Does not require any non-standard libraries
26
26
  * Works every Ruby from 1.8.6 to 1.9.2
27
27
  * Which means you have to avoid Enumerators and to care about Encodings
28
+ * (`spec/few` is OK of working only in 1.8.7+)
28
29
 
29
30
  Future plan
30
31
 
data/bin/few CHANGED
@@ -4,21 +4,36 @@ require 'tempfile'
4
4
  require 'cgi'
5
5
  require 'kconv'
6
6
 
7
- def open_browser(path)
8
- case RUBY_PLATFORM
7
+ def open_browser(url)
8
+ case RUBY_PLATFORM.downcase
9
+ when /linux/
10
+ if ENV['KDE_FULL_SESSION'] == 'true'
11
+ system 'kfmclient', 'exec', url
12
+ elsif ENV['GNOME_DESKTOP_SESSION_ID']
13
+ system 'gnome-open', url
14
+ elsif system("exo-open -v >& /dev/null")
15
+ system 'exo-open', url
16
+ else
17
+ system 'firefox', url
18
+ end
9
19
  when /darwin/
10
- system 'open', path
11
- when /mswin(?!ce)|mingw|cygwin|bccwin/
12
- system 'start', path
20
+ system 'open', url
21
+ when /mswin(?!ce)|mingw|bccwin/
22
+ system 'start', url
13
23
  else
14
- system 'firefox', path
24
+ system 'firefox', url
15
25
  end
16
26
  end
17
27
 
18
28
  def require_monad(*libraries)
19
29
  libraries.all? {|l|
30
+ l = l.to_s
20
31
  begin
21
- require l.to_s
32
+ if File.basename(l).include? '.'
33
+ load l
34
+ else
35
+ require l
36
+ end
22
37
  rescue LoadError
23
38
  end
24
39
  }
@@ -26,18 +41,23 @@ end
26
41
 
27
42
  require_monad :rubygems, :markdown
28
43
 
29
- def few(filetype = 'text')
44
+ def few(o={})
45
+ opt = {:filetype => :text, :tee => false}.merge(o)
30
46
  t = Tempfile.new('few')
31
47
 
32
48
  File.open(t.path, 'w') do |io|
33
- a = CGI.escapeHTML ARGF.read.toutf8
49
+ if opt[:tee]
50
+ b = ''
51
+ ARGF.each do |l|
52
+ print l
53
+ b += l
54
+ end
55
+ a = CGI.escapeHTML b
56
+ else
57
+ a = CGI.escapeHTML ARGF.read.toutf8
58
+ end
34
59
  a = a.gsub(/\r?\n/, "<br />\n")
35
60
 
36
- # NOTE: Currently "&nbsp;" doesn't work on ujihisa's environment.
37
- # This may be because of the font you use.
38
-
39
- a = a.gsub(/^(\s+)(.+)<br \/>$/) { '<p style="text-indent: ' + ($1.size/2.0).to_s + 'em;">' + $2 + '</p>' }
40
- a = a.gsub(/\s{2,}/) {|m| '&nbsp;'*(m.size*1.5).to_i }
41
61
  a = a.gsub(/.\x08/, '')
42
62
  a = a.gsub(/\x1b\[([0-9]*)m/) do
43
63
  case $1
@@ -67,13 +87,18 @@ def few(filetype = 'text')
67
87
  io.puts <<-EOF
68
88
  <html>
69
89
  <head>
70
- <title>few: #{ARGF.filename} (#{filetype})</title>
90
+ <title>few: #{ARGF.filename} (#{opt[:filetype].to_s})</title>
71
91
  <style type="text/css">
72
- p { margin: 0; }
92
+ body {
93
+ white-space: pre;
94
+ line-height: 7px;
95
+ font-size: 12pt;
96
+ font-family: "menlo regular", "monaco", "courier", monospace;
97
+ }
73
98
  </style>
74
99
  </head>
75
100
  <body>
76
- #{a}
101
+ #{a}
77
102
  </body>
78
103
  </html>
79
104
  EOF
@@ -88,19 +113,24 @@ end
88
113
 
89
114
  case ARGV[0]
90
115
  when '-h', '--help'
91
- puts "[USAGE]: few {filename}"
92
- puts " cat {filename} | few"
116
+ puts "[USAGE]: few [-h|--help|-v|--version|--selfupdate|--filetype=([a-zA-Z0-9]+)|-t|-T|--tee] [filename]"
117
+ puts "[EXAMPLES]: few {filename}"
118
+ puts " cat {filename} | few"
119
+ puts " make |& few --tee"
93
120
  when '-v', '--version'
94
- puts "0.0.1"
121
+ puts "0.0.2"
95
122
  when '--selfupdate'
96
123
  require 'open-uri'
97
- code = open('http://github.com/ujihisa/few/raw/master/few') {|io| io.read }
124
+ code = open('http://github.com/ujihisa/few/raw/master/bin/few') {|io| io.read }
98
125
  raise unless /^#!/ =~ code
99
126
  File.open(__FILE__, 'w') {|io| io.print code }
100
127
  system __FILE__, '-v'
101
128
  when /--filetype=([a-zA-Z0-9]+)/
102
129
  ARGV.shift
103
- few $1
130
+ few(:filetype => $1.to_sym)
131
+ when '--tee', '-t', '-T'
132
+ ARGV.shift
133
+ few(:tee => true, :filetype => :tee)
104
134
  else
105
135
  few
106
136
  end
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: few
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ujihisa
8
+ - Sora Harakami
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
12
 
12
- date: 2010-01-06 00:00:00 -08:00
13
+ date: 2010-02-21 00:00:00 -08:00
13
14
  default_executable:
14
15
  dependencies: []
15
16