class Qwik::Page
These methods will be used in ext_save
Attributes
cache[R]
files[RW]
key[R]
rrefs[RW]
Public Class Methods
embed_password(content)
click to toggle source
# File vendor/qwik/lib/qwik/act-password.rb, line 53 def self.embed_password(content) new_pass = get_password(content) return content if new_pass.nil? # Nothing to embed. new_content = content.sub(/\{\{password\((.+)\)\}\}/) { "{{password(#{$1.md5hex})}}" } return new_content end
get_body(str)
click to toggle source
# File vendor/qwik/lib/qwik/page-get.rb, line 87 def self.get_body(str) ar = [] first_line = true start_body = true str.each_line {|line| if first_line first_line = false if line[0] == ?* && line[1] != ?* # this is title else ar << line end else if start_body if /\A$/ =~ line # Skip empty line. next else start_body = false end end if ! start_body ar << line end end } return ar.join end
get_first_line(str)
click to toggle source
# File vendor/qwik/lib/qwik/page-get.rb, line 36 def self.get_first_line(str) return nil if str.nil? while true # If the str has only one line, return it. i = str.index(?\n) return str if i.nil? # Get the first line. line = str[0..i] line.chop! # The end of line is newline. if line[0] == ?# str = str[(i+1)..-1] # Store rest and try again. next end return line end raise # Do not come here. end
get_password(str)
click to toggle source
# File vendor/qwik/lib/qwik/act-password.rb, line 48 def self.get_password(str) return $1 if str && /\{\{password\((.+)\)\}\}/ =~ str return nil end
get_title(str)
click to toggle source
# File vendor/qwik/lib/qwik/page-get.rb, line 31 def self.get_title(str) first_line = get_first_line(str) return parse_title_line(first_line) end
new(config, pages, key)
click to toggle source
# File vendor/qwik/lib/qwik/page.rb, line 12 def initialize(config, pages, key) @pages = pages @key = key.to_s @db = @pages.db @db.create(@key) # init_generate # FIXME @files = nil @rrefs = nil @cache = {} end
parse_title(title, tags=[])
click to toggle source
# File vendor/qwik/lib/qwik/page-get.rb, line 63 def self.parse_title(title, tags=[]) return nil if title.nil? title = title.strip # Remove start and end spaces. return nil if title.empty? # The title should not be empty. # If the title has a tag, if /\A\[(.+?)\]/ =~ title tag = $1 return [title, tags] if $'.empty? title = $' tags << tag return parse_title(title, tags) # Resursive. end return [title, tags] end
parse_title_line(line)
click to toggle source
# File vendor/qwik/lib/qwik/page-get.rb, line 56 def self.parse_title_line(line) return nil unless /\A\*/ =~ line # must begin with '*'. title = $' # the rest of the line. return nil if title[0] == ?* # must be h2 level. return parse_title(title) end
Public Instance Methods
<=>(other)
click to toggle source
# File vendor/qwik/lib/qwik/page.rb, line 39 def <=>(other) return self.key <=> other.key end
add(v)
click to toggle source
# File vendor/qwik/lib/qwik/page-put.rb, line 26 def add(v) str = self.get addstr = '' # FIXME: Use normalize_eol? if ! (str.empty? || str[-1] == ?\n) addstr += "\n" end addstr += v if !(v.empty? || v[-1] == ?\n) addstr += "\n" end @db.add(@key, addstr) end
delete()
click to toggle source
# File vendor/qwik/lib/qwik/page-put.rb, line 44 def delete @db.delete(@key) # @pages.delete(@key) end
get()
click to toggle source
# File vendor/qwik/lib/qwik/page-get.rb, line 10 def get return @db.get(@key) end
Also aliased as: load
get_body()
click to toggle source
# File vendor/qwik/lib/qwik/page-get.rb, line 83 def get_body return Page.get_body(self.get) end
get_body_tree()
click to toggle source
# File vendor/qwik/lib/qwik/page-generate.rb, line 46 def get_body_tree @body_tree_str = nil if ! defined?(@body_tree_str) @body_tree = nil if ! defined?(@body_tree) str = self.get_body return @body_tree if str == @body_tree_str @body_tree_str = str if EmodePreProcessor.emode?(str) str = EmodePreProcessor.preprocess(str) end tokens = TextTokenizer.tokenize(str) @body_tree = TextParser.make_tree(tokens) return @body_tree end
get_md5()
click to toggle source
# File vendor/qwik/lib/qwik/page-generate.rb, line 12 def get_md5 @md5_str = nil if ! defined?(@md5_str) @md5 = nil if ! defined?(@md5) str = self.get return @md5 if str == @md5_str return @md5 = (@md5_str = str).md5hex end
get_password()
click to toggle source
# File vendor/qwik/lib/qwik/act-password.rb, line 44 def get_password return Page.get_password(self.load) end
get_title()
click to toggle source
# File vendor/qwik/lib/qwik/page-get.rb, line 23 def get_title title, tags = Page.get_title(self.get) return title if title # Abandon to get title and return the page key. return @key end
get_tokens()
click to toggle source
# File vendor/qwik/lib/qwik/page-generate.rb, line 20 def get_tokens @tokens_str = nil if ! defined?(@tokens_str) @tokens = nil if ! defined?(@tokens) str = self.get return @tokens if str == @tokens_str @tokens_str = str @tokens = TextTokenizer.tokenize(str) return @tokens end
get_tree()
click to toggle source
# File vendor/qwik/lib/qwik/page-generate.rb, line 31 def get_tree @tree_str = nil if ! defined?(@tree_str) @tree = nil if ! defined?(@tree) str = self.get return @tree if str == @tree_str @tree_str = str if EmodePreProcessor.emode?(str) str = EmodePreProcessor.preprocess(str) end tokens = TextTokenizer.tokenize(str) @tree = TextParser.make_tree(tokens) return @tree end
inspect()
click to toggle source
# File vendor/qwik/lib/qwik/page.rb, line 31 def inspect return "#<Page:"+@key+">" end
match_password?(v)
click to toggle source
# File vendor/qwik/lib/qwik/act-password.rb, line 62 def match_password?(v) old_pass_md5 = self.get_password return true if old_pass_md5.nil? # No password. Go on. new_pass_md5 = Page.get_password(v) # assume already become md5 return false if new_pass_md5.nil? # Can not go if there is no pass return false if new_pass_md5 != old_pass_md5 # should be correct pass return true # Go on. end
mtime()
click to toggle source
# File vendor/qwik/lib/qwik/page-get.rb, line 19 def mtime return @db.mtime(@key) end
put(v)
click to toggle source
# File vendor/qwik/lib/qwik/page-put.rb, line 10 def put(v) return @db.put(@key, v) end
Also aliased as: store
put_with_md5(v, md5)
click to toggle source
# File vendor/qwik/lib/qwik/page-put.rb, line 19 def put_with_md5(v, md5) if md5 && self.get.md5hex != md5 raise PageCollisionError end put(v) end
put_with_time(v, time)
click to toggle source
# File vendor/qwik/lib/qwik/page-put.rb, line 15 def put_with_time(v, time) @db.put(@key, v, time) end
size()
click to toggle source
# File vendor/qwik/lib/qwik/page-get.rb, line 15 def size return @db.size(@key) end
touch()
click to toggle source
# File vendor/qwik/lib/qwik/page-put.rb, line 49 def touch @db.touch(@key) end
url()
click to toggle source
# File vendor/qwik/lib/qwik/page.rb, line 35 def url return @key+'.html' end
wikidb()
click to toggle source
# File vendor/qwik/lib/qwik/page-wikidb.rb, line 17 def wikidb # @wikidb = WikiDB.new(self) unless defined?(@wikidb) # return @wikidb WikiDB.new(self) end