Sha256: 1ee33b53ea70bd05c2f3dd9e45806248aac726eeec5cb6fb564a6e9c863dcbfa

Contents?: true

Size: 1.94 KB

Versions: 5

Compression:

Stored size: 1.94 KB

Contents

# -*- 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'

module Milkode
  def view(record, params, before)
    @title = record.shortpath
    @path = record.shortpath

    q = params[:query] && Query.new(params[:query]) 

    if (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
    
    @elapsed = Time.now - before
    haml :view
  end

  def search(path, params, before)
    @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;
    @elapsed = Time.now - before
    haml :search
  end

  def filelist(path, params, before)
    @title = filelist_title(path)
    @path = path
    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>"
    end
    @elapsed = Time.now - before
    haml :filelist
  end

  def file_or_dirimg(is_file)
    src = (is_file) ? '/images/file.png' : '/images/directory.png'
    "<img alt='' style='vertical-align:bottom; border: 0; margin: 1px;' src='#{src}'>"
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
milkode-0.1.4 lib/milkode/cdweb/lib/command.rb
milkode-0.1.3 lib/milkode/cdweb/lib/command.rb
milkode-0.1.2 lib/milkode/cdweb/lib/command.rb
milkode-0.1.1 lib/milkode/cdweb/lib/command.rb
milkode-0.1.0 lib/milkode/cdweb/lib/command.rb