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
Support a new relative_include
tag
#2870
Conversation
I like it. Feels like it overlaps with collections, though... Collection documents are meant to be pieces of include-able stuff. That's why collections are optionally rendered. Have you tried this with collections? |
I've just tried working it out in collections, here's my experience so far. I create an _assets directory to start with. As I would like to keep my SASS and JS/CS in separate, but within one directory, I create two subfolders for each of them. As you pointed out, I can flip {% for asset in site.assets %}
{{ asset.output }}
{% endfor %} And here's the rub (as I see it): we're just dumping the contents straight into the HTML. We're not able to compress it, or even generate a single file. Well, that's not entirely true: I can create a separate file outside of my _assets directory, whose sole purpose it is to collect the CSS and JS within the loop, so that it can be included in the project. Now I have two assets directories. I can push to a dummy repo to show what I mean, but I'm trying to work out a way for there to be just a single assets directory that contains all the assets. For Sass, this is pretty easy. Create assets/stylesheets, then create a file called application.scss, with these contents: ---
---
@import 'globals';
@import 'plugins';
@import 'sections';
@import 'shared'; In _config.yml, write the following and you're done: sass:
sass_dir: assets/stylesheets/
style: :compressed For JS, you can create a single file like the one above. And with Am I mistaken somewhere? |
@@ -138,7 +148,11 @@ def source(file, context) | |||
File.read(file, file_read_opts(context)) | |||
end | |||
end | |||
|
|||
class RelativeIncludeTag < IncludeTag | |||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why use case statements instead of just overwrite certain methods based on the tag class? If you have a separate class, you may as well separate the class-specific code from each other. 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true.dat
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want me to do that, I am happy to submit a PR to your PR. Or something? #howtogithub
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I was planing on just killing this and relying more on tag_name
to do the weight. There's only two spots that need to change. Does that make sense? #howdoiprogram
Please note, that all includes run through the Liquid parser. I remember issues in the past with including sass files, because Liquid fails on invalid Is |
def render(context) | ||
dir = File.join(File.realpath(context.registers[:site].source), INCLUDES_DIR) | ||
dir = dir_to_include(context) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dir_to_include
? Are we including the whole dir? Or is it resolved_includes_dir
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second one. 😊
Lookin' preeeeety good! Just a couple comments above. ❤️ |
MERGED. 🎯 Would you mind writing some docs for this? There are docs already for the |
@parkr More than these? gjtorikian@afd30b0 ☕ |
Yeah -- there will be confusion (probably) around how relativity is applied there. Relative to site source? To includes dir? A bit more verbiage might halp :) |
yes please more verbiage. i'm studying this right now (via github.com/jekyll/site/_includes/docs_ul.html): {% assign items = include.items %}
<ul>
{% for item in items %}
{% assign item_url = item | prepend:"/docs/" | append:"/" %}
{% if item_url == page.url %}
{% assign c = "current" %}
{% else %}
{% assign c = "" %}
{% endif %}
{% for p in site.docs %}
{% if p.url == item_url %}
<li class="{{ c }}"><a href="{{ site.url }}{{ p.url }}">{{ p.title }}</a></li>
{% endif %}
{% endfor %}
{% endfor %}
</ul> I figure it's got something to do with this PR, but still don't get it. |
The above code has nothing to do with this PR. |
+1 for relative includes! Any idea when this will make it into the |
It already is! We shipped Jekyll 2.4.0, which includes this, a few weeks ago. |
OMG, nice! 👍 That just made my weekend. Thanks @gjtorikian!!! |
Are there any docs for this? |
Thanks! |
This PR aims to solve a problem reported here and elsewhere.
When it comes to assets, I'm perfectly happy with the following import strategy:
What bothers me, though, is that I must place my assets in the _includes folder. Given that SASS has its own
import
notation, and that I want to be a good citizen and use Bower for imports, it becomes impossible to keep all my assets tidy and in a single location.With
relative_include
, I should be able to include files relative to the file they're defined in. I should not be able to do../
and go somewhere else--that's bad. Most of this checking--along with evil symlinks--is already accomplished by the currentIncludeTag
, which is very nice.Please let me know how you feel about this. 💟