Skip to content
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

Merged
merged 7 commits into from
Nov 30, 2017

Conversation

chalin
Copy link
Contributor

@chalin chalin commented Nov 30, 2017

Contributes to #407, by

  • Creating a testable version of the homepage "compute pi" example.
  • Providing tests for the "compute pi" example.
  • Providing a script for generating the HTML version of the homepage example, which contains embedded tootlips.

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

@chalin chalin added fix.examples Adds or changes example infra.structure Relates to the tools that create dart.dev test.general Relates to unit, integration, perf testing labels Nov 30, 2017
@chalin chalin added this to the 1.24 milestone Nov 30, 2017
@chalin chalin requested a review from filiph November 30, 2017 17:51
@googlebot googlebot added the cla: yes Contributor has signed the Contributor License Agreement label Nov 30, 2017
Copy link
Contributor

@filiph filiph left a 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
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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\("([^"]+)"\)$');
Copy link
Contributor

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").

Copy link
Contributor Author

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++],
Copy link
Contributor

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.

Copy link
Contributor Author

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],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tooltipAnchor ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

footnote.removeClass('blink');
}, 1000);
}, 2000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the increased time?

Copy link
Contributor Author

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>")
Copy link
Contributor

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.

Copy link
Contributor Author

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

@chalin
Copy link
Contributor Author

chalin commented Nov 30, 2017

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.

Done

And the staging server has been refreshed: https://dartlang-org-staging-0.firebaseapp.com

@filiph
Copy link
Contributor

filiph commented Nov 30, 2017

LGTM!

@chalin chalin merged commit 57a8f86 into dart-lang:master Nov 30, 2017
@chalin chalin deleted the chalin-main-site-ex-1130 branch November 30, 2017 19:50
@chalin
Copy link
Contributor Author

chalin commented Nov 30, 2017

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.

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Contributor has signed the Contributor License Agreement fix.examples Adds or changes example infra.structure Relates to the tools that create dart.dev test.general Relates to unit, integration, perf testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants