Module: Milkode

Defined in:
lib/milkode/cdweb/lib/info_home.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/grep/findgrep.rb,
lib/milkode/cdweb/lib/grep.rb,
lib/milkode/cdweb/cli_cdweb.rb,
lib/milkode/cdweb/lib/mkurl.rb,
lib/milkode/cdweb/lib/query.rb,
lib/milkode/database/updater.rb,
lib/milkode/cdweb/lib/command.rb,
lib/milkode/cdstk/milkode_yaml.rb,
lib/milkode/cdweb/lib/database.rb,
lib/milkode/grep/fast_gotoline.rb,
lib/milkode/cdstk/cdstk_command.rb,
lib/milkode/common/wide_matcher.rb,
lib/milkode/grep/findgrep_option.rb,
lib/milkode/cdweb/lib/web_setting.rb,
lib/milkode/common/ignore_checker.rb,
lib/milkode/common/ignore_setting.rb,
lib/milkode/common/plang_detector.rb,
lib/milkode/cdweb/lib/info_package.rb,
lib/milkode/cdweb/lib/package_list.rb,
lib/milkode/cdweb/lib/search_files.rb,
lib/milkode/database/package_table.rb,
lib/milkode/cdstk/yaml_file_wrapper.rb,
lib/milkode/database/document_table.rb,
lib/milkode/database/document_record.rb,
lib/milkode/cdweb/lib/coderay_wrapper.rb,
lib/milkode/cdweb/lib/search_contents.rb,
lib/milkode/cdweb/lib/search_gotoline.rb,
lib/milkode/database/groonga_database.rb,
lib/milkode/cdweb/lib/search_fuzzy_gotoline.rb

Overview

Author:

  • ongaeshi

Defined Under Namespace

Modules: CdstkCommand, Dbdir, Util Classes: AddError, CLI, CLI_Cdweb, CLI_Grep, Cdstk, CodeRayWrapper, ConvertError, Database, DocumentRecord, DocumentTable, FastGotoline, FindGrep, FindGrepOption, Grep, GroongaDatabase, IgnoreChecker, IgnoreError, IgnoreSetting, InfoHome, InfoPackage, MatchLineResult, MilkodeYaml, Mkurl, Package, PackageList, PackageTable, PlangDetector, Query, SearchContents, SearchFiles, SearchFuzzyGotoLine, SearchGotoLine, Updater, WebSetting, WideMatcher, WideMatcherZero, YamlFileWrapper

Instance Method Summary collapse

Instance Method Details

#filelist(path, params, before, suburl) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/milkode/cdweb/lib/command.rb', line 91

def filelist(path, params, before, suburl)
  @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], suburl)}<a href='#{Mkurl.new(suburl + '/home/' + v[0], params).inherit_query_shead}'>#{File.basename v[0]}</a></dt>"
  end.join
  Database.instance.touch_viewtime(path)
  @elapsed = Time.now - before
  haml :filelist
end

#packages(params, before, suburl) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/milkode/cdweb/lib/command.rb', line 105

def packages(params, before, suburl)
  @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|
    "<dt class='result-file'>#{file_or_dirimg(false, suburl)}<a href='#{Mkurl.new(suburl + '/home/' + v, params).inherit_query_shead}'>#{File.basename v}</a></dt>"
  end.join
  @elapsed = Time.now - before
  haml :packages
end

#search(path, params, before, suburl) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/milkode/cdweb/lib/command.rb', line 56

def search(path, params, before, suburl)
  @setting = WebSetting.new
  @path = path
  query = Query.new(params[:query])
  @title = "'#{query.query_string}' in #{path_title(path)}"

  if (query.gotolines.size > 0)
    searcher = SearchFuzzyGotoLine.new(path, params, query, suburl)

    if searcher.directjump?
      redirect searcher.directjump_url
    end

  elsif (query.keywords.size > 0)
    if Util::gotoline_keyword?(query.keywords[0])
      searcher = SearchGotoLine.new(path, params, query, suburl)
    else
      searcher = SearchContents.new(path, params, query, suburl)

      if searcher.directjump?
        redirect searcher.directjump_url
      end
    end
  else
    searcher = SearchFiles.new(path, params, query, suburl)
  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



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/milkode/cdweb/lib/command.rb', line 18

def view(record, params, before)
  @setting = WebSetting.new
  @title = record.shortpath
  @path = record.shortpath
  is_sensitive = params[:sensitive] == 'on'

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

  if (Util::larger_than_oneline(record.content) and q and !q.keywords.empty?)
    if Util::gotoline_keyword? q.keywords[0]
      gotolines = Util::parse_gotoline(q.keywords)
      match_lines = []
      gotolines.each do |v|
        if v[0][0][1..-1] == record.shortpath
            match_lines << Grep::MatchLineResult.new(v[1] - 1, nil)
        end
      end
      @record_content = CodeRayWrapper.new(record.content, record.shortpath, match_lines).to_html
    else
      grep = Grep.new(record.content)
      match_lines = grep.match_lines_and(q.keywords, is_sensitive, q.wide_match_range)

      if match_lines.empty? && q.wide_match_range_empty?
        # 検索範囲を広げる
        match_lines = grep.match_lines_and(q.keywords, is_sensitive, 7)
      end
      
      @record_content = CodeRayWrapper.new(record.content, record.shortpath, match_lines).to_html
    end
  else
    @record_content = CodeRayWrapper.new(record.content, record.shortpath).to_html
  end
  
  Database.instance.touch_viewtime(@path)
  @elapsed = Time.now - before
  haml :view
end