Sha256: a82b4ddfa2302ebc20d11094b32beae54ab3c6daf1c71bf7cadfd2d31b5829c9

Contents?: true

Size: 961 Bytes

Versions: 49

Compression:

Stored size: 961 Bytes

Contents

require 'tilt/template'

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

    def self.engine_initialized?
      defined? ::Nokogiri
    end

    def initialize_engine
      require_template_library 'nokogiri'
    end

    def prepare; end

    def evaluate(scope, locals)
      if data.respond_to?(:to_str)
        wrapper = proc { yield.sub(DOCUMENT_HEADER, "") } if block_given?
        super(scope, locals, &wrapper)
      else
        ::Nokogiri::XML::Builder.new.tap(&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

49 entries across 42 versions & 11 rubygems

Version Path
mango-0.7.0 vendor/bundler/ruby/2.0.0/gems/tilt-1.4.1/lib/tilt/nokogiri.rb
torquebox-console-0.3.0 vendor/bundle/jruby/1.9/gems/tilt-1.3.4/lib/tilt/nokogiri.rb
challah-1.0.0 vendor/bundle/gems/tilt-1.4.1/lib/tilt/nokogiri.rb
swipe-rails-0.0.5 vendor/bundle/gems/tilt-1.4.1/lib/tilt/nokogiri.rb
font-awesome-rails-3.1.1.2 vendor/ruby/1.9.1/gems/tilt-1.3.7/lib/tilt/nokogiri.rb
font-awesome-rails-3.1.1.2 vendor/ruby/1.9.1/gems/tilt-1.3.5/lib/tilt/nokogiri.rb
font-awesome-rails-3.1.1.2 vendor/ruby/2.0.0/gems/tilt-1.3.5/lib/tilt/nokogiri.rb
font-awesome-rails-3.1.1.1 vendor/ruby/1.9.1/gems/tilt-1.3.5/lib/tilt/nokogiri.rb
font-awesome-rails-3.1.1.1 vendor/ruby/2.0.0/gems/tilt-1.3.5/lib/tilt/nokogiri.rb
font-awesome-rails-3.1.1.1 vendor/ruby/1.9.1/gems/tilt-1.3.7/lib/tilt/nokogiri.rb
challah-1.0.0.beta3 vendor/bundle/gems/tilt-1.3.7/lib/tilt/nokogiri.rb
challah-1.0.0.beta3 vendor/bundle/gems/tilt-1.4.1/lib/tilt/nokogiri.rb
tilt-1.4.1 lib/tilt/nokogiri.rb
tilt-1.4.0 lib/tilt/nokogiri.rb
fc-webicons-0.0.4 vendor/bundle/ruby/1.9.1/gems/tilt-1.3.6/lib/tilt/nokogiri.rb
challah-1.0.0.beta2 vendor/bundle/gems/tilt-1.3.7/lib/tilt/nokogiri.rb
challah-1.0.0.beta vendor/bundle/gems/tilt-1.3.6/lib/tilt/nokogiri.rb
tilt-1.3.7 lib/tilt/nokogiri.rb
fc-webicons-0.0.3 vendor/bundle/ruby/1.9.1/gems/tilt-1.3.6/lib/tilt/nokogiri.rb
fc-webicons-0.0.2 vendor/bundle/ruby/1.9.1/gems/tilt-1.3.6/lib/tilt/nokogiri.rb