Class: Tilt::NokogiriTemplate

Inherits:
Template
  • Object
show all
Defined in:
lib/tilt/nokogiri.rb

Overview

Nokogiri template implementation. See: nokogiri.org/

Constant Summary

DOCUMENT_HEADER =
/^<\?xml version=\"1\.0\"\?>\n?/

Instance Attribute Summary

Attributes inherited from Template

#data, #file, #line, #options

Instance Method Summary (collapse)

Methods inherited from Template

#basename, default_mime_type, default_mime_type=, #eval_file, #initialize, metadata, #metadata, #name, #render

Constructor Details

This class inherits a constructor from Tilt::Template

Instance Method Details

- (Object) evaluate(scope, locals)



13
14
15
16
17
18
19
20
# File 'lib/tilt/nokogiri.rb', line 13

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

- (Object) precompiled_postamble(locals)



27
28
29
# File 'lib/tilt/nokogiri.rb', line 27

def precompiled_postamble(locals)
  "xml.to_xml"
end

- (Object) precompiled_preamble(locals)



22
23
24
25
# File 'lib/tilt/nokogiri.rb', line 22

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

- (Object) precompiled_template(locals)



31
32
33
# File 'lib/tilt/nokogiri.rb', line 31

def precompiled_template(locals)
  data.to_str
end

- (Object) prepare



11
# File 'lib/tilt/nokogiri.rb', line 11

def prepare; end