Skip to content

Instantly share code, notes, and snippets.

@miau
Created September 20, 2011 22:20
Show Gist options
  • Select an option

  • Save miau/1230597 to your computer and use it in GitHub Desktop.

Select an option

Save miau/1230597 to your computer and use it in GitHub Desktop.
patch for milkode to work on subdirectory
diff --git a/lib/milkode/cdweb/app.rb b/lib/milkode/cdweb/app.rb
index 839bae3..95390b0 100644
--- a/lib/milkode/cdweb/app.rb
+++ b/lib/milkode/cdweb/app.rb
@@ -17,14 +17,14 @@ require 'milkode/cdweb/lib/mkurl'
set :haml, :format => :html5
-get '/' do
+get '/milkode/' do
@version = "0.2.2"
@package_num = Database.instance.fileList('').size
@file_num = Database.instance.fileNum
haml :index
end
-post '/search*' do
+post '/milkode/search*' do
path = unescape(params[:pathname])
case params[:shead]
@@ -34,10 +34,10 @@ post '/search*' do
path = path.split('/')[0,3].join('/')
end
- redirect Mkurl.new("#{path}", params).inherit_query_shead
+ redirect "/milkode" + Mkurl.new("#{path}", params).inherit_query_shead
end
-get '/home*' do |path|
+get '/milkode/home*' do |path|
before = Time.now
path = path.sub(/^\//, "")
record = Database.instance.record(path)
@@ -53,7 +53,7 @@ get '/home*' do |path|
end
end
-get %r{/help} do
+get %r{/milkode/help} do
haml :help
end
@@ -70,7 +70,7 @@ helpers do
# -- utility --
def link(query)
- "<a href='#{'/home?query=' + escape_url(query)}'>#{query}</a>"
+ "<a href='#{'/milkode/home?query=' + escape_url(query)}'>#{query}</a>"
end
def create_form(path, query, shead)
@@ -81,10 +81,10 @@ helpers do
<<EOF
<script type="text/javascript">
function set_pathname() {
- document.searchform.pathname.value = location.pathname;
+ document.searchform.pathname.value = location.pathname.replace(new RegExp('^/[^/]+'), '');
}
</script>
- <form name="searchform" action='/search' method='post'>
+ <form name="searchform" action='/milkode/search' method='post'>
<p>
<input name='query' size='60' type='text' value='#{query}' />
<input type='submit' value='検索' onclick='set_pathname()'><br></input>
@@ -109,14 +109,14 @@ EOF
href = Mkurl.new('/home/' + path, params).inherit_query_shead
flist = File.join("/home/#{path}", flistpath)
<<EOF
- #{headicon('go-home-5.png')} <a href="/home" class="headmenu">全てのパッケージ</a>
- #{headicon('document-new-4.png')} <a href="#{href}" class="headmenu" onclick="window.open('#{href}'); return false;">新しい検索</a>
- #{headicon('directory.png')} <a href="#{flist}" class="headmenu">ファイル一覧</a>
+ #{headicon('go-home-5.png')} <a href="/milkode/home" class="headmenu">全てのパッケージ</a>
+ #{headicon('document-new-4.png')} <a href="/milkode#{href}" class="headmenu" onclick="window.open('/milkode#{href}'); return false;">新しい検索</a>
+ #{headicon('directory.png')} <a href="/milkode#{flist}" class="headmenu">ファイル一覧</a>
EOF
end
def headicon(name)
- "<img alt='' style='vertical-align:center; border: 0px; margin: 0px;' src='/images/#{name}'>"
+ "<img alt='' style='vertical-align:center; border: 0px; margin: 0px;' src='/milkode/images/#{name}'>"
end
def topic_path(path, params)
@@ -125,7 +125,7 @@ EOF
path.split('/').map_with_index {|v, index|
href += '/' + v
- "<a id='topic_#{index}' href='#{Mkurl.new(href, params).inherit_query_shead}' onclick='topic_path(\"topic_#{index}\");'>#{v}</a>"
+ "<a id='topic_#{index}' href='/milkode#{Mkurl.new(href, params).inherit_query_shead}' onclick='topic_path(\"topic_#{index}\");'>#{v}</a>"
}.join('/')
end
diff --git a/lib/milkode/cdweb/cli_cdweb.rb b/lib/milkode/cdweb/cli_cdweb.rb
index a726df2..6d71e31 100644
--- a/lib/milkode/cdweb/cli_cdweb.rb
+++ b/lib/milkode/cdweb/cli_cdweb.rb
@@ -46,7 +46,7 @@ module Rack
server.run wrapped_app, options do
if (options[:LaunchBrowser])
host = options[:Host] || options[:BindAddress] # options[:BindAddress] for WEBrick
- Launchy.open("http://#{host}:#{options[:Port]}")
+ Launchy.open("http://#{host}:#{options[:Port]}/milkode")
end
end
end
diff --git a/lib/milkode/cdweb/lib/command.rb b/lib/milkode/cdweb/lib/command.rb
index 2565f36..904960f 100644
--- a/lib/milkode/cdweb/lib/command.rb
+++ b/lib/milkode/cdweb/lib/command.rb
@@ -55,14 +55,14 @@ module Milkode
fileList = Database.instance.fileList(path)
@total_records = fileList.size
@record_content = fileList.map do |v|
- "<dt class='result-file'>#{file_or_dirimg(v[1])}<a href='#{Mkurl.new('/home/' + v[0], params).inherit_query_shead}'>#{File.basename v[0]}</a></dt>"
+ "<dt class='result-file'>#{file_or_dirimg(v[1])}<a href='/milkode#{Mkurl.new('/home/' + v[0], params).inherit_query_shead}'>#{File.basename v[0]}</a></dt>"
end.join
@elapsed = Time.now - before
haml :filelist
end
def file_or_dirimg(is_file)
- src = (is_file) ? '/images/file.png' : '/images/directory.png'
+ src = (is_file) ? '/milkode/images/file.png' : '/milkode/images/directory.png'
"<img alt='' style='vertical-align:bottom; border: 0; margin: 1px;' src='#{src}'>"
end
end
diff --git a/lib/milkode/cdweb/lib/search_contents.rb b/lib/milkode/cdweb/lib/search_contents.rb
index 37bc38c..0a041df 100644
--- a/lib/milkode/cdweb/lib/search_contents.rb
+++ b/lib/milkode/cdweb/lib/search_contents.rb
@@ -97,7 +97,7 @@ EOF
coderay.set_range(first_index..last_index)
<<EOS
- <dt class='result-record'><a href='#{"/home/" + record_link(record) + "##{coderay.line_number_start}"}'>#{Util::relative_path record.shortpath, @path}</a></dt>
+ <dt class='result-record'><a href='#{"/milkode/home/" + record_link(record) + "##{coderay.line_number_start}"}'>#{Util::relative_path record.shortpath, @path}</a></dt>
<dd>
#{coderay.to_html}
</dd>
diff --git a/lib/milkode/cdweb/lib/search_files.rb b/lib/milkode/cdweb/lib/search_files.rb
index 69945b2..33db004 100644
--- a/lib/milkode/cdweb/lib/search_files.rb
+++ b/lib/milkode/cdweb/lib/search_files.rb
@@ -79,7 +79,7 @@ EOF
def result_record(record)
<<EOS
- <dt class='result-file'>#{file_or_dirimg(true)}<a href='#{"/home/" + record_link(record)}'>#{Util::relative_path record.shortpath, @path}</a></dt>
+ <dt class='result-file'>#{file_or_dirimg(true)}<a href='#{"/milkode/home/" + record_link(record)}'>#{Util::relative_path record.shortpath, @path}</a></dt>
EOS
end
diff --git a/lib/milkode/cdweb/views/filelist.haml b/lib/milkode/cdweb/views/filelist.haml
index 8acef43..d0fb254 100644
--- a/lib/milkode/cdweb/views/filelist.haml
+++ b/lib/milkode/cdweb/views/filelist.haml
@@ -1,6 +1,6 @@
.header
%h1
- <a href="/"><img src="/images/MilkodeIcon135.png" alt="milkode-icon-mini" border="0" height="75px"/></a>
+ <a href="/milkode/"><img src="/milkode/images/MilkodeIcon135.png" alt="milkode-icon-mini" border="0" height="75px"/></a>
Milkode
= create_headmenu(@path, params)
diff --git a/lib/milkode/cdweb/views/help.haml b/lib/milkode/cdweb/views/help.haml
index dab7ddf..6d3e409 100644
--- a/lib/milkode/cdweb/views/help.haml
+++ b/lib/milkode/cdweb/views/help.haml
@@ -2,7 +2,7 @@
.header
%h1
- <a href="/"><img src="/images/MilkodeIcon135.png" alt="milkode-icon-mini" border="0" height="75px"/></a>
+ <a href="/milkode/"><img src="/milkode/images/MilkodeIcon135.png" alt="milkode-icon-mini" border="0" height="75px"/></a>
#{@title} - Milkode
.content
diff --git a/lib/milkode/cdweb/views/index.haml b/lib/milkode/cdweb/views/index.haml
index 138affb..baa3f36 100644
--- a/lib/milkode/cdweb/views/index.haml
+++ b/lib/milkode/cdweb/views/index.haml
@@ -1,18 +1,18 @@
%div(align="center")
.header_home
- %h1 <a href="/"><img src="/images/MilkodeIcon135.png" alt="milkode-icon" border="0" height="135px"/></a> Milkode <font class="version">#{@version}</font>
+ %h1 <a href="/milkode/"><img src="/milkode/images/MilkodeIcon135.png" alt="milkode-icon" border="0" height="135px"/></a> Milkode <font class="version">#{@version}</font>
.content
- %form(method="post" action="/search")
+ %form(method="post" action="/milkode/search")
%p
%input(name="query" type="text" size="60")
%input(type="submit" value="検索")
%input(name='pathname' type='hidden' value='/home')
.footer_home
- <a href="/home">#{@package_num}</a>のパッケージ<br>
- <a href="/home?query=f:*">#{@file_num}</a>のファイル<br>
- <a href="/help">ヘルプ</a> ,
+ <a href="/milkode/home">#{@package_num}</a>のパッケージ<br>
+ <a href="/milkode/home?query=f:*">#{@file_num}</a>のファイル<br>
+ <a href="/milkode/help">ヘルプ</a> ,
<a href="http://milkode.ongaeshi.me">milkodeについて</a>
diff --git a/lib/milkode/cdweb/views/layout.haml b/lib/milkode/cdweb/views/layout.haml
index d42187c..fe4d4e7 100644
--- a/lib/milkode/cdweb/views/layout.haml
+++ b/lib/milkode/cdweb/views/layout.haml
@@ -4,10 +4,10 @@
%head
%meta(charset='utf-8')
%title= [@title, 'Milkode'].compact.join(' - ')
- %link(rel="stylesheet" href="/css/milkode.css" type="text/css" media="all")
- %link(rel="stylesheet" href="/css/coderay.css" type="text/css" media="all")
- %link(rel="stylesheet" href="/css/coderay-patch.css" type="text/css" media="all")
- %script(type='text/javascript' src='/js/milkode.js')
+ %link(rel="stylesheet" href="/milkode/css/milkode.css" type="text/css" media="all")
+ %link(rel="stylesheet" href="/milkode/css/coderay.css" type="text/css" media="all")
+ %link(rel="stylesheet" href="/milkode/css/coderay-patch.css" type="text/css" media="all")
+ %script(type='text/javascript' src='/milkode/js/milkode.js')
%body
-# %header
diff --git a/lib/milkode/cdweb/views/search.haml b/lib/milkode/cdweb/views/search.haml
index 72e43e4..45ae793 100644
--- a/lib/milkode/cdweb/views/search.haml
+++ b/lib/milkode/cdweb/views/search.haml
@@ -1,6 +1,6 @@
.header
%h1
- <a href="/"><img src="/images/MilkodeIcon135.png" alt="milkode-icon-mini" border="0" height="75px"/></a>
+ <a href="/milkode/"><img src="/milkode/images/MilkodeIcon135.png" alt="milkode-icon-mini" border="0" height="75px"/></a>
Milkode
= create_headmenu(@path, params)
diff --git a/lib/milkode/cdweb/views/view.haml b/lib/milkode/cdweb/views/view.haml
index f7cb90e..621a092 100644
--- a/lib/milkode/cdweb/views/view.haml
+++ b/lib/milkode/cdweb/views/view.haml
@@ -1,6 +1,6 @@
.header
%h1
- <a href="/"><img src="/images/MilkodeIcon135.png" alt="milkode-icon-mini" border="0" height="75px"/></a>
+ <a href="/milkode/"><img src="/milkode/images/MilkodeIcon135.png" alt="milkode-icon-mini" border="0" height="75px"/></a>
Milkode
= create_headmenu(@path, params, '..')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment