diff options
Diffstat (limited to 'ruwiki/tags/release-0.7/lib/ruwiki')
19 files changed, 0 insertions, 2212 deletions
diff --git a/ruwiki/tags/release-0.7/lib/ruwiki/backend.rb b/ruwiki/tags/release-0.7/lib/ruwiki/backend.rb deleted file mode 100644 index e0d4178..0000000 --- a/ruwiki/tags/release-0.7/lib/ruwiki/backend.rb +++ /dev/null @@ -1,165 +0,0 @@ -#-- -# Ruwiki -# Copyright © 2002 - 2004, Digikata and HaloStatue -# Alan Chen (alan@digikata.com) -# Austin Ziegler (ruwiki@halostatue.ca) -# -# Licensed under the same terms as Ruby. -# -# $Id$ -#++ -require 'algorithm/diff' - -class Ruwiki - # The list of known backends. - KNOWN_BACKENDS = [:flatfiles] - - # The Ruwiki backend delegator. Ruwiki will always instantiate a version - # of this class which delegates the actual method execution to the Backend - # class. Error handling is handled by capturing (and possibly forwarding) - # exceptions raised by the delegate class. - class BackendDelegator - def initialize(ruwiki, backend) - @message = ruwiki.config.message - options = ruwiki.config.storage_options - - unless Ruwiki::KNOWN_BACKENDS.include?(backend) - raise RuntimeError, @message[:backend_unknown] % [backend] - end - - beconst = (befile = backend.id2name).capitalize - - require "ruwiki/backend/#{befile}" - - beoptions = options[backend] - @delegate = Ruwiki::Backend.const_get(beconst).new(beoptions) - rescue Ruwiki::Backend::BackendError => e - if e.kind_of?(Array) - raise Ruwiki::Backend::BackendError.new(nil), @message[e.reason[0]] % e.reason[1] - else - raise - end - end - - # Retrieve the specified topic and project page. Calls Backend#load - # after verifying that the project exists. - def retrieve(topic, project = 'Default') - unless page_exists?(topic, project) - if project_exists?(project) - return { :content => "", :topic => topic, :project => project } - else - return { :content => @message[:project_does_not_exist] % [project], - :topic => topic, :project => project } - end - end - - buffer = @delegate.load(topic, project) - return { :rawtext => buffer.join(""), :project => project, :topic => topic } - rescue Errno::EACCES => e - raise Ruwiki::Backend::BackendError.new(e), @message[:no_access_to_read_topic] % [project, topic] - rescue Exception => e - p = [project, topic, %Q~#{e}<br />\n#{e.backtrace.join('<br />\n')}~] - raise Ruwiki::Backend::BackendError.new(e), @message[:cannot_retrieve_topic] % p - end - - # Stores the specified topic and project page. - def store(page) - @delegate.store(page) - rescue Errno::EACCES => e - raise Ruwiki::Backend::BackendError.new(e), @message[:no_access_to_store_topic] % [page.project, page.topic] - rescue Exception => e - p = [page.project, page.topic, %Q~#{e}<br />\n#{e.backtrace.join('<br />\n')}~] - raise Ruwiki::Backend::BackendError.new(e), @message[:cannot_store_topic] % p - end - - # Destroys the specified topic and project page. - def destroy(page) - @delegate.destroy(page) - rescue Errno::EACCES => e - raise Ruwiki::Backend::BackendError.new(e), @message[:no_access_to_destroy_topic] % [page.project, page.topic] - rescue Exception => e - p = [project, topic, %Q~#{e}<br />\n#{e.backtrace.join('<br />\n')}~] - raise Ruwiki::Backend::BackendError.new(e), @message[:cannot_destroy_topic] % p - end - - # Releases the lock on the page. - def release_lock(page, address = 'UNKNOWN') - @delegate.release_lock(page, address) - rescue Ruwiki::Backend::BackendError - raise Ruwiki::Backend::BackendError.new(nil), @message[:cannot_release_lock] % [page.project, page.topic] - rescue Errno::EACCES, Exception => e - p = [project, topic, %Q~#{e}<br />\n#{e.backtrace.join('<br />\n')}~] - raise Ruwiki::Backend::BackendError.new(e), @message[:error_releasing_lock] % p - end - - # Attempts to obtain a lock on the page. - def obtain_lock(page, address = 'UNKNOWN', timeout = 600) - @delegate.obtain_lock(page, address, timeout) - rescue Ruwiki::Backend::BackendError - raise Ruwiki::Backend::BackendError.new(nil), @message[:cannot_obtain_lock] % [page.project, page.topic] - rescue Errno::EACCES, Exception => e - p = [project, topic, %Q~#{e}<br />\n#{e.backtrace.join('<br />\n')}~] - raise Ruwiki::Backend::BackendError.new(e), @message[:error_creating_lock] % p - end - - # Checks to see if the project exists. - def project_exists?(project) - @delegate.project_exists?(project) - end - - # Checks to see if the page exists. - def page_exists?(topic, project = 'Default') - @delegate.page_exists?(topic, project) - end - - # Attempts to create the project. - def create_project(project) - @delegate.create_project(project) - rescue Ruwiki::Backend::ProjectExists => e - raise Ruwiki::Backend::BackendError.new(e), @message[:project_already_exists] % [project] - rescue Errno::EACCES => e - raise Ruwiki::Backend::BackendError.new(e), @message[:no_access_to_create_project] % [project] - rescue Exception => e - p = [project, %Q~#{e}<br />\n#{e.backtrace.join('<br />\n')}~] - raise Ruwiki::Backend::BackendError.new(e), @message[:cannot_create_project] % p - end - - # Attempts to destroy the project. - def destroy_project(project) - @delegate.destroy_project(project) - rescue Errno::EACCES => e - raise Ruwiki::Backend::BackendError.new(e), @message[:no_access_to_destroy_project] % [project] - rescue Exception => e - p = [project, %Q~#{e}<br />\n#{e.backtrace.join('<br />\n')}~] - raise Ruwiki::Backend::BackendError.new(e), @message[:cannot_destroy_project] % p - end - end - - # The Ruwiki backend abstract class and factory. - class Backend - class ProjectExists < StandardError #:nodoc: - end - class BackendError < StandardError #:nodoc: - attr_reader :reason - - def initialize(reason, *args) - @reason = reason - end - end - def initialize(storage_options) - end - - private - # Creates the current diff object. - def make_diff(page, oldpage, newpage) - { - 'old_version' => page.old_version, - 'new_version' => page.version, - 'change_date' => Time.now, - 'change_ip' => page.change_ip, - 'change_id' => page.change_id, - 'diff' => Diff.diff(oldpage, newpage) - } - end - end -end diff --git a/ruwiki/tags/release-0.7/lib/ruwiki/backend/flatfiles.rb b/ruwiki/tags/release-0.7/lib/ruwiki/backend/flatfiles.rb deleted file mode 100644 index e00c5c2..0000000 --- a/ruwiki/tags/release-0.7/lib/ruwiki/backend/flatfiles.rb +++ /dev/null @@ -1,155 +0,0 @@ -#-- -# Ruwiki -# Copyright © 2002 - 2004, Digikata and HaloStatue -# Alan Chen (alan@digikata.com) -# Austin Ziegler (ruwiki@halostatue.ca) -# -# Licensed under the same terms as Ruby. -# -# $Id$ -#++ -class Ruwiki - class Backend - # Stores Ruwiki pages as flatfiles. - class Flatfiles < Ruwiki::Backend - # Initializes the flatfile backend. This will read - # storage_options[:flatfiles] to determine the options set by the - # user. The following options are known for <tt>:flatfiles</tt>: - # - # :data_path:: The directory in which the wiki files will be found. - # By default, this is "./data/" - # :extension:: The extension of the wiki files. By default, this is - # +nil+. - def initialize(options) - options[:data_path] ||= "./data/" - @data_path = options[:data_path] - @extension = options[:extension] - if not (File.exists?(@data_path) and File.directory?(@data_path)) - raise Ruwiki::Backend::BackendError.new([:flatfiles_no_data_directory, [@data_path]]) - end - super options - end - - # Loads the topic page from disk. - def load(topic, project) - pagefile = page_file(topic, project) - buffer = File.readlines(pagefile) - end - - # Saves the topic page -- and its difference with the previous version - # -- to disk. - def store(page) - pf = page_file(page.topic, page.project) - cf = "#{pf}.rdiff" - - oldfile = File.readlines(pf) rescue [] - oldfile.collect! { |e| e.chomp } - newfile = page.rawtext.split(/\n/) - - diff = make_diff(page, oldfile, newfile) - diffs = [] - File.open(cf, 'rb') { |f| diffs = Marshal.load(f) } if File.exists?(cf) - diffs << diff - changes = Marshal.dump(diffs) - - File.open(cf, 'wb') { |cfh| cfh.print changes } - File.open(pf, 'wb') { |pfh| pfh.puts page.rawtext } - end - - # Destroys the topic page. - def destroy(page) - pf = page_file(page.topic, page.project) - File.unlink(pf) if File.exists?(pf) - end - - # Checks to see if the project exists. - def project_exists?(project) - pd = project_directory(project) - File.exists?(pd) and File.directory?(pd) - end - - # Checks to see if the page exists. - def page_exists?(topic, project = 'Default') - pf = page_file(topic, project) - project_exists?(project) and File.exists?(pf) - end - - # Tries to create the project. - def create_project(project) - pd = project_directory(project) - raise Ruwiki::Backend::ProjectExists if File.exists?(pd) - Dir.mkdir(pd) - end - - # Tries to destroy the project. - def destroy_project(project) - pd = project_directory(project) - Dir.rmdir(pd) if File.exists?(pd) and File.directory?(pd) - end - - # Attempts to obtain a lock on the topic page. - def obtain_lock(page, address = 'UNKNOWN', timeout = 600) - pf = page_file(page.topic, page.project) - lf = "#{pf}.lock" - time = Time.now.to_i - - lock_okay = false - # See if we have the lock already. - if File.exists?(lf) - data = File.readlines(lf) - # If the lock belongs to this address, we don't care how old it - # is. Thus, release it. - lock_okay ||= (data[0].chomp == address) - # If the lock is older than 10 minutes, release it. - lock_okay ||= (data[1].to_i < time) - else - lock_okay = true - end - - if lock_okay - open(lf, 'w') { |lfh| lfh.puts "#{address}\n#{time + timeout}" } - else - raise Ruwiki::Backend::BackendError(nil) - end - end - - # Releases the lock on the topic page. - def release_lock(page, address = 'UNKNOWN') - pf = page_file(page.topic, page.project) - lf = "#{pf}.lock" - time = Time.now.to_i - - lock_okay = false - if File.exists?(lf) - data = File.readlines(lf) - # If the lock belongs to this address, then we can safely remove - # it. - lock_okay ||= (data[0].chomp == address) - # If the lock is older than 10 minutes, release it. - lock_okay ||= (data[1].to_i < time) - else - lock_okay = true - end - - if lock_okay - File.unlink(lf) if File.exists?(lf) - else - raise Ruwiki::Backend::BackendError.new(nil) - end - end - - private - def project_directory(project) - File.join(@data_path, project) - end - - def page_file(topic, project = 'Default') - if @extension.nil? - File.join(project_directory(project), topic) - else - File.join(project_directory(project), "#{topic}.#{@extension}") - end - end - end - end -end diff --git a/ruwiki/tags/release-0.7/lib/ruwiki/config.rb b/ruwiki/tags/release-0.7/lib/ruwiki/config.rb deleted file mode 100644 index ba3acea..0000000 --- a/ruwiki/tags/release-0.7/lib/ruwiki/config.rb +++ /dev/null @@ -1,134 +0,0 @@ -#-- -# Ruwiki -# Copyright © 2002 - 2004, Digikata and HaloStatue -# Alan Chen (alan@digikata.com) -# Austin Ziegler (ruwiki@halostatue.ca) -# -# Licensed under the same terms as Ruby. -# -# $Id$ -#++ -class Ruwiki - # Features known to Ruwiki. - KNOWN_FEATURES = [ ] - - # Ruwiki configuration. - class Config - # Templates known to Ruwiki. - TEMPLATES = [ :body, :content, :error, :edit, :controls, :save ] - - # Adds additional information to the (rare) error reports. Defaults to - # +false+. - attr_accessor :debug - # The default page for display when Ruwiki is called without any - # arguments. Defaults to +ProjectIndex+ - attr_accessor :default_page - # The default project for display when Ruwiki is called without any - # arguments or a project specification. Defaults to +Default+ - attr_accessor :default_project - # The storage type as a Symbol. Corresponds to a filename that will be - # found in ruwiki/backend. In this version of Ruwiki, only flatfiles.rb - # (e.g., :flatfiles) is defined. Defaults to <tt>:flatfiles</tt>. - attr_accessor :storage_type - # The options for the specified storage type. This is a hash of hashes - # with auto-vifification. See the storage type for available options. - attr_reader :storage_options - # The options for the specified feature. This is a hash of hashes with - # auto-vifification. See #features for more information. - attr_reader :feature_options - # The path for templates. Defaults to <tt>./templates/</tt>. - attr_accessor :template_path - # The name of the Wiki. Defaults to <tt>ruwiki</tt> - attr_accessor :title - # The email address of the webmaster for the Wiki. Defaults to +nil+. - attr_accessor :webmaster - # The name of the Ruwiki CSS file. Defaults to <tt>ruwiki.css</tt>. - attr_accessor :css - # The template set. Templates are always named as - # <template_path>/<template_set>/<template_kind>. - #Template filename. Must be reachable by File#read. - attr_accessor :template_set - # Ruwiki is internationalized. This method sets the Ruwiki error - # messages (and a few other messages) )to the specified language Module. - # The language Module must have a constant Hash called +Message+ - # containing a set of symbols and localized versions of the messages - # associated with them. - # - # If the file 'ruwiki/lang/es.rb' contains the module - # <tt>Ruwiki::Lang::ES</tt>, the error messages for RSS could be - # localized to Español thus: - # - # require 'ruwiki/lang/es' - # ... - # wiki.config.language = Ruwiki::Lang::ES - # - # Localization is per wiki instance. In a servlet environment, this may - # mean that only a single language is recognised. - # - # See Ruwiki::Lang::EN for more information. - attr_accessor :language - # The message hash. - attr_reader :message - - def language=(l) #:nodoc: - @language = l - @message = l::Message - @message.default = l::Message.default - end - - # Returns the template string - def template(kind = :body) - raise ConfigError, message[:no_template_found] % [kind.inspect, @template_set] unless TEMPLATES.include?(kind) - File.read(File.join(@template_path, @template_set, "#{kind.to_s}.tmpl")) - end - - # Returns a copy of the list of features supported by this Wiki. - def features - @features.dup - end - - # Adds a new feature to the Wiki. - def add_feature(feature) - raise ConfigError, message[:unknown_feature] % [feature.inspect] unless KNOWN_FEATURES.include?(feature) - @features << feature - end - - # Returns the CSS stylesheet content for the Wiki. This previously - # returned the <link> to the stylesheet, but instead returns a <style> - # block in the head so that the CSS is kept with the template set, which - # may be kept outside of the HTML area. - def css_link - %Q[<style>#{File.read(File.join(@template_path, @template_set, @css))}</style>] - end - - # Creates a new configuration object. - def initialize - @debug = false - @default_project = "Default" - @default_page = "ProjectIndex" - @storage_type = :flatfiles - @storage_options = Hash.new { |h, k| h[k] = {} } - @template_path = "./templates/" - @template_set = "default" - @css = "ruwiki.css" - @webmaster = nil - @title = "Ruwiki" - @features = [] - @feature_options = Hash.new { |h, k| h[k] = {} } - - self.language = Ruwiki::Lang::EN - end - - # Verifies that required configuration options are actually set. Right - # now, it only checks the values that are defaulted to +nil+. - def verify - raise ConfigError, message[:no_webmaster_defined] if @webmaster.nil? - raise ConfigError, message[:invalid_template_dir] % [@template_path] unless File.exists?(@template_path) and File.directory?(@template_path) - t = File.join(@template_path, @template_set) - raise ConfigError, message[:no_template_set] % [@template_set] unless File.exists?(t) and File.directory?(t) - end - - class ConfigError < StandardError #:nodoc: - end - end -end diff --git a/ruwiki/tags/release-0.7/lib/ruwiki/handler.rb b/ruwiki/tags/release-0.7/lib/ruwiki/handler.rb deleted file mode 100644 index e31bbc1..0000000 --- a/ruwiki/tags/release-0.7/lib/ruwiki/handler.rb +++ /dev/null @@ -1,207 +0,0 @@ -#-- -# Ruwiki -# Copyright © 2002 - 2004, Digikata and HaloStatue -# Alan Chen (alan@digikata.com) -# Austin Ziegler (ruwiki@halostatue.ca) -# -# Licensed under the same terms as Ruby. -# -# $Id$ -#++ -class Ruwiki - class Handler - class << self - # Generate a new Handler pair from a CGI request. - def from_cgi(cgi, output_stream = $stdout) - Ruwiki::Handler.new do |o| - o.request = Ruwiki::Handler::CGIRequest.new(cgi) - o.response = Ruwiki::Handler::CGIResponse.new(cgi, output_stream) - end - end - - # Generate a new Handler pair from a WEBrick request. - def from_webrick(req, res) - Ruwiki::Handler.new do |o| - o.request = Ruwiki::Handler::WEBrickRequest.new(req) - o.response = Ruwiki::Handler::WEBrickResponse.new(res) - end - end - end - - # Returns the handler's request object. - attr_accessor :request - # Returns the handler's response object. - attr_accessor :response - - # Creates the handler pair. - def initialize(&block) #:yields: self - @request = nil - @response = nil - yield self if block_given? - end - - # REpresents an abstract incoming request. This insulates the rest of - # the code from knowing whether parameters are passed as part of the - # path, as parameters in the URL, or in some other fashion. - class AbstractRequest - def initialize(*args) - end - end - - # Handles all requests from web applications. - # - # Subclasses should provide: - # @parameters:: Hash-like object that responds to #[] and #hash_key?] - # @environment:: Hash-like object that responds to #[] - class AbstractWebRequest < AbstractRequest - # The parameters provided via the web request. - attr_reader :parameters - # The environment provided to the web request. - attr_reader :environment - # The request path. - attr_reader :path - - # Yields each parameter key in succession. - def each_parameter #:yields: key, value - @parameters.each { |k, v| yield k, v } - end - - def each_environment #:yields: key, value - @environment.each { |k, v| yield k, v } - end - - # Return the URL of our server. - def server_url - res = "http://" # should detect whether we're in secure server mode. - if @environment['HTTP_HOST'] - res << @environment['HTTP_HOST'] - else - res << "#{@environment['SERVER_NAME']}:#{@environment['SERVER_PORT']}" - end - end - - # Return the URL of this script. - def script_url - server_url << @environment['SCRIPT_NAME'].to_s - end - - # Return the URL of this request. - def request_url - res = script_url - res << @environment['PATH_INFO'] if @environment['PATH_INFO'] - query = @environment['QUERY_STRING'] - res << "?#{@environment['QUERY_STRING']}" if query && !query.empty? - res - end - - # Convert a file path into a URL - def make_url(project, path) - "#{server_url}/#{project}/#{path}" - end - - def determine_request_path - @path = "" - return @path if @environment['PATH_INFO'].nil? - @path = @environment['PATH_INFO'].dup - end - end - - # Request for CGI-based activity to ruwiki. - class CGIRequest < AbstractWebRequest - def initialize(cgi, output_stream = $stdout) - @environment = ENV - @cgi = cgi - @parameters = {} - cgi.params.each { |k, v| @parameters[k] = v[0] } - super - end - end - - # Request for WEBrick based servlet activity to ruwiki. - class WEBrickRequest < AbstractWebRequest - def initialize(req) - @environment = req.meta_vars - @parameters = req.query - super - end - end - - # Used to write responses in different execution environments such as - # CGI and Webrick. - # - # If you want to create a new response object, you'll need to implement - # #add_header, #write_headers, and #<<. - # - # The Response object is instantiated with an output stream which must - # supply +<<+ and +puts+ methods. - class AbstractResponse - # Add to the list of headers to be sent back to the client. - def add_header(key, value) - raise "Not implemented" - end - - # Write the accumulated headers back to the client. - def write_headers - raise "Not implemented" - end - - # Write the string to the client. - def <<(string) - raise "Not implemented" - end - - # output_stream must respond to #<< and #puts. - def initialize(output_stream = $stdout) - @headers = {} - @output_stream = output_stream - end - end - - # CGIResponse is the response object for CGI mode. - class CGIResponse < AbstractResponse - # output_stream must respond to #<< and #puts. - def initialize(cgi, output_stream = $stdout) - @cgi = cgi - super(output_stream) - end - - # Add the header pair for later output as a CGI header. - def add_header(key, value) - @headers[key] = value - end - - # Write the headers to the stream. The headers can only be written - # once. - def write_headers - return if @written - @headers.each { |key, value| @output_stream.puts "#{key}: #{value}\r\n" } - @output_stream.puts - @written = true - end - - # Output the string to the stream provided. - def <<(string) - @output_stream << string - end - end - - # WEBrickResponse is the response object for WEBrick servlet mode. - class WEBrickResponse < AbstractResponse - def initialize(webrick_response) - @response = webrick_response - end - - def add_header(key,value) - @response[key] = value - end - - def write_headers - # Webrick will take care of this on its own. - end - - def <<(string) - @response.body << string - end - end - end -end diff --git a/ruwiki/tags/release-0.7/lib/ruwiki/lang/de.rb b/ruwiki/tags/release-0.7/lib/ruwiki/lang/de.rb deleted file mode 100644 index 721c44a..0000000 --- a/ruwiki/tags/release-0.7/lib/ruwiki/lang/de.rb +++ /dev/null @@ -1,60 +0,0 @@ -#-- -# Ruwiki -# Copyright © 2002 - 2004, Digikata and HaloStatue -# Alan Chen (alan@digikata.com) -# Austin Ziegler (austin@halostatue.ca) -# Translation by Christian Neukirchen (chneukirchen@yahoo.de) on 22oct2003 -# -# Licensed under the same terms as Ruby. -# -# $Id$ -#++ -class Ruwiki - module Lang - # Ruwiki::Lang::DE is the German-language output module. It contains a - # hash, *Message*, that contains the messages that may be reported by - # any method in the Ruwiki library. The messages are identified by a - # Symbol. - module DE - Message = { - # The encoding for the webpages. This should match the encoding used - # to create these messages. - :encoding => "iso-8859-1", - # Backend-related messages. - :backend_unknown => "Unbekanntes Backend %s.", - :cannot_create_project => "Kann %s nicht erstellen: %s", - :cannot_destroy_project => "Kann %s nicht zerstören: %s", - :cannot_destroy_topic => "Kann %s::%s nicht zerstören: %s", - :cannot_obtain_lock => "Kann keine Sperre für %s::%s erhalten. Bitte in Kürze nochmal versuchen.", - :cannot_release_lock => "Kann die Sperre für %s::%s nicht lösen. Bitte später nochmal versuchen.", - :cannot_retrieve_topic => "Kann auf %s::%s nicht zugreifen: %s", - :cannot_store_topic => "Kann %s::%s nicht speichern: %s", - :error_creating_lock => "Fehler beim Erzeugen der Sperre von %s::%s: %s", - :error_releasing_lock => "Fehler beim Lösen der Sperre von %s::%s: %s", - :flatfiles_no_data_directory => "Das Daten-Verzeichnis (%s) existiert nicht.", - :no_access_to_create_project => "Keine Berechtigung um das Projekt (%s) zu erstellen.", - :no_access_to_destroy_project => "Keine Berechtigung um das Projekt (%s) zu zerstören.", - :no_access_to_destroy_topic => "Kann %s::%s nicht zerstören: %s.", - :no_access_to_read_topic => "Kann auf %s::%s nicht zugreifen: %s.", - :no_access_to_store_topic => "Kann %s::%s nicht speichern: %s.", - :project_already_exists => "Das Projekt %s existiert bereits.", - :project_does_not_exist => "Das Projekt %s existiert nicht.", - # Config-related messages. - :config_not_ruwiki_config => "Die Konfiguration muss von Typ der Klasse Ruwiki::Config sein.", - :invalid_template_dir => "Der angegebene Pfad für Schablonen (%s) existiert nicht oder ist kein Verzeichnis.", - :no_template_found => "Keine Schablone %s im Schablonen-Set '%s' gefunden.", - :no_template_set => "Es gibt kein Schablonen-Set '%s' im Schablonen-Pfad.", - :no_webmaster_defined => "Konfigurations-Fehler: Webmaster nicht definiert.", - # Miscellaneous messages. - :complete_utter_failure => "Fataler Fehler", - :editing => "Editieren", - :error => "Fehler", - :invalid_path_info_value => "Fataler Fehler in der Web-Umgebung. PATH_INFO = %s", - # Should this really get translated? --chris - :render_arguments => "Ruwiki#render muss mit zwei oder mehr Argumenten aufgerufen werden.", - :unknown_feature => "Unbekanntes Feature %s." - } - Message.default = proc { |h, k| "Sprachdatei-FEHLER: Unbekannter Nachrichten-Typ #{k.inspect}." } - end - end -end diff --git a/ruwiki/tags/release-0.7/lib/ruwiki/lang/en.rb b/ruwiki/tags/release-0.7/lib/ruwiki/lang/en.rb deleted file mode 100644 index 6a15a3a..0000000 --- a/ruwiki/tags/release-0.7/lib/ruwiki/lang/en.rb +++ /dev/null @@ -1,58 +0,0 @@ -#-- -# Ruwiki -# Copyright © 2002 - 2004, Digikata and HaloStatue -# Alan Chen (alan@digikata.com) -# Austin Ziegler (austin@halostatue.ca) -# -# Licensed under the same terms as Ruby. -# -# $Id$ -#++ -class Ruwiki - module Lang - # Ruwiki::Lang::EN is the English-language output module. It contains a - # hash, *Message*, that contains the messages that may be reported by - # any method in the Ruwiki library. The messages are identified by a - # Symbol. - module EN - Message = { - # The encoding for the webpages. This should match the encoding used - # to create these messages. - :encoding => "iso-8859-1", - # Backend-related messages. - :backend_unknown => "Backend %s is unknown.", - :cannot_create_project => "Cannot create project %s: %s", - :cannot_destroy_project => "Cannot destroy project %s: %s", - :cannot_destroy_topic => "Cannot destroy %s::%s: %s", - :cannot_obtain_lock => "Unable to obtain a lock on %s::%s. Try again shortly.", - :cannot_release_lock => "Unable to release the lock on %s::%s. Try again shortly.", - :cannot_retrieve_topic => "Cannot retrieve %s::%s: %s", - :cannot_store_topic => "Cannot store project %s::%s: %s", - :error_creating_lock => "Error creating lock on %s::%s: %s", - :error_releasing_lock => "Error releasing lock on %s::%s: %s", - :flatfiles_no_data_directory => "The data directory (%s) does not exist.", - :no_access_to_create_project => "No permission to create project %s.", - :no_access_to_destroy_project => "No permission to destroy project %s::%s.", - :no_access_to_destroy_topic => "No permission to destroy topic %s::%s.", - :no_access_to_read_topic => "No permission to retrieve the %s::%s.", - :no_access_to_store_topic => "No permission to store the %s::%s.", - :project_already_exists => "Project %s already exists.", - :project_does_not_exist => "Project %s does not exist.", - # Config-related messages. - :config_not_ruwiki_config => "Configuration must be of class Ruwiki::Config.", - :invalid_template_dir => "The specified path for templates (%s) does not exist or is not a directory.", - :no_template_found => "No template of %s found in template set %s.", - :no_template_set => "There is no template set '%s' in the template path.", - :no_webmaster_defined => "Configuration error: Webmaster is unset.", - # Miscellaneous messages. - :complete_utter_failure => "Complete and Utter Failure", - :editing => "Editing", - :error => "Error", - :invalid_path_info_value => "Something has gone seriously wrong with the web environment. PATH_INFO = %s", - :render_arguments => "Ruwiki#render must be called with zero or two arguments.", - :unknown_feature => "Unknown feature %s." - } - Message.default = proc { |h, k| "Language ERROR: Unknown message key #{k.inspect}." } - end - end -end diff --git a/ruwiki/tags/release-0.7/lib/ruwiki/lang/es.rb b/ruwiki/tags/release-0.7/lib/ruwiki/lang/es.rb deleted file mode 100644 index 345392a..0000000 --- a/ruwiki/tags/release-0.7/lib/ruwiki/lang/es.rb +++ /dev/null @@ -1,59 +0,0 @@ -#-- -# Ruwiki -# Copyright © 2002 - 2004, Digikata and HaloStatue -# Alan Chen (alan@digikata.com) -# Austin Ziegler (austin@halostatue.ca) -# Mauricio Julio Fernández Pradier (batsman.geo@yahoo.com) -# -# Licensed under the same terms as Ruby. -# -# $Id$ -#++ -class Ruwiki - module Lang - # Ruwiki::Lang::ES is the English-language output module. It contains a - # hash, *Message*, that contains the messages that may be reported by - # any method in the Ruwiki library. The messages are identified by a - # Symbol. - module ES - Message = { - # The encoding for the webpages. This should match the encoding used - # to create these messages. - :encoding => "iso-8859-1", - # Backend-related messages. - :backend_unknown => "Clase Backend desconocida: %s.", - :cannot_create_project => "No puede crearse el proyecto %s: %s", - :cannot_destroy_project => "No puede borrarse el proyecto %s: %s", - :cannot_destroy_topic => "No puede borrarse %s::%s: %s", - :cannot_obtain_lock => "Imposible obtener acceso exclusivo sobre %s::%s. Reinténtelo en breve.", - :cannot_release_lock => "Imposible liberar acceso exclusivo sobre %s::%s. Reinténtelo en breve.", - :cannot_retrieve_topic => "No puede leerse %s::%s: %s", - :cannot_store_topic => "No puede archivarse %s::%s: %s", - :error_creating_lock => "Error al crear el cerrojo sobre %s::%s: %s", - :error_releasing_lock => "Error al liberar el cerrojo sobre %s::%s: %s", - :flatfiles_no_data_directory => "El directorio de datos (%s) no existe.", - :no_access_to_create_project => "Permiso denegado al crear el proyecto %s.", - :no_access_to_destroy_project => "Permiso denegado al borrar el proyecto %s::%s.", - :no_access_to_destroy_topic => "Permiso denegado al borrar el nodo %s::%s.", - :no_access_to_read_topic => "Permiso denegado al leer el nodo %s::%s.", - :no_access_to_store_topic => "Permiso denegado al salvar el nodo %s::%s.", - :project_already_exists => "El proyecto %s ya existe.", - :project_does_not_exist => "El proyecto %s no existe.", - # Config-related messages. - :config_not_ruwiki_config => "La configuración debe ser de clase Ruwiki::Config.", - :invalid_template_dir => "El path especificado para plantillas (%s) no existe o no es un directorio.", - :no_template_found => "No se encontró ninguna plantilla para %s en el conjunto %s.", - :no_template_set => "No hay ningún juego de plantillas '%s' en el path.", - :no_webmaster_defined => "Error de configuración: Webmaster no está definido.", - # Miscellaneous messages. - :complete_utter_failure => "Fallo total y absoluto.", - :editing => "Editando", - :error => "Error", - :invalid_path_info_value => "Algo huele a podrido en su entorno Web. PATH_INFO = %s", - :render_arguments => "Ruwiki#render debe ser llamado con cero o dos argumentos.", - :unknown_feature => "Clase Feature desconocida: %s." - } - Message.default = proc { |h, k| "ERROR De la Lengua: Llave desconocida del mensaje #{k.inspect}." } - end - end -end diff --git a/ruwiki/tags/release-0.7/lib/ruwiki/page.rb b/ruwiki/tags/release-0.7/lib/ruwiki/page.rb deleted file mode 100644 index 72f9d95..0000000 --- a/ruwiki/tags/release-0.7/lib/ruwiki/page.rb +++ /dev/null @@ -1,131 +0,0 @@ -#-- -# Ruwiki -# Copyright © 2002 - 2004, Digikata and HaloStatue -# Alan Chen (alan@digikata.com) -# Austin Ziegler (ruwiki@halostatue.ca) -# -# Licensed under the same terms as Ruby. -# -# $Id$ -#++ -class Ruwiki - # A generic page for Ruwiki. - class Page - # The page ID. - attr_accessor :page_id - # The current version of the page. - attr_accessor :version - # The previous version of the page. - attr_accessor :old_version - # The page topic (the name of the page). - attr_accessor :topic - # The project of the page. - attr_accessor :project - # Unformatted page text. - attr_reader :content - # Formatted page text. - attr_accessor :formatted - - # The IP address of the person who made the last change. - def change_ip - %Q(#{@remote_host} #{@remote_addr}) - end - - # The ID, if present, of the person who made the last change. Not yet - # implemented. - def change_id - nil - end - - # Creates a Ruwiki page. - def initialize(init = {}) - @markup = init[:markup] - @script = init[:script] - - @remote_host = init[:remote_host] - @remote_addr = init[:remote_addr] - - @project = init[:project] || "Default" - @topic = init[:topic] || "NewTopic" - @content = init[:content] || "" - @page_id = init[:page_id] || 0 - @version = init[:version] || 0 - @old_version = @version - 1 - - if init.has_key?(:rawtext) - @rawtext = init[:rawtext].dup - @content = parse_header(@rawtext.dup) - @formatted = parse_content(@content, @project) - elsif not @content.empty? - @formatted = parse_content(@content.dup, @project) - else - @formatted = "" - end - @content.gsub!(/\r/, "") - end - - # The content of the page. - def content=(content) - @content = content.gsub(/\r/, "") - @formatted = parse_content(content, @project) - end - - # Output raw header and raw page context for saving. - def rawtext - return <<-EOS -id: #{@page_id} -topic: #{@topic} -version: #{@version} -#EHDR -#{@content} - EOS - end - - # Outputs the HTML version of the page. - def to_html - @formatted - end - - private - HEADER_RE = /^([a-z]+)\s*:\s*(.*)$/ - HEADER_END_RE = /^#EHDR$/ - - # Parse the header. - def parse_header(rawtext) - rawbuf = rawtext.split("\n") - - loop do - break if rawbuf.nil? or rawbuf.empty? - - if rawbuf[0] =~ HEADER_END_RE - rawbuf.shift - break - end - - match = HEADER_RE.match(rawbuf[0]) - - if match - case match[1].intern - when :id - @page_id = match[2].to_i - when :topic - @topic = match[2] - when :version - @version = match[2].to_i - @old_version = @version - 1 - end - rawbuf.shift - end - end - - rawbuf.join("\n") - end - - # Parse the content. - def parse_content(content, project) - parsed = @markup.parse(content, project) - - parsed - end - end -end diff --git a/ruwiki/tags/release-0.7/lib/ruwiki/servlet.rb b/ruwiki/tags/release-0.7/lib/ruwiki/servlet.rb deleted file mode 100644 index d687539..0000000 --- a/ruwiki/tags/release-0.7/lib/ruwiki/servlet.rb +++ /dev/null @@ -1,34 +0,0 @@ -#-- -# Ruwiki -# Copyright © 2002 - 2004, Digikata and HaloStatue -# Alan Chen (alan@digikata.com) -# Austin Ziegler (ruwiki@halostatue.ca) -# -# Licensed under the same terms as Ruby. -# -# $Id$ -#++ -require 'webrick' - -class Ruwiki - class Servlet < WEBrick::HTTPServlet::AbstractServlet - def initialize(config) - @config = config - end - - # Converts a POST into a GET. - def do_POST(req, res) - do_GET(req, res) - end - - def do_GET(req, res) - # Generate the reponse handlers for Ruwiki from the request and response - # objects provided. - wiki = Ruwiki.new(Ruwiki::Handler.from_webrick(req, res)) - - # Configuration defaults to certain values. This overrides the defaults. - wiki.config = $config unless $config.nil? - wiki.run - end - end -end diff --git a/ruwiki/tags/release-0.7/lib/ruwiki/template.rb b/ruwiki/tags/release-0.7/lib/ruwiki/template.rb deleted file mode 100644 index 9655f21..0000000 --- a/ruwiki/tags/release-0.7/lib/ruwiki/template.rb +++ /dev/null @@ -1,223 +0,0 @@ -#-- -# Ruwiki -# Copyright © 2002 - 2004, Digikata and HaloStatue -# Alan Chen (alan@digikata.com) -# Austin Ziegler (ruwiki@halostatue.ca) -# -# Licensed under the same terms as Ruby. -# -# This file is originally from rdoc by Dave Thomas (dave@pragprog.com). -# -# $Id$ -#++ -class Ruwiki - # RDoc's cheap-n-cheerful HTML page template system. You create a template - # containing: - # - # * variable names between percent signs (<tt>%fred%</tt>) - # * blocks of repeating stuff: - # START:key - # ... stuff - # END:key - # - # You feed the code a hash. For simple variables, the values are resolved - # directly from the hash. For blocks, the hash entry corresponding to +key+ - # will be an array of hashes. The block will be generated once for each - # entry. Blocks can be nested arbitrarily deeply. - # - # The template may also contain: - # IF:key - # ... stuff - # ENDIF:key - # - # _stuff_ will only be included in the output if the corresponding key is - # set in the value hash. - # - # Usage: Given a set of templates <tt>T1, T2,</tt> etc - # values = { "name" => "Dave", state => "TX" } - # t = TemplatePage.new(T1, T2, T3) - # File.open(name, "w") {|f| t.write_html_on(f, values)} - # or - # res = '' - # t.write_html_on(res, values) - # - class TemplatePage - - # A context holds a stack of key/value pairs (like a symbol table). When - # asked to resolve a key, it first searches the top of the stack, then - # the next level, and so on until it finds a match (or runs out of - # entries). - class Context - def initialize - @stack = [] - end - - def push(hash) - @stack.push(hash) - end - - def pop - @stack.pop - end - - # Find a scalar value, throwing an exception if not found. This method - # is used when substituting the %xxx% constructs - def find_scalar(key) - @stack.reverse_each do |level| - if val = level[key] - return val unless val.kind_of? Array - end - end - raise "Template error: can't find variable '#{key}'" - end - - # Lookup any key in the stack of hashes - def lookup(key) - @stack.reverse_each do |level| - val = level[key] - return val if val - end - nil - end - end - - # Simple class to read lines out of a string - class LineReader - # we're initialized with an array of lines - def initialize(lines) - @lines = lines - end - - # read the next line - def read - @lines.shift - end - - # Return a list of lines up to the line that matches a pattern. That - # last line is discarded. - def read_up_to(pattern) - res = [] - while line = read - if pattern.match(line) - return LineReader.new(res) - else - res << line - end - end - raise "Missing end tag in template: #{pattern.source}" - end - - # Return a copy of ourselves that can be modified without affecting us - def dup - LineReader.new(@lines.dup) - end - end - - # +templates+ is an array of strings containing the templates. We start at - # the first, and substitute in subsequent ones where the string - # <tt>!INCLUDE!</tt> occurs. For example, we could have the overall page - # template containing - # - # <html><body> - # <h1>Master</h1> - # !INCLUDE! - # </bost></html> - # - # and substitute subpages in to it by passing [master, sub_page]. This - # gives us a cheap way of framing pages - def initialize(*templates) - result = "!INCLUDE!" - templates.each do |content| - result.sub!(/!INCLUDE!/, content) - end - @lines = LineReader.new(result.split($/)) - end - - # Render the templates into HTML, storing the result on +op+ using the - # method <tt><<</tt>. The <tt>value_hash</tt> contains key/value pairs - # used to drive the substitution (as described above) - def write_html_on(op, value_hash) - @context = Context.new - op << substitute_into(@lines, value_hash).tr("\000", '\\') - end - - # Substitute a set of key/value pairs into the given template. Keys with - # scalar values have them substituted directly into the page. Those with - # array values invoke <tt>substitute_array</tt> (below), which examples a - # block of the template once for each row in the array. - # - # This routine also copes with the <tt>IF:</tt>_key_ directive, removing - # chunks of the template if the corresponding key does not appear in the - # hash, and the START: directive, which loops its contents for each value - # in an array - def substitute_into(lines, values) - @context.push(values) - skip_to = nil - result = [] - - while line = lines.read - - case line - - when /^IF:(\w+)/ - lines.read_up_to(/^ENDIF:#$1/) unless @context.lookup($1) - - when /^IFNOT:(\w+)/ - lines.read_up_to(/^ENDIF:#$1/) if @context.lookup($1) - - when /^ENDIF:/ - ; - - when /^START:(\w+)/ - tag = $1 - body = lines.read_up_to(/^END:#{tag}/) - inner_values = @context.lookup(tag) - raise "unknown tag: #{tag}" unless inner_values - raise "not array: #{tag}" unless inner_values.kind_of?(Array) - inner_values.each do |vals| - result << substitute_into(body.dup, vals) - end - else - result << expand_line(line.dup) - end - end - - @context.pop - - result.join("\n") - end - - # Given an individual line, we look for %xxx% constructs and - # HREF:ref:name: constructs, substituting for each. - def expand_line(line) - # Generate a cross reference if a reference is given, - # otherwise just fill in the name part - - line.gsub!(/HREF:(\w+?):(\w+?):/) do - ref = @context.lookup($1) - name = @context.find_scalar($2) - - if ref and !ref.kind_of?(Array) - "<a href=\"#{ref}\">#{name}</a>" - else - name - end - end - - # Substitute in values for %xxx% constructs. This is made complex - # because the replacement string may contain characters that are - # meaningful to the regexp (like \1) - - line = line.gsub(/%([a-zA-Z]\w*)%/) do - val = @context.find_scalar($1) - val.tr('\\', "\000") - end - - line - rescue Exception => e - $stderr.puts "Error in template: #{e}" - $stderr.puts "Original line: #{line}" - exit - end - end -end diff --git a/ruwiki/tags/release-0.7/lib/ruwiki/wiki.rb b/ruwiki/tags/release-0.7/lib/ruwiki/wiki.rb deleted file mode 100644 index d315357..0000000 --- a/ruwiki/tags/release-0.7/lib/ruwiki/wiki.rb +++ /dev/null @@ -1,90 +0,0 @@ -#-- -# Ruwiki -# Copyright © 2002 - 2004, Digikata and HaloStatue -# Alan Chen (alan@digikata.com) -# Austin Ziegler (ruwiki@halostatue.ca) -# -# Licensed under the same terms as Ruby. -# -# $Id$ -#++ -class Ruwiki - # Ruwiki's Wiki markup class. This will convert the Wiki markup known by - # Ruwiki (defined by Token classes). The algorithm is as follows: - # - # 1. For each known Token class, match each instance of it in the content - # stream. Replace each instance in the content stream with a Token - # marker: TOKEN_x or \TOKEN_x, where x is a digit representing the - # Token. (\TOKEN_x is a special case of token matching. See - # Ruwiki::Markup::Token for more information.) Store the Token for - # later processing. - # 2. Go back through the content, replacing each instance of \TOKEN_x - # with the Token's defined restore value (which should be the same - # value as was originally matched). - # 3. Go through the content, replacing each instance of TOKEN_x with the - # Token's defined replacement value. - # 4. Go through the tokens, in reverse, and execute the post replacement - # routine defined by the Token. (This may be necessary to collapse - # consecutive HTML structures.) - # 5. Return the parsed content and the collected metadata. - # - # == Tokens - # Look at Ruwiki::Markup::Token describes how to create Token objects. - class Wiki - def parse(content, project) - content = content.dup - tokens = [] - project ||= @default_project - - Token.tokenlist.each do |token| - content.gsub!(token.regexp) do |m| - match = Regexp.last_match - tc = token.new(match, project, @backend, @script) - tokens << tc - if m[0, 1] == '\\' - "\\TOKEN_#{tokens.size - 1}" - else - "TOKEN_#{tokens.size - 1}" - end - end - end - - replaced = [] - s = true - loop do - break if replaced.size >= tokens.size - break if s.nil? - s = content.gsub!(/\\TOKEN_(\d+)/) { |m| - match = Regexp.last_match - itoken = match[1].to_i - replaced << itoken - tokens[itoken].restore - } - - s = content.gsub!(/TOKEN_(\d+)/) { |m| - match = Regexp.last_match - itoken = match[1].to_i - replaced << itoken - tokens[itoken].replace - } - end - - token_classes = tokens.map { |token| token.class }.sort_by { |token| token.rank } - token_classes.uniq.each { |tc| tc.post_replace(content) } - - content - end - - attr_accessor :default_project - attr_accessor :script - attr_accessor :backend - - # Creates the markup class. - def initialize(default_project, script) - @default_project = default_project - @script = script - end - end -end - -require 'ruwiki/wiki/tokens' diff --git a/ruwiki/tags/release-0.7/lib/ruwiki/wiki/tokens.rb b/ruwiki/tags/release-0.7/lib/ruwiki/wiki/tokens.rb deleted file mode 100644 index c7ff6c7..0000000 --- a/ruwiki/tags/release-0.7/lib/ruwiki/wiki/tokens.rb +++ /dev/null @@ -1,132 +0,0 @@ -#-- -# Ruwiki -# Copyright © 2002 - 2004, Digikata and HaloStatue -# Alan Chen (alan@digikata.com) -# Austin Ziegler (ruwiki@halostatue.ca) -# -# Licensed under the same terms as Ruby. -# -# $Id$ -#++ -class Ruwiki - class Wiki - # The base Token class. All Token classes must inherit from Token and - # *must* implement the following methods: - # - # [self.regexp] The regular expression that the Token will be - # replacing. - # [replace] The mechanism for replacing the Token with the desired - # results. - # - # Token classes <i>should</i> implement the following method: - # [self.rank] Default: <tt>5000</tt>. Affects the sort order. - # Must return an integer. - # - # Token classes <i>may</i> implement the following methods: - # [restore] Restores the token without replacement. - # Implements the results of the escape character. - # NOTE: each Token class is responsible for its own - # restore. Tokens that are anchored to the - # beginning of a line are the most likely to need - # to reimplement this. - # [self.post_replace] Performs any necessary massaging of the data. See - # the implementation of Ruwiki::Wiki::Lists for - # more information. - class Token - @@tokenlist = [] - @@sorted = false - - class << self - # Tokens should define rank if they must be first or last in - # processing. Otherwise, they are sorted in the order defined. - def rank - 5000 - end - - # The Wiki parsing routine uses Token.tokenlist to determine the - # tokens that are processed, and the order in which they are - # processed. See Token.rank for more information. - def tokenlist - unless @@sorted - head = @@tokenlist.shift - @@tokenlist.sort! { |a, b| a.rank <=> b.rank } - @@tokenlist.unshift(head) - sorted = true - end - @@tokenlist - end - - def inherited(child_class) #:nodoc: - @@tokenlist << Token if @@tokenlist.empty? - - # Make the child class post_replace a blank function because we - # don't want to propogate the currently defined post_replace. - # The current post_replace is specific to Token_Base only. - class << child_class - def self.post_replace(content) - content - end - end - - @@tokenlist << child_class - @@sorted = false - end - - # The replacement regular expression. - def regexp - /TOKEN_(\d*)/ - end - end - - # All Token classes must match this header signature if they define - # #initialize. - # - # [match] The MatchData object for this Token. - # [project] The project being processed. - # [backend] The backend for the wiki. This is used to determine if - # the page or project exists. The object passed must - # respond to #project_exists?(project) and - # #page_exists?(page, project). - # [script] The URI to the script. - def initialize(match, project, backend, script) - @match = match - @project = project - @backend = backend - @script = script - end - - # The replacement method. Uses @match to replace the token with the - # appropriate values. - def replace - "TOKEN_#{@match[1]}" - end - - # Restores the token without replacement. By default, replaces - # "dangerous" HTML characters. - def restore - @match[0].gsub(/&/, "&").gsub(/</, "<").gsub(/>/, ">") - end - - # The content may need massaging after processing. - def self.post_replace(content) - content - end - end - end -end - - # Load the tokens from the ruwiki/wiki/tokens directory. -tokens_dir = 'ruwiki/wiki/tokens' - -$LOAD_PATH.each do |path| - target = "#{path}/#{tokens_dir}" - if File.exists?(target) and File.directory?(target) - Dir::glob("#{target}/*.rb") do |token| - begin - require token - rescue LoadError - nil - end - end - end -end diff --git a/ruwiki/tags/release-0.7/lib/ruwiki/wiki/tokens/00default.rb b/ruwiki/tags/release-0.7/lib/ruwiki/wiki/tokens/00default.rb deleted file mode 100644 index 448ff3f..0000000 --- a/ruwiki/tags/release-0.7/lib/ruwiki/wiki/tokens/00default.rb +++ /dev/null @@ -1,188 +0,0 @@ -#-- -# Ruwiki -# Copyright © 2002 - 2004, Digikata and HaloStatue -# Alan Chen (alan@digikata.com) -# Austin Ziegler (ruwiki@halostatue.ca) -# -# Licensed under the same terms as Ruby. -# -# $Id$ -#++ - -# $debug = File.open("output.txt", "w") - -class Ruwiki - class Wiki - # The Paragraph Token class changes blank lines to <p> tags. This class, - # under the current implementation, should be *first* in the Token list - # after Token. - class Paragraph < Ruwiki::Wiki::Token - # This Token is #rank 0, because it should be first in the Token list. - def self.rank - 0 - end - - # Matches blank lines. %r{^\s*$} - def self.regexp - %r{(^\s*$)} - end - - # Replaces with "<p>" - def replace - "</p><p>" - end - - # Ensures that <p> won't be surrounded by <br> tags. - def self.post_replace(content) - content.gsub!(%r{\A}, '<p>') - content.gsub!(%r{\z}, '</p>') - content.gsub!(%r{^}, '<p>') - content.gsub!(%r{\n}, "</p>\n") - content.gsub!(%r{<p>(<p>)+}, '<p>') - content.gsub!(%r{</p>(</p>)+}, '</p>') - content.gsub!(%r{((?:<p>(?:.*?)</p>\n)+?<p></p><p></p>)}) do |m| - r = m.gsub(%r{</p>\n<p>}, "\n<p>") - r.gsub!(%r{<p></p><p></p>}, "</p>") - r.gsub!(%r{\n<p>}, "\n") - r.gsub!(%r{\n</p>}, '</p>') - r - end - content.gsub!(%r{<p></p>}, '') - content - end - end - - # The Code Token class converts indented text to "unformatted" (<pre>) - # text. This class should be *second* in the Token list. - class Code < Ruwiki::Wiki::Token - # This Token is #rank 1, because it should be second in the Token list. - def self.rank - 1 - end - - # Matches indented text. %r{^(\s+\S.*)$} - def self.regexp - %r{^(\s+\S.*)$} - end - - # Replaces the text to <pre>content</pre>. - def replace - content = @match.captures[0] - content.gsub!(/&/, '&') - content.gsub!(/</, '<') - content.gsub!(/>/, '>') - - %Q{</p><pre>#{content}</pre>} - end - - # Converts cases of %r{</pre>(\n|<br ?/?>)<pre>} to \1. - def self.post_replace(content) - content.gsub!(%r{</pre>((\n)*</p>(\n)*)?<pre>}, "\n") - content.gsub!(%r{</pre>(\n|<br ?/?>)?<pre>}, '\1') - content.gsub!(%r{<p><pre>}, '<pre>') - content.gsub!(%r{</pre></p>}, '</pre>') - content - end - end - - RE_URI_SCHEME = %r{[\w.]+?:} - RE_URI_PATH = %r{[^\s<>\]]} - RE_URI_TEXT = %r{[^\]]*} - RE_IMAGE = /(jpg|jpeg|png|gif)$/ - - # Converts URLs in the form of [url] to numbered links. - class NumberedLinks < Ruwiki::Wiki::Token - class << self - attr_accessor :count - end - - def self.rank - 2 - end - - def self.regexp - %r{\[(#{RE_URI_SCHEME}(?:#{RE_URI_PATH})*?)\]} - end - - def replace - extlink = @match.captures[0] - - NumberedLinks.count ||= 0 - NumberedLinks.count += 1 - name = "[#{NumberedLinks.count}]" - - if extlink =~ RE_IMAGE - %Q{<img src="#{extlink}" title="#{name}" alt="#{name}" />} - else - %Q{<a class="rw_extlink" href="#{extlink}">#{name}</a>} - end - end - end - - # Converts URLs in the form of [url name] to named links. - class NamedLinks < Ruwiki::Wiki::Token - def self.rank - 3 - end - - def self.regexp - %r{\[(#{RE_URI_SCHEME}(?:#{RE_URI_PATH})*?)\s+(#{RE_URI_TEXT})\]} - end - - def replace - extlink = @match.captures[0] - name = @match.captures[1] - - if extlink =~ RE_IMAGE - %Q{<img src="#{extlink}" title="#{name}" alt="#{name}" />} - else - %Q{<a class="rw_extlink" href="#{extlink}">#{name}</a>} - end - end - end - - # Converts URLs to links where the "name" of the link is the URL itself. - class ExternalLinks < Ruwiki::Wiki::Token - def self.rank - 501 - end - - def self.regexp - %r{\b(#{RE_URI_SCHEME}#{RE_URI_PATH}+)} - end - - def replace - extlink = @match.captures[0] - - if extlink =~ RE_IMAGE - %Q{<img src="#{extlink}" title="Image at: #{extlink}" alt="Image at: #{extlink}" />} - else - %Q{<a class="rw_extlink" href="#{extlink}">#{extlink}</a>} - end - end - end - - # Creates a horizontal rule. - class HRule < Ruwiki::Wiki::Token - def self.regexp - %r|^\\?-{4,}| - end - - def replace - "<hr />" - end - - def restore - @match[0][1 .. -1] - end - - def self.post_replace(content) - content.gsub!(%r{(<p>)*<hr ?/?>(</p>)*}, "<hr />") - content.gsub!(%r{\n<hr />}, "</p>\n<hr />") - content.gsub!(%r{<hr ?/?>\n<br ?/?>}, "<hr />") - content.gsub!(%r{(\n|<br ?/?>)?<hr>(\n|<br ?/?>)?}, "<hr />") - content - end - end - end -end diff --git a/ruwiki/tags/release-0.7/lib/ruwiki/wiki/tokens/01wikilinks.rb b/ruwiki/tags/release-0.7/lib/ruwiki/wiki/tokens/01wikilinks.rb deleted file mode 100644 index 586bff8..0000000 --- a/ruwiki/tags/release-0.7/lib/ruwiki/wiki/tokens/01wikilinks.rb +++ /dev/null @@ -1,168 +0,0 @@ -#-- -# Ruwiki -# Copyright © 2002 - 2004, Digikata and HaloStatue -# Alan Chen (alan@digikata.com) -# Austin Ziegler (ruwiki@halostatue.ca) -# -# Licensed under the same terms as Ruby. -# -# $Id$ -#++ -require 'cgi' - -class Ruwiki - class Wiki - # This provides the basic WikiWord match. This supports WikiWord, - # CPlusPlus, ThisIsALink, and C_Plus_Plus. - RE_WIKI_WORDS = %r{[[:upper:]][\w_]*(?:[[:lower:]]+[[:upper:]_]|[[:upper:]_]+[[:lower:]])[\w_]*} - # This provides wikipedia format matches, e.g., [[wikipedia links]]. The - # only restriction on words in this format is that they must NOT begin - # with an underscore ('_'). - RE_WIKIPEDIA_WORDS = %r{\[\[([^_].*?)\]\]} - # This provides the basic Wiki Project match. - RE_PROJECT_WORD = %r{[[:upper:]][[:lower:]]+} - - # This provides the Wiki view link format: - VIEW_LINK = %Q[<a class="rw_pagelink" href="%s">%s</a>] - EDIT_LINK = %Q[<span class="rw_edittext">%s</span><a class="rw_pagelink" href="%s">?</a>] - - # Creates a crosslink for a Project::WikiPage. - class ProjectCrossLink < Ruwiki::Wiki::Token - def self.rank - 500 - end - - def self.regexp - %r{(#{RE_PROJECT_WORD})::(#{RE_WIKI_WORDS})} - end - - def replace - project = @match.captures[0] - topic = @match.captures[1] - link = CGI.escape(topic.dup) - - if @backend.page_exists?(topic, project) - VIEW_LINK % ["#{@script}/#{project}/#{link}", "#{project}::#{topic.gsub(/_/, ' ')}"] - else - EDIT_LINK % ["#{project}::#{topic.gsub(/_/, ' ')}", "#{@script}/#{project}/#{link}/_edit"] - end - end - end - - # Creates a crosslink for a Project::WikiPage using a Wikipedia link - # format. - class ProjectCrossLinkWikipedia < Ruwiki::Wiki::Token - def self.rank - 500 - end - - def self.regexp - %r{(#{RE_PROJECT_WORD})::#{RE_WIKIPEDIA_WORDS}} - end - - def replace - project = @match.captures[0] - topic = @match.captures[1] - link = CGI.escape(topic) - - if @backend.page_exists?(topic, project) - VIEW_LINK % ["#{@script}/#{project}/#{link}", "#{project}::#{topic}"] - else - EDIT_LINK % ["#{project}::#{topic}", "#{@script}/#{project}/#{link}/_edit"] - end - end - end - - # Creates a link to the project index from ::Project. - class ProjectIndex < Ruwiki::Wiki::Token - def self.rank - 501 - end - - def self.regexp - %r{(\B|\\)::(#{RE_PROJECT_WORD})} - end - - def restore - @match[0][1..-1] - end - - def replace - project = @match.captures[1] - - if @backend.page_exists?('ProjectIndex', project) - VIEW_LINK % ["#{@script}/#{project}/ProjectIndex", project] - else - if @backend.project_exists?(project) - EDIT_LINK % [project, "#{@script}/#{project}/ProjectIndex/_edit"] - else - EDIT_LINK % [project, "#{@script}/#{project}/_create"] - end - end - end - end - - # Creates a link to a WikiPage in the current project. - class WikiLinks < Ruwiki::Wiki::Token - def self.rank - 503 - end - - def self.regexp - %r{(\b|\\)(#{RE_WIKI_WORDS})\b} - end - - def restore - @match[0][1..-1] - end - - def replace - topic = @match.captures[1] - link = CGI.escape(topic.dup) - - if @backend.page_exists?(topic, @project) - VIEW_LINK % ["#{@script}/#{@project}/#{link}", topic.gsub(/_/, ' ')] - else - EDIT_LINK % [topic.gsub(/_/, ' '), "#{@script}/#{@project}/#{link}/_edit"] - end - end - end - - # Creates a link to a WikiPage in the current project using a Wikipedia - # link format. - class WikipediaLinks < Ruwiki::Wiki::Token - def self.rank - 502 - end - - def self.regexp - %r{(\B|\\)#{RE_WIKIPEDIA_WORDS}\B} - end - - def restore - @match[0][1..-1] - end - - ALT_TEXT = %r{(.+)\|(.+)}o - - def replace - captures = @match.captures - topic = @match.captures[1] - link = CGI.escape(topic) - - at = ALT_TEXT.match(topic) - - if not at.nil? - topic = at.captures[1] - link = CGI.escape(at.captures[0]) - end - - if @backend.page_exists?(link, @project) - VIEW_LINK % ["#{@script}/#{@project}/#{link}", topic] - else - EDIT_LINK % [topic, "#{@script}/#{@project}/#{link}/_edit"] - end - end - end - end -end diff --git a/ruwiki/tags/release-0.7/lib/ruwiki/wiki/tokens/abbreviations.rb b/ruwiki/tags/release-0.7/lib/ruwiki/wiki/tokens/abbreviations.rb deleted file mode 100644 index 3329fab..0000000 --- a/ruwiki/tags/release-0.7/lib/ruwiki/wiki/tokens/abbreviations.rb +++ /dev/null @@ -1,42 +0,0 @@ -#-- -# Ruwiki -# Copyright © 2002 - 2004, Digikata and HaloStatue -# Alan Chen (alan@digikata.com) -# Austin Ziegler (ruwiki@halostatue.ca) -# -# Licensed under the same terms as Ruby. -# -# $Id$ -#++ -class Ruwiki - class Wiki - # Converts abbreviations. - class Abbreviations < Ruwiki::Wiki::Token - ABBREVIATIONS = { - "PM" => "PocoMail" - } - - def self.regexp - %r!@\{([^\}]*)\}! - end - - def replace - k = @match.captures[0] - if k.nil? or k.empty? - data = "<dl>" - ABBREVIATIONS.each do |k, v| - data << "<dt>#{k}</dt><dd>#{v}</dd>" - end - data << "</dl>" - else - if ABBREVIATIONS.has_key?(k) - data = ABBREVIATIONS[k] - else - data = @match[0] - end - end - data - end - end - end -end diff --git a/ruwiki/tags/release-0.7/lib/ruwiki/wiki/tokens/calendar.rb b/ruwiki/tags/release-0.7/lib/ruwiki/wiki/tokens/calendar.rb deleted file mode 100644 index 4c38d59..0000000 --- a/ruwiki/tags/release-0.7/lib/ruwiki/wiki/tokens/calendar.rb +++ /dev/null @@ -1,147 +0,0 @@ -#-- -# Ruwiki -# Copyright © 2002 - 2004, Digikata and HaloStatue -# Alan Chen (alan@digikata.com) -# Austin Ziegler (ruwiki@halostatue.ca) -# -# Licensed under the same terms as Ruby. -# -# $Id$ -#++ -class Ruwiki - class Wiki - # Produces Lists - class Calendar < Ruwiki::Wiki::Token - def self.regexp - %r{^\\?%calendar\s*\((?:(today)|(\d+),\s*(\d+))(?:,\s*(#{RE_PROJECT_WORD}))?\)} - end - - def self.make(year, month) - result = [] - t = Time.local(year, month, 1) - r = Array.new(t.wday, nil) - r << 1 - - 2.upto(31) do |i| - break if Time.local(year, month, i).month != month - r << i - end - - r += Array.new((- r.size) % 7, nil) - - 0.step(r.size - 1, 7) do |i| - result << r[i, 7] - end - result - end - - def make_month_link(project, year, month, state = nil) - ym = "%04d%02d" % [year, month] - case state - when :prev - title = "« #{year}.#{month}" - when :next - title = "#{year}.#{month} »" - else - title = "#{project}::#{year}.#{month}" - end - url = "#{@script}/#{project}/#{ym}" - - if @backend.page_exists?(ym, project) - VIEW_LINK % [url, title] - else - EDIT_LINK % [title, "#{url}/_edit"] - end - end - - def replace - today = @match.captures[0] - project = @match.captures[3] || @project - now = Time.now - - if today.nil? - year = @match.captures[1].to_i - month = @match.captures[2].to_i - else - year = now.year - month = now.month - end - - if (year == now.year) and (month == now.month) - show_today = now.day - else - show_today = nil - end - - result = <<-"CALENDAR_HEAD" -</p> -<div class="rw_calendar"> -<table class="rw_calendar" summary="calendar for ::#{project}: #{year}.#{month}"> -<thead> - CALENDAR_HEAD - - result << %Q{ <tr>\n<th colspan="7" class="rw_calendar-current-month">} - result << make_month_link(project, year, month) - result << %Q{</th>\n </tr>\n <tr>\n<th colspan="2" class="rw_calendar-prev-month">} - result << make_month_link(project, year, month - 1, :prev) - result << %Q{</th>\n<th colspan="3"></th>\n<th colspan="2" class="rw_calendar-next-month">} - result << make_month_link(project, year, month + 1, :next) - result << "</th>\n" - - result << <<-"CALENDAR_HEAD2" - </tr> - <tr> - <th class="rw_calendar-weekend">Su</th> - <th class="rw_calendar-weekday">Mo</th> - <th class="rw_calendar-weekday">Tu</th> - <th class="rw_calendar-weekday">We</th> - <th class="rw_calendar-weekday">Th</th> - <th class="rw_calendar-weekday">Fr</th> - <th class="rw_calendar-weekend">Sa</th> - </tr> -</thead> -<tbody> - CALENDAR_HEAD2 - - Calendar.make(year, month).each do |week| - result << " <tr>\n" - week.each do |day| - if day.nil? - result << %Q{ <td class="rw_calendar-day"></td>\n} - else - date = "%04d%02d%02d" % [year, month, day] - # Add the ability to create pages based on date here. - if show_today == day - result << %Q{ <td class="rw_calendar-today">} - else - result << %Q{ <td class="rw_calendar-day">} - end - if @backend.page_exists?(date, project) - result << VIEW_LINK % ["#{@script}/#{project}/#{date}", day] - else - result << EDIT_LINK % [day, "#{@script}/#{project}/#{date}/_edit"] - end - result << %Q{</td>\n} - end - end - result << " </tr>\n" - end - - result << "</tbody>\n</table>\n</div>\n<p>" - result - end - - def restore - @match[0][1 .. -1] - end - - def self.post_replace(content) - content.gsub!(%r{<p>(\s*</?div(?: [^>]+)?>\s*)</p>}, '\1') - content.gsub!(%r{<p>(\s*</?table(?: [^>]+)?>\s*)</p>}, '\1') - content.gsub!(%r{<p>(\s*</?t(?:head|body|r)(?: [^>]+)?>\s*)</p>}, '\1') - content.gsub!(%r{<p>(\s*<t[hd].+?</t[hd]>\s*)</p>}, '\1') - content - end - end - end -end diff --git a/ruwiki/tags/release-0.7/lib/ruwiki/wiki/tokens/headings.rb b/ruwiki/tags/release-0.7/lib/ruwiki/wiki/tokens/headings.rb deleted file mode 100644 index 069f3df..0000000 --- a/ruwiki/tags/release-0.7/lib/ruwiki/wiki/tokens/headings.rb +++ /dev/null @@ -1,43 +0,0 @@ -#-- -# Ruwiki -# Copyright © 2002 - 2004, Digikata and HaloStatue -# Alan Chen (alan@digikata.com) -# Austin Ziegler (ruwiki@halostatue.ca) -# -# Licensed under the same terms as Ruby. -# -# $Id$ -#++ -class Ruwiki - class Wiki - # Converts headings. - class Headings < Ruwiki::Wiki::Token -# def self.rank -# 5 -# end - - def self.regexp - %r{^\\?(=+)\s+(.*)} - end - - def restore - @match[0][1 .. -1] - end - - def replace - level = @match.captures[0].count("=") - content = @match.captures[1] - level = 6 if level > 6 - "<h#{level}>#{content}</h#{level}>" - end - - def self.post_replace(content) - content.gsub!(%r{(</h\d>)\n}) { |m| "#{$1}\n<p>" } - content.gsub!(%r{(</h\d>)</p>\n<p>}) { |m| "#{$1}\n<p>" } - content.gsub!(%r{<p>(<h\d>)}, '\1') - content.gsub!(%r{(</h\d>)</p>}, '\1') - content - end - end - end -end diff --git a/ruwiki/tags/release-0.7/lib/ruwiki/wiki/tokens/lists.rb b/ruwiki/tags/release-0.7/lib/ruwiki/wiki/tokens/lists.rb deleted file mode 100644 index 9826a9b..0000000 --- a/ruwiki/tags/release-0.7/lib/ruwiki/wiki/tokens/lists.rb +++ /dev/null @@ -1,129 +0,0 @@ -#-- -# Ruwiki -# Copyright © 2002 - 2004, Digikata and HaloStatue -# Alan Chen (alan@digikata.com) -# Austin Ziegler (ruwiki@halostatue.ca) -# -# Licensed under the same terms as Ruby. -# -# $Id$ -#++ -class Ruwiki - class Wiki - # Produces Lists - class Lists < Ruwiki::Wiki::Token - def self.regexp - %r{^\\?((\*)+|(#)+)\s+(.*)} - end - - def replace - content = @match.captures[3] - - if @match.captures[2].nil? - char = '*' - elem = 'ul' - else - char = '#' - elem = 'ol' - end - - indent = @match.captures[0].count(char) - - pre = '' - post = '' - indent.times do - pre << "<#{elem}><li>" - post << "</li></#{elem}>" - end - "#{pre}#{content}#{post}" - end - - def restore - @match[0][1 .. -1] - end - - def self.post_replace(content) - content.gsub!(%r{<p><([uo]l)>}, '<\1>') - content.gsub!(%r{</([uo]l)></p>}, '</\1>') - content.gsub!(%r{</[uo]l>\n?<[uo]l>}, '') - content.gsub!(%r{</ol>(\n|(<br ?/?>))?<ol>}, '') - content.gsub!(%r{</ul>(\n|(<br ?/?>))?<ul>}, '') - content.gsub!(%r{<li><([uo]l)>}, '<\1>') - content.gsub!(%r{</li><li>}, "</li>\n<li>") - content.gsub!(%r{</([uo]l)></li>}, '</\1>') - content.gsub!(%r{([^>])\n<([uo]l)>}) { |m| "#{$1}</p>\n<#{$2}>" } - content - end - end - - # Produces block quotes. - class Blockquotes < Ruwiki::Wiki::Token - def self.regexp - %r{^\\?((:+)|(>+))(\s+.*)$} - end - - def replace - content = @match.captures[3] - - if @match.captures[2].nil? - char = ':' - cite = '' - else - char = '>' - cite = ' type="cite"' - end - indent = @match.captures[0].count(char) - - pre = '' - post = '' - indent.times do - pre << "<blockquote#{cite}>" - post << "</blockquote>" - end - "#{pre}#{content}#{post}" - end - - def restore - @match[0][1 .. -1] - end - - def self.post_replace(content) - content.gsub!(%r{</blockquote>(\n|<br ?/?>)?<blockquote[^>]*>}, '') - content.gsub!(%r{(</?blockquote[^>]*>\n?)\s*}, '\1') - content.gsub!(%r{</blockquote>(<blockquote[^>]*>)+}, '\1') - content - end - end - - # Produces definition lists. Does not completely work correctly. - class Definitions < Ruwiki::Wiki::Token - def self.regexp - %r{^\\?(;+)\s+([^:]+)\s+:\s+(.*)} - end - - def replace - definition = @match.captures[2] - term = @match.captures[1] - indent = @match.captures[0].count(';') - - pre = '' - post = '' - indent.times do - pre << "<dl>" - post << "</dl>" - end - "#{pre}<dt>#{term}</dt><dd>#{definition}</dd>#{post}" - end - - def restore - @match[0][1 .. -1] - end - - def self.post_replace(content) - content.gsub!(%r{</dl>(\n|<br ?/?>)?<dl>}, '') - content.gsub!(%r{</dl>(<dl>)+}, '\1') - content - end - end - end -end diff --git a/ruwiki/tags/release-0.7/lib/ruwiki/wiki/tokens/rubylists.rb b/ruwiki/tags/release-0.7/lib/ruwiki/wiki/tokens/rubylists.rb deleted file mode 100644 index a33f0df..0000000 --- a/ruwiki/tags/release-0.7/lib/ruwiki/wiki/tokens/rubylists.rb +++ /dev/null @@ -1,47 +0,0 @@ -#-- -# Ruwiki -# Copyright © 2002 - 2004, Digikata and HaloStatue -# Alan Chen (alan@digikata.com) -# Austin Ziegler (ruwiki@halostatue.ca) -# -# Licensed under the same terms as Ruby. -# -# $Id$ -#++ -class Ruwiki - class Wiki - # Convert ruby-talk mailing list references (e.g., [ruby-talk:12345]) - # into named links. - class RubyTalkLinks < Ruwiki::Wiki::Token - def self.rank - 2 - end - - def self.regexp - %r{\[ruby-talk:(\d+)\]} - end - - def replace - lm = @match.captures[0] - %Q(<a class="rw_extlink" href="http://www.ruby-talk.org/#{lm}">#{@match[0]}</a>) - end - end - - # Convert ruby-core/ext/dev/list/math mailing list references (e.g., - # [ruby-core:12345]) into named links. - class OtherRubyLinks < Ruwiki::Wiki::Token - def self.rank - 2 - end - - def self.regexp - %r{\[ruby-(list|doc|core|dev|ext|math):(\d+)\]} - end - - def replace - ln, lm = @match.captures[0..1] - %Q(<a class="rw_extlink" href="http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-#{ln}/#{lm}">#{@match[0]}</a>) - end - end - end -end |