Class: Rackful::Serializer::XHTML

Inherits:
Rackful::Serializer show all
Defined in:
lib/rackful/serializer.rb

Direct Known Subclasses

HTTPStatus::Resource::XHTML

Constant Summary

CONTENT_TYPES =

The content types served by this serializer.

See Also:

  • Serializer::CONTENT_TYPES
[
  'application/xml; charset=UTF-8',
  'text/xml; charset=UTF-8',
  'text/html; charset=UTF-8',
  'application/xhtml+xml; charset=UTF-8',
]

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

This class inherits a constructor from Rackful::Serializer

Instance Attribute Details

- (String) content_type (readonly) Originally defined in class Rackful::Serializer

Returns The content type to be served by this Serializer. This will always be one of the content types listed in constant CONTENT_TYPES.

Returns:

  • (String)

    The content type to be served by this Serializer. This will always be one of the content types listed in constant CONTENT_TYPES.

- (Request) request (readonly) Originally defined in class Rackful::Serializer

Returns:

- (Resource) resource (readonly) Originally defined in class Rackful::Serializer

Returns:

Class Method Details

Set a footer generator.

Yield Parameters:

Yield Returns:

  • (String)

    some XHTML



141
142
143
144
# File 'lib/rackful/serializer.rb', line 141

def self.footer &block
  @@footer = block
  self
end

+ (void) header {|serializer| ... }

Set a header generator.

Yield Parameters:

Yield Returns:

  • (String)

    some XHTML



124
125
126
127
# File 'lib/rackful/serializer.rb', line 124

def self.header &block
  @@header = block
  self
end

Instance Method Details

- (void) each {|xhtml| ... }

Yield Parameters:

  • xhtml (String)


85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/rackful/serializer.rb', line 85

def each &block
  tmp = ''
  # The XML header is only sent for XML media types:
  if /xml/ === self.content_type
    tmp += <<EOS
<?xml version="1.0" encoding="UTF-8"?>
EOS
  end
  tmp += <<EOS
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<head>
<title>#{ Rack::Utils.escape_html(self.resource.title) }</title>
<base href="#{self.html_base_uri}"/>
EOS
  unless '/' == self.request.canonical_uri.path
    tmp += <<EOS
<link rel="contents" href="#{'/' === self.request.canonical_uri.path[-1] ? '../' : './' }"/>
EOS
  end
  r = self.resource.to_rackful
  tmp += self.header + '<div id="rackful-content"' + self.xsd_type( r ) + '>'
  yield tmp
  each_nested( r, &block )
  yield '</div>' + footer
end