Sha256: 4b8cf3a0fa4d45429c75b50100e03e72dea33e1ad1997fbb2dc3623d9cf2b37d

Contents?: true

Size: 1.41 KB

Versions: 2

Compression:

Stored size: 1.41 KB

Contents

# -*- coding: utf-8 -*-
module Nwiki
  module Core
    class Wiki
      def self.repo_filename_encoding
        Encoding::UTF_8
      end

      def self.parser
        Orgmode::Parser
      end

      def self.canonicalize_path path
        unescaped_path = URI.unescape(path).force_encoding(repo_filename_encoding)
        unescaped_path.sub(/^\//, '')
      end

      def initialize path
        @path = path
        @access = GitAccess.new(path)
      end

      def find path
        canonicalized_path = self.class.canonicalize_path path
        blob_entry = @access
          .tree('master')
          .find { |e| canonicalized_path == e.path.sub(/\.org$/){ '' } }
        return nil unless blob_entry
        byte_string = blob_entry.blob(@access.repo).data
        if blob_entry.name =~ /\.org$/
          byte_string.force_encoding(self.class.repo_filename_encoding)
          Page.new(::File.basename(blob_entry.name, '.org'), byte_string, self.class.parser)
        else
          File.new(blob_entry.name, byte_string)
        end
      end

      def name
        blob_entry = @access
          .tree('master')
          .find { |e| e.path == '__nwiki/name' }
        return '' unless blob_entry
        byte_string = blob_entry.blob(@access.repo).data
        byte_string.force_encoding(self.class.repo_filename_encoding)
        byte_string.chomp
      end

      def exist?
        @access.exist?
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nwiki-0.0.3 lib/nwiki/core/wiki.rb
nwiki-0.0.2 lib/nwiki/core/wiki.rb