Cache Document#to_liquid
This commit is contained in:
parent
015e9570cd
commit
f99abc5314
|
@ -4,8 +4,7 @@ module Jekyll
|
||||||
class Document
|
class Document
|
||||||
include Comparable
|
include Comparable
|
||||||
|
|
||||||
attr_reader :path, :site, :extname, :output_ext
|
attr_reader :path, :site, :extname, :output_ext, :content, :output, :collection
|
||||||
attr_accessor :content, :collection, :output
|
|
||||||
|
|
||||||
YAML_FRONT_MATTER_REGEXP = /\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m
|
YAML_FRONT_MATTER_REGEXP = /\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m
|
||||||
|
|
||||||
|
@ -24,6 +23,16 @@ module Jekyll
|
||||||
@has_yaml_header = nil
|
@has_yaml_header = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def output=(output)
|
||||||
|
@to_liquid = nil
|
||||||
|
@output = output
|
||||||
|
end
|
||||||
|
|
||||||
|
def content=(content)
|
||||||
|
@to_liquid = nil
|
||||||
|
@content = content
|
||||||
|
end
|
||||||
|
|
||||||
# Fetch the Document's data.
|
# Fetch the Document's data.
|
||||||
#
|
#
|
||||||
# Returns a Hash containing the data. An empty hash is returned if
|
# Returns a Hash containing the data. An empty hash is returned if
|
||||||
|
@ -205,6 +214,8 @@ module Jekyll
|
||||||
#
|
#
|
||||||
# Returns nothing.
|
# Returns nothing.
|
||||||
def read(opts = {})
|
def read(opts = {})
|
||||||
|
@to_liquid = nil
|
||||||
|
|
||||||
if yaml_file?
|
if yaml_file?
|
||||||
@data = SafeYAML.load_file(path)
|
@data = SafeYAML.load_file(path)
|
||||||
else
|
else
|
||||||
|
@ -213,9 +224,9 @@ module Jekyll
|
||||||
unless defaults.empty?
|
unless defaults.empty?
|
||||||
@data = defaults
|
@data = defaults
|
||||||
end
|
end
|
||||||
@content = File.read(path, merged_file_read_opts(opts))
|
self.content = File.read(path, merged_file_read_opts(opts))
|
||||||
if content =~ YAML_FRONT_MATTER_REGEXP
|
if content =~ YAML_FRONT_MATTER_REGEXP
|
||||||
@content = $POSTMATCH
|
self.content = $POSTMATCH
|
||||||
data_file = SafeYAML.load($1)
|
data_file = SafeYAML.load($1)
|
||||||
unless data_file.nil?
|
unless data_file.nil?
|
||||||
@data = Utils.deep_merge_hashes(defaults, data_file)
|
@data = Utils.deep_merge_hashes(defaults, data_file)
|
||||||
|
@ -233,7 +244,7 @@ module Jekyll
|
||||||
#
|
#
|
||||||
# Returns a Hash representing this Document's data.
|
# Returns a Hash representing this Document's data.
|
||||||
def to_liquid
|
def to_liquid
|
||||||
if data.is_a?(Hash)
|
@to_liquid ||= if data.is_a?(Hash)
|
||||||
Utils.deep_merge_hashes data, {
|
Utils.deep_merge_hashes data, {
|
||||||
"output" => output,
|
"output" => output,
|
||||||
"content" => content,
|
"content" => content,
|
||||||
|
@ -279,6 +290,5 @@ module Jekyll
|
||||||
def write?
|
def write?
|
||||||
collection && collection.write?
|
collection && collection.write?
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue