method
to_tag
v3.2.8 -
Show latest stable
-
0 notes -
Class: ActiveSupport::XmlMini
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.8
- 3.0.0 (0)
- 3.0.9 (0)
- 3.1.0 (0)
- 3.2.1 (0)
- 3.2.8 (0)
- 3.2.13 (0)
- 4.0.2 (0)
- 4.1.8 (0)
- 4.2.1 (0)
- 4.2.7 (0)
- 4.2.9 (0)
- 5.0.0.1 (0)
- 5.1.7 (0)
- 5.2.3 (0)
- 6.0.0 (0)
- 6.1.3.1 (0)
- 6.1.7.7 (0)
- 7.0.0 (0)
- 7.1.3.2 (0)
- 7.1.3.4 (0)
- What's this?
to_tag(key, value, options)
public
Hide source
# File activesupport/lib/active_support/xml_mini.rb, line 98 def to_tag(key, value, options) type_name = options.delete(:type) merged_options = options.merge(:root => key, :skip_instruct => true) if value.is_a?(::Method) || value.is_a?(::Proc) if value.arity == 1 value.call(merged_options) else value.call(merged_options, key.to_s.singularize) end elsif value.respond_to?(:to_xml) value.to_xml(merged_options) else type_name ||= TYPE_NAMES[value.class.name] type_name ||= value.class.name if value && !value.respond_to?(:to_str) type_name = type_name.to_s if type_name key = rename_key(key.to_s, options) attributes = options[:skip_types] || type_name.nil? ? { } : { :type => type_name } attributes[:nil] = true if value.nil? encoding = options[:encoding] || DEFAULT_ENCODINGS[type_name] attributes[:encoding] = encoding if encoding formatted_value = FORMATTING[type_name] && !value.nil? ? FORMATTING[type_name].call(value) : value options[:builder].tag!(key, formatted_value, attributes) end end