Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fold private methods into the :render method as local variables #327

Merged
merged 3 commits into from Dec 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 12 additions & 25 deletions lib/jekyll-feed/meta-tag.rb
Expand Up @@ -6,35 +6,22 @@ class MetaTag < Liquid::Tag
include Jekyll::Filters::URLFilters

def render(context)
# Jekyll::Filters::URLFilters requires `@context` to be set in the environment.
@context = context
attrs = attributes.map do |k, v|
v = v.to_s unless v.respond_to?(:encode)
%(#{k}=#{v.encode(:xml => :attr)})
end
"<link #{attrs.join(" ")} />"
end

private

def config
@config ||= @context.registers[:site].config
end

def attributes
{
:type => "application/atom+xml",
:rel => "alternate",
:href => absolute_url(path),
:title => title,
}.keep_if { |_, v| v }
end
config = context.registers[:site].config
path = config.dig("feed", "path") || "feed.xml"
title = config["title"] || config["name"]

def path
config.dig("feed", "path") || "feed.xml"
end
attributes = {
:type => "application/atom+xml",
:rel => "alternate",
:href => absolute_url(path),
}
attributes[:title] = title if title

def title
config["title"] || config["name"]
attrs = attributes.map { |k, v| "#{k}=#{v.to_s.encode(:xml => :attr)}" }.join(" ")
"<link #{attrs} />"
end
end
end