Class: WP2Middleman::Migrator

Inherits:
Object
  • Object
show all
Defined in:
lib/wp2middleman/migrator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(wp_xml_export_file, body_to_markdown: false, include_fields: []) ⇒ Migrator

Returns a new instance of Migrator.



7
8
9
10
11
12
# File 'lib/wp2middleman/migrator.rb', line 7

def initialize(wp_xml_export_file, body_to_markdown: false, include_fields: [])
  @posts = WP2Middleman::PostCollection.from_file(wp_xml_export_file)
    .without_attachments
    .only_valid
    .to_middleman(body_to_markdown: body_to_markdown, include_fields: include_fields)
end

Instance Attribute Details

#postsObject (readonly)

Returns the value of attribute posts.



5
6
7
# File 'lib/wp2middleman/migrator.rb', line 5

def posts
  @posts
end

Instance Method Details

#ensure_export_directoryObject



26
27
28
29
30
# File 'lib/wp2middleman/migrator.rb', line 26

def ensure_export_directory
  unless File.directory? output_path
    FileUtils.mkdir_p output_path
  end
end

#migrateObject



14
15
16
17
18
19
20
# File 'lib/wp2middleman/migrator.rb', line 14

def migrate
  ensure_export_directory

  posts.each do |post|
    File.write(post.full_filename(output_path), post.file_content)
  end
end

#output_pathObject



22
23
24
# File 'lib/wp2middleman/migrator.rb', line 22

def output_path
  "#{Dir.pwd}/export/"
end