Class: ClWiki::Page
- Inherits:
-
Object
- Object
- ClWiki::Page
- Defined in:
- lib/cl_wiki/page.rb
Constant Summary collapse
- @@wikiIndexClient =
nil
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#fileFullPathAndName ⇒ Object
readonly
Returns the value of attribute fileFullPathAndName.
-
#full_name ⇒ Object
readonly
Returns the value of attribute full_name.
-
#mtime ⇒ Object
readonly
Returns the value of attribute mtime.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#pagePath ⇒ Object
readonly
Returns the value of attribute pagePath.
-
#raw_content ⇒ Object
readonly
Returns the value of attribute raw_content.
Class Method Summary collapse
- .page_exists?(page_name) ⇒ Boolean
- .read_file_full_path_and_name(full_name, wiki_path = $wiki_path) ⇒ Object
- .wikiIndexClient ⇒ Object
Instance Method Summary collapse
- #content_never_edited? ⇒ Boolean
-
#convert_newline_to_br ⇒ Object
<pre> text in 1.13.2 had extra line feeds, because the n were xformed to
n, which results in two line feeds when rendered by Mozilla. - #delete ⇒ Object
- #get_footer ⇒ Object
- #get_forward_ref(content) ⇒ Object
- #get_header ⇒ Object
-
#initialize(fullName, wiki_path = $wiki_path) ⇒ Page
constructor
refactor away wikiPath …
- #process_custom_renderers ⇒ Object
- #read_content(include_header_and_footer = true, include_diff = false) ⇒ Object
- #read_page_attributes ⇒ Object
- #read_raw_content ⇒ Object
- #read_raw_content_with_forwarding(full_page_name) ⇒ Object
- #update_content(newcontent, mtime) ⇒ Object
Constructor Details
#initialize(fullName, wiki_path = $wiki_path) ⇒ Page
refactor away wikiPath … should be taken care of elsewhere, otherwise ClWiki must know it, and it should be storage independent
22 23 24 25 26 27 28 |
# File 'lib/cl_wiki/page.rb', line 22 def initialize(fullName, wiki_path=$wiki_path) @full_name = fullName @wiki_path = wiki_path @wikiFile = ClWiki::File.new(@full_name, @wiki_path) @pagePath = @wikiFile.pagePath @name = @wikiFile.name end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
12 13 14 |
# File 'lib/cl_wiki/page.rb', line 12 def content @content end |
#fileFullPathAndName ⇒ Object (readonly)
Returns the value of attribute fileFullPathAndName.
12 13 14 |
# File 'lib/cl_wiki/page.rb', line 12 def fileFullPathAndName @fileFullPathAndName end |
#full_name ⇒ Object (readonly)
Returns the value of attribute full_name.
12 13 14 |
# File 'lib/cl_wiki/page.rb', line 12 def full_name @full_name end |
#mtime ⇒ Object (readonly)
Returns the value of attribute mtime.
12 13 14 |
# File 'lib/cl_wiki/page.rb', line 12 def mtime @mtime end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/cl_wiki/page.rb', line 12 def name @name end |
#pagePath ⇒ Object (readonly)
Returns the value of attribute pagePath.
12 13 14 |
# File 'lib/cl_wiki/page.rb', line 12 def pagePath @pagePath end |
#raw_content ⇒ Object (readonly)
Returns the value of attribute raw_content.
12 13 14 |
# File 'lib/cl_wiki/page.rb', line 12 def raw_content @raw_content end |
Class Method Details
.page_exists?(page_name) ⇒ Boolean
175 176 177 178 179 180 181 182 183 184 |
# File 'lib/cl_wiki/page.rb', line 175 def self.page_exists?(page_name) if ($wiki_conf.useIndex != ClWiki::Configuration::USE_INDEX_NO) && ($wiki_conf.useIndexForPageExists) res = ClWiki::Page.wikiIndexClient.page_exists?(page_name) else wiki_file = ClWiki::File.new(page_name, $wiki_path, $wikiPageExt, false) res = wiki_file.file_exists? end res end |
.read_file_full_path_and_name(full_name, wiki_path = $wiki_path) ⇒ Object
69 70 71 72 |
# File 'lib/cl_wiki/page.rb', line 69 def self.read_file_full_path_and_name(full_name, wiki_path=$wiki_path) wiki_file = ClWikiFile.new(full_name, wiki_path, $wikiPageExt, false) wiki_file.fullPathAndName end |
.wikiIndexClient ⇒ Object
50 51 52 53 |
# File 'lib/cl_wiki/page.rb', line 50 def self.wikiIndexClient @@wikiIndexClient = ClWikiIndexClient.new if !@@wikiIndexClient @@wikiIndexClient end |
Instance Method Details
#content_never_edited? ⇒ Boolean
61 62 63 |
# File 'lib/cl_wiki/page.rb', line 61 def content_never_edited? @wikiFile.content_is_default? end |
#convert_newline_to_br ⇒ Object
<pre> text in 1.13.2 had extra line feeds, because the n were xformed to
n, which results in two line feeds when rendered by Mozilla. The change a few versions ago inside convert_newline_to_br which started converting n to
n is the culprit here. I did this for more readable html, but that does screw up <pre> sections, so it’s put back now.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/cl_wiki/page.rb', line 35 def convert_newline_to_br newcontent = "" insideHtmlTags = false @content.each_line do |substr| insideHtmlTags = true if (substr =~ /#{$HTML_START}/) insideHtmlTags = false if (substr =~ /#{$HTML_END}/) if ((!ClWiki::PageFormatter.only_html(substr)) or (substr == "\n")) and !insideHtmlTags newcontent = newcontent + substr.gsub(/\n/, "<br>") else newcontent = newcontent + substr end end @content = newcontent end |
#delete ⇒ Object
65 66 67 |
# File 'lib/cl_wiki/page.rb', line 65 def delete @wikiFile.delete end |
#get_footer ⇒ Object
138 139 140 141 |
# File 'lib/cl_wiki/page.rb', line 138 def f = ClWiki::PageFormatter.new(nil, @full_name) f.(self) end |
#get_forward_ref(content) ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/cl_wiki/page.rb', line 143 def get_forward_ref(content) content_ary = content.split("\n") res = (content_ary.collect { |ln| ln.strip.empty? ? nil : ln }.compact.length == 1) if res res = content_ary[0] =~ /^see (.*)/i end if res page_name = $1 f = ClWiki::PageFormatter.new(content, @full_name) res = f.is_wiki_name?(page_name) if res res = ClWiki::Page.page_exists?(page_name) end end if res page_name else nil end end |
#get_header ⇒ Object
133 134 135 136 |
# File 'lib/cl_wiki/page.rb', line 133 def get_header f = ClWiki::PageFormatter.new(nil, @full_name) f.header(@full_name, self) end |
#process_custom_renderers ⇒ Object
122 123 124 125 126 127 128 129 130 131 |
# File 'lib/cl_wiki/page.rb', line 122 def process_custom_renderers root_dirs = [::File.join(::File.dirname(__FILE__), 'format')] + $wiki_conf.custom_formatter_load_path root_dirs.each do |root_dir| Dir[::File.join(root_dir, 'format.*')].each do |fn| require fn end end ClWiki::CustomFormatters.instance.process_formatters(@content, self) end |
#read_content(include_header_and_footer = true, include_diff = false) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/cl_wiki/page.rb', line 108 def read_content(=true, include_diff=false) read_page_attributes @content, final_page_name = read_raw_content_with_forwarding(@full_name) process_custom_renderers convert_newline_to_br f = ClWiki::PageFormatter.new(@content, final_page_name) @content = "<div class='wikiBody'>#{f.formatLinks}</div>" if @content = get_header + @content + end @content = CLabs::WikiDiffFormatter.format_diff(@wikiFile.diff) + @content if include_diff @content end |
#read_page_attributes ⇒ Object
74 75 76 77 78 |
# File 'lib/cl_wiki/page.rb', line 74 def read_page_attributes wikiFile = @wikiFile # ClWikiFile.new(@fullName, @wikiPath) @mtime = wikiFile.modTimeAtLastRead @fileFullPathAndName = wikiFile.fullPathAndName end |
#read_raw_content ⇒ Object
55 56 57 58 59 |
# File 'lib/cl_wiki/page.rb', line 55 def read_raw_content @raw_content = @wikiFile.content.join.gsub(/\r\n/, "\n") read_page_attributes ClWiki::Page.wikiIndexClient.add_hit(@full_name) if $wiki_conf.access_log_index end |
#read_raw_content_with_forwarding(full_page_name) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/cl_wiki/page.rb', line 80 def read_raw_content_with_forwarding(full_page_name) stack = [] history = [] content = '' final_page_name = full_page_name stack.push(full_page_name) while !stack.empty? this_pg_name = stack.pop if history.index(this_pg_name) pg_content = '-= CIRCULAR FORWARDING DETECTED =-' else pg = ClWiki::Page.new(this_pg_name) pg.read_raw_content pg_content = pg.raw_content fwd_full_page_name = get_forward_ref(pg_content) if fwd_full_page_name pg_content = "Auto forwarded from #{this_pg_name.strip_slash_prefix}<br><br>#{fwd_full_page_name}<br><br>" stack.push fwd_full_page_name else final_page_name = this_pg_name end end content << pg_content << "\n" history << this_pg_name end [content, final_page_name] end |
#update_content(newcontent, mtime) ⇒ Object
165 166 167 168 169 170 171 172 173 |
# File 'lib/cl_wiki/page.rb', line 165 def update_content(newcontent, mtime) wikiFile = @wikiFile # ClWikiFile.new(@fullName, @wikiPath) wikiFile.clientLastReadModTime = mtime wikiFile.content = newcontent if $wiki_conf.useIndex != ClWiki::Configuration::USE_INDEX_NO wikiIndexClient = ClWiki::IndexClient.new wikiIndexClient.reindex_page(@full_name) end end |