Skip to content

Commit

Permalink
namespace as jekyll-titles-from-headings
Browse files Browse the repository at this point in the history
  • Loading branch information
benbalter committed Nov 17, 2016
1 parent da89eda commit a575b58
Show file tree
Hide file tree
Showing 12 changed files with 111 additions and 32 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,2 +1,3 @@
*.gem
Gemfile.lock
spec/examples.txt
4 changes: 4 additions & 0 deletions .rubocop.yml
Expand Up @@ -4,3 +4,7 @@ inherit_gem:
AllCops:
Exclude:
- vendor/**/*

Metrics/BlockLength:
Exclude:
- spec/**/*
@@ -1,11 +1,11 @@
# encoding: utf-8

$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
require "titles-from-headings/version"
require "jekyll-titles-from-headings/version"

Gem::Specification.new do |s|
s.name = "titles-from-headings"
s.version = TitlesFromHeadings::VERSION
s.name = "jekyll-titles-from-headings"
s.version = JekyllTitlesFromHeadings::VERSION
s.authors = ["Ben Balter"]
s.email = ["ben.balter@github.com"]
s.homepage = "https://github.com/benbalter/titles-from-headings"
Expand Down
5 changes: 5 additions & 0 deletions lib/jekyll-titles-from-headings.rb
@@ -0,0 +1,5 @@
require "jekyll"
require "jekyll-titles-from-headings/generator"

module JekyllTitlesFromHeadings
end
@@ -1,4 +1,4 @@
module TitlesFromHeadings
module JekyllTitlesFromHeadings
class Generator < Jekyll::Generator
attr_accessor :site

Expand Down
3 changes: 3 additions & 0 deletions lib/jekyll-titles-from-headings/version.rb
@@ -0,0 +1,3 @@
module JekyllTitlesFromHeadings
VERSION = "0.1.0".freeze
end
5 changes: 0 additions & 5 deletions lib/titles-from-headings.rb

This file was deleted.

3 changes: 0 additions & 3 deletions lib/titles-from-headings/version.rb

This file was deleted.

18 changes: 0 additions & 18 deletions spec/examples.txt

This file was deleted.

92 changes: 92 additions & 0 deletions spec/jekyll-titles_from_headings/generator_spec.rb
@@ -0,0 +1,92 @@
RSpec.describe JekyllTitlesFromHeadings::Generator do
let(:site) { fixture_site("site") }
let(:post) { site.posts.first }
let(:page) { page_by_path(site, "page.md") }
let(:page_with_title) { page_by_path(site, "page-with-title.md") }
let(:html_page) { page_by_path(site, "html-page.html") }
let(:page_with_h2) { page_by_path(site, "page-with-h2.md") }
let(:page_with_h3) { page_by_path(site, "page-with-h3.md") }

subject { described_class.new(site) }

before(:each) do
site.reset
site.read
end

it "saves the site" do
expect(subject.site).to eql(site)
end

context "detecting titles" do
it "knows when a page has a title" do
expect(subject.title?(page_with_title)).to eql(true)
end

it "knows when a page doesn't have a title" do
expect(subject.title?(page)).to eql(false)
end
end

context "detecting markdown" do
it "knows when a page is markdown" do
expect(subject.markdown?(page)).to eql(true)
end

it "knows when a page isn't markdown" do
expect(subject.markdown?(html_page)).to eql(false)
end

it "knows the markdown converter" do
expect(subject.markdown_converter).to be_a(Jekyll::Converters::Markdown)
end
end

context "detecting when to add a title" do
it "knows not to add a title for pages with titles" do
expect(subject.should_add_title?(page_with_title)).to eql(false)
end

it "knows not to add a title for HTML pages" do
expect(subject.should_add_title?(html_page)).to eql(false)
end

it "knows not add a title to non-HTML pages without titles" do
expect(subject.should_add_title?(page)).to eql(true)
end
end

context "extracting title" do
it "pulls title with an H1" do
expect(subject.title_for(page)).to eql("Just an H1")
end

it "pulls title with an H2" do
expect(subject.title_for(page_with_h2)).to eql("Just an H2")
end

it "pulls title with an H3" do
expect(subject.title_for(page_with_h3)).to eql("Just an H3")
end

it "respects YAML titles" do
expect(subject.title_for(page_with_title)).to eql("Page with title")
end
end

context "generating" do
before { subject.generate(site) }

it "sets titles for pages" do
expect(page.data["title"]).to eql("Just an H1")
end

it "respect a document's auto-generated title" do
expect(post.data["title"]).to eql("Test")
end

it "respects a document's YAML title" do
expect(page_with_title.data["title"]).to eql("Page with title")
end
end
end
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
@@ -1,4 +1,4 @@
require "titles-from-headings"
require "jekyll-titles-from-headings"

RSpec.configure do |config|
config.expect_with :rspec do |expectations|
Expand Down
2 changes: 1 addition & 1 deletion spec/titles_from_headings/generator_spec.rb
@@ -1,4 +1,4 @@
RSpec.describe TitlesFromHeadings::Generator do
RSpec.describe JekyllTitlesFromHeadings::Generator do
let(:site) { fixture_site("site") }
let(:post) { site.posts.first }
let(:page) { page_by_path(site, "page.md") }
Expand Down

0 comments on commit a575b58

Please sign in to comment.