sphonglepress 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +100 -0
- data/History.txt +4 -0
- data/Manifest.txt +11 -0
- data/PostInstall.txt +7 -0
- data/README.rdoc +62 -0
- data/Rakefile +1 -0
- data/bin/sphonglepress +7 -0
- data/lib/sphonglepress/config.rb +34 -0
- data/lib/sphonglepress/database.rb +31 -0
- data/lib/sphonglepress/export.rb +43 -0
- data/lib/sphonglepress/extensions.rb +17 -0
- data/lib/sphonglepress/git.rb +19 -0
- data/lib/sphonglepress/importer.rb +105 -0
- data/lib/sphonglepress/middleman.rb +24 -0
- data/lib/sphonglepress/models/attachment.rb +32 -0
- data/lib/sphonglepress/models/base_post.rb +19 -0
- data/lib/sphonglepress/models/page.rb +23 -0
- data/lib/sphonglepress/models/post.rb +0 -0
- data/lib/sphonglepress/version.rb +3 -0
- data/lib/sphonglepress/visitor.rb +13 -0
- data/lib/sphonglepress.rb +150 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/sphonglepress.gemspec +31 -0
- data/templates/config/database.yml +12 -0
- data/templates/config/settings.yml +7 -0
- data/templates/config/sitemap.yml +0 -0
- data/templates/middleman/default.html.haml +0 -0
- data/templates/middleman/layout.haml +39 -0
- data/test/test_helper.rb +3 -0
- data/test/test_sphonglepress.rb +11 -0
- metadata +137 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm 1.9.2@sphonglepress
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
sphonglepress (0.0.1)
|
5
|
+
activerecord
|
6
|
+
haml
|
7
|
+
middleman
|
8
|
+
thor
|
9
|
+
tilt
|
10
|
+
|
11
|
+
GEM
|
12
|
+
remote: http://rubygems.org/
|
13
|
+
specs:
|
14
|
+
activemodel (3.0.9)
|
15
|
+
activesupport (= 3.0.9)
|
16
|
+
builder (~> 2.1.2)
|
17
|
+
i18n (~> 0.5.0)
|
18
|
+
activerecord (3.0.9)
|
19
|
+
activemodel (= 3.0.9)
|
20
|
+
activesupport (= 3.0.9)
|
21
|
+
arel (~> 2.0.10)
|
22
|
+
tzinfo (~> 0.3.23)
|
23
|
+
activesupport (3.0.9)
|
24
|
+
arel (2.0.10)
|
25
|
+
builder (2.1.2)
|
26
|
+
chunky_png (1.2.0)
|
27
|
+
coffee-script (2.2.0)
|
28
|
+
coffee-script-source
|
29
|
+
execjs
|
30
|
+
coffee-script-source (1.1.1)
|
31
|
+
compass (0.11.2)
|
32
|
+
chunky_png (~> 1.1)
|
33
|
+
fssm (>= 0.2.7)
|
34
|
+
sass (~> 3.1)
|
35
|
+
crack (0.1.8)
|
36
|
+
daemons (1.1.4)
|
37
|
+
eventmachine (0.12.10)
|
38
|
+
execjs (1.2.0)
|
39
|
+
multi_json (~> 1.0)
|
40
|
+
fssm (0.2.7)
|
41
|
+
haml (3.1.2)
|
42
|
+
http_router (0.7.10)
|
43
|
+
rack (>= 1.0.0)
|
44
|
+
url_mount (~> 0.2.1)
|
45
|
+
httparty (0.7.8)
|
46
|
+
crack (= 0.1.8)
|
47
|
+
i18n (0.5.0)
|
48
|
+
middleman (1.2.8)
|
49
|
+
coffee-script (~> 2.2.0)
|
50
|
+
compass (= 0.11.2)
|
51
|
+
haml (~> 3.1.0)
|
52
|
+
httparty (~> 0.7.0)
|
53
|
+
padrino-core (~> 0.9.23)
|
54
|
+
padrino-helpers (~> 0.9.23)
|
55
|
+
rack (~> 1.0)
|
56
|
+
rack-test (~> 0.5.0)
|
57
|
+
sass (~> 3.1.0)
|
58
|
+
shotgun (~> 0.8.0)
|
59
|
+
sinatra (~> 1.2.0)
|
60
|
+
thin (~> 1.2.0)
|
61
|
+
thor (~> 0.14.0)
|
62
|
+
tilt (~> 1.3.0)
|
63
|
+
uglifier (~> 0.5.0)
|
64
|
+
multi_json (1.0.3)
|
65
|
+
padrino-core (0.9.29)
|
66
|
+
activesupport (>= 3.0.0)
|
67
|
+
http_router (~> 0.7.8)
|
68
|
+
sinatra (~> 1.2.6)
|
69
|
+
thor (>= 0.14.3)
|
70
|
+
tilt (~> 1.3.0)
|
71
|
+
padrino-helpers (0.9.29)
|
72
|
+
i18n (>= 0.4.1)
|
73
|
+
padrino-core (= 0.9.29)
|
74
|
+
rack (1.3.0)
|
75
|
+
rack-test (0.5.7)
|
76
|
+
rack (>= 1.0)
|
77
|
+
sass (3.1.4)
|
78
|
+
shotgun (0.8)
|
79
|
+
rack (>= 1.0)
|
80
|
+
sinatra (1.2.6)
|
81
|
+
rack (~> 1.1)
|
82
|
+
tilt (< 2.0, >= 1.2.2)
|
83
|
+
thin (1.2.11)
|
84
|
+
daemons (>= 1.0.9)
|
85
|
+
eventmachine (>= 0.12.6)
|
86
|
+
rack (>= 1.0.0)
|
87
|
+
thor (0.14.6)
|
88
|
+
tilt (1.3.2)
|
89
|
+
tzinfo (0.3.29)
|
90
|
+
uglifier (0.5.4)
|
91
|
+
execjs (>= 0.3.0)
|
92
|
+
multi_json (>= 1.0.2)
|
93
|
+
url_mount (0.2.1)
|
94
|
+
rack
|
95
|
+
|
96
|
+
PLATFORMS
|
97
|
+
ruby
|
98
|
+
|
99
|
+
DEPENDENCIES
|
100
|
+
sphonglepress!
|
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/PostInstall.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
= sphonglepress
|
2
|
+
|
3
|
+
* http://github.com/nhemsley/sphonglepress
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
Sphonglepress is a command line utility for interacting with & making the task of importing content into a wordpress site
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* FIX (list of features or problems)
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
sphonglepress clean_wp # clean up the wordpress directory of the external files from middleman
|
16
|
+
sphonglepress create_static_files # create the static files to import into wordpress from (you will need a sitemap.yml)
|
17
|
+
sphonglepress dump_db # dump the current database as latest dump to load from
|
18
|
+
sphonglepress export_layout # export the layout and static files from middleman to wordpress
|
19
|
+
sphonglepress headers_footers # export headers and footers to wordpress directory
|
20
|
+
sphonglepress help [TASK] # Describe available tasks or one specific task
|
21
|
+
sphonglepress import_site # Import the site from sitemap and static files
|
22
|
+
sphonglepress init # Initialize wordpress directory
|
23
|
+
sphonglepress load_db # load the most recent 'clean' database dump
|
24
|
+
|
25
|
+
|
26
|
+
== REQUIREMENTS:
|
27
|
+
|
28
|
+
thor
|
29
|
+
middleman
|
30
|
+
activerecord
|
31
|
+
tilt
|
32
|
+
haml
|
33
|
+
|
34
|
+
== INSTALL:
|
35
|
+
|
36
|
+
|
37
|
+
* TODO upload to rubygems
|
38
|
+
|
39
|
+
== LICENSE:
|
40
|
+
|
41
|
+
(The MIT License)
|
42
|
+
|
43
|
+
Copyright (c) 2011 FIXME full name
|
44
|
+
|
45
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
46
|
+
a copy of this software and associated documentation files (the
|
47
|
+
'Software'), to deal in the Software without restriction, including
|
48
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
49
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
50
|
+
permit persons to whom the Software is furnished to do so, subject to
|
51
|
+
the following conditions:
|
52
|
+
|
53
|
+
The above copyright notice and this permission notice shall be
|
54
|
+
included in all copies or substantial portions of the Software.
|
55
|
+
|
56
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
57
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
58
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
59
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
60
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
61
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
62
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/sphonglepress
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
module Sphonglepress
|
5
|
+
class Config
|
6
|
+
class << self
|
7
|
+
def create_config(config)
|
8
|
+
FileUtils.mkdir("config")
|
9
|
+
write_config config
|
10
|
+
end
|
11
|
+
|
12
|
+
def write_config(config)
|
13
|
+
FileUtils.cp(config["sitemap_file"] || "#{::Sphonglepress::App::TEMPLATE_DIR}/config/sitemap.yml", "config/sitemap.yml")
|
14
|
+
File.open("config/settings.yml", 'w') {|f| f.write(config.to_yaml.to_s)}
|
15
|
+
end
|
16
|
+
|
17
|
+
def config
|
18
|
+
begin
|
19
|
+
c = YAML::load(IO.read(::Sphonglepress::CONFIG_DIR.join("settings.yml")))
|
20
|
+
c["db"] = YAML::load(IO.read(::Sphonglepress::CONFIG_DIR.join("database.yml")))
|
21
|
+
c["middleman_dir"] = Pathname.new(c["middleman_dir"])
|
22
|
+
c["wp_clone_dir"] = Pathname.new(c["wp_clone_dir"])
|
23
|
+
return c
|
24
|
+
rescue
|
25
|
+
return {}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def wp_theme_dir
|
30
|
+
config["wp_clone_dir"].join("wp-content/themes", config["wp_theme_dir"])
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Sphonglepress
|
2
|
+
class Database
|
3
|
+
class << self
|
4
|
+
def drop(config)
|
5
|
+
db = config["db"][::Sphonglepress::ENV_MODE]
|
6
|
+
cmd = "echo \"drop database \\`#{db["database"]}\\`\" | mysql #{db_opts_no_db(CONFIG)}"
|
7
|
+
puts cmd
|
8
|
+
`#{cmd}`
|
9
|
+
end
|
10
|
+
|
11
|
+
def create(config)
|
12
|
+
db = config["db"][::Sphonglepress::ENV_MODE]
|
13
|
+
cmd = "echo \"create database \\`#{db["database"]}\\`\" | mysql #{db_opts_no_db(CONFIG)}"
|
14
|
+
puts cmd
|
15
|
+
`#{cmd}`
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
def db_opts(config)
|
20
|
+
db = config["db"][::Sphonglepress::ENV_MODE]
|
21
|
+
db_opts_no_db(config) << db["database"]
|
22
|
+
end
|
23
|
+
|
24
|
+
def db_opts_no_db(config)
|
25
|
+
db = config["db"][::Sphonglepress::ENV_MODE]
|
26
|
+
"-u #{db["username"]} " << (db["password"] ? "-p #{db["password"]} " : " ")
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Sphonglepress
|
2
|
+
class Export
|
3
|
+
class << self
|
4
|
+
def headers_footers
|
5
|
+
build_dir = ::Sphonglepress::Config.config["middleman_dir"].join("build")
|
6
|
+
puts build_dir
|
7
|
+
|
8
|
+
default_file = build_dir.join("default.html")
|
9
|
+
default_parts = split_file(IO.read(default_file))
|
10
|
+
|
11
|
+
other_files = Dir["#{build_dir}/*.html"]. #without default.html
|
12
|
+
reject {|file| Pathname.new(file).basename.to_s == "default.html"}
|
13
|
+
|
14
|
+
others = {}
|
15
|
+
other_files.each do |file|
|
16
|
+
others[File.basename(file, '.*')] = split_file(IO.read(file))
|
17
|
+
end
|
18
|
+
|
19
|
+
File.open(::Sphonglepress::Config.wp_theme_dir.join("header.php"), 'w') {|file| file.write(default_parts[:header])}
|
20
|
+
File.open(::Sphonglepress::Config.wp_theme_dir.join("footer.php"), 'w') {|file| file.write(default_parts[:footer])}
|
21
|
+
|
22
|
+
others.each do |name, parts|
|
23
|
+
File.open(::Sphonglepress::Config.wp_theme_dir.join("header-#{name}.php"), 'w') {|file| file.write(parts[:header])}
|
24
|
+
File.open(::Sphonglepress::Config.wp_theme_dir.join("footer-#{name}.php"), 'w') {|file| file.write(parts[:footer])}
|
25
|
+
File.open(::Sphonglepress::Config.wp_theme_dir.join("#{name}.php"), 'w') {|file| file.write(parts[:content])}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def files
|
30
|
+
cmd = "cp -r #{CONFIG["middleman_dir"]}/build/*/ #{::Sphonglepress::WP_DIR}"
|
31
|
+
`#{cmd}`
|
32
|
+
end
|
33
|
+
|
34
|
+
def split_file(contents)
|
35
|
+
first = contents.split("<!-- BEGIN_BODY -->")
|
36
|
+
second = first.last.split("<!-- END_BODY -->")
|
37
|
+
|
38
|
+
{:header => first.first, :content => second.first, :footer => second.last}
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class Object
|
2
|
+
def self.subclasses(direct = false)
|
3
|
+
classes = []
|
4
|
+
if direct
|
5
|
+
ObjectSpace.each_object(Class) do |c|
|
6
|
+
next unless c.superclass == self
|
7
|
+
classes << c
|
8
|
+
end
|
9
|
+
else
|
10
|
+
ObjectSpace.each_object(Class) do |c|
|
11
|
+
next unless c.ancestors.include?(self) and (c != self)
|
12
|
+
classes << c
|
13
|
+
end
|
14
|
+
end
|
15
|
+
classes
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
|
2
|
+
module Sphonglepress
|
3
|
+
class Git
|
4
|
+
class << self
|
5
|
+
def clone(options)
|
6
|
+
clone_cmd = "git clone #{options['wp_git_url']} #{options['wp_clone_dir']}"
|
7
|
+
|
8
|
+
puts clone_cmd
|
9
|
+
`#{clone_cmd}`
|
10
|
+
end
|
11
|
+
|
12
|
+
def checkout(options)
|
13
|
+
checkout_cmd = "git --git-dir=#{options['wp_clone_dir']}/.git --work-tree=#{options['wp_clone_dir']} checkout #{options['wp_git_tag']}"
|
14
|
+
puts checkout_cmd
|
15
|
+
`#{checkout_cmd}`
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'tilt'
|
2
|
+
require 'haml'
|
3
|
+
|
4
|
+
require 'sphonglepress/models/page'
|
5
|
+
|
6
|
+
module Sphonglepress
|
7
|
+
class Importer
|
8
|
+
class << self
|
9
|
+
def import(hash)
|
10
|
+
structure(hash)
|
11
|
+
end
|
12
|
+
|
13
|
+
def structure(hash, parent=nil)
|
14
|
+
i=0
|
15
|
+
sorted = hash.keys.sort {|a,b| a[0].to_i <=> b[0].to_i }
|
16
|
+
pages = []
|
17
|
+
page = nil
|
18
|
+
sorted.each do |key|
|
19
|
+
title = key[2..key.length].gsub("_", " ").upcase
|
20
|
+
if parent
|
21
|
+
page = Models::Page.new(:post_title => title, :post_type => "page", :menu_order => i, :parent => parent)
|
22
|
+
parent.posts << page
|
23
|
+
else
|
24
|
+
page = Models::Page.new(:post_title => title, :post_type => "page", :menu_order => i)
|
25
|
+
end
|
26
|
+
#puts page.post_title
|
27
|
+
page.post_name = page.post_title.downcase.split(" ").join("-")
|
28
|
+
page.post_date = page.post_modified = DateTime.now
|
29
|
+
page.post_date_gmt = page.post_modified_gmt = DateTime.now.new_offset(0)
|
30
|
+
pages << page
|
31
|
+
|
32
|
+
page_content_file = ::Sphonglepress::STATIC_DIR.join(full_path_for_page(page)).to_s << ".html.haml"
|
33
|
+
|
34
|
+
begin
|
35
|
+
if File.exist?(page_content_file)
|
36
|
+
#puts "found #{page_content_file}"
|
37
|
+
page.post_content = Tilt.new(page_content_file).render
|
38
|
+
else
|
39
|
+
puts "Couldnt find #{page_content_file} in the static directory"
|
40
|
+
end
|
41
|
+
rescue Haml::SyntaxError => e
|
42
|
+
puts "Error on line #{e.line}: #{e.message}"
|
43
|
+
raise
|
44
|
+
end
|
45
|
+
|
46
|
+
i += 10
|
47
|
+
|
48
|
+
|
49
|
+
if hash[key].is_a? Hash
|
50
|
+
structure(hash[key], page)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
pages
|
54
|
+
end
|
55
|
+
|
56
|
+
def persist(page)
|
57
|
+
page.save
|
58
|
+
page.posts.each {|p| persist(p)}
|
59
|
+
end
|
60
|
+
|
61
|
+
def visit(page)
|
62
|
+
Visitor.subclasses.each do |v|
|
63
|
+
v.visit(page)
|
64
|
+
page.posts.each do |p|
|
65
|
+
visit(p)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def filenames_for_site(pages)
|
71
|
+
filenames = []
|
72
|
+
pages.each do |page|
|
73
|
+
filenames.concat(filenames_for_page(page))
|
74
|
+
end
|
75
|
+
filenames
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
# http://stackoverflow.com/questions/1939333/how-to-make-a-ruby-string-safe-for-a-filesystem
|
81
|
+
def sanitize_filename(filename)
|
82
|
+
filename.strip.gsub(/^.*(\\|\/)/, '').gsub(/[^0-9A-Za-z.\-]/, '-')
|
83
|
+
end
|
84
|
+
|
85
|
+
def full_path_for_page(page)
|
86
|
+
return "" unless page
|
87
|
+
path = full_path_for_page(page.parent)
|
88
|
+
join = path.length > 0 ? "_" : ""
|
89
|
+
return "#{path << join}" << "#{sanitize_filename(page.post_title)}"
|
90
|
+
end
|
91
|
+
|
92
|
+
def filenames_for_page(page)
|
93
|
+
filenames = []
|
94
|
+
|
95
|
+
filenames << full_path_for_page(page)
|
96
|
+
page.posts.each do |child|
|
97
|
+
filenames.concat filenames_for_page(child)
|
98
|
+
end
|
99
|
+
filenames
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Sphonglepress
|
2
|
+
class Middleman
|
3
|
+
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def init(site)
|
7
|
+
puts "Creating Middleman static site"
|
8
|
+
`mm-init #{site}`
|
9
|
+
|
10
|
+
`cp #{::Sphonglepress::App::TEMPLATE_DIR.join("middleman/layout.haml")} #{site}/views`
|
11
|
+
`cp #{::Sphonglepress::App::TEMPLATE_DIR.join("middleman/default.html.haml")} #{site}/views`
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
def build
|
16
|
+
cwd = Dir.pwd
|
17
|
+
Dir.chdir ::Sphonglepress::Config.config["middleman_dir"]
|
18
|
+
puts `mm-build`
|
19
|
+
Dir.chdir cwd
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Sphonglepress::Models
|
2
|
+
class Attachment < BasePost
|
3
|
+
attr_accessor :file
|
4
|
+
|
5
|
+
scope :attachments, where(:post_type => "attachment")
|
6
|
+
|
7
|
+
before_save :do_stuff
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def do_stuff
|
12
|
+
return if !@file
|
13
|
+
self.post_type = "attachment"
|
14
|
+
now = DateTime.now
|
15
|
+
year = now.year
|
16
|
+
month = now.month
|
17
|
+
random = rand(36**8).to_s(36)
|
18
|
+
ext = File.extname(@file)
|
19
|
+
monthed_dir = now.strftime("%Y/%m")
|
20
|
+
upload_dir = ::Sphonglepress::WP_UPLOAD_DIR.join(monthed_dir)
|
21
|
+
bare_file_name = "#{random}#{ext}"
|
22
|
+
|
23
|
+
self.post_title = self.post_name = bare_file_name
|
24
|
+
self.post_status = "inherit"
|
25
|
+
self.guid = url = "/wp-content/uploads/#{monthed_dir}/#{bare_file_name}"
|
26
|
+
self.post_mime_type = "image/jpeg"
|
27
|
+
file_name = upload_dir.join(bare_file_name)
|
28
|
+
FileUtils.mkdir_p upload_dir
|
29
|
+
FileUtils.cp(@file, file_name)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Sphonglepress::Models
|
2
|
+
class BasePost < ActiveRecord::Base
|
3
|
+
set_table_name :wp_posts
|
4
|
+
set_primary_key :ID
|
5
|
+
|
6
|
+
has_many :children, :foreign_key => 'post_parent', :class_name => self.class
|
7
|
+
belongs_to :parent, :foreign_key => 'post_parent', :class_name => self.class
|
8
|
+
|
9
|
+
after_initialize :set_dates
|
10
|
+
|
11
|
+
private
|
12
|
+
def set_dates
|
13
|
+
self.post_date = DateTime.now
|
14
|
+
self.post_modified_gmt = DateTime.now
|
15
|
+
self.post_modified = DateTime.now
|
16
|
+
self.post_date_gmt = DateTime.now
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
|
3
|
+
module Sphonglepress::Models
|
4
|
+
class Page < ActiveRecord::Base
|
5
|
+
set_table_name :wp_posts
|
6
|
+
set_primary_key :ID
|
7
|
+
|
8
|
+
scope :pages, where(:post_type => "page")
|
9
|
+
|
10
|
+
has_many :posts, :foreign_key => 'post_parent', :class_name => "Page"
|
11
|
+
belongs_to :parent, :foreign_key => 'post_parent', :class_name => "Page"
|
12
|
+
|
13
|
+
after_initialize :set_dates
|
14
|
+
|
15
|
+
private
|
16
|
+
def set_dates
|
17
|
+
self.post_date = DateTime.now
|
18
|
+
self.post_modified_gmt = DateTime.now
|
19
|
+
self.post_modified = DateTime.now
|
20
|
+
self.post_date_gmt = DateTime.now
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
File without changes
|
@@ -0,0 +1,150 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
require 'active_record'
|
5
|
+
require 'pathname'
|
6
|
+
require 'logger'
|
7
|
+
require "thor"
|
8
|
+
|
9
|
+
begin
|
10
|
+
ActiveRecord::Base.logger = Logger.new('sql.log')
|
11
|
+
ActiveRecord::Base.configurations = YAML::load(IO.read('config/database.yml'))
|
12
|
+
ActiveRecord::Base.establish_connection("development")
|
13
|
+
rescue
|
14
|
+
end
|
15
|
+
|
16
|
+
require "sphonglepress/extensions.rb"
|
17
|
+
require "sphonglepress/git.rb"
|
18
|
+
require "sphonglepress/middleman.rb"
|
19
|
+
require "sphonglepress/config.rb"
|
20
|
+
require "sphonglepress/export.rb"
|
21
|
+
require "sphonglepress/database.rb"
|
22
|
+
|
23
|
+
|
24
|
+
begin
|
25
|
+
require "sphonglepress/importer.rb"
|
26
|
+
require "sphonglepress/visitor.rb"
|
27
|
+
|
28
|
+
require "sphonglepress/models/base_post"
|
29
|
+
require "sphonglepress/models/attachment"
|
30
|
+
rescue
|
31
|
+
end
|
32
|
+
|
33
|
+
module Sphonglepress
|
34
|
+
VERSION = '0.0.1'
|
35
|
+
|
36
|
+
class App < Thor
|
37
|
+
desc "init", "Initialize wordpress directory"
|
38
|
+
method_options :wp_git_url => :string, :wp_git_tag => :string, :wp_clone_dir => :string, :sitemap_file => :string
|
39
|
+
def init
|
40
|
+
opts = DEFAULT_OPTIONS.merge options
|
41
|
+
Git.clone(opts)
|
42
|
+
Git.checkout(opts)
|
43
|
+
Middleman.init(opts["middleman_dir"])
|
44
|
+
Config.create_config(opts)
|
45
|
+
end
|
46
|
+
|
47
|
+
desc "headers_footers", "export headers and footers to wordpress directory"
|
48
|
+
def headers_footers
|
49
|
+
Middleman.build
|
50
|
+
Export.headers_footers
|
51
|
+
end
|
52
|
+
|
53
|
+
desc "clean_wp", "clean up the wordpress directory of the external files from middleman"
|
54
|
+
def clean_wp
|
55
|
+
dirs = Dir[LAYOUT_DIR.join("public").to_s << "/*/"]
|
56
|
+
full_dirs = dirs.map {|d| WP_DIR.join(Pathname.new(d).basename)}.join(" ")
|
57
|
+
cmd = "rm -rf #{full_dirs}"
|
58
|
+
puts cmd
|
59
|
+
`#{cmd}`
|
60
|
+
cmd = "rm -rf #{WP_UPLOAD_DIR.to_s}/*"
|
61
|
+
`#{cmd}`
|
62
|
+
end
|
63
|
+
|
64
|
+
desc "import_site", "Import the site from sitemap and static files"
|
65
|
+
method_options :visitor => :string
|
66
|
+
def import_site
|
67
|
+
pages = Importer.import sitemap_hash
|
68
|
+
pages.each { |page| Importer.persist page }
|
69
|
+
visitors = Dir[CONFIG_DIR.join("visitors").to_s << "/*.rb"].map{|v| "config/visitors/" << Pathname.new(v).basename}
|
70
|
+
visitors.each do |v|
|
71
|
+
puts "requiring #{v}"
|
72
|
+
require v
|
73
|
+
end
|
74
|
+
pages.each { |page| Importer.visit page }
|
75
|
+
Visitor.subclasses.each {|s| s.once}
|
76
|
+
end
|
77
|
+
|
78
|
+
desc "load_db", "load the most recent 'clean' database dump"
|
79
|
+
def load_db
|
80
|
+
Database.drop(CONFIG)
|
81
|
+
Database.create(CONFIG)
|
82
|
+
db_opts = Database.db_opts(CONFIG)
|
83
|
+
latest_dump = Dir["#{::Sphonglepress::DB_DUMP_DIR}/*.sql"].sort_by{ |f| File.ctime(f) }.last
|
84
|
+
puts "mysql #{db_opts} < #{latest_dump}"
|
85
|
+
`mysql #{db_opts} < #{latest_dump}`
|
86
|
+
end
|
87
|
+
|
88
|
+
desc "dump_db", "dump the current database as latest dump to load from"
|
89
|
+
def dump_db
|
90
|
+
random = rand(36**8).to_s(36)
|
91
|
+
dump_file = "#{::Sphonglepress::DB_DUMP_DIR.join("#{CONFIG['db']['development']['database']}")}-#{random}.sql"
|
92
|
+
puts "file: #{dump_file}"
|
93
|
+
db_opts = Database.db_opts(CONFIG)
|
94
|
+
|
95
|
+
`mysqldump #{db_opts} > #{dump_file}`
|
96
|
+
end
|
97
|
+
|
98
|
+
desc "create_static_files", "create the static files to import into wordpress from (you will need a sitemap.yml)"
|
99
|
+
def create_static_files
|
100
|
+
site = sitemap_hash
|
101
|
+
pages = Importer.structure(site)
|
102
|
+
|
103
|
+
FileUtils.mkdir_p(STATIC_DIR)
|
104
|
+
|
105
|
+
filenames = Importer.filenames_for_site pages
|
106
|
+
|
107
|
+
full_files = filenames.map {|file| STATIC_DIR.join("#{file}.html.haml").to_s }
|
108
|
+
|
109
|
+
FileUtils.touch(full_files)
|
110
|
+
end
|
111
|
+
|
112
|
+
desc "export_layout", "export the layout and static files from middleman to wordpress"
|
113
|
+
def export_layout
|
114
|
+
Middleman.build
|
115
|
+
Export.files
|
116
|
+
end
|
117
|
+
|
118
|
+
desc "full_refresh", "do a full refresh of the whole shebang (layouts, headers, database, import content)"
|
119
|
+
def full_refresh
|
120
|
+
clean_wp
|
121
|
+
headers_footers
|
122
|
+
export_layout
|
123
|
+
load_db
|
124
|
+
import_site
|
125
|
+
end
|
126
|
+
|
127
|
+
private
|
128
|
+
|
129
|
+
def sitemap_hash
|
130
|
+
YAML::load(IO.read(::Sphonglepress::CONFIG_DIR.join("sitemap.yml")))
|
131
|
+
end
|
132
|
+
|
133
|
+
APP_DIR = Pathname.new(File.expand_path(File.dirname(__FILE__))).join("..")
|
134
|
+
TEMPLATE_DIR = APP_DIR.join("templates")
|
135
|
+
DEFAULT_OPTIONS = YAML::load(IO.read(TEMPLATE_DIR.join("config/settings.yml")))
|
136
|
+
end
|
137
|
+
|
138
|
+
PROJECT_DIR = Pathname.new(File.expand_path(Dir.pwd))
|
139
|
+
CONFIG_DIR = PROJECT_DIR.join("config")
|
140
|
+
ENV_MODE = "development"
|
141
|
+
CONFIG = Config.config
|
142
|
+
|
143
|
+
|
144
|
+
DB_DIR = PROJECT_DIR.join("db")
|
145
|
+
DB_DUMP_DIR = PROJECT_DIR.join("db/dumps")
|
146
|
+
STATIC_DIR = PROJECT_DIR.join(CONFIG["static_dir"]) rescue nil
|
147
|
+
WP_DIR = PROJECT_DIR.join(CONFIG["wp_clone_dir"]) rescue nil
|
148
|
+
WP_UPLOAD_DIR = WP_DIR.join("wp-content/uploads") rescue nil
|
149
|
+
LAYOUT_DIR = PROJECT_DIR.join(CONFIG["middleman_dir"]) rescue nil
|
150
|
+
end
|
data/script/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# File: script/console
|
3
|
+
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
+
|
5
|
+
libs = " -r irb/completion"
|
6
|
+
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
|
+
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
+
libs << " -r #{File.dirname(__FILE__) + '/../lib/sphonglepress.rb'}"
|
9
|
+
puts "Loading sphonglepress gem"
|
10
|
+
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/destroy'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/generate'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Generate.new.run(ARGV)
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "sphonglepress/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "sphonglepress"
|
7
|
+
s.version = Sphonglepress::VERSION
|
8
|
+
s.authors = ["Nicholas Hemsley"]
|
9
|
+
s.email = ["nick.hems@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Gem for populating wordpress}
|
12
|
+
s.description = %q{Sphonglepress is a command line utility for interacting with & making the task of importing content into a wordpress site}
|
13
|
+
|
14
|
+
s.rubyforge_project = "sphonglepress"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
# s.add_development_dependency "rspec"
|
23
|
+
# s.add_runtime_dependency "rest-client"
|
24
|
+
|
25
|
+
s.add_dependency('thor')
|
26
|
+
s.add_dependency('middleman')
|
27
|
+
s.add_dependency('activerecord')
|
28
|
+
s.add_dependency('tilt')
|
29
|
+
s.add_dependency('haml')
|
30
|
+
|
31
|
+
end
|
File without changes
|
File without changes
|
@@ -0,0 +1,39 @@
|
|
1
|
+
!!! 5
|
2
|
+
%html{ :lang => "en" }
|
3
|
+
%head
|
4
|
+
%title <?php wp_title(); ?>
|
5
|
+
%meta{ :charset => "utf-8" }
|
6
|
+
|
7
|
+
/ Always force latest IE rendering engine (even in intranet) & Chrome Frame
|
8
|
+
%meta{ :content => "IE=edge,chrome=1", "http-equiv" => "X-UA-Compatible" }
|
9
|
+
|
10
|
+
/ Comment in layout
|
11
|
+
|
12
|
+
= stylesheet_link_tag "style.css"
|
13
|
+
|
14
|
+
= javascript_include_tag "jquery"
|
15
|
+
= javascript_include_tag "application.js"
|
16
|
+
|
17
|
+
= yield_content :head
|
18
|
+
|
19
|
+
%body{ :class => "#{page_classes}" }
|
20
|
+
#main
|
21
|
+
#header
|
22
|
+
%a#logo{:href => "/"}
|
23
|
+
%img{:src=>"/images/logo.png"}
|
24
|
+
#menu
|
25
|
+
%ul
|
26
|
+
:plain
|
27
|
+
<?php wp_list_pages('sort_column=menu_order&title_li=');?>
|
28
|
+
#content-wrapper
|
29
|
+
= yield_content :sidebar
|
30
|
+
#content
|
31
|
+
%h1
|
32
|
+
:plain
|
33
|
+
<?php wp_title(); ?>
|
34
|
+
|
35
|
+
/BEGIN_BODY
|
36
|
+
|
37
|
+
= yield
|
38
|
+
|
39
|
+
/END_BODY
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sphonglepress
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Nicholas Hemsley
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-08-24 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: thor
|
16
|
+
requirement: &84388670 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *84388670
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: middleman
|
27
|
+
requirement: &84388460 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *84388460
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: activerecord
|
38
|
+
requirement: &84388250 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *84388250
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: tilt
|
49
|
+
requirement: &84388040 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *84388040
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: haml
|
60
|
+
requirement: &84387830 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :runtime
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *84387830
|
69
|
+
description: Sphonglepress is a command line utility for interacting with & making
|
70
|
+
the task of importing content into a wordpress site
|
71
|
+
email:
|
72
|
+
- nick.hems@gmail.com
|
73
|
+
executables:
|
74
|
+
- sphonglepress
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- .gitignore
|
79
|
+
- .rvmrc
|
80
|
+
- Gemfile
|
81
|
+
- Gemfile.lock
|
82
|
+
- History.txt
|
83
|
+
- Manifest.txt
|
84
|
+
- PostInstall.txt
|
85
|
+
- README.rdoc
|
86
|
+
- Rakefile
|
87
|
+
- bin/sphonglepress
|
88
|
+
- lib/sphonglepress.rb
|
89
|
+
- lib/sphonglepress/config.rb
|
90
|
+
- lib/sphonglepress/database.rb
|
91
|
+
- lib/sphonglepress/export.rb
|
92
|
+
- lib/sphonglepress/extensions.rb
|
93
|
+
- lib/sphonglepress/git.rb
|
94
|
+
- lib/sphonglepress/importer.rb
|
95
|
+
- lib/sphonglepress/middleman.rb
|
96
|
+
- lib/sphonglepress/models/attachment.rb
|
97
|
+
- lib/sphonglepress/models/base_post.rb
|
98
|
+
- lib/sphonglepress/models/page.rb
|
99
|
+
- lib/sphonglepress/models/post.rb
|
100
|
+
- lib/sphonglepress/version.rb
|
101
|
+
- lib/sphonglepress/visitor.rb
|
102
|
+
- script/console
|
103
|
+
- script/destroy
|
104
|
+
- script/generate
|
105
|
+
- sphonglepress.gemspec
|
106
|
+
- templates/config/database.yml
|
107
|
+
- templates/config/settings.yml
|
108
|
+
- templates/config/sitemap.yml
|
109
|
+
- templates/middleman/default.html.haml
|
110
|
+
- templates/middleman/layout.haml
|
111
|
+
- test/test_helper.rb
|
112
|
+
- test/test_sphonglepress.rb
|
113
|
+
homepage: ''
|
114
|
+
licenses: []
|
115
|
+
post_install_message:
|
116
|
+
rdoc_options: []
|
117
|
+
require_paths:
|
118
|
+
- lib
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
none: false
|
121
|
+
requirements:
|
122
|
+
- - ! '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
none: false
|
127
|
+
requirements:
|
128
|
+
- - ! '>='
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
requirements: []
|
132
|
+
rubyforge_project: sphonglepress
|
133
|
+
rubygems_version: 1.8.6
|
134
|
+
signing_key:
|
135
|
+
specification_version: 3
|
136
|
+
summary: Gem for populating wordpress
|
137
|
+
test_files: []
|