Class: Grenweb::HTMLRendeler
- Inherits:
-
Object
- Object
- Grenweb::HTMLRendeler
- Includes:
- Rack::Utils
- Defined in:
- lib/grenweb/html_renderer.rb
Instance Method Summary collapse
- #empty_summary ⇒ Object
- #footer ⇒ Object
- #footer_home(package, files) ⇒ Object
- #fullpath(path) ⇒ Object
- #header(title, header1) ⇒ Object
- #header_home(title, header1, version) ⇒ Object
-
#initialize(script_name) ⇒ HTMLRendeler
constructor
A new instance of HTMLRendeler.
- #line(lineno, line, match_datas) ⇒ Object
- #link(keyword) ⇒ Object
- #match_strong(line, match_datas) ⇒ Object
- #pagination_link(page, label) ⇒ Object
- #pagination_span(content) ⇒ Object
- #record_content(record) ⇒ Object
- #record_content_line(record) ⇒ Object
- #result_record(record, patterns, nth = 1) ⇒ Object
- #result_record_match_line(record, patterns, nth) ⇒ Object
- #sample_code ⇒ Object
- #search_box(text = "") ⇒ Object
- #search_summary(keyword, total_records, range, elapsed) ⇒ Object
- #view_summary(path, elapsed) ⇒ Object
Constructor Details
#initialize(script_name) ⇒ HTMLRendeler
Returns a new instance of HTMLRendeler.
16 17 18 |
# File 'lib/grenweb/html_renderer.rb', line 16 def initialize(script_name) @script_name = Pathname(script_name) end |
Instance Method Details
#empty_summary ⇒ Object
173 174 175 176 177 178 179 |
# File 'lib/grenweb/html_renderer.rb', line 173 def empty_summary() " <div class='search-summary'>\n<p>gren web\u691C\u7D22</p>\n </div>\n" end |
#footer ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/grenweb/html_renderer.rb', line 44 def "</div>\n\n<div class=\"footer\">\n</div>\n</body>\n</html>\n" end |
#footer_home(package, files) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/grenweb/html_renderer.rb', line 80 def (package, files) "</div>\n\n<div class=\"footer_home\">\n <!-- <a href=\"\#{fullpath('::search/p:*')}\">\#{package}</a>\u306E\u30D1\u30C3\u30B1\u30FC\u30B8 , -->\n <a href=\"\#{fullpath('::search/f:*')}\">\#{files}</a>\u306E\u30D5\u30A1\u30A4\u30EB<br>\n <a href=\"\#{fullpath('::help')}\">\u30D8\u30EB\u30D7</a> , \n <a href=\"http://ongaeshi.github.com/gren\">gren\u306B\u3064\u3044\u3066</a>\n</div>\n</div>\n</body>\n</html>\n" end |
#fullpath(path) ⇒ Object
233 234 235 236 237 238 239 |
# File 'lib/grenweb/html_renderer.rb', line 233 def fullpath(path) unless (path == '') (@script_name + path).to_s else @script_name.to_s end end |
#header(title, header1) ⇒ Object
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/grenweb/html_renderer.rb', line 20 def header(title, header1) "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"ja\" lang=\"ja\">\n<head>\n <meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\" />\n <!-- <meta name=\"robot\" content=\"noindex,nofollow\" /> -->\n <title>\#{title}</title>\n <link rel=\"stylesheet\" href=\"\#{fullpath('css/gren.css')}\" type=\"text/css\" media=\"all\" />\n</head>\n<body>\n<div class=\"header\">\n <h1>\n<a href=\"\#{fullpath('')}\"><img src=\"\#{fullpath('images/gren-icon-mini.png')}\" alt=\"gren-icon\" border=\"0\"/></a>\n\#{header1}\n </h1>\n</div>\n\n<div class=\"content\">\n" end |
#header_home(title, header1, version) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/grenweb/html_renderer.rb', line 55 def header_home(title, header1, version) "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"ja\" lang=\"ja\">\n<head>\n <meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\" />\n <!-- <meta name=\"robot\" content=\"noindex,nofollow\" /> -->\n <title>\#{title}</title>\n <link rel=\"stylesheet\" href=\"\#{fullpath('css/gren.css')}\" type=\"text/css\" media=\"all\" />\n</head>\n<body>\n<div align=\"center\">\n<div class=\"header_home\">\n <h1>\n<a href=\"\#{fullpath('')}\"><img src=\"\#{fullpath('images/gren-icon.png')}\" alt=\"gren-icon\" border=\"0\" height=\"100px\"/></a>\n\#{header1} <font class=\"version\">\#{version}</font>\n </h1>\n</div>\n\n<div class=\"content\">\n" end |
#line(lineno, line, match_datas) ⇒ Object
152 153 154 |
# File 'lib/grenweb/html_renderer.rb', line 152 def line(lineno, line, match_datas) sprintf("%5d: %s", lineno, match_strong(Rack::Utils::escape_html(line), match_datas)) end |
#link(keyword) ⇒ Object
229 230 231 |
# File 'lib/grenweb/html_renderer.rb', line 229 def link(keyword) "<a href='#{fullpath('::search' + '/' + Rack::Utils::escape_html(keyword))}'>#{keyword}</a>" end |
#match_strong(line, match_datas) ⇒ Object
156 157 158 159 160 161 162 |
# File 'lib/grenweb/html_renderer.rb', line 156 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 |
#pagination_link(page, label) ⇒ Object
164 165 166 167 |
# File 'lib/grenweb/html_renderer.rb', line 164 def pagination_link(page, label) href = "?page=#{page}" pagination_span("<a href='#{href}'>#{label}</a>") end |
#pagination_span(content) ⇒ Object
169 170 171 |
# File 'lib/grenweb/html_renderer.rb', line 169 def pagination_span(content) "<span class='pagination-link'>#{content}</span>\n" end |
#record_content(record) ⇒ Object
133 134 135 136 137 138 139 |
# File 'lib/grenweb/html_renderer.rb', line 133 def record_content(record) "<pre>\n\#{record_content_line(record)}\n</pre>\n" end |
#record_content_line(record) ⇒ Object
141 142 143 144 145 146 147 148 149 150 |
# File 'lib/grenweb/html_renderer.rb', line 141 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 |
#result_record(record, patterns, nth = 1) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/grenweb/html_renderer.rb', line 96 def result_record(record, patterns, nth=1) if (patterns.size > 0) "<dt class='result-record'><a href='\#{fullpath(\"::view/\" + Rack::Utils::escape_html(record.shortpath))}'>\#{record.shortpath}</a></dt>\n<dd>\n <pre class='lines'>\n\#{result_record_match_line(record, patterns, nth)}\n </pre>\n</dd>\n" else "<dt class='result-record'><a href='\#{fullpath(\"::view/\" + Rack::Utils::escape_html(record.shortpath))}'>\#{record.shortpath}</a></dt>\n" end end |
#result_record_match_line(record, patterns, nth) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/grenweb/html_renderer.rb', line 113 def result_record_match_line(record, patterns, nth) str = "" grep = Grep.new(record.content) lines = grep.match_lines_or(patterns) unless (lines.empty?) index = lines[0].index (index - nth..index + nth).each do |i| if (0 <= i && i < grep.content.size) match_datas = (i == index) ? lines[0].match_datas : [] str << line(i + 1, grep.content[i], match_datas) + "\n" end end end str end |
#sample_code ⇒ Object
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/grenweb/html_renderer.rb', line 210 def sample_code " <div class='sample-code'>\n <ol>\n<li>\u30AD\u30FC\u30EF\u30FC\u30C9\u3067\u691C\u7D22<br>\n \#{link('def open')}\n<li>\uFF11\u30D5\u30EC\u30FC\u30BA\u3068\u3057\u3066\u691C\u7D22<br>\n \#{link('\"def open\"')}\n<li>\u30D1\u30C3\u30B1\u30FC\u30B8\u540D\u3067\u7D5E\u308A\u8FBC\u307F<br>\n \#{link('def open p:gren')}\n<li>\u30D5\u30A1\u30A4\u30EB\u540D\u3084\u62E1\u5F35\u5B50\u3067\u7D5E\u308A\u8FBC\u307F<br>\n \#{link('def open f:test s:rb')}\n<li>\u7D44\u307F\u5408\u308F\u305B<br>\n \#{link('p:gren p:tidtools s:rb f:test assert f:cli')}\n </ol>\n </div>\n" end |
#search_box(text = "") ⇒ Object
199 200 201 202 203 204 205 206 207 208 |
# File 'lib/grenweb/html_renderer.rb', line 199 def search_box(text = "") "<form method=\"post\" action=\"\#{fullpath('::search')}\">\n <p>\n<input name=\"query\" type=\"text\" size=\"60\" value=\"\#{text}\" />\n<input type=\"submit\" value=\"\u691C\u7D22\" />\n </p>\n</form>\n" end |
#search_summary(keyword, total_records, range, elapsed) ⇒ Object
181 182 183 184 185 186 187 188 189 |
# File 'lib/grenweb/html_renderer.rb', line 181 def search_summary(keyword, total_records, range, elapsed) " <div class='search-summary'>\n<span class=\"keyword\">\#{keyword}</span>\u306E\u691C\u7D22\u7D50\u679C:\n<span class=\"total-entries\">\#{total_records}</span>\u4EF6\u4E2D\n<span class=\"display-range\">\#{range.first} - \#{range.last}</span>\u4EF6\uFF08\#{elapsed}\u79D2\uFF09\n </div>\n" end |
#view_summary(path, elapsed) ⇒ Object
191 192 193 194 195 196 197 |
# File 'lib/grenweb/html_renderer.rb', line 191 def view_summary(path, elapsed) " <div class='search-summary'>\n<span class=\"keyword\">\#{path}</span>\uFF08\#{elapsed}\u79D2\uFF09\n </div>\n" end |