-
Notifications
You must be signed in to change notification settings - Fork 676
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
Homepage "compute pi" example: Dart sources, tests, and HTML-version generator #448
Conversation
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.
Thanks for doing this! In retrospect, it was kind of stupid of me to have this huge example code featured on the front page and have no continuous testing set up for it. Kudos for fixing that glaring bug.
I'm not a big fan of making the "tooltip" more visible via color. It's now too high in the visual hierarchy of the page.
Can you please revert that change and stash it? We don't need it for testing/generating the example. We might want to noodle on it in a separate PR.
line = lineWithoutTipInstruction.replaceFirst(escapedAnchor, | ||
'<span class="frontpage-highlight" data-text="$ttText">$escapedAnchor</span>'); | ||
} | ||
// TODO: remove these temporary conversions used to minimize diffs with existing HTML |
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 these are just to make the diff prettier, I think you can remove it. If the difference is functional, keep these.
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.
With these in place, the generation script creates exactly the same HTML (when compared to the file as created in the second commit). I'll strip these out in a followup commit, if that is ok with 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.
Actually, I've removed them in a separate commit.
final HtmlEscape _htmlEscape = | ||
new HtmlEscape(new HtmlEscapeMode(escapeLtGt: true)); | ||
final HtmlUnescape _htmlUnescape = new HtmlUnescape(); | ||
final tipRE = new RegExp(r'^(.*?) //!tip\("([^"]+)"\)$'); |
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.
nit: maybe tipPattern
? When I see tipRE
in code I don't know what the "RE" means (maybe it's just me being more used to "RegEx").
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.
Renamed to tipRegExp
.
if (match == null) throw 'Tip instruction match failed for line: $line'; | ||
final lineWithoutTipInstruction = match[1], | ||
anchor = _htmlUnescape.convert(match[2]), | ||
tooltip = tooltips[indexOfNextTooltip++], |
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.
nit: do indexOfNextTooltip += 1;
separately. The ++
is really easy to overlook.
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.
done
final lineWithoutTipInstruction = match[1], | ||
anchor = _htmlUnescape.convert(match[2]), | ||
tooltip = tooltips[indexOfNextTooltip++], | ||
ttAnchor = tooltip[0], |
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.
tooltipAnchor ?
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.
done
src/_assets/javascripts/main.js
Outdated
footnote.removeClass('blink'); | ||
}, 1000); | ||
}, 2000); |
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 the increased time?
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.
It just made more sense with the new look. Since the commit that this change is a part of has been stashed, it will go away (and we can discuss it later, if need be).
} | ||
|
||
/// Generates a stream of increasingly accurate estimates of π. //!tip("///") | ||
Stream<double> computePi({int batch: 100000}) async* { //!tip("async*") //!tip("{int batch: 100000}") //!tip("<double>") |
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 the change from batch of 1M to 100K intentional? No problem either way, just checking.
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.
This was to match the original sources in the published DartPad: https://dartpad.dartlang.org/fb763a4a770b5cdd896982e10ccf4118
- Changed single quotes to double quotes for a `data-text` attribute. - Make default batch value match what is in the current DartPad (drop one 0).
eafcbf4
to
0d06f29
Compare
Done And the staging server has been refreshed: https://dartlang-org-staging-0.firebaseapp.com |
LGTM! |
Oh, and thanks for the kudos. Double kudos to you for such a great example, covering many of Dart's features in such a compact example! |
Contributes to #407, by
Specifically, some of the files in this PR are:
examples/lib/pi_monte_carlo.dart
:source for the "compute pi" homepage example. This was derived from the DartPad sources.
examples/lib/pi_monte_carlo_tooltips.html
:tooltips for the highlighted features of the homepage example.
scripts/create_site_main_example.dart
:simple script used to generate the HTML version of the homepage example from the Dart source and tooltip files.
examples/test/pi_test.dart
:tests the homepage example.
I've ensured that the generated HTML version of the homepage example matches the current version visible on dartlag.org.
This PR also includes some minor CSS changes to modernize the look of the tooltip/footnote area of the homepage. These are in a separate commit in case you prefer the old look.
Staged at: https://dartlang-org-staging-0.firebaseapp.com