Sha256: a69b404eb9b55a6df750860c22dd127acddbd7c8bdd0b2f9280c3d0963d029e6

Contents?: true

Size: 773 Bytes

Versions: 1

Compression:

Stored size: 773 Bytes

Contents

module Xml
  module Kit
    class Template
      attr_reader :target

      def initialize(target)
        @target = target
      end

      # Returns the compiled template as a [String].
      #
      # @param options [Hash] The options hash to pass to the template engine.
      def to_xml(options = {})
        template.render(target, options)
      end

      private

      def template_path
        return target.template_path if target.respond_to?(:template_path)

        root_path = File.expand_path(File.dirname(__FILE__))
        template_name = "#{target.class.name.split("::").last.underscore}.builder"
        File.join(root_path, "builders/templates/", template_name)
      end

      def template
        Tilt.new(template_path)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
xml-kit-0.1.0 lib/xml/kit/template.rb