# frozen_string_literal: false
# This file contains the implementation of trackbacks. It is entirely internal
# and not useful to outside developers.
TRACKBACK_PREFIX = 'trackback'
TRACKBACK_URI = 'http://madskills.com/public/xml/rss/module/trackback/'
RDF.install_ns(TRACKBACK_PREFIX, TRACKBACK_URI)
Rss.install_ns(TRACKBACK_PREFIX, TRACKBACK_URI)
def trackback_validate(ignore_unknown_element, tags, uri)
if tags.find {|tag| tag == "about"} and
!tags.find {|tag| tag == "ping"}
raise MissingTagError.new("#{TRACKBACK_PREFIX}:ping", tag_name)
module BaseTrackBackModel
ELEMENTS = %w(ping about)
def append_features(klass)
unless klass.class == Module
klass.module_eval {include TrackBackUtils}
klass.install_must_call_validator(TRACKBACK_PREFIX, TRACKBACK_URI)
var_name = "#{TRACKBACK_PREFIX}_#{name}"
klass_name = "TrackBack#{Utils.to_class_name(name)}"
klass.install_have_child_element(name, TRACKBACK_URI, "?", var_name)
klass.module_eval(<<-EOC, __FILE__, __LINE__)
remove_method :#{var_name}
@#{var_name} and @#{var_name}.value
remove_method :#{var_name}=
@#{var_name} = Utils.new_with_value_if_need(#{klass_name}, value)
[%w(about s)].each do |name, postfix|
var_name = "#{TRACKBACK_PREFIX}_#{name}"
klass_name = "TrackBack#{Utils.to_class_name(name)}"
klass.install_have_children_element(name, TRACKBACK_URI, "*",
klass.module_eval(<<-EOC, __FILE__, __LINE__)
remove_method :#{var_name}
@#{var_name}.first and @#{var_name}.first.value
ret = @#{var_name}.__send__("[]", *args)
ret.collect {|x| x.value}
remove_method :#{var_name}=
remove_method :set_#{var_name}
item = Utils.new_with_value_if_need(#{klass_name}, args[0])
new_val = new_value.collect do |val|
Utils.new_with_value_if_need(#{klass_name}, val)
new_val = Utils.new_with_value_if_need(#{klass_name}, new_val)
@#{var_name}.__send__("[]=", *(args[0..-2] + [new_val]))
alias set_#{var_name} #{var_name}=
extend BaseTrackBackModel
class TrackBackPing < Element
["resource", ::RSS::RDF::URI, true]
].each do |name, uri, required|
install_get_attribute(name, uri, required, nil, nil,
"#{::RSS::RDF::PREFIX}:#{name}")
alias_method(:value, :resource)
alias_method(:value=, :resource=)
if Utils.element_initialize_arguments?(args)
tag_name_with_prefix(TRACKBACK_PREFIX)
class TrackBackAbout < Element
["resource", ::RSS::RDF::URI, true]
].each do |name, uri, required|
install_get_attribute(name, uri, required, nil, nil,
"#{::RSS::RDF::PREFIX}:#{name}")
alias_method(:value, :resource)
alias_method(:value=, :resource=)
if Utils.element_initialize_arguments?(args)
tag_name_with_prefix(TRACKBACK_PREFIX)
def setup_maker_attributes(about)
about.resource = self.resource
extend BaseTrackBackModel
class TrackBackPing < Element
alias_method(:value, :content)
alias_method(:value=, :content=)
if Utils.element_initialize_arguments?(args)
tag_name_with_prefix(TRACKBACK_PREFIX)
class TrackBackAbout < Element
alias_method(:value, :content)
alias_method(:value=, :content=)
if Utils.element_initialize_arguments?(args)
tag_name_with_prefix(TRACKBACK_PREFIX)
class Item; include TrackBackModel10; end
class Item; include TrackBackModel20; end
BaseTrackBackModel::ELEMENTS.each do |name|
class_name = Utils.to_class_name(name)
BaseListener.install_class_name(TRACKBACK_URI, name,
"TrackBack#{class_name}")
BaseTrackBackModel::ELEMENTS.collect! {|name| "#{TRACKBACK_PREFIX}_#{name}"}