Created
May 27, 2012 02:58
-
-
Save Oreolek/2798874 to your computer and use it in GitHub Desktop.
Jekyll Theme switcher by Oreolek
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# you should add something like this to your config: | |
# theme: theme-name | |
module Jekyll | |
module Theme | |
class ThemeChooser < Generator | |
safe false | |
def generate(site) | |
themes_path = '_themes/' | |
target_path = site.config['source'] + '/_layouts' | |
unless site.config['theme'] then | |
unless (Dir.entries(target_path).size - 2 > 0) then | |
STDERR.puts 'theme parameter is not set. The _layouts directory is not empty. Theme will not be generated.' | |
return | |
end | |
puts "theme parameter is not set. Using _layouts directory. The plugin will now exit." | |
return | |
end | |
theme = File.join(themes_path, site.config['theme']) | |
unless FileTest.directory?(theme) then | |
STDERR.puts "Theme directory #{theme} not found. Theme will not be generated." | |
return | |
end | |
print "Copying theme '#{site.config['theme']}'.." | |
FileUtils.cp_r(Dir.getwd + '/' + theme + '/.', target_path) | |
puts "." | |
site.read_layouts | |
puts "done." | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment