Module: Milkode

Defined in:
lib/milkode/cdweb/lib/grep.rb,
lib/milkode/cli.rb,
lib/milkode/cdstk/cdstk.rb,
lib/milkode/common/util.rb,
lib/milkode/common/dbdir.rb,
lib/milkode/cdstk/package.rb,
lib/milkode/grep/cli_grep.rb,
lib/milkode/cdweb/cli_cdweb.rb,
lib/milkode/cdweb/lib/mkurl.rb,
lib/milkode/cdweb/lib/query.rb,
lib/milkode/cdweb/lib/command.rb,
lib/milkode/cdstk/milkode_yaml.rb,
lib/milkode/cdweb/lib/database.rb,
lib/milkode/cdstk/cdstk_command.rb,
lib/milkode/cdweb/lib/web_setting.rb,
lib/milkode/common/ignore_checker.rb,
lib/milkode/common/ignore_setting.rb,
lib/milkode/cdweb/lib/search_files.rb,
lib/milkode/cdstk/yaml_file_wrapper.rb,
lib/milkode/cdweb/lib/coderay_wrapper.rb,
lib/milkode/cdweb/lib/search_contents.rb

Overview

Author:

  • ongaeshi

Defined Under Namespace

Modules: CdstkCommand, Dbdir, Util Classes: CLI, CLI_Cdweb, CLI_Grep, Cdstk, CodeRayWrapper, Database, Grep, IgnoreChecker, IgnoreError, IgnoreSetting, MilkodeYaml, Mkurl, Package, Query, SearchContents, SearchFiles, WebSetting, YamlFileWrapper

Instance Method Summary collapse

Instance Method Details

#file_or_dirimg(is_file) ⇒ Object



68
69
70
71
# File 'lib/milkode/cdweb/lib/command.rb', line 68

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

#filelist(path, params, before) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/milkode/cdweb/lib/command.rb', line 55

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|
    "<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.join
  @elapsed = Time.now - before
  haml :filelist
end

#search(path, params, before) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/milkode/cdweb/lib/command.rb', line 35

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 = "<dl class='autopagerize_page_element'>#{searcher.html_contents}</dl>#{searcher.html_pagination}";
  @match_num = searcher.match_num
  @elapsed = Time.now - before
  haml :search
end

#view(record, params, before) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/milkode/cdweb/lib/command.rb', line 16

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