Sha256: 71f10853c5fb00e614b1d31959b628b14366b6da6cef5334c48631d3d1ec7d59

Contents?: true

Size: 861 Bytes

Versions: 14

Compression:

Stored size: 861 Bytes

Contents

# frozen_string_literal: true
require_relative 'template'
require 'nokogiri'

module Tilt
  # Nokogiri template implementation. See:
  # http://nokogiri.org/
  class NokogiriTemplate < Template
    DOCUMENT_HEADER = /\A<\?xml version=\"1\.0\"\?>\n?/
    self.default_mime_type = 'text/xml'

    def evaluate(scope, locals)
      if @data.respond_to?(:to_str)
        if block_given?
          super(scope, locals){yield.sub(DOCUMENT_HEADER, "")}
        else
          super
        end
      else
        ::Nokogiri::XML::Builder.new(&@data).to_xml
      end
    end

    def precompiled_preamble(locals)
      return super if locals.include? :xml
      "xml = ::Nokogiri::XML::Builder.new { |xml| }\n#{super}"
    end

    def precompiled_postamble(locals)
      "xml.to_xml"
    end

    def precompiled_template(locals)
      @data.to_str
    end
  end
end

Version data entries

14 entries across 13 versions & 5 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.1.0/gems/tilt-2.4.0/lib/tilt/nokogiri.rb
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/tilt-2.4.0/lib/tilt/nokogiri.rb
tilt-2.6.0 lib/tilt/nokogiri.rb
brakeman-7.0.0 bundle/ruby/3.1.0/gems/tilt-2.5.0/lib/tilt/nokogiri.rb
tilt-2.5.0 lib/tilt/nokogiri.rb
brakeman-6.2.2 bundle/ruby/3.1.0/gems/tilt-2.4.0/lib/tilt/nokogiri.rb
brakeman-6.2.2.rc1 bundle/ruby/3.3.0/gems/tilt-2.4.0/lib/tilt/nokogiri.rb
brakeman-6.2.1 bundle/ruby/3.1.0/gems/tilt-2.4.0/lib/tilt/nokogiri.rb
brakeman-6.2.0 bundle/ruby/3.1.0/gems/tilt-2.4.0/lib/tilt/nokogiri.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/tilt-2.4.0/lib/tilt/nokogiri.rb
tilt-2.4.0 lib/tilt/nokogiri.rb
getargv-0.3.3-universal-darwin vendor/bundle/ruby/3.3.0/gems/tilt-2.3.0/lib/tilt/nokogiri.rb
tilt-2.3.0 lib/tilt/nokogiri.rb
tilt-2.2.0 lib/tilt/nokogiri.rb