Skip to content

Instantly share code, notes, and snippets.

@Oreolek
Created May 27, 2012 02:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Oreolek/2798874 to your computer and use it in GitHub Desktop.
Save Oreolek/2798874 to your computer and use it in GitHub Desktop.
Jekyll Theme switcher by Oreolek
# 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