Started on attachment import

* created Attachment
* created Dump#attachments
* specs
* replaced require with autoload
This commit is contained in:
Marc Remolt 2011-06-05 17:43:30 +02:00
parent 814c7b4ca8
commit 772cfdc25b
8 changed files with 101 additions and 18 deletions

View File

@ -1,7 +1,7 @@
PATH PATH
remote: ./ remote: ./
specs: specs:
refinerycms-wordpress-import (0.1.0) refinerycms-wordpress-import (0.2.0)
bundler (~> 1.0) bundler (~> 1.0)
nokogiri (~> 1.4.4) nokogiri (~> 1.4.4)
refinerycms (~> 1.0.0) refinerycms (~> 1.0.0)

View File

@ -1,15 +1,16 @@
require 'nokogiri'
require "wordpress/railtie"
module Refinery module Refinery
module WordPress module WordPress
autoload :Author, 'wordpress/author'
autoload :Tag, 'wordpress/tag'
autoload :Category, 'wordpress/category'
autoload :Page, 'wordpress/page'
autoload :Post, 'wordpress/post'
autoload :Comment, 'wordpress/comment'
autoload :Dump, 'wordpress/dump'
autoload :Attachment, 'wordpress/attachment'
end end
end end
require 'nokogiri'
require 'wordpress/author'
require 'wordpress/tag'
require 'wordpress/category'
require 'wordpress/page'
require 'wordpress/post'
require 'wordpress/comment'
require 'wordpress/dump'
require "wordpress/railtie"

View File

@ -0,0 +1,27 @@
module Refinery
module WordPress
class Attachment
attr_reader :node
def initialize(node)
@node = node
end
def title
node.xpath("title").text
end
def description
node.xpath("description").text
end
def post_date
DateTime.parse node.xpath("wp:post_date").text
end
def url
node.xpath("wp:attachment_url").text
end
end
end
end

View File

@ -47,6 +47,12 @@ module Refinery
Category.new(category.text) Category.new(category.text)
end end
end end
def attachments
doc.xpath("//item[wp:post_type = 'attachment']").collect do |attachment|
Attachment.new(attachment)
end
end
end end
end end
end end

View File

