Class: Wiki2Go::Web

Inherits:
Object
  • Object
show all
Defined in:
lib/Wiki2Go/Web.rb

Overview

A Wiki2Go::Web object contains all the information about the (sub)wiki we're working in The different fields are to be filled in by the webserver interface (Webrick or CGI or…)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server, port, subsite, before, verb, web, page, request = nil) ⇒ Web


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/Wiki2Go/Web.rb', line 29

def initialize(server,port,subsite,before,verb,web,page,request=nil)
  @name = Web.clean(web)
  @current_page = Web.clean(page)
  @server = server
  @port = port
  @subsite = Web.clean(subsite)

  @verb = verb
  @script_extension = Web.extension_of(verb)
  @script_prefix = Web.clean(before)

  @request = request
  @alias = nil
  @title = nil
end

Instance Attribute Details

#current_pageObject

The page of the subwiki


14
15
16
# File 'lib/Wiki2Go/Web.rb', line 14

def current_page
  @current_page
end

#nameObject

The name of the subwiki


12
13
14
# File 'lib/Wiki2Go/Web.rb', line 12

def name
  @name
end

#portObject

Returns the value of attribute port


19
20
21
# File 'lib/Wiki2Go/Web.rb', line 19

def port
  @port
end

#requestObject

CGI/Webrick request


25
26
27
# File 'lib/Wiki2Go/Web.rb', line 25

def request
  @request
end

#script_extensionObject

extension for scripts


21
22
23
# File 'lib/Wiki2Go/Web.rb', line 21

def script_extension
  @script_extension
end

#script_prefixObject

directory containing scripts


23
24
25
# File 'lib/Wiki2Go/Web.rb', line 23

def script_prefix
  @script_prefix
end

#serverObject

URL to be used as the base for all URLs


18
19
20
# File 'lib/Wiki2Go/Web.rb', line 18

def server
  @server
end

#subsiteObject

subdirectory where to find the wiki


27
28
29
# File 'lib/Wiki2Go/Web.rb', line 27

def subsite
  @subsite
end

#verbObject

The 'verb' (action) that was executed


16
17
18
# File 'lib/Wiki2Go/Web.rb', line 16

def verb
  @verb
end

Class Method Details

.extension_of(verb) ⇒ Object


130
131
132
133
# File 'lib/Wiki2Go/Web.rb', line 130

def Web.extension_of(verb)
  verb =~ /(\.[^\.]*)$/
  return ($1.nil? ? "" : $1)
end

.from_page_url(url, verb, config) ⇒ Object


115
116
117
118
# File 'lib/Wiki2Go/Web.rb', line 115

def Web.from_page_url(url,verb,config)
  uri = URI::parse(url)
  return Web.page_url(uri.host,uri.port,uri.path,verb,config)
end

.from_request(request, config) ⇒ Object


121
122
123
124
125
126
127
128
# File 'lib/Wiki2Go/Web.rb', line 121

def Web.from_request(request,config)
  server = request.host
  port   = request.port
  before,verb = Web.parse_scriptpath(request.script_name,config)
  web,page = Web.parse_path(request.path,config.multi_wiki)
  web = Web.new(server,port,config.subsite,before,verb,web,page,request)
  return web
end

.page_url(server, port, url, verb, config) ⇒ Object


106
107
108
109
110
111
112
113
# File 'lib/Wiki2Go/Web.rb', line 106

def Web.page_url(server,port,url,verb,config)
  before,verb,web,page = Web.parse_url(url,verb,config)
  if !web.nil? && !page.nil? then
    return Web.new(server,port,'',before,verb,web,page)
  else
    return Web.new(server,port,'',before,verb,"Wiki2go","Frontpage")
  end
end

Instance Method Details

#aliasObject


70
71
72
# File 'lib/Wiki2Go/Web.rb', line 70

def alias
  @alias || user
end

#alias=(name) ⇒ Object


66
67
68
# File 'lib/Wiki2Go/Web.rb', line 66

def alias=(name)
  @alias = name
end

#base_urlObject


82
83
84
85
86
87
88
89
90
91
# File 'lib/Wiki2Go/Web.rb', line 82

def base_url
  if @port.nil? || @port.to_s.empty? || @port.to_s == "80" then
    url = "http://#{@server}/"
  elsif port.to_s == "443" then
    url = "https://#{@server}/"
  else
    url = "http://#{@server}:#{@port}/"
  end
  url
end

#cloneObject


45
46
47
48
49
50
# File 'lib/Wiki2Go/Web.rb', line 45

def clone
  copy =  Web.new(@server,@port,@subsite,@script_prefix,@verb,@name,@current_page,@request)
  copy.alias = @alias
  copy.title = @title 
  return copy
end

#error_pageObject

The URL of the static error page


102
103
104
# File 'lib/Wiki2Go/Web.rb', line 102

def error_page
  File.join(base_url,'error.html')
end

#pathObject


93
94
95
96
97
98
99
# File 'lib/Wiki2Go/Web.rb', line 93

def path
  if @name.empty? then
    @current_page
  else
    File.join(@name,@current_page)
  end
end

#secure?Boolean Also known as: secure


60
61
62
# File 'lib/Wiki2Go/Web.rb', line 60

def secure?
  @request.nil? ? false : @request.authenticated?
end

#titleObject


78
79
80
# File 'lib/Wiki2Go/Web.rb', line 78

def title
  @title || @current_page
end

#title=(name) ⇒ Object


74
75
76
# File 'lib/Wiki2Go/Web.rb', line 74

def title=(name)
  @title = name
end

#urlObject


52
53
54
# File 'lib/Wiki2Go/Web.rb', line 52

def url
  File.join(base_url,@subsite,script_prefix,@verb + @script_extension,path)  
end

#userObject


56
57
58
# File 'lib/Wiki2Go/Web.rb', line 56

def user
  @request.nil? ? 'unknown' : @request.user
end