class Jekyll::ThemeGemExtractor
Attributes
options[R]
site[R]
theme_root[R]
Public Class Methods
new(site, options)
click to toggle source
# File lib/theme_gem_extractor.rb, line 7 def initialize(site, options) @site = site @options = options @theme_root = site.in_theme_dir("/") end
Public Instance Methods
already_exists_msg(file)
click to toggle source
# File lib/theme_gem_extractor.rb, line 96 def already_exists_msg(file) Jekyll.logger.warn "Error:", "'#{relative_path(file)}' already " \ "exists at destination. Use --force to overwrite." end
directory_listing(path)
click to toggle source
# File lib/theme_gem_extractor.rb, line 75 def directory_listing(path) Jekyll.logger.info "Listing:", "Contents of '#{relative_path(path)}' in theme gem..." files_in(path).each do |file| Jekyll.logger.info "", " * #{relative_path(file)}" end end
extract(path)
click to toggle source
# File lib/theme_gem_extractor.rb, line 13 def extract(path) file_path = site.in_theme_dir path unless File.exist?(file_path) puts "" raise ArgumentError, "Specified path #{path.yellow} doesn't exist in the theme-gem." end extract_to_source file_path end
extract_contents(source, destination)
click to toggle source
# File lib/theme_gem_extractor.rb, line 42 def extract_contents(source, destination) FileUtils.cp_r "#{source}/.", destination files_in(source).each do |file| extraction_msg file end rescue Errno::ENOENT FileUtils.mkdir_p destination retry end
extract_directory_contents(path)
click to toggle source
# File lib/theme_gem_extractor.rb, line 33 def extract_directory_contents(path) destination = site.in_source_dir relative_path(path) if File.exist?(destination) && !options["force"] already_exists_msg path else extract_contents path, destination end end
extract_file_with_directory(file_path)
click to toggle source
# File lib/theme_gem_extractor.rb, line 52 def extract_file_with_directory(file_path) file = file_path.split("/").last dir_path = File.dirname( site.in_source_dir(relative_path(file_path)) ) FileUtils.mkdir_p dir_path if File.exist?(File.join(dir_path, file)) && !options["force"] already_exists_msg file_path else FileUtils.cp_r file_path, dir_path extraction_msg file_path end end
extract_to_source(path)
click to toggle source
# File lib/theme_gem_extractor.rb, line 23 def extract_to_source(path) return list_contents(path) if options["show"] if File.directory? path extract_directory_contents path else extract_file_with_directory path end end
extraction_msg(file)
click to toggle source
# File lib/theme_gem_extractor.rb, line 92 def extraction_msg(file) Jekyll.logger.info "Extract:", relative_path(file) end
files_in(dir_path)
click to toggle source
# File lib/theme_gem_extractor.rb, line 84 def files_in(dir_path) Dir["#{dir_path}/**/*"].reject { |d| File.directory? d } end
list_contents(path)
click to toggle source
# File lib/theme_gem_extractor.rb, line 67 def list_contents(path) if File.directory? path directory_listing path else Jekyll.logger.warn "", "The --show switch only works for directories" end end
relative_path(path)
click to toggle source
# File lib/theme_gem_extractor.rb, line 88 def relative_path(path) path.sub theme_root, "" end