-
-
Notifications
You must be signed in to change notification settings - Fork 75
/
munger.rb
70 lines (54 loc) · 1.46 KB
/
munger.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# frozen_string_literal: true
module Jekyll
module RemoteTheme
class Munger
extend Forwardable
def_delegator :site, :config
attr_reader :site
def initialize(site)
@site = site
end
def munge!
return unless raw_theme
unless theme.valid?
Jekyll.logger.error LOG_KEY, "#{raw_theme.inspect} is not a valid remote theme"
return
end
Jekyll.logger.info LOG_KEY, "Using theme #{theme.name_with_owner}"
return theme if munged?
downloader.run
configure_theme
enqueue_theme_cleanup
theme
end
private
def munged?
site.theme&.is_a?(Jekyll::RemoteTheme::Theme)
end
def theme
@theme ||= Theme.new(raw_theme)
end
def raw_theme
config[CONFIG_KEY]
end
def downloader
@downloader ||= Downloader.new(theme)
end
def configure_theme
return unless theme
site.config["theme"] = theme.name
site.theme = theme
site.theme.configure_sass if site.theme.respond_to?(:configure_sass)
site.send(:configure_include_paths)
site.plugin_manager.require_theme_deps
end
def enqueue_theme_cleanup
at_exit do
return unless munged? && downloader.downloaded?
Jekyll.logger.debug LOG_KEY, "Cleaning up #{theme.root}"
FileUtils.rm_rf theme.root
end
end
end
end
end