# -*- coding: utf-8 -*- # # @file # @brief # @author ongaeshi # @date 2011/06/25 require 'rubygems' require 'sinatra' require 'haml' require 'sass' $LOAD_PATH.unshift '../..' require 'milkode/cdweb/lib/database' require 'milkode/cdweb/lib/command' require 'milkode/cdweb/lib/mkurl' set :haml, :format => :html5 get '/' do @version = "0.1.3" @package_num = Database.instance.fileList('').size @file_num = Database.instance.fileNum haml :index end post '/home*' do |path| path = path.sub(/^\//, "") case params[:shead] when 'all' path = "" when 'package' path = path.split('/')[0] end redirect Mkurl.new("home/#{path}", params).inherit_query_shead end get '/home*' do |path| before = Time.now path = path.sub(/^\//, "") record = Database.instance.record(path) if (record) view(record, params, before) else unless (params[:query]) filelist(path, params, before) else search(path, params, before) end end end get %r{/help} do haml :help end # -- helper function -- helpers do # -- escape functions -- alias h escape_html alias escape_url escape def escape_path(src) escape_url(src).gsub("%2F", '/') end # -- utility -- def link(query) "#{query}" end def create_form(path, query, shead) shead = shead || 'directory' # こっちにすると'検索'ボタンを押した時に新しくウィンドウが開く #
<


#{create_radio('all', shead)} #{create_radio('package', shead)} #{create_radio('directory', shead)}

EOF end def create_radio(value, shead) str = (value == shead) ? 'checked' : '' "" end def create_headmenu(path, query) # href = "#{request.path_info}?'#{request.query_string}" # href = '/home/rack-1.3.0/lib/rack/handler/cgi.rb?shead=directory' href = Mkurl.new('/home/' + path, params).inherit_query_shead <全てのパッケージ 新しい検索 EOF end def topic_path(path, params) href = '/home' path.split('/').map {|v| href += '/' + v "#{v}" }.join('/') end def package_name(path) (path == "") ? 'root' : path.split('/')[0] end def current_name(path) (path == "") ? 'root' : File.basename(path) end def path_title(path) (path == "") ? "root" : path end def filelist_title(path) (path == "") ? "Package List" : path end end