templates/default/start.rb in Soks-0.0.7 vs templates/default/start.rb in Soks-1.0.0

- old
+ new

@@ -1,144 +1,88 @@ #!/usr/local/bin/ruby # This file was created automatically on <%= Time.now %> -# Uncomment different sections to enable features of this wiki. - -#Get a logger going require 'logger' -$LOG = Logger.new(STDOUT) # For development -$LOG.level = Logger::DEBUG # For development -# $LOG = Logger.new('soks.log', 10, 1024000) # For production -# $LOG.level = Logger::WARN # For production + +$LOG = Logger.new(STDOUT) +$LOG.level = Logger::DEBUG $LOG.datetime_format = "%Y-%m-%d %H:%M:%S" #Add the required libraries to the search path begin require 'rubygems' - require_gem 'Soks', '= <%= settings[:version] %>' + require_gem 'Soks', '~> <%= settings[:version] %>' $LOG.info 'Loaded Soks <%= settings[:version] %> from gem' rescue LoadError $LOG.info "Soks Gem version <%= settings[:version] %> could not be found" $:.push( "<%= settings[:soks_libraries].join('","') %>" ) require 'soks' $LOG.info 'Loaded Soks libraries from <%= settings[:soks_libraries].join('","') %>' end -module StartSoks +root_directory = File.expand_path( File.dirname( __FILE__) ) +$MESSAGES = YAML.load( IO.readlines("#{root_directory}/views/messages.yaml").join ) +banned_titles = IO.readlines("#{root_directory}/banned_titles.txt").map { |title| title.strip } - # EDIT THIS TO CHANGE THE AUTHENTICATION -=begin - # If you uncomment this, don't forget to uncomment the authenticators line in the CUSTOMSETTINGS hash below! - # You can choose what level of authentication to apply based on regular expressions matched - # against the page title. These regexps are tried in order.Defaults are here: - authenticators = [ [ %r{/(view|rss|print|find|meta|attachment)/.*}, WEBrick::HTTPAuth::NoAuthenticationRequired.new ], - # [ %r{/upload/.*}, WEBrick::HTTPAuth::NotPermitted.new ], - # [ %r{/(edit|save)/home page}, WEBrick::HTTPAuth::SiteWidePassword.new('password','You need to enter the site wide password to edit the home page') ], - # [ %r{/(view|edit|save)/private.*},WEBrick::HTTPAuth::BasicAuth.new( :UserDB => htpasswd, :Realm => realm ) ], # See webrick documentation - [ %r{.*}, WEBrick::HTTPAuth::AskForUserName.new( 'No password, just enter a name') ] - ] -=end +server = WEBrick::HTTPServer.new(:Port => <%= settings[:port] %> ) - # EDIT THIS TO CHANGE THE BASIC SETTINGS, DEFAULTS ARE IN /LIB/SOKS.rb - CUSTOMSETTINGS = { - :root_directory => File.expand_path( File.dirname( __FILE__) ), - # :name => 'test', - # :description => 'A Soks Wiki', - # :server_type => WEBrick::Daemon, # Uncomment if you wish to fork, only works on some OSs - # :home_page => 'Home Page', - :url => '<%= settings[:url] %>', - :port => <%= settings[:port] %>, - # :authenticators => authenticators - } +wiki = Wiki.new( "#{root_directory}/content", "#{root_directory}/caches" ) +wiki.check_files_every = :min + +view = View.new( wiki, "<%= settings[:url] %>", "#{root_directory}/views" ) +view.name = 'A Soks Wiki' +view.description = 'A Soks Wiki for you!' +view.reload_erb_each_request = false +view.dont_frame_views = ['print','rss','listrss','linksfromrss'] +view.redcloth_hard_breaks = false +view.author_to_email_conversion = '@address-not-known.com' + +servlet = ServletSettings.new( wiki, view ) +servlet.home_page = 'Home Page' +servlet.content_types = { 'Rss' => 'application/xml', 'Listrss' => 'application/xml', 'Linksfromrss' => 'application/xml' } +servlet.force_no_cache = false + +servlet.authenticators << [ /\/(edit|save|upload|delete|rollback)\//i, WEBrick::HTTPAuth::AskForUserName.new( 'No password, just enter a name') ] +servlet.authenticators << [ /.*/, WEBrick::HTTPAuth::NoAuthenticationRequired.new ] + +servlet.static_file_directories[ 'Attachment' ] = "#{root_directory}/attachment" +servlet.upload_directory = 'Attachment' # Must be one of the static file directories + +wiki.watch_for(:start) do |event,wiki,view| + MergeOldRevisionsHelper.new( wiki, :day, 2, 60*60*24) - def self.start + AutomaticDetailedList.new( wiki, 'Known bugs' ) do |page| + page.name =~ /^Bug:/i && page.name !~ /^Bug: Type a title here/i + end - # EDIT THIS TO CHANGE THE HELPERS (Index, Recent changes etc) - start_wiki( CUSTOMSETTINGS ) do |wiki, view| + AutomaticList.new( wiki, 'Instructions and Howtos' ) { |page| page.name =~ /^How to /i } + AutomaticSummary.new( wiki, 'Latest News', :max_pages_to_show => 1, :reverse_sort => true) { |page| page.name =~ /^News:/i } + AutomaticSummary.new( wiki, 'All News', :reverse_sort => true) { |page| page.name =~ /^News:/i } - # Examples of automatically generated summary pages: - AutomaticSummary.new( wiki, - :regexp_for_title => /^How to /i, - :pagename => 'Instructions and Howtos' - ) - - AutomaticSummary.new( wiki, - :regexp_for_title => /^Bug:/i, - :regexp_to_exclude_title => /^Bug: Type a title here/i, - :pagename => 'Known bugs', - :include_metadata => true - ) - - AutomaticSummary.new( wiki, - :regexp_for_title => /^News:/i, - :max_pages_to_show => 1, - :lines_to_include => 10, - :reverse_sort => true, - :pagename => 'Latest News' - ) - - AutomaticSummary.new( wiki, - :regexp_for_title => /^News:/i, - :lines_to_include => 10, - :reverse_sort => true, - :pagename => 'All News' - ) - - # Possible settings for the Automatic Summary (with defaults) - # :regexp_for_title => /.*/, # These three regexps act as an AND - # :regexp_for_author => nil, - # :regexp_for_content => nil, - # :max_pages_to_show => nil, - # :pagename => 'Summary', - # :author => 'AutomaticSummary', - # :lines_to_include => nil, # nil puts a link, can pass a block instead to render - # :only_new_pages => false, - # :sort_pages_by => :created_on, # Could be :revised_on or :score or :name or :name_for_index, or :author - # :reverse_sort => false, - # :include_metadata => false, # Includes author and time in summary - # :summarise_revisions => false, # If true, then can contain several revisions for same page - # :remove_deleted_pages => true, # If false will keep references to deleted pages - - # These are beta and off by default... -=begin - require 'helpers/rss2wiki-helper' - RSS2WikiHelper.new( wiki, :url => 'http://rubyforge.org/export/rss_sfnews.php' ) - - require 'helpers/mail2wiki-helper' - Mail2WikiHelper.new( wiki, :server => 'imap.hermes.cam.ac.uk', - :username => 'tamc2', - :password => 'PASSWORD', - :mailbox => 'mcr notices', - :check_period => 600, # Seconds - :subject_regexp => /.*/ ) - - require 'helpers/wiki2html' - Wiki2Html.new( wiki, view, :views_to_copy => ['view','meta','rss'], - :extension => '.html', - :destination_dir => '/Users/tamc2/Sites', - :destination_url => 'http://localhost/~tamc2') -=end - - # Putting these towards the end speeds things up. - AutomaticRecentChanges.new( wiki ) - - AutomaticOnePageIndex.new( wiki ) # Index on one page, best for small wikis - # AutomaticMultiPageIndex.new( wiki ) # One page per letter index, best for large wikis - - # calendar = AutomaticCalendar.new( wiki ) # Adds a series of calendar pages to the wiki - # AutomaticUpcomingEvents.new( wiki, calendar ) # Creates a page with the next weeks events drawn from the calendar pages - - # This is an array of titles that will NOT be automatically linked. - # Default is the 30 most common words in the english language - # Note that pages can still be created with these titles, and they can still be manually linked to. - banned_titles = IO.readlines("#{CUSTOMSETTINGS[:root_directory]}/banned_titles.txt").map { |title| title.strip } - - # This takes a while, so do it last. Note that the banned_titles argument is optional. - AutomaticUpdateCrossLinks.new( wiki, view, banned_titles ) - end - end + #ViewCountHelper.new( wiki ) # Counts which are the most popular pages + #ViewerCountHelper.new( wiki ) # Counts who visits the wiki most + #AuthorCountHelper.new(wiki) # Counts who makes the most revisions + + AutomaticRecentChanges.new( wiki ) -end + AutomaticOnePageIndex.new( wiki ) # Index on one page, best for small wikis + # AutomaticMultiPageIndex.new( wiki ) # One page per letter index, best for large wikis + + #calendar = AutomaticCalendar.new( wiki ) # Adds a series of calendar pages to the wiki + #AutomaticUpcomingEvents.new( wiki, calendar ) # Creates a page with the next weeks events drawn from the calendar pages -if $0 == __FILE__ then - StartSoks::start -end + AutomaticUpdateCrossLinks.new( wiki, view, banned_titles ) +end + + +server.mount("/", WikiServlet, servlet ) + +trap("INT") { + $LOG.warn "Trying to shutdown gracefully" + server.shutdown + wiki.shutdown + $LOG.info "Shutdown." +} + +$LOG.warn "Starting server" +wiki.notify(:start,wiki,view) +server.start \ No newline at end of file