Skip to content

Commit 91d66fb

Browse files
committed
constructor gets config, not site
1 parent 5699c12 commit 91d66fb

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

lib/jekyll-relative-links/generator.rb

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module JekyllRelativeLinks
44
class Generator < Jekyll::Generator
5-
attr_accessor :site
5+
attr_accessor :site, :config
66

77
# Use Jekyll's native relative_url filter
88
include Jekyll::Filters::URLFilters
@@ -16,20 +16,20 @@ class Generator < Jekyll::Generator
1616
CONFIG_KEY = "relative_links"
1717
ENABLED_KEY = "enabled"
1818
COLLECTIONS_KEY = "collections"
19-
LOG_KEY = "JekyllRelativeLinks:"
19+
LOG_KEY = "Relative Links:"
2020

2121
safe true
2222
priority :lowest
2323

24-
def initialize(site)
25-
@site = site
26-
@context = context
24+
def initialize(config)
25+
@config = config
2726
end
2827

2928
def generate(site)
29+
return if disabled?
30+
3031
@site = site
3132
@context = context
32-
return if disabled?
3333

3434
documents = site.pages
3535
documents = site.pages + site.docs_to_write if collections?
@@ -124,7 +124,7 @@ def fragment?(string)
124124
end
125125

126126
def option(key)
127-
site.config[CONFIG_KEY] && site.config[CONFIG_KEY][key]
127+
config[CONFIG_KEY] && config[CONFIG_KEY][key]
128128
end
129129

130130
def disabled?
@@ -150,7 +150,7 @@ def excluded?(document)
150150
end
151151

152152
def global_entry_filter
153-
@global_entry_filter ||= Jekyll::EntryFilter.new(@site)
153+
@global_entry_filter ||= Jekyll::EntryFilter.new(site)
154154
end
155155
end
156156
end

spec/jekyll-relative-links/generator_spec.rb

+5-3
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,20 @@
1717
let(:item) { doc_by_path(site, "_items/some-item.md") }
1818
let(:item_2) { doc_by_path(site, "_items/some-subdir/another-item.md") }
1919

20-
subject { described_class.new(site) }
20+
subject { described_class.new(site.config) }
2121

2222
before(:each) do
2323
site.reset
2424
site.read
2525
end
2626

27-
it "saves the site" do
28-
expect(subject.site).to eql(site)
27+
it "saves the config" do
28+
expect(subject.config).to eql(site.config)
2929
end
3030

3131
context "detecting markdown" do
32+
before { subject.instance_variable_set "@site", site }
33+
3234
it "knows when an extension is markdown" do
3335
expect(subject.send(:markdown_extension?, ".md")).to eql(true)
3436
end

0 commit comments

Comments
 (0)