sphonglepress 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/sphonglepress.rb CHANGED
@@ -5,29 +5,41 @@ require 'active_record'
5
5
  require 'pathname'
6
6
  require 'logger'
7
7
  require "thor"
8
+ require 'fileutils'
9
+
10
+ require "sphonglepress/config.rb"
8
11
 
9
12
  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
13
+ if File.exist? 'config/database.yml'
14
+ ActiveRecord::Base.logger = Logger.new('sql.log')
15
+ ActiveRecord::Base.configurations = YAML::load(IO.read('config/database.yml'))
16
+ ActiveRecord::Base.establish_connection("development")
17
+ end
18
+ rescue Exception => e
19
+ puts "Error configuring active record:"
20
+ puts e.to_s
14
21
  end
15
22
 
16
23
  require "sphonglepress/extensions.rb"
17
24
  require "sphonglepress/git.rb"
18
25
  require "sphonglepress/middleman.rb"
19
- require "sphonglepress/config.rb"
20
26
  require "sphonglepress/export.rb"
21
27
  require "sphonglepress/database.rb"
28
+ require "sphonglepress/watcher.rb"
22
29
 
23
30
 
24
31
  begin
25
32
  require "sphonglepress/importer.rb"
26
- require "sphonglepress/visitor.rb"
27
-
33
+ require "sphonglepress/visitors/visitor.rb"
34
+ require "sphonglepress/visitors/attachment_visitor.rb"
35
+ require "sphonglepress/visitors/document_importer.rb"
36
+
37
+
28
38
  require "sphonglepress/models/base_post"
29
39
  require "sphonglepress/models/attachment"
30
- rescue
40
+ rescue Exception => e
41
+ puts "Error requiring importer, visitor & activemodel classes (this can probably be ignored):"
42
+ puts e.to_s
31
43
  end
32
44
 
33
45
  module Sphonglepress
@@ -40,8 +52,12 @@ module Sphonglepress
40
52
  opts = DEFAULT_OPTIONS.merge options
41
53
  Git.clone(opts)
42
54
  Git.checkout(opts)
43
- Middleman.init(opts["middleman_dir"])
55
+ Middleman.init(opts)
44
56
  Config.create_config(opts)
57
+
58
+ #FIXME: move this somewhere better
59
+ visitors_dir = TEMPLATE_DIR.join(opts['template'], "visitors")
60
+ `cp -r #{visitors_dir} config/`
45
61
  end
46
62
 
47
63
  desc "headers_footers", "export headers and footers to wordpress directory"
@@ -52,8 +68,8 @@ module Sphonglepress
52
68
 
53
69
  desc "clean_wp", "clean up the wordpress directory of the external files from middleman"
54
70
  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(" ")
71
+ dirs = Dir[LAYOUT_DIR.join("source").to_s << "/*/"]
72
+ full_dirs = dirs.map {|d| ::Sphonglepress::Config.wp_theme_dir.join(Pathname.new(d).basename)}.join(" ")
57
73
  cmd = "rm -rf #{full_dirs}"
58
74
  puts cmd
59
75
  `#{cmd}`
@@ -64,23 +80,34 @@ module Sphonglepress
64
80
  desc "import_site", "Import the site from sitemap and static files"
65
81
  method_options :visitor => :string
66
82
  def import_site
67
- pages = Importer.import sitemap_hash
83
+ pages = ::Sphonglepress::Importer.import sitemap_hash
68
84
  pages.each { |page| Importer.persist page }
69
- visitors = Dir[CONFIG_DIR.join("visitors").to_s << "/*.rb"].map{|v| "config/visitors/" << Pathname.new(v).basename}
85
+ visitors = Dir[CONFIG_DIR.join("visitors").to_s << "/*.rb"].map{|v| "config/visitors/" << Pathname.new(v).basename.to_s}
70
86
  visitors.each do |v|
71
87
  puts "requiring #{v}"
72
- require v
88
+ require Dir.pwd.to_s << "/" << v
73
89
  end
90
+ ::Sphonglepress::Visitors::Visitor.subclasses.each {|s| s.instance.once}
91
+
74
92
  pages.each { |page| Importer.visit page }
