Class: LameSitemapper::ReportGenerator
- Inherits:
-
Object
- Object
- LameSitemapper::ReportGenerator
- Defined in:
- lib/report_generator.rb
Constant Summary collapse
- INDENT =
" "
- XML_PROLOG =
<<-EOS <?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"> EOS
- XML_EPILOG =
"</urlset>"
- XML_NODE_TEMPLATE1 =
<<-EOS <url> <loc>%s</loc> </url> EOS
- XML_NODE_TEMPLATE2 =
<<-EOS <url> <loc>%s</loc> <changefreq>%s</changefreq> </url> EOS
- HTML_PROLOG =
<<-EOS <html> <head> <title>%s sitemap</title> </head> <body> <h1>Site %s</h1> EOS
- HTML_EPILOG =
<<-EOS </body> </html> EOS
Instance Method Summary collapse
-
#initialize(options, host) ⇒ ReportGenerator
constructor
A new instance of ReportGenerator.
- #to_graph(page) ⇒ Object
- #to_html(page) ⇒ Object
- #to_sitemap(page) ⇒ Object
- #to_test_yml(page) ⇒ Object
- #to_text(page) ⇒ Object
Constructor Details
#initialize(options, host) ⇒ ReportGenerator
Returns a new instance of ReportGenerator.
38 39 40 41 |
# File 'lib/report_generator.rb', line 38 def initialize , host @options = @host = host end |
Instance Method Details
#to_graph(page) ⇒ Object
96 97 98 99 100 |
# File 'lib/report_generator.rb', line 96 def to_graph(page) graph = Graphviz::Graph.new tree_to_graph(page, graph) graph.to_dot end |
#to_html(page) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/report_generator.rb', line 63 def to_html(page) out = [] out << HTML_PROLOG % [ page.path, page.path ] page.each do |p| out << "<h2>#{scraped_mark(p)}#{p.format_codes}<a href=\"#{p.path}\">#{p.path}</a></h2>\n" if p.scraped? out << "<h3>Images</h3>\n" if p.images.count > 0 p.images.each do |img| uri = UrlHelper.get_normalized_url(@host, img) out << "<div>\n" out << "<a href=\"#{uri}\">#{uri}</a>\n" out << "</div>\n" end out << "<h3>Links</h3>\n" if p.links.count > 0 p.links.each do |link| uri = UrlHelper.get_normalized_url(@host, link) out << "<div>\n" out << "<p>#{uri}</p>\n" out << "</div>\n" end out << "<h3>Scripts</h3>\n" if p.scripts.count > 0 p.scripts.each do |script| uri = UrlHelper.get_normalized_url(@host, script) out << "<div>\n" out << "<p>#{uri}</p>\n" out << "</div>\n" end end end out << HTML_EPILOG out.join end |
#to_sitemap(page) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/report_generator.rb', line 49 def to_sitemap(page) out = [] out << XML_PROLOG page.each do |p| if @options.frequency_type != :none out << XML_NODE_TEMPLATE2 % [ p.path, @options.frequency_type ] else out << XML_NODE_TEMPLATE1 % [ p.path ] end end out << XML_EPILOG out.join end |
#to_test_yml(page) ⇒ Object
102 103 104 105 106 |
# File 'lib/report_generator.rb', line 102 def to_test_yml(page) out = [] tree_to_test_yml(page, out) out.join end |
#to_text(page) ⇒ Object
43 44 45 46 47 |
# File 'lib/report_generator.rb', line 43 def to_text(page) out = [] tree_to_text(page, out) out.join end |