Sha256: db251971a56252e63485df219bc41c4bdba91e7675bb7c2830cc0ec344b79ba9

Contents?: true

Size: 1.69 KB

Versions: 10

Compression:

Stored size: 1.69 KB

Contents

module RDF::RDFa
  ##
  # RDFa format specification.
  #
  # @example Obtaining an RDFa format class
  #   RDF::Format.for(:rdfa)     #=> RDF::RDFa::Format
  #   RDF::Format.for("etc/doap.html")
  #   RDF::Format.for(file_name:      "etc/doap.html")
  #   RDF::Format.for(file_extension: "html")
  #   RDF::Format.for(content_type:   "text/html")
  #   RDF::Format.for(content_type:   "application/xhtml+xml")
  #
  # @example Obtaining serialization format MIME types
  #   RDF::Format.content_types      #=> {"text/html" => [RDF::RDFa::Format]}
  #
  # @example Obtaining serialization format file extension mappings
  #   RDF::Format.file_extensions    #=> {xhtml: "application/xhtml+xml"}
  #
  # @see http://www.w3.org/TR/rdf-testcases/#ntriples
  class Format < RDF::Format
    content_encoding 'utf-8'
    content_type     'text/html;q=0.5',
      aliases: %w(application/xhtml+xml;q=0.7 image/svg+xml;q=0.4),
      extensions: [:html, :xhtml, :svg]
    reader { RDF::RDFa::Reader }
    writer { RDF::RDFa::Writer }

    ##
    # Sample detection to see if it matches RDFa (not RDF/XML or Microdata)
    #
    # Use a text sample to detect the format of an input file. Sub-classes implement
    # a matcher sufficient to detect probably format matches, including disambiguating
    # between other similar formats.
    #
    # @param [String] sample Beginning several bytes (~ 1K) of input.
    # @return [Boolean]
    def self.detect(sample)
      (sample.match(/<[^>]*(about|resource|prefix|typeof|property|vocab)\s*="[^>]*>/m) ||
       sample.match(/<[^>]*DOCTYPE\s+html[^>]*>.*xmlns:/im)
      ) && !sample.match(/<(\w+:)?(RDF)/)
    end

    def self.symbols
      [:rdfa, :lite, :html, :xhtml, :svg]
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rdf-rdfa-3.1.0 lib/rdf/rdfa/format.rb
rdf-rdfa-3.0.1 lib/rdf/rdfa/format.rb
rdf-rdfa-3.0.0 lib/rdf/rdfa/format.rb
rdf-rdfa-2.2.4 lib/rdf/rdfa/format.rb
rdf-rdfa-2.2.3 lib/rdf/rdfa/format.rb
rdf-rdfa-2.2.2 lib/rdf/rdfa/format.rb
rdf-rdfa-2.2.1 lib/rdf/rdfa/format.rb
rdf-rdfa-2.2.0 lib/rdf/rdfa/format.rb
rdf-rdfa-2.1.1 lib/rdf/rdfa/format.rb
rdf-rdfa-2.1.0 lib/rdf/rdfa/format.rb