Skip to content

Commit 2882119

Browse files
committed
Inherit Jekyll's rubocop config for consistency
This PR is the result of adding inherit_gem:\n jekyll: .rubocop.yml to .rubocop.yml and running rubocop -a so that this project follows Jekyll core's coding styles for consistency like other core plugins. This way, as Jekyll's Ruby style changes, so too will this project's.
1 parent 40823a4 commit 2882119

File tree

7 files changed

+67
-63
lines changed

7 files changed

+67
-63
lines changed

.rubocop.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
inherit_gem:
2+
jekyll: .rubocop.yml

jekyll-archives.gemspec

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
lib = File.expand_path('../lib', __FILE__)
1+
lib = File.expand_path("../lib", __FILE__)
22
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3-
require 'jekyll-archives/version'
3+
require "jekyll-archives/version"
44

55
Gem::Specification.new do |s|
66
s.name = "jekyll-archives"
@@ -13,10 +13,11 @@ Gem::Specification.new do |s|
1313
s.licenses = ["MIT"]
1414
s.files = ["lib/jekyll-archives.rb", "lib/jekyll-archives/archive.rb"]
1515

16-
s.add_dependency "jekyll", '>= 2.4'
16+
s.add_dependency "jekyll", ">= 2.4"
1717

18-
s.add_development_dependency 'rake'
19-
s.add_development_dependency 'rdoc'
20-
s.add_development_dependency 'shoulda'
21-
s.add_development_dependency 'minitest'
18+
s.add_development_dependency "rake"
19+
s.add_development_dependency "rdoc"
20+
s.add_development_dependency "shoulda"
21+
s.add_development_dependency "minitest"
22+
s.add_development_dependency "rubocop"
2223
end

lib/jekyll-archives.rb

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
require 'jekyll'
1+
require "jekyll"
22

33
module Jekyll
44
module Archives
55
# Internal requires
6-
autoload :Archive, 'jekyll-archives/archive'
7-
autoload :VERSION, 'jekyll-archives/version'
6+
autoload :Archive, "jekyll-archives/archive"
7+
autoload :VERSION, "jekyll-archives/version"
88

9-
if (Jekyll.const_defined? :Hooks)
9+
if Jekyll.const_defined? :Hooks
1010
Jekyll::Hooks.register :site, :after_reset do |site|
1111
# We need to disable incremental regen for Archives to generate with the
1212
# correct content
@@ -18,31 +18,31 @@ class Archives < Jekyll::Generator
1818
safe true
1919

2020
DEFAULTS = {
21-
'layout' => 'archive',
22-
'enabled' => [],
23-
'permalinks' => {
24-
'year' => '/:year/',
25-
'month' => '/:year/:month/',
26-
'day' => '/:year/:month/:day/',
27-
'tag' => '/tag/:name/',
28-
'category' => '/category/:name/'
21+
"layout" => "archive",
22+
"enabled" => [],
23+
"permalinks" => {
24+
"year" => "/:year/",
25+
"month" => "/:year/:month/",
26+
"day" => "/:year/:month/:day/",
27+
"tag" => "/tag/:name/",
28+
"category" => "/category/:name/"
2929
}
30-
}
30+
}.freeze
3131

3232
def initialize(config = nil)
33-
if config['jekyll-archives'].nil?
34-
@config = DEFAULTS
35-
else
36-
@config = Utils.deep_merge_hashes(DEFAULTS, config['jekyll-archives'])
37-
end
33+
@config = if config["jekyll-archives"].nil?
34+
DEFAULTS
35+
else
36+
Utils.deep_merge_hashes(DEFAULTS, config["jekyll-archives"])
37+
end
3838
end
3939

4040
def generate(site)
4141
@site = site
4242
@posts = site.posts
4343
@archives = []
4444

45-
@site.config['jekyll-archives'] = @config
45+
@site.config["jekyll-archives"] = @config
4646

4747
read
4848
render
@@ -93,7 +93,7 @@ def read_dates
9393
# Checks if archive type is enabled in config
9494
def enabled?(archive)
9595
@config["enabled"] == true || @config["enabled"] == "all" || if @config["enabled"].is_a? Array
96-
@config["enabled"].include? archive
96+
@config["enabled"].include? archive
9797
end
9898
end
9999

@@ -113,19 +113,19 @@ def write
113113
end
114114

115115
def tags
116-
@site.post_attr_hash('tags')
116+
@site.post_attr_hash("tags")
117117
end
118118

119119
def categories
120-
@site.post_attr_hash('categories')
120+
@site.post_attr_hash("categories")
121121
end
122122

123123
# Custom `post_attr_hash` method for years
124124
def years
125125
hash = Hash.new { |h, key| h[key] = [] }
126126

127127
# In Jekyll 3, Collection#each should be called on the #docs array directly.
128-
if Jekyll::VERSION >= '3.0.0'
128+
if Jekyll::VERSION >= "3.0.0"
129129
@posts.docs.each { |p| hash[p.date.strftime("%Y")] << p }
130130
else
131131
@posts.each { |p| hash[p.date.strftime("%Y")] << p }

lib/jekyll-archives/archive.rb

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ class Archive
99
attr_accessor :site
1010

1111
# Attributes for Liquid templates
12-
ATTRIBUTES_FOR_LIQUID = %w[
12+
ATTRIBUTES_FOR_LIQUID = %w(
1313
posts
1414
type
1515
title
1616
date
1717
name
1818
path
1919
url
20-
]
20+
).freeze
2121

2222
# Initialize a new Archive page
2323
#
@@ -31,7 +31,7 @@ def initialize(site, title, type, posts)
3131
@posts = posts
3232
@type = type
3333
@title = title
34-
@config = site.config['jekyll-archives']
34+
@config = site.config["jekyll-archives"]
3535

3636
# Generate slug if tag or category (taken from jekyll/jekyll/features/support/env.rb)
3737
if title.to_s.length
@@ -53,17 +53,17 @@ def initialize(site, title, type, posts)
5353
#
5454
# Returns the template String.
5555
def template
56-
@config['permalinks'][type]
56+
@config["permalinks"][type]
5757
end
5858

5959
# The layout to use for rendering
6060
#
6161
# Returns the layout as a String
6262
def layout
63-
if @config['layouts'] && @config['layouts'][type]
64-
@config['layouts'][type]
63+
if @config["layouts"] && @config["layouts"][type]
64+
@config["layouts"][type]
6565
else
66-
@config['layout']
66+
@config["layout"]
6767
end
6868
end
6969

@@ -82,12 +82,12 @@ def url_placeholders
8282
# Returns the String url.
8383
def url
8484
@url ||= URL.new({
85-
:template => template,
85+
:template => template,
8686
:placeholders => url_placeholders,
87-
:permalink => nil
87+
:permalink => nil
8888
}).to_s
8989
rescue ArgumentError
90-
raise ArgumentError.new "Template \"#{template}\" provided is invalid."
90+
raise ArgumentError, "Template \"#{template}\" provided is invalid."
9191
end
9292

9393
# Add any necessary layouts to this post
@@ -108,9 +108,9 @@ def render(layouts, site_payload)
108108
#
109109
# Returns the Hash representation of this Convertible.
110110
def to_liquid(attrs = nil)
111-
further_data = Hash[(attrs || self.class::ATTRIBUTES_FOR_LIQUID).map { |attribute|
111+
further_data = Hash[(attrs || self.class::ATTRIBUTES_FOR_LIQUID).map do |attribute|
112112
[attribute, send(attribute)]
113-
}]
113+
end]
114114

