gren 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,8 @@
1
+ === 0.3.1 2010/11/20
2
+
3
+ * grenweb
4
+ * 相対パスで動作するように
5
+
1
6
  === 0.3.0 2010/11/02
2
7
 
3
8
  * grenweb
@@ -1,3 +1,7 @@
1
+ === 0.3.1 2010/11/20
2
+
3
+ * grenweb
4
+
1
5
  === 0.3.0 2010/11/02
2
6
 
3
7
  * grenweb
@@ -7,5 +7,5 @@ require 'rubygems'
7
7
  require File.expand_path(File.dirname(__FILE__) + "/../lib/gren")
8
8
  require "grenweb/cli"
9
9
 
10
- Version = "0.3.0"
10
+ Version = "0.3.1"
11
11
  Grenweb::CLI.execute(STDOUT, ARGV)
@@ -2,5 +2,5 @@ $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
4
  module Gren
5
- VERSION = '0.3.0'
5
+ VERSION = '0.3.1'
6
6
  end
@@ -15,6 +15,7 @@ module Grenweb
15
15
  include Rack::Utils
16
16
 
17
17
  def call(env)
18
+ @env = env
18
19
  @request = Rack::Request.new(env)
19
20
  @query = Query.new(@request)
20
21
 
@@ -27,9 +28,10 @@ module Grenweb
27
28
  private
28
29
 
29
30
  def render
30
- @response.write HTMLRendeler.header("gren - help", "gren - help")
31
- @response.write HTMLRendeler.sample_code
32
- @response.write HTMLRendeler.footer
31
+ r = HTMLRendeler.new(@request.script_name + '/..')
32
+ @response.write r.header("gren - help", "gren - help")
33
+ @response.write r.sample_code
34
+ @response.write r.footer
33
35
  @response.to_a
34
36
  end
35
37
  end
@@ -15,6 +15,7 @@ module Grenweb
15
15
  include Rack::Utils
16
16
 
17
17
  def call(env)
18
+ @env = env
18
19
  @request = Rack::Request.new(env)
19
20
  @query = Query.new(@request)
20
21
 
@@ -27,9 +28,10 @@ module Grenweb
27
28
  private
28
29
 
29
30
  def render
30
- @response.write HTMLRendeler.header_home("gren", "gren", Version)
31
- @response.write HTMLRendeler.search_box
32
- @response.write HTMLRendeler.footer_home("??", Database.instance.fileNum)
31
+ r = HTMLRendeler.new(@request.script_name)
32
+ @response.write r.header_home("gren", "gren", Version)
33
+ @response.write r.search_box
34
+ @response.write r.footer_home("??", Database.instance.fileNum)
33
35
  @response.to_a
34
36
  end
35
37
  end
@@ -13,7 +13,11 @@ module Grenweb
13
13
  class HTMLRendeler
14
14
  include Rack::Utils
15
15
 
16
- def self.header(title, header1)
16
+ def initialize(script_name)
17
+ @script_name = Pathname(script_name)
18
+ end
19
+
20
+ def header(title, header1)
17
21
  <<EOS
18
22
  <?xml version="1.0" encoding="utf-8"?>
19
23
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
@@ -23,12 +27,12 @@ module Grenweb
23
27
  <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
24
28
  <!-- <meta name="robot" content="noindex,nofollow" /> -->
25
29
  <title>#{title}</title>
26
- <link rel="stylesheet" href="/css/gren.css" type="text/css" media="all" />
30
+ <link rel="stylesheet" href="#{fullpath('css/gren.css')}" type="text/css" media="all" />
27
31
  </head>
28
32
  <body>
29
33
  <div class="header">
30
34
  <h1>
31
- <a href="/"><img src="/images/gren-icon-mini.png" alt="gren-icon" border="0"/></a>
35
+ <a href="#{fullpath('')}"><img src="#{fullpath('images/gren-icon-mini.png')}" alt="gren-icon" border="0"/></a>
32
36
  #{header1}
33
37
  </h1>
34
38
  </div>
@@ -37,7 +41,7 @@ module Grenweb
37
41
  EOS
38
42
  end
39
43
 
40
- def self.footer
44
+ def footer
41
45
  <<EOS
42
46
  </div>
43
47
 
@@ -48,7 +52,7 @@ EOS
48
52
  EOS
49
53
  end
50
54
 
51
- def self.header_home(title, header1, version)
55
+ def header_home(title, header1, version)
52
56
  <<EOS
53
57
  <?xml version="1.0" encoding="utf-8"?>
54
58
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
@@ -58,13 +62,13 @@ EOS
58
62
  <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
59
63
  <!-- <meta name="robot" content="noindex,nofollow" /> -->
60
64
  <title>#{title}</title>
61
- <link rel="stylesheet" href="/css/gren.css" type="text/css" media="all" />
65
+ <link rel="stylesheet" href="#{fullpath('css/gren.css')}" type="text/css" media="all" />
62
66
  </head>
63
67
  <body>
64
68
  <div align="center">
65
69
  <div class="header_home">
66
70
  <h1>
67
- <a href="/"><img src="/images/gren-icon.png" alt="gren-icon" border="0" height="100px"/></a>
71
+ <a href="#{fullpath('')}"><img src="#{fullpath('images/gren-icon.png')}" alt="gren-icon" border="0" height="100px"/></a>
68
72
  #{header1} <font class="version">#{version}</font>
69
73
  </h1>
70
74
  </div>
@@ -73,14 +77,14 @@ EOS
73
77
  EOS
74
78
  end
75
79
 
76
- def self.footer_home(package, files)
80
+ def footer_home(package, files)
77
81
  <<EOS
78
82
  </div>
79
83
 
80
84
  <div class="footer_home">
81
- <!-- <a href="/::search/p:*">#{package}</a>のパッケージ , -->
82
- <a href="/::search/f:*">#{files}</a>のファイル<br>
83
- <a href="/::help">ヘルプ</a> ,
85
+ <!-- <a href="#{fullpath('::search/p:*')}">#{package}</a>のパッケージ , -->
86
+ <a href="#{fullpath('::search/f:*')}">#{files}</a>のファイル<br>
87
+ <a href="#{fullpath('::help')}">ヘルプ</a> ,
84
88
  <a href="http://ongaeshi.github.com/gren">grenについて</a>
85
89
  </div>
86
90
  </div>
@@ -89,10 +93,10 @@ EOS
89
93
  EOS
90
94
  end
91
95
 
92
- def self.result_record(record, patterns, nth=1)
96
+ def result_record(record, patterns, nth=1)
93
97
  if (patterns.size > 0)
94
98
  <<EOS
95
- <dt class='result-record'><a href='#{"/::view/" + Rack::Utils::escape_html(record.shortpath)}'>#{record.shortpath}</a></dt>
99
+ <dt class='result-record'><a href='#{fullpath("::view/" + Rack::Utils::escape_html(record.shortpath))}'>#{record.shortpath}</a></dt>
96
100
  <dd>
97
101
  <pre class='lines'>
98
102
  #{result_record_match_line(record, patterns, nth)}
@@ -101,12 +105,12 @@ EOS
101
105
  EOS
102
106
  else
103
107
  <<EOS
104
- <dt class='result-record'><a href='#{"/::view/" + Rack::Utils::escape_html(record.shortpath)}'>#{record.shortpath}</a></dt>
108
+ <dt class='result-record'><a href='#{fullpath("::view/" + Rack::Utils::escape_html(record.shortpath))}'>#{record.shortpath}</a></dt>
105
109
  EOS
106
110
  end
107
111
  end
108
112
 
109
- def self.result_record_match_line(record, patterns, nth)
113
+ def result_record_match_line(record, patterns, nth)
110
114
  str = ""
111
115
 
112
116
  grep = Grep.new(record.content)
@@ -126,7 +130,7 @@ EOS
126
130
  str
127
131
  end
128
132
 
129
- def self.record_content(record)
133
+ def record_content(record)
130
134
  <<EOS
131
135
  <pre>
132
136
  #{record_content_line(record)}
@@ -134,7 +138,7 @@ EOS
134
138
  EOS
135
139
  end
136
140
 
137
- def self.record_content_line(record)
141
+ def record_content_line(record)
138
142
  str = ""
139
143
 
140
144
  grep = Grep.new(record.content)
@@ -145,11 +149,11 @@ EOS
145
149
  str
146
150
  end
147
151
 
148
- def self.line(lineno, line, match_datas)
152
+ def line(lineno, line, match_datas)
149
153
  sprintf("%5d: %s", lineno, match_strong(Rack::Utils::escape_html(line), match_datas))
150
154
  end
151
155
 
152
- def self.match_strong(line, match_datas)
156
+ def match_strong(line, match_datas)
153
157
  match_datas.each do |m|
154
158
  line = line.split(m[0]).join('<strong>' + m[0] + '</strong>') unless (m.nil?)
155
159
  end
@@ -157,16 +161,16 @@ EOS
157
161
  line
158
162
  end
159
163
 
160
- def self.pagination_link(page, label)
164
+ def pagination_link(page, label)
161
165
  href = "?page=#{page}"
162
166
  pagination_span("<a href='#{href}'>#{label}</a>")
163
167
  end
164
168
 
165
- def self.pagination_span(content)
169
+ def pagination_span(content)
166
170
  "<span class='pagination-link'>#{content}</span>\n"
167
171
  end
168
172
 
169
- def self.empty_summary()
173
+ def empty_summary()
170
174
  <<EOS
171
175
  <div class='search-summary'>
172
176
  <p>gren web検索</p>
@@ -174,7 +178,7 @@ EOS
174
178
  EOS
175
179
  end
176
180
 
177
- def self.search_summary(keyword, total_records, range, elapsed)
181
+ def search_summary(keyword, total_records, range, elapsed)
178
182
  <<EOS
179
183
  <div class='search-summary'>
180
184
  <span class="keyword">#{keyword}</span>の検索結果:
@@ -184,7 +188,7 @@ EOS
184
188
  EOS
185
189
  end
186
190
 
187
- def self.view_summary(path, elapsed)
191
+ def view_summary(path, elapsed)
188
192
  <<EOS
189
193
  <div class='search-summary'>
190
194
  <span class="keyword">#{path}</span>(#{elapsed}秒)
@@ -192,9 +196,9 @@ EOS
192
196
  EOS
193
197
  end
194
198
 
195
- def self.search_box(text = "")
199
+ def search_box(text = "")
196
200
  <<EOS
197
- <form method="post" action="/::search">
201
+ <form method="post" action="#{fullpath('::search')}">
198
202
  <p>
199
203
  <input name="query" type="text" size="60" value="#{text}" />
200
204
  <input type="submit" value="検索" />
@@ -203,7 +207,7 @@ EOS
203
207
  EOS
204
208
  end
205
209
 
206
- def self.sample_code
210
+ def sample_code
207
211
  <<EOS
208
212
  <div class='sample-code'>
209
213
  <ol>
@@ -222,8 +226,16 @@ EOS
222
226
  EOS
223
227
  end
224
228
 
225
- def self.link(keyword)
226
- "<a href='/::search/#{Rack::Utils::escape_html(keyword)}'>#{keyword}</a>"
229
+ def link(keyword)
230
+ "<a href='#{fullpath('::search' + '/' + Rack::Utils::escape_html(keyword))}'>#{keyword}</a>"
231
+ end
232
+
233
+ def fullpath(path)
234
+ unless (path == '')
235
+ (@script_name + path).to_s
236
+ else
237
+ @script_name.to_s
238
+ end
227
239
  end
228
240
  end
229
241
  end
@@ -26,6 +26,8 @@ module Grenweb
26
26
 
27
27
  @nth = 3 # マッチした行の前後何行を表示するか
28
28
 
29
+ @rendeler = HTMLRendeler.new(@request.script_name + '/..')
30
+
29
31
  if @request.post? or @request['query']
30
32
  post_request
31
33
  else
@@ -55,27 +57,27 @@ module Grenweb
55
57
  end
56
58
 
57
59
  def render_header
58
- @response.write HTMLRendeler.header("gren : #{@query.escape_html}", "gren")
60
+ @response.write @rendeler.header("gren : #{@query.escape_html}", "gren")
59
61
  end
60
62
 
61
63
  def render_search_box
62
- @response.write HTMLRendeler.search_box(@query.escape_html)
64
+ @response.write @rendeler.search_box(@query.escape_html)
63
65
  end
64
66
 
65
67
  def render_search_result
66
68
  if @query.empty?
67
- @response.write HTMLRendeler.empty_summary
69
+ @response.write @rendeler.empty_summary
68
70
  else
69
71
  records, total_records, elapsed = Database.instance.search(@query.keywords, @query.packages, @query.fpaths, @query.suffixs, calcPage, calcLimit)
70
72
  render_search_summary(records, total_records, elapsed)
71
- records.each { |record| @response.write(HTMLRendeler.result_record(record, @query.keywords, @nth)) }
73
+ records.each { |record| @response.write(@rendeler.result_record(record, @query.keywords, @nth)) }
72
74
  render_pagination(calcPage, total_records)
73
75
  end
74
76
  end
75
77
 
76
78
  def render_search_summary(records, total_records, elapsed)
77
79
  pageStart = calcPage * calcLimit
