# -*- coding: utf-8 -*- # # @file # @brief # @author ongaeshi # @date 2011/07/11 require 'milkode/cdweb/lib/database' require 'milkode/cdweb/lib/coderay_wrapper' require 'milkode/cdweb/lib/search_contents' require 'milkode/cdweb/lib/search_files' require 'milkode/cdweb/lib/mkurl' require 'milkode/common/util' module Milkode def view(record, params, before) @setting = WebSetting.new @title = record.shortpath @path = record.shortpath q = params[:query] && Query.new(params[:query]) if (Util::larger_than_oneline(record.content) and q and !q.keywords.empty?) grep = Grep.new(record.content) match_lines = grep.match_lines_and(q.keywords) @record_content = CodeRayWrapper.new(record.content, record.shortpath, match_lines).to_html else @record_content = CodeRayWrapper.new(record.content, record.shortpath).to_html end Database.instance.touch_viewtime(@path) @elapsed = Time.now - before haml :view end def search(path, params, before) @setting = WebSetting.new @path = path query = Query.new(params[:query]) @title = "'#{query.query_string}' in #{path_title(path)}" if (query.keywords.size > 0) searcher = SearchContents.new(path, params, query) else searcher = SearchFiles.new(path, params, query) end @total_records = searcher.total_records @range = searcher.data_range @record_content = "
#{searcher.html_contents}
#{searcher.html_pagination}"; @match_num = searcher.match_num @elapsed = Time.now - before haml :search end def filelist(path, params, before) @setting = WebSetting.new @title = filelist_title(path) @path = path fileList = Database.instance.fileList(path) @total_records = fileList.size @record_content = fileList.map do |v| "
#{file_or_dirimg(v[1])}#{File.basename v[0]}
" end.join Database.instance.touch_viewtime(path) @elapsed = Time.now - before haml :filelist end def packages(params, before) @setting = WebSetting.new @title = "Package List" @path = "" packages = Database.instance.packages(params["sort"]) @total_records = packages.size @sort_change_content = [ sort_change_content(params["sort"], '名前'), '|', sort_change_content(params["sort"], '最近使った', 'viewtime'), '|', sort_change_content(params["sort"], '追加順' , 'addtime'), '|', sort_change_content(params["sort"], '更新順' , 'updatetime'), '|', sort_change_content(params["sort"], 'お気に入り', 'favtime'), ].join("\n") @record_content = packages.map do |v| "
#{file_or_dirimg(false)}#{File.basename v}
" end.join @elapsed = Time.now - before haml :packages end private def file_or_dirimg(is_file) src = (is_file) ? '/images/file.png' : '/images/directory.png' "" end def sort_change_content(current_value, text, sort_kind = nil) if (current_value != sort_kind) if (sort_kind) "#{text}" else "#{text}" end else text end end end