Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ build: off

environment:
matrix:
- RUBY_FOLDER_VER: "25-x64"
- RUBY_FOLDER_VER: "26"
JEKYLL_VERSION: "3.7.0"
- RUBY_FOLDER_VER: "26"
JEKYLL_VERSION: "4.0.0.pre.alpha1"
- RUBY_FOLDER_VER: "26"
- RUBY_FOLDER_VER: "25"
- RUBY_FOLDER_VER: "24"
- RUBY_FOLDER_VER: "23"

install:
- SET PATH=C:\Ruby%RUBY_FOLDER_VER%\bin;%PATH%
- SET PATH=C:\Ruby%RUBY_FOLDER_VER%-x64\bin;%PATH%
- bundle install --retry 5 --jobs=%NUMBER_OF_PROCESSORS% --clean --path vendor\bundle

test_script:
Expand Down
33 changes: 27 additions & 6 deletions lib/jekyll-github-metadata/edit-link-tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,40 @@ def uri
end

def parts
@parts ||= [repository_url, "edit/", branch, source_path, page_path]
memoize_conditionally { [repository_url, "edit/", branch, source_path, page_path] }
end

def parts_normalized
@parts_normalized ||= parts.map.with_index do |part, index|
part = remove_leading_slash(part.to_s)
part = ensure_trailing_slash(part) unless index == parts.length - 1
ensure_not_just_a_slash(part)
memoize_conditionally do
parts.map.with_index do |part, index|
part = remove_leading_slash(part.to_s)
part = ensure_trailing_slash(part) unless index == parts.length - 1
ensure_not_just_a_slash(part)
end
end
end

def page
@page ||= context.registers[:page]
memoize_conditionally { context.registers[:page] }
end

# Utility function for compatibility with Jekyll 4.0
def memoize_conditionally
if renderer_cached?
yield
else
dispatcher = "@#{caller_locations(1..1).first.label}".to_sym
if instance_variable_defined?(dispatcher)
instance_variable_get(dispatcher)
else
instance_variable_set(dispatcher, yield)
end
end
end

# Utility function to detect Jekyll 4.0
def renderer_cached?
@renderer_cached ||= context.registers[:site].liquid_renderer.respond_to?(:cache)
end

def site
Expand Down
15 changes: 15 additions & 0 deletions spec/edit_link_tag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,21 @@
expect(rendered).to eql("#{repository_url}/edit/#{branch}/page.md")
end

context "is conditionally context-aware" do
it "returns correct URL" do
# create a static instance. `subject` creates a different instance on each call.
tag = described_class.parse(tag_name, markup, tokenizer, parse_context)

expect(tag.render(render_context)).to eql("#{repository_url}/edit/#{branch}/page.md")
filename = site.liquid_renderer.respond_to?(:cache) ? "dummy_page.md" : "page.md"
new_context = make_context(
:page => make_page("path" => "dummy_page.md"),
:site => site
)
expect(tag.render(new_context)).to eql("#{repository_url}/edit/#{branch}/#{filename}")
end
end

context "when passed markup" do
let(:markup) { '"Improve this page"' }

Expand Down