Class: Web::Wiki::Page
Overview
end experiment with SimpleDispatcher
Defined Under Namespace
Classes: Asset
Constant Summary collapse
- @@attributes =
:nodoc:
[]
- @@max_revisions =
25
Instance Attribute Summary collapse
-
#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
-
#content=(newcontent) ⇒ Object
this method must be after the page_attr :content call.
- #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.
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
#history ⇒ Object
Returns the value of attribute history.
69 70 71 |
# File 'lib/web/wiki/page.rb', line 69 def history @history end |
#mtime ⇒ Object
Returns the value of attribute mtime.
69 70 71 |
# File 'lib/web/wiki/page.rb', line 69 def mtime @mtime end |
#name ⇒ Object
Returns the value of attribute name.
69 70 71 |
# File 'lib/web/wiki/page.rb', line 69 def name @name end |
#remote_addr ⇒ Object
Returns the value of attribute remote_addr.
69 70 71 |
# File 'lib/web/wiki/page.rb', line 69 def remote_addr @remote_addr end |
#revision ⇒ Object
Returns the value of attribute revision.
69 70 71 |
# File 'lib/web/wiki/page.rb', line 69 def revision @revision end |
Class Method Details
Instance Method Details
#assets ⇒ Object
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(/&/, "&"))}))[^"']*)(((\s|'|")[^>]*>)|>)} => '\1\3\7', }.each{ |pattern, replacement| newcontent.gsub!( pattern, replacement ) } @content = newcontent end |
#dir ⇒ Object
123 124 125 |
# File 'lib/web/wiki/page.rb', line 123 def dir File.join( Web::Wiki.store_dir, escaped_name ) end |
#download_link ⇒ Object
119 120 121 |
# File 'lib/web/wiki/page.rb', line 119 def download_link File.join( Web::Wiki.store_url, escaped_name, "" ) end |
#escaped_name ⇒ Object
115 116 117 |
# File 'lib/web/wiki/page.rb', line 115 def escaped_name name.gsub( /\//, "-slash-" ) end |
#historical_assets ⇒ Object
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 |
#html ⇒ Object
187 188 189 |
# File 'lib/web/wiki/page.rb', line 187 def html Web::Wiki::Linker.new.replace_links(self.content) end |
#mtime_pretty ⇒ Object
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_fields ⇒ Object
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_request ⇒ Object
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 |
#template ⇒ Object
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 |