Class: Web
- Inherits:
-
Object
- Object
- Web
- Defined in:
- app/models/web.rb
Direct Known Subclasses
Constant Summary collapse
- @@BLIKI_TEMPLATE =
"Try a weekly worksheet:\n\n| / | *Morning* | *Afternoon* |\n" + "| *Mon* | - | - |\n| *Tue* | - | - |\n| *Wed* | - | - |\n" + "| *Thu* | - | - |\n| *Fri* | - | - |\n"
Instance Attribute Summary collapse
-
#additional_style ⇒ Object
Returns the value of attribute additional_style.
-
#address ⇒ Object
Returns the value of attribute address.
-
#brackets_only ⇒ Object
Returns the value of attribute brackets_only.
-
#color ⇒ Object
Returns the value of attribute color.
-
#count_pages ⇒ Object
Returns the value of attribute count_pages.
-
#markup ⇒ Object
Default values.
-
#menu_category ⇒ Object
Returns the value of attribute menu_category.
-
#menu_content ⇒ Object
Returns the value of attribute menu_content.
-
#menu_limit ⇒ Object
Returns the value of attribute menu_limit.
-
#menu_type ⇒ Object
Returns the value of attribute menu_type.
-
#name ⇒ Object
Returns the value of attribute name.
-
#pages ⇒ Object
Returns the value of attribute pages.
-
#password ⇒ Object
Returns the value of attribute password.
-
#published ⇒ Object
Returns the value of attribute published.
-
#rendered_menu ⇒ Object
Returns the value of attribute rendered_menu.
-
#safe_mode ⇒ Object
Returns the value of attribute safe_mode.
Instance Method Summary collapse
-
#add_bliki_entry(page) ⇒ Object
Bliki methods.
- #add_page(page) ⇒ Object
- #authors ⇒ Object
- #bliki ⇒ Object
- #bliki_entries_authored_by(author) ⇒ Object
- #bliki_entries_by_date ⇒ Object
- #bliki_entries_by_name ⇒ Object
- #bliki_entries_that_match(regexp) ⇒ Object
- #bliki_entries_that_reference(page_name) ⇒ Object
- #categories ⇒ Object
- #create_author_graph(prog) ⇒ Object
-
#create_category_graph(prog, show_authors) ⇒ Object
{{{.
-
#create_mind_map(prog, missing, show_authors) ⇒ Object
create a Mind Map graph and return the PNG and HTML map files generated.
-
#initialize(name, address, password = nil) ⇒ Web
constructor
A new instance of Web.
-
#make_link(name, text = nil, options = {}) ⇒ Object
Create a link for the given page name and link text based on the render mode in options and whether the page exists in the this web.
-
#refresh_pages_with_references(page_name) ⇒ Object
Clears the display cache for all the pages with references to.
- #refresh_revisions ⇒ Object
- #remove_pages(pages_to_be_removed) ⇒ Object
- #revised_on ⇒ Object
- #select(&accept) ⇒ Object
Constructor Details
#initialize(name, address, password = nil) ⇒ Web
Returns a new instance of Web.
19 20 21 22 |
# File 'app/models/web.rb', line 19 def initialize(name, address, password = nil) @name, @address, @password, @safe_mode = name, address, password, false @pages = {} end |
Instance Attribute Details
#additional_style ⇒ Object
Returns the value of attribute additional_style.
9 10 11 |
# File 'app/models/web.rb', line 9 def additional_style @additional_style end |
#address ⇒ Object
Returns the value of attribute address.
8 9 10 |
# File 'app/models/web.rb', line 8 def address @address end |
#brackets_only ⇒ Object
Returns the value of attribute brackets_only.
9 10 11 |
# File 'app/models/web.rb', line 9 def brackets_only @brackets_only end |
#color ⇒ Object
Returns the value of attribute color.
9 10 11 |
# File 'app/models/web.rb', line 9 def color @color end |
#count_pages ⇒ Object
Returns the value of attribute count_pages.
9 10 11 |
# File 'app/models/web.rb', line 9 def count_pages @count_pages end |
#markup ⇒ Object
Default values
86 87 88 |
# File 'app/models/web.rb', line 86 def markup @markup end |
#menu_category ⇒ Object
Returns the value of attribute menu_category.
8 9 10 |
# File 'app/models/web.rb', line 8 def end |
#menu_content ⇒ Object
Returns the value of attribute menu_content.
8 9 10 |
# File 'app/models/web.rb', line 8 def end |
#menu_limit ⇒ Object
Returns the value of attribute menu_limit.
8 9 10 |
# File 'app/models/web.rb', line 8 def end |
#menu_type ⇒ Object
Returns the value of attribute menu_type.
8 9 10 |
# File 'app/models/web.rb', line 8 def end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'app/models/web.rb', line 8 def name @name end |
#pages ⇒ Object
Returns the value of attribute pages.
8 9 10 |
# File 'app/models/web.rb', line 8 def pages @pages end |
#password ⇒ Object
Returns the value of attribute password.
8 9 10 |
# File 'app/models/web.rb', line 8 def password @password end |
#published ⇒ Object
Returns the value of attribute published.
9 10 11 |
# File 'app/models/web.rb', line 9 def published @published end |
#rendered_menu ⇒ Object
Returns the value of attribute rendered_menu.
8 9 10 |
# File 'app/models/web.rb', line 8 def end |
#safe_mode ⇒ Object
Returns the value of attribute safe_mode.
9 10 11 |
# File 'app/models/web.rb', line 9 def safe_mode @safe_mode end |
Instance Method Details
#add_bliki_entry(page) ⇒ Object
Bliki methods
242 243 244 |
# File 'app/models/web.rb', line 242 def add_bliki_entry(page) bliki[page.name] = page end |
#add_page(page) ⇒ Object
24 25 26 |
# File 'app/models/web.rb', line 24 def add_page(page) @pages[page.name] = page end |
#authors ⇒ Object
44 45 46 |
# File 'app/models/web.rb', line 44 def select. end |
#bliki ⇒ Object
15 16 17 |
# File 'app/models/web.rb', line 15 def bliki @bliki ||= Hash.new end |
#bliki_entries_authored_by(author) ⇒ Object
262 263 264 |
# File 'app/models/web.rb', line 262 def () bliki.values.select { |page| page..include?() } end |
#bliki_entries_by_date ⇒ Object
246 247 248 |
# File 'app/models/web.rb', line 246 def bliki_entries_by_date bliki.values.sort_by { |page| page.revisions.first.created_at }.reverse end |
#bliki_entries_by_name ⇒ Object
250 251 252 |
# File 'app/models/web.rb', line 250 def bliki_entries_by_name pages.values.sort_by { |page| [page.name] } end |
#bliki_entries_that_match(regexp) ⇒ Object
254 255 256 |
# File 'app/models/web.rb', line 254 def bliki_entries_that_match(regexp) bliki.values.select { |page| page.content =~ /#{regexp}/i } end |
#bliki_entries_that_reference(page_name) ⇒ Object
258 259 260 |
# File 'app/models/web.rb', line 258 def bliki_entries_that_reference(page_name) bliki.values.select { |page| page.wiki_words.include?(page_name) } end |
#categories ⇒ Object
48 49 50 |
# File 'app/models/web.rb', line 48 def categories select.map { |page| page.categories }.flatten.uniq.sort end |
#create_author_graph(prog) ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'app/models/web.rb', line 157 def (prog) dotFile = File.("#{WikiService.storage_path}/graph.dot") mapFile = File.("#{WikiService.storage_path}/graph.map") pngFile = File.("#{WikiService.storage_path}/map.png") File.open(dotFile, "w") do |file| # Graph properties: file.puts "digraph G {" file.puts 'size="8,8";' file.puts 'ratio=fill;' file.puts 'concentrate=true;' file.puts 'node [fontsize=10,fontname="Tahoma"];' file.puts 'edge [len=1.5];' # Links and node properties: auths = # avoid repeated selects auths.each do |auth| file.puts "#{auth} [style=filled,color=grey,URL=\"../show/#{auth}\"];" end nodes = pages.values nodes.delete_if { |entry| auths.include? entry.name } nodes.each do |page| file.puts "#{page.name} [URL=\"../show/#{page.name}\"];" page..each do |auth| file.puts "#{auth} -> #{page.name};" end end file.puts "}" end system("#{prog} -Tcmap #{dotFile} -o #{mapFile}") system("#{prog} -Tpng #{dotFile} -o #{pngFile}") [pngFile, mapFile] end |
#create_category_graph(prog, show_authors) ⇒ Object
{{{
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'app/models/web.rb', line 196 def create_category_graph(prog, ) #{{{ dotFile = File.("#{WikiService.storage_path}/graph.dot") mapFile = File.("#{WikiService.storage_path}/graph.map") pngFile = File.("#{WikiService.storage_path}/map.png") File.open(dotFile, "w") do |file| # Graph properties: file.puts "digraph G {" file.puts 'size="8,8";' file.puts 'ratio=fill;' file.puts 'concentrate=true;' file.puts 'node [fontsize=10,fontname="Tahoma"];' file.puts 'edge [len=1.5];' # Page Special nodes properties: file.puts "HomePage [color=\"##{color}\",style=bold];" categories.each do |category| file.puts "#{category} [fontsize=20,style=filled,color=grey,comment=\"#{category}\"];" end # Links and node properties: nodes = pages.values auths = # avoid repeated selects unless == 'on' nodes.delete_if { |entry| auths.include? entry.name } end nodes.each do |page| file.puts "#{page.name} [URL=\"../show/#{page.name}\"];" page.categories.each do |category| file.puts "#{category} -> #{page.name};" end end file.puts "}" end system("#{prog} -Tcmap #{dotFile} -o #{mapFile}") system("#{prog} -Tpng #{dotFile} -o #{pngFile}") [pngFile, mapFile] end |
#create_mind_map(prog, missing, show_authors) ⇒ Object
create a Mind Map graph and return the PNG and HTML map files generated
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'app/models/web.rb', line 97 def create_mind_map(prog, missing, ) dotFile = File.("#{WikiService.storage_path}/graph.dot") mapFile = File.("#{WikiService.storage_path}/graph.map") pngFile = File.("#{WikiService.storage_path}/map.png") File.open(dotFile, "w") do |file| # Graph properties: file.puts "digraph G {" file.puts 'size="8,8";' file.puts 'ratio=fill;' file.puts 'concentrate=true;' file.puts 'node [fontsize=10,fontname="Tahoma"];' file.puts 'edge [len=1.5];' # Page Special nodes properties: file.puts "HomePage [color=\"##{color}\",style=bold];" # Links and node properties: nodes = pages.values auths = # avoid repeated selects unless == 'on' nodes.delete_if { |entry| auths.include? entry.name } end nodes.each do |page| file.puts "#{page.name} [URL=\"../show/#{page.name}\"];" page.references.each do |referer| unless page.name == referer.name unless != 'on' and auths.include? referer.name file.puts "#{referer.name} -> #{page.name};" end end end end # find missing pages: if missing missing.each do |wanted| file.puts "#{wanted} [URL=\"/#{@address}/show/#{wanted}\", fontsize=10,style=filled,color=grey];" end pages.values.each do |page| missing.each do |wanted| if page.content =~ /#{wanted}/ file.puts "#{page.name} -> #{wanted};" end end end end file.puts "}" end system("#{prog} -Tcmap #{dotFile} -o #{mapFile}") system("#{prog} -Tpng #{dotFile} -o #{pngFile}") [pngFile, mapFile] end |
#make_link(name, text = nil, options = {}) ⇒ Object
Create a link for the given page name and link text based on the render mode in options and whether the page exists in the this web.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/models/web.rb', line 55 def make_link(name, text = nil, = {}) page = pages[name] text = text || WikiWords.separate(name) link = CGI.escape(name) case [:mode] when :export if page then "<a class=\"existingWikiWord\" href=\"#{link}.html\">#{text}</a>" else "<span class=\"newWikiWord\">#{text}</span>" end when :publish if page then "<a class=\"existingWikiWord\" href=\"../show/#{link}\">#{text}</a>" else "<span class=\"newWikiWord\">#{text}</span>" end else if page then "<a class=\"existingWikiWord\" href=\"../show/#{link}\">#{text}</a>" else "<span class=\"newWikiWord\">#{text}<a href=\"../show/#{link}\">?</a></span>" end end end |
#refresh_pages_with_references(page_name) ⇒ Object
Clears the display cache for all the pages with references to
75 76 77 78 79 |
# File 'app/models/web.rb', line 75 def refresh_pages_with_references(page_name) select.pages_that_reference(page_name).each { |page| page.revisions.each { |revision| revision.clear_display_cache } } end |
#refresh_revisions ⇒ Object
81 82 83 |
# File 'app/models/web.rb', line 81 def refresh_revisions select.each { |page| page.revisions.each { |revision| revision.clear_display_cache } } end |
#remove_pages(pages_to_be_removed) ⇒ Object
28 29 30 |
# File 'app/models/web.rb', line 28 def remove_pages(pages_to_be_removed) pages.delete_if { |page_name, page| pages_to_be_removed.include?(page) } end |
#revised_on ⇒ Object
32 33 34 |
# File 'app/models/web.rb', line 32 def revised_on pages.values.sort_by { |page| [page.created_at] }.reverse.first.created_at end |
#select(&accept) ⇒ Object
36 37 38 |
# File 'app/models/web.rb', line 36 def select(&accept) PageSet.new(self, @pages.values, accept) end |