wp2tumblr 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Guardfile +2 -1
- data/README.md +8 -3
- data/bin/wp2tumblr +1 -0
- data/lib/wp2tumblr.rb +1 -0
- data/lib/wp2tumblr/version.rb +1 -1
- data/lib/wp2tumblr/wordpress.rb +16 -1
- data/spec/wp2tumblr/wordpress_format.xml +2 -2
- data/spec/wp2tumblr_spec.rb +8 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dcbe7618bf9a026e696e9e26e198be786a537686
|
4
|
+
data.tar.gz: eee95d425a089d79e51343b26ef049947e2d2d45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d49c3d3ffb7bbff1d1804a998867d8548eed64c5d1936d583d4a143ce4956ef80af6be6d4dc230441ed55d4baa4427036508de4fbb3e2bb641095cbb16959bc
|
7
|
+
data.tar.gz: 4e6481f7739e05fd3da1ea5e7f2af207255da4bd41d2f83e27c1dea1d3ea6e8512be87b39f11166a3128459ff7a3214092f6a0a1737996864f0fd6b0e200d3e0
|
data/Guardfile
CHANGED
@@ -4,7 +4,8 @@
|
|
4
4
|
guard 'rspec' do
|
5
5
|
watch(%r{^spec/.+_spec\.rb$})
|
6
6
|
watch(%r{^wp2tumblr/*.rb$})
|
7
|
-
watch(%r{^lib/(.+)\.rb$})
|
7
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
8
|
+
watch(%r{^lib/wp2tumblr/(.+)\.rb$})
|
8
9
|
watch('spec/spec_helper.rb') { "spec" }
|
9
10
|
end
|
10
11
|
|
data/README.md
CHANGED
@@ -7,12 +7,12 @@ A CLI tool to import wordpress xml files into Tumblr via the Tumblr api
|
|
7
7
|
$ gem install wp2tumblr
|
8
8
|
|
9
9
|
## Usage
|
10
|
-
This gem is dependant on the `~/.tumblr` config file that the [tumblr_client gem](
|
10
|
+
This gem is dependant on the `~/.tumblr` config file that the [tumblr_client gem](https://github.com/tumblr/tumblr_client) generates. If you have not previously installed the [tumblr_client gem](https://github.com/tumblr/tumblr_client) and have run the [irb console setup](https://github.com/tumblr/tumblr_client#the-irb-console) you will be prompted to do so upon first use of this gem.
|
11
11
|
|
12
12
|
### Import
|
13
13
|
Once you have completed the config process simply run the following command:
|
14
14
|
|
15
|
-
|
15
|
+
$ wp2tumblr text -b myblog.tumblr.com -f ~/path/to/my/wordpress/export/file
|
16
16
|
|
17
17
|
the `text` command tells `wp2tumblr` to import all of the wordpress posts as type "text". Currently "text" is the only option. Since there is no dirrect correlation between wordpress post types and Tumblr post types, text is the default. Future iterations (pull requests are welcome), will allow you to import different Tumblr post types.
|
18
18
|
|
@@ -34,7 +34,12 @@ Once you have your application token's run:
|
|
34
34
|
|
35
35
|
$ tumblr
|
36
36
|
|
37
|
-
You will be prompted to enter your OAuth Consumer key, then your OAuth Consumer Secret. The [tumblr_client gem]('https://github.com/tumblr/tumblr_client') will then output an authorize url, copy and paste that into your browser and your callback url will receive the `oauth_verifier` post containing the OAuth Verifier token.
|
37
|
+
You will be prompted to enter your OAuth Consumer key, then your OAuth Consumer Secret. The [tumblr_client gem]('https://github.com/tumblr/tumblr_client') will then output an authorize url, copy and paste that into your browser and your callback url will receive the `oauth_verifier` post containing the OAuth Verifier token.
|
38
|
+
|
39
|
+
|
40
|
+
## Changelog
|
41
|
+
- **Version 0.1.0:** Minor Feature, added Base64 encoding of images
|
42
|
+
- **Version 0.0.1:** Initial Release
|
38
43
|
|
39
44
|
## Contributing
|
40
45
|
|
data/bin/wp2tumblr
CHANGED
data/lib/wp2tumblr.rb
CHANGED
data/lib/wp2tumblr/version.rb
CHANGED
data/lib/wp2tumblr/wordpress.rb
CHANGED
@@ -20,7 +20,7 @@ module Wp2tumblr
|
|
20
20
|
items = get_file_contents(file)
|
21
21
|
@posts = []
|
22
22
|
items.to_enum.with_index(0) do |item, i|
|
23
|
-
@posts[i] = {title: item.at_xpath("title").text, content: item.at_xpath("content:encoded").text, created_at: item.at_xpath("pubDate").text}
|
23
|
+
@posts[i] = {title: item.at_xpath("title").text, content: parse_images(item.at_xpath("content:encoded").text), created_at: item.at_xpath("pubDate").text}
|
24
24
|
end
|
25
25
|
@posts
|
26
26
|
end
|
@@ -87,6 +87,21 @@ module Wp2tumblr
|
|
87
87
|
@meta
|
88
88
|
end
|
89
89
|
|
90
|
+
def self.parse_images(post_content)
|
91
|
+
html = Nokogiri::HTML(post_content)
|
92
|
+
html.css("img").each do |image|
|
93
|
+
begin
|
94
|
+
encoded_image = Base64.encode64(open(image['src']) {|io| io.read})
|
95
|
+
rescue
|
96
|
+
puts "Error processing image: #{$!}, #{image['src']}"
|
97
|
+
next
|
98
|
+
end
|
99
|
+
file_extension = image['src'][/\.[^.]*$/].split('.')[1]
|
100
|
+
image['src'] = "data:image/#{file_extension};base64,#{encoded_image}"
|
101
|
+
end
|
102
|
+
html
|
103
|
+
end
|
104
|
+
|
90
105
|
private
|
91
106
|
|
92
107
|
def self.get_file_contents(file)
|
@@ -52,7 +52,7 @@
|
|
52
52
|
<dc:creator>testuser</dc:creator>
|
53
53
|
<guid isPermaLink="false">http://testblog.com/?p=3199</guid>
|
54
54
|
<description></description>
|
55
|
-
<content:encoded><![CDATA[test content]]></content:encoded>
|
55
|
+
<content:encoded><![CDATA[<p>test content</p><div class="center"><img src="http://placekitten.com.s3.amazonaws.com/homepage-samples/200/287.jpg" alt=""/></div><p>test content</p><div class="center"><img src="http://placekitten.com.s3.amazonaws.com/homepage-samples/200/287.jpg" alt=""/></div>]]></content:encoded>
|
56
56
|
<excerpt:encoded><![CDATA[]]></excerpt:encoded>
|
57
57
|
<wp:post_id>3199</wp:post_id>
|
58
58
|
<wp:post_date>2013-03-01 07:59:29</wp:post_date>
|
@@ -113,7 +113,7 @@
|
|
113
113
|
<dc:creator>testuser</dc:creator>
|
114
114
|
<guid isPermaLink="false">http://testblog.com/?p=3199</guid>
|
115
115
|
<description></description>
|
116
|
-
<content:encoded><![CDATA[test content]]></content:encoded>
|
116
|
+
<content:encoded><![CDATA[test content <div class="center"><img src="http://placehold.it/120x120" alt=""/></div>]]></content:encoded>
|
117
117
|
<excerpt:encoded><![CDATA[]]></excerpt:encoded>
|
118
118
|
<wp:post_id>3199</wp:post_id>
|
119
119
|
<wp:post_date>2013-03-01 07:59:29</wp:post_date>
|
data/spec/wp2tumblr_spec.rb
CHANGED
@@ -49,6 +49,14 @@ describe Wp2tumblr::Wordpress do
|
|
49
49
|
parsed_params[0][:comments][0][:author].should eq("Test Commenter")
|
50
50
|
end
|
51
51
|
end
|
52
|
+
|
53
|
+
describe ".parse_images" do
|
54
|
+
it "Encodes images as base64" do
|
55
|
+
posts = Wp2tumblr::Wordpress.parse_xml(file, :posts)
|
56
|
+
post = posts[0][:content]
|
57
|
+
Wp2tumblr::Wordpress.parse_images(post).to_s.should include('base64')
|
58
|
+
end
|
59
|
+
end
|
52
60
|
end
|
53
61
|
|
54
62
|
describe Wp2tumblr::TumblrClient do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wp2tumblr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jonlunsford
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oauth
|