Class: Rackful::Serializer::XHTML
- Inherits:
-
Rackful::Serializer
- Object
- Rackful::Serializer
- Rackful::Serializer::XHTML
- Defined in:
- lib/rackful/serializer.rb
Direct Known Subclasses
Constant Summary
- CONTENT_TYPES =
The content types served by this serializer.
[ '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)
-
- (String) content_type
inherited
from Rackful::Serializer
readonly
The content type to be served by this Serializer.
- - (Request) request inherited from Rackful::Serializer readonly
- - (Resource) resource inherited from Rackful::Serializer readonly
Class Method Summary (collapse)
-
+ (void) footer {|serializer| ... }
Set a footer generator.
-
+ (void) header {|serializer| ... }
Set a header generator.
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
.
- (Request) request (readonly) Originally defined in class Rackful::Serializer
- (Resource) resource (readonly) Originally defined in class Rackful::Serializer
Class Method Details
+ (void) footer {|serializer| ... }
Set a footer generator.
141 142 143 144 |
# File 'lib/rackful/serializer.rb', line 141 def self. &block @@footer = block self end |
+ (void) header {|serializer| ... }
Set a header generator.
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| ... }
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>' + end |