class Jekyll::ThemeBuilder
Constants
- SCAFFOLD_DIRECTORIES
Attributes
code_of_conduct[R]
name[R]
path[R]
Public Class Methods
new(theme_name, opts)
click to toggle source
# File lib/jekyll/theme_builder.rb, line 11 def initialize(theme_name, opts) @name = theme_name.to_s.tr(" ", "_").squeeze("_") @path = Pathname.new(File.expand_path(name, Dir.pwd)) @code_of_conduct = !!opts["code_of_conduct"] end
Public Instance Methods
create!()
click to toggle source
# File lib/jekyll/theme_builder.rb, line 17 def create! create_directories create_starter_files create_gemspec create_accessories initialize_git_repo end
user_email()
click to toggle source
# File lib/jekyll/theme_builder.rb, line 29 def user_email @user_email ||= `git config user.email`.chomp end
user_name()
click to toggle source
# File lib/jekyll/theme_builder.rb, line 25 def user_name @user_name ||= `git config user.name`.chomp end
Private Instance Methods
create_accessories()
click to toggle source
# File lib/jekyll/theme_builder.rb, line 83 def create_accessories accessories = %w(README.md LICENSE.txt) accessories << "CODE_OF_CONDUCT.md" if code_of_conduct accessories.each do |filename| write_file(filename, template(filename)) end end
create_directories()
click to toggle source
# File lib/jekyll/theme_builder.rb, line 68 def create_directories mkdir_p(SCAFFOLD_DIRECTORIES) end
create_gemspec()
click to toggle source
# File lib/jekyll/theme_builder.rb, line 78 def create_gemspec write_file("Gemfile", template("Gemfile")) write_file("#{name}.gemspec", template("theme.gemspec")) end
create_starter_files()
click to toggle source
# File lib/jekyll/theme_builder.rb, line 72 def create_starter_files %w(page post default).each do |layout| write_file("_layouts/#{layout}.html", template("_layouts/#{layout}.html")) end end
erb()
click to toggle source
# File lib/jekyll/theme_builder.rb, line 50 def erb @erb ||= ERBRenderer.new(self) end
initialize_git_repo()
click to toggle source
# File lib/jekyll/theme_builder.rb, line 91 def initialize_git_repo Jekyll.logger.info "initialize", path.join(".git").to_s Dir.chdir(path.to_s) { `git init` } write_file(".gitignore", template("gitignore")) end
mkdir_p(directories)
click to toggle source
# File lib/jekyll/theme_builder.rb, line 54 def mkdir_p(directories) Array(directories).each do |directory| full_path = path.join(directory) Jekyll.logger.info "create", full_path.to_s FileUtils.mkdir_p(full_path) end end
root()
click to toggle source
# File lib/jekyll/theme_builder.rb, line 35 def root @root ||= Pathname.new(File.expand_path("../", __dir__)) end
template(filename)
click to toggle source
# File lib/jekyll/theme_builder.rb, line 46 def template(filename) erb.render(template_file(filename).read) end
template_file(filename)
click to toggle source
# File lib/jekyll/theme_builder.rb, line 39 def template_file(filename) [ root.join("theme_template", "#{filename}.erb"), root.join("theme_template", filename.to_s), ].find(&:exist?) end
write_file(filename, contents)
click to toggle source
# File lib/jekyll/theme_builder.rb, line 62 def write_file(filename, contents) full_path = path.join(filename) Jekyll.logger.info "create", full_path.to_s File.write(full_path, contents) end