-
Notifications
You must be signed in to change notification settings - Fork 79
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
New filters #74
New filters #74
Conversation
Whoops! My apologies: I need to rebase this off of master, rather than off of my other pull request. I'll do that after I get some sleep. |
@johannhof: I am confused as to which tests would go in the |
@johannhof: I'm working on |
@djwf Thanks so much for your work on this. Just wanted to let you know it's not been forgotten, I'm simply traveling between continents for work. I'll get to reviewing this today or tomorrow. :) |
@johannhof No worries at all: I'll just keep plugging away at them. Note that I'm using the list of filters at the liquid markup web site as the authoritative list, as I noticed some of those missing from your list in #11 . |
Ok, looking at this now. The re-ordering makes it a bit hard to see what exactly changed, but I'll manage. As to your questions:
Cheers |
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.
Pretty good. Just a couple of nits. Thanks so much!
Note that I did not very thoroughly look at the reordered functions (GitHubs diff sucks for that). I'll just assume you didn't plant a trojan horse here.
src/filters.rs
Outdated
pub fn replace_first(input: &Value, args: &[Value]) -> FilterResult { | ||
if args.len() != 2 { | ||
return Err(InvalidArgumentCount(format!("expected 2, {} given", args.len()))); | ||
} |
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.
While you're at it, you can replace this with check_args_len
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.
Got it, done.
@@ -670,6 +670,23 @@ pub fn truncatewords(input: &Value, args: &[Value]) -> FilterResult { | |||
} | |||
} | |||
|
|||
/// Removes any duplicate elements in an array. |
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.
Maybe leave a comment that this operates in O(n^2) worst-case, which should be fine IMO.
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.
Got it, done.
@@ -1,10 +1,44 @@ | |||
use Renderable; | |||
use context::Context; | |||
use filters::{size, upcase, downcase, capitalize, minus, plus, times, divided_by, ceil, floor, | |||
round, prepend, append, first, last, pluralize, replace_first, replace, date, sort, | |||
slice, modulo, escape, escape_once, remove_first, remove, strip_html, truncatewords}; |
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.
Was this change made because of rustfmt? I liked the grouped version a bit better.
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.
That was just because it makes it match the list of filters in the impl Renderable ...
section, and it made it easier to see where/what was added. I don't have strong feelings about it either way, so I'll put it back to a grouped version (ordered alphabetically).
try!(check_args_len(args, 0)); | ||
match *input { | ||
Value::Array(ref array) => { | ||
let mut reversed = array.clone(); |
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.
Note to self: Look if we can reduce allocation in filters (by modifying output.rs
) before 1.0
src/filters.rs
Outdated
let ellipsis = "...".to_string(); | ||
let append = match args.get(1) { | ||
Some(&Str(ref x)) => x, | ||
_ => &ellipsis, |
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.
You can replace this with just "..."
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.
Ah damn I just noticed you took that from truncatewords
. Can you please fix this up in truncatewords
, too? Thank you!
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.
Yep: fixed both truncate and truncatewords.
Thanks for the answers and the review: note that the most recent nightly of Also, my rustfmt (
The rustfmt for the Travis CI builds, however, formats the grouped filter use statement differently:
No big deal, but I figured you'd want to know. |
Seems like there's an issue around that recently added rule: https://github.com/Manishearth/rust-clippy/issues/1580 You can ignore it by adding
Feel free to update the version to |
Nevermind, I just merged #80 so you'll just have to rebase :) |
- Split helper functions into separate section. - Sort filter functions to simplify finding a navigation. - Sort unit tests to maintain the same ordering as the filters.
- Introduces dependency on unicode_segmentation crate - Uses segmentation of strings based on grapheme clusters to properly handle unicode strings
This reverts commit 10f5e84. Apparently the new rustfmt requires GLIBC_2.18, to fix later.
Looks great! |
I'm putting all the filters I create from the list in issue #11 here, as they are part of the standard, and the filter in pull request #73 is not.
Let me know if I should merge these two or split all filters into their own pull requests. Also, note that I'll use this to add more filters, and will leave a note when I've finished adding filters. If you'd prefer I not work that way, let me know and I'll change it up.