Introduce `theme` drop to expose theme details (#9129)

Merge pull request 9129
This commit is contained in:
Ashwin Maroli 2022-09-24 19:24:56 +05:30 committed by GitHub
parent 5b64b27b2c
commit b8cf7cf96d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 74 additions and 0 deletions

View File

@ -0,0 +1,36 @@
# frozen_string_literal: true
module Jekyll
module Drops
class ThemeDrop < Drop
delegate_methods :root, :version
delegate_method_as :runtime_dependencies, :dependencies
def authors
@authors ||= gemspec.authors.join(", ")
end
def version
@version ||= gemspec.version.to_s
end
def description
@description ||= gemspec.description || gemspec.summary
end
def metadata
@metadata ||= gemspec.metadata
end
private
def gemspec
@gemspec ||= @obj.send(:gemspec)
end
def fallback_data
@fallback_data ||= {}
end
end
end
end

View File

@ -16,6 +16,10 @@ module Jekyll
@site_drop ||= SiteDrop.new(@obj)
end
def theme
@theme_drop ||= ThemeDrop.new(@obj.theme) if @obj.theme
end
private
def fallback_data

34
test/test_theme_drop.rb Normal file
View File

@ -0,0 +1,34 @@
# frozen_string_literal: true
require "helper"
class TestThemeDrop < JekyllUnitTest
should "be initialized only for gem-based themes" do
assert_nil fixture_site.to_liquid.theme
end
context "a theme drop" do
setup do
@drop = fixture_site("theme" => "test-theme").to_liquid.theme
end
should "respond to `key?`" do
assert_respond_to @drop, :key?
end
should "export relevant data to Liquid templates" do
expected = {
"authors" => "Jekyll",
"dependencies" => [],
"description" => "This is a theme used to test Jekyll",
"metadata" => {},
"root" => theme_dir,
"version" => "0.1.0",
}
expected.each_key do |key|
assert @drop.key?(key)
assert_equal expected[key], @drop[key]
end
end
end
end