Module: Wikiscript

Defined in:
lib/wikiscript.rb,
lib/wikiscript.rb,
lib/wikiscript/page.rb,
lib/wikiscript/client.rb,
lib/wikiscript/version.rb,
lib/wikiscript/page_reader.rb,
lib/wikiscript/table_reader.rb,
lib/wikiscript/outline_reader.rb

Defined Under Namespace

Classes: Client, OutlineReader, Page, PageReader, TableReader

Constant Summary collapse

Logging =
LogUtils::Logging
%r{
  \[\[
    (?<link>[^|\]]+)     # everything but pipe (|) or bracket (])
    (?:
      \|
      (?<title>[^\]]+)
    )?                   # optional wiki link title
  \]\]
}x
VERSION =
'0.4.0'

Class Method Summary collapse

Class Method Details



5
6
7
# File 'lib/wikiscript/version.rb', line 5

def self.banner
  "wikiscript/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}] in (#{root})"
end

.get(title, lang: Wikiscript.lang) ⇒ Object Also known as: fetch, download



95
# File 'lib/wikiscript.rb', line 95

def self.get( title, lang: Wikiscript.lang )      Page.get( title, lang: lang ); end

.langObject



33
34
35
36
# File 'lib/wikiscript.rb', line 33

def self.lang
  # note: for now always returns a string e.g. 'en', 'de' etc. not a symbol
  @@lang ||= 'en'
end

.lang=(value) ⇒ Object

for now make lang a global - change why? why not??



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

def self.lang=(value)
  @@lang = value.to_s     # use to_s - lets you pass ing :en, :de etc.
end

.parse(text) ⇒ Object

more convenience shortcuts / helpers



91
# File 'lib/wikiscript.rb', line 91

def self.parse( text )        PageReader.parse( text );  end

todo/change: find a better name - use match_link/etc. - why? why not?



74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/wikiscript.rb', line 74

def self.parse_link( text )     ## todo/change: find a better name - use match_link/etc. - why? why not?
  ##  find first matching link
  ##   return [nil,nil] if nothing found
  if (m = LINK_PATTERN.match( text ))
    link  = m[:link]
    title = m[:title]

    link  = link.strip     ## remove leading and trailing spaces
    title = title.strip   if title
    [link,title]
  else
    [nil,nil]
  end
end

.parse_table(text) ⇒ Object



92
# File 'lib/wikiscript.rb', line 92

def self.parse_table( text )  TableReader.parse_table( text );  end

.read(path) ⇒ Object



94
# File 'lib/wikiscript.rb', line 94

def self.read( path )                             Page.read( path ); end

.rootObject



9
10
11
# File 'lib/wikiscript/version.rb', line 9

def self.root
  File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )
end


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/wikiscript.rb', line 53

def self.unlink( text )
  ## replace ALL wiki links with title (or link)
  ##  e.g. [[Santiago]] ([[La Florida, Chile|La Florida]])
  ##   =>    Santiago (La Florida)
  text = text.gsub( LINK_PATTERN ) do |_|
    link  = $~[:link]
    title = $~[:title]

    if title
      title
    else
      link
    end
  end

  text.strip
end