Sha256: 241143ea87870ac7e84adeba12db175328145782d1c8d5de9552667b1d5cef18

Contents?: true

Size: 1.68 KB

Versions: 2

Compression:

Stored size: 1.68 KB

Contents

require 'caramelize/database_connector'
require 'caramelize/filters/wikka_to_markdown'

module Caramelize
  module InputWiki
    class WikkaWiki < Wiki
      include DatabaseConnector

      SQL_PAGES = 'SELECT id, tag, body, time, latest, user, note FROM wikka_pages ORDER BY time;'.freeze
      SQL_AUTHORS = 'SELECT name, email FROM wikka_users;'.freeze

      def initialize(options = {})
        super(options)
        @options[:markup] = :wikka
        @options[:filters] << Caramelize::Wikka2Markdown
      end

      # after calling this action, titles and @revisions are expected to be filled
      def read_pages
        pages.each do |row|
          titles << row['tag']
          page = Page.new(build_properties(row))
          revisions << page
        end
        titles.uniq!
        #revisions.sort! { |a,b| a.time <=> b.time }

        revisions
      end

      def read_authors
        results = database.query(authors_query)
        results.each do |row|
          authors[row['name']] = OpenStruct.new(name:  row['name'],
                                                email: row['email'] )
        end
      end

      private

      def pages_query
        SQL_PAGES
      end

      def authors_query
        SQL_AUTHORS
      end

      def pages
        @pages ||= database.query(pages_query)
      end

      def build_properties(row)
        author = authors[row['user']]
        {
          id: row["id"],
          title: row["tag"],
          body: row["body"],
          markup: :wikka,
          latest: row["latest"] == "Y",
          time: row["time"],
          message: row["note"],
          author: author,
          author_name: row["user"]
        }
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
caramelize-1.1.1 lib/caramelize/input_wiki/wikkawiki.rb
caramelize-1.1.0 lib/caramelize/input_wiki/wikkawiki.rb