@ -16,7 +16,7 @@
<!-- 7. WordPress will then import each of the posts, pages, comments, categories, etc. --> <!-- 7. WordPress will then import each of the posts, pages, comments, categories, etc. -->
<!-- contained in this file into your site. --> <!-- contained in this file into your site. -->
<!-- generator="WordPress/3.1.2" created="2011-05-21 12:27" --> <!-- generator="WordPress/3.1.2" created="2011-06-05 15:27" -->
<rss version="2.0" <rss version="2.0"
xmlns:excerpt="http://wordpress.org/export/1.1/excerpt/" xmlns:excerpt="http://wordpress.org/export/1.1/excerpt/"
xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
@ -29,7 +29,7 @@
<title>My test blog</title> <title>My test blog</title>
<link>http://localhost/wordpress</link> <link>http://localhost/wordpress</link>
<description>Just another WordPress site</description> <description>Just another WordPress site</description>
<pubDate>Sat, 21 May 2011 12:27:19 +0000</pubDate> <pubDate>Sun, 05 Jun 2011 15:27:27 +0000</pubDate>
<language>en</language> <language>en</language>
<wp:wxr_version>1.1</wp:wxr_version> <wp:wxr_version>1.1</wp:wxr_version>
<wp:base_site_url>http://localhost/wordpress</wp:base_site_url> <wp:base_site_url>http://localhost/wordpress</wp:base_site_url>
@ -161,6 +161,8 @@ In hac habitasse platea dictumst. Nunc quis tortor sed libero hendrerit dapibu
Integer interdum purus id erat. Duis nec velit vitae dolor mattis euismod. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Suspendisse pellentesque dignissim lacus. Integer interdum purus id erat. Duis nec velit vitae dolor mattis euismod. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Suspendisse pellentesque dignissim lacus.
<a href="http://localhost/wordpress/wp-content/uploads/2011/05/200px-Tux.svg_.png"><img class="alignnone size-full wp-image-13" title="200px-Tux.svg" src="http://localhost/wordpress/wp-content/uploads/2011/05/200px-Tux.svg_.png" alt="" width="200" height="235" /></a>
Nulla semper euismod arcu. Suspendisse egestas, erat a consectetur dapibus, felis orci cursus eros, et sollicitudin purus urna et metus. Integer eget est sed nunc euismod vestibulum. Integer nulla dui, tristique in, euismod et, interdum imperdiet, enim. Mauris at lectus. Sed egestas tortor nec mi.]]></content:encoded> Nulla semper euismod arcu. Suspendisse egestas, erat a consectetur dapibus, felis orci cursus eros, et sollicitudin purus urna et metus. Integer eget est sed nunc euismod vestibulum. Integer nulla dui, tristique in, euismod et, interdum imperdiet, enim. Mauris at lectus. Sed egestas tortor nec mi.]]></content:encoded>
<excerpt:encoded><![CDATA[]]></excerpt:encoded> <excerpt:encoded><![CDATA[]]></excerpt:encoded>
<wp:post_id>6</wp:post_id> <wp:post_id>6</wp:post_id>
@ -182,12 +184,12 @@ Nulla semper euismod arcu. Suspendisse egestas, erat a consectetur dapibus, fel
<wp:postmeta> <wp:postmeta>
<wp:meta_key>_edit_last</wp:meta_key> <wp:meta_key>_edit_last</wp:meta_key>
<wp:meta_value><![CDATA[1]]></wp:meta_value> <wp:meta_value><![CDATA[1]]></wp:meta_value>
</wp:postmeta> </wp:postmeta>
<wp:comment> <wp:comment>
<wp:comment_id>2</wp:comment_id> <wp:comment_id>2</wp:comment_id>
<wp:comment_author><![CDATA[admin]]></wp:comment_author> <wp:comment_author><![CDATA[admin]]></wp:comment_author>
<wp:comment_author_email>admin@example.com</wp:comment_author_email> <wp:comment_author_email>admin@example.com</wp:comment_author_email>
<wp:comment_author_url></wp:comment_author_url> <wp:comment_author_url>http://www.example.com/</wp:comment_author_url>
<wp:comment_author_IP>127.0.0.1</wp:comment_author_IP> <wp:comment_author_IP>127.0.0.1</wp:comment_author_IP>
<wp:comment_date>2011-05-21 12:26:24</wp:comment_date> <wp:comment_date>2011-05-21 12:26:24</wp:comment_date>
<wp:comment_date_gmt>2011-05-21 12:26:24</wp:comment_date_gmt> <wp:comment_date_gmt>2011-05-21 12:26:24</wp:comment_date_gmt>
@ -201,7 +203,7 @@ Nulla semper euismod arcu. Suspendisse egestas, erat a consectetur dapibus, fel
<wp:comment_id>3</wp:comment_id> <wp:comment_id>3</wp:comment_id>
<wp:comment_author><![CDATA[admin]]></wp:comment_author> <wp:comment_author><![CDATA[admin]]></wp:comment_author>
<wp:comment_author_email>admin@example.com</wp:comment_author_email> <wp:comment_author_email>admin@example.com</wp:comment_author_email>
<wp:comment_author_url>http://www.example.com/</wp:comment_author_url> <wp:comment_author_url>http://www.example.com/</wp:comment_author_url>
<wp:comment_author_IP>127.0.0.1</wp:comment_author_IP> <wp:comment_author_IP>127.0.0.1</wp:comment_author_IP>
<wp:comment_date>2011-05-21 12:26:30</wp:comment_date> <wp:comment_date>2011-05-21 12:26:30</wp:comment_date>
<wp:comment_date_gmt>2011-05-21 12:26:30</wp:comment_date_gmt> <wp:comment_date_gmt>2011-05-21 12:26:30</wp:comment_date_gmt>
@ -278,5 +280,36 @@ Class aptent taciti sociosqu ad litora torquent per conubia nostra, per incepto
<wp:meta_value><![CDATA[default]]></wp:meta_value> <wp:meta_value><![CDATA[default]]></wp:meta_value>
</wp:postmeta> </wp:postmeta>
</item> </item>
<item>
<title>200px-Tux.svg</title>
<link>http://localhost/wordpress/?attachment_id=13</link>
<pubDate>Sun, 05 Jun 2011 15:26:51 +0000</pubDate>
<dc:creator>admin</dc:creator>
<guid isPermaLink="false">http://localhost/wordpress/wp-content/uploads/2011/05/200px-Tux.svg_.png</guid>
<description>Tux, the Linux mascot</description>
<content:encoded><![CDATA[]]></content:encoded>
<excerpt:encoded><![CDATA[]]></excerpt:encoded>
<wp:post_id>13</wp:post_id>
<wp:post_date>2011-06-05 15:26:51</wp:post_date>
<wp:post_date_gmt>2011-06-05 15:26:51</wp:post_date_gmt>
<wp:comment_status>open</wp:comment_status>
<wp:ping_status>open</wp:ping_status>
<wp:post_name>200px-tux-svg</wp:post_name>
<wp:status>inherit</wp:status>
<wp:post_parent>6</wp:post_parent>
<wp:menu_order>0</wp:menu_order>
<wp:post_type>attachment</wp:post_type>
<wp:post_password></wp:post_password>
<wp:is_sticky>0</wp:is_sticky>
<wp:attachment_url>http://localhost/wordpress/wp-content/uploads/2011/05/200px-Tux.svg_.png</wp:attachment_url>
<wp:postmeta>
<wp:meta_key>_wp_attached_file</wp:meta_key>
<wp:meta_value><![CDATA[2011/05/200px-Tux.svg_.png]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key>_wp_attachment_metadata</wp:meta_key>
<wp:meta_value><![CDATA[a:6:{s:5:"width";s:3:"200";s:6:"height";s:3:"235";s:14:"hwstring_small";s:22:"height='96' width='81'";s:4:"file";s:26:"2011/05/200px-Tux.svg_.png";s:5:"sizes";a:2:{s:9:"thumbnail";a:3:{s:4:"file";s:26:"200px-Tux.svg_-150x150.png";s:5:"width";s:3:"150";s:6:"height";s:3:"150";}s:14:"post-thumbnail";a:3:{s:4:"file";s:26:"200px-Tux.svg_-200x198.png";s:5:"width";s:3:"200";s:6:"height";s:3:"198";}}s:10:"image_meta";a:10:{s:8:"aperture";s:1:"0";s:6:"credit";s:0:"";s:6:"camera";s:0:"";s:7:"caption";s:0:"";s:17:"created_timestamp";s:1:"0";s:9:"copyright";s:0:"";s:12:"focal_length";s:1:"0";s:3:"iso";s:1:"0";s:13:"shutter_speed";s:1:"0";s:5:"title";s:0:"";}}]]></wp:meta_value>
</wp:postmeta>
</item>
</channel> </channel>
</rss> </rss>

View File

@ -0,0 +1,10 @@
require 'spec_helper'
describe Refinery::WordPress::Attachment, :type => :model do
let(:attachment) { test_dump.attachments.first }
specify { attachment.title.should == '200px-Tux.svg' }
specify { attachment.description.should == 'Tux, the Linux mascot' }
specify { attachment.url.should == 'http://localhost/wordpress/wp-content/uploads/2011/05/200px-Tux.svg_.png' }
specify { attachment.post_date.should == DateTime.new(2011, 6, 5, 15, 26, 51) }
end

View File

@ -3,8 +3,8 @@ require 'spec_helper'
describe Refinery::WordPress::Author, :type => :model do describe Refinery::WordPress::Author, :type => :model do
let(:author) { test_dump.authors.first } let(:author) { test_dump.authors.first }
it { author.login.should == 'admin' } specify { author.login.should == 'admin' }
it { author.email.should == 'admin@example.com' } specify { author.email.should == 'admin@example.com' }
describe "#to_refinery" do describe "#to_refinery" do
before do before do

View File

@ -66,4 +66,10 @@ describe Refinery::WordPress::Dump, :type => :model do
dump.posts(true).should have(2).posts dump.posts(true).should have(2).posts
end end
end end
describe "#attachments" do
it "should return all attachments" do
dump.attachments.should have(1).attachment
end
end
end end