jekyll-remote-theme 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8229e0bedfef52dba41d17eff8eb8e4bba23972c
4
- data.tar.gz: 3f0cb3209952df98c3d7db8fac598590f83e6fcc
3
+ metadata.gz: f143d51ba614a2d6ee6050d17b36942e09f3a6ba
4
+ data.tar.gz: 6920fee94da6e9cdc86e84fb64a80991ea8d1e84
5
5
  SHA512:
6
- metadata.gz: 75fef7047c3d3f2d5a6727e53a6079ca45f45d6e3340f769d95d4f4874c89df97735e905d6f9b59eca401aae8057b5ac06859bbd0a884818bcf933a115bdcf63
7
- data.tar.gz: 68995b0baa3a99fc41682e74ac5a6c4cdb953a0b814461e03cac599dad36ff26f4c5d107994ac06ebd62cbff4ae76621aa114a18b890025b67a560d25b9f9b57
6
+ metadata.gz: 1e0c47f5100f3abb9948fc3c24cd5dbba8673ddc3f554793b278d4cc7f7d53a3257a1dd684d7122330d999145540d338008b289aec938ccd92be94460ab6e2ea
7
+ data.tar.gz: 136a0edffff8009838810ac562ea521f2fa01a39ea4222382f5f6c03cbb11b85caaa60c357deba097d5f8504b06c45e05f366ad6ad996f8e7c56135b5eac003e
@@ -4,11 +4,15 @@ require "jekyll"
4
4
  require "fileutils"
5
5
  require "tempfile"
6
6
  require "addressable"
7
+ require "typhoeus"
8
+ require "zip"
7
9
 
8
10
  $LOAD_PATH.unshift(File.dirname(__FILE__))
9
11
 
10
12
  module Jekyll
11
13
  module RemoteTheme
14
+ class DownloadError < StandardError; end
15
+
12
16
  autoload :Downloader, "jekyll-remote-theme/downloader"
13
17
  autoload :Executor, "jekyll-remote-theme/executor"
14
18
  autoload :MockGemspec, "jekyll-remote-theme/mock_gemspec"
@@ -16,8 +20,9 @@ module Jekyll
16
20
  autoload :Theme, "jekyll-remote-theme/theme"
17
21
  autoload :VERSION, "jekyll-remote-theme/version"
18
22
 
19
- CONFIG_KEY = "remote_theme".freeze
20
- LOG_KEY = "Remote Theme:".freeze
23
+ CONFIG_KEY = "remote_theme".freeze
24
+ LOG_KEY = "Remote Theme:".freeze
25
+ TEMP_PREFIX = "jekyll-remote-theme-".freeze
21
26
 
22
27
  def self.init(site)
23
28
  Munger.new(site).munge!
@@ -28,3 +33,5 @@ end
28
33
  Jekyll::Hooks.register :site, :after_reset do |site|
29
34
  Jekyll::RemoteTheme.init(site)
30
35
  end
36
+
37
+ Ethon.logger = Jekyll.logger.writer
@@ -7,8 +7,12 @@ module Jekyll
7
7
 
8
8
  HOST = "https://codeload.github.com".freeze
9
9
  PROJECT_URL = "https://github.com/benbalter/jekyll-remote-theme".freeze
10
- USER_AGENT = "Jekyll Remote Theme/#{VERSION} (+#{PROJECT_URL})".freeze
11
- TEMP_PREFIX = "jekyll-remote-theme-".freeze
10
+ TYPHOEUS_OPTIONS = {
11
+ :headers => {
12
+ :user_agent => "Jekyll Remote Theme/#{VERSION} (+#{PROJECT_URL})",
13
+ },
14
+ :verbose => (Jekyll.logger.level == :verbose),
15
+ }.freeze
12
16
 
13
17
  attr_reader :theme
14
18
  private :theme
@@ -25,7 +29,6 @@ module Jekyll
25
29
 
26
30
  download
27
31
  unzip
28
- set_theme_root
29
32
 
30
33
  @downloaded = true
31
34
  end
@@ -34,10 +37,6 @@ module Jekyll
34
37
  @downloaded ||= theme_dir_exists? && !theme_dir_empty?
35
38
  end
36
39
 
37
- def temp_dir
38
- @temp_dir ||= File.realpath Dir.mktmpdir(TEMP_PREFIX)
39
- end
40
-
41
40
  private
42
41
 
43
42
  def zip_file
@@ -46,29 +45,24 @@ module Jekyll
46
45
 
47
46
  def download
48
47
  Jekyll.logger.debug LOG_KEY, "Downloading #{zip_url} to #{zip_file.path}"