75
- Visitor.subclasses.each {|s| s.once}
76
93
  end
77
94
 
95
+ desc "create_db", "create the wordpress database"
96
+ def create_db
97
+ Database.create(CONFIG)
98
+ end
99
+
100
+ desc "drop_db", "drop the wordpress database"
101
+ def drop_db
102
+ Database.drop(CONFIG)
103
+ end
104
+
78
105
  desc "load_db", "load the most recent 'clean' database dump"
79
106
  def load_db
80
107
  Database.drop(CONFIG)
81
108
  Database.create(CONFIG)
82
109
  db_opts = Database.db_opts(CONFIG)
83
- latest_dump = Dir["#{::Sphonglepress::DB_DUMP_DIR}/*.sql"].sort_by{ |f| File.ctime(f) }.last
110
+ latest_dump = Dir["#{::Sphonglepress::DB_DUMP_DIR}/*.sql"].sort_by{ |f| File.mtime(f) }.last
84
111
  puts "mysql #{db_opts} < #{latest_dump}"
85
112
  `mysql #{db_opts} < #{latest_dump}`
86
113
  end
@@ -91,6 +118,18 @@ module Sphonglepress
91
118
  dump_file = "#{::Sphonglepress::DB_DUMP_DIR.join("#{CONFIG['db']['development']['database']}")}-#{random}.sql"
92
119
  puts "file: #{dump_file}"
93
120
  db_opts = Database.db_opts(CONFIG)
121
+ FileUtils.mkdir_p ::Sphonglepress::DB_DUMP_DIR
122
+
123
+ `mysqldump #{db_opts} > #{dump_file}`
124
+ end
125
+
126
+ desc "dump_db_live", "dump the current database as database to go live with"
127
+ def dump_db_live
128
+ random = rand(36**8).to_s(36)
129
+ dump_file = "#{::Sphonglepress::DB_DUMP_DIR_LIVE.join("#{CONFIG['db']['development']['database']}")}-#{random}.sql"
130
+ puts "file: #{dump_file}"
131
+ db_opts = Database.db_opts(CONFIG)
132
+ FileUtils.mkdir_p ::Sphonglepress::DB_DUMP_DIR_LIVE
94
133
 
95
134
  `mysqldump #{db_opts} > #{dump_file}`
96
135
  end
@@ -104,7 +143,9 @@ module Sphonglepress
104
143
 
105
144
  filenames = Importer.filenames_for_site pages
106
145
 
107
- full_files = filenames.map {|file| STATIC_DIR.join("#{file}.html.haml").to_s }
146
+ full_files = filenames.
147
+ map {|file| STATIC_DIR.join("#{file}.html.haml").to_s }.
148
+ reject {|file| File.exist? file }
108
149
 
109
150
  FileUtils.touch(full_files)
110
151
  end
@@ -115,14 +156,43 @@ module Sphonglepress
115
156
  Export.files
116
157
  end
117
158
 
159
+ desc "export", "copy static files to wordpress"
160
+ def export
161
+ Middleman.build
162
+ Export.files
163
+ Export.headers_footers
164
+ end
165
+
118
166
  desc "full_refresh", "do a full refresh of the whole shebang (layouts, headers, database, import content)"
119
167
  def full_refresh
120
168
  clean_wp
121
- headers_footers
122
- export_layout
169
+ Middleman.clean
170
+ export
123
171
  load_db
124
172
  import_site
125
173
  end
174
+
175
+ desc "watch", "monitor directory & reload on change"
176
+ def watch
177
+ Signal.trap("INT") { exit! }
178
+ Signal.trap("QUIT") { full_refresh }
179
+
180
+ puts "Watching"
181
+ Watcher.new(self).watch
182
+ end
183
+
184
+ require 'ruby-debug'
185
+ desc "import_static_from_doc", "Try and import site structure from site.odt file in the static/document directory"
186
+ def import_static_from_doc
187
+ pages = ::Sphonglepress::Importer.import sitemap_hash
188
+ document_importer_klass = ::Sphonglepress::Visitors::DocumentImporter
189
+ document_importer_klass.instance.once
190
+ pages.each { |page| Importer.visit page, [document_importer_klass]}
191
+ end
192
+
193
+
194
+
195
+ #desc "populate_static_from_doc"
126
196
 
127
197
  private
128
198
 
@@ -143,6 +213,7 @@ module Sphonglepress
143
213
 
144
214
  DB_DIR = PROJECT_DIR.join("db")
145
215
  DB_DUMP_DIR = PROJECT_DIR.join("db/dumps")
216
+ DB_DUMP_DIR_LIVE = PROJECT_DIR.join("db/live_dumps")
146
217
  STATIC_DIR = PROJECT_DIR.join(CONFIG["static_dir"]) rescue nil
147
218
  WP_DIR = PROJECT_DIR.join(CONFIG["wp_clone_dir"]) rescue nil
148
219
  WP_UPLOAD_DIR = WP_DIR.join("wp-content/uploads") rescue nil
@@ -12,12 +12,13 @@ module Sphonglepress
12
12
  def write_config(config)
13
13
  FileUtils.cp(config["sitemap_file"] || "#{::Sphonglepress::App::TEMPLATE_DIR}/config/sitemap.yml", "config/sitemap.yml")
14
14
  File.open("config/settings.yml", 'w') {|f| f.write(config.to_yaml.to_s)}
15
+ FileUtils.cp("#{::Sphonglepress::App::TEMPLATE_DIR}/config/database.yml", "config/database.yml")
15
16
  end
16
17
 
17
18
  def config
18
19
  begin
19
20
  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["db"] = YAML::load(IO.read(::Sphonglepress::CONFIG_DIR.join("database.yml"))) rescue nil
21
22
  c["middleman_dir"] = Pathname.new(c["middleman_dir"])
22
23
  c["wp_clone_dir"] = Pathname.new(c["wp_clone_dir"])
23
24
  return c
@@ -1,24 +1,27 @@
1
+ require 'fileutils'
2
+
1
3
  module Sphonglepress
2
4
  class Export
3
5
  class << self
4
6
  def headers_footers
5
7
  build_dir = ::Sphonglepress::Config.config["middleman_dir"].join("build")
6
- puts build_dir
7
-
8
- default_file = build_dir.join("default.html")
8
+ default_file = build_dir.join("index.html")
9
9
  default_parts = split_file(IO.read(default_file))
10
10
 
11
11
  other_files = Dir["#{build_dir}/*.html"]. #without default.html
12
- reject {|file| Pathname.new(file).basename.to_s == "default.html"}
12
+ reject {|file| Pathname.new(file).basename.to_s == "index.html"}
13
13
 
14
14
  others = {}
15
15
  other_files.each do |file|
16
16
  others[File.basename(file, '.*')] = split_file(IO.read(file))
17
17
  end
18
18
 
19
+ FileUtils.mkdir_p ::Sphonglepress::Config.wp_theme_dir unless Dir.exist? ::Sphonglepress::Config.wp_theme_dir
20
+
19
21
  File.open(::Sphonglepress::Config.wp_theme_dir.join("header.php"), 'w') {|file| file.write(default_parts[:header])}
20
22
  File.open(::Sphonglepress::Config.wp_theme_dir.join("footer.php"), 'w') {|file| file.write(default_parts[:footer])}
21
-
23
+ File.open(::Sphonglepress::Config.wp_theme_dir.join("index.php"), 'w') {|file| file.write(default_parts[:content])}
24
+
22
25
  others.each do |name, parts|
23
26
  File.open(::Sphonglepress::Config.wp_theme_dir.join("header-#{name}.php"), 'w') {|file| file.write(parts[:header])}
24
27
  File.open(::Sphonglepress::Config.wp_theme_dir.join("footer-#{name}.php"), 'w') {|file| file.write(parts[:footer])}
@@ -27,7 +30,10 @@ module Sphonglepress
27
30
  end
28
31
 
29
32
  def files
