Sha256: 4d7f42646f685b3f23bc706aaa1637ec67670080c2edce6a95d520ed82ddf7ba
Contents?: true
Size: 1.47 KB
Versions: 21
Compression:
Stored size: 1.47 KB
Contents
# NOTE: search-and-replace content> with contents> before importing module BlogLogic module Import class WordPress attr_accessor :source_file def initialize(file) self.source_file = file end def to(blog) self.posts.each do |post| blog.posts.create( :title => post.title, :author => blog.default_author, :publication_date => post.publication_date, :content => post.content, :summary => post.content.truncate(255), :state => 'published' ) end end def posts @posts ||= [] if @posts.empty? raw_posts.each do |item| @posts << Post.new( :title => item.xpath('.//title').first.content, :date => item.xpath('.//pubDate').first.content, :content => item.xpath('.//contents').children.first.content, :summary => item.xpath('.//excerpt').first.try(:content) ) end end @posts end def source @source ||= Nokogiri::XML(File.open(self.source_file)) end def raw_posts self.source.xpath('//item') end class Post attr_accessor :title, :date, :content def initialize(args) args.each{|k,v| self.send("#{k}=",v) if self.respond_to?(k)} end def publication_date DateTime.parse(self.date) end end end end end
Version data entries
21 entries across 21 versions & 1 rubygems