Module: AsFoo::AsHtml
- Included in:
- String
- Defined in:
- lib/as_foo/as_html.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#as_html(with: nil, options: nil) ⇒ String
Converted string.
Class Method Details
.available_pager ⇒ Object
6 7 8 9 10 |
# File 'lib/as_foo/as_html.rb', line 6 def available_pager @@_as_foo_html_pager ||= %i(w3m elinks lynx links).find {|command| system("which #{command}", out: "/dev/null", err: "/dev/null") } end |
Instance Method Details
#as_html(with: nil, options: nil) ⇒ String
Returns converted string.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/as_foo/as_html.rb', line 14 def as_html(with: nil, options: nil) pager = with || AsHtml.available_pager raise "could not find available pager command" unless pager case pager when :w3m IO.popen("w3m -dump -T text/html", "w") do |w3m| w3m.puts self.to_s end when :lynx IO.popen("lynx -dump -nonumbers -nolist -stdin", "w") do |lynx| lynx.puts self.to_s end when :links Tempfile.open ["as_foo", ".html"] do |src| src.puts self.to_s src.flush `links -dump #{src.path}` end when :elinks IO.popen("elinks -dump -no-numbering -no-references", "w") do |elinks| elinks.puts self.to_s end else raise ArgumentError.new("unexpected method #{pager}") end end |