module Juli::Wiki

When new file is added:

  1. The filename becomes wikiname.

  2. scan all of files (includes itself because this also contains the wikiname), convert token to wiki-link if exists and generate HTML.

When a file is deleted:

  1. The filename (wikiname) is lost.

  2. scan all of files (includes itself because this also contains the wikiname), convert token to wiki-link if exists and generate HTML.

Public Class Methods

build_wikinames() click to toggle source
# File lib/juli/wiki.rb, line 34
def build_wikinames
  wikiname = {}
  Dir.chdir(Juli::Util.juli_repo){
    Dir.glob('**/*.txt'){|f|
      wikiname[encode(Juli::Util.to_wikiname(f))] = 1
    }
  }
  wikiname.keys.sort_by{|a| -1 * a.length}
end
decode(str) click to toggle source

decode '(', ')'

EXAMPLE

'juli(1)' -> 'juli(1)'

# File lib/juli/wiki.rb, line 30
def decode(str)
  str.gsub(/\\\(/, '(').gsub(/\\\)/, ')')
end
encode(str) click to toggle source

encode(=escape) '(', ')'

EXAMPLE

'juli(1)' -> 'juli(1)'

# File lib/juli/wiki.rb, line 22
def encode(str)
  str.gsub(/\(/, '\(').gsub(/\)/, '\)')
end
wikinames() click to toggle source

global name to return wikinames data, which is just string array ordered by length in descendant.

# File lib/juli/wiki.rb, line 46
def wikinames
  $_wikinames ||= build_wikinames
end

Private Instance Methods

build_wikinames() click to toggle source
# File lib/juli/wiki.rb, line 34
def build_wikinames
  wikiname = {}
  Dir.chdir(Juli::Util.juli_repo){
    Dir.glob('**/*.txt'){|f|
      wikiname[encode(Juli::Util.to_wikiname(f))] = 1
    }
  }
  wikiname.keys.sort_by{|a| -1 * a.length}
end
decode(str) click to toggle source

decode '(', ')'

EXAMPLE

'juli(1)' -> 'juli(1)'

# File lib/juli/wiki.rb, line 30
def decode(str)
  str.gsub(/\\\(/, '(').gsub(/\\\)/, ')')
end
encode(str) click to toggle source

encode(=escape) '(', ')'

EXAMPLE

'juli(1)' -> 'juli(1)'

# File lib/juli/wiki.rb, line 22
def encode(str)
  str.gsub(/\(/, '\(').gsub(/\)/, '\)')
end
wikinames() click to toggle source

global name to return wikinames data, which is just string array ordered by length in descendant.

# File lib/juli/wiki.rb, line 46
def wikinames
  $_wikinames ||= build_wikinames
end