30
- cmd = "cp -r #{CONFIG["middleman_dir"]}/build/*/ #{::Sphonglepress::WP_DIR}"
33
+ cmd = "cp -r #{CONFIG["middleman_dir"]}/build/*/ #{::Sphonglepress::Config.config["wp_clone_dir"]}"
34
+ `#{cmd}`
35
+ cmd = "cp -r #{CONFIG["middleman_dir"]}/build/stylesheets/*.css #{::Sphonglepress::Config.wp_theme_dir}/"
36
+ puts cmd
31
37
  `#{cmd}`
32
38
  end
33
39
 
@@ -12,11 +12,11 @@ module Sphonglepress
12
12
 
13
13
  def structure(hash, parent=nil)
14
14
  i=0
15
- sorted = hash.keys.sort {|a,b| a[0].to_i <=> b[0].to_i }
15
+ sorted = hash.keys.sort {|a,b| a.split("_").first.to_i <=> b.split("_").first.to_i }
16
16
  pages = []
17
17
  page = nil
18
18
  sorted.each do |key|
19
- title = key[2..key.length].gsub("_", " ").upcase
19
+ title = key[2..key.length].gsub("_", " ")
20
20
  if parent
21
21
  page = Models::Page.new(:post_title => title, :post_type => "page", :menu_order => i, :parent => parent)
22
22
  parent.posts << page
@@ -34,7 +34,7 @@ module Sphonglepress
34
34
  begin
35
35
  if File.exist?(page_content_file)
36
36
  #puts "found #{page_content_file}"
37
- page.post_content = Tilt.new(page_content_file).render
37
+ page.post_content = Tilt.new(page_content_file, :ugly => true).render
38
38
  else
39
39
  puts "Couldnt find #{page_content_file} in the static directory"
40
40
  end
@@ -58,11 +58,12 @@ module Sphonglepress
58
58
  page.posts.each {|p| persist(p)}
59
59
  end
60
60
 
61
- def visit(page)
62
- Visitor.subclasses.each do |v|
63
- v.visit(page)
61
+ def visit(page, visitors = Visitors::Visitor.subclasses)
62
+ visitors.each do |v|
63
+ visitor = v.instance
64
+ visitor.visit(page)
64
65
  page.posts.each do |p|
65
- visit(p)
66
+ visitor.visit(p)
66
67
  end
67
68
  end
68
69
  end
@@ -99,6 +100,9 @@ module Sphonglepress
99
100
  filenames
100
101
  end
101
102
 
103
+ def images_for_page(page)
104
+
105
+ end
102
106
 
103
107
  end
104
108
  end
@@ -3,12 +3,16 @@ module Sphonglepress
3
3
 
4
4
 
5
5
  class << self
6
- def init(site)
6
+ def init(options)
7
+ site = options['middleman_dir']
7
8
  puts "Creating Middleman static site"
8
9
  `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`
10
+
11
+ `rm #{site}/source/*.erb`
12
+ to_copy = Dir["#{Sphonglepress::App::TEMPLATE_DIR}/#{options['template']}/middleman/*.haml"]
13
+ to_copy.each do |c|
14
+ `cp #{c} #{site}/source`
15
+ end
12
16
 
13
17
  end
14
18
 
@@ -18,6 +22,13 @@ module Sphonglepress
18
22
  puts `mm-build`
19
23
  Dir.chdir cwd
20
24
  end
25
+
26
+ def clean
27
+ cwd = Dir.pwd
28
+ Dir.chdir ::Sphonglepress::Config.config["middleman_dir"]
29
+ puts `rm -rf build`
30
+ Dir.chdir cwd
31
+ end
21
32
  end
22
33
 
23
34
  end
@@ -1,3 +1,5 @@
1
+ require 'mime/types'
2
+
1
3
  module Sphonglepress::Models
2
4
  class Attachment < BasePost
3
5
  attr_accessor :file
@@ -8,25 +10,36 @@ module Sphonglepress::Models
8
10
 
9
11
  private
10
12
 
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
13
+ def randomize_filename(file)
17
14
  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}"
