Sha256: b3ab51d380901c296a0a55197133efd14df96f3c65beb78977052f4595911579

Contents?: true

Size: 648 Bytes

Versions: 10

Compression:

Stored size: 648 Bytes

Contents

# frozen_string_literal: true

require "tilt/jbuilder"

module Mihari
  module Services
    #
    # Jbuilder based JSON renderer
    #
    class JbuilderRenderer < Service
      attr_reader :template

      #
      # @param [String] template
      # @param [Hash] params
      #
      # @return [String]
      #
      def call(template, params = {})
        @template = template

        jbuilder_template = Tilt::JbuilderTemplate.new { template_string }
        jbuilder_template.render(nil, params)
      end

      def template_string
        return File.read(template) if Pathname(template).exist?

        template
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
mihari-8.0.2 lib/mihari/services/renderer.rb
mihari-8.0.1 lib/mihari/services/renderer.rb
mihari-8.0.0 lib/mihari/services/renderer.rb
mihari-7.6.4 lib/mihari/services/renderer.rb
mihari-7.6.3 lib/mihari/services/renderer.rb
mihari-7.6.2 lib/mihari/services/renderer.rb
mihari-7.6.1 lib/mihari/services/renderer.rb
mihari-7.6.0 lib/mihari/services/renderer.rb
mihari-7.5.0 lib/mihari/services/renderer.rb
mihari-7.4.0 lib/mihari/services/renderer.rb