Class: Nwiki::Core::Wiki

Inherits:
Object
  • Object
show all
Defined in:
lib/nwiki/core/wiki.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Wiki

Returns a new instance of Wiki.



20
21
22
23
# File 'lib/nwiki/core/wiki.rb', line 20

def initialize path
  @path = path
  @access = GitAccess.new(path)
end

Class Method Details

.canonicalize_path(path) ⇒ Object



15
16
17
18
# File 'lib/nwiki/core/wiki.rb', line 15

def self.canonicalize_path path
  unescaped_path = URI.unescape(path).force_encoding(repo_filename_encoding)
  unescaped_path.sub(/^\//, '')
end

.parserObject



11
12
13
# File 'lib/nwiki/core/wiki.rb', line 11

def self.parser
  Orgmode::Parser
end

.repo_filename_encodingObject



7
8
9
# File 'lib/nwiki/core/wiki.rb', line 7

def self.repo_filename_encoding
  Encoding::UTF_8
end

Instance Method Details

#authorObject



61
62
63
# File 'lib/nwiki/core/wiki.rb', line 61

def author
  @access.author
end

#find(path) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/nwiki/core/wiki.rb', line 25

def find path
  canonicalized_path = self.class.canonicalize_path path
  if canonicalized_path == ''
    find_directory(canonicalized_path)
  else
    find_page_or_file(canonicalized_path)
  end
end

#find_directory(path) ⇒ Object



47
48
49
50
51
# File 'lib/nwiki/core/wiki.rb', line 47

def find_directory path
  files = @access.all_files
  Directory.encoding = self.class.repo_filename_encoding
  Directory.new(path, files.map(&:path))
end

#find_page_or_file(path) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/nwiki/core/wiki.rb', line 34

def find_page_or_file path
  entry = @access.find_file do |entry_path|
    path == entry_path.sub(/\.org$/){ '' }
  end
  return nil unless entry
  if entry.path =~ /\.org$/
    path = entry.path.sub(/\.org$/){ '' }
    Page.new(path, entry.text, self.class.parser)
  else
    File.new(entry.path, entry.content)
  end
end

#logObject



65
66
67
# File 'lib/nwiki/core/wiki.rb', line 65

def log
  @access.log
end

#subtitleObject



57
58
59
# File 'lib/nwiki/core/wiki.rb', line 57

def subtitle
  @access.subtitle
end

#titleObject



53
54
55
# File 'lib/nwiki/core/wiki.rb', line 53

def title
  @access.title
end