Module: Wikiscript

Defined in:
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

Defined Under Namespace

Classes: Client, Page, PageReader, TableReader

Constant Summary collapse

%r{
  \[\[
    (?<link>[^|\]]+)     # everything but pipe (|) or bracket (])
    (?:
      \|
      (?<title>[^\]]+)
    )?                   # optional wiki link title
  \]\]
}x
VERSION =
'0.2.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}]"
end

.langObject



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

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??



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

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

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



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

def self.parse_link( value )     ## 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( value ))
    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

.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


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

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

    if title
      title
    else
      link
    end
  end

  value.strip
end