Skip to content

Commit

Permalink
Merge pull request #65 from DirtyF/rubocop
Browse files Browse the repository at this point in the history
Merge pull request 65
  • Loading branch information
jekyllbot authored Jan 24, 2017
2 parents 112c508 + b8b0bf1 commit 14652e6
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 106 deletions.
10 changes: 10 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
inherit_gem:
jekyll: .rubocop.yml


Metrics/BlockLength:
Exclude:
- test/**/*.rb
Metrics/LineLength:
Exclude:
- test/**/*.rb
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source 'https://rubygems.org'
source "https://rubygems.org"
gemspec

if ENV["GH_PAGES"]
Expand All @@ -8,4 +8,4 @@ elsif ENV["JEKYLL_VERSION"]
end

# Support for Ruby < 2.2.2 & activesupport
gem "activesupport", "~> 4.2" if RUBY_VERSION < '2.2.2'
gem "activesupport", "~> 4.2" if RUBY_VERSION < "2.2.2"
21 changes: 9 additions & 12 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# From jekyll/jekyll-mentions

require 'rubygems'
require 'bundler'
require "rubygems"
require "bundler"

begin
Bundler.setup(:default, :development, :test)
Expand All @@ -11,25 +11,22 @@ rescue Bundler::BundlerError => e
exit e.status_code
end


# Test task

require 'rake'
require 'rake/testtask'
require "rake"
require "rake/testtask"

Rake::TestTask.new(:test) do |test|
test.libs << 'lib' << 'test'
test.pattern = 'test/**/test_*.rb'
test.verbose = true
test.libs << "lib" << "test"
test.pattern = "test/**/test_*.rb"
end

task :default => 'test'

task :default => "test"

# Release task

def name
@name ||= File.basename(Dir['*.gemspec'].first, ".*")
@name ||= File.basename(Dir["*.gemspec"].first, ".*")
end

def version
Expand All @@ -46,7 +43,7 @@ end

desc "Release #{name} v#{version}"
task :release => :build do
unless `git branch` =~ /^\* master$/
unless `git branch` =~ %r!^\* master$!
puts "You must be on the master branch to release!"
exit!
end
Expand Down
15 changes: 8 additions & 7 deletions jekyll-archives.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
lib = File.expand_path('../lib', __FILE__)
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'jekyll-archives/version'
require "jekyll-archives/version"

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

s.add_dependency "jekyll", '>= 2.4'
s.add_dependency "jekyll", ">= 2.4"

s.add_development_dependency 'rake'
s.add_development_dependency 'rdoc'
s.add_development_dependency 'shoulda'
s.add_development_dependency 'minitest'
s.add_development_dependency "minitest"
s.add_development_dependency "rake"
s.add_development_dependency "rdoc"
s.add_development_dependency "rubocop"
s.add_development_dependency "shoulda"
end
44 changes: 22 additions & 22 deletions lib/jekyll-archives.rb
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
require 'jekyll'
require "jekyll"

module Jekyll
module Archives
# Internal requires
autoload :Archive, 'jekyll-archives/archive'
autoload :VERSION, 'jekyll-archives/version'
autoload :Archive, "jekyll-archives/archive"
autoload :VERSION, "jekyll-archives/version"

class Archives < Jekyll::Generator
safe true

DEFAULTS = {
'layout' => 'archive',
'enabled' => [],
'permalinks' => {
'year' => '/:year/',
'month' => '/:year/:month/',
'day' => '/:year/:month/:day/',
'tag' => '/tag/:name/',
'category' => '/category/:name/'
"layout" => "archive",
"enabled" => [],
"permalinks" => {
"year" => "/:year/",
"month" => "/:year/:month/",
"day" => "/:year/:month/:day/",
"tag" => "/tag/:name/",
"category" => "/category/:name/"
}
}
}.freeze

def initialize(config = nil)
if config['jekyll-archives'].nil?
@config = DEFAULTS
else
@config = Utils.deep_merge_hashes(DEFAULTS, config['jekyll-archives'])
end
@config = if config["jekyll-archives"].nil?
DEFAULTS
else
Utils.deep_merge_hashes(DEFAULTS, config["jekyll-archives"])
end
end

def generate(site)
@site = site
@posts = site.posts
@archives = []

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

read
@site.pages.concat(@archives)
Expand Down Expand Up @@ -80,7 +80,7 @@ def read_dates
# Checks if archive type is enabled in config
def enabled?(archive)
@config["enabled"] == true || @config["enabled"] == "all" || if @config["enabled"].is_a? Array
@config["enabled"].include? archive
@config["enabled"].include? archive
end
end

Expand All @@ -101,19 +101,19 @@ def write
end

def tags
@site.post_attr_hash('tags')
@site.post_attr_hash("tags")
end

def categories
@site.post_attr_hash('categories')
@site.post_attr_hash("categories")
end

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

# In Jekyll 3, Collection#each should be called on the #docs array directly.
if Jekyll::VERSION >= '3.0.0'
if Jekyll::VERSION >= "3.0.0"
@posts.docs.each { |p| hash[p.date.strftime("%Y")] << p }
else
@posts.each { |p| hash[p.date.strftime("%Y")] << p }
Expand Down
46 changes: 21 additions & 25 deletions lib/jekyll-archives/archive.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module Jekyll
module Archives
class Archive < Jekyll::Page

attr_accessor :posts, :type, :slug

# Attributes for Liquid templates
Expand All @@ -28,12 +27,11 @@ def initialize(site, title, type, posts)
@posts = posts
@type = type
@title = title
@config = site.config['jekyll-archives']
@config = site.config["jekyll-archives"]

# Generate slug if tag or category (taken from jekyll/jekyll/features/support/env.rb)
if title.is_a? String
@slug = Utils.slugify(title)
end
# Generate slug if tag or category
# (taken from jekyll/jekyll/features/support/env.rb)
@slug = Utils.slugify(title) if title.is_a? String

# Use ".html" for file extension and url for path
@ext = File.extname(relative_path)
Expand All @@ -50,25 +48,25 @@ def initialize(site, title, type, posts)
#
# Returns the template String.
def template
@config['permalinks'][type]
@config["permalinks"][type]
end

# The layout to use for rendering
#
# Returns the layout as a String
def layout
if @config['layouts'] && @config['layouts'][type]
@config['layouts'][type]
if @config["layouts"] && @config["layouts"][type]
@config["layouts"][type]
else
@config['layout']
@config["layout"]
end
end

# Returns a hash of URL placeholder names (as symbols) mapping to the
# desired placeholder replacements. For details see "url.rb".
def url_placeholders
if @title.is_a? Hash
@title.merge({ :type => @type })
@title.merge(:type => @type)
else
{ :name => @slug, :type => @type }
end
Expand All @@ -79,16 +77,16 @@ def url_placeholders
# Returns the String url.
def url
@url ||= URL.new({
:template => template,
:template => template,
:placeholders => url_placeholders,
:permalink => nil
:permalink => nil
}).to_s
rescue ArgumentError
raise ArgumentError.new "Template \"#{template}\" provided is invalid."
raise ArgumentError, "Template \"#{template}\" provided is invalid."
end

def permalink
data && data.is_a?(Hash) && data['permalink']
data && data.is_a?(Hash) && data["permalink"]
end

# Add any necessary layouts to this post
Expand All @@ -115,14 +113,14 @@ def add_dependencies
end
end
end

# Convert this Convertible's data to a Hash suitable for use by Liquid.
#
# Returns the Hash representation of this Convertible.
def to_liquid(attrs = nil)
further_data = Hash[(attrs || self.class::ATTRIBUTES_FOR_LIQUID).map { |attribute|
further_data = Hash[(attrs || self.class::ATTRIBUTES_FOR_LIQUID).map do |attribute|
[attribute, send(attribute)]
}]
end]

Utils.deep_merge_hashes(data, further_data)
end
Expand All @@ -132,17 +130,15 @@ def to_liquid(attrs = nil)
# Returns a String (for tag and category archives) and nil for
# date-based archives.
def title
if @title.is_a? String
@title
end
@title if @title.is_a? String
end

# Produce a date object if a date-based archive
#
# Returns a Date.
def date
if @title.is_a? Hash
args = @title.values.map { |s| s.to_i }
args = @title.values.map(&:to_i)
Date.new(*args)
end
end
Expand All @@ -151,8 +147,8 @@ def date
#
# Returns the destination relative path String.
def relative_path
path = URL.unescape_path(url).gsub(/^\//, '')
path = File.join(path, "index.html") if url =~ /\/$/
path = URL.unescape_path(url).gsub(%r!^\/!, "")
path = File.join(path, "index.html") if url =~ %r!\/$!
path
end

Expand All @@ -166,7 +162,7 @@ def regenerate?

# Returns the object as a debug String.
def inspect
"#<Jekyll:Archive @type=#{@type.to_s} @title=#{@title} @data=#{@data.inspect}>"
"#<Jekyll:Archive @type=#{@type} @title=#{@title} @data=#{@data.inspect}>"
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/jekyll-archives/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Jekyll
module Archives
VERSION = '2.1.0'
VERSION = "2.1.0".freeze
end
end
15 changes: 8 additions & 7 deletions test/helper.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# Taken from jekyll/jekyll-mentions (Copyright (c) 2014 GitHub, Inc. Licensened under the MIT).
# Taken from jekyll/jekyll-mentions
# (Copyright (c) 2014 GitHub, Inc. Licensened under the MIT).

require 'rubygems'
require 'minitest/autorun'
require 'shoulda'
require "rubygems"
require "minitest/autorun"
require "shoulda"

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
$LOAD_PATH.unshift(File.dirname(__FILE__))

require 'jekyll-archives'
require "jekyll-archives"

TEST_DIR = File.expand_path("../", __FILE__)
SOURCE_DIR = File.expand_path("source", TEST_DIR)
Expand All @@ -20,7 +21,7 @@ def fixture_site(config = {})
Jekyll::Utils.deep_merge_hashes(
Jekyll::Configuration::DEFAULTS,
{
"source" => SOURCE_DIR,
"source" => SOURCE_DIR,
"destination" => DEST_DIR
}
),
Expand Down
Loading

0 comments on commit 14652e6

Please sign in to comment.