Stash frequently used Drop setter keys for reuse (#8394)
Merge pull request 8394
This commit is contained in:
parent
e0221ed3a8
commit
5dc43a88de
|
@ -7,6 +7,20 @@ module Jekyll
|
||||||
|
|
||||||
NON_CONTENT_METHODS = [:fallback_data, :collapse_document].freeze
|
NON_CONTENT_METHODS = [:fallback_data, :collapse_document].freeze
|
||||||
|
|
||||||
|
# A private stash to avoid repeatedly generating the setter method name string for
|
||||||
|
# a call to `Drops::Drop#[]=`.
|
||||||
|
# The keys of the stash below have a very high probability of being called upon during
|
||||||
|
# the course of various `Jekyll::Renderer#run` calls.
|
||||||
|
SETTER_KEYS_STASH = {
|
||||||
|
"content" => "content=",
|
||||||
|
"layout" => "layout=",
|
||||||
|
"page" => "page=",
|
||||||
|
"paginator" => "paginator=",
|
||||||
|
"highlighter_prefix" => "highlighter_prefix=",
|
||||||
|
"highlighter_suffix" => "highlighter_suffix=",
|
||||||
|
}.freeze
|
||||||
|
private_constant :SETTER_KEYS_STASH
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
# Get or set whether the drop class is mutable.
|
# Get or set whether the drop class is mutable.
|
||||||
# Mutability determines whether or not pre-defined fields may be
|
# Mutability determines whether or not pre-defined fields may be
|
||||||
|
@ -119,7 +133,7 @@ module Jekyll
|
||||||
# and the key matches a method in which case it raises a
|
# and the key matches a method in which case it raises a
|
||||||
# DropMutationException.
|
# DropMutationException.
|
||||||
def []=(key, val)
|
def []=(key, val)
|
||||||
setter = "#{key}="
|
setter = SETTER_KEYS_STASH[key] || "#{key}="
|
||||||
if respond_to?(setter)
|
if respond_to?(setter)
|
||||||
public_send(setter, val)
|
public_send(setter, val)
|
||||||
elsif respond_to?(key.to_s)
|
elsif respond_to?(key.to_s)
|
||||||
|
|
Loading…
Reference in New Issue