as_foo 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c8de3a11e04f746a2d53eb97928d39a6c6d07919
4
- data.tar.gz: 9465d20087508d53be79dfc29cac2c5db7ef5aa0
3
+ metadata.gz: 15806f9b676702f523658aa4b6fa37b9aa7a36c0
4
+ data.tar.gz: d31a85c8805a37da5f5cf491a83a93a16eaf687b
5
5
  SHA512:
6
- metadata.gz: 51c723d2f44906c77456200e8ee4b7d8a6435421a8c13c345f35136ee7aacf283602fc943659b3719c976aa577ae956d45fc9a94ab5967bff20bc00453bbd05b
7
- data.tar.gz: d4f7ebe561669887c46683975cbda3154947aafdf006a2a9981c56839305de15b3e21edeffb1e4543576fe23f934ef54ad0d3d488c466cdef325c4e895a2c215
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 = <<MD
31
+ >> md = <<MARKDOWN
27
32
  # Sample
28
33
  - a
29
34
  - b
30
- MD
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
+ &#19982;&#35613;&#37326;&#26230;&#23376; &#29983;&#35477; 136
82
+ &#21608;&#24180;
83
+
84
+
85
+ _________________________________________________________
86
+ Google Search I'm Feeling Lucky Advanced searchLanguage tools
87
+
88
+ Google.co.jp offered in: &#26085;&#26412;&#35486;
89
+
90
+ Advertising ProgramsBusiness SolutionsAbout GoogleGoogle.com
91
+
92
+ ? 2013 - Privacy & Terms
93
+ => nil
66
94
  ```
67
95
 
68
96
 
@@ -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: :w3m, options: nil)
7
- case with
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 #{with}")
40
+ raise ArgumentError.new("unexpected method #{pager}")
29
41
  end
30
42
  end
31
43
  end
@@ -1,3 +1,3 @@
1
1
  module AsFoo
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: as_foo
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
  - tmaeda