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.
-
#check_pass_on_edit ⇒ Object
Returns the value of attribute check_pass_on_edit.
-
#color ⇒ Object
Returns the value of attribute color.
-
#count_pages ⇒ Object
Returns the value of attribute count_pages.
-
#default_to_published ⇒ Object
Returns the value of attribute default_to_published.
-
#enable_dclick_edit ⇒ Object
Returns the value of attribute enable_dclick_edit.
-
#enable_menu ⇒ Object
Returns the value of attribute enable_menu.
-
#links_map ⇒ Object
Returns the value of attribute links_map.
-
#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.
-
#mind_map_size ⇒ Object
Returns the value of attribute mind_map_size.
-
#mm_graph_type ⇒ Object
Mind Map defaults.
-
#mm_prog ⇒ Object
Mind Map defaults.
-
#mm_selected_categories ⇒ Object
Mind Map defaults.
-
#mm_show_authors ⇒ Object
Mind Map defaults.
-
#mm_show_leaves ⇒ Object
Mind Map defaults.
-
#mm_show_missing ⇒ Object
Mind Map defaults.
-
#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.
-
#symbols_map ⇒ Object
Returns the value of attribute symbols_map.
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
-
#call_graphviz(prog, dotFile, mapFile, pngFile) ⇒ Object
}}}.
- #categories ⇒ Object
- #create_author_graph(prog, selected_categories, mm_size) ⇒ Object
-
#create_category_graph(prog, show_authors, selected_categories, mm_size) ⇒ Object
{{{.
-
#create_mind_map(prog, missing, show_authors, show_leaves, selected_categories, mm_size) ⇒ Object
create a Mind Map graph and return the PNG and HTML map files generated.
-
#filter_categories(pages, selected_categories) ⇒ Object
{{{.
-
#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.
- #output_graph_footer_to(file) ⇒ Object
-
#output_graph_header_to(file, mm_size) ⇒ Object
}}}.
-
#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
- #select_bliki(&accept) ⇒ Object
Constructor Details
#initialize(name, address, password = nil) ⇒ Web
Returns a new instance of Web.
23 24 25 26 |
# File 'app/models/web.rb', line 23 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 |
#check_pass_on_edit ⇒ Object
Returns the value of attribute check_pass_on_edit.
10 11 12 |
# File 'app/models/web.rb', line 10 def check_pass_on_edit @check_pass_on_edit 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 |
#default_to_published ⇒ Object
Returns the value of attribute default_to_published.
9 10 11 |
# File 'app/models/web.rb', line 9 def default_to_published @default_to_published end |
#enable_dclick_edit ⇒ Object
Returns the value of attribute enable_dclick_edit.
10 11 12 |
# File 'app/models/web.rb', line 10 def enable_dclick_edit @enable_dclick_edit end |
#enable_menu ⇒ Object
Returns the value of attribute enable_menu.
10 11 12 |
# File 'app/models/web.rb', line 10 def @enable_menu end |
#links_map ⇒ Object
Returns the value of attribute links_map.
10 11 12 |
# File 'app/models/web.rb', line 10 def links_map @links_map end |
#markup ⇒ Object
Default values
95 96 97 |
# File 'app/models/web.rb', line 95 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 @menu_category end |
#menu_content ⇒ Object
Returns the value of attribute menu_content.
8 9 10 |
# File 'app/models/web.rb', line 8 def @menu_content end |
#menu_limit ⇒ Object
Returns the value of attribute menu_limit.
8 9 10 |
# File 'app/models/web.rb', line 8 def @menu_limit end |
#menu_type ⇒ Object
Returns the value of attribute menu_type.
8 9 10 |
# File 'app/models/web.rb', line 8 def @menu_type end |
#mind_map_size ⇒ Object
Returns the value of attribute mind_map_size.
10 11 12 |
# File 'app/models/web.rb', line 10 def mind_map_size @mind_map_size end |
#mm_graph_type ⇒ Object
Mind Map defaults
13 14 15 |
# File 'app/models/web.rb', line 13 def mm_graph_type @mm_graph_type end |
#mm_prog ⇒ Object
Mind Map defaults
13 14 15 |
# File 'app/models/web.rb', line 13 def mm_prog @mm_prog end |
#mm_selected_categories ⇒ Object
Mind Map defaults
13 14 15 |
# File 'app/models/web.rb', line 13 def mm_selected_categories @mm_selected_categories end |
#mm_show_authors ⇒ Object
Mind Map defaults
13 14 15 |
# File 'app/models/web.rb', line 13 def @mm_show_authors end |
#mm_show_leaves ⇒ Object
Mind Map defaults
13 14 15 |
# File 'app/models/web.rb', line 13 def mm_show_leaves @mm_show_leaves end |
#mm_show_missing ⇒ Object
Mind Map defaults
13 14 15 |
# File 'app/models/web.rb', line 13 def mm_show_missing @mm_show_missing 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 @rendered_menu 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 |
#symbols_map ⇒ Object
Returns the value of attribute symbols_map.
10 11 12 |
# File 'app/models/web.rb', line 10 def symbols_map @symbols_map end |
Instance Method Details
#add_bliki_entry(page) ⇒ Object
Bliki methods
277 278 279 |
# File 'app/models/web.rb', line 277 def add_bliki_entry(page) bliki[page.name] = page end |
#add_page(page) ⇒ Object
28 29 30 |
# File 'app/models/web.rb', line 28 def add_page(page) @pages[page.name] = page end |
#authors ⇒ Object
52 53 54 |
# File 'app/models/web.rb', line 52 def select. end |
#bliki ⇒ Object
19 20 21 |
# File 'app/models/web.rb', line 19 def bliki @bliki ||= Hash.new end |
#bliki_entries_authored_by(author) ⇒ Object
297 298 299 |
# File 'app/models/web.rb', line 297 def () bliki.values.select { |page| page..include?() } end |
#bliki_entries_by_date ⇒ Object
281 282 283 |
# File 'app/models/web.rb', line 281 def bliki_entries_by_date bliki.values.sort_by { |page| page.revisions.first.created_at }.reverse end |
#bliki_entries_by_name ⇒ Object
285 286 287 |
# File 'app/models/web.rb', line 285 def bliki_entries_by_name pages.values.sort_by { |page| [page.name] } end |
#bliki_entries_that_match(regexp) ⇒ Object
289 290 291 |
# File 'app/models/web.rb', line 289 def bliki_entries_that_match(regexp) bliki.values.select { |page| page.content =~ /#{regexp}/i } end |
#bliki_entries_that_reference(page_name) ⇒ Object
293 294 295 |
# File 'app/models/web.rb', line 293 def bliki_entries_that_reference(page_name) bliki.values.select { |page| page.wiki_words.include?(page_name) } end |
#call_graphviz(prog, dotFile, mapFile, pngFile) ⇒ Object
}}}
270 271 272 273 |
# File 'app/models/web.rb', line 270 def call_graphviz(prog, dotFile, mapFile, pngFile) system("#{prog} -Tcmap \"#{dotFile}\" -o \"#{mapFile}\"") system("#{prog} -Tpng \"#{dotFile}\" -o \"#{pngFile}\"") end |
#categories ⇒ Object
56 57 58 |
# File 'app/models/web.rb', line 56 def categories select.map { |page| page.categories }.flatten.uniq.sort end |
#create_author_graph(prog, selected_categories, mm_size) ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'app/models/web.rb', line 175 def (prog, selected_categories, mm_size) 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: output_graph_header_to file, mm_size # 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.reject { |entry| auths.include? entry.name } nodes = filter_categories(nodes, selected_categories) nodes.each do |page| file.puts %{"#{page.plain_name}" [URL="../show/#{page.name}"];} page..each do |auth| file.puts %{"#{auth}" -> "#{page.plain_name}";} end end file end call_graphviz(prog, dotFile, mapFile, pngFile) [pngFile, mapFile] end |
#create_category_graph(prog, show_authors, selected_categories, mm_size) ⇒ Object
{{{
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 239 240 241 242 243 244 |
# File 'app/models/web.rb', line 208 def create_category_graph(prog, , selected_categories, mm_size) #{{{ 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: output_graph_header_to file, mm_size # Page Special nodes properties: categs = selected_categories.empty? ? categories : selected_categories categs.each do |category| file.puts %{"#{category}" [fontsize=20,style=filled,color=grey,comment="#{category}",URL="../list/?category=#{category}"];} end # Links and node properties: nodes = filter_categories(pages.values, selected_categories) auths = # avoid repeated selects unless nodes.delete_if { |entry| auths.include? entry.name } end nodes.each do |page| file.puts %{"#{page.plain_name}" [URL=\"../show/#{page.name}\"];} page.categories.each do |category| file.puts %{"#{category}" -> "#{page.plain_name}";} end end file end call_graphviz(prog, dotFile, mapFile, pngFile) [pngFile, mapFile] end |
#create_mind_map(prog, missing, show_authors, show_leaves, selected_categories, mm_size) ⇒ Object
create a Mind Map graph and return the PNG and HTML map files generated
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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'app/models/web.rb', line 113 def create_mind_map(prog, missing, , show_leaves, selected_categories, mm_size) 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: output_graph_header_to file, mm_size # Links and node properties: nodes = filter_categories(pages.values, selected_categories) auths = # avoid repeated selects unless nodes.delete_if { |entry| auths.include? entry.name } end unless show_leaves nodes.delete_if { |page| (page.wiki_words - [missing].flatten).size == 0 } end # Page Special nodes properties: file.puts %{"Home Page" [color=\"##{color}\",style=bold];} if nodes.map{ |p| p.name }.include? "HomePage" nodes.each do |page| file.puts %{"#{page.plain_name}" [URL=\"../show/#{page.name}\"];} page.references.each do |referer| unless page.name == referer.name or not nodes.include? referer unless ! and auths.include? referer.name file.puts %{"#{referer.plain_name}" -> "#{page.plain_name}";} end end end end # find missing pages: if missing shown_missing = [] nodes.each do |page| missing.each do |wanted| if page.content =~ /#{wanted}/ file.puts %{"#{page.plain_name}" -> "#{WikiWords.separate wanted}";} shown_missing << wanted end end end shown_missing.each do |wanted| file.puts %{"#{WikiWords.separate wanted}" [URL="/#{@address}/show/#{wanted}", fontsize=10,style=filled,color=grey];} end end file end call_graphviz(prog, dotFile, mapFile, pngFile) [pngFile, mapFile] end |
#filter_categories(pages, selected_categories) ⇒ Object
{{{
259 260 261 262 263 264 265 266 267 268 |
# File 'app/models/web.rb', line 259 def filter_categories(pages, selected_categories) #{{{ nodes = pages unless selected_categories.empty? nodes = pages.reject { |page| (page.categories & selected_categories).empty? } if selected_categories.include? 'none' nodes += pages.select { |page| page.categories.empty? } end end nodes 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.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/models/web.rb', line 63 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=\"../published/#{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 |
#output_graph_footer_to(file) ⇒ Object
255 256 257 |
# File 'app/models/web.rb', line 255 def file file.puts "}" end |
#output_graph_header_to(file, mm_size) ⇒ Object
}}}
246 247 248 249 250 251 252 253 |
# File 'app/models/web.rb', line 246 def output_graph_header_to file, mm_size file.puts "digraph G {" file.puts "size=\"#{mm_size}\";" if mm_size file.puts 'ratio=fill;' file.puts 'concentrate=true;' file.puts 'node [fontsize=10,fontname="Tahoma"];' file.puts 'edge [len=1.5];' end |
#refresh_pages_with_references(page_name) ⇒ Object
Clears the display cache for all the pages with references to
83 84 85 86 87 |
# File 'app/models/web.rb', line 83 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
89 90 91 92 |
# File 'app/models/web.rb', line 89 def refresh_revisions select.each { |page| page.revisions.each { |revision| revision.clear_display_cache } } select_bliki.each { |page| page.revisions.each { |revision| revision.clear_display_cache } } end |
#remove_pages(pages_to_be_removed) ⇒ Object
32 33 34 |
# File 'app/models/web.rb', line 32 def remove_pages(pages_to_be_removed) pages.delete_if { |page_name, page| pages_to_be_removed.include?(page) } end |
#revised_on ⇒ Object
36 37 38 |
# File 'app/models/web.rb', line 36 def revised_on pages.values.sort_by { |page| [page.created_at] }.reverse.first.created_at end |