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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f59412e9fec07818d51b71a5954b774bf9783f7d
4
- data.tar.gz: cb0a03a3babfd042d113cac0cd66cbb82dd8157f
3
+ metadata.gz: dcbe7618bf9a026e696e9e26e198be786a537686
4
+ data.tar.gz: eee95d425a089d79e51343b26ef049947e2d2d45
5
5
  SHA512:
6
- metadata.gz: 3ac975a1b166332f4b622a9bbf8d4639282138501b9e86fe9811bf6a81fe1add62f8b3fd730b7a4fcc359dd19d1a093e31f6abe5b944a67721c35cab72622188
7
- data.tar.gz: a4a9bf34d0cf586f8f71442589829b8a413386b2f162d2a7f832edf31ca34d759f08c45a7ce21c4961b8aee8209f23f5555c44820ada8de03d46b2fb9112c1c3
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$}) { |m| "spec/lib/#{m[1]}_spec.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]('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.
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
- $ wp2tumblr text -b myblog.tumblr.com -f ~/path/to/my/wordpress/export/file
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
@@ -56,6 +56,7 @@ if File.exists?(tumblr_config_path)
56
56
  end
57
57
 
58
58
  else
59
+ puts ""
59
60
  puts "You need to configure your Tumblr api credentials."
60
61
  puts "For more info see: https://github.com/tumblr/tumblr_client#the-irb-console"
61
62
  puts "run 'tumblr' then try again"
data/lib/wp2tumblr.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require "open-uri"
1
2
  require "wp2tumblr/wordpress"
2
3
  require "wp2tumblr/tumblr_client"
3
4
 
@@ -1,3 +1,3 @@
1
1
  module Wp2tumblr
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -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>
@@ -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.1
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-17 00:00:00.000000000 Z
11
+ date: 2013-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oauth