Module: CodeStock

Defined in:
lib/codestock/cdweb/lib/grep.rb,
lib/cdstk/cdstk.rb,
lib/common/dbdir.rb,
lib/cdstk/cli_cdstk.rb,
lib/cdstk/cdstk_yaml.rb,
lib/cdview/cli_cdview.rb,
lib/codestock/cdweb/cli_cdweb.rb,
lib/codestock/cdweb/lib/mkurl.rb,
lib/codestock/cdweb/lib/query.rb,
lib/codestock/cdweb/lib/command.rb,
lib/codestock/cdweb/lib/database.rb,
lib/codestock/cdweb/lib/search_files.rb,
lib/codestock/cdweb/lib/coderay_wrapper.rb,
lib/codestock/cdweb/lib/search_contents.rb

Overview

Author:

  • ongaeshi

Defined Under Namespace

Classes: CLI_Cdstk, CLI_Cdview, CLI_Cdweb, Cdstk, CdstkYaml, CodeRayWrapper, Database, Grep, Mkurl, Query, SearchContents, SearchFiles

Constant Summary collapse

DEFAULT_PATH =
'~/.codestock'

Instance Method Summary collapse

Instance Method Details

#db_default_dirObject



13
14
15
16
17
18
19
# File 'lib/common/dbdir.rb', line 13

def db_default_dir
  if (ENV['CODESTOCK_DEFAULT_DIR'])
    File.expand_path ENV['CODESTOCK_DEFAULT_DIR']
  else
    File.expand_path DEFAULT_PATH
  end
end

#db_expand_groonga_path(path = '.') ⇒ Object



29
30
31
# File 'lib/common/dbdir.rb', line 29

def db_expand_groonga_path(path = '.')
  File.expand_path db_groonga_path(path)
end

#db_groonga_path(path = '.') ⇒ Object



25
26
27
# File 'lib/common/dbdir.rb', line 25

def db_groonga_path(path = '.')
  (Pathname.new(path) + 'db/grendb.db').to_s
end

#db_yaml_path(path = '.') ⇒ Object



33
34
35
# File 'lib/common/dbdir.rb', line 33

def db_yaml_path(path = '.')
  (Pathname.new(path) + 'grendb.yaml').to_s
end

#dbdir?(path = '.') ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/common/dbdir.rb', line 21

def dbdir?(path = '.')
  FileTest.exist? db_yaml_path(path)
end

#file_or_dirimg(is_file) ⇒ Object



63
64
65
66
# File 'lib/codestock/cdweb/lib/command.rb', line 63

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



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/codestock/cdweb/lib/command.rb', line 51

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

#search(path, params, before) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/codestock/cdweb/lib/command.rb', line 33

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

#view(record, params, before) ⇒ Object



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

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