app/models/web.rb in Pimki-1.6.092 vs app/models/web.rb in Pimki-1.7.092

- old
+ new

@@ -4,12 +4,12 @@ require "wiki_words" require "zip/zip" class Web attr_accessor :pages, :name, :address, :password, :menu_type, :menu_content, :rendered_menu, :menu_limit, :menu_category - attr_accessor :markup, :color, :safe_mode, :additional_style, :published, :brackets_only, :count_pages - attr_accessor :mind_map_size, :symbols_map, :links_map, :enable_dclick_edit, :check_pass_on_edit + attr_accessor :markup, :color, :safe_mode, :additional_style, :published, :default_to_published, :brackets_only, :count_pages + attr_accessor :mind_map_size, :symbols_map, :links_map, :enable_dclick_edit, :check_pass_on_edit, :enable_menu # Mind Map defaults attr_accessor :mm_prog, :mm_graph_type, :mm_show_missing, :mm_show_authors, :mm_show_leaves, :mm_selected_categories @@BLIKI_TEMPLATE = "Try a weekly worksheet:\n\n| / | *Morning* | *Afternoon* |\n" + @@ -94,38 +94,35 @@ # Default values def markup() @markup || :textile end def color() @color || "008B26" end def brackets_only() @brackets_only || false end def count_pages() @count_pages || false end + def enable_menu() @enable_menu || true end def menu_content() @menu_content || nil end def menu_limit() @menu_limit || 20 end + def default_to_published() @default_to_published || false end def menu_type() (@menu_type.nil? || @menu_type.empty?) ? 'linkers' : @menu_type end def mind_map_size() (@mind_map_size == '0,0' ? '6,5' : @mind_map_size) end def mm_prog() @mm_prog || 'neato' end def mm_graph_type() @mm_graph_type || 'normal' end def mm_show_missing() @mm_show_missing || false end def mm_show_authors() @mm_show_authors || false end def mm_show_leaves() @mm_show_leaves || true end def mm_selected_categories() @mm_selected_categories || [] end - + # create a Mind Map graph and return the PNG and HTML map files generated - def create_mind_map(prog, missing, show_authors, show_leaves, selected_categories) + def create_mind_map(prog, missing, show_authors, show_leaves, selected_categories, mm_size) dotFile = File.expand_path("#{WikiService.storage_path}/graph.dot") mapFile = File.expand_path("#{WikiService.storage_path}/graph.map") pngFile = File.expand_path("#{WikiService.storage_path}/map.png") File.open(dotFile, "w") do |file| # Graph properties: - file.puts "digraph G {" - file.puts "size=\"#{mind_map_size}\";" - file.puts 'ratio=fill;' - file.puts 'concentrate=true;' - file.puts 'node [fontsize=10,fontname="Tahoma"];' - file.puts 'edge [len=1.5];' + output_graph_header_to file, mm_size # Links and node properties: nodes = filter_categories(pages.values, selected_categories) auths = authors # avoid repeated selects unless show_authors @@ -138,18 +135,18 @@ (page.wiki_words - [missing].flatten).size == 0 } end # Page Special nodes properties: - file.puts "HomePage [color=\"##{color}\",style=bold];" if nodes.map{ |p| p.name }.include? "HomePage" + file.puts %{"Home Page" [color=\"##{color}\",style=bold];} if nodes.map{ |p| p.name }.include? "HomePage" nodes.each do |page| - file.puts "#{page.name} [URL=\"../show/#{page.name}\"];" + 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 !show_authors and auths.include? referer.name - file.puts "#{referer.name} -> #{page.name};" + file.puts %{"#{referer.plain_name}" -> "#{page.plain_name}";} end end end end @@ -157,84 +154,74 @@ if missing shown_missing = [] nodes.each do |page| missing.each do |wanted| if page.content =~ /#{wanted}/ - file.puts "#{page.name} -> #{wanted};" + file.puts %{"#{page.plain_name}" -> "#{WikiWords.separate wanted}";} shown_missing << wanted end end end shown_missing.each do |wanted| - file.puts "#{wanted} [URL=\"/#{@address}/show/#{wanted}\", fontsize=10,style=filled,color=grey];" + file.puts %{"#{WikiWords.separate wanted}" [URL="/#{@address}/show/#{wanted}", fontsize=10,style=filled,color=grey];} end end - file.puts "}" + output_graph_footer_to file end call_graphviz(prog, dotFile, mapFile, pngFile) [pngFile, mapFile] end - def create_author_graph(prog, selected_categories) + def create_author_graph(prog, selected_categories, mm_size) dotFile = File.expand_path("#{WikiService.storage_path}/graph.dot") mapFile = File.expand_path("#{WikiService.storage_path}/graph.map") pngFile = File.expand_path("#{WikiService.storage_path}/map.png") File.open(dotFile, "w") do |file| # Graph properties: - file.puts "digraph G {" - file.puts "size=\"#{mind_map_size}\";" if mind_map_size - #file.puts 'ratio=fill;' - file.puts 'concentrate=true;' - file.puts 'node [fontsize=10,fontname="Tahoma"];' - file.puts 'edge [len=1.5];' + output_graph_header_to file, mm_size # Links and node properties: auths = authors # avoid repeated selects auths.each do |auth| - file.puts "#{auth} [style=filled,color=grey,URL=\"../show/#{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.name} [URL=\"../show/#{page.name}\"];" + file.puts %{"#{page.plain_name}" [URL="../show/#{page.name}"];} page.authors.each do |auth| - file.puts "#{auth} -> #{page.name};" + file.puts %{"#{auth}" -> "#{page.plain_name}";} end end - file.puts "}" + output_graph_footer_to file end call_graphviz(prog, dotFile, mapFile, pngFile) [pngFile, mapFile] end - def create_category_graph(prog, show_authors, selected_categories) #{{{ + def create_category_graph(prog, show_authors, selected_categories, mm_size) #{{{ dotFile = File.expand_path("#{WikiService.storage_path}/graph.dot") mapFile = File.expand_path("#{WikiService.storage_path}/graph.map") pngFile = File.expand_path("#{WikiService.storage_path}/map.png") File.open(dotFile, "w") do |file| # Graph properties: - file.puts "digraph G {" - file.puts "size=\"#{mind_map_size}\";" if mind_map_size - #file.puts 'ratio=fill;' - file.puts 'concentrate=true;' - file.puts 'node [fontsize=10,fontname="Tahoma"];' - file.puts 'edge [len=1.5];' + 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}\"];" + 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 = authors # avoid repeated selects @@ -242,23 +229,36 @@ nodes.delete_if { |entry| auths.include? entry.name } end nodes.each do |page| - file.puts "#{page.name} [URL=\"../show/#{page.name}\"];" + file.puts %{"#{page.plain_name}" [URL=\"../show/#{page.name}\"];} page.categories.each do |category| - file.puts "#{category} -> #{page.name};" + file.puts %{"#{category}" -> "#{page.plain_name}";} end end - file.puts "}" + output_graph_footer_to file end call_graphviz(prog, dotFile, mapFile, pngFile) [pngFile, mapFile] end #}}} + 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 + + def output_graph_footer_to file + file.puts "}" + end + 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' \ No newline at end of file