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

Document file sideloading #789

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

SergeiGolos
Copy link

The idea here is to create a mechanism for side-loading additional CSS and Script tags into the generated report document.

Broke up the BatchResultWriter into a couple of classes allowing the document creation process to be more compose-able. The update logic breaks up the resolution of resources and the updating of the document into two separate interfaces. IDocumentBuilder which modifies the HtmlDocument that is passed into it via the Apply method and the IDocumentPartLoader which resolves resources and exposes the text via the .Read() method.

Only 3 IDocumentBuilder are default, the ScriptTagBuilder, StyleTagBuilder and ReportPartBuilder which should only be run once per report. They are pretty self explanatory and represent the binding logic originally found in the writeJavascript and WriteCSS methods.

The resolution of content for the IDocumentBuilders is left to the IDocumentPartLoader implementations.

  • ResourceFileLoader: this replaces the original function,
  • LocalFileLoader: loads a given file as a resource.
  • CombinedResourceLoader: allows multiple resources to be combined via string.Join, the default is \n\n but can be overwritten in the constructor.
  • StringFileLoader: Bypases IO and loads string from memory.

StyleTagBuilder and ScriptTagBuilder are now instances of the Html tag they represent.  In the IDocumentBuilder interfaces they now simply attach themselves.
Updated the class to have the Assembly passed into it.  Also created some default overides to make it easier to use the class.
 - Refactored the BatchResultWriter to reduce the logic in a static class and moved the logic into a HtmlDocumentBuilder class.
 - HtmlDocumentBuilder can be swapped in BatchResultWriter
 - DefaultHtmlDocumentBuilder defines the current script and css tags.
 - Script tag support user URI for src attribtues instead of content.
 - Script and Style Tags support string as their content.
 - Link tag added
 - Everything on the HtmlDocument is created with IDocumentBuilders even the title.
 - Added some comments to the code.
@mvastarelli
Copy link

Test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants