Skip to content
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
Merged

Extract include tag read file in a method #1490

merged 13 commits into from
Sep 19, 2013

Conversation

doktorbro
Copy link
Member

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
Copy link

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-
Copy link
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
Copy link
Member Author

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

@doktorbro
Copy link
Member Author

@mattr- Done.

@@ -4,6 +4,8 @@ class IncludeTag < Liquid::Tag

MATCHER = /([\w-]+)\s*=\s*(?:"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)'|([\w\.-]+))/

INCLUDES = '_includes'
Copy link
Member

Choose a reason for hiding this comment

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

INCLUDES_DIR would make more sense here.

@parkr
Copy link
Member

parkr commented Sep 15, 2013

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

We'll also need a rebase please.

@doktorbro
Copy link
Member Author

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

@@ -4,6 +4,10 @@ class IncludeTag < Liquid::Tag

MATCHER = /([\w-]+)\s*=\s*(?:"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)'|([\w\.-]+))/

VALID_SYNTAX = "{% include file.ext param='value' param2='value' %}"
Copy link
Member

Choose a reason for hiding this comment

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

What do you think of SYNTAX_EXAMPLE for this?

@mattr-
Copy link
Member

mattr- commented Sep 17, 2013

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

@coveralls
Copy link

Coverage Status

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

@coveralls
Copy link

Coverage Status

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

@maul-esel
Copy link

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.

unless @params =~ full_matcher
def validate_file_name
if @file !~ /^[a-zA-Z0-9_\/\.-]+$/ || @file =~ /\.\// || @file =~ /\/\./
raise SyntaxError.new <<-eos
Copy link
Member

Choose a reason for hiding this comment

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

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

@parkr
Copy link
Member

parkr commented Sep 17, 2013

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

@coveralls
Copy link

Coverage Status

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

@doktorbro
Copy link
Member Author

@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
Copy link

@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
Copy link
Member Author

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

@maul-esel
Copy link

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
Copy link
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
Copy link
Member

parkr commented Sep 18, 2013

This PR LGTM. @mattr-?

@mattr-
Copy link
Member

mattr- commented Sep 19, 2013

❤️ ❤️ ❤️ ❤️ ❤️

Nice work!

mattr- added a commit that referenced this pull request Sep 19, 2013
Extract include tag read file in a method
@mattr- mattr- merged commit 793eb96 into jekyll:master Sep 19, 2013
mattr- added a commit that referenced this pull request Sep 19, 2013
@doktorbro doktorbro deleted the allow-include-read-override branch September 19, 2013 05:43
@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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants