Skip to content

Commit 14652e6

Browse files
authored
Merge pull request #65 from DirtyF/rubocop
Merge pull request 65
2 parents 112c508 + b8b0bf1 commit 14652e6

File tree

9 files changed

+101
-106
lines changed

9 files changed

+101
-106
lines changed

.rubocop.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
inherit_gem:
2+
jekyll: .rubocop.yml
3+
4+
5+
Metrics/BlockLength:
6+
Exclude:
7+
- test/**/*.rb
8+
Metrics/LineLength:
9+
Exclude:
10+
- test/**/*.rb

Gemfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
source 'https://rubygems.org'
1+
source "https://rubygems.org"
22
gemspec
33

44
if ENV["GH_PAGES"]
@@ -8,4 +8,4 @@ elsif ENV["JEKYLL_VERSION"]
88
end
99

1010
# Support for Ruby < 2.2.2 & activesupport
11-
gem "activesupport", "~> 4.2" if RUBY_VERSION < '2.2.2'
11+
gem "activesupport", "~> 4.2" if RUBY_VERSION < "2.2.2"

Rakefile

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# From jekyll/jekyll-mentions
22

3-
require 'rubygems'
4-
require 'bundler'
3+
require "rubygems"
4+
require "bundler"
55

66
begin
77
Bundler.setup(:default, :development, :test)
@@ -11,25 +11,22 @@ rescue Bundler::BundlerError => e
1111
exit e.status_code
1212
end
1313

14-
1514
# Test task
1615

17-
require 'rake'
18-
require 'rake/testtask'
16+
require "rake"
17+
require "rake/testtask"
1918

2019
Rake::TestTask.new(:test) do |test|
21-
test.libs << 'lib' << 'test'
22-
test.pattern = 'test/**/test_*.rb'
23-
test.verbose = true
20+
test.libs << "lib" << "test"
21+
test.pattern = "test/**/test_*.rb"
2422
end
2523

26-
task :default => 'test'
27-
24+
task :default => "test"
2825

2926
# Release task
3027

3128
def name
32-
@name ||= File.basename(Dir['*.gemspec'].first, ".*")
29+
@name ||= File.basename(Dir["*.gemspec"].first, ".*")
3330
end
3431

3532
def version
@@ -46,7 +43,7 @@ end
4643

4744
desc "Release #{name} v#{version}"
4845
task :release => :build do
49-
unless `git branch` =~ /^\* master$/
46+
unless `git branch` =~ %r!^\* master$!
5047
puts "You must be on the master branch to release!"
5148
exit!
5249
end

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 "minitest"
19+
s.add_development_dependency "rake"
20+
s.add_development_dependency "rdoc"
21+
s.add_development_dependency "rubocop"
22+
s.add_development_dependency "shoulda"
2223
end

lib/jekyll-archives.rb

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
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

99
class Archives < Jekyll::Generator
1010
safe true
1111

1212
DEFAULTS = {
13-
'layout' => 'archive',
14-
'enabled' => [],
15-
'permalinks' => {
16-
'year' => '/:year/',
17-
'month' => '/:year/:month/',
18-
'day' => '/:year/:month/:day/',
19-
'tag' => '/tag/:name/',
20-
'category' => '/category/:name/'
13+
"layout" => "archive",
14+
"enabled" => [],
15+
"permalinks" => {
16+
"year" => "/:year/",
17+
"month" => "/:year/:month/",
18+
"day" => "/:year/:month/:day/",
19+
"tag" => "/tag/:name/",
20+
"category" => "/category/:name/"
2121
}
22-
}
22+
}.freeze
2323

2424
def initialize(config = nil)
25-
if config['jekyll-archives'].nil?
26-
@config = DEFAULTS
27-
else
28-
@config = Utils.deep_merge_hashes(DEFAULTS, config['jekyll-archives'])
29-
end
25+
@config = if config["jekyll-archives"].nil?
26+
DEFAULTS
27+
else
28+
Utils.deep_merge_hashes(DEFAULTS, config["jekyll-archives"])
29+
end
3030
end
3131

3232
def generate(site)
3333
@site = site
3434
@posts = site.posts
3535
@archives = []
3636

37-
@site.config['jekyll-archives'] = @config
37+
@site.config["jekyll-archives"] = @config
3838

3939
read
4040
@site.pages.concat(@archives)
@@ -80,7 +80,7 @@ def read_dates
8080
# Checks if archive type is enabled in config
8181
def enabled?(archive)
8282
@config["enabled"] == true || @config["enabled"] == "all" || if @config["enabled"].is_a? Array
83-
@config["enabled"].include? archive
83+
@config["enabled"].include? archive
8484
end
8585
end
8686

@@ -101,19 +101,19 @@ def write
101101
end
102102

103103
def tags
104-
@site.post_attr_hash('tags')
104+
@site.post_attr_hash("tags")
105105
end
106106

107107
def categories
108-
@site.post_attr_hash('categories')
108+
@site.post_attr_hash("categories")
109109
end
110110

111111
# Custom `post_attr_hash` method for years
112112
def years
113113
hash = Hash.new { |h, key| h[key] = [] }
114114

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

lib/jekyll-archives/archive.rb

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module Jekyll
22
module Archives
33
class Archive < Jekyll::Page
4-
54
attr_accessor :posts, :type, :slug
65

76
# Attributes for Liquid templates
@@ -28,12 +27,11 @@ def initialize(site, title, type, posts)
2827
@posts = posts
2928
@type = type
3029
@title = title
31-
@config = site.config['jekyll-archives']
30+
@config = site.config["jekyll-archives"]
3231

33-
# Generate slug if tag or category (taken from jekyll/jekyll/features/support/env.rb)
34-
if title.is_a? String
35-
@slug = Utils.slugify(title)
36-
end
32+
# Generate slug if tag or category
33+
# (taken from jekyll/jekyll/features/support/env.rb)
34+
@slug = Utils.slugify(title) if title.is_a? String
3735

3836
# Use ".html" for file extension and url for path
3937
@ext = File.extname(relative_path)
@@ -50,25 +48,25 @@ def initialize(site, title, type, posts)
5048
#
5149
# Returns the template String.
5250
def template
53-
@config['permalinks'][type]
51+
@config["permalinks"][type]
5452
end
5553

5654
# The layout to use for rendering
5755
#
5856
# Returns the layout as a String
5957
def layout
60-
if @config['layouts'] && @config['layouts'][type]
61-
@config['layouts'][type]
58+
if @config["layouts"] && @config["layouts"][type]
59+
@config["layouts"][type]
6260
else
63-
@config['layout']
61+
@config["layout"]
6462
end
6563
end
6664

6765
# Returns a hash of URL placeholder names (as symbols) mapping to the
6866
# desired placeholder replacements. For details see "url.rb".
6967
def url_placeholders
7068
if @title.is_a? Hash
71-
@title.merge({ :type => @type })
69+
@title.merge(:type => @type)
7270
else
7371
{ :name => @slug, :type => @type }
7472
end
@@ -79,16 +77,16 @@ def url_placeholders
7977
# Returns the String url.
8078
def url
8179
@url ||= URL.new({
82-
:template => template,
80+
:template => template,
8381
:placeholders => url_placeholders,
84-
:permalink => nil
82+
:permalink => nil
8583
}).to_s
8684
rescue ArgumentError
87-
raise ArgumentError.new "Template \"#{template}\" provided is invalid."
85+
raise ArgumentError, "Template \"#{template}\" provided is invalid."
8886
end
8987

9088
def permalink
91-
data && data.is_a?(Hash) && data['permalink']
89+
data && data.is_a?(Hash) && data["permalink"]
9290
end
9391

9492
# Add any necessary layouts to this post
@@ -115,14 +113,14 @@ def add_dependencies
115113
end
116114
end
117115
end
118-
116+
119117
# Convert this Convertible's data to a Hash suitable for use by Liquid.
120118
#
121119
# Returns the Hash representation of this Convertible.
122120
def to_liquid(attrs = nil)
123-
further_data = Hash[(attrs || self.class::ATTRIBUTES_FOR_LIQUID).map { |attribute|
121+
further_data = Hash[(attrs || self.class::ATTRIBUTES_FOR_LIQUID).map do |attribute|
124122
[attribute, send(attribute)]
125-
}]
123+
end]
126124

127125
Utils.deep_merge_hashes(data, further_data)
128126
end
@@ -132,17 +130,15 @@ def to_liquid(attrs = nil)
132130
# Returns a String (for tag and category archives) and nil for
133131
# date-based archives.
134132
def title
135-
if @title.is_a? String
136-
@title
137-
end
133+
@title if @title.is_a? String
138134
end
139135

140136
# Produce a date object if a date-based archive
141137
#
142138
# Returns a Date.
143139
def date
144140
if @title.is_a? Hash
145-
args = @title.values.map { |s| s.to_i }
141+
args = @title.values.map(&:to_i)
146142
Date.new(*args)
147143
end
148144
end
@@ -151,8 +147,8 @@ def date
151147
#
152148
# Returns the destination relative path String.
153149
def relative_path
154-
path = URL.unescape_path(url).gsub(/^\//, '')
155-
path = File.join(path, "index.html") if url =~ /\/$/
150+
path = URL.unescape_path(url).gsub(%r!^\/!, "")
151+
path = File.join(path, "index.html") if url =~ %r!\/$!
156152
path
157153
end
158154

@@ -166,7 +162,7 @@ def regenerate?
166162

167163
# Returns the object as a debug String.
168164
def inspect
169-
"#<Jekyll:Archive @type=#{@type.to_s} @title=#{@title} @data=#{@data.inspect}>"
165+
"#<Jekyll:Archive @type=#{@type} @title=#{@title} @data=#{@data.inspect}>"
170166
end
171167
end
172168
end

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
),

0 commit comments

Comments
 (0)