Skip to content

rename Liquid 4 has_key to key to add compatibility for liquid 4 #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 21, 2017

Conversation

marcanuy
Copy link
Contributor

Using Liquid 4 key.

Copy link
Member

@DirtyF DirtyF left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It did fix the error message that prevented Jekyll 3.5 from compiling

@benbalter
Copy link
Contributor

Based on the failing tests, we may need to see if context responds to key? and if not use has_key? to maintain compatibility with pre 3.5.

@marcanuy
Copy link
Contributor Author

What about this? Having each code for both versions:

          if Gem.loaded_specs['liquid'].version < Gem::Version.create('4.0')
            if context.has_key?(gist_id)
              gist_id = context[gist_id]
            end
            if context.has_key?(filename)
              filename = context[filename]
            end
          else
            if context.key?(gist_id)
              gist_id = context[gist_id]
            end
            if context.key?(filename)
              filename = context[filename]
            end
          end

Until there is another more elegant solution.

@parkr
Copy link
Member

parkr commented Jun 20, 2017

What about a helper method?

          
            if context_contains_key?(context, gist_id)
              gist_id = context[gist_id]
            end

            if context_contains_key?(context, filename)
              filename = context[filename]
            end
      
# ...

def context_contains_key?(context, key)
  if context.respond_to?(:has_key?)
    context.has_key?(key)
  else
    context.key?(key)
  end
end

@DirtyF
Copy link
Member

DirtyF commented Jun 20, 2017

@benbalter you're right without a helper it is not backward compatible

Liquid Exception: undefined method key?' for #<Liquid::Context:0x007fe5abf97cf0> in /Users/frank/code/jamstatic.fr/_posts/2016-09-18-utiliser-des-plugins-jekyll-avec-github-pages.md jekyll 3.4.3 | Error: undefined method key?' for #Liquid::Context:0x007fe5abf97cf0

marcanuy added a commit to marcanuy/jekyll-gist that referenced this pull request Jun 21, 2017
@DirtyF
Copy link
Member

DirtyF commented Jun 21, 2017

Works fine on 3.4.3 and 3.5.0
Do this plugin still want to support Jekyll 2.0?

@parkr
Copy link
Member

parkr commented Jun 21, 2017

Do this plugin still want to support Jekyll 2.0?

Jekyll 2.0 is old enough that I would say no, we don't need support for it.

@parkr parkr changed the title rename Liquid 4 has_key to key rename Liquid 4 has_key to key to add compatibility for liquid 4 Jun 21, 2017
@parkr
Copy link
Member

parkr commented Jun 21, 2017

@jekyllbot: merge

@jekyllbot jekyllbot merged commit 18efb2a into jekyll:master Jun 21, 2017
jekyllbot added a commit that referenced this pull request Jun 21, 2017
parkr added a commit that referenced this pull request Jun 21, 2017
@jekyll jekyll locked and limited conversation to collaborators Apr 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants