Class: Web::Wiki::Page
Overview
:nodoc:
Defined Under Namespace
Classes: Asset
Constant Summary collapse
- @@attributes =
[]
- @@max_revisions =
25
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#history ⇒ Object
Returns the value of attribute history.
-
#mtime ⇒ Object
Returns the value of attribute mtime.
-
#name ⇒ Object
Returns the value of attribute name.
-
#remote_addr ⇒ Object
Returns the value of attribute remote_addr.
-
#revision ⇒ Object
Returns the value of attribute revision.
Class Method Summary collapse
Instance Method Summary collapse
- #assets ⇒ Object
- #dir ⇒ Object
- #download_link ⇒ Object
- #escaped_name ⇒ Object
- #historical_assets ⇒ Object
- #html ⇒ Object
-
#initialize(name) ⇒ Page
constructor
A new instance of Page.
- #mtime_pretty ⇒ Object
- #set_automatic_fields ⇒ Object
- #set_by_request ⇒ Object
- #template ⇒ Object
Constructor Details
#initialize(name) ⇒ Page
Returns a new instance of Page.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/web/wiki/page.rb', line 79 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
#content ⇒ Object
Returns the value of attribute content.
186 187 188 |
# File 'lib/web/wiki/page.rb', line 186 def content @content end |
#history ⇒ Object
Returns the value of attribute history.
77 78 79 |
# File 'lib/web/wiki/page.rb', line 77 def history @history end |
#mtime ⇒ Object
Returns the value of attribute mtime.
77 78 79 |
# File 'lib/web/wiki/page.rb', line 77 def mtime @mtime end |
#name ⇒ Object
Returns the value of attribute name.
77 78 79 |
# File 'lib/web/wiki/page.rb', line 77 def name @name end |
#remote_addr ⇒ Object
Returns the value of attribute remote_addr.
77 78 79 |
# File 'lib/web/wiki/page.rb', line 77 def remote_addr @remote_addr end |
#revision ⇒ Object
Returns the value of attribute revision.
77 78 79 |
# File 'lib/web/wiki/page.rb', line 77 def revision @revision end |
Class Method Details
.max_revisions ⇒ Object
58 59 60 |
# File 'lib/web/wiki/page.rb', line 58 def Page.max_revisions @@max_revisions end |
Instance Method Details
#assets ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/web/wiki/page.rb', line 156 def assets a = if (File.exists? dir) (Dir.entries( dir ) - [".", ".."]).find_all { |e| e =~ /^[^\#]/ }.collect{ |e| Asset.new(self, e) } else [ ] end a end |
#dir ⇒ Object
131 132 133 |
# File 'lib/web/wiki/page.rb', line 131 def dir File.join( Web::Wiki.store_dir, escaped_name ) end |
#download_link ⇒ Object
127 128 129 |
# File 'lib/web/wiki/page.rb', line 127 def download_link File.join( Web::Wiki.store_url, escaped_name, "" ) end |
#escaped_name ⇒ Object
123 124 125 |
# File 'lib/web/wiki/page.rb', line 123 def escaped_name name.gsub( /\//, "-slash-" ) end |
#historical_assets ⇒ Object
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/web/wiki/page.rb', line 169 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 |
#html ⇒ Object
196 197 198 |
# File 'lib/web/wiki/page.rb', line 196 def html Web::Wiki::Linker.new.replace_links(self.content) end |
#mtime_pretty ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/web/wiki/page.rb', line 96 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_fields ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/web/wiki/page.rb', line 69 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_request ⇒ Object
62 63 64 65 66 67 |
# File 'lib/web/wiki/page.rb', line 62 def set_by_request @@attributes.each { |symbol| self.send( symbol.to_s + "=", Web["page." + symbol.to_s] ) } set_automatic_fields end |
#template ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/web/wiki/page.rb', line 111 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 |