Browse code

Added warning if users try to add posts, pages, or generate their site before installing an Octopress theme, fixes #116

Brandon Mathis authored on 25/08/2011 at 14:36:57
Showing 1 changed files
... ...
@@ -1,6 +1,5 @@
1 1
 require "rubygems"
2 2
 require "bundler/setup"
3
-require "stringex"
4 3
 
5 4
 ## -- Rsync Deploy config -- ##
6 5
 # Be sure your public key is listed in your server's ~/.ssh/authorized_keys file
... ...
@@ -44,50 +43,32 @@ end
44 44
 
45 45
 desc "Generate jekyll site"
46 46
 task :generate do
47
+  raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(source_dir)
47 48
   puts "## Generating Site with Jekyll"
48 49
   system "jekyll"
49 50
 end
50 51
 
51 52
 desc "Watch the site and regenerate when it changes"
52 53
 task :watch do
53
-  puts "Starting to watch source with Jekyll and Compass."
54
-  jekyllPid = spawn("jekyll --auto")
55
-  compassPid = spawn("compass watch")
56
-
57
-  trap("INT") {
58
-	Process.kill(9, jekyllPid)
59
-	Process.kill(9, compassPid)
60
-	exit 0
61
-  }
62
-
63
-  Process.wait
54
+  raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(source_dir)
55
+  system "trap 'kill $jekyllPid $compassPid' Exit; jekyll --auto & jekyllPid=$!; compass watch & compassPid=$!; wait"
64 56
 end
65 57
 
66 58
 desc "preview the site in a web browser"
67 59
 task :preview do
68
-  puts "Starting to watch source with Jekyll and Compass. Starting Rack on port #{server_port}"
69
-  jekyllPid = spawn("jekyll --auto")
70
-  compassPid = spawn("compass watch")
71
-  rackupPid = spawn("rackup --port #{server_port}")
72
-
73
-  trap("INT") {
74
-	Process.kill(9, jekyllPid)
75
-	Process.kill(9, compassPid)
76
-	Process.kill(9, rackupPid)
77
-	exit 0
78
-  }
79
-
80
-  Process.wait
60
+  raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(source_dir)
61
+  system "trap 'kill $jekyllPid $compassPid $rackPid' Exit; jekyll --auto & jekyllPid=$!; compass watch & compassPid=$!; rackup --port #{server_port} & rackPid=$!; wait"
81 62
 end
82 63
 
83 64
 # usage rake new_post[my-new-post] or rake new_post['my new post'] or rake new_post (defaults to "new-post")
84 65
 desc "Begin a new post in #{source_dir}/#{posts_dir}"
85 66
 task :new_post, :title do |t, args|
67
+  raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(source_dir)
86 68
   require './plugins/titlecase.rb'
87 69
   mkdir_p "#{source_dir}/#{posts_dir}"
88 70
   args.with_defaults(:title => 'new-post')
89 71
   title = args.title
90
-  filename = "#{source_dir}/#{posts_dir}/#{Time.now.strftime('%Y-%m-%d')}-#{title.to_url}.#{new_post_ext}"
72
+  filename = "#{source_dir}/#{posts_dir}/#{Time.now.strftime('%Y-%m-%d')}-#{title.downcase.gsub(/&/,'and').gsub(/[,'":\?!\(\)\[\]]/,'').gsub(/[\W\.]/, '-').gsub(/-+$/,'')}.#{new_post_ext}"
91 73
   puts "Creating new post: #{filename}"
92 74
   open(filename, 'w') do |post|
93 75
     system "mkdir -p #{source_dir}/#{posts_dir}/";
... ...
@@ -104,6 +85,7 @@ end
104 104
 # usage rake new_page[my-new-page] or rake new_page[my-new-page.html] or rake new_page (defaults to "new-page.markdown")
105 105
 desc "Create a new page in #{source_dir}/(filename)/index.#{new_page_ext}"
106 106
 task :new_page, :filename do |t, args|
107
+  raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(source_dir)
107 108
   require './plugins/titlecase.rb'
108 109
   args.with_defaults(:filename => 'new-page')
109 110
   page_dir = source_dir
... ...
@@ -147,7 +129,7 @@ end
147 147
 
148 148
 desc "Clean out caches: _code_cache, _gist_cache, .sass-cache"
149 149
 task :clean do
150
-  rm_rf ["_code_cache/**", "_gist_cache/**", ".sass-cache/**", "source/stylesheets/screen.css"]
150
+  system "rm -rf _code_cache/** _gist_cache/** .sass-cache/** source/stylesheets/screen.css"
151 151
 end
152 152
 
153 153
 desc "Move sass to sass.old, install sass theme updates, replace sass/custom with sass.old/custom"
... ...
@@ -155,11 +137,11 @@ task :update_style, :theme do |t, args|
155 155
   theme = args.theme || 'classic'
156 156
   if File.directory?("sass.old")
157 157
     puts "removed existing sass.old directory"
158
-    rm_r "sass.old", :secure=>true
158
+    system "rm -r sass.old"
159 159
   end
160
-  mv "sass", "sass.old"
160
+  system "mv sass sass.old"
161 161
   puts "## Moved styles into sass.old/"
162
-  cp_r "#{themes_dir}/"+theme+"/sass/", "sass"
162
+  system "mkdir -p sass; cp -R #{themes_dir}/"+theme+"/sass/* sass/"
163 163
   cp_r "sass.old/custom/.", "sass/custom"
164 164
   puts "## Updated Sass ##"
165 165
 end
... ...
@@ -169,16 +151,15 @@ task :update_source, :theme do |t, args|
169 169
   theme = args.theme || 'classic'
170 170
   if File.directory?("#{source_dir}.old")
171 171
     puts "removed existing #{source_dir}.old directory"
172
-    rm_r "#{source_dir}.old", :secure=>true
172
+    system "rm -r #{source_dir}.old"
173 173
   end
174
-  mv source_dir, "#{source_dir}.old"
174
+  system "mv #{source_dir} #{source_dir}.old"
175 175
   puts "moved #{source_dir} into #{source_dir}.old/"
176
-  mkdir_p source_dir
177
-  cp_r "#{themes_dir}/"+theme+"/source/.", source_dir
178
-  cp_r "#{source_dir}.old/.", source_dir, :preserve=>true
179
-  cp_r "#{source_dir}.old/_includes/custom/.", "#{source_dir}/_includes/custom/"
180
-  mv "#{source_dir}/index.html", "#{blog_index_dir}", :force=>true if blog_index_dir != source_dir
181
-  cp "#{source_dir}.old/index.html", source_dir if blog_index_dir != source_dir
176
+  system "mkdir -p #{source_dir}; cp -R #{themes_dir}/"+theme+"/source/. #{source_dir}"
177
+  system "cp -Rn #{source_dir}.old/. #{source_dir}"
178
+  system "cp -Rf #{source_dir}.old/_includes/custom/. #{source_dir}/_includes/custom/"
179
+  system "mv -f #{source_dir}/index.html #{blog_index_dir}" if blog_index_dir != source_dir
180
+  system "cp -f #{source_dir}.old/index.html #{source_dir}" if blog_index_dir != source_dir
182 181
   puts "## Updated #{source_dir} ##"
183 182
 end
184 183
 
... ...
@@ -187,19 +168,7 @@ end
187 187
 ##############
188 188
 
189 189
 desc "Default deploy task"
190
-multitask :deploy => [:copydot, "#{deploy_default}"] do
191
-end
192
-
193
-desc "copy dot files for deployment"
194
-task :copydot do
195
-  cd "#{source_dir}" do
196
-    exclusions = [".", "..", ".DS_Store"]
197
-    Dir[".*"].each do |file|
198
-      if !File.directory?(file) && !exclusions.include?(file)
199
-        cp(file, "../#{public_dir}");
200
-      end
201
-    end
202
-  end
190
+task :deploy => "#{deploy_default}" do
203 191
 end
204 192
 
205 193
 desc "Deploy website via rsync"
... ...
@@ -209,7 +178,7 @@ task :rsync do
209 209
 end
210 210
 
211 211
 desc "deploy public directory to github pages"
212
-multitask :push do
212
+task :push do
213 213
   puts "## Deploying branch to Github Pages "
214 214
   (Dir["#{deploy_dir}/*"]).each { |f| rm_rf(f) }
215 215
   system "cp -R #{public_dir}/* #{deploy_dir}"