wp_conversion 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 327b7f9634c689d1232a2e0594c26c5e9c949f68
4
+ data.tar.gz: 6dd964531a5d61b3aa8ac3fe7fde947fa72a7ddb
5
+ SHA512:
6
+ metadata.gz: 7ddb96ef601a3c71f4a6efbcc6162be44a2089852d588c5c601786dca2dc252e01471a9b95b28e046e27be51e84723d97c4cfe4d0238dbb964c51ffaf77eaa9b
7
+ data.tar.gz: 5dc68ed4eaf4a5bebe5eec78038c55a7a8d03ecd08333002d447b12284ead759c47e0f6becf6cd929aa64e357e2a0ddbda541f04996365147cacccba56340a9b
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ .DS_Store
2
+ results.html
3
+ pkg
4
+ html
5
+ tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in wp_conversion.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,117 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ wp_conversion (0.1.0)
5
+ activesupport
6
+ html_massage
7
+ methadone (~> 1.3.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activesupport (4.0.0)
13
+ i18n (~> 0.6, >= 0.6.4)
14
+ minitest (~> 4.2)
15
+ multi_json (~> 1.3)
16
+ thread_safe (~> 0.1)
17
+ tzinfo (~> 0.3.37)
18
+ aruba (0.5.3)
19
+ childprocess (>= 0.3.6)
20
+ cucumber (>= 1.1.1)
21
+ rspec-expectations (>= 2.7.0)
22
+ atomic (1.1.10)
23
+ builder (3.2.2)
24
+ childprocess (0.3.9)
25
+ ffi (~> 1.0, >= 1.0.11)
26
+ coderay (1.0.9)
27
+ cucumber (1.3.5)
28
+ builder (>= 2.1.2)
29
+ diff-lcs (>= 1.1.3)
30
+ gherkin (~> 2.12.0)
31
+ multi_json (~> 1.7.5)
32
+ multi_test (>= 0.0.2)
33
+ diff-lcs (1.2.4)
34
+ ffi (1.9.0)
35
+ formatador (0.2.4)
36
+ gherkin (2.12.0)
37
+ multi_json (~> 1.3)
38
+ guard (1.8.1)
39
+ formatador (>= 0.2.4)
40
+ listen (>= 1.0.0)
41
+ lumberjack (>= 1.0.2)
42
+ pry (>= 0.9.10)
43
+ thor (>= 0.14.6)
44
+ guard-cucumber (1.4.0)
45
+ cucumber (>= 1.2.0)
46
+ guard (>= 1.1.0)
47
+ guard-rspec (3.0.2)
48
+ guard (>= 1.8)
49
+ rspec (~> 2.13)
50
+ html_massage (0.2.1)
51
+ nokogiri (>= 1.4)
52
+ rest-client (>= 1.6)
53
+ reverse_markdown (>= 0.4)
54
+ sanitize (>= 2.0)
55
+ thor
56
+ i18n (0.6.4)
57
+ json (1.8.0)
58
+ listen (1.2.2)
59
+ rb-fsevent (>= 0.9.3)
60
+ rb-inotify (>= 0.9)
61
+ rb-kqueue (>= 0.2)
62
+ lumberjack (1.0.4)
63
+ methadone (1.3.0)
64
+ bundler
65
+ method_source (0.8.2)
66
+ mime-types (1.23)
67
+ mini_portile (0.5.1)
68
+ minitest (4.7.5)
69
+ multi_json (1.7.7)
70
+ multi_test (0.0.2)
71
+ nokogiri (1.6.0)
72
+ mini_portile (~> 0.5.0)
73
+ pry (0.9.12.2)
74
+ coderay (~> 1.0.5)
75
+ method_source (~> 0.8)
76
+ slop (~> 3.4)
77
+ rake (10.1.0)
78
+ rb-fsevent (0.9.3)
79
+ rb-inotify (0.9.0)
80
+ ffi (>= 0.5.0)
81
+ rb-kqueue (0.2.0)
82
+ ffi (>= 0.5.0)
83
+ rdoc (4.0.1)
84
+ json (~> 1.4)
85
+ rest-client (1.6.7)
86
+ mime-types (>= 1.16)
87
+ reverse_markdown (0.4.4)
88
+ nokogiri
89
+ rspec (2.14.1)
90
+ rspec-core (~> 2.14.0)
91
+ rspec-expectations (~> 2.14.0)
92
+ rspec-mocks (~> 2.14.0)
93
+ rspec-core (2.14.4)
94
+ rspec-expectations (2.14.0)
95
+ diff-lcs (>= 1.1.3, < 2.0)
96
+ rspec-mocks (2.14.1)
97
+ sanitize (2.0.6)
98
+ nokogiri (>= 1.4.4)
99
+ slop (3.4.6)
100
+ thor (0.18.1)
101
+ thread_safe (0.1.2)
102
+ atomic
103
+ tzinfo (0.3.37)
104
+
105
+ PLATFORMS
106
+ ruby
107
+
108
+ DEPENDENCIES
109
+ aruba
110
+ bundler (~> 1.3)
111
+ guard
112
+ guard-cucumber
113
+ guard-rspec
114
+ rake
115
+ rdoc
116
+ rspec
117
+ wp_conversion!
data/Guardfile ADDED
@@ -0,0 +1,16 @@
1
+ # Guardfile for wp_conversion gem
2
+
3
+ # More info at https://github.com/guard/guard#readme
4
+
5
+ guard 'cucumber', cli: '-c --format pretty --strict' do
6
+ watch(%r{^features/.+\.feature$})
7
+ watch(%r{^features/support/.+$}) { 'features' }
8
+ watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
9
+ end
10
+
11
+ guard :rspec, cli: '-c --format documentation' do
12
+ watch(%r{^spec/.+_spec\.rb$})
13
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
14
+ watch('spec/spec_helper.rb') { "spec" }
15
+ end
16
+
data/LICENSE.txt ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2013 YOUR NAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # WpConversion
2
+
3
+ Convert a Wordpress XML export into pages suitable for a jekyll site
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'wp_conversion'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install wp_conversion
18
+
19
+ ## Usage
20
+
21
+ $ wp_conversion WPExport.xml
22
+
23
+ This will create 3 directories: `posts`, `pages`, and `attachments`
24
+ that will contain markdown files reflecting the items in the wordpress
25
+ export. The posts and pages will be converted such that a site can be
26
+ generated via jekyll.
27
+
28
+ * Posts have the YYYY-MM-DD-title.markdown format.
29
+ * Pages just have title.markdown.
30
+ * Files will have the appropriate YAML header for jekyll processing.
31
+ * Attachments will be YAML files with the link to the attachment.
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,66 @@
1
+ def dump_load_path
2
+ puts $LOAD_PATH.join("\n")
3
+ found = nil
4
+ $LOAD_PATH.each do |path|
5
+ if File.exists?(File.join(path,"rspec"))
6
+ puts "Found rspec in #{path}"
7
+ if File.exists?(File.join(path,"rspec","core"))
8
+ puts "Found core"
9
+ if File.exists?(File.join(path,"rspec","core","rake_task"))
10
+ puts "Found rake_task"
11
+ found = path
12
+ else
13
+ puts "!! no rake_task"
14
+ end
15
+ else
16
+ puts "!!! no core"
17
+ end
18
+ end
19
+ end
20
+ if found.nil?
21
+ puts "Didn't find rspec/core/rake_task anywhere"
22
+ else
23
+ puts "Found in #{path}"
24
+ end
25
+ end
26
+ require 'bundler'
27
+ require 'rake/clean'
28
+
29
+ begin
30
+ require 'rspec/core/rake_task'
31
+ rescue LoadError
32
+ dump_load_path
33
+ raise
34
+ end
35
+
36
+ require 'cucumber'
37
+ require 'cucumber/rake/task'
38
+ gem 'rdoc' # we need the installed RDoc gem, not the system one
39
+ require 'rdoc/task'
40
+
41
+ include Rake::DSL
42
+
43
+ Bundler::GemHelper.install_tasks
44
+
45
+
46
+ RSpec::Core::RakeTask.new do |t|
47
+ # Put spec opts in a file named .rspec in root
48
+ end
49
+
50
+
51
+ CUKE_RESULTS = 'results.html'
52
+ CLEAN << CUKE_RESULTS
53
+ Cucumber::Rake::Task.new(:features) do |t|
54
+ t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty --no-source -x"
55
+ t.fork = false
56
+ end
57
+
58
+ Rake::RDocTask.new do |rd|
59
+
60
+ rd.main = "README.rdoc"
61
+
62
+ rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
63
+ end
64
+
65
+ task :default => [:spec,:features]
66
+
data/bin/wp_conversion ADDED
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'methadone'
5
+ require 'wp_conversion'
6
+
7
+ class App
8
+ include Methadone::Main
9
+ include Methadone::CLILogging
10
+ include WpConversion
11
+
12
+ main do |wp_xml|
13
+ begin
14
+
15
+ logger.level=Logger::WARN
16
+ logger.level=Logger::INFO if options[:verbose]
17
+ logger.error_level=Logger::DEBUG if options[:debug]
18
+ debug "options: #{options}"
19
+ debug "wp_xml: #{wp_xml}"
20
+
21
+ info "Reading #{wp_xml}"
22
+ items = WpConversion.xml_to_hash(File.read(wp_xml))['rss']['channel']['item']
23
+ info "#{items.size} items to save"
24
+
25
+ items.each do |item|
26
+ info "Saving item #{item['title']} as #{item['post_type']}"
27
+ if options[:yaml]
28
+ info "Saving as yaml"
29
+ WpConversion.save_an_item(item,:yaml)
30
+ end
31
+ info "Converting to markdown"
32
+ WpConversion.save_an_item(item,:markdown)
33
+ end
34
+
35
+ rescue Exception => e
36
+ error "#{e} (#{e.class})"
37
+ debug "Backtrace: \n" + e.backtrace.join("\n")
38
+ end
39
+
40
+
41
+ end
42
+
43
+ description "Convert Wordpress xml export to markdown files suitable for jekyll site"
44
+
45
+ # on("--flag VAL","Some flag")
46
+ # options[flag] will contain VAL
47
+
48
+ # on("--[no-]switch","Some switch")
49
+ on("--verbose","Make wp_conversion chatty")
50
+ on("--debug", "Turn on debug mode")
51
+ on("--yaml", "Save items as yaml files as well")
52
+
53
+ arg :wp_xml, "Wordpress xml export file."
54
+
55
+ # Make an argument optional
56
+ # arg :optional_arg, :optional
57
+
58
+ version WpConversion::VERSION
59
+
60
+ # use_log_level_option
61
+
62
+ go!
63
+ end
@@ -0,0 +1,50 @@
1
+ Feature: convert a wordpress export to markdown
2
+ In order to convert a wordpress export to markdown
3
+ I will need run the conversion script
4
+
5
+ Background:
6
+ Given a test export xml file
7
+
8
+ Scenario: run the conversion script
9
+ When I successfully run "wp_conversion" with the test file
10
+ Then the exit status should be 0
11
+ And the output should match /^$/
12
+ And the following directories should exist:
13
+ |pages|
14
+ |posts|
15
+ |attachments|
16
+ And the following files should exist:
17
+ | posts/2010-05-03-introduction.markdown |
18
+ | posts/2010-05-03-thematic.markdown |
19
+ | posts/2010-05-28-a-problem-with-partial-lines.markdown |
20
+ | posts/2010-05-28-buddymatic.markdown |
21
+ | posts/2010-05-29-another-problem-cant-set-background-colour-on-menu-bounding-box.markdown |
22
+ | posts/2013-07-06-this-site-is-going-away.markdown |
23
+ | pages/a-haiku.markdown |
24
+ | pages/a-little-child.markdown |
25
+ | pages/a-new-poem.markdown |
26
+ | pages/and-you-learn.markdown |
27
+ | pages/be-careful-what-you-say-the-power-of-words.markdown |
28
+
29
+ Scenario: save the items as yaml files
30
+ When I successfully run "wp_conversion" with the "yaml" switch and the test file
31
+ Then the exit status should be 0
32
+ And the output should match /^$/
33
+ And the following directories should exist:
34
+ |pages|
35
+ |posts|
36
+ |attachments|
37
+ And the following files should exist:
38
+ | posts/2010-05-03-introduction.yaml |
39
+ | posts/2010-05-03-thematic.yaml |
40
+ | posts/2010-05-28-a-problem-with-partial-lines.yaml |
41
+ | posts/2010-05-28-buddymatic.yaml |
42
+ | posts/2010-05-29-another-problem-cant-set-background-colour-on-menu-bounding-box.yaml |
43
+ | posts/2013-07-06-this-site-is-going-away.yaml |
44
+ | pages/a-haiku.yaml |
45
+ | pages/a-little-child.yaml |
46
+ | pages/a-new-poem.yaml |
47
+ | pages/and-you-learn.yaml |
48
+ | pages/be-careful-what-you-say-the-power-of-words.yaml |
49
+
50
+
@@ -0,0 +1,8 @@
1
+ Given(/^a test export xml file$/) do
2
+ $test_xml_file = File.join(File.expand_path("../../support",__FILE__),'test_data','test.xml')
3
+ File.exist?($test_xml_file)
4
+ end
5
+
6
+ When(/^I successfully run "(.*?)" with(?: the "(.*?)" switch and)? the test file$/) do |arg1, switch|
7
+ step("I successfully run `#{arg1} --#{switch} #{$test_xml_file}`")
8
+ end
@@ -0,0 +1 @@
1
+ puts File.join(File.expand_path("../../support",__FILE__),'test_data','test.xml')
@@ -0,0 +1 @@
1
+ # Put your step definitions here
@@ -0,0 +1,16 @@
1
+ require 'aruba/cucumber'
2
+ require 'methadone/cucumber'
3
+
4
+ ENV['PATH'] = "#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
5
+ LIB_DIR = File.join(File.expand_path(File.dirname(__FILE__)),'..','..','lib')
6
+
7
+ Before do
8
+ # Using "announce" causes massive warnings on 1.9.2
9
+ @puts = true
10
+ @original_rubylib = ENV['RUBYLIB']
11
+ ENV['RUBYLIB'] = LIB_DIR + File::PATH_SEPARATOR + ENV['RUBYLIB'].to_s
12
+ end
13
+
14
+ After do
15
+ ENV['RUBYLIB'] = @original_rubylib
16
+ end