Class Recipe
A recipe contains instructions how to generate tags etc. which can contain multiple resized images
Implements
Namespace: ToSic.Sxc.Images
Assembly: ToSic.Sxc.dll
Syntax
[PublicApi("Still Beta / WIP")]
public class Recipe : ICanDump
Remarks
All the properties are read-only. If you need to override anything, copy it and set the modified values, then use the copy.
Constructors
| Improve this Doc View SourceRecipe(string, string, string, string, int, bool?, bool?, string, IDictionary<string, object>, IEnumerable<Recipe>)
Lighter constructor for json, without parameter Recipe.
Important If you call this from your code, always use named parameters, as the parameter order can change in future.
Declaration
[JsonConstructor]
public Recipe(string name = null, string forTag = null, string forFactor = null, string forCss = null, int width = 0, bool? setWidth = null, bool? setHeight = null, string variants = null, IDictionary<string, object> attributes = null, IEnumerable<Recipe> recipes = null)
Parameters
Type | Name | Description |
---|---|---|
string | name | An optional name |
string | forTag | Restricts the rule to only apply to specific tags - ATM |
string | forFactor | Restricts the rule to only apply to resizes for a specified factor |
string | forCss | Restricts the rule to only apply to pages which have the specified CSS Framework |
int | width | Initial width to use when resizing |
bool? | setWidth | Set the |
bool? | setHeight | Set the |
string | variants | Special string containing variants to generate |
IDictionary<string, object> | attributes | List of attributes to set on the |
IEnumerable<Recipe> | recipes | List of additional recipes which will all inherit values from this master after creation |
Recipe(Recipe, string, string, string, string, int, bool?, bool?, string, IDictionary<string, object>, IEnumerable<Recipe>)
Important
If you call this from your code, always use named parameters, as the parameter order can change in future.
Declaration
public Recipe(Recipe original, string name = null, string forTag = null, string forFactor = null, string forCss = null, int width = 0, bool? setWidth = null, bool? setHeight = null, string variants = null, IDictionary<string, object> attributes = null, IEnumerable<Recipe> recipes = null)
Parameters
Type | Name | Description |
---|---|---|
Recipe | original | An original recipe to copy if we want to get a modified recipe based on one which already existed. |
string | name | An optional name |
string | forTag | Restricts the rule to only apply to specific tags - ATM |
string | forFactor | Restricts the rule to only apply to resizes for a specified factor |
string | forCss | Restricts the rule to only apply to pages which have the specified CSS Framework |
int | width | Initial width to use when resizing |
bool? | setWidth | Set the |
bool? | setHeight | Set the |
string | variants | Special string containing variants to generate |
IDictionary<string, object> | attributes | List of attributes to set on the |
IEnumerable<Recipe> | recipes | List of additional recipes which will all inherit values from this master after creation |
Properties
| Improve this Doc View SourceAttributes
Attributes to add to the img tag
Declaration
public IDictionary<string, object> Attributes { get; }
Property Value
Type | Description |
---|---|
IDictionary<string, object> |
Remarks
System.Text.Json requires that the case-insensitive property name and type match the parameter in the constructor. We are using string/object because a value could also be { "name": true, "other-name": 5 } in the json configuration
ForCss
WIP, not implemented yet
Declaration
public string ForCss { get; set; }
Property Value
Type | Description |
---|---|
string |
ForFactor
Determines which factors this recipe should be applied to. Null means any factor.
Declaration
public string ForFactor { get; }
Property Value
Type | Description |
---|---|
string |
ForTag
TODO: DOC
img
,source
Declaration
public string ForTag { get; }
Property Value
Type | Description |
---|---|
string |
Name
Just an identifier - no technical use
Declaration
public string Name { get; }
Property Value
Type | Description |
---|---|
string |
Recipes
wip TODO: DOC
Declaration
public IEnumerable<Recipe> Recipes { get; }
Property Value
Type | Description |
---|---|
IEnumerable<Recipe> |
Remarks
System.Text.Json requires that the case-insensitive property name and type match the parameter in the constructor.
SetHeight
Determines if the img tag will receive a height-attribute
Declaration
public bool? SetHeight { get; }
Property Value
Type | Description |
---|---|
bool? |
SetWidth
Determines if the img tag will receive a width-attribute
Declaration
public bool? SetWidth { get; }
Property Value
Type | Description |
---|---|
bool? |
Variants
Source-Set rules (comma separated) which will determine what will be generated.
Examples:
1x,1.5x,2x
- screen resolutions200w,400w,600w,800w,1000w
- pixel sizes0.5*,1*,1.5*,2*
- multipliers of the originally specified pixel size
Important: According to the HTML standard you can mix pixel-sizes and multipliers, but not resolutions with any of the other types.
Declaration
public string Variants { get; }
Property Value
Type | Description |
---|---|
string |
Width
The initial width to assume in this resize, from which other sizes would be calculated.
If set to 0, it will be ignored.
Declaration
public int Width { get; }
Property Value
Type | Description |
---|---|
int |
Methods
| Improve this Doc View SourceDump()
Create a string dump of the current objects state/contents.
Declaration
public string Dump()
Returns
Type | Description |
---|---|
string |