Skip to content

Commit

Permalink
Add an explicit note on the front readme and in the language.md about…
Browse files Browse the repository at this point in the history
… case sensitive .NET properties/members (#38)
  • Loading branch information
xoofx committed Dec 12, 2017
1 parent 6084388 commit d0c1e7f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
4 changes: 4 additions & 0 deletions doc/language.md
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 446,10 @@ If the object is a "pure" scriban objects (created with a `{...}` or instantiat
may be
```

> **NOTE**
> By default, Properties and methods of .NET objects are automatically exposed with lowercase and `_` names. It means that a property like `MyMethodIsNice` will be exposed as `my_method_is_nice`. This is the default convention, originally to match the behavior of liquid templates.
> If you want to change this behavior, you need to use a [`MemberRenamer`](runtime.md#member-renamer) delegate
### 5.1 The special property `empty?`

Any object can respond the the property `.empty?` to check if it is empty or not:
Expand Down
18 changes: 13 additions & 5 deletions doc/runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 256,9 @@ This function can be imported into a ScriptObject:
> Notice that when using a function with pipe calls like `{{description | string.strip }}``, the last argument passed to the `string.strip` function is the result of the previous pipe.
> That's a reason why you will notice in all builtin functions in scriban that they usually take the most relevant parameter as a last parameter instead of the first parameter, to allow proper support for pipe calls.
> NOTE: The members of a .NET object are exposed using only lowercase characters and introducing `_` whenever there is a uppercase character. It means that by default the string `MyMethodIsNice` will be exposed `my_method_is_nice`. This is done via a member renamer delegate. You can setup a member renamer when importing an existing .NET object but also a default member renamer on the `TemplateContext`. See [Member renamer](#member-renamer) in advanced usages about this topic.
> **NOTE**
> By default, Properties and methods of .NET objects are automatically exposed with lowercase and `_` names. It means that a property like `MyMethodIsNice` will be exposed as `my_method_is_nice`. This is the default convention, originally to match the behavior of liquid templates.
> If you want to change this behavior, you need to use a [`MemberRenamer`](#member-renamer) delegate
#### Automatic functions import from `ScriptObject`

Expand Down Expand Up @@ -299,7 301,9 @@ Notice that if you want to ignore a member when importing a .NET object or .NET

> NOTE: Because Scriban doesn't support Function overloading, it is required that functions imported from a type must have different names.
> NOTE: The members of a .NET object are exposed using only lowercase characters and introducing `_` whenever there is a uppercase character. It means that by default the string `MyMethodIsNice` will be exposed `my_method_is_nice`. This is done via a member renamer delegate. You can setup a member renamer when importing an existing .NET object but also a default member renamer on the `TemplateContext`. See [Member renamer](#member-renamer) in advanced usages about this topic.
> **NOTE**
> By default, Properties and methods of .NET objects are automatically exposed with lowercase and `_` names. It means that a property like `MyMethodIsNice` will be exposed as `my_method_is_nice`. This is the default convention, originally to match the behavior of liquid templates.
> If you want to change this behavior, you need to use a [`MemberRenamer`](#member-renamer) delegate
#### Function arguments, optional and `params`

Expand Down Expand Up @@ -422,7 426,9 @@ and import the properties/functions of this object into a ScriptObject, via `Scr

Also any objects inheriting from `IDictionary<TKey, TValue>` or `IDictionary` will be also accessible automatically. Typically, you can usually access directly any generic JSON objects that was parsed by a JSON library.

> NOTE: The members of a .NET object are exposed using only lowercase characters and introducing `_` whenever there is a uppercase character. It means that by default the string `MyMethodIsNice` will be exposed `my_method_is_nice`. This is done via a member renamer delegate. You can setup a member renamer when importing an existing .NET object but also a default member renamer on the `TemplateContext`. See [Member renamer](#member-renamer) in advanced usages about this topic.
> **NOTE**
> By default, Properties and methods of .NET objects are automatically exposed with lowercase and `_` names. It means that a property like `MyMethodIsNice` will be exposed as `my_method_is_nice`. This is the default convention, originally to match the behavior of liquid templates.
> If you want to change this behavior, you need to use a [`MemberRenamer`](#member-renamer) delegate
#### Accessing a .NET object

Expand All @@ -448,7 454,9 @@ For example, if we re-use the previous `MyObject` directly as a variable in a `S
Console.WriteLine(context.Output.ToString());
```

> NOTE: The members of a .NET object are exposed using only lowercase characters and introducing `_` whenever there is a uppercase character. It means that by default the string `MyMethodIsNice` will be exposed `my_method_is_nice`. This is done via a member renamer delegate. You can setup a member renamer when importing an existing .NET object but also a default member renamer on the `TemplateContext`. See [Member renamer](#member-renamer) in advanced usages about this topic.
> **NOTE**
> By default, Properties and methods of .NET objects are automatically exposed with lowercase and `_` names. It means that a property like `MyMethodIsNice` will be exposed as `my_method_is_nice`. This is the default convention, originally to match the behavior of liquid templates.
> If you want to change this behavior, you need to use a [`MemberRenamer`](#member-renamer) delegate
#### read-only properties

Expand Down Expand Up @@ -514,7 522,7 @@ The `TemplateContext` stack is setup like this: `scriptObject2` => `scriptObjec

As you can see the variable `var1` will be resolved from `scriptObject1` but the variable `var2` will be resolved from `scriptObject2` as there is an override here.

> **NOTE**: If a variable is not found, the runtime will not throw an error but will return `null` instead. It allows to check for a variable existence `if !page` for example. In case you want your script to throw an exception if a variable was not found, you can specify `TemplateContext.StrictVariables = true` to enforce checks. See the [safe runtime](#safe-runtime) section for more details.
> **NOTE** If a variable is not found, the runtime will not throw an error but will return `null` instead. It allows to check for a variable existence `if !page` for example. In case you want your script to throw an exception if a variable was not found, you can specify `TemplateContext.StrictVariables = true` to enforce checks. See the [safe runtime](#safe-runtime) section for more details.
When writing to a variable, only the `ScriptObject` at the top of the `TemplateContext` will be used. This top object is accessible through `TemplateContext.CurrentGlobal` property. It the previous example, if we had something like this in a template:

Expand Down
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 35,10 @@ var template = Template.Parse(@"
var result = template.Render(new { Products = this.ProductList });
```

> **NOTE**
> By default, Properties and methods of .NET objects are automatically exposed with lowercase and `_` names. It means that a property like `MyMethodIsNice` will be exposed as `my_method_is_nice`. This is the default convention, originally to match the behavior of liquid templates.
> If you want to change this behavior, you need to use a [`MemberRenamer`](doc/runtime.md#member-renamer) delegate
## Features

- Very **efficient**, **fast** parser and a **lightweight** runtime. CPU and Garbage Collector friendly. Check the [benchmarks](doc/benchmarks.md) for more details.
Expand Down

0 comments on commit d0c1e7f

Please sign in to comment.