Sha256: 0e60be0da01d8db7a2c5d9f180b316cd846b9abee14dd1a31dbd6c08674112b0
Contents?: true
Size: 1.32 KB
Versions: 2
Compression:
Stored size: 1.32 KB
Contents
module Evernicious class EnexBuilder def build_enex_document(bookmarks) builder = Nokogiri::XML::Builder.new do |xml| xml.send('en-export'.to_sym){ bookmarks.each do |bookmark| build_bookmark(xml, bookmark) end } end Nokogiri::XML(builder.to_xml) end private def build_bookmark(xml, bookmark) xml.note{ xml.title bookmark.title xml.content{ xml.cdata(within_enex_note(bookmark.comments)) } xml.created as_evernote_date(bookmark.added_at) xml.updated as_evernote_date(bookmark.added_at) xml.send('source-url'.to_sym, bookmark.url) bookmark.tags.each do |tag| xml.tag tag end } end def within_enex_note(content) builder = Nokogiri::XML::Builder.new do |xml| xml.doc.create_internal_subset('en-note', nil, "http://xml.evernote.com/pub/enml2.dtd") xml.send('en-note'.to_sym){ xml.text(content) } end builder.to_xml end def as_evernote_date(delicious_date) delicious_date.strftime("%Y%m%dT%H%M%SZ") end end # bookmarks = BookmarksParser.new.parse(File.open("d.htm", "r")) # puts EnexBuilder.new.build_enex_document(bookmarks).to_xml(:encoding => 'UTF-8') end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
evernicious-0.9.0.1 | lib/evernicious/enex_builder.rb |
evernicious-0.9.0 | lib/evernicious/enex_builder.rb |