78
- @response.write HTMLRendeler.search_summary(@query.query_string,
80
+ @response.write @rendeler.search_summary(@query.query_string,
79
81
  total_records,
80
82
  (total_records.zero? ? 0 : pageStart + 1)..(pageStart + records.size),
81
83
  elapsed)
@@ -88,23 +90,23 @@ module Grenweb
88
90
  last_page = (total_records / calcLimit.to_f).ceil
89
91
  @response.write("<div class='pagination'>\n")
90
92
  if page > 0
91
- @response.write(HTMLRendeler.pagination_link(page - 1, "<<"))
93
+ @response.write(@rendeler.pagination_link(page - 1, "<<"))
92
94
  end
93
95
  last_page.times do |i|
94
96
  if i == page
95
- @response.write(HTMLRendeler.pagination_span(i))
97
+ @response.write(@rendeler.pagination_span(i))
96
98
  else
97
- @response.write(HTMLRendeler.pagination_link(i, i))
99
+ @response.write(@rendeler.pagination_link(i, i))
98
100
  end
99
101
  end
100
102
  if page < (last_page - 1)
101
- @response.write(HTMLRendeler.pagination_link(page + 1, ">>"))
103
+ @response.write(@rendeler.pagination_link(page + 1, ">>"))
102
104
  end
103
105
  @response.write("</div>\n")
104
106
  end
105
107
 
106
108
  def render_footer
107
- @response.write HTMLRendeler.footer
109
+ @response.write @rendeler.footer
108
110
  end
109
111
 
110
112
  private
@@ -7,6 +7,7 @@
7
7
 
8
8
  require 'rack'
9
9
  require File.join(File.dirname(__FILE__), 'database')
10
+ require File.join(File.dirname(__FILE__), 'html_renderer')
10
11
 
11
12
  module Grenweb
12
13
  class Viewer
@@ -22,17 +23,19 @@ module Grenweb
22
23
 
23
24
  record, elapsed = Database.instance.record(req2query)
24
25
 
26
+ @rendeler = HTMLRendeler.new(@request.script_name + '/..')
27
+
25
28
  if (record)
26
- @response.write HTMLRendeler.header("gren : #{record.shortpath}", "gren")
27
- @response.write HTMLRendeler.search_box("")
28
- @response.write HTMLRendeler.view_summary(record.shortpath, elapsed)
29
- @response.write HTMLRendeler.record_content(record)
29
+ @response.write @rendeler.header("gren : #{record.shortpath}", "gren")
30
+ @response.write @rendeler.search_box("")
31
+ @response.write @rendeler.view_summary(record.shortpath, elapsed)
32
+ @response.write @rendeler.record_content(record)
30
33
  else
31
- @response.write HTMLRendeler.header("gren : not found.", "gren")
32
- @response.write HTMLRendeler.search_box("")
33
- @response.write HTMLRendeler.empty_summary
34
+ @response.write @rendeler.header("gren : not found.", "gren")
35
+ @response.write @rendeler.search_box("")
36
+ @response.write @rendeler.empty_summary
34
37
  end
35
- @response.write HTMLRendeler.footer
38
+ @response.write @rendeler.footer
36
39
 
37
40
  @response.to_a
38
41
  end
@@ -40,14 +43,9 @@ module Grenweb
40
43
  private
41
44
 
42
45
  def req2query
46
+ p @request.path_info
43
47
  unescape(@request.path_info.gsub(/\A\/|\/z/, ''))
44
48
  end
45
49
 
46
- def req2path(component='')
47
- path = []
48
- path << ((@request.script_name == "") ? '/' : @request.script_name)
49
- path << component if (component)
50
- path.join('/')
51
- end
52
50
  end
53
51
  end
@@ -6,14 +6,15 @@ class TestGrenwebHTMLRendeler < Test::Unit::TestCase
6
6
  include Grenweb
7
7
 
8
8
  def setup
9
+ @rendeler = HTMLRendeler.new('/')
9
10
  end
10
11
 
11
12
  def test_pagination_line
12
- assert_equal("<span class='pagination-link'><a href='?page=1'>test</a></span>\n", HTMLRendeler.pagination_link(1, "test"))
13
+ assert_equal("<span class='pagination-link'><a href='?page=1'>test</a></span>\n", @rendeler.pagination_link(1, "test"))
13
14
  end
14
15
 
15
16
  def test_search_summary
16
- assert_equal(HTMLRendeler.search_summary(10, 500, 10..20, 0.00893),
17
+ assert_equal(@rendeler.search_summary(10, 500, 10..20, 0.00893),
17
18
  <<-EOS)
18
19
  <div class='search-summary'>
19
20
  <span class="keyword">10</span>の検索結果:
@@ -24,11 +25,11 @@ EOS
24
25
  end
25
26
 
26
27
  def test_match_strong
27
- assert_equal(HTMLRendeler.match_strong("This is line.", [nil, nil]), "This is line.")
28
+ assert_equal(@rendeler.match_strong("This is line.", [nil, nil]), "This is line.")
28
29
  end
29
30
 
30
31
  def test_search_box
31
- assert_equal(HTMLRendeler.search_box('test must'), <<-EOF)
32
+ assert_equal(@rendeler.search_box('test must'), <<-EOF)
32
33
  <form method="post" action="/::search">
33
34
  <p>
34
35
  <input name="query" type="text" size="60" value="test must" />
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 0
9
- version: 0.3.0
8
+ - 1
9
+ version: 0.3.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - ongaeshi
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-11-02 00:00:00 +09:00
17
+ date: 2010-11-20 00:00:00 +09:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency