wordpress-wxr 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +0 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/wordpress/wxr.rb +50 -0
- data/lib/wordpress/wxr/attachment.rb +12 -0
- data/lib/wordpress/wxr/attachments.rb +31 -0
- data/lib/wordpress/wxr/author.rb +39 -0
- data/lib/wordpress/wxr/authors.rb +35 -0
- data/lib/wordpress/wxr/categories.rb +35 -0
- data/lib/wordpress/wxr/category.rb +29 -0
- data/lib/wordpress/wxr/comment.rb +41 -0
- data/lib/wordpress/wxr/element.rb +13 -0
- data/lib/wordpress/wxr/item.rb +110 -0
- data/lib/wordpress/wxr/page.rb +8 -0
- data/lib/wordpress/wxr/pages.rb +31 -0
- data/lib/wordpress/wxr/post.rb +8 -0
- data/lib/wordpress/wxr/posts.rb +31 -0
- data/lib/wordpress/wxr/tag.rb +25 -0
- data/lib/wordpress/wxr/tags.rb +35 -0
- data/lib/wordpress/wxr/version.rb +5 -0
- data/wordpress-wxr.gemspec +27 -0
- metadata +141 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3a6e12c55a5574216b7300de4ac2d1e533654527
|
4
|
+
data.tar.gz: 73272e1c15e8bb66364e6f7ccbe0eac645cf6df2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4adbbf58d4272d8515858cc824e1e9c30d6d4b0f219e04c531901a08214242f3b460bb2afa3c4124011c82918aa991f3234eed0b2ba8d73d7c71ed45f649ce54
|
7
|
+
data.tar.gz: d98e0f54758da12b6c0eb98cdb92b968777632989cbe3224d68a667afca9014b4fd2a9d1d282805acdcdecbe13d77b43ffee5b81730a818fdab55221bcf0aff8
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at rjk@wormbytes.ca. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 ePublishing, Inc.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
File without changes
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "wordpress/xml/parser"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
require 'wordpress/wxr/attachments'
|
4
|
+
require 'wordpress/wxr/authors'
|
5
|
+
require 'wordpress/wxr/categories'
|
6
|
+
require 'wordpress/wxr/pages'
|
7
|
+
require 'wordpress/wxr/posts'
|
8
|
+
require 'wordpress/wxr/tags'
|
9
|
+
require 'wordpress/wxr/version'
|
10
|
+
|
11
|
+
module Wordpress
|
12
|
+
class WXR
|
13
|
+
def self.parse(path_to_xml)
|
14
|
+
file = File.open(path_to_xml)
|
15
|
+
new(::Nokogiri::XML(file.read.delete("\u0004")))
|
16
|
+
end
|
17
|
+
|
18
|
+
attr_reader :document
|
19
|
+
private :document
|
20
|
+
|
21
|
+
def initialize(document)
|
22
|
+
@document = document
|
23
|
+
freeze
|
24
|
+
end
|
25
|
+
|
26
|
+
def attachments
|
27
|
+
Attachments.new(document, self)
|
28
|
+
end
|
29
|
+
|
30
|
+
def authors
|
31
|
+
Authors.new(document, self)
|
32
|
+
end
|
33
|
+
|
34
|
+
def categories
|
35
|
+
Categories.new(document, self)
|
36
|
+
end
|
37
|
+
|
38
|
+
def pages
|
39
|
+
Pages.new(document, self)
|
40
|
+
end
|
41
|
+
|
42
|
+
def posts
|
43
|
+
Posts.new(document, self)
|
44
|
+
end
|
45
|
+
|
46
|
+
def tags
|
47
|
+
Tags.new(document, self)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'wordpress/wxr/attachment'
|
2
|
+
|
3
|
+
module Wordpress
|
4
|
+
class WXR
|
5
|
+
class Attachments
|
6
|
+
include Enumerable
|
7
|
+
|
8
|
+
attr_reader :document, :wxr
|
9
|
+
private :document, :wxr
|
10
|
+
|
11
|
+
def initialize(document, wxr)
|
12
|
+
@document = document
|
13
|
+
@wxr = wxr
|
14
|
+
end
|
15
|
+
|
16
|
+
def each
|
17
|
+
return enum_for(:each) unless block_given?
|
18
|
+
|
19
|
+
nodes.each do |node|
|
20
|
+
yield Attachment.new(node, wxr)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def nodes
|
27
|
+
document.xpath("//item[wp:post_type = 'attachment']")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'wordpress/wxr/element'
|
2
|
+
require 'email_address'
|
3
|
+
|
4
|
+
module Wordpress
|
5
|
+
class WXR
|
6
|
+
class Author < Element
|
7
|
+
def id
|
8
|
+
Integer(node.xpath('wp:author_id').text)
|
9
|
+
end
|
10
|
+
|
11
|
+
def login
|
12
|
+
node.xpath('wp:author_login').text
|
13
|
+
end
|
14
|
+
|
15
|
+
def email
|
16
|
+
EmailAddress.new(node.xpath('wp:author_email').text)
|
17
|
+
end
|
18
|
+
|
19
|
+
def display_name
|
20
|
+
node.xpath('wp:author_display_name').text
|
21
|
+
end
|
22
|
+
|
23
|
+
def first_name
|
24
|
+
node.xpath('wp:author_first_name').text
|
25
|
+
end
|
26
|
+
|
27
|
+
def last_name
|
28
|
+
node.xpath('wp:author_last_name').text
|
29
|
+
end
|
30
|
+
|
31
|
+
def ==(other)
|
32
|
+
self.class == other.class &&
|
33
|
+
id == other.id &&
|
34
|
+
login == other.login
|
35
|
+
end
|
36
|
+
alias eql? ==
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'wordpress/wxr/author'
|
2
|
+
|
3
|
+
module Wordpress
|
4
|
+
class WXR
|
5
|
+
class Authors
|
6
|
+
include Enumerable
|
7
|
+
|
8
|
+
attr_reader :document, :wxr
|
9
|
+
private :document, :wxr
|
10
|
+
|
11
|
+
def initialize(document, wxr)
|
12
|
+
@document = document
|
13
|
+
@wxr = wxr
|
14
|
+
end
|
15
|
+
|
16
|
+
def each
|
17
|
+
return enum_for(:each) unless block_given?
|
18
|
+
|
19
|
+
nodes.each do |node|
|
20
|
+
yield Author.new(node, wxr)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def find_by(login:)
|
25
|
+
each.find { |author| author.login == login }
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def nodes
|
31
|
+
document.xpath('//wp:author')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'wordpress/wxr/category'
|
2
|
+
|
3
|
+
module Wordpress
|
4
|
+
class WXR
|
5
|
+
class Categories
|
6
|
+
include Enumerable
|
7
|
+
|
8
|
+
attr_reader :document, :wxr
|
9
|
+
private :document, :wxr
|
10
|
+
|
11
|
+
def initialize(document, wxr)
|
12
|
+
@document = document
|
13
|
+
@wxr = wxr
|
14
|
+
end
|
15
|
+
|
16
|
+
def each
|
17
|
+
return enum_for(:each) unless block_given?
|
18
|
+
|
19
|
+
nodes.each do |node|
|
20
|
+
yield Category.new(node, wxr)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def find_by(nicename:)
|
25
|
+
each.find { |category| category.nicename == nicename }
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def nodes
|
31
|
+
document.xpath('//wp:category')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'wordpress/wxr/element'
|
2
|
+
|
3
|
+
module Wordpress
|
4
|
+
class WXR
|
5
|
+
class Category < Element
|
6
|
+
def id
|
7
|
+
Integer(node.xpath('wp:term_id').text)
|
8
|
+
end
|
9
|
+
|
10
|
+
def nicename
|
11
|
+
node.xpath('wp:category_nicename').text
|
12
|
+
end
|
13
|
+
|
14
|
+
def parent
|
15
|
+
wxr.categories.find_by(nicename: node.xpath('wp:category_parent').text)
|
16
|
+
end
|
17
|
+
|
18
|
+
def name
|
19
|
+
node.xpath('wp:cat_name').text
|
20
|
+
end
|
21
|
+
|
22
|
+
def ==(other)
|
23
|
+
self.class == other.class &&
|
24
|
+
id == other.id
|
25
|
+
end
|
26
|
+
alias eql? ==
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'wordpress/wxr/element'
|
2
|
+
require 'email_address'
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
module Wordpress
|
6
|
+
class WXR
|
7
|
+
class Comment < Element
|
8
|
+
def author
|
9
|
+
node.xpath('wp:comment_author').text
|
10
|
+
end
|
11
|
+
|
12
|
+
def email
|
13
|
+
EmailAddress.new(node.xpath('wp:comment_author_email').text)
|
14
|
+
end
|
15
|
+
|
16
|
+
def url
|
17
|
+
URI(node.xpath('wp:comment_author_url').text)
|
18
|
+
end
|
19
|
+
|
20
|
+
def date
|
21
|
+
DateTime.parse(node.xpath('wp:comment_date').text)
|
22
|
+
end
|
23
|
+
|
24
|
+
def content
|
25
|
+
node.xpath('wp:comment_content').text
|
26
|
+
end
|
27
|
+
|
28
|
+
def approved?
|
29
|
+
node.xpath('wp:comment_approved').text.to_i == 1
|
30
|
+
end
|
31
|
+
|
32
|
+
def ==(other)
|
33
|
+
self.class == other.class &&
|
34
|
+
email == other.email &&
|
35
|
+
date == other.date &&
|
36
|
+
content == other.content
|
37
|
+
end
|
38
|
+
alias eql? ==
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'wordpress/wxr/element'
|
2
|
+
require 'wordpress/wxr/tag'
|
3
|
+
require 'wordpress/wxr/category'
|
4
|
+
# require 'wordpress/wxr/comments'
|
5
|
+
|
6
|
+
require 'date'
|
7
|
+
require 'uri'
|
8
|
+
|
9
|
+
module Wordpress
|
10
|
+
class WXR
|
11
|
+
class Item < Element
|
12
|
+
def title
|
13
|
+
node.xpath('title').text
|
14
|
+
end
|
15
|
+
|
16
|
+
def link
|
17
|
+
URI(node.xpath('link').text)
|
18
|
+
end
|
19
|
+
|
20
|
+
def creator
|
21
|
+
wxr.authors.find_by(login: node.xpath('dc:creator').text)
|
22
|
+
end
|
23
|
+
|
24
|
+
def guid
|
25
|
+
node.xpath('guid').text
|
26
|
+
end
|
27
|
+
|
28
|
+
def content
|
29
|
+
node.xpath('content:encoded').text
|
30
|
+
end
|
31
|
+
|
32
|
+
def excerpt
|
33
|
+
node.xpath('excerpt:encoded').text
|
34
|
+
end
|
35
|
+
|
36
|
+
def id
|
37
|
+
Integer(node.xpath('wp:post_id').text)
|
38
|
+
end
|
39
|
+
|
40
|
+
def posted_at
|
41
|
+
# Attempt to use the GMT post date since it includes a timezone.
|
42
|
+
# Failing that, use the post_date which will use the current timezone.
|
43
|
+
DateTime.parse(node.xpath('wp:post_date_gmt').text)
|
44
|
+
rescue ArgumentError
|
45
|
+
DateTime.parse node.xpath('wp:post_date').text
|
46
|
+
end
|
47
|
+
|
48
|
+
def comment_status
|
49
|
+
# TODO: `opened` or `closed`
|
50
|
+
node.xpath('wp:comment_status').text
|
51
|
+
end
|
52
|
+
|
53
|
+
def ping_status
|
54
|
+
node.xpath('wp:ping_status').text
|
55
|
+
end
|
56
|
+
|
57
|
+
def name
|
58
|
+
node.xpath('wp:post_name').text
|
59
|
+
end
|
60
|
+
|
61
|
+
def status
|
62
|
+
node.xpath('wp:status').text
|
63
|
+
end
|
64
|
+
|
65
|
+
def tags
|
66
|
+
# xml dump has "post_tag" for wordpress 3.1 and "tag" for 3.0
|
67
|
+
path = if node.xpath("category[@domain='post_tag']").count > 0
|
68
|
+
"category[@domain='post_tag']"
|
69
|
+
else
|
70
|
+
"category[@domain='tag']"
|
71
|
+
end
|
72
|
+
|
73
|
+
node.xpath(path).map do |tag_node|
|
74
|
+
wxr.tags.find_by(slug: tag_node['nicename'])
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def categories
|
79
|
+
node.xpath("category[@domain='category']").map do |cat|
|
80
|
+
wxr.categories.find_by(nicename: cat['nicename'])
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# def comments
|
85
|
+
# node.xpath('wp:comment').map do |comment_node|
|
86
|
+
# Comment.new(comment_node)
|
87
|
+
# end
|
88
|
+
# end
|
89
|
+
|
90
|
+
# TODO: status: publish, draft, pending, private, trash, inherit
|
91
|
+
def draft?
|
92
|
+
status != 'publish'
|
93
|
+
end
|
94
|
+
|
95
|
+
def published?
|
96
|
+
!draft?
|
97
|
+
end
|
98
|
+
|
99
|
+
def sticky?
|
100
|
+
!node.xpath('wp:is_sticky').text.to_i.zero?
|
101
|
+
end
|
102
|
+
|
103
|
+
def ==(other)
|
104
|
+
self.class == other.class &&
|
105
|
+
id == other.id
|
106
|
+
end
|
107
|
+
alias eql? ==
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'wordpress/wxr/page'
|
2
|
+
|
3
|
+
module Wordpress
|
4
|
+
class WXR
|
5
|
+
class Pages
|
6
|
+
include Enumerable
|
7
|
+
|
8
|
+
attr_reader :document, :wxr
|
9
|
+
private :document, :wxr
|
10
|
+
|
11
|
+
def initialize(document, wxr)
|
12
|
+
@document = document
|
13
|
+
@wxr = wxr
|
14
|
+
end
|
15
|
+
|
16
|
+
def each
|
17
|
+
return enum_for(:each) unless block_given?
|
18
|
+
|
19
|
+
nodes.each do |node|
|
20
|
+
yield Page.new(node, wxr)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def nodes
|
27
|
+
document.xpath("//item[wp:post_type = 'page']")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'wordpress/wxr/post'
|
2
|
+
|
3
|
+
module Wordpress
|
4
|
+
class WXR
|
5
|
+
class Posts
|
6
|
+
include Enumerable
|
7
|
+
|
8
|
+
attr_reader :document, :wxr
|
9
|
+
private :document, :wxr
|
10
|
+
|
11
|
+
def initialize(document, wxr)
|
12
|
+
@document = document
|
13
|
+
@wxr = wxr
|
14
|
+
end
|
15
|
+
|
16
|
+
def each
|
17
|
+
return enum_for(:each) unless block_given?
|
18
|
+
|
19
|
+
nodes.each do |node|
|
20
|
+
yield Post.new(node, wxr)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def nodes
|
27
|
+
document.xpath("//item[wp:post_type = 'post']")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'wordpress/wxr/element'
|
2
|
+
|
3
|
+
module Wordpress
|
4
|
+
class WXR
|
5
|
+
class Tag < Element
|
6
|
+
def id
|
7
|
+
Integer(node.xpath('wp:term_id').text)
|
8
|
+
end
|
9
|
+
|
10
|
+
def slug
|
11
|
+
node.xpath('wp:tag_slug').text
|
12
|
+
end
|
13
|
+
|
14
|
+
def name
|
15
|
+
node.xpath('wp:tag_name').text
|
16
|
+
end
|
17
|
+
|
18
|
+
def ==(other)
|
19
|
+
self.class == other.class &&
|
20
|
+
(name == other.name || id == other.id)
|
21
|
+
end
|
22
|
+
alias eql? ==
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'wordpress/wxr/tag'
|
2
|
+
|
3
|
+
module Wordpress
|
4
|
+
class WXR
|
5
|
+
class Tags
|
6
|
+
include Enumerable
|
7
|
+
|
8
|
+
attr_reader :document, :wxr
|
9
|
+
private :document, :wxr
|
10
|
+
|
11
|
+
def initialize(document, wxr)
|
12
|
+
@document = document
|
13
|
+
@wxr = wxr
|
14
|
+
end
|
15
|
+
|
16
|
+
def each
|
17
|
+
return enum_for(:each) unless block_given?
|
18
|
+
|
19
|
+
nodes.each do |node|
|
20
|
+
yield Tag.new(node, wxr)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def find_by(slug:)
|
25
|
+
each.find { |tag| tag.slug == slug }
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def nodes
|
31
|
+
document.xpath('//wp:tag')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'wordpress/wxr/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'wordpress-wxr'
|
8
|
+
spec.version = Wordpress::WXR::VERSION
|
9
|
+
spec.authors = ['ePublishing, inc.']
|
10
|
+
spec.email = ['development@ePublishing.com']
|
11
|
+
|
12
|
+
spec.summary = 'Parse a WordPress XML file into separate Ruby objects.'
|
13
|
+
spec.homepage = 'https://bitbucket.org/epub_dev/wordpress-wxr'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = 'exe'
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.12'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
24
|
+
|
25
|
+
spec.add_runtime_dependency 'email_address', '~> 0.1.3'
|
26
|
+
spec.add_runtime_dependency 'nokogiri'
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wordpress-wxr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ePublishing, inc.
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: email_address
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.1.3
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.1.3
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: nokogiri
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- development@ePublishing.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- CODE_OF_CONDUCT.md
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- bin/console
|
98
|
+
- bin/setup
|
99
|
+
- lib/wordpress/wxr.rb
|
100
|
+
- lib/wordpress/wxr/attachment.rb
|
101
|
+
- lib/wordpress/wxr/attachments.rb
|
102
|
+
- lib/wordpress/wxr/author.rb
|
103
|
+
- lib/wordpress/wxr/authors.rb
|
104
|
+
- lib/wordpress/wxr/categories.rb
|
105
|
+
- lib/wordpress/wxr/category.rb
|
106
|
+
- lib/wordpress/wxr/comment.rb
|
107
|
+
- lib/wordpress/wxr/element.rb
|
108
|
+
- lib/wordpress/wxr/item.rb
|
109
|
+
- lib/wordpress/wxr/page.rb
|
110
|
+
- lib/wordpress/wxr/pages.rb
|
111
|
+
- lib/wordpress/wxr/post.rb
|
112
|
+
- lib/wordpress/wxr/posts.rb
|
113
|
+
- lib/wordpress/wxr/tag.rb
|
114
|
+
- lib/wordpress/wxr/tags.rb
|
115
|
+
- lib/wordpress/wxr/version.rb
|
116
|
+
- wordpress-wxr.gemspec
|
117
|
+
homepage: https://bitbucket.org/epub_dev/wordpress-wxr
|
118
|
+
licenses:
|
119
|
+
- MIT
|
120
|
+
metadata: {}
|
121
|
+
post_install_message:
|
122
|
+
rdoc_options: []
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
requirements: []
|
136
|
+
rubyforge_project:
|
137
|
+
rubygems_version: 2.2.5
|
138
|
+
signing_key:
|
139
|
+
specification_version: 4
|
140
|
+
summary: Parse a WordPress XML file into separate Ruby objects.
|
141
|
+
test_files: []
|