Code Monkey home page Code Monkey logo

Comments (7)

NeVeSpl avatar NeVeSpl commented on September 26, 2024 1

Obviously, it is not expected, but Scriban is responsible for that part. NTypewriter uses Scriban v5.5, and apparently, there was some fix in version 5.6 of scriban/scriban#483 related to not intended indentation.

from ntypewriter.

gregveres avatar gregveres commented on September 26, 2024

Checkout this section of docs

Basically, you need to add a '-' to supress the extra whitespace.

{{ - class.BareName }}

from ntypewriter.

washamdev avatar washamdev commented on September 26, 2024

That removes all whitespaces and new lines before that line though.

image

from ntypewriter.

NeVeSpl avatar NeVeSpl commented on September 26, 2024

I have another idea, maybe the class name contains whitespaces? I would try:
{{ class.BareName | String.Strip }}

from ntypewriter.

gregveres avatar gregveres commented on September 26, 2024

or maybe add a {{ }} ahead of the {{ - class.BareName }} to ensure that the new line isn't stripped.
In my templates, I make sure there are no indentations in the main body of my template. If I need to output something from a function, I return it as a string that the main body prints out. This way I control all the indentation from the main body.

Like this:

{{- # Helper classes }}
{{- func ImportType(type)
	useType = Type.Unwrap(type)
	if (useType.ArrayType != null) 
	  useType = useType.ArrayType
	end
	if (type.IsEnum) 
	  path = "@skycourt/api/enums"
	else
	  path = "./" | String.Append useType.Name
    end
	if ((useType.Attributes | Array.Filter @AttrIsExportToTypescript).size > 0)
		ret "import { " | String.Append useType.Name | String.Append " } from '" | String.Append path | String.Append "';\r"
	end
	ret null
	end
}}
{{- func AttrIsExportToTypescript(attr)
	ret attr.Name | String.Contains "ExportToTypescript"
	end
}}

{{- # output classes }}
{{ $barrelFile = "" }}
{{- for class in data.Classes | Symbols.ThatHaveAttribute "ExportToTypescript" | Array.Concat (data.Classes | Symbols.ThatHaveAttribute "ExportToTypescriptWithKnockout") | Array.Sort "Name"
		capture output }}

{{- for type in (class | Type.AllReferencedTypes)}}
	{{- ImportType type}}
{{-end}}

export interface {{class.Name}}{{if class.HasBaseClass}} extends {{class.BaseClass.Name; end}} {
  {{- for prop in class.Properties | Symbols.ThatArePublic }}
  {{ prop.Name | String.ToCamelCase }}: {{prop | Custom.ToTypeScriptType }}{{if !for.last}},{{end}}
  {{-end}}
}
{{- end}}

from ntypewriter.

washamdev avatar washamdev commented on September 26, 2024

@gregveres I didn't need the {{-. Just using {{ worked, as long as I added the blank entry first. So {{ }}{{ class.BareName }} was the winner! Thank you! Is this a bug or expected behavior?

from ntypewriter.

gregveres avatar gregveres commented on September 26, 2024

Based on the documentation, I would say it is working as expected.
But if it is a bug, then it is a bug in Scriban, not in NTypewriter. You could as on their github site.

from ntypewriter.

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.