-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
more generic composition #8
Comments
It think this is doable, but it would be a lot easier to explain just by changing some code. Is this repo publicly available, or is there any chance you could put it up somewhere (or even a reduced test case) so we can collaborate on getting it working for you? |
@doowb do you have any thoughts on how we can accomplish this? I like the use case |
my project is a mess right now as i have been hacking all kinds of things together trying to get this "directory structure as collection configuration" setup working. however, i will either clean it or make a simplified test case repo and get that posted soon. thanks again. |
Actually, you know what might work... we could allow |
I can take a look. I don't have any ideas off the top of my head, but a reduced test case repo would be helpful. |
@doowb @jonschlinkert working on a simplified test case repo as we speak .. my project is a bit in tatters and i am very new to git/etc.. thanks for your patience. @doowb yes, i added the collections to
thus this would indicate that the however, what i am going for is the ability to define collections by the directory structure (and possibly YAML/YFM data) instead of adding an explicit directive for each collection inside the Gruntfile. this would allow one to add more items (in this case a new will get that test repo up soon. thanks. |
Okay, looking at that From the main post, it looks like you're trying to build a list of "index" pages for each release and each "index" page will contain the content of the Are you also wanting to render out each individual |
bingo. a
yes, this is the other issue: each track's thanks. |
OK, thanks for your patience and help so far. i created a simple repo to hopefully demonstrate what i am trying to do: https://github.com/waynedpj/Assemble-releases all the config and data is in the we can consider my goals are:
thanks again. |
K. I think it looks close and we should just have to add some YFM to the |
Made the changes to the show rendering the tracks inside the releases' index.html. Rendering the tracks themselves should be just running assemble normally. |
Hope this helps |
Hi @waynedpj (and everyone else), First, I recognized your use case and setup from a ruhoh discussion. Just curious- what made you look at/move to assemble? (this may be a discussion for a different venue) Second, my setup is a little similar to yours, so I thought I'd share. I'm trying to create a magazine archive consisting of issues and articles. Here is the directory structure I am using:
To display the correct articles on the issue's Here is the gruntfile:
I am also new to this—open to comments, suggestions, etc... |
definitely helps @doowb thanks so much. i made some comments on the commit but i realize that i should have put them here. copying+pasting .. thank you very much for the quick help. it works as expected with both releases. i played with this in my project and was able to get it a little more generic by placing a
which sets the so in my layout for releases i now have anyway, i have a few follow ups that i will post in the original thread once i get my head around this a bit more. thanks again to you and @jonschlinkert for the help. your solution in particular inspired some "a ha!" moments in me once i figured out how it worked. peace |
ahoy @bludrop .. thanks for taking the time to post your setup, i appreciate it.
sure, no worries. i really like Ruhoh and Ruby in general, but Ruhoh seems like it is going through a major overhaul and i got stuck in a few places with the current version, particularly with sub collections as sub directories. of course, if i was a Ruby programmer i could have coded my way out of it, but unfortunately i am not. i also have a deadline for getting this site done and so here i am trying out Assemble which is very nice. also, due to its Grunt integration, i found lots of automated tasks which turned out to be useful as this site has lots of graphics that need to be tamed. as always, different tools for different tasks. however, the new Silly stuff that the next Ruhoh is based on looks pretty neat-o.
thanks again for sharing your setup. it looks like you are ahead of me with understanding Assemble in general, and particularly collections. they are pretty powerful and i am just starting to get the hang of them. i am always getting stuck on thinking that the directory hierarchy has all the info for defining collections and i forget about the Gruntfile.js config. however, now my config is starting to look like yours now, especially after this issue. coming from Ruhoh/Mustache, i also forget about all these powerful helpers. in particular, i am interested how you are using thanks again. |
ahoy @doowb @jonschlinkert moving along thanks to the changes you proposed but had a few comments/questions about this setup:
### collections of tracks per release
tracks:
options:
layout: track.html
data:
- <%= project.src %>/root/releases/*/tracks/**/*.{json,yml,yaml}
files:
- expand: true
cwd: <%= project.src %>/root/releases
src:
- "*/tracks/**/*.html"
dest: <%= project.stage %>/releases with this setup (and referring to the dir layout at the top of this issue) all tracks from all releases get placed in the same OK, thanks again and good night. |
I'm glad you're making progress!
This is exactly what I was thinking when I mentioned making
I've never encountered this use case, so I'm not sure if it's correct but it's unlikely that Assemble can't resolve it if we try to work through this. Oftentimes the solution ends up being simpler than it initially seems. To put it another way, since Assemble gives you all of the configuration information as variables (src, dest etc) throughout the build, I think we just need to figure out how to provide the right context to the How about using YFM with a custom property in each index that defines either the ---
cwd: a/b/c/
---
<!-- post -->
{{#compose cwd=cwd src="*.html"}}
{{{@content}}}
{{/compose}} @doowb, I think this is a good use case for the Strings lib. I could see it being handy if paths for the entire target were built dynamically using those replacement patterns |
Is it possible to retain all tracks in the I think this is what I am doing with {{#compose 'src/issues/**/*.md' }}
{{#is ../. section}}
{{#is ../../../issue issue }}
<li class="media list-group-item">
<a class="pull-left" href="{{../filename}}.html">
<img class="media-object" src="{{article_image}}" alt="article thumbnail" style="width:150px;height:100px;">
</a>
<div class="media-body">
<h4 class="media-heading"><a href="{{slugify title}}.html">{{title}}</a></h4>
<h5>{{subhead}}</h5>
<p class="author"><a href="/magazine/tova-serkin">{{author}}</a></p>
</div>
</li>
{{/is}}
{{/is}}
{{/compose}} |
I think that should work, but the |
Okay, this is just to get some ideas flowing. take a look at https://github.com/helpers/handlebars-helper-compose/tree/master/test/fixtures/dynamic. In each dir, {{#compose cwd="<%= dir %>" src="posts/*.md"}}
<p class="content">{{{@content}}}</p>
{{/compose}} This is just an example of what we can do, but I added a |
The reason I put the |
Also, this dynamic dir/lo-dash idea looks great. I will try it out, too. |
@jonschlinkert thanks. if i am following correctly, that is what @doowb initially suggested here and what you meant way up at the start of this thread by using it works but the problem (IMHO) is that we are duplicating data already available in the directory structure itself: we know that the only tracks we want to compose/import are those in the |
@bludrop i was thinking the same thing that night and i believe using your method with the also, having all the tracks in the same collection was similar to the problem i ran into with Ruhoh that eventually got me stuck. there, all the also, it seems like the Assemble wizards have already started on a more dynamic solution ;) thanks again. |
@jonschlinkert thanks, this works great and removes the need to set obviously i have a lack of understanding about how Assemble works, but why could we not simply use also, why is it not working to use
the thanks again. |
Also, |
duh! sorry for missing the obvious answer to my own question.
OK. thanks again. may i say that the difference about what is available via |
don't be too hard on yourself! it can get confusing for anyone. As a general rule think of handlebars as what you should use for rendering HTML and Lo-Dash is what you should use for config. So, for example, let's say we have a title variable on the page context:
we can change the context for
which is probably best. Or, if there is a good reason, we could do:
Don't get hung up on the use case, there are many other uses for this. I've been wanting to do a blog post about this specific topic for a long time |
also, although this is probably obvious, it might be worth mentioning just as a tactic for creating a "separation of concerns" regarding usage of Lo-Dash versus Handlebars templates. As you know, with handlebars we can't just do:
nor can we nest handlebars expressions like this:
but we can do this:
And the only reason we can do this here is b/c I make use of Another thing I'll be thinking about for this is Handlebars subexpressions, which allows you to use the return value of a helper as a variable in the "parent" helper. So I could see some potential for using subexpressions to build out paths dynamically. |
@jonschlinkert thanks for the overview, i appreciate and obviously need it. this rule of thumb for when to use which template system makes sense, but one thing is still unclear to me: do LoDash and Handlebars templates both share the same context/namespace? in other words does again, forgive me for missing these obvious things! peace |
OK, so to answer my own question from above: it depends ;) as you say, inside this compose helper you use grunt.config. but in general LoDash templates are resolved in the context of the grunt.config object, while Handlebar templates are resolved in terms of the Handlebar context (
funny, i was trying to use those the other day then realized that they are only available with the latest release of Handlebars .. see handlebars-lang/handlebars.js#690 i think they would be very useful in these more dynamic setups as you say. |
ahoy,
first, thanks for the refactor and all this work on Assemble. this helper was the thing that caught my eye and made me give Assemble a try. and your push this morning fixed a bug i was encountering last night when i finally got a chance to try this helper. thanks again ;)
so far the compose helper seems to work as advertised, but i am having a hard time using it in a layout and making in generic enough to work with whatever uses that layout.
here is a simplified version of my setup:
i am trying to use Assemble to view the collections that are already modeled by the directory structure i.e. the
releases
(AKA albums) collection has 2 elementsA
andB
, each release collection element has a sub collectiontracks
which contain the tracks of the release, andpages
has simple content pages.i am trying to use this compose helper in a layout for a release to pull in the track contents in the subdirectory
tracks
of the release collection. so far i have been unable to set thecwd
option for eachrelease
folder differently unless i specify each release separately in the global Assemble options.what i am trying overall to achieve is to have the directory structure be the configuration, allowing new
releases
to simply be created by making a new directory and adding content in the correct place, instead of explicitly naming everything in the global Assemble config.i am new to Assemble and perhaps there is another way to do this, or this is not a supported use case at this time. any advice would be appreciated.
thanks again.
The text was updated successfully, but these errors were encountered: