Class: Web::Wiki::Page

Inherits:
Object show all
Defined in:
lib/web/wiki/page.rb

Overview

end experiment with SimpleDispatcher

Defined Under Namespace

Classes: Asset

Constant Summary collapse

@@attributes =

:nodoc:

[]
@@max_revisions =
25

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Page

Returns a new instance of Page.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/web/wiki/page.rb', line 71

def initialize( name )
  self.name = name
  self.revision = 0
  self.history = [ ]
  self.content = ""
  self.comment = ""
  self.illustration = ""
  self.bg_color = "ffffff"
  self.text_color = "000000"
  self.align = "left"
  self.valign = "top"
  self.top_margin = "5"
  self.left_margin = "5"
  self.mtime = Time.now()
  self.remote_addr = "auto-create"
end

Instance Attribute Details

#historyObject

Returns the value of attribute history.



69
70
71
# File 'lib/web/wiki/page.rb', line 69

def history
  @history
end

#mtimeObject

Returns the value of attribute mtime.



69
70
71
# File 'lib/web/wiki/page.rb', line 69

def mtime
  @mtime
end

#nameObject

Returns the value of attribute name.



69
70
71
# File 'lib/web/wiki/page.rb', line 69

def name
  @name
end

#remote_addrObject

Returns the value of attribute remote_addr.



69
70
71
# File 'lib/web/wiki/page.rb', line 69

def remote_addr
  @remote_addr
end

#revisionObject

Returns the value of attribute revision.



69
70
71
# File 'lib/web/wiki/page.rb', line 69

def revision
  @revision
end

Class Method Details

.max_revisionsObject



50
51
52
# File 'lib/web/wiki/page.rb', line 50

def Page.max_revisions
  @@max_revisions
end

.page_attr(*symbols) ⇒ Object



42
43
44
45
46
47
# File 'lib/web/wiki/page.rb', line 42

def Page.page_attr( *symbols )
  symbols.each { |symbol|
    attr_accessor symbol
    @@attributes.push symbol
  }
end

Instance Method Details

#assetsObject



148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/web/wiki/page.rb', line 148

def assets
  a = if (File.exists? dir)
        (Dir.entries( dir ) - [".", ".."]).find_all { |e|
          e =~ /^[^\#]/
        }.collect{ |e|
          Asset.new(self, e)
        }
      else
        [ ]
      end
  a
end

#content=(newcontent) ⇒ Object

this method must be after the page_attr :content call



178
179
180
181
182
183
184
185
# File 'lib/web/wiki/page.rb', line 178

def content=( newcontent )
  {
    %r{(<[^>]*)(http:\/\/[^"']*)(((#{Regexp.escape(download_link)})|(#{Regexp.escape(download_link.gsub(/&/, "&amp;"))}))[^"']*)(((\s|'|")[^>]*>)|>)} => '\1\3\7',
}.each{ |pattern, replacement|
    newcontent.gsub!( pattern, replacement )
  }
  @content = newcontent
end

#dirObject



123
124
125
# File 'lib/web/wiki/page.rb', line 123

def dir
  File.join( Web::Wiki.store_dir, escaped_name )
end


119
120
121
# File 'lib/web/wiki/page.rb', line 119

def download_link
  File.join( Web::Wiki.store_url, escaped_name, "" )
end

#escaped_nameObject



115
116
117
# File 'lib/web/wiki/page.rb', line 115

def escaped_name
  name.gsub( /\//, "-slash-" )
end

#historical_assetsObject



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/web/wiki/page.rb', line 161

def historical_assets
  historical = {}
  assets.each { |e|
    historical[e] = Dir[dir + "/*" + e].entries.sort { |a,b|
      File.mtime( a ) <=> File.mtime( b )
    }.collect { |e|
      File.basename(e)
    }
  }
  Dir[dir + "/\#*deleted.*"].entries.each{ |e|
    base = File.basename(e).gsub( /\#(\d+\.){0,1}deleted\./, "" )
    historical[base] = [ File.basename(e) ] unless historical.has_key?( base )
  }
  historical
end

#htmlObject



187
188
189
# File 'lib/web/wiki/page.rb', line 187

def html
  Web::Wiki::Linker.new.replace_links(self.content)
end

#mtime_prettyObject



88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/web/wiki/page.rb', line 88

def mtime_pretty
  if (mtime.hour > 12)
    mtime.hour - 12
elsif (mtime.hour == 0)
    12
  else
    mtime.hour
  end.to_s + ":" +
      mtime.min.to_s +
            mtime.strftime("%p ").downcase +
mtime.strftime("%b ") +
      mtime.mday.to_s +
            mtime.strftime( ", %Y" )
end

#set_automatic_fieldsObject



61
62
63
64
65
66
67
# File 'lib/web/wiki/page.rb', line 61

def set_automatic_fields
  self.revision += 1
  self.mtime = Time.now()
  self.history.unshift self.clone
  self.history.pop if ( self.history.size > Page.max_revisions )
  self.remote_addr = ENV["REMOTE_ADDR"]
end

#set_by_requestObject



54
55
56
57
58
59
# File 'lib/web/wiki/page.rb', line 54

def set_by_request
  @@attributes.each { |symbol|
    self.send( symbol.to_s + "=", Web["page." + symbol.to_s] )
  }
  set_automatic_fields
end

#templateObject



103
104
105
106
107
108
109
110
111
112
113
# File 'lib/web/wiki/page.rb', line 103

def template
  if (self.name == Web::Wiki::pref(:home_page))
    Web::Wiki::pref( :home_template )
  elsif(self.illustration == nil)
    "basic.html"
  elsif (self.illustration.empty?)
    "basic.html"
  else
    "illustration.html"
  end
end