49
- cmd = [
50
- *timeout_command, "curl", "--url", zip_url, "--output", zip_file.path,
51
- "--user-agent", USER_AGENT, "--fail", "--silent", "--show-error",
52
- ]
53
- run_command(*cmd)
48
+ request = Typhoeus::Request.new zip_url, TYPHOEUS_OPTIONS
49
+ request.on_headers { |response| raise_if_unsuccessful(response) }
50
+ request.on_body { |chunk| zip_file.write(chunk) }
51
+ request.on_complete { |response| raise_if_unsuccessful(response) }
52
+ request.run
54
53
  end
55
54
 
56
55
  def unzip
57
- Jekyll.logger.debug LOG_KEY, "Unzipping #{zip_file.path} to #{temp_dir}"
58
- cmd = [*timeout_command, "unzip", zip_file.path, "-d", temp_dir]
59
- run_command(*cmd)
60
- zip_file.unlink
61
- end
56
+ Jekyll.logger.debug LOG_KEY, "Unzipping #{zip_file.path} to #{theme.root}"
62
57
 
63
- # Codeload generated zip files contain a top level folder in the form of
64
- # THEME_NAME-GIT_REF/. While requests for Git repos are case incensitive,
65
- # the zip subfolder will respect the case in the repository's name, thus
66
- # making it impossible to predict the true path to the theme. In case we're
67
- # on a case-sensitive file system, set the theme's root to the true theme
68
- # directory, after we've extracted the zip and can determine its actual path.
69
- def set_theme_root
70
- theme.root = Dir["#{temp_dir}/*"].first
71
- Jekyll.logger.debug LOG_KEY, "Setting theme root to #{theme.root}"
58
+ # File IO is already open, rewind pointer to start of file to read
59
+ zip_file.rewind
60
+
61
+ Zip::File.open(zip_file) do |archive|
62
+ archive.each { |file| file.extract path_without_name_and_ref(file.name) }
63
+ end
64
+
65
+ zip_file.unlink
72
66
  end
73
67
 
74
68
  # Full URL to codeload zip download endpoint for the given theme
@@ -85,6 +79,26 @@ module Jekyll
85
79
  def theme_dir_empty?
86
80
  Dir["#{theme.root}/*"].empty?
87
81
  end
82
+
83
+ def raise_if_unsuccessful(response)
84
+ if response.timed_out?
85
+ raise DownloadError, "Request timed out"
86
+ elsif response.code.zero?
87
+ raise DownloadError, response.return_message
88
+ elsif response.code != 200
89
+ msg = "Request failed with #{response.code} - #{response.status_message}"
90
+ raise DownloadError, msg
91
+ end
92
+ end
93
+
94
+ # Codeload generated zip files contain a top level folder in the form of
95
+ # THEME_NAME-GIT_REF/. While requests for Git repos are case incensitive,
96
+ # the zip subfolder will respect the case in the repository's name, thus
97
+ # making it impossible to predict the true path to the theme. In case we're
98
+ # on a case-sensitive file system, strip the parent folder from all paths.
99
+ def path_without_name_and_ref(path)
100
+ Jekyll.sanitized_path theme.root, path.split("/").drop(1).join("/")
101
+ end
88
102
  end
89
103
  end
90
104
  end
@@ -58,8 +58,8 @@ module Jekyll
58
58
  def enqueue_theme_cleanup
59
59
  at_exit do
60
60
  return unless munged? && downloader.downloaded?
61
- Jekyll.logger.debug LOG_KEY, "Cleaning up #{downloader.temp_dir}"
62
- FileUtils.rm_rf downloader.temp_dir
61
+ Jekyll.logger.debug LOG_KEY, "Cleaning up #{theme.root}"
62
+ FileUtils.rm_rf theme.root
63
63
  end
64
64
  end
65
65
  end
@@ -16,6 +16,7 @@ module Jekyll
16
16
  # 2. owner/theme-name@git_ref - a GitHub owner + theme-name + Git ref string
17
17
  def initialize(raw_theme)
18
18
  @raw_theme = raw_theme.to_s.downcase.strip
19
+ super(@raw_theme)
19
20
  end
20
21
 
21
22
  def name
@@ -39,13 +40,8 @@ module Jekyll
39
40
  theme_parts[:ref] || "master"
40
41
  end
41
42
 
42
- # Override Jekyll::Theme's native #root which calls gemspec.full_gem_path
43
43
  def root
44
- defined?(@root) ? @root : nil
45
- end
46
-
47
- def root=(path)
48
- @root = File.realpath(path)
44
+ @root ||= File.realpath Dir.mktmpdir(TEMP_PREFIX)
49
45
  end
50
46
 
51
47
  def inspect
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module RemoteTheme
5
- VERSION = "0.1.0".freeze
5
+ VERSION = "0.2.0".freeze
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-remote-theme
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Balter
@@ -24,6 +24,34 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubyzip
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: typhoeus
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.1'
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: jekyll-theme-primer
29
57
  requirement: !ruby/object:Gem::Requirement