Class: Wiki2Go::Page
- Inherits:
-
Object
- Object
- Wiki2Go::Page
- Defined in:
- lib/Wiki2Go/Page.rb
Overview
Represents one page in the Wiki
Instance Attribute Summary collapse
-
#alias ⇒ Object
readonly
Authorname given by author.
-
#author ⇒ Object
Real author (if authenticated) or IP/DNS address.
-
#created_on ⇒ Object
Date and time created.
-
#filename ⇒ Object
readonly
Name of the file.
-
#lastmodified ⇒ Object
readonly
Date and time last modified.
-
#lines ⇒ Object
Array of Strings containing the page text.
-
#name ⇒ Object
Descriptive name given by author.
Class Method Summary collapse
-
.is_dynamic?(pagename) ⇒ Boolean
Does filename indicate that page should be executed (Rublet)?.
-
.make_page(filename, lines, default_time) ⇒ Object
Create a Page with data read from file filename = filename of the page (relative to the site text root) lines = Array of Strings with file contents default_time = File data to use as a default creation/modification time if none is present in the file.
Instance Method Summary collapse
-
#checksum(salt = "") ⇒ Object
Checksum based on content, author, document name and author alias Returns String with hex digest.
-
#content ⇒ Object
Content as a String.
-
#initialize(filename, lines, author, time, name, aliasname = nil) ⇒ Page
constructor
Create a new page filename = filename of the page (relative to the site text root) lines = String or Array of Strings with page contents author = real author id (authenticated name, DNS name, ip address) time = modification time name = page title aliasname = [opt] chosen alias of the author.
-
#is_dynamic? ⇒ Boolean
Does this page contain dynamic (Rublet) content?.
-
#length ⇒ Object
Number of of lines.
-
#title ⇒ Object
DEPRECATED use filename instead.
-
#title=(name) ⇒ Object
DEPRECATED use filename= instead.
-
#write(file) ⇒ Object
Write page to file file = IO object or similar, implementing puts.
Constructor Details
#initialize(filename, lines, author, time, name, aliasname = nil) ⇒ Page
Create a new page filename = filename of the page (relative to the site text root) lines = String or Array of Strings with page contents author = real author id (authenticated name, DNS name, ip address) time = modification time name = page title aliasname = [opt] chosen alias of the author
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/Wiki2Go/Page.rb', line 30 def initialize(filename,lines, , time,name,aliasname=nil) @filename = filename @name = name if lines.kind_of?(String) @lines = lines.split($/) else @lines = lines end @lastmodified = time @created_on = time @author = @alias = aliasname || end |
Instance Attribute Details
#alias ⇒ Object (readonly)
Authorname given by author
15 16 17 |
# File 'lib/Wiki2Go/Page.rb', line 15 def alias @alias end |
#author ⇒ Object
Real author (if authenticated) or IP/DNS address
13 14 15 |
# File 'lib/Wiki2Go/Page.rb', line 13 def @author end |
#created_on ⇒ Object
Date and time created
21 22 23 |
# File 'lib/Wiki2Go/Page.rb', line 21 def created_on @created_on end |
#filename ⇒ Object (readonly)
Name of the file
9 10 11 |
# File 'lib/Wiki2Go/Page.rb', line 9 def filename @filename end |
#lastmodified ⇒ Object (readonly)
Date and time last modified
19 20 21 |
# File 'lib/Wiki2Go/Page.rb', line 19 def lastmodified @lastmodified end |
#lines ⇒ Object
Array of Strings containing the page text
17 18 19 |
# File 'lib/Wiki2Go/Page.rb', line 17 def lines @lines end |
#name ⇒ Object
Descriptive name given by author
11 12 13 |
# File 'lib/Wiki2Go/Page.rb', line 11 def name @name end |
Class Method Details
.is_dynamic?(pagename) ⇒ Boolean
Does filename indicate that page should be executed (Rublet)?
121 122 123 |
# File 'lib/Wiki2Go/Page.rb', line 121 def Page.is_dynamic?(pagename) pagename =~ /\.rbl$/ end |
.make_page(filename, lines, default_time) ⇒ Object
Create a Page with data read from file filename = filename of the page (relative to the site text root) lines = Array of Strings with file contents default_time = File data to use as a default creation/modification time if none is present in the file
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/Wiki2Go/Page.rb', line 51 def Page.make_page(filename, lines,default_time) = "unknown" lastmodified = default_time created = nil name = File.basename(filename,'.rbl') last = lines.last while !last.nil? and last =~ /\$([^:]+):(.*)\$/ do keyword = $1 value = $2 case keyword when 'AUTHOR' then = value when 'LASTMODIFIED' then lastmodified = Time.at(value.to_i) when 'CREATED_ON' then created = Time.at(value.to_i) when 'NAME' then name = value when 'ALIAS' then aliasname = value end lines.slice!(-1) last = lines.last end created ||= lastmodified page = Page.new(filename, lines, , lastmodified,name,aliasname) page.created_on = created page end |
Instance Method Details
#checksum(salt = "") ⇒ Object
Checksum based on content, author, document name and author alias Returns String with hex digest
101 102 103 |
# File 'lib/Wiki2Go/Page.rb', line 101 def checksum(salt="") Digest::SHA256.hexdigest("#{salt}#{content}--#{}--#{name}--#{self.alias}") end |
#content ⇒ Object
Content as a String
95 96 97 |
# File 'lib/Wiki2Go/Page.rb', line 95 def content return @lines.join($/) end |
#is_dynamic? ⇒ Boolean
Does this page contain dynamic (Rublet) content?
116 117 118 |
# File 'lib/Wiki2Go/Page.rb', line 116 def is_dynamic? Page.is_dynamic?(@filename) end |
#length ⇒ Object
Number of of lines
90 91 92 |
# File 'lib/Wiki2Go/Page.rb', line 90 def length return @lines.length end |
#title ⇒ Object
DEPRECATED use filename instead
106 107 108 |
# File 'lib/Wiki2Go/Page.rb', line 106 def title @filename end |
#title=(name) ⇒ Object
DEPRECATED use filename= instead
111 112 113 |
# File 'lib/Wiki2Go/Page.rb', line 111 def title=(name) @filename = name end |
#write(file) ⇒ Object
Write page to file file = IO object or similar, implementing puts
80 81 82 83 84 85 86 87 |
# File 'lib/Wiki2Go/Page.rb', line 80 def write(file) file.puts @lines file.puts "$ALIAS:#{@alias}$" unless @alias.nil? file.puts "$NAME:#{@name}$" file.puts "$LASTMODIFIED:#{@lastmodified.to_i}$" file.puts "$CREATED_ON:#{@created_on.to_i}$" file.puts "$AUTHOR:#{@author}$" end |