Class Site
In: app/models/site.rb
Parent: ActiveRecord::Base

A Site can be a BaselineProcess (static, published website from EPF) or a Wiki, which is an enhanced EPFC site. Baseline Processes are used to create or update Wiki sites.

Creation or update of a Wiki is a two step process for performance reasons. This way the second step can be performed using a job that runs at night.

More information:

Copyright (c) 2006 Logica

Methods

Constants

HTML_FILE_PATTERN = /.*.htm(l)?/i   A wikifiable file is a HTML file
WIKI_FILE_PATTERN = /(.)*wiki(.)*/i   A wikifiable is not a Wiki file (a version file created using the Wiki)

Public Class methods

array of HTML files that are candate Wikification

[Source]

     # File app/models/site.rb, line 98
 98:   def self.files_html(path)
 99:     paths = Array.new
100:      (Dir.entries(path) - [".", ".."]).each do |entry| 
101:       new_path = File.expand_path(entry, path)
102:       if FileTest.directory?(new_path)   
103:         paths = paths + Site.files_html(new_path)
104:       else
105:         paths << new_path if !HTML_FILE_PATTERN.match(entry).nil? && WIKI_FILE_PATTERN.match(entry).nil?
106:       end
107:     end
108:     return paths
109:   end

Method templates returns current versions of pages from the Wiki ‘Templates’. These pages are templates for creating new pages.

[Source]

    # File app/models/site.rb, line 77
77:   def self.templates
78:     w = Wiki.find_by_title('Templates')
79:     raise "No Templates Wiki was found. There should always be a Wiki with title 'Templates' to provide templates for creating new pages" if !w
80:     returning tpls = [] do
81:       w.pages.each do |p|
82:         tpls << p.current_version if p.current_version # NOTE: a new checked out Template has no current version
83:       end
84:     end
85:   end

Public Instance methods

[Source]

    # File app/models/site.rb, line 58
58:   def baseline_process?
59:     return self.class.name == 'BaselineProcess'
60:   end

[Source]

    # File app/models/site.rb, line 44
44:   def baseline_processes_candidate
45:     returning bp_candidate = [] do
46:       if self.status == 'Ready' # TODO
47:         Site.find_baseline_processes.each do |bp|
48:           bp_candidate << bp unless self.baselines.include?(bp.baseline)
49:         end
50:       end    
51:     end
52:   end

[Source]

    # File app/models/site.rb, line 40
40:    def content_scanned?
41:     return !self.content_scanned_on.nil?
42:   end

[Source]

     # File app/models/site.rb, line 111
111:   def files_wikifiable
112:     raise 'Path can\'t be blank' if self.path.blank?
113:     logger.info("Finding wikifiable files in #{self.path}")
114:     returning paths = [] do
115:       Site.files_html(self.path).each do |path2|
116:         #logger.info("#{path2}") 
117:         paths << path2 unless Page::ELEMENT_TYPE_PATTERN.match(IO.readlines(path2).join("\n")).nil?
118:       end
119:     end
120:   end

[Source]

    # File app/models/site.rb, line 62
62:   def path 
63:     return "#{ENV['EPFWIKI_ROOT_DIR']}#{ENV['EPFWIKI_PUBLIC_FOLDER']}/#{ENV['EPFWIKI_WIKIS_FOLDER']}/#{self.folder}" if self.wiki?
64:     return "#{ENV['EPFWIKI_ROOT_DIR']}#{ENV['EPFWIKI_PUBLIC_FOLDER']}/#{ENV['EPFWIKI_SITES_FOLDER']}/#{self.folder}"
65:   end

[Source]

    # File app/models/site.rb, line 71
71:   def path2zip 
72:     return self.path + '.zip'
73:   end

[Source]

    # File app/models/site.rb, line 67
67:   def rel_path
68:     return self.path.gsub(ENV['EPFWIKI_ROOT_DIR'] + "#{ENV['EPFWIKI_PUBLIC_FOLDER']}/",'')
69:   end

[Source]

    # File app/models/site.rb, line 87
87:   def unzip_upload
88:     logger.info("Unzipping upload #{self.path2zip}")
89:     raise "Folder #{self.path} exists" if File.exists?(self.path)
90:     cmdline = "unzip \"#{self.path2zip}\" -d \"#{self.path}\""
91:     logger.debug("Executing command #{cmdline}")
92:     cmd = IO.popen(cmdline, "w+")
93:     cmd.close_write
94:     write_log("unzip_upload.log", cmd.readlines.compact.join("\n"))
95:   end

[Source]

    # File app/models/site.rb, line 54
54:   def wiki?
55:     return self.class.name == 'Wiki'
56:   end

[Validate]