Sha256: eb9f3e7c7a1f2e0f0205c64796c8ea924a48bd011c0a3db3e07801cfd53f3db7

Contents?: true

Size: 1.05 KB

Versions: 23

Compression:

Stored size: 1.05 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)

        json
      end

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

        super(json)

        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

23 entries across 23 versions & 1 rubygems

Version Path
vedeu-0.6.35 lib/vedeu/output/renderers/json.rb
vedeu-0.6.34 lib/vedeu/output/renderers/json.rb
vedeu-0.6.33 lib/vedeu/output/renderers/json.rb
vedeu-0.6.32 lib/vedeu/output/renderers/json.rb
vedeu-0.6.31 lib/vedeu/output/renderers/json.rb
vedeu-0.6.30 lib/vedeu/output/renderers/json.rb
vedeu-0.6.29 lib/vedeu/output/renderers/json.rb
vedeu-0.6.28 lib/vedeu/output/renderers/json.rb
vedeu-0.6.27 lib/vedeu/output/renderers/json.rb
vedeu-0.6.26 lib/vedeu/output/renderers/json.rb
vedeu-0.6.25 lib/vedeu/output/renderers/json.rb
vedeu-0.6.24 lib/vedeu/output/renderers/json.rb
vedeu-0.6.23 lib/vedeu/output/renderers/json.rb
vedeu-0.6.22 lib/vedeu/output/renderers/json.rb
vedeu-0.6.21 lib/vedeu/output/renderers/json.rb
vedeu-0.6.20 lib/vedeu/output/renderers/json.rb
vedeu-0.6.19 lib/vedeu/output/renderers/json.rb
vedeu-0.6.18 lib/vedeu/output/renderers/json.rb
vedeu-0.6.17 lib/vedeu/output/renderers/json.rb
vedeu-0.6.16 lib/vedeu/output/renderers/json.rb