Render theme-gem root only in development (#9680)

Merge pull request 9680
This commit is contained in:
Ashwin Maroli 2024-09-16 21:10:55 +05:30 committed by GitHub
parent eba4dbcc72
commit 32074ef944
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 25 additions and 3 deletions

View File

@ -183,7 +183,9 @@ jekyll:
theme: theme:
- name: theme.root - name: theme.root
description: Absolute path to the theme-gem. description: >-
Absolute path to the theme-gem. Rendered only when environment variable <code>JEKYLL_ENV</code>
is set to <code>development</code>.
- name: theme.authors - name: theme.authors
description: Comma separated string composed of the authors of the theme-gem. description: Comma separated string composed of the authors of the theme-gem.
- name: theme.description - name: theme.description

View File

@ -3,9 +3,12 @@
module Jekyll module Jekyll
module Drops module Drops
class ThemeDrop < Drop class ThemeDrop < Drop
delegate_methods :root
delegate_method_as :runtime_dependencies, :dependencies delegate_method_as :runtime_dependencies, :dependencies
def root
@root ||= ENV["JEKYLL_ENV"] == "development" ? @obj.root : ""
end
def authors def authors
@authors ||= gemspec.authors.join(", ") @authors ||= gemspec.authors.join(", ")
end end

View File

@ -22,7 +22,7 @@ class TestThemeDrop < JekyllUnitTest
"dependencies" => [], "dependencies" => [],
"description" => "This is a theme used to test Jekyll", "description" => "This is a theme used to test Jekyll",
"metadata" => {}, "metadata" => {},
"root" => theme_dir, "root" => "",
"version" => "0.1.0", "version" => "0.1.0",
} }
expected.each_key do |key| expected.each_key do |key|
@ -30,5 +30,22 @@ class TestThemeDrop < JekyllUnitTest
assert_equal expected[key], @drop[key] assert_equal expected[key], @drop[key]
end end
end end
should "render gem root only in development mode" do
with_env("JEKYLL_ENV", nil) do
drop = fixture_site("theme" => "test-theme").to_liquid.theme
assert_equal "", drop["root"]
end
with_env("JEKYLL_ENV", "development") do
drop = fixture_site("theme" => "test-theme").to_liquid.theme
assert_equal theme_dir, drop["root"]
end
with_env("JEKYLL_ENV", "production") do
drop = fixture_site("theme" => "test-theme").to_liquid.theme
assert_equal "", drop["root"]
end
end
end end
end end