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