Sha256: 769c9000385ae52d2c9b23789a00e2c6e726b33344b77fd660fecf8c28af8113

Contents?: true

Size: 1.09 KB

Versions: 25

Compression:

Stored size: 1.09 KB

Contents

module Vedeu

  module Renderers

    # Renders a {Vedeu::Terminal::Buffer} as JSON.
    #
    class JSON < Vedeu::Renderers::File

      # Returns a new instance of Vedeu::Renderers::JSON.
      #
      # @param options [Hash]
      # @return [Vedeu::Renderers::JSON]
      def initialize(options = {})
        @options = options || {}
      end

      # Render a cleared output.
      #
      # @return [String]
      def clear
        json = parse({})

        super(json, { compression: false })

        json
      end

      # @param output [Vedeu::Models::Page]
      # @return [String]
      def render(output)
        json = parse(output)

        super(json, { compression: false })

        json
      end

      private

      # @param output [Vedeu::Models::Page]
      # @return [String]
      def parse(output)
        ::JSON.pretty_generate(as_hash(output))
      end

      # @param output [Vedeu::Models::Page]
      # @return [Array]
      def as_hash(output)
        return output if output.is_a?(Hash)

        output.content.map(&:to_hash)
      end

    end # JSON

  end # Renderers

end # Vedeu

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
vedeu-0.6.61 lib/vedeu/output/renderers/json.rb
vedeu-0.6.60 lib/vedeu/output/renderers/json.rb
vedeu-0.6.59 lib/vedeu/output/renderers/json.rb
vedeu-0.6.58 lib/vedeu/output/renderers/json.rb
vedeu-0.6.57 lib/vedeu/output/renderers/json.rb
vedeu-0.6.56 lib/vedeu/output/renderers/json.rb
vedeu-0.6.54 lib/vedeu/output/renderers/json.rb
vedeu-0.6.53 lib/vedeu/output/renderers/json.rb
vedeu-0.6.52 lib/vedeu/output/renderers/json.rb
vedeu-0.6.51 lib/vedeu/output/renderers/json.rb
vedeu-0.6.50 lib/vedeu/output/renderers/json.rb
vedeu-0.6.49 lib/vedeu/output/renderers/json.rb
vedeu-0.6.48 lib/vedeu/output/renderers/json.rb
vedeu-0.6.47 lib/vedeu/output/renderers/json.rb
vedeu-0.6.46 lib/vedeu/output/renderers/json.rb
vedeu-0.6.45 lib/vedeu/output/renderers/json.rb
vedeu-0.6.44 lib/vedeu/output/renderers/json.rb
vedeu-0.6.43 lib/vedeu/output/renderers/json.rb
vedeu-0.6.42 lib/vedeu/output/renderers/json.rb
vedeu-0.6.41 lib/vedeu/output/renderers/json.rb