Skip to content

Commit

Permalink
Fold private methods into the :render method as local variables (#327)
Browse files Browse the repository at this point in the history
Merge pull request 327
  • Loading branch information
ashmaroli committed Dec 16, 2021
1 parent 84aeaa0 commit 982a532
Showing 1 changed file with 12 additions and 25 deletions.
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

0 comments on commit 982a532

Please sign in to comment.