Sha256: a1d0e38956639aa36afe070a7f1879c2a499e4c0ca20cbef85e251b24676ca42

Contents?: true

Size: 1.17 KB

Versions: 4

Compression:

Stored size: 1.17 KB

Contents

module Brief
  class Document
    attr_reader :content, :options

    def initialize(options)
      @options = options

      case
      when options.is_a?(String)
        @content = options
      when options.is_a?(Pathname)
        @content = options.read
      when options.is_a?(Hash)
        @content = options[:path].read
      end
    end

    def write using
      using.run_before_hooks(:write) do
        write
      end
    end

    def publish using=nil
      using ||= publisher

      document = self
      using.run_before_hooks(:publish) do
        process(document)
      end
    end

    def publisher
      @publisher ||= Brief::Publisher.find(options[:publisher] || "default")
    end

    def method_missing meth, *args, &block
      if parser.respond_to?(meth)
        return parser.send(meth, *args, &block)
      end

      super
    end

    def checksum
      @checksum ||= Digest::MD5.hexdigest(content)
    end

    def parser
      @parser ||= Brief::Parser.new(content, checksum: checksum)
    end


    def settings
      parser.front_matter
    end

    def elements
      parser.send(:elements)
    end

    def tree
      parser.send(:tree)
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
brief-0.0.5 lib/brief/document.rb
brief-0.0.4 lib/brief/document.rb
brief-0.0.3 lib/brief/document.rb
brief-0.0.2 lib/brief/document.rb