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

Extract include tag read file in a method #1490

Merged
merged 13 commits into from Sep 19, 2013

Conversation

Projects
None yet
6 participants
@doktorbro
Member

doktorbro commented Sep 1, 2013

With that change people can easily hook into the file read procedure by inheritting from the Jekyll::Tags::IncludeTag class. For example to write a 5 lines plugin that remove trailing file whitespaces (related #1455).

@maul-esel

This comment has been minimized.

Contributor

maul-esel commented Sep 2, 2013

By itself, this code change feels strange to me; but with the given background I see no purpose to deny it unless there's a more general hook solution ahead.

I would recommend to document the purpose of that method in the code though, otherwise it might easily get killed during a refactoring in the future.

@mattr-

This comment has been minimized.

Member

mattr- commented Sep 14, 2013

I think it might make more sense to refactor the source variable into a source method that does the same thing as your method. This also means that includes_dir might need to become a method as well. This would take care of two things at once: implement your use case and refactor this class a bit.

Would you give it a try and update your pull request?

@doktorbro

This comment has been minimized.

Member

doktorbro commented Sep 14, 2013

Yes, I’ll try it. Thank you for pointing me at the better solution.

@doktorbro

This comment has been minimized.

Member

doktorbro commented Sep 15, 2013

@mattr- Done.

@parkr

View changes

lib/jekyll/tags/include.rb Outdated
@@ -4,6 +4,8 @@ class IncludeTag < Liquid::Tag
MATCHER = /([\w-]+)\s*=\s*(?:"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)'|([\w\.-]+))/
INCLUDES = '_includes'

This comment has been minimized.

@parkr

parkr Sep 15, 2013

Member

INCLUDES_DIR would make more sense here.

@parkr

View changes

lib/jekyll/tags/include.rb Outdated
if File.symlink?(includes_dir)
return "Includes directory '#{includes_dir}' cannot be a symlink"
def validate_file(dir)
if File.symlink?(dir)

This comment has been minimized.

@parkr

parkr Sep 15, 2013

Member

Let's make this conditional on the site being in safe mode so people can symlink it if they want in unsafe mode. Thoughts?

@parkr

View changes

lib/jekyll/tags/include.rb Outdated
if !File.exists?(file)
return "Included file #{@file} not found in _includes directory"
return "Included file #{@file} not found in #{INCLUDES} directory"
elsif File.symlink?(file)

This comment has been minimized.

@parkr

parkr Sep 15, 2013

Member

I also think the files could be symlinks in unsafe mode.

@parkr

This comment has been minimized.

Member

parkr commented Sep 15, 2013

Looks pretty good so far. @mattr- what do you think?

We'll also need a rebase please.

@doktorbro

This comment has been minimized.

Member

doktorbro commented Sep 16, 2013

Now the class looks really dry. I hope you guys like it.

@parkr

View changes

lib/jekyll/tags/include.rb Outdated
@@ -4,6 +4,10 @@ class IncludeTag < Liquid::Tag
MATCHER = /([\w-]+)\s*=\s*(?:"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)'|([\w\.-]+))/
VALID_SYNTAX = "{% include file.ext param='value' param2='value' %}"

This comment has been minimized.

@parkr

parkr Sep 17, 2013

Member

What do you think of SYNTAX_EXAMPLE for this?

@parkr

View changes

lib/jekyll/tags/include.rb Outdated
@@ -4,6 +4,10 @@ class IncludeTag < Liquid::Tag
MATCHER = /([\w-]+)\s*=\s*(?:"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)'|([\w\.-]+))/

This comment has been minimized.

@parkr

parkr Sep 17, 2013

Member

What do you think of VALID_SYNTAX for this?

@parkr

View changes

lib/jekyll/tags/include.rb Outdated
return "The included file '_includes/#{@file}' should not be a symlink"
return "Included file '#{@file}' not found in '#{INCLUDES_DIR}' directory"
elsif File.symlink?(file) && safe?
return "The included file '#{INCLUDES_DIR}/#{@file}' should not be a symlink"

This comment has been minimized.

@parkr

parkr Sep 17, 2013

Member

I'd prefer not to have the explicit returns here if that's ok.

@parkr

View changes

lib/jekyll/tags/include.rb Outdated
return "Include file '#{@file}' contains invalid characters or sequences"
def validate_dir(dir, safe)
if File.symlink?(dir) && safe?
return "Includes directory '#{dir}' cannot be a symlink"

This comment has been minimized.

@parkr

parkr Sep 17, 2013

Member

No need for this return

@parkr

View changes

lib/jekyll/tags/include.rb Outdated
if @file !~ /^[a-zA-Z0-9_\/\.-]+$/ || @file =~ /\.\// || @file =~ /\/\./
return "Include file '#{@file}' contains invalid characters or sequences"
def validate_dir(dir, safe)
if File.symlink?(dir) && safe?

This comment has been minimized.

@parkr

parkr Sep 17, 2013

Member

I think this safe? is a CoffeeScript paradigm, but I don't think it's in Ruby.

@mattr-

View changes

lib/jekyll/tags/include.rb Outdated
end
end
def blank?
false
end
# This method allows to modify the file content by inheriting from the class.
# Don’t refactor it.

This comment has been minimized.

@mattr-

mattr- Sep 17, 2013

Member

I don't think this last line in the comment is necessary anymore. Because it's obvious how the method is used now, it's unlikely to be a candidate for a refactoring (and in fact looks like it was created as part of a refactoring) 😃

@mattr-

This comment has been minimized.

Member

mattr- commented Sep 17, 2013

Just a few small things and then this will be good to go. Nice work @penibelst ❤️

@coveralls

This comment has been minimized.

coveralls commented Sep 17, 2013

Coverage Status

Changes Unknown when pulling 25519b3 on penibelst:allow-include-read-override into * on mojombo:master*.

@coveralls

This comment has been minimized.

coveralls commented Sep 17, 2013

Coverage Status

Changes Unknown when pulling 7cec996 on penibelst:allow-include-read-override into * on mojombo:master*.

@maul-esel

This comment has been minimized.

Contributor

maul-esel commented Sep 17, 2013

Might I note: early validation of file name etc. is, by itself, a very good idea. However, it is totally incompatible to #1495 (variables as file names). In case this PR is merged first, I'll have to rebase mine and partly revert this change.

@parkr

View changes

lib/jekyll/tags/include.rb Outdated
unless @params =~ full_matcher
def validate_file_name
if @file !~ /^[a-zA-Z0-9_\/\.-]+$/ || @file =~ /\.\// || @file =~ /\/\./
raise SyntaxError.new <<-eos

This comment has been minimized.

@parkr

parkr Sep 17, 2013

Member

Do you think this should be an ArgumentError? I think SyntaxError is reserved for Ruby syntax issues.

@parkr

This comment has been minimized.

Member

parkr commented Sep 17, 2013

@penibelst I really, really like this. Thank you so much for all your hard work on this!!

@coveralls

This comment has been minimized.

coveralls commented Sep 17, 2013

Coverage Status

Changes Unknown when pulling f97eed5 on penibelst:allow-include-read-override into * on mojombo:master*.

@doktorbro

This comment has been minimized.

Member

doktorbro commented Sep 17, 2013

@maul-esel Do what you have to do. All I initially wanted was to extract the source read procedure in a one line method.

@parkr Thank you.

What is the Invisible Man @coveralls trying to tell me?

@maul-esel

This comment has been minimized.

Contributor

maul-esel commented Sep 17, 2013

@coveralls is the bot of coveralls.io, trying to determine if merging your PR improves the test suite (but failing, because it has been setup for jekyll after you opened your PR).

@doktorbro

This comment has been minimized.

Member

doktorbro commented Sep 17, 2013

I’ll block @coveralls as long as it clutters human comments.

@maul-esel

This comment has been minimized.

Contributor

maul-esel commented Sep 17, 2013

Yeah I liked it at first as well, but it's a little annyoing now. The commenting can be turned off though on coveralls.io. Not sure if @parkr and @mattr- as collaborators can do it, or just @mojombo himself.

@parkr

This comment has been minimized.

Member

parkr commented Sep 18, 2013

I've turned it off for now. It's kind of helpful as we require tests for all contributions (per our CONTRIBUTING docs) but it does clutter for the push-frequent folks.

@parkr

This comment has been minimized.

Member

parkr commented Sep 18, 2013

This PR LGTM. @mattr-?

@mattr-

This comment has been minimized.

Member

mattr- commented Sep 19, 2013

❤️ ❤️ ❤️ ❤️ ❤️

Nice work!

mattr- added a commit that referenced this pull request Sep 19, 2013

@mattr- mattr- merged commit 793eb96 into jekyll:master Sep 19, 2013

1 check failed

default The Travis CI build failed
Details

mattr- added a commit that referenced this pull request Sep 19, 2013

@doktorbro doktorbro deleted the doktorbro:allow-include-read-override branch Sep 19, 2013

@jekyll jekyll locked and limited conversation to collaborators Feb 27, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.