Method: ContentDm::GenericMapper#to_html
- Defined in:
- lib/contentdm/mapper.rb
#to_html(record, opts = {}) ⇒ Object
Serialize the given Record to an HTML string
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/contentdm/mapper.rb', line 52 def to_html(record, opts = {}) = { :encoding => 'UTF-8', :save_with => (SaveOptions::AS_XML | SaveOptions::NO_DECLARATION), :indent => 2 }.merge(opts) builder = Nokogiri::XML::Builder.new do |doc| doc.span { record..each_pair { |k,v| unless v.nil? or v.to_s.empty? (prefix,tag) = k.split(/\./) # Convert from camelCase to Human Readable Label tag = tag.gsub(/(\S)([A-Z])/,'\1 \2').gsub(/\b('?[a-z])/) { $1.capitalize } doc.p { doc.b { doc.text "#{tag}:" } doc.text " " if v.is_a?(Array) doc.br v.each { |value| doc.text value unless value.empty? doc.br } else doc.text v end } end } } end builder.to_xml() end |