as_foo 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +30 -2
- data/lib/as_foo/as_html.rb +15 -3
- data/lib/as_foo/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15806f9b676702f523658aa4b6fa37b9aa7a36c0
|
4
|
+
data.tar.gz: d31a85c8805a37da5f5cf491a83a93a16eaf687b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3bfc53849c17db94c6a5d2c717f7a13bc79e36cc25799abf37d99496ae9daf9e22bcbff31792526954f03fd18e319669da4519d807acad94b457b32b2995f2a0
|
7
|
+
data.tar.gz: e81e7ad3cf1f15f1bd5d7ad2fee5f7f64a58191558b79cb9ce581fd02ce9446ff4ebafff31afde7d02b160c5180f6f568660f19cb34fd1507efec1ca4dfbc6b6
|
data/README.md
CHANGED
@@ -18,16 +18,21 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
$ gem install as_foo
|
20
20
|
|
21
|
+
## Requirement
|
22
|
+
|
23
|
+
- `w3m`, `lynx`, `links` or `elinks` command to use `as_html` (The command used to render html is autodetected.)
|
24
|
+
- `redcarpet` gem to use `as_markdown`
|
25
|
+
|
21
26
|
## Usage
|
22
27
|
|
23
28
|
```
|
24
29
|
>> require 'as_foo'
|
25
30
|
=> true
|
26
|
-
>> md = <<
|
31
|
+
>> md = <<MARKDOWN
|
27
32
|
# Sample
|
28
33
|
- a
|
29
34
|
- b
|
30
|
-
|
35
|
+
MARKDOWN
|
31
36
|
=> "# Sample\n- a\n- b\n"
|
32
37
|
>> md.as_markdown
|
33
38
|
=> "<h1>Sample</h1>\n\n<ul>\n<li>a</li>\n<li>b</li>\n</ul>\n"
|
@@ -63,6 +68,29 @@ Japan
|
|
63
68
|
(C) 2013 - Privacy & Terms
|
64
69
|
|
65
70
|
=> nil
|
71
|
+
|
72
|
+
>> open("https://www.google.com/?hl=en").read.as_html(with: :lynx)
|
73
|
+
|
74
|
+
Search Images Maps Play YouTube Gmail Drive Calendar More ?
|
75
|
+
Web History | Settings | Sign in
|
76
|
+
|
77
|
+
|
78
|
+
[chrome-48.png] A faster way to browse the web
|
79
|
+
Install Google Chrome
|
80
|
+
|
81
|
+
与謝野晶子 生誕 136
|
82
|
+
周年
|
83
|
+
|
84
|
+
|
85
|
+
_________________________________________________________
|
86
|
+
Google Search I'm Feeling Lucky Advanced searchLanguage tools
|
87
|
+
|
88
|
+
Google.co.jp offered in: 日本語
|
89
|
+
|
90
|
+
Advertising ProgramsBusiness SolutionsAbout GoogleGoogle.com
|
91
|
+
|
92
|
+
? 2013 - Privacy & Terms
|
93
|
+
=> nil
|
66
94
|
```
|
67
95
|
|
68
96
|
|
data/lib/as_foo/as_html.rb
CHANGED
@@ -2,9 +2,21 @@ require 'tempfile'
|
|
2
2
|
|
3
3
|
module AsFoo
|
4
4
|
module AsHtml
|
5
|
+
class << self
|
6
|
+
def available_pager
|
7
|
+
@@_as_foo_html_pager ||= %i(w3m elinks lynx links).find {|command|
|
8
|
+
system("which #{command}", out: "/dev/null", err: "/dev/null")
|
9
|
+
}
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
5
13
|
# @return [String] converted string
|
6
|
-
def as_html(with:
|
7
|
-
|
14
|
+
def as_html(with: nil, options: nil)
|
15
|
+
pager = with || AsHtml.available_pager
|
16
|
+
|
17
|
+
raise "could not find available pager command" unless pager
|
18
|
+
|
19
|
+
case pager
|
8
20
|
when :w3m
|
9
21
|
IO.popen("w3m -dump -T text/html", "w") do |w3m|
|
10
22
|
w3m.puts self.to_s
|
@@ -25,7 +37,7 @@ module AsFoo
|
|
25
37
|
elinks.puts self.to_s
|
26
38
|
end
|
27
39
|
else
|
28
|
-
raise ArgumentError.new("unexpected method #{
|
40
|
+
raise ArgumentError.new("unexpected method #{pager}")
|
29
41
|
end
|
30
42
|
end
|
31
43
|
end
|
data/lib/as_foo/version.rb
CHANGED