Skip to content

Commit

Permalink
Backport #9680 for v4.3.x: Render theme-gem root only in development (#…
Browse files Browse the repository at this point in the history
…9684)

This backports 32074ef to 4.3-stable
  • Loading branch information
ashmaroli authored Sep 16, 2024
1 parent e139840 commit c0a92da
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
4 changes: 3 additions & 1 deletion docs/_data/jekyll_variables.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ page:
theme:
- 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
description: Comma separated string composed of the authors of the theme-gem.
- name: theme.description
Expand Down
5 changes: 4 additions & 1 deletion lib/jekyll/drops/theme_drop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
module Jekyll
module Drops
class ThemeDrop < Drop
delegate_methods :root
delegate_method_as :runtime_dependencies, :dependencies

def root
@root ||= ENV["JEKYLL_ENV"] == "development" ? @obj.root : ""
end

def authors
@authors ||= gemspec.authors.join(", ")
end
Expand Down
19 changes: 18 additions & 1 deletion test/test_theme_drop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,30 @@ class TestThemeDrop < JekyllUnitTest
"dependencies" => [],
"description" => "This is a theme used to test Jekyll",
"metadata" => {},
"root" => theme_dir,
"root" => "",
"version" => "0.1.0",
}
expected.each_key do |key|
assert @drop.key?(key)
assert_equal expected[key], @drop[key]
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

0 comments on commit c0a92da

Please sign in to comment.