Sha256: df03dd843d28562e0b0b460e6df4afeb933a35e0adf037cb010ae1bd66e9ddd8
Contents?: true
Size: 947 Bytes
Versions: 2
Compression:
Stored size: 947 Bytes
Contents
require 'nokogiri' module WP2Middleman class PostCollection include Enumerable def self.from_file(wp_xml_export_file) xml = Nokogiri::XML(File.open("#{Dir.pwd}/#{wp_xml_export_file}")) new xml.css('item').collect { |raw_wp_post| WP2Middleman::Post.new(raw_wp_post) } end def initialize(posts=[]) @posts = posts end def each(&block) posts.each &block end def [] key posts[key] end def empty? posts.empty? end def without_attachments self.class.new(reject(&:attachment?)) end def only_valid self.class.new(select(&:valid?)) end def to_middleman(body_to_markdown: false, include_fields: []) middleman_posts = collect { |p| WP2Middleman::MiddlemanPost.new(p, body_to_markdown: body_to_markdown, include_fields: include_fields) } self.class.new(middleman_posts) end private attr_reader :posts end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
wp2middleman-0.0.3 | lib/wp2middleman/post_collection.rb |
wp2middleman-0.0.2 | lib/wp2middleman/post_collection.rb |