Giter VIP home page Giter VIP logo

Comments (11)

krzysztofzablocki avatar krzysztofzablocki commented on May 21, 2024

It's an interesting option to add, but I think we have much more things to add before we should consider implementing this.

When we start to mutate original Source then I start getting a little more worried about potential implications, FWIW. you wouldn't be able to use private code in that case anyway, only fileprivate.

Once we get to more stable feature set then we can explore this feature, does that make sense?

from sourcery.

ilyapuchka avatar ilyapuchka commented on May 21, 2024

Sure, not even for 1.0 maybe.

from sourcery.

krzysztofzablocki avatar krzysztofzablocki commented on May 21, 2024

I'll probably consider how to implement this next because it would be convenient for things like NSCoding etc

from sourcery.

krzysztofzablocki avatar krzysztofzablocki commented on May 21, 2024

How do we feel about this syntax for both code and template:

// sourcery:inline:Type.AutoCoding
// sourcery:end

It would:

  • Remove the body of that generated pattern while parsing (to avoid chicken-egg problem)
  • Find the same pattern in one of the template generated code
    • Replace the source code with generated code
    • [Question] Comment out or Remove the Template fragment?

from sourcery.

ilyapuchka avatar ilyapuchka commented on May 21, 2024

What do you mean by "comment or remove the template fragment"? Do you mean these annotations for source code?

from sourcery.

krzysztofzablocki avatar krzysztofzablocki commented on May 21, 2024

I wonder what should happen inside the output swift file (because there might be more code than just the inline fragments, whether we comment it out, or remove it completely when we put it inside the project source code.

e.g. currently NSCoding has commented out code, that the replacePlaceholders script uses, we won't do it like that obviously, but I wonder if having commented out code that we replace wouldn't be helpful, especially in watcher mode

from sourcery.

ilyapuchka avatar ilyapuchka commented on May 21, 2024

You mean having this in template:

something else

// sourcery:inline:Type.AutoCoding
...
// sourcery:end

something else

should we remove what is generated by everything outside annotated block? I would say yes. Otherwise it may be just easier to put the name of the template in the annotation and just put everything generated by it in the source file. And in the end templates as everything else should do one thing only.
Why do you think we would need to keep it commented?

from sourcery.

krzysztofzablocki avatar krzysztofzablocki commented on May 21, 2024

this is what I mean:
e.g. Template.stencil

some common code needed for the template

{% for type in types.implementing.AutoCoding %}
 // sourcery:inline:{{ type.name }}.NSCoding
   required init?(coder aDecoder: NSCoder) {
     ...     
   }
// sourcery:end

e.g. source code:

class Foo: NSObject, AutoCoding {
   // sourcery:inline:Foo.NSCoding
   This is where the code would be injected
  // sourcery:end
}

What happens in Template.generated.swift?

a) the code between sourcery:inline disappear completely
b) the code between sourcery:inline is commented out but there (same as injected into source)

from sourcery.

ilyapuchka avatar ilyapuchka commented on May 21, 2024

Now I get it =) I would go for "a" but will maybe add a comment saying "generated code inlined in file ..."

from sourcery.

 avatar commented on May 21, 2024

Ok, just to confirm something

I use the inline approach for all of the generated code in my project.

The following file demands I have an output key.

while reading .yml 'some/path/.sourcery.yml'. 'Invalid output. 'output' key is missing or is not a string or object.'

The presence of an output key in the following file seems to generate an empty file called someName.generated.swift

sources:
  - some/path
templates:
  - some/path
output:
  ./

There is currently no option to stop this file from being generated, right?

It's not the end of the world as I can just exclude it from compile sources & git.

from sourcery.

ilyapuchka avatar ilyapuchka commented on May 21, 2024

@rob-nash the output path is required, as well as sources and templates paths. The empty generated files are supposed to be removed. If not - that's a bug, you may want to create a new issue with a reproducible example.

from sourcery.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.