Commit current state
This commit is contained in:
parent
b914b871b1
commit
e97db077c2
2
Gemfile
2
Gemfile
@ -1,2 +1,4 @@
|
||||
source "https://rubygems.org"
|
||||
gem "nokogiri"
|
||||
gem "colorize"
|
||||
gem "css_parser"
|
||||
|
10
Gemfile.lock
10
Gemfile.lock
@ -1,15 +1,23 @@
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
addressable (2.5.2)
|
||||
public_suffix (>= 2.0.2, < 4.0)
|
||||
colorize (0.8.1)
|
||||
css_parser (1.6.0)
|
||||
addressable
|
||||
mini_portile2 (2.3.0)
|
||||
nokogiri (1.8.2)
|
||||
mini_portile2 (~> 2.3.0)
|
||||
public_suffix (3.0.2)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
colorize
|
||||
css_parser
|
||||
nokogiri
|
||||
|
||||
BUNDLED WITH
|
||||
1.15.4
|
||||
1.16.1
|
||||
|
66
browse.rb
66
browse.rb
@ -1,4 +1,7 @@
|
||||
require "nokogiri"
|
||||
require "colorize"
|
||||
require "css_parser"
|
||||
include CssParser
|
||||
$mode=""
|
||||
pages={}
|
||||
|
||||
@ -6,49 +9,65 @@ pages["/"]=<<-ENDPAGE
|
||||
<html>
|
||||
<p>Welcome to my website!</p>
|
||||
<p><b>Bold</b></p>
|
||||
<p><i>Italics</b><p>
|
||||
<p><i>Italics</b></p>
|
||||
<p>
|
||||
<a href="/page">A page</a>
|
||||
<br>
|
||||
<a href="/anotherpage">Another page</a>
|
||||
</p>
|
||||
</html>
|
||||
ENDPAGE
|
||||
|
||||
pages["/page"]=<<-ENDPAGE
|
||||
<html>
|
||||
<p>A page</p>
|
||||
<p><b><i>Bold and Italic</i></b></p>
|
||||
<p><b><i>Bold and Italic</i>hi</b></p>
|
||||
<p>
|
||||
<a href="/">Home</a>
|
||||
<pr>
|
||||
<a href="/anotherpage">Another page</a>
|
||||
</p>
|
||||
</html>
|
||||
ENDPAGE
|
||||
|
||||
pages["/anotherpage"]=<<-ENDPAGE
|
||||
<html>
|
||||
<p>Here is more info</p>
|
||||
<p>
|
||||
<a href="/page">A page</a>
|
||||
<br>
|
||||
<a href="/">Home</a>
|
||||
</p>
|
||||
</html>
|
||||
ENDPAGE
|
||||
currentpage="/"
|
||||
|
||||
def showtext(text,nline=true)
|
||||
color_codes={
|
||||
:black => 0, :light_black => 30,
|
||||
:red => 1, :light_red => 61,
|
||||
:green => 2, :light_green => 62,
|
||||
:yellow => 3, :light_yellow => 63,
|
||||
:blue => 4, :light_blue => 64,
|
||||
:magenta => 5, :light_magenta => 65,
|
||||
:cyan => 6, :light_cyan => 66,
|
||||
:white => 7, :light_white => 67,
|
||||
:default => 9
|
||||
}
|
||||
def showtext(text)
|
||||
case $mode
|
||||
when "b"
|
||||
puts "\e[1m#{text}\e[0m" if nline
|
||||
print "\e[1m#{text}\e[0m" if !nline
|
||||
print "\e[1m"
|
||||
when "i"
|
||||
puts "\e[3m#{text}\e[0m" if nline
|
||||
print "\e[3m#{text}\e[0m" if !nline
|
||||
print "\e[3m"
|
||||
when "ib"
|
||||
puts "\e[1m\e[3m#{text}\e[0m" if nline
|
||||
print "\e[1m\e[3m#{text}\e[0m" if !nline
|
||||
when ""
|
||||
puts text if nline
|
||||
print text if !nline
|
||||
print "\e[1m"
|
||||
print "\e[3m"
|
||||
end
|
||||
print text
|
||||
print "\e[0m"
|
||||
end
|
||||
def dispelem(elem)
|
||||
if elem.class==Nokogiri::XML::Text
|
||||
showtext(elem)
|
||||
showtext(elem.to_s)
|
||||
return
|
||||
end
|
||||
case elem.name
|
||||
@ -56,10 +75,13 @@ def dispelem(elem)
|
||||
elem.children.each do |elem|
|
||||
dispelem(elem)
|
||||
end
|
||||
puts "\n"
|
||||
when "br"
|
||||
puts "\n"
|
||||
when "a"
|
||||
$links.push(elem["href"])
|
||||
showtext(elem.children[0],false)
|
||||
puts "[#{$linkid}]"
|
||||
showtext(elem.children[0])
|
||||
print "[#{$linkid}]"
|
||||
$linkid+=1
|
||||
when "b"
|
||||
if $mode=="i"
|
||||
@ -70,7 +92,11 @@ def dispelem(elem)
|
||||
elem.children.each do |elem|
|
||||
dispelem(elem)
|
||||
end
|
||||
$mode=""
|
||||
if $mode=="ib"
|
||||
$mode="i"
|
||||
else
|
||||
$mode=""
|
||||
end
|
||||
when "i"
|
||||
if $mode=="b"
|
||||
$mode="ib"
|
||||
@ -80,7 +106,11 @@ def dispelem(elem)
|
||||
elem.children.each do |elem|
|
||||
dispelem(elem)
|
||||
end
|
||||
$mode=""
|
||||
if $mode=="ib"
|
||||
$mode="b"
|
||||
else
|
||||
$mode=""
|
||||
end
|
||||
end
|
||||
end
|
||||
while true
|
||||
|
Loading…
Reference in New Issue
Block a user