15
+ ext = File.extname(file)
16
+ basename = File.basename(file, ext)
17
+ bare_file_name = "#{basename}-#{random}#{ext}"
18
+ end
19
+
20
+ def do_stuff
21
+ return unless @file
22
+
23
+ self.post_type = "attachment"
24
+ now = DateTime.now
25
+ year = now.year
26
+ month = now.month
27
+ monthed_dir = now.strftime("%Y/%m")
28
+ upload_dir = ::Sphonglepress::WP_UPLOAD_DIR.join(monthed_dir)
29
+ bare_file_name = File.basename(@file)
30
+ file_name = upload_dir.join(bare_file_name)
31
+
32
+ file_name = upload_dir.join(bare_filename = randomize_filename(@file)) if File.exist? file_name
33
+
34
+ FileUtils.mkdir_p upload_dir unless Dir.exist? upload_dir
35
+ FileUtils.cp(@file, file_name)
36
+ ext = File.extname(file)
37
+
38
+ self.post_title = self.post_name = bare_file_name
39
+ self.post_status = "inherit"
40
+ self.guid = url = "/wp-content/uploads/#{monthed_dir}/#{bare_file_name}"
41
+ self.post_mime_type = ::MIME::Types.type_for(bare_file_name).first.to_s
22
42
 
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
43
  end
44
+ end
32
45
  end
@@ -12,6 +12,16 @@ module Sphonglepress::Models
12
12
 
13
13
  after_initialize :set_dates
14
14
 
15
+ def url
16
+ current = self
17
+ urls = []
18
+ while (current)
19
+ urls << current.post_title.gsub(/[^ a-zA-Z-]/, "").gsub(" ", "-").downcase
20
+ current = current.parent
21
+ end
22
+ urls.reverse.join("/")
23
+ end
24
+
15
25
  private
16
26
  def set_dates
17
27
  self.post_date = DateTime.now
