class CustomJekyll::Generator
Attributes
site_name[R]
Public Class Methods
new(site_name)
click to toggle source
# File lib/custom_jekyll/generator.rb, line 16 def initialize(site_name) @site_name = site_name g_site_folder end
path_to_resources()
click to toggle source
# File lib/custom_jekyll/generator.rb, line 5 def path_to_resources $LOAD_PATH.detect do |dir| dir.include?('custom_jekyll') && dir.include?('lib') end end
path_to_site_template()
click to toggle source
# File lib/custom_jekyll/generator.rb, line 11 def path_to_site_template path_to_resources.dup << '/custom_jekyll/site_template' end
Public Instance Methods
add_site_name_to_site_config()
click to toggle source
# File lib/custom_jekyll/generator.rb, line 41 def add_site_name_to_site_config config = File.read('_config.yml') config.gsub!('%site_title%', humanize_site_name) overwrite_config(config) end
change_directory_to_site()
click to toggle source
# File lib/custom_jekyll/generator.rb, line 47 def change_directory_to_site Dir.chdir(site_name) end
copy_templates_to_new_site()
click to toggle source
# File lib/custom_jekyll/generator.rb, line 32 def copy_templates_to_new_site FileUtils.cp_r(site_template, site_name) end
g_site_folder()
click to toggle source
# File lib/custom_jekyll/generator.rb, line 28 def g_site_folder Dir.mkdir(site_name) end
generate_site()
click to toggle source
# File lib/custom_jekyll/generator.rb, line 21 def generate_site copy_templates_to_new_site change_directory_to_site run_automated_commands add_site_name_to_site_config end
run_automated_commands()
click to toggle source
# File lib/custom_jekyll/generator.rb, line 36 def run_automated_commands run_bundle_install make_git_repo end
Private Instance Methods
humanize_site_name()
click to toggle source
# File lib/custom_jekyll/generator.rb, line 68 def humanize_site_name site_name.split(/-|\s/).map {|w| w.capitalize}.join("\s") end
make_git_repo()
click to toggle source
# File lib/custom_jekyll/generator.rb, line 64 def make_git_repo system("git init") end
overwrite_config(content)
click to toggle source
# File lib/custom_jekyll/generator.rb, line 72 def overwrite_config(content) File.open '_config.yml', 'w' do |f| f.write content end end
run_bundle_install()
click to toggle source
# File lib/custom_jekyll/generator.rb, line 57 def run_bundle_install puts "Running bundle install in #{site_name}" Bundler.with_clean_env do system("bundle install") end end
site_template()
click to toggle source
# File lib/custom_jekyll/generator.rb, line 53 def site_template self.class.path_to_site_template << '/.' end