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

RFC: allowing to save template for later use? #80

Closed
Roger-luo opened this issue Jun 23, 2019 · 8 comments · Fixed by #61
Closed

RFC: allowing to save template for later use? #80

Roger-luo opened this issue Jun 23, 2019 · 8 comments · Fixed by #61

Comments

@Roger-luo
Copy link
Contributor

It feels annoying that each time I create a template and I have to create it again after I exit REPL. It would be nice if we could have

A proposed workflow is to extend the generate function to accept a new keyword which would looks like

generate("MyPackage"; template="MyTemplate")

and for interactive_template, it would search a local folder to check if there is a previous saved template first.

we could have a save function that saves a generated template object to a folder inside PkgTemplates folder, or an external repo. I'm wondering if people would like this feature.

@christopher-dG
Copy link
Member

From what I've seen of GitHub templates, they don't have enough features to replicate this package. Hopefully in the future though!

On saving: would simply using the Serialisation stdlib do what you want?

@Roger-luo
Copy link
Contributor Author

I think any serialization functionality can do the job! but I think it would be nice to have this directly in the package.

the point is after being able to save the template configuration to a file, I could share it, re-edit it and put it public. And next time if I want to generate a package, I can just type one line without choosing anything else.

regarding to github template: I think we can just consider github template as serialization format for a package, it won't contain any further info except a configured template

@oxinabox
Copy link
Collaborator

oxinabox commented Sep 3, 2019

The following does not work, but should.
Unfortunately, PkgTemplaters overrides show wrong,
so that does not include a parsable output.

julia> using PkgTemplates

julia> ox_template = Template(;
            user="oxinabox",
            license="MIT",
            authors=["Lyndon White"],
            dir=".",
            julia_version=v"1.0",
            plugins=[
                TravisCI(),
                Codecov(),
                AppVeyor(),
                GitHubPages(),
                CirrusCI(),
            ],
        );

julia> open("mytemplates.jl" ,"w") do fh
           print(fh, "const ox_template = ")
           show(fh, ox_template)
       end

If that worked all one would need to do is

using PkgTemplates
include("mytemplates.jl")

@Roger-luo for interest, what Invenia does internally is have a private package:
InvenialTemplates on our internal registry,
that has out standard templates defined in it,
and since it is a whole repo it can have more than just the template configuration,
it also has stuff like the CSS stylesheet, and graphics we use for our docs etc.
But for many people that is over overkill and just writing something that can be included.

I wonder if we should actaully create a PkgTemplatesCommons.jl
where anyone can add their templates and others can see what people are doing.

@christopher-dG
Copy link
Member

Unfortunately, PkgTemplaters overrides show wrong, so that does not include a parsable output.

I don't think the recommendation to output Julia syntax has ever been more than a recommendation.

@christopher-dG
Copy link
Member

I'd probably just recommend using Serialization, or doing something like this in startup.jl:

template() = Template(; #= ... =#)

That way it's up to you to using PkgTemplates before you call the function, but you don't get a huge startup overhead.

@oxinabox
Copy link
Collaborator

oxinabox commented Sep 3, 2019

it is a strong recommendation though,
as it is hella useful for things like this
and for other plain text serialization.

There is a way you can have both by using the Mime String.
I think rather than overloading show(::IO, ::MyType) one overloads show(::IO, ::MIME"text/plain", MyType)

Discussion here
JuliaLang/julia#30757

@Roger-luo
Copy link
Contributor Author

@oxinabox Thanks, I agree with you, we could have some sort of common template package that provides and share some common templates that allows you generate a package with only one button. InvenialTemplates is definitely a good thing!

@christopher-dG
Copy link
Member

#61 includes a short doc section with recommendations for saving (which could certainly be expanded) and eval(Meta.parse(sprint(show, t))) == t works so you can dump to a file if desired. The "template showcase/registry" idea is good but maybe can be taken care of later.

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.

3 participants