@@ -1,3 +1,3 @@
1
1
  module Sphonglepress
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,18 @@
1
+ #This visitor checks for a directory in static/attachments with the same location as the relative url for the page, and attaches any files it finds
2
+ module Sphonglepress::Visitors
3
+ class AttachmentVisitor < Visitor
4
+ def visit(page)
5
+ attachments_dir = ::Sphonglepress::STATIC_DIR.join("attachments", page.url)
6
+ Dir["#{attachments_dir}/*"].each do |file|
7
+ attachment = Sphonglepress::Models::Attachment.new
8
+ attachment.file = file
9
+ attachment.post_parent = page.id
10
+ attachment.save
11
+ end
12
+ end
13
+
14
+ #run this once per import
15
+ def once
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,103 @@
1
+ require 'nokogiri'
2
+ require 'haml/html'
3
+ require 'fileutils'
4
+
5
+ #This visitor checks for a site.odt & the config file ("import_from_site_document")
6
+ # and attempts to import thi into the site, based on position of h1s
7
+ module Sphonglepress::Visitors
8
+ class DocumentImporter #< Visitor
9
+ include Singleton
10
+
11
+ #override this to visit each page
12
+ def visit(page)
13
+ debugger
14
+ found = @segments[page.post_title]
15
+ return unless found
16
+ #page.post_content = found
17
+ file = ::Sphonglepress::STATIC_DIR.join("from_document", full_path_for_page(page) << ".html.haml")
18
+ FileUtils.mkdir_p(file.dirname) unless Dir.exist? file.dirname
19
+ File.open(file, 'w') do |f|
20
+ f.write Haml::HTML.new(found, :xhtml => true).render
21
+ end
22
+
23
+ end
24
+
25
+ #run this once per import
26
+ def once
27
+ convert
28
+ source_doc = Sphonglepress::STATIC_DIR.join("document", "site.html")
29
+ cleaned = clean(source_doc)
30
+ @segments = segment cleaned
31
+ end
32
+
33
+ def clean(doc)
34
+
35
+ require ::Sphonglepress::App::APP_DIR.join("vendor", "html_cleaner")
36
+ opts = {
37
+ :remove_attrs => %w(style width height cellpadding cellspacing valign halign),
38
+ :remove_tags => %w(font style meta b),
39
+ :remove_nested_empty_tags => [%w(p br)]
40
+ }
41
+
42
+ cleaner = HTMLCleaner.new(IO.read(doc), opts)
43
+ File.open(Sphonglepress::STATIC_DIR.join("document", "site.cleaned.html"), 'w') do |f|
44
+ f.write(cleaner.render)
45
+ end
46
+ cleaner.render
47
+ end
48
+
49
+ def segment(doc)
50
+ segments = {}
51
+ doc = Nokogiri::HTML(doc)
52
+ headers = doc.css('h1')
53
+ headers.each_with_index do |h, index|
54
+ heading = clean_header(h)
55
+ content = content_until(h, headers[index+1])
56
+ segments[heading] = content.chomp.chomp("\n")
57
+ end
58
+ segments
59
+ end
60
+
61
+ def content_until(from, to)
62
+ siblings = [from.next_sibling]
63
+ while((siblings.last.next_sibling != to) rescue false)
64
+ siblings << siblings.last.next_sibling
65
+ end
66
+ siblings.inject("") {|m, s| m << s.to_s}
67
+ end
68
+
69
+ def clean_header(tag)
70
+ tag.inner_html.chomp.gsub("\n", " ").gsub(/ +/, " ").chomp(":").gsub(/^[0-9]*\./, "").strip rescue ""
71
+ end
72
+
73
+ def convert
74
+ source_dir = Sphonglepress::STATIC_DIR.join("document")
75
+ source_doc = source_dir.join("site.odt")
76
+ puts "SOURCE DOC: #{source_doc}" if File.exist? source_doc
77
+ cmd = "libreoffice -headless -convert-to html -outdir #{source_dir} #{source_doc}"
78
+ `#{cmd}`
79
+ end
80
+
81
+ # http://stackoverflow.com/questions/1939333/how-to-make-a-ruby-string-safe-for-a-filesystem
82
+ def sanitize_filename(filename)
83
+ filename.strip.gsub(/^.*(\\|\/)/, '').gsub(/[^0-9A-Za-z.\-]/, '-')
84
+ end
85
+
86
+ def full_path_for_page(page)
87
+ return "" unless page
88
+ path = full_path_for_page(page.parent)
89
+ join = path.length > 0 ? "_" : ""
90
+ return "#{path << join}" << "#{sanitize_filename(page.post_title)}"
91
+ end
92
+
93
+ def filenames_for_page(page)
94
+ filenames = []
95
+
96
+ filenames << full_path_for_page(page)
97
+ page.posts.each do |child|
98
+ filenames.concat filenames_for_page(child)
99
+ end
100
+ filenames
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,13 @@
1
+ module Sphonglepress::Visitors
2
+ class Visitor
3
+ include Singleton
4
+
5
+ #override this to visit each page
6
+ def visit(page)
7
+ end
8
+
9
+ #run this once per import
10
+ def once
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,61 @@
1
+ require 'fssm'
2
+
3
+ module Sphonglepress
4
+ class Watcher
5
+ def initialize(app)
6
+ @app = app
7
+ end
8
+
9
+ def watch
10
+ myself = self
11
+ while true do
12
+ begin
13
+ FSSM.monitor do
14
+ path ::Sphonglepress::STATIC_DIR do
15
+
16
+ update {|base, relative| myself.static }
17
+ delete {|base, relative| myself.static }
18
+ create {|base, relative| mysqlf.static }
19
+ end
20
+
21
+ path ::Sphonglepress::LAYOUT_DIR.join("source") do
22
+ update {|base, relative| myself.middleman }
23
+ delete {|base, relative| myself.middleman }
24
+ create {|base, relative| myself.middleman }
25
+ end
26
+
27
+ path ::Sphonglepress::CONFIG_DIR do
28
+ update {|base, relative| myself.config_sitemap }
29
+ delete {|base, relative| myself.config_sitemap }
30
+ create {|base, relative| myself.config_sitemap }
31
+ end
32
+
33
+ end
34
+
35
+ rescue Exception => e
36
+
37
+ end
38
+ end
39
+ end
40
+
41
+ def static
42
+ puts "Static dir changed, reloading site content"
43
+ @app.load_db
44
+ @app.import_site
45
+ puts "DONE"
46
+
47
+ end
48
+
49
+ def middleman
50
+ puts "Middleman directory changed, reloading static assets"
51
+ @app.export
52
+ puts "DONE"
53
+ end
54
+
55
+ def config_sitemap
56
+ puts "Config dir changed, Creating any static files not created"
57
+ @app.create_static_files
58
+ puts "DONE"
59
+ end
60
+ end
61
+ end
@@ -27,5 +27,11 @@ Gem::Specification.new do |s|
27
27
  s.add_dependency('activerecord')
28
28
  s.add_dependency('tilt')
29
29
  s.add_dependency('haml')
30
+ s.add_dependency('mysql')
31
+ s.add_dependency('fssm')
32
+ #FIXME: move html-cleaner into gem & remove this
33
+ s.add_dependency('hpricot')
34
+ s.add_dependency('mime-types')
35
+
30
36
 
31
37
  end
@@ -1,12 +1,7 @@
1
- # SQLite version 3.x
2
- # gem install sqlite3
1
+ # Edit this to your needs
3
2
  development:
4
3
  adapter: mysql2
5
4
  database: development
6
5
  pool: 5
7
6
  timeout: 5000
8
-
9
- adapter: mysql2
10
- database: production
11
- pool: 5
12
- timeout: 5000
7
+ username: root
@@ -1,7 +1,8 @@
1
1
  ---
2
- wp_git_tag: v3.1.3
2
+ wp_git_tag: v3.2.1
3
3
  wp_clone_dir: wordpress
4
- wp_git_url: https://github.com/dxw/wordpress
5
- wp_theme_dir: twentyten
4
+ wp_git_url: https://github.com/nhemsley/wordpress
5
+ wp_theme_dir: default
6
6
  middleman_dir: middleman
7
7
  static_dir: static
8
+ template: splash
@@ -0,0 +1 @@
1
+ 0_HOME: 0
@@ -0,0 +1,8 @@
1
+ :plain
2
+ <?php get_header("home"); ?>
3
+ <?php if (have_posts()) : ?>
4
+ <?php while (have_posts()) : the_post(); ?>
5
+ <?php the_content(); ?>
6
+ <?php endwhile; ?>
7
+ <?php endif; ?>
8
+ <?php get_footer("home"); ?>
@@ -0,0 +1,8 @@
1
+ :plain
2
+ <?php get_header(); ?>
3
+ <?php if (have_posts()) : ?>
4
+ <?php while (have_posts()) : the_post(); ?>
5
+ <?php the_content(); ?>
6
+ <?php endwhile; ?>
7
+ <?php endif; ?>
8
+ <?php get_footer(); ?>
@@ -0,0 +1,11 @@
1
+ class Visitor < Sphonglepress::Visitor
2
+ class << self
3
+ #override this to visit each page
4
+ def visit(page)
5
+ end
6
+
7
+ #run this once per import
8
+ def once
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,47 @@
1
+ require 'hpricot'
2
+ require 'ruby-debug'
3
+
4
+ class HTMLCleaner
5
+ def initialize(html, options = nil)
6
+ @html = html
7
+ @doc = Hpricot(@html)
8
+ @options = options
9
+ end
10
+
11
+ def remove_attr(attr)
12
+ @doc.search("[@#{attr}]").each do |e|
13
+ e.remove_attribute(attr)
14
+ end
15
+ end
16
+
17
+ def remove_tag(tag)
18
+ els = @doc.search(tag)
19
+ els.collect!{|node| node if node.children == nil}.compact.remove
20
+
21
+ @doc.search(tag).each do |e|
22
+ inner = e.children
23
+ parent = e.parent
24
+ if inner
25
+ parent.replace_child(e, inner)
26
+ end
27
+ end
28
+ end
29
+
30
+ def remove_nested_empty_tags(first, second)
31
+ els = @doc.search(first)
32
+ remove = els.select do |el|
33
+ ret = true
34
+ ret = false unless el.children.detect {|ch| ch.name == second && ch.inner_html.chomp == ""}
35
+ ret
36
+ end
37
+ remove.each {|r| r.parent.children.delete(r) }
38
+ end
39
+
40
+ def render
41
+ @options[:remove_attrs].each { |a| remove_attr a } if @options[:remove_attrs]
42
+ @options[:remove_tags].each { |a| remove_tag a } if @options[:remove_tags]
43
+ @options[:remove_nested_empty_tags].each { |a| remove_nested_empty_tags(a[0], a[1]) } if @options[:remove_nested_empty_tags]
44
+
45
+ @doc.to_s
46
+ end
47
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sphonglepress
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-24 00:00:00.000000000Z
12
+ date: 2011-10-19 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
16
- requirement: &84388670 !ruby/object:Gem::Requirement
16
+ requirement: &16288120 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *84388670
24
+ version_requirements: *16288120
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: middleman
27
- requirement: &84388460 !ruby/object:Gem::Requirement
27
+ requirement: &16287700 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *84388460
35
+ version_requirements: *16287700
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: activerecord
38
- requirement: &84388250 !ruby/object:Gem::Requirement
38
+ requirement: &16287280 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *84388250
46
+ version_requirements: *16287280
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: tilt
49
- requirement: &84388040 !ruby/object:Gem::Requirement
49
+ requirement: &16286860 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *84388040
57
+ version_requirements: *16286860
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: haml
60
- requirement: &84387830 !ruby/object:Gem::Requirement
60
+ requirement: &16286440 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,51 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *84387830
68
+ version_requirements: *16286440
69
+ - !ruby/object:Gem::Dependency
70
+ name: mysql
71
+ requirement: &16286020 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: *16286020
80
+ - !ruby/object:Gem::Dependency
81
+ name: fssm
82
+ requirement: &16285600 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :runtime
89
+ prerelease: false
90
+ version_requirements: *16285600
91
+ - !ruby/object:Gem::Dependency
92
+ name: hpricot
93
+ requirement: &16285180 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ type: :runtime
100
+ prerelease: false
101
+ version_requirements: *16285180
102
+ - !ruby/object:Gem::Dependency
103
+ name: mime-types
104
+ requirement: &16284760 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :runtime
111
+ prerelease: false
112
+ version_requirements: *16284760
69
113
  description: Sphonglepress is a command line utility for interacting with & making
70
114
  the task of importing content into a wordpress site
71
115
  email:
@@ -98,7 +142,10 @@ files:
98
142
  - lib/sphonglepress/models/page.rb
99
143
  - lib/sphonglepress/models/post.rb
100
144
  - lib/sphonglepress/version.rb
101
- - lib/sphonglepress/visitor.rb
145
+ - lib/sphonglepress/visitors/attachment_visitor.rb
146
+ - lib/sphonglepress/visitors/document_importer.rb
147
+ - lib/sphonglepress/visitors/visitor.rb
148
+ - lib/sphonglepress/watcher.rb
102
149
  - script/console
103
150
  - script/destroy
104
151
  - script/generate
@@ -106,10 +153,13 @@ files:
106
153
  - templates/config/database.yml
107
154
  - templates/config/settings.yml
108
155
  - templates/config/sitemap.yml
109
- - templates/middleman/default.html.haml
110
- - templates/middleman/layout.haml
156
+ - templates/splash/middleman/home.html.haml
157
+ - templates/splash/middleman/index.html.haml
158
+ - templates/splash/middleman/layout.haml
159
+ - templates/splash/visitors/splash.rb
111
160
  - test/test_helper.rb
112
161
  - test/test_sphonglepress.rb
162
+ - vendor/html_cleaner.rb
113
163
  homepage: ''
114
164
  licenses: []
115
165
  post_install_message:
@@ -130,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
180
  version: '0'
131
181
  requirements: []
132
182
  rubyforge_project: sphonglepress
133
- rubygems_version: 1.8.6
183
+ rubygems_version: 1.8.10
134
184
  signing_key:
135
185
  specification_version: 3
136
186
  summary: Gem for populating wordpress
@@ -1,13 +0,0 @@
1
- module Sphonglepress
2
- class Visitor
3
- class << self
4
- #override this to visit each page
5
- def visit(page)
6
- end
7
-
8
- #run this once per import
9
- def once
10
- end
11
- end
12
- end
13
- end
File without changes