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

Allow Users to choose which file formats to generate SRS in #2751

Closed
Ant13731 opened this issue Jul 30, 2021 · 1 comment · Fixed by #2771
Closed

Allow Users to choose which file formats to generate SRS in #2751

Ant13731 opened this issue Jul 30, 2021 · 1 comment · Fixed by #2771
Assignees

Comments

@Ant13731
Copy link
Collaborator

Based on #1732, from Dr. Carette and Dr. Smith,

Having DocSpec mean the kind of document to generate makes sense. Now, we might want a bit more control, i.e. the choice to generate just the HTML or just the latex version of the SRS (for example). This shouldn't be controlled by a 'file type', but something more meaningful. So maybe a list of kinds? And then instead of Filename, perhaps DirectoryRoot ?

We won't always want to generate all possible file types for all our outputs. Within our GitHub page, while we are developing Drasil, it makes sense for us to generate everything we can generate. However, when Drasil makes it out into the wild and someone is using it on a real project, they might not want everything. This becomes more noticeable if we extend the file formats for the SRS documents. For instance we could add a text version, or an rtf version. The person using the software might have no need for the tex version, and choose not to generate it. I don't think fine grained control on the types of files that are generated is a high priority, but we should allow for flexibility in the future.

@Ant13731 Ant13731 self-assigned this Jul 30, 2021
@Ant13731
Copy link
Collaborator Author

I've started a bit on this issue, but I the idea I came up with feels super hacky, though I can't quite put my finger on it. I wanted to make it so that the user can pass in the Formats they want (Formats is defined in drasil-printers) as a list. I also wanted to limit those options to be SRS specific so that Website couldn't generate a PDF, though I suppose Drasil could if we wanted it to. I think it would be good to have these options somewhere in DocSpec, but I didn't really know how to go about implementing it.

I started by making the SRS constructor take a list of Formats:

-- added a list of possible formats to the SRS constructor so users can choose either PDF, HTML, or Plain
-- Choosing Plain at the moment will return nothing
data DocType = SRS [Format] | Website

Then, following through with the implementation, I made prnt recursive. Initially I had also made prntDoc recursive over the list of formats, but I realized prnt is already doing the heavy lifting. So instead, I passed a singleton list of Format and just pattern matched on that.

-- make prnt recursive over the list of Format
prnt sm dt@(DocSpec (SRS (x:xs)) fn) body = 
   --         manually put 'x' into a singleton list
  do prntDoc (DocSpec (SRS [x]) fn) body sm
     prntAuxFiles
     prnt sm (DocSpec (SRS xs) fn) body
  where
    prntAuxFiles = case x of
      TeX  -> prntMake dt
      HTML -> prntCSS SRS fn body
      _ -> return
prnt sm dt@(DocSpec _ fn) body = return

-- added pattern matches for HTML and TeX but it seems pretty fragile
prntDoc :: DocSpec -> Document -> PrintingInformation -> IO ()
prntDoc (DocSpec Website fn) d pinfo = prntDoc' "Website" fn HTML d pinfo
prntDoc (DocSpec (SRS [HTML]) fn) d pinfo = prntDoc' "SRS/HTML" fn HTML d pinfo
prntDoc (DocSpec (SRS [TeX]) fn) d pinfo = prntDoc' "SRS/PDF" fn TeX d pinfo
prntDoc (DocSpec _ fn) d pinfo = error "Something is wrong in prntDoc. This should not happen."

Is there anything I should do to make this better? I thought about making the SRS constructor takeonly one Format at a time and make the user call the prnt functions twice. Maybe instead of a list, we could use the NonEmpty list type? Otherwise, should there be a default format if the printer gets passed an empty value?

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 a pull request may close this issue.

1 participant