Class: RSS::Atom::Feed::Entry::Content
- Includes:
- CommonModel
- Defined in:
- lib/rss/atom.rb
Overview
Contains or links to the content of the Entry. It has the following attributes:
-
type
-
src
Reference: validator.w3.org/feed/docs/rfc4287.html#element.content
Constant Summary
Constants included from CommonModel
CommonModel::ELEMENTS, CommonModel::NSPOOL
Constants inherited from Element
Element::GET_ATTRIBUTES, Element::HAVE_CHILDREN_ELEMENTS, Element::INDENT, Element::MODELS, Element::MUST_CALL_VALIDATORS, Element::NEED_INITIALIZE_VARIABLES, Element::PLURAL_FORMS, Element::TO_ELEMENT_METHODS
Instance Attribute Summary collapse
-
#xml ⇒ Object
Returns or builds the element content in XML.
Attributes inherited from Element
Class Method Summary collapse
Instance Method Summary collapse
-
#atom_validate(ignore_unknown_element, tags, uri) ⇒ Object
Raises a MissingAttributeError, NotAvailableValueError, MissingTagError or NotExpectedTagError if the element is not properly formatted.
-
#have_xml_content? ⇒ Boolean
Returns true if the element has inline XML content.
-
#inline_html? ⇒ Boolean
Returns true if the element contains inline content that has a HTML media type.
-
#inline_other? ⇒ Boolean
Returns true if the element contains inline content that has a MIME media type.
-
#inline_other_base64? ⇒ Boolean
Returns true if the element contains inline content encoded in base64.
-
#inline_other_text? ⇒ Boolean
Returns true if the element contains inline content that has a text media type.
-
#inline_other_xml? ⇒ Boolean
Returns true if the element contains inline content that has a XML media type.
-
#inline_text? ⇒ Boolean
Returns true if the element contains inline content that has a text or HTML media type, or no media type at all.
-
#inline_xhtml? ⇒ Boolean
Returns true if the element contains inline content that has a XHTML media type.
-
#mime_split ⇒ Object
Splits the type attribute into an array, e.g.
-
#need_base64_encode? ⇒ Boolean
Returns true if the content needs to be encoded in base64.
-
#out_of_line? ⇒ Boolean
Returns true if the element contains linked content.
-
#xhtml ⇒ Object
Returns the element content in XHTML.
Methods included from CommonModel
Methods inherited from Element
add_have_children_element, add_need_initialize_variable, add_plural_form, add_to_element_method, content_setup, #convert, #converter=, def_corresponded_attr_reader, def_corresponded_attr_writer, #full_name, get_attributes, have_children_elements, have_content?, inherited, inherited_base, #initialize, install_get_attribute, install_model, install_must_call_validator, install_ns, models, must_call_validators, need_initialize_variables, need_parent?, plural_forms, required_prefix, required_uri, #set_next_element, tag_name, #tag_name, to_element_methods, #to_s, #valid?, #validate, #validate_for_stream
Methods included from BaseModel
#install_date_element, #install_have_child_element, #install_have_children_element, #install_text_element
Methods included from Utils
element_initialize_arguments?, get_file_and_line_from_caller, html_escape, new_with_value_if_need, to_class_name
Methods included from Utils::InheritedReader
#inherited_array_reader, #inherited_hash_reader, #inherited_reader
Methods included from SetupMaker
Constructor Details
This class inherits a constructor from RSS::Element
Instance Attribute Details
#xml ⇒ Object
Returns or builds the element content in XML.
644 645 646 647 648 649 650 651 652 653 654 655 656 |
# File 'lib/rss/atom.rb', line 644 def xml return @xml unless inline_xhtml? return @xml if @xml.nil? if @xml.is_a?(XML::Element) and [@xml.name, @xml.uri] == ["div", XHTML_URI] return @xml end children = @xml children = [children] unless children.is_a?(Array) XML::Element.new("div", nil, XHTML_URI, {"xmlns" => XHTML_URI}, children) end |
Class Method Details
.xml_getter ⇒ Object
620 621 622 |
# File 'lib/rss/atom.rb', line 620 def xml_getter "xml" end |
.xml_setter ⇒ Object
616 617 618 |
# File 'lib/rss/atom.rb', line 616 def xml_setter "xml=" end |
Instance Method Details
#atom_validate(ignore_unknown_element, tags, uri) ⇒ Object
Raises a MissingAttributeError, NotAvailableValueError, MissingTagError or NotExpectedTagError if the element is not properly formatted.
670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 |
# File 'lib/rss/atom.rb', line 670 def atom_validate(ignore_unknown_element, , uri) if out_of_line? raise MissingAttributeError.new(tag_name, "type") if @type.nil? unless (content.nil? or content.empty?) raise NotAvailableValueError.new(tag_name, content) end elsif inline_xhtml? if @xml.nil? raise MissingTagError.new("div", tag_name) end unless @xml.name == "div" and @xml.uri == XHTML_URI raise NotExpectedTagError.new(@xml.name, @xml.uri, tag_name) end end end |
#have_xml_content? ⇒ Boolean
Returns true if the element has inline XML content.
639 640 641 |
# File 'lib/rss/atom.rb', line 639 def have_xml_content? inline_xhtml? or inline_other_xml? end |
#inline_html? ⇒ Boolean
Returns true if the element contains inline content that has a HTML media type.
694 695 696 697 |
# File 'lib/rss/atom.rb', line 694 def inline_html? return false if out_of_line? @type == "html" or mime_split == ["text", "html"] end |
#inline_other? ⇒ Boolean
Returns true if the element contains inline content that has a MIME media type.
707 708 709 710 711 712 |
# File 'lib/rss/atom.rb', line 707 def inline_other? return false if out_of_line? media_type, subtype = mime_split return false if media_type.nil? or subtype.nil? true end |
#inline_other_base64? ⇒ Boolean
Returns true if the element contains inline content encoded in base64.
743 744 745 |
# File 'lib/rss/atom.rb', line 743 def inline_other_base64? inline_other? and !inline_other_text? and !inline_other_xml? end |
#inline_other_text? ⇒ Boolean
Returns true if the element contains inline content that has a text media type.
716 717 718 719 720 721 722 723 |
# File 'lib/rss/atom.rb', line 716 def inline_other_text? return false unless inline_other? return false if inline_other_xml? media_type, = mime_split return true if "text" == media_type.downcase false end |
#inline_other_xml? ⇒ Boolean
Returns true if the element contains inline content that has a XML media type.
727 728 729 730 731 732 733 734 735 736 737 738 739 |
# File 'lib/rss/atom.rb', line 727 def inline_other_xml? return false unless inline_other? media_type, subtype = mime_split normalized_mime_type = "#{media_type}/#{subtype}".downcase if /(?:\+xml|^xml)$/ =~ subtype or %w(text/xml-external-parsed-entity application/xml-external-parsed-entity application/xml-dtd).find {|x| x == normalized_mime_type} return true end false end |
#inline_text? ⇒ Boolean
Returns true if the element contains inline content that has a text or HTML media type, or no media type at all.
688 689 690 |
# File 'lib/rss/atom.rb', line 688 def inline_text? !out_of_line? and [nil, "text", "html"].include?(@type) end |
#inline_xhtml? ⇒ Boolean
Returns true if the element contains inline content that has a XHTML media type.
701 702 703 |
# File 'lib/rss/atom.rb', line 701 def inline_xhtml? !out_of_line? and @type == "xhtml" end |
#mime_split ⇒ Object
Splits the type attribute into an array, e.g. [“text”, “xml”]
753 754 755 756 757 758 759 760 |
# File 'lib/rss/atom.rb', line 753 def mime_split media_type = subtype = nil if /\A\s*([a-z]+)\/([a-z\+]+)\s*(?:;.*)?\z/i =~ @type.to_s media_type = $1.downcase subtype = $2.downcase end [media_type, subtype] end |
#need_base64_encode? ⇒ Boolean
Returns true if the content needs to be encoded in base64.
763 764 765 |
# File 'lib/rss/atom.rb', line 763 def need_base64_encode? inline_other_base64? end |
#out_of_line? ⇒ Boolean
Returns true if the element contains linked content.
748 749 750 |
# File 'lib/rss/atom.rb', line 748 def out_of_line? not @src.nil? end |
#xhtml ⇒ Object
Returns the element content in XHTML.
659 660 661 662 663 664 665 |
# File 'lib/rss/atom.rb', line 659 def xhtml if inline_xhtml? xml else nil end end |