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 8 def initialize(theme_name, opts) @name = theme_name.to_s.tr(" ", "_").gsub(%r!_+!, "_") @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 14 def create! create_directories create_starter_files create_gemspec create_accessories initialize_git_repo end
Private Instance Methods
create_accessories()
click to toggle source
# File lib/jekyll/theme_builder.rb, line 72 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 57 def create_directories mkdir_p(SCAFFOLD_DIRECTORIES) end
create_gemspec()
click to toggle source
# File lib/jekyll/theme_builder.rb, line 67 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 61 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 39 def erb @erb ||= ERBRenderer.new(self) end
initialize_git_repo()
click to toggle source
# File lib/jekyll/theme_builder.rb, line 80 def initialize_git_repo Jekyll.logger.info "initialize", path.join(".git").to_s Dir.chdir(path.to_s) { %x`git init` } write_file(".gitignore", template("gitignore")) end
mkdir_p(directories)
click to toggle source
# File lib/jekyll/theme_builder.rb, line 43 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 24 def root @root ||= Pathname.new(File.expand_path("../", __dir__)) end
template(filename)
click to toggle source
# File lib/jekyll/theme_builder.rb, line 35 def template(filename) erb.render(template_file(filename).read) end
template_file(filename)
click to toggle source
# File lib/jekyll/theme_builder.rb, line 28 def template_file(filename) [ root.join("theme_template", "#{filename}.erb"), root.join("theme_template", filename.to_s) ].find(&:exist?) end
user_email()
click to toggle source
# File lib/jekyll/theme_builder.rb, line 90 def user_email @user_email ||= %x`git config user.email`.chomp end
user_name()
click to toggle source
# File lib/jekyll/theme_builder.rb, line 86 def user_name @user_name ||= %x`git config user.name`.chomp end
write_file(filename, contents)
click to toggle source
# File lib/jekyll/theme_builder.rb, line 51 def write_file(filename, contents) full_path = path.join(filename) Jekyll.logger.info "create", full_path.to_s File.write(full_path, contents) end