|
|
DescriptionAdd Jinja2 macro for adding trailing strings.
There's a lot of repetitive code in ComputedStyleBase.h.tmpl to handle
formatting. For example, the member initialiser list in the generated
constructor needs a trailing comma for every member except the last one.
This patch moves such code into a generic macro in macros.tmpl, which
which makes it available for other templates.
This will be used more frequently when we start introducing more
complexity to the ComputedStyle templates.
BUG=628043
Review-Url: https://codereview.chromium.org/2680123002
Cr-Commit-Position: refs/heads/master@{#450173}
Committed: https://chromium.googlesource.com/chromium/src/+/c0a8bdbcd693f00a522afa34e5bdceb3129bb1da
Patch Set 1 #
Total comments: 3
Patch Set 2 : Change to print_if #
Total comments: 4
Messages
Total messages: 27 (9 generated)
shend@chromium.org changed reviewers: + bugsnash@chromium.org
Hi Bugs, PTAL
lgtm
shend@chromium.org changed reviewers: + meade@chromium.org
Hi Eddy, PTAL :)
bugsnash@chromium.org changed reviewers: - meade@chromium.org
lgtm
On 2017/02/12 at 22:48:20, Bugs Nash wrote: > lgtm I swear I didn't just do that lgtm :s
shend@chromium.org changed reviewers: + meade@chromium.org
Hi Eddy, PTAL
lgtm Nice fix! One small comment. https://codereview.chromium.org/2680123002/diff/1/third_party/WebKit/Source/b... File third_party/WebKit/Source/build/scripts/templates/macros.tmpl (right): https://codereview.chromium.org/2680123002/diff/1/third_party/WebKit/Source/b... third_party/WebKit/Source/build/scripts/templates/macros.tmpl:60: {% macro trailing(loop, str) -%} Would it make sense to pass in loop.last here instead of passing in loop? It made me double take a little on why loop is being passed into trailing() above...
https://codereview.chromium.org/2680123002/diff/1/third_party/WebKit/Source/b... File third_party/WebKit/Source/build/scripts/templates/macros.tmpl (right): https://codereview.chromium.org/2680123002/diff/1/third_party/WebKit/Source/b... third_party/WebKit/Source/build/scripts/templates/macros.tmpl:60: {% macro trailing(loop, str) -%} On 2017/02/13 at 06:19:58, Eddy wrote: > Would it make sense to pass in loop.last here instead of passing in loop? It made me double take a little on why loop is being passed into trailing() above... Hmm, my intention for this macro is to print a string based on the current loop state. If I make it take in loop.last (i.e. a bool), then the macro kinda becomes print_if_true(bool, str). It's also less typing for the caller :P. Would it help if I added an explanatory comment here?
https://codereview.chromium.org/2680123002/diff/1/third_party/WebKit/Source/b... File third_party/WebKit/Source/build/scripts/templates/macros.tmpl (right): https://codereview.chromium.org/2680123002/diff/1/third_party/WebKit/Source/b... third_party/WebKit/Source/build/scripts/templates/macros.tmpl:60: {% macro trailing(loop, str) -%} On 2017/02/13 06:40:37, shend wrote: > On 2017/02/13 at 06:19:58, Eddy wrote: > > Would it make sense to pass in loop.last here instead of passing in loop? It > made me double take a little on why loop is being passed into trailing() > above... > > Hmm, my intention for this macro is to print a string based on the current loop > state. If I make it take in loop.last (i.e. a bool), then the macro kinda > becomes print_if_true(bool, str). It's also less typing for the caller :P. Would > it help if I added an explanatory comment here? Hmm, it's really print_if_false right? I think it's actually clearer to name it what it does - which is clearer about what's happening? {% for field in fields %} {{field.name}}({{default_value(field)}}){{trailing(loop, ',')}} {% endfor %} {% for field in fields %} {{field.name}}({{default_value(field)}}){{print_if_false(loop.last, ',')}} {% endfor %}
On 2017/02/13 at 06:51:15, meade wrote: > https://codereview.chromium.org/2680123002/diff/1/third_party/WebKit/Source/b... > File third_party/WebKit/Source/build/scripts/templates/macros.tmpl (right): > > https://codereview.chromium.org/2680123002/diff/1/third_party/WebKit/Source/b... > third_party/WebKit/Source/build/scripts/templates/macros.tmpl:60: {% macro trailing(loop, str) -%} > On 2017/02/13 06:40:37, shend wrote: > > On 2017/02/13 at 06:19:58, Eddy wrote: > > > Would it make sense to pass in loop.last here instead of passing in loop? It > > made me double take a little on why loop is being passed into trailing() > > above... > > > > Hmm, my intention for this macro is to print a string based on the current loop > > state. If I make it take in loop.last (i.e. a bool), then the macro kinda > > becomes print_if_true(bool, str). It's also less typing for the caller :P. Would > > it help if I added an explanatory comment here? > > Hmm, it's really print_if_false right? I think it's actually clearer to name it what it does - which is clearer about what's happening? > > > {% for field in fields %} > {{field.name}}({{default_value(field)}}){{trailing(loop, ',')}} > {% endfor %} > > > > {% for field in fields %} > {{field.name}}({{default_value(field)}}){{print_if_false(loop.last, ',')}} > {% endfor %} Yeah 'trailing' does look mysterious in comparison. Instead of print_if_false(loop.last), what do you think of print_if_not(loop.last)? I feel like the latter reads better, and it's equivalent to print_if(not loop.last).
On 2017/02/13 at 06:59:39, shend wrote: > On 2017/02/13 at 06:51:15, meade wrote: > > https://codereview.chromium.org/2680123002/diff/1/third_party/WebKit/Source/b... > > File third_party/WebKit/Source/build/scripts/templates/macros.tmpl (right): > > > > https://codereview.chromium.org/2680123002/diff/1/third_party/WebKit/Source/b... > > third_party/WebKit/Source/build/scripts/templates/macros.tmpl:60: {% macro trailing(loop, str) -%} > > On 2017/02/13 06:40:37, shend wrote: > > > On 2017/02/13 at 06:19:58, Eddy wrote: > > > > Would it make sense to pass in loop.last here instead of passing in loop? It > > > made me double take a little on why loop is being passed into trailing() > > > above... > > > > > > Hmm, my intention for this macro is to print a string based on the current loop > > > state. If I make it take in loop.last (i.e. a bool), then the macro kinda > > > becomes print_if_true(bool, str). It's also less typing for the caller :P. Would > > > it help if I added an explanatory comment here? > > > > Hmm, it's really print_if_false right? I think it's actually clearer to name it what it does - which is clearer about what's happening? > > > > > > {% for field in fields %} > > {{field.name}}({{default_value(field)}}){{trailing(loop, ',')}} > > {% endfor %} > > > > > > > > {% for field in fields %} > > {{field.name}}({{default_value(field)}}){{print_if_false(loop.last, ',')}} > > {% endfor %} > > Yeah 'trailing' does look mysterious in comparison. Instead of print_if_false(loop.last), what do you think of print_if_not(loop.last)? I feel like the latter reads better, and it's equivalent to print_if(not loop.last). actually, why not just have print_if and do print_if(not loop.last)?
Both sound good! print_if_not(foo) vs print_if(not foo) seem so similar that I don't mind :p On 13 Feb. 2017 6:03 pm, <shend@chromium.org> wrote: On 2017/02/13 at 06:59:39, shend wrote: > On 2017/02/13 at 06:51:15, meade wrote: > > https://codereview.chromium.org/2680123002/diff/1/third_ party/WebKit/Source/build/scripts/templates/macros.tmpl > > File third_party/WebKit/Source/build/scripts/templates/macros.tmpl (right): > > > > https://codereview.chromium.org/2680123002/diff/1/third_ party/WebKit/Source/build/scripts/templates/macros.tmpl#newcode60 > > third_party/WebKit/Source/build/scripts/templates/macros.tmpl:60: {% macro trailing(loop, str) -%} > > On 2017/02/13 06:40:37, shend wrote: > > > On 2017/02/13 at 06:19:58, Eddy wrote: > > > > Would it make sense to pass in loop.last here instead of passing in loop? It > > > made me double take a little on why loop is being passed into trailing() > > > above... > > > > > > Hmm, my intention for this macro is to print a string based on the current loop > > > state. If I make it take in loop.last (i.e. a bool), then the macro kinda > > > becomes print_if_true(bool, str). It's also less typing for the caller :P. Would > > > it help if I added an explanatory comment here? > > > > Hmm, it's really print_if_false right? I think it's actually clearer to name it what it does - which is clearer about what's happening? > > > > > > {% for field in fields %} > > {{field.name}}({{default_value(field)}}){{trailing(loop, ',')}} > > {% endfor %} > > > > > > > > {% for field in fields %} > > {{field.name}}({{default_value(field)}}){{print_if_false(loop.last, ',')}} > > {% endfor %} > > Yeah 'trailing' does look mysterious in comparison. Instead of print_if_false(loop.last), what do you think of print_if_not(loop.last)? I feel like the latter reads better, and it's equivalent to print_if(not loop.last). actually, why not just have print_if and do print_if(not loop.last)? https://codereview.chromium.org/2680123002/ -- You received this message because you are subscribed to the Google Groups "Blink Reviews" group. To unsubscribe from this group and stop receiving emails from it, send an email to blink-reviews+unsubscribe@chromium.org.
Both sound good! print_if_not(foo) vs print_if(not foo) seem so similar that I don't mind :p On 13 Feb. 2017 6:03 pm, <shend@chromium.org> wrote: On 2017/02/13 at 06:59:39, shend wrote: > On 2017/02/13 at 06:51:15, meade wrote: > > https://codereview.chromium.org/2680123002/diff/1/third_ party/WebKit/Source/build/scripts/templates/macros.tmpl > > File third_party/WebKit/Source/build/scripts/templates/macros.tmpl (right): > > > > https://codereview.chromium.org/2680123002/diff/1/third_ party/WebKit/Source/build/scripts/templates/macros.tmpl#newcode60 > > third_party/WebKit/Source/build/scripts/templates/macros.tmpl:60: {% macro trailing(loop, str) -%} > > On 2017/02/13 06:40:37, shend wrote: > > > On 2017/02/13 at 06:19:58, Eddy wrote: > > > > Would it make sense to pass in loop.last here instead of passing in loop? It > > > made me double take a little on why loop is being passed into trailing() > > > above... > > > > > > Hmm, my intention for this macro is to print a string based on the current loop > > > state. If I make it take in loop.last (i.e. a bool), then the macro kinda > > > becomes print_if_true(bool, str). It's also less typing for the caller :P. Would > > > it help if I added an explanatory comment here? > > > > Hmm, it's really print_if_false right? I think it's actually clearer to name it what it does - which is clearer about what's happening? > > > > > > {% for field in fields %} > > {{field.name}}({{default_value(field)}}){{trailing(loop, ',')}} > > {% endfor %} > > > > > > > > {% for field in fields %} > > {{field.name}}({{default_value(field)}}){{print_if_false(loop.last, ',')}} > > {% endfor %} > > Yeah 'trailing' does look mysterious in comparison. Instead of print_if_false(loop.last), what do you think of print_if_not(loop.last)? I feel like the latter reads better, and it's equivalent to print_if(not loop.last). actually, why not just have print_if and do print_if(not loop.last)? https://codereview.chromium.org/2680123002/ -- You received this message because you are subscribed to the Google Groups "Chromium-reviews" group. To unsubscribe from this group and stop receiving emails from it, send an email to chromium-reviews+unsubscribe@chromium.org.
On 2017/02/13 at 07:07:20, chromium-reviews wrote: > Both sound good! > print_if_not(foo) vs print_if(not foo) seem so similar that I don't mind :p > > On 13 Feb. 2017 6:03 pm, <shend@chromium.org> wrote: > > On 2017/02/13 at 06:59:39, shend wrote: > > On 2017/02/13 at 06:51:15, meade wrote: > > > > https://codereview.chromium.org/2680123002/diff/1/third_ > party/WebKit/Source/build/scripts/templates/macros.tmpl > > > File third_party/WebKit/Source/build/scripts/templates/macros.tmpl > (right): > > > > > > > https://codereview.chromium.org/2680123002/diff/1/third_ > party/WebKit/Source/build/scripts/templates/macros.tmpl#newcode60 > > > third_party/WebKit/Source/build/scripts/templates/macros.tmpl:60: {% > macro > trailing(loop, str) -%} > > > On 2017/02/13 06:40:37, shend wrote: > > > > On 2017/02/13 at 06:19:58, Eddy wrote: > > > > > Would it make sense to pass in loop.last here instead of passing in > loop? It > > > > made me double take a little on why loop is being passed into > trailing() > > > > above... > > > > > > > > Hmm, my intention for this macro is to print a string based on the > current > loop > > > > state. If I make it take in loop.last (i.e. a bool), then the macro > kinda > > > > becomes print_if_true(bool, str). It's also less typing for the > caller :P. > Would > > > > it help if I added an explanatory comment here? > > > > > > Hmm, it's really print_if_false right? I think it's actually clearer to > name > it what it does - which is clearer about what's happening? > > > > > > > > > {% for field in fields %} > > > {{field.name}}({{default_value(field)}}){{trailing(loop, ',')}} > > > {% endfor %} > > > > > > > > > > > > {% for field in fields %} > > > {{field.name}}({{default_value(field)}}){{print_if_false(loop.last, > ',')}} > > > {% endfor %} > > > > Yeah 'trailing' does look mysterious in comparison. Instead of > print_if_false(loop.last), what do you think of print_if_not(loop.last)? I > feel > like the latter reads better, and it's equivalent to print_if(not > loop.last). > > actually, why not just have print_if and do print_if(not loop.last)? > > https://codereview.chromium.org/2680123002/ > > -- > You received this message because you are subscribed to the Google Groups "Chromium-reviews" group. > To unsubscribe from this group and stop receiving emails from it, send an email to chromium-reviews+unsubscribe@chromium.org. > Changed to print_if(not loop.last) so we don't need to implement both print_if and print_if_not.
The CQ bit was checked by shend@chromium.org
The patchset sent to the CQ was uploaded after l-g-t-m from meade@chromium.org, bugsnash@chromium.org Link to the patchset: https://codereview.chromium.org/2680123002/#ps20001 (title: "Change to print_if")
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.or...
CQ is committing da patch. Bot data: {"patchset_id": 20001, "attempt_start_ts": 1487022074240310, "parent_rev": "b1230ec0b1aeafd15f311ded99d5c88718495c8d", "commit_rev": "c0a8bdbcd693f00a522afa34e5bdceb3129bb1da"}
Message was sent while issue was closed.
Description was changed from ========== Add Jinja2 macro for adding trailing strings. There's a lot of repetitive code in ComputedStyleBase.h.tmpl to handle formatting. For example, the member initialiser list in the generated constructor needs a trailing comma for every member except the last one. This patch moves such code into a generic macro in macros.tmpl, which which makes it available for other templates. This will be used more frequently when we start introducing more complexity to the ComputedStyle templates. BUG=628043 ========== to ========== Add Jinja2 macro for adding trailing strings. There's a lot of repetitive code in ComputedStyleBase.h.tmpl to handle formatting. For example, the member initialiser list in the generated constructor needs a trailing comma for every member except the last one. This patch moves such code into a generic macro in macros.tmpl, which which makes it available for other templates. This will be used more frequently when we start introducing more complexity to the ComputedStyle templates. BUG=628043 Review-Url: https://codereview.chromium.org/2680123002 Cr-Commit-Position: refs/heads/master@{#450173} Committed: https://chromium.googlesource.com/chromium/src/+/c0a8bdbcd693f00a522afa34e5bd... ==========
Message was sent while issue was closed.
Committed patchset #2 (id:20001) as https://chromium.googlesource.com/chromium/src/+/c0a8bdbcd693f00a522afa34e5bd...
Message was sent while issue was closed.
sashab@chromium.org changed reviewers: + sashab@chromium.org
Message was sent while issue was closed.
Ahh <3 this patch. \o/ https://codereview.chromium.org/2680123002/diff/20001/third_party/WebKit/Sour... File third_party/WebKit/Source/build/scripts/templates/ComputedStyleBase.h.tmpl (right): https://codereview.chromium.org/2680123002/diff/20001/third_party/WebKit/Sour... third_party/WebKit/Source/build/scripts/templates/ComputedStyleBase.h.tmpl:14: {% macro default_value(field) -%} What's the dashes for? https://codereview.chromium.org/2680123002/diff/20001/third_party/WebKit/Sour... third_party/WebKit/Source/build/scripts/templates/ComputedStyleBase.h.tmpl:27: {{field.name}}({{default_value(field)}}){{print_if(not loop.last, ',')}} Woah loop.last awesome!!
Message was sent while issue was closed.
https://codereview.chromium.org/2680123002/diff/20001/third_party/WebKit/Sour... File third_party/WebKit/Source/build/scripts/templates/ComputedStyleBase.h.tmpl (right): https://codereview.chromium.org/2680123002/diff/20001/third_party/WebKit/Sour... third_party/WebKit/Source/build/scripts/templates/ComputedStyleBase.h.tmpl:14: {% macro default_value(field) -%} On 2017/02/19 at 23:17:03, sashab wrote: > What's the dashes for? They strip out leading/trailing whitespace so you can write the {% macro %} stuff on a separate line without introducing excess new lines in the generated code. https://codereview.chromium.org/2680123002/diff/20001/third_party/WebKit/Sour... third_party/WebKit/Source/build/scripts/templates/ComputedStyleBase.h.tmpl:27: {{field.name}}({{default_value(field)}}){{print_if(not loop.last, ',')}} On 2017/02/19 at 23:17:03, sashab wrote: > Woah loop.last awesome!! \o/ |