Skip to content

Refactor html generator into frontend and backend #2115

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

Merged
merged 12 commits into from
Jan 9, 2020

Conversation

jdkoren
Copy link
Contributor

@jdkoren jdkoren commented Jan 7, 2020

This splits the generator logic into a frontend and backend. The frontend walks the package graph, delegates to the backend to render documentation for an element, and forwards rendered content to a FileWriter to be written.

There is currently one backend, for html content.

@googlebot googlebot added the cla: yes Google CLA check succeeded. label Jan 7, 2020
import 'package:dartdoc/src/warnings.dart';
import 'package:path/path.dart' as path;

typedef FileWriter = File Function(String filePath, Object content,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would it be better if this were an abstract class?

Copy link
Contributor

Choose a reason for hiding this comment

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

See comment on usage of FileWriter elsewhere.


GeneratorFrontEnd(this._generatorBackend, this._writer);

// Implement FileWriter so we can wrap the one given to us.
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 part feels a little weird, but we need to accomplish two things:

  • Fix path separators
  • Apply the outputDirectory given to us, required by signature of generate()

I think delegating to a writer is still appropriate because it can be mocked in tests. Perhaps with the writer being a separate component, we could remove outputDirectory from the signature of Generator.generate() and instead have DartdocFileWriter do this work instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

There is an awful lot of joining/splitting of outputDirectory going on (and that was in the original). Anything we can do to reduce the number of times we are recombining paths seems like a good idea; I've just never went through and cleaned this up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Latest push no longer has this "wrapping" structure, and all this path manipulation happens in one place, DartdocFileWriter.

@@ -0,0 +1,377 @@
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
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 file was html_generator_instance.dart . Most of the structure is maintained, but there's enough difference to convince Git that it's a new file.

Copy link
Contributor

@jcollins-g jcollins-g left a comment

Choose a reason for hiding this comment

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

Overall it looks good; a few minor things and I think we're good to land.

import 'package:dartdoc/src/warnings.dart';
import 'package:path/path.dart' as path;

typedef FileWriter = File Function(String filePath, Object content,
Copy link
Contributor

Choose a reason for hiding this comment

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

See comment on usage of FileWriter elsewhere.


GeneratorFrontEnd(this._generatorBackend, this._writer);

// Implement FileWriter so we can wrap the one given to us.
Copy link
Contributor

Choose a reason for hiding this comment

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

There is an awful lot of joining/splitting of outputDirectory going on (and that was in the original). Anything we can do to reduce the number of times we are recombining paths seems like a good idea; I've just never went through and cleaned this up.

logInfo('Generating docs for category ${category.name} from '
'${category.package.fullyQualifiedName}...');
indexAccumulator.add(category);
_generatorBackend.generateCategory(write, packageGraph, category);
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, this approach is an improvement. Eventually it seems like we should be able to refactor and use a visitor pattern but I think this is definitely good enough for now.

lib/dartdoc.dart Outdated
List<Generator> generators = await initHtmlGenerators(config);
return Dartdoc._(config, generators);
return Dartdoc._(
config, await initHtmlGenerator(config, DartdocFileWriter().write));
Copy link
Contributor

Choose a reason for hiding this comment

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

This suggests to me that DartdocFileWriter could be a class implementing call() -- this way you could just pass an instance of DartdocFileWriter and dispense with the typedef.

Make FileWriter an abstract class and give it the responsibility for
recording written filenames. This removes the FileWriter wrapping in
GeneratorFrontEnd.
@jdkoren jdkoren requested a review from jcollins-g January 9, 2020 17:28
Copy link
Contributor

@jcollins-g jcollins-g left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@jdkoren jdkoren merged commit 983b3d6 into dart-lang:master Jan 9, 2020
@jdkoren jdkoren deleted the html_backend branch January 9, 2020 21:00
@jdkoren jdkoren restored the html_backend branch January 9, 2020 21:05
jdkoren added a commit that referenced this pull request Jan 9, 2020
jcollins-g pushed a commit that referenced this pull request Jan 9, 2020
jdkoren added a commit that referenced this pull request Jan 9, 2020
jdkoren added a commit that referenced this pull request Jan 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Google CLA check succeeded.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants