Comments (8)
This was posted in another issue recently.
dust.helpers.loop = function(chunk, context, bodies, params) {
var from = parseInt(dust.helpers.tap(params.from, chunk, context), 10) || 1,
to = parseInt(dust.helpers.tap(params.to, chunk, context), 10) || 1,
len = Math.abs(to - from) + 1,
increment = (to - from) / (len - 1) || 1;
while(from !== to) {
chunk = bodies.block(chunk, context.push(from, from, len));
from += increment;
}
return chunk.render(bodies.block, context.push(from, from, len));
}
Used like
{@loop from=1 to="{end}"}This is iteration {.}{/loop}
{@loop from=10 to=0}Countdown T-{.}{/loop}
Sent from my iPad
On Nov 6, 2014, at 07:08, Luke Frake <[email protected]mailto:[email protected]> wrote:
I've started using dustjs for a project, and I need to be able to loop N times.
Is there a reason there isn't already a helper for this, as it seems like a basic piece of logic? The reason I'm asking is because I don't want to go against the core principles of dust.
If there is no reason, should I create a fork and a PR for a helper?
β
Reply to this email directly or view it on GitHubhttps://github.com//issues/99.
from dustjs-helpers.
Great, thanks for that!
Should this be moved into the helpers if it's something that a few people want?
from dustjs-helpers.
That was my very quick untested code, and I suspect it has some bugs ;)
But I can look at polishing it up and asking if it's something that should be included.
I'm really not sure what the scope of dust-helpers is supposed to be. I have a bunch of these utility helpers (and I know others do too) that could expand the amount of functionality we provide.
from dustjs-helpers.
I've given it a quick test and it works perfectly for me! I won't promise there isn't a single bug ;)
I've got some helpers that I use on my project that I would merge in if people needed them. I don't know if there is a sensible way of gauging interest with helpers? Maybe just raising issues for helpers that we want/ have made, then if it gets enough +1's a fork can be created?
from dustjs-helpers.
I think that's totally reasonable!
I plan on rewriting the way helpers plug in to allow you to register new ones in a self-contained manner, so then you can provide helpers like you provide, say, Grunt plugins. That should make PRs easier.
from dustjs-helpers.
Sounds awesome, I'll keep an ear to the ground on this then
from dustjs-helpers.
Adding lots more helpers has come up before β dig through the closed issues. The problem is there are lots of individual needs but the 80/20 rules soon shows up and the low use helpers are many. The end result would be a very large dustjs-helpers library with attendant cost in the client environment.
In the end, I gave up and created dust-motes as a place to collect helpers of more than passing interest but not A-list helpers. After the initial push, it has languished but a couple of things like if and provide have become popular. I donβt take all PRs (e.g. no action on one that used eval heavily) but this could be a place for the less universally interesting ones.
http://rragan.github.io/dust-motes/
Rich
From: Seth Kinast [mailto:[email protected]]
Sent: Thursday, November 06, 2014 8:01 AM
To: linkedin/dustjs-helpers
Cc: Ragan, Richard
Subject: Re: [dustjs-helpers] Is there a reason why there is no loop helper? (#99)
That was my very quick untested code, and I suspect it has some bugs ;)
But I can look at polishing it up and asking if it's something that should be included.
I'm really not sure what the scope of dust-helpers is supposed to be. I have a bunch of these utility helpers (and I know others do too) that could expand the amount of functionality we provide.
β
Reply to this email directly or view it on GitHubhttps://github.com//issues/99#issuecomment-62001125.
from dustjs-helpers.
Would having unused helpers have a detrimental affect one the end product. I mean the helpers would probably exist in the end product, but apart from that... Does dust get much slower per helper It has registered?
Maybe a customized package would be better. I only use about 4 of the helpers available in this repo for instance. So really I only need those four and the ones I've made.
My main concern is together we will right better code, so getting things on here would mean a better end product.
from dustjs-helpers.
Related Issues (20)
- Testing sub boolean value HOT 2
- Drop Node 0.8 support
- breaking semver and my sites HOT 2
- Helpers 1.6.0 and dustjs-linkedin 2.6.0 can break some apps HOT 13
- @default and @none helpers not working properly on 1.6.0 version HOT 12
- Don't require a key for {@select} HOT 5
- {@select}s with multiple keys break when used with {@any} / {@none}
- Feature regression in 1.7.0, logic helpers ignored in select bodies HOT 9
- Cannot use 'else' as a property in IE8 HOT 1
- Sync test framework changes / saucelabs
- @select fails to render multiple @eq statements inside a @none block HOT 7
- Make use of context options to store @select state
- Add case-insensitive {@eq} comparator HOT 12
- Issue in running in production mode
- @eq helper doesn't work when accessing an object at a deeper level HOT 7
- Fix Travis tests by not supporting node 0.10 and node 0.12
- Support dustjs v3.0.0 HOT 4
- deprecate and remove if helper HOT 4
- Peer dependencies issue with dustjs-linkedin HOT 16
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dustjs-helpers.