Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 381 lines (335 sloc) 12.657 kb
4c18e3c1 »
2011-12-30 version 0.0.1
1 require "rubygems"
2 require 'rake'
53a801b0 »
2012-01-31 Implement theme installer v 0.1.0
3 require 'yaml'
4c18e3c1 »
2011-12-30 version 0.0.1
4
9d7d4eb4 »
2012-01-18 reorganize rakefile
5 SOURCE = "."
6 CONFIG = {
4c29c7ed »
2012-02-03 bump version : 0.2.0
7 'version' => "0.2.0",
9d7d4eb4 »
2012-01-18 reorganize rakefile
8 'themes' => File.join(SOURCE, "_includes", "themes"),
9 'layouts' => File.join(SOURCE, "_layouts"),
10 'posts' => File.join(SOURCE, "_posts"),
53a801b0 »
2012-01-31 Implement theme installer v 0.1.0
11 'post_ext' => "md",
12 'theme_package_version' => "0.1.0"
9d7d4eb4 »
2012-01-18 reorganize rakefile
13 }
6ee3125c »
2012-01-16 adding the new_post task, with bugs fixed which were pointed out by @…
14
53a801b0 »
2012-01-31 Implement theme installer v 0.1.0
15 # Path configuration helper
16 module JB
17 class Path
18 SOURCE = "."
19 Paths = {
20 :layouts => "_layouts",
21 :themes => "_includes/themes",
22 :theme_assets => "assets/themes",
23 :theme_packages => "_theme_packages",
24 :posts => "_posts"
25 }
26
27 def self.base
28 SOURCE
29 end
30
31 # build a path relative to configured path settings.
32 def self.build(path, opts = {})
33 opts[:root] ||= SOURCE
34 path = "#{opts[:root]}/#{Paths[path.to_sym]}/#{opts[:node]}".split("/")
35 path.compact!
36 File.__send__ :join, path
37 end
38
39 end #Path
40 end #JB
41
f52ff5aa »
2012-01-23 Refactor new post rake task
42 # Usage: rake post title="A Title"
9d7d4eb4 »
2012-01-18 reorganize rakefile
43 desc "Begin a new post in #{CONFIG['posts']}"
f52ff5aa »
2012-01-23 Refactor new post rake task
44 task :post do
9d7d4eb4 »
2012-01-18 reorganize rakefile
45 abort("rake aborted: '#{CONFIG['posts']}' directory not found.") unless FileTest.directory?(CONFIG['posts'])
f52ff5aa »
2012-01-23 Refactor new post rake task
46 title = ENV["title"] || "new-post"
47 slug = title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
9d7d4eb4 »
2012-01-18 reorganize rakefile
48 filename = File.join(CONFIG['posts'], "#{Time.now.strftime('%Y-%m-%d')}-#{slug}.#{CONFIG['post_ext']}")
6ee3125c »
2012-01-16 adding the new_post task, with bugs fixed which were pointed out by @…
49 if File.exist?(filename)
50 abort("rake aborted!") if ask("#{filename} already exists. Do you want to overwrite?", ['y', 'n']) == 'n'
51 end
9d7d4eb4 »
2012-01-18 reorganize rakefile
52
6ee3125c »
2012-01-16 adding the new_post task, with bugs fixed which were pointed out by @…
53 puts "Creating new post: #{filename}"
54 open(filename, 'w') do |post|
55 post.puts "---"
56 post.puts "layout: post"
f52ff5aa »
2012-01-23 Refactor new post rake task
57 post.puts "title: \"#{title.gsub(/-/,' ')}\""
6ee3125c »
2012-01-16 adding the new_post task, with bugs fixed which were pointed out by @…
58 post.puts "category: "
59 post.puts "tags: []"
60 post.puts "---"
f52ff5aa »
2012-01-23 Refactor new post rake task
61 post.puts "{% include JB/setup %}"
6ee3125c »
2012-01-16 adding the new_post task, with bugs fixed which were pointed out by @…
62 end
f52ff5aa »
2012-01-23 Refactor new post rake task
63 end # task :post
6ee3125c »
2012-01-16 adding the new_post task, with bugs fixed which were pointed out by @…
64
6d0e38b3 »
2012-01-23 Add rake task to create pages
65 # Usage: rake page name="about.html"
66 # You can also specify a sub-directory path.
67 # If you don't specify a file extention we create an index.html at the path specified
68 desc "Create a new page."
69 task :page do
70 name = ENV["name"] || "new-page.md"
71 filename = File.join(SOURCE, "#{name}")
72 filename = File.join(filename, "index.html") if File.extname(filename) == ""
73 title = File.basename(filename, File.extname(filename)).gsub(/[\W\_]/, " ").gsub(/\b\w/){$&.upcase}
74 if File.exist?(filename)
75 abort("rake aborted!") if ask("#{filename} already exists. Do you want to overwrite?", ['y', 'n']) == 'n'
76 end
77
78 mkdir_p File.dirname(filename)
79 puts "Creating new page: #{filename}"
80 open(filename, 'w') do |post|
81 post.puts "---"
82 post.puts "layout: page"
83 post.puts "title: \"#{title}\""
84 post.puts "---"
85 post.puts "{% include JB/setup %}"
86 end
87 end # task :page
88
223a9ca6 »
2012-01-12 add rake preview for development
89 desc "Launch preview environment"
90 task :preview do
91 system "jekyll --auto --server"
9d7d4eb4 »
2012-01-18 reorganize rakefile
92 end # task :preview
93
533d840a »
2012-02-01 Namespace 'switch_theme'
94 # Public: Alias - Maintains backwards compatability for theme switching.
95 task :switch_theme => "theme:switch"
96
53a801b0 »
2012-01-31 Implement theme installer v 0.1.0
97 namespace :theme do
98
533d840a »
2012-02-01 Namespace 'switch_theme'
99 # Public: Switch from one theme to another for your blog.
100 #
101 # name - String, Required. name of the theme you want to switch to.
102 # The the theme must be installed into your JB framework.
103 #
104 # Examples
105 #
106 # rake theme:switch name="the-program"
107 #
108 # Returns Success/failure messages.
109 desc "Switch between Jekyll-bootstrap themes."
110 task :switch do
111 theme_name = ENV["name"].to_s
112 theme_path = File.join(CONFIG['themes'], theme_name)
113 settings_file = File.join(theme_path, "settings.yml")
114 non_layout_files = ["settings.yml"]
115
116 abort("rake aborted: name cannot be blank") if theme_name.empty?
117 abort("rake aborted: '#{theme_path}' directory not found.") unless FileTest.directory?(theme_path)
118 abort("rake aborted: '#{CONFIG['layouts']}' directory not found.") unless FileTest.directory?(CONFIG['layouts'])
119
120 Dir.glob("#{theme_path}/*") do |filename|
121 next if non_layout_files.include?(File.basename(filename).downcase)
122 puts "Generating '#{theme_name}' layout: #{File.basename(filename)}"
123
124 open(File.join(CONFIG['layouts'], File.basename(filename)), 'w') do |page|
125 if File.basename(filename, ".html").downcase == "default"
126 page.puts "---"
127 page.puts File.read(settings_file) if File.exist?(settings_file)
128 page.puts "---"
129 else
130 page.puts "---"
131 page.puts "layout: default"
132 page.puts "---"
133 end
134 page.puts "{% include JB/setup %}"
135 page.puts "{% include themes/#{theme_name}/#{File.basename(filename)} %}"
136 end
137 end
fdfb9c4c »
2012-02-01 Fix prompt complaining that directories already exist
138
139 puts "=> Theme successfully switched!"
140 puts "=> Reload your web-page to check it out =)"
533d840a »
2012-02-01 Namespace 'switch_theme'
141 end # task :switch
142
21b64c2b »
2012-02-01 Update theme packager methods
143 # Public: Install a theme using the theme packager.
144 # Version 0.1.0 simple 1:1 file matching.
145 #
146 # git - String, Optional path to the git repository of the theme to be installed.
147 # name - String, Optional name of the theme you want to install.
148 # Passing name requires that the theme package already exist.
149 #
150 # Examples
151 #
152 # rake theme:install git="https://github.com/jekyllbootstrap/theme-twitter.git"
153 # rake theme:install name="cool-theme"
154 #
155 # Returns Success/failure messages.
53a801b0 »
2012-01-31 Implement theme installer v 0.1.0
156 desc "Install theme"
157 task :install do
21b64c2b »
2012-02-01 Update theme packager methods
158 if ENV["git"]
159 manifest = theme_from_git_url(ENV["git"])
160 name = manifest["name"]
161 else
162 name = ENV["name"].to_s.downcase
163 end
53a801b0 »
2012-01-31 Implement theme installer v 0.1.0
164
21b64c2b »
2012-02-01 Update theme packager methods
165 packaged_theme_path = JB::Path.build(:theme_packages, :node => name)
166
fdfb9c4c »
2012-02-01 Fix prompt complaining that directories already exist
167 abort("rake aborted!
168 => ERROR: 'name' cannot be blank") if name.empty?
169 abort("rake aborted!
170 => ERROR: '#{packaged_theme_path}' directory not found.
171 => Installable themes can be added via git. You can find some here: http://github.com/jekyllbootstrap
172 => To download+install run: `rake theme:install git='[PUBLIC-CLONE-URL]'`
173 => example : rake theme:install git='git@github.com:jekyllbootstrap/theme-the-program.git'
174 ") unless FileTest.directory?(packaged_theme_path)
53a801b0 »
2012-01-31 Implement theme installer v 0.1.0
175
21b64c2b »
2012-02-01 Update theme packager methods
176 manifest = verify_manifest(packaged_theme_path)
177
53a801b0 »
2012-01-31 Implement theme installer v 0.1.0
178 # Get relative paths to packaged theme files
fdfb9c4c »
2012-02-01 Fix prompt complaining that directories already exist
179 # Exclude directories as they'll be recursively created. Exclude meta-data files.
53a801b0 »
2012-01-31 Implement theme installer v 0.1.0
180 packaged_theme_files = []
fdfb9c4c »
2012-02-01 Fix prompt complaining that directories already exist
181 FileUtils.cd(packaged_theme_path) {
182 Dir.glob("**/*.*") { |f|
183 next if ( FileTest.directory?(f) || f =~ /^(manifest|readme|packager)/i )
184 packaged_theme_files << f
185 }
186 }
53a801b0 »
2012-01-31 Implement theme installer v 0.1.0
187
188 # Mirror each file into the framework making sure to prompt if already exists.
189 packaged_theme_files.each do |filename|
190 file_install_path = File.join(JB::Path.base, filename)
191 if File.exist? file_install_path
192 next if ask("#{file_install_path} already exists. Do you want to overwrite?", ['y', 'n']) == 'n'
193 else
194 mkdir_p File.dirname(file_install_path)
195 cp_r File.join(packaged_theme_path, filename), file_install_path
196 end
197 end
198
199 puts "=> #{name} theme has been installed!"
200 puts "=> ---"
201 if ask("=> Want to switch themes now?", ['y', 'n']) == 'y'
202 system("rake switch_theme name='#{name}'")
203 end
204 end
21b64c2b »
2012-02-01 Update theme packager methods
205
206 # Public: Package a theme using the theme packager.
207 # The theme must be structured using valid JB API.
208 # In other words packaging is essentially the reverse of installing.
209 #
210 # name - String, Required name of the theme you want to package.
211 #
212 # Examples
213 #
214 # rake theme:package name="twitter"
215 #
216 # Returns Success/failure messages.
53a801b0 »
2012-01-31 Implement theme installer v 0.1.0
217 desc "Package theme"
218 task :package do
219 name = ENV["name"].to_s.downcase
220 theme_path = JB::Path.build(:themes, :node => name)
221 asset_path = JB::Path.build(:theme_assets, :node => name)
222
223 abort("rake aborted: name cannot be blank") if name.empty?
224 abort("rake aborted: '#{theme_path}' directory not found.") unless FileTest.directory?(theme_path)
225 abort("rake aborted: '#{asset_path}' directory not found.") unless FileTest.directory?(asset_path)
226
227 ## Mirror theme's template directory (_includes)
228 packaged_theme_path = JB::Path.build(:themes, :root => JB::Path.build(:theme_packages, :node => name))
229 mkdir_p packaged_theme_path
230 cp_r theme_path, packaged_theme_path
231
232 ## Mirror theme's asset directory
233 packaged_theme_assets_path = JB::Path.build(:theme_assets, :root => JB::Path.build(:theme_packages, :node => name))
234 mkdir_p packaged_theme_assets_path
235 cp_r asset_path, packaged_theme_assets_path
236
237 ## Log packager version
238 packager = {"packager" => {"version" => CONFIG["theme_package_version"].to_s } }
239 open(JB::Path.build(:theme_packages, :node => "#{name}/packager.yml"), "w") do |page|
240 page.puts packager.to_yaml
241 end
242
243 puts "=> '#{name}' theme is packaged and available at: #{JB::Path.build(:theme_packages, :node => name)}"
244 end
245
246 end # end namespace :theme
247
39a97e81 »
2012-02-24 custom rake tasks to parse haml_layouts, launch an interactive server…
248 # Begin custom rake tasks for haml/css/coffeescript tools
249
9b742727 »
2012-02-25 minimal theme updated, added external js and added minimal them content
250 desc "Parse haml includes"
251 task :parse_haml_includes do
252 print "Parsing Haml includes..."
253 system(%{
254 cd _includes/themes/minimal/haml &&
255 for f in *.haml; do [ -e $f ] && haml $f ../${f%.haml}.html; done
256 })
257 puts "done."
258 end
259
39a97e81 »
2012-02-24 custom rake tasks to parse haml_layouts, launch an interactive server…
260 desc "Parse haml layouts"
9b742727 »
2012-02-25 minimal theme updated, added external js and added minimal them content
261 task :parse_haml_layouts do
39a97e81 »
2012-02-24 custom rake tasks to parse haml_layouts, launch an interactive server…
262 print "Parsing Haml layouts..."
263 system(%{
264 cd _layouts/haml &&
265 for f in *.haml; do [ -e $f ] && haml $f ../${f%.haml}.html; done
266 })
267 puts "done."
268 end
269
e3466ecc »
2012-02-24 dev is shorter
270 desc "Launch preview dev environment"
271 task :dev do
39a97e81 »
2012-02-24 custom rake tasks to parse haml_layouts, launch an interactive server…
272 Rake::Task["parse_haml"].invoke
273 system "jekyll --auto --server"
274 end
275
276 desc "Build site"
277 task :build do |task, args|
9b742727 »
2012-02-25 minimal theme updated, added external js and added minimal them content
278 Rake::Task["parse_haml_includes"].invoke
279 Rake::Task["parse_haml_layouts"].invoke
39a97e81 »
2012-02-24 custom rake tasks to parse haml_layouts, launch an interactive server…
280 system "jekyll"
281 end
282
bd66f316 »
2012-02-24 moar sweet rake files
283 # Create a New Post File
284 # usage: rake write["Post Title Goes Here",category]
285 desc "Given a title as an argument, create a new post file"
286 task :write, [:title, :category] do |t, args|
287 filename = "#{Time.now.strftime('%Y-%m-%d')}-#{args.title.gsub(/\s/, '_').downcase}.markdown"
288 path = File.join("_posts", filename)
289 if File.exist? path; raise RuntimeError.new("Won't clobber #{path}"); end
290 File.open(path, 'w') do |file|
291 file.write <<-EOS
292 ---
293 layout: post
294 category: #{args.category}
295 title: #{args.title}
296 date: #{Time.now.strftime('%Y-%m-%d %k:%M:%S')}
297 ---
298 EOS
299 end
300 puts "Now open #{path} in an editor."
301 end
302
303 # Combine and Minify CSS and JavaScript
304 # DEPENDENCY: Juicer: http://cjohansen.no/en/ruby/juicer_a_css_and_javascript_packaging_tool
305 # rake juicer:css # to combine master.css located at _site/style/master.css
306 # rake juicer:js # to combine master.js located at _site/js/master.js
307 namespace :juicer do
308 desc 'Merges stylesheets'
309 task :css => :"juicer:js" do
310 sh 'juicer merge --force _site/style/master.css'
311 end
312 desc 'Merges JavaScripts'
313 task :js do
314 sh 'juicer merge -i --force _site/js/master.js'
315 end
316 end
317
318 # Upload Files with RSync
319 # DEPENDENCY: rsync
320 # rake rsync:dryrun # If you're not sure, do dry-run
321 # rake rsync:live # Rsync to your server
322 namespace :rsync do
323 desc "--dry-run rsync"
324 task :dryrun do
325 system('rsync _site/ -ave ssh --dry-run --delete USERNAME@YOURDOMAIN.com:YOURHOSTDIRECTORY')
326 end
327 desc "rsync"
328 task :live do
329 system('rsync _site/ -ave ssh --delete USERNAME@YOURDOMAIN.com:YOURHOSTDIRECTORY')
330 end
331 end
332
333
21b64c2b »
2012-02-01 Update theme packager methods
334 # Internal: Download and process a theme from a git url.
335 # Notice we don't know the name of the theme until we look it up in the manifest.
336 # So we'll have to change the folder name once we get the name.
337 #
338 # url - String, Required url to git repository.
339 #
340 # Returns theme manifest hash
341 def theme_from_git_url(url)
342 tmp_path = JB::Path.build(:theme_packages, :node => "_tmp")
343 system("git clone #{url} #{tmp_path}")
344 manifest = verify_manifest(tmp_path)
345 new_path = JB::Path.build(:theme_packages, :node => manifest["name"])
346 if File.exist?(new_path) && ask("=> #{new_path} theme package already exists. Override?", ['y', 'n']) == 'n'
347 remove_dir(tmp_path)
348 abort("rake aborted: '#{manifest["name"]}' already exists as theme package.")
349 end
350
351 remove_dir(new_path) if File.exist?(new_path)
352 mv(tmp_path, new_path)
353 manifest
354 end
355
356 # Internal: Process theme package manifest file.
357 #
358 # theme_path - String, Required. File path to theme package.
359 #
360 # Returns theme manifest hash
361 def verify_manifest(theme_path)
362 manifest = File.join(theme_path, "manifest.yml")
363 abort("rake aborted: repo must contain valid manifest.yml") unless File.exist? manifest
364 manifest = YAML.load_file(manifest)
365 manifest
366 end
53a801b0 »
2012-01-31 Implement theme installer v 0.1.0
367
9d7d4eb4 »
2012-01-18 reorganize rakefile
368 def ask(message, valid_options)
369 if valid_options
370 answer = get_stdin("#{message} #{valid_options.to_s.gsub(/"/, '').gsub(/, /,'/')} ") while !valid_options.include?(answer)
371 else
372 answer = get_stdin(message)
373 end
374 answer
223a9ca6 »
2012-01-12 add rake preview for development
375 end
9d7d4eb4 »
2012-01-18 reorganize rakefile
376
377 def get_stdin(message)
378 print message
379 STDIN.gets.chomp
39a97e81 »
2012-02-24 custom rake tasks to parse haml_layouts, launch an interactive server…
380 end
Something went wrong with that request. Please try again.