Skip to content

Commit

Permalink
It's ready for you, world.
Browse files Browse the repository at this point in the history
  • Loading branch information
envygeeks committed Jul 14, 2015
0 parents commit af81bee
Show file tree
Hide file tree
Showing 19 changed files with 298 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/spec/fixture/.*
/spec/fixture/_site
/Gemfile.lock
/coverage
/.bundle
/vendor
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--color
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
rvm:
- 2.0
- 2.1
- 2.2
notifications:
recipients:
- jordon@envygeeks.io
branches:
only:
- master
7 changes: 7 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source "https://rubygems.org"
gemspec

gem "rake"
group :development do
gem "pry"
end
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright 2015 Jordon Bedwell.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[![Build Status](https://travis-ci.org/envygeeks/ruby-jekyll3-post-tags.png?branch=master)](https://travis-ci.org/envygeeks/ruby-jekyll3-post-tags) [![Coverage Status](https://coveralls.io/repos/envygeeks/ruby-jekyll3-post-tags/badge.png?branch=master)](https://coveralls.io/r/envygeeks/ruby-jekyll3-post-tags) [![Code Climate](https://codeclimate.com/github/envygeeks/ruby-jekyll3-post-tags/badges/gpa.svg)](https://codeclimate.com/github/envygeeks/ruby-jekyll3-post-tags) [![Dependency Status](https://gemnasium.com/envygeeks/ruby-jekyll3-post-tags.svg)](https://gemnasium.com/envygeeks/ruby-jekyll3-post-tags)
3 changes: 3 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec)
task :default => [:spec]
21 changes: 21 additions & 0 deletions jekyll3-post-tags.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
$:.unshift(File.expand_path("../lib", __FILE__))
require "jekyll/post/tags/version"

Gem::Specification.new do |spec|
spec.description = "Assets using Sprockets 3 for your Jekyll 3"
spec.files = %W(Rakefile Gemfile README.md LICENSE) + Dir["lib/**/*"]
spec.homepage = "http://github.com/envygeeks/ruby-jekyll3-post-tags/"
spec.version = Jekyll::Post::Tags::VERSION
spec.summary = "Post Tags for Jekyll3"
spec.email = ["jordon@envygeeks.io"]
spec.name = "jekyll3-post-tags"
spec.license = "MIT"
spec.has_rdoc = false
spec.require_paths = ["lib"]
spec.authors = ["Jordon Bedwell"]

spec.add_runtime_dependency("jekyll", "~> 3.0.0.pre.beta7")
spec.add_development_dependency("envygeeks-coveralls", "~> 1.0")
spec.add_development_dependency("luna-rspec-formatters", "~> 3.3")
spec.add_development_dependency("rspec", "~> 3.3")
end
4 changes: 4 additions & 0 deletions lib/jekyll/post/tags.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require "jekyll"
require "jekyll/post"
require_relative "tags/generator"
require_relative "tags/template"
19 changes: 19 additions & 0 deletions lib/jekyll/post/tags/generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module Jekyll
module Tags
class Generator < Jekyll::Generator
priority :low; safe true

def generate(site)
if site.layouts.has_key?("tag")
then site.tags.keys.each do |t|
site.pages.push(
Post::Tags::Template.new(
site, t
)
)
end
end
end
end
end
end
68 changes: 68 additions & 0 deletions lib/jekyll/post/tags/template.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
module Jekyll
class Post
module Tags
class Template < Jekyll::Page
attr_accessor :site, :base, :tag, :dir, :name, :tag_layout

def initialize(site, tag)
@site = site
@tag = tag
@base = site.source
@dir, @name = tag_path
@tag_layout = "tag.html"
process_tag_template
setup_defaults
end

def regenerate?
@site.posts.any? do |v|
@site.regenerator.regenerate?(v)
end
end

def write(*a)
if regenerate?
super
end
end

def render(*a)
if regenerate?
super
end
end

private
def process_tag_template
base = File.join(@base, @site.config["layouts"])
read_yaml(base, @tag_layout)
process(@name)
end

private
def tag_path
pth = @site.config["tag_permalink"] ||= "tag/:tag"
pth = pth.sub(":tag", @tag).gsub(/\A\//, "").split(
"/"
)

unless pth[-1] =~ /\.html$/
pth[-1] = "#{pth[-1]}.html"
end

[
pth[0...-1].join("/"),
pth.last
]
end

private
def setup_defaults
@data["title"] ||= "Tag: #{@tag}"
@data["description"] ||= "Tag: #{@tag}"
@data["tag"] = @tag
end
end
end
end
end
7 changes: 7 additions & 0 deletions lib/jekyll/post/tags/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Jekyll
class Post
module Tags
VERSION = "0.0.1"
end
end
end
11 changes: 11 additions & 0 deletions spec/fixture/_layouts/default.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
---
<!DOCTYPE html>
<html>
<head>
<title>{{ page.title }}</title>
</head>
<body>
{{ content }}
</body>
</html>
12 changes: 12 additions & 0 deletions spec/fixture/_layouts/tag.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
layout: default
recent: false
sidebar: "blog"
heading: true
---

<ul class="tags">
{% for post in site.tags[page.tag] %}
<li>{{ page.tag }}</li>
{% endfor %}
</ul>
5 changes: 5 additions & 0 deletions spec/fixture/_posts/2014-07-14-test-post.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
tags: [hello, world]
---

Hello World
17 changes: 17 additions & 0 deletions spec/lib/jekyll/post/tags_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require "rspec/helper"
describe Jekyll::Post::Tags do
before :each do
silence_stdout do
stub_jekyll_site.process
end
end

let :base do
File.expand_path("../../../../fixture/_site", __FILE__)
end

it "should generate html pages" do
expect(Pathname.new(File.join(base, "tag/hello.html"))).to exist
expect(Pathname.new(File.join(base, "tag/world.html"))).to exist
end
end
9 changes: 9 additions & 0 deletions spec/rspec/helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require "rspec"
require "support/simplecov"
require "luna/rspec/formatters/checks"
require "jekyll/post/tags"
require "jekyll"

Dir[File.expand_path("../../support/*.rb", __FILE__)].each do |v|
require v
end
73 changes: 73 additions & 0 deletions spec/support/jekyll.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
module Jekyll::RSpecHelpers
def silence_stdout(return_stringio = false)
old_stdout, old_stderr = $stdout, $stderr
$stdout = stdout = StringIO.new
$stderr = stderr = StringIO.new
output = yield
if return_stringio
return [
$stdout.string,
$stderr.string
]
else
return output
end
ensure
$stdout = old_stdout
$stderr = old_stderr
end

def capture_stdout(&block)
return silence_stdout(
true, &block
)
end

def strip_ansi(str)
str.gsub(
/\e\[(?:\d+)(?:;\d+)?m/, ""
)
end

def stub_jekyll_site(oth_opts = {})
opts = Jekyll::Utils.deep_merge_hashes(
Jekyll::Configuration::DEFAULTS, {
"full_rebuild" => true,
"source" => File.expand_path("../../fixture", __FILE__),
"destination" => File.expand_path("../../fixture/_site", __FILE__)
}
)

Jekyll::Site.new(
Jekyll::Utils.deep_merge_hashes(
opts, oth_opts
)
)
end

def get_stubbed_file(file)
File.read(
File.join(
File.expand_path("../../fixture/_site", __FILE__), file
)
)
end

class << self
def cleanup_trash
%W(.asset-cache .jekyll-metadata _site _assets/manifest.json).each do |v|
FileUtils.rm_rf(
File.join(
File.expand_path("../../fixture", __FILE__), v
)
)
end
end
end
end

RSpec.configure do |c|
c.include Jekyll::RSpecHelpers
c.before(:each) { Jekyll::RSpecHelpers.cleanup_trash }
c.after (:each) { Jekyll::RSpecHelpers.cleanup_trash }
end
5 changes: 5 additions & 0 deletions spec/support/simplecov.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require "envygeeks/coveralls"
SimpleCov.start do
add_filter "/spec/"
add_filter "/vendor/"
end

0 comments on commit af81bee

Please sign in to comment.