115115
Utils.deep_merge_hashes(data, further_data)
116116
end
@@ -130,7 +130,7 @@ def title
130130
# Returns a Date.
131131
def date
132132
if @title.is_a? Hash
133-
args = @title.values.map { |s| s.to_i }
133+
args = @title.values.map(&:to_i)
134134
Date.new(*args)
135135
end
136136
end
@@ -150,14 +150,14 @@ def destination(dest)
150150
#
151151
# Returns the destination relative path String.
152152
def relative_path
153-
path = URL.unescape_path(url).gsub(/^\//, '')
153+
path = URL.unescape_path(url).gsub(/^\//, "")
154154
path = File.join(path, "index.html") if url =~ /\/$/
155155
path
156156
end
157157

158158
# Returns the object as a debug String.
159159
def inspect
160-
"#<Jekyll:Archive @type=#{@type.to_s} @title=#{@title} @data=#{@data.inspect}>"
160+
"#<Jekyll:Archive @type=#{@type} @title=#{@title} @data=#{@data.inspect}>"
161161
end
162162

163163
# Returns the Boolean of whether this Page is HTML or not.

lib/jekyll-archives/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Jekyll
22
module Archives
3-
VERSION = '2.1.0'
3+
VERSION = "2.1.0".freeze
44
end
55
end

test/helper.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
# Taken from jekyll/jekyll-mentions (Copyright (c) 2014 GitHub, Inc. Licensened under the MIT).
1+
# Taken from jekyll/jekyll-mentions
2+
# (Copyright (c) 2014 GitHub, Inc. Licensened under the MIT).
23

3-
require 'rubygems'
4-
require 'minitest/autorun'
5-
require 'shoulda'
4+
require "rubygems"
5+
require "minitest/autorun"
6+
require "shoulda"
67

7-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
8+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
89
$LOAD_PATH.unshift(File.dirname(__FILE__))
910

10-
require 'jekyll-archives'
11+
require "jekyll-archives"
1112

1213
TEST_DIR = File.expand_path("../", __FILE__)
1314
SOURCE_DIR = File.expand_path("source", TEST_DIR)
@@ -20,7 +21,7 @@ def fixture_site(config = {})
2021
Jekyll::Utils.deep_merge_hashes(
2122
Jekyll::Configuration::DEFAULTS,
2223
{
23-
"source" => SOURCE_DIR,
24+
"source" => SOURCE_DIR,
2425
"destination" => DEST_DIR
2526
}
2627
),

test/test_jekyll_archives.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'helper'
1+
require "helper"
22

33
class TestJekyllArchives < Minitest::Test
44
context "the jekyll-archives plugin" do
@@ -52,7 +52,7 @@ class TestJekyllArchives < Minitest::Test
5252
setup do
5353
@site = fixture_site({
5454
"jekyll-archives" => {
55-
"layout" => "archive-too",
55+
"layout" => "archive-too",
5656
"enabled" => true
5757
}
5858
})
@@ -89,10 +89,10 @@ class TestJekyllArchives < Minitest::Test
8989
setup do
9090
@site = fixture_site({
9191
"jekyll-archives" => {
92-
"enabled" => true,
92+
"enabled" => true,
9393
"permalinks" => {
94-
"year" => "/year/:year/",
95-
"tag" => "/tag-:name.html",
94+
"year" => "/year/:year/",
95+
"tag" => "/tag-:name.html",
9696
"category" => "/category-:name.html"
9797
}
9898
}
@@ -168,11 +168,11 @@ class TestJekyllArchives < Minitest::Test
168168
})
169169
@site.process
170170
@archives = @site.config["archives"]
171-
@tag_archive = @archives.detect {|a| a.type == "tag"}
172-
@category_archive = @archives.detect {|a| a.type == "category"}
173-
@year_archive = @archives.detect {|a| a.type == "year"}
174-
@month_archive = @archives.detect {|a| a.type == "month"}
175-
@day_archive = @archives.detect {|a| a.type == "day"}
171+
@tag_archive = @archives.detect { |a| a.type == "tag" }
172+
@category_archive = @archives.detect { |a| a.type == "category" }
173+
@year_archive = @archives.detect { |a| a.type == "year" }
174+
@month_archive = @archives.detect { |a| a.type == "month" }
175+
@day_archive = @archives.detect { |a| a.type == "day" }
176176
end
177177

178178
should "populate the title field in case of category or tag" do

0 commit comments

Comments
 (0)