From 533d840a7556217ebc8250e157de843b9a9f5f04 Mon Sep 17 00:00:00 2001 From: Jade Dominguez Date: Wed, 1 Feb 2012 15:15:35 -0800 Subject: Namespace 'switch_theme' Make sure to maintain backwards compatibility --- Rakefile | 75 +++++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 44 insertions(+), 31 deletions(-) (limited to 'Rakefile') diff --git a/Rakefile b/Rakefile index 3e04930..fe7a9d1 100644 --- a/Rakefile +++ b/Rakefile @@ -85,44 +85,57 @@ task :page do end end # task :page -desc "Switch between Jekyll-bootstrap themes." -task :switch_theme do - theme_name = ENV["name"].to_s - theme_path = File.join(CONFIG['themes'], theme_name) - settings_file = File.join(theme_path, "settings.yml") - non_layout_files = ["settings.yml"] - - abort("rake aborted: name cannot be blank") if theme_name.empty? - abort("rake aborted: '#{theme_path}' directory not found.") unless FileTest.directory?(theme_path) - abort("rake aborted: '#{CONFIG['layouts']}' directory not found.") unless FileTest.directory?(CONFIG['layouts']) - - Dir.glob("#{theme_path}/*") do |filename| - next if non_layout_files.include?(File.basename(filename).downcase) - puts "Generating '#{theme_name}' layout: #{File.basename(filename)}" - - open(File.join(CONFIG['layouts'], File.basename(filename)), 'w') do |page| - if File.basename(filename, ".html").downcase == "default" - page.puts "---" - page.puts File.read(settings_file) if File.exist?(settings_file) - page.puts "---" - else - page.puts "---" - page.puts "layout: default" - page.puts "---" - end - page.puts "{% include JB/setup %}" - page.puts "{% include themes/#{theme_name}/#{File.basename(filename)} %}" - end - end -end # task :switch_theme - desc "Launch preview environment" task :preview do system "jekyll --auto --server" end # task :preview +# Public: Alias - Maintains backwards compatability for theme switching. +task :switch_theme => "theme:switch" + namespace :theme do + # Public: Switch from one theme to another for your blog. + # + # name - String, Required. name of the theme you want to switch to. + # The the theme must be installed into your JB framework. + # + # Examples + # + # rake theme:switch name="the-program" + # + # Returns Success/failure messages. + desc "Switch between Jekyll-bootstrap themes." + task :switch do + theme_name = ENV["name"].to_s + theme_path = File.join(CONFIG['themes'], theme_name) + settings_file = File.join(theme_path, "settings.yml") + non_layout_files = ["settings.yml"] + + abort("rake aborted: name cannot be blank") if theme_name.empty? + abort("rake aborted: '#{theme_path}' directory not found.") unless FileTest.directory?(theme_path) + abort("rake aborted: '#{CONFIG['layouts']}' directory not found.") unless FileTest.directory?(CONFIG['layouts']) + + Dir.glob("#{theme_path}/*") do |filename| + next if non_layout_files.include?(File.basename(filename).downcase) + puts "Generating '#{theme_name}' layout: #{File.basename(filename)}" + + open(File.join(CONFIG['layouts'], File.basename(filename)), 'w') do |page| + if File.basename(filename, ".html").downcase == "default" + page.puts "---" + page.puts File.read(settings_file) if File.exist?(settings_file) + page.puts "---" + else + page.puts "---" + page.puts "layout: default" + page.puts "---" + end + page.puts "{% include JB/setup %}" + page.puts "{% include themes/#{theme_name}/#{File.basename(filename)} %}" + end + end + end # task :switch + # Public: Install a theme using the theme packager. # Version 0.1.0 simple 1:1 file matching. # -- cgit v1.2.3