lib/grenweb/html_renderer.rb in gren-0.3.0 vs lib/grenweb/html_renderer.rb in gren-0.3.1

- old
+ new

@@ -11,104 +11,108 @@ module Grenweb class HTMLRendeler include Rack::Utils - def self.header(title, header1) + def initialize(script_name) + @script_name = Pathname(script_name) + end + + def header(title, header1) <<EOS <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja"> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <!-- <meta name="robot" content="noindex,nofollow" /> --> <title>#{title}</title> - <link rel="stylesheet" href="/css/gren.css" type="text/css" media="all" /> + <link rel="stylesheet" href="#{fullpath('css/gren.css')}" type="text/css" media="all" /> </head> <body> <div class="header"> <h1> - <a href="/"><img src="/images/gren-icon-mini.png" alt="gren-icon" border="0"/></a> + <a href="#{fullpath('')}"><img src="#{fullpath('images/gren-icon-mini.png')}" alt="gren-icon" border="0"/></a> #{header1} </h1> </div> <div class="content"> EOS end - def self.footer + def footer <<EOS </div> <div class="footer"> </div> </body> </html> EOS end - def self.header_home(title, header1, version) + def header_home(title, header1, version) <<EOS <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja"> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <!-- <meta name="robot" content="noindex,nofollow" /> --> <title>#{title}</title> - <link rel="stylesheet" href="/css/gren.css" type="text/css" media="all" /> + <link rel="stylesheet" href="#{fullpath('css/gren.css')}" type="text/css" media="all" /> </head> <body> <div align="center"> <div class="header_home"> <h1> - <a href="/"><img src="/images/gren-icon.png" alt="gren-icon" border="0" height="100px"/></a> + <a href="#{fullpath('')}"><img src="#{fullpath('images/gren-icon.png')}" alt="gren-icon" border="0" height="100px"/></a> #{header1} <font class="version">#{version}</font> </h1> </div> <div class="content"> EOS end - def self.footer_home(package, files) + def footer_home(package, files) <<EOS </div> <div class="footer_home"> - <!-- <a href="/::search/p:*">#{package}</a>のパッケージ , --> - <a href="/::search/f:*">#{files}</a>のファイル<br> - <a href="/::help">ヘルプ</a> , + <!-- <a href="#{fullpath('::search/p:*')}">#{package}</a>のパッケージ , --> + <a href="#{fullpath('::search/f:*')}">#{files}</a>のファイル<br> + <a href="#{fullpath('::help')}">ヘルプ</a> , <a href="http://ongaeshi.github.com/gren">grenについて</a> </div> </div> </body> </html> EOS end - def self.result_record(record, patterns, nth=1) + def result_record(record, patterns, nth=1) if (patterns.size > 0) <<EOS - <dt class='result-record'><a href='#{"/::view/" + Rack::Utils::escape_html(record.shortpath)}'>#{record.shortpath}</a></dt> + <dt class='result-record'><a href='#{fullpath("::view/" + Rack::Utils::escape_html(record.shortpath))}'>#{record.shortpath}</a></dt> <dd> <pre class='lines'> #{result_record_match_line(record, patterns, nth)} </pre> </dd> EOS else <<EOS - <dt class='result-record'><a href='#{"/::view/" + Rack::Utils::escape_html(record.shortpath)}'>#{record.shortpath}</a></dt> + <dt class='result-record'><a href='#{fullpath("::view/" + Rack::Utils::escape_html(record.shortpath))}'>#{record.shortpath}</a></dt> EOS end end - def self.result_record_match_line(record, patterns, nth) + def result_record_match_line(record, patterns, nth) str = "" grep = Grep.new(record.content) lines = grep.match_lines_or(patterns) @@ -124,88 +128,88 @@ end str end - def self.record_content(record) + def record_content(record) <<EOS <pre> #{record_content_line(record)} </pre> EOS end - def self.record_content_line(record) + def record_content_line(record) str = "" grep = Grep.new(record.content) grep.content.each_with_index do |l, index| str << line(index + 1, l, []) + "\n" end str end - def self.line(lineno, line, match_datas) + def line(lineno, line, match_datas) sprintf("%5d: %s", lineno, match_strong(Rack::Utils::escape_html(line), match_datas)) end - def self.match_strong(line, match_datas) + def match_strong(line, match_datas) match_datas.each do |m| line = line.split(m[0]).join('<strong>' + m[0] + '</strong>') unless (m.nil?) end line end - def self.pagination_link(page, label) + def pagination_link(page, label) href = "?page=#{page}" pagination_span("<a href='#{href}'>#{label}</a>") end - def self.pagination_span(content) + def pagination_span(content) "<span class='pagination-link'>#{content}</span>\n" end - def self.empty_summary() + def empty_summary() <<EOS <div class='search-summary'> <p>gren web検索</p> </div> EOS end - def self.search_summary(keyword, total_records, range, elapsed) + def search_summary(keyword, total_records, range, elapsed) <<EOS <div class='search-summary'> <span class="keyword">#{keyword}</span>の検索結果: <span class="total-entries">#{total_records}</span>件中 <span class="display-range">#{range.first} - #{range.last}</span>件(#{elapsed}秒) </div> EOS end - def self.view_summary(path, elapsed) + def view_summary(path, elapsed) <<EOS <div class='search-summary'> <span class="keyword">#{path}</span>(#{elapsed}秒) </div> EOS end - def self.search_box(text = "") + def search_box(text = "") <<EOS -<form method="post" action="/::search"> +<form method="post" action="#{fullpath('::search')}"> <p> <input name="query" type="text" size="60" value="#{text}" /> <input type="submit" value="検索" /> </p> </form> EOS end - def self.sample_code + def sample_code <<EOS <div class='sample-code'> <ol> <li>キーワードで検索<br> #{link('def open')} @@ -220,11 +224,19 @@ </ol> </div> EOS end - def self.link(keyword) - "<a href='/::search/#{Rack::Utils::escape_html(keyword)}'>#{keyword}</a>" + def link(keyword) + "<a href='#{fullpath('::search' + '/' + Rack::Utils::escape_html(keyword))}'>#{keyword}</a>" + end + + def fullpath(path) + unless (path == '') + (@script_name + path).to_s + else + @script_name.to_s + end end end end