You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You may ask yourself many questions about this basic examples, and you will find most if not all answers in this readme. In case is missing something, feel free to ask via discussions.
71
+
72
+
But I want to explain a few things now.
73
+
74
+
First you may notice that our `src/button.html` component has a `type` and `class` attribute, and when we use the component in `src/index.html` we add type and class attribute. The result is that `type` is override, and `class` is merged.
75
+
76
+
By default `class` and `style` attributes are merged, while all others attribute are override. You can also override class and style attribute by prepending `override:` to the class attribute. Example:
All attributes you pass to the component will be added to the first root element of your component, and only if they are not defined as `props` via `<script props>`. More details on this later.
86
+
87
+
Second you may notice a `<yield>` tag.
88
+
89
+
This is where your content will be injected.
90
+
91
+
In next section you can find all available options and then more examples.
|**root**|`'./'`| String value as root path for components lookup. |
98
+
|**roots**|`['']`| Array of additional multi roots path from `options.root`. |
99
+
|**tagPrefix**|`x-`| String for tag prefix. |
100
+
|**tag**|`false`| String or boolean value for component tag. Use this with `options.attribute`. Boolean only false.|
101
+
|**attribute**|`src`| String value for component attribute for set path. |
102
+
|**namespaces**|`[]`| Array of namespace's root path, fallback path and custom path for override. |
103
+
|**namespaceSeparator**|`::`| String value for namespace separator to be used with tag name. Example `<x-namespace::button>`|
104
+
|**namespaceFallback**|`false`| Boolean value for use fallback path to defined roots in `options.roots`. |
105
+
|**fileExtension**|`html`| String value for file extension of the components used for retrieve x-tag file.|
106
+
|**yield**|`yield`| String value for `<yield>` tag name. Where main content of component is injected. |
107
+
|**slot**|`slot`| String value for `<slot>` tag name.|
108
+
|**fill**|`fill`|String value for `<fill>` tag name. |
109
+
|**push**|`push`| String value for `<push>` tag name. |
110
+
|**stack**|`stack`|String value for `<stack>` tag name. |
111
+
|**localsAttr**|`props`|String value used in `<script props>` parsed by the plugin to retrieve locals in the components. |
112
+
|**expressions**|`{}`| Object to configure `posthtml-expressions`. You can pre-set locals or customize the delimiters for example.|
113
+
|**plugins**|`[]`| PostHTML plugins to apply for every parsed components.|
114
+
|**matcher**|`[{tag: options.tagPrefix}]`| Array of object used to match the tags.|
115
+
|**attrsParserRules**|`{}`| Additional rules for attributes parser plugin.|
116
+
|**strict**|`true`| Boolean value for enable or disable throw an exception. |
94
117
95
118
## Features
96
119
97
120
### Tag names and x-tags
98
121
99
122
You can use the components in multiple ways, or also a combination of them.
100
-
Like with `posthtml-extend` and `posthtml-modules` you can define a tag name or multiples tag name in combination with an attribute name or multiple attributes name for set the path to the components.
123
+
Like with `posthtml-extend` and `posthtml-modules` you can define a tag name in combination with an attribute name for set the path of the components.
101
124
102
125
For example for the same button component `src/button.html` in the basic example we can define the tag name and attribute name and then use it in this way:
We can also set multiple tag names by passing an array of component name and an array of attribute name, this is useful if you need to migrate from `posthtml-extend` and `posthtml-modules` where you are using different tag name.
124
-
125
-
Init PostHTML with multiple tag names and attributes:
If you need more control over how to match the tags, you can pass directly an array of matcher or single object via `options.matcher` like shown in below example:
152
147
153
148
```js
@@ -198,7 +193,7 @@ If your components are in a subfolder then you can use `dot` to access it, examp
198
193
<x-forms.button>Submit</x-forms.button>
199
194
```
200
195
201
-
If your components are in a sub-folder with multiple files, then for avoid to type the main file you can use `index.html` without specify it.
196
+
If your components are in a sub-folder with multiple files, then for avoid typing the main file you can use `index.html` without specify it.
202
197
Please see below example to understand better.
203
198
204
199
```html
@@ -244,11 +239,13 @@ With namespaces you can define a top level root path to your components like sho
244
239
245
240
### Slots
246
241
242
+
### Stacks
243
+
247
244
### Props
248
245
249
-
### Matcher
246
+
### Attributes
250
247
251
-
## Migration from posthtml-extend and posthtml-modules
248
+
## Migration
252
249
253
250
## Contributing
254
251
@@ -265,4 +262,5 @@ See [PostHTML Guidelines](https://github.com/posthtml/posthtml/tree/master/docs)
265
262
266
263
## Credits
267
264
268
-
Thanks to all PostHTML contributors and especially to `posthtml-extend` and `posthtml-modules` contributors, as part of code are ~~stolen~~ borrowed from these plugins.
265
+
Thanks to all PostHTML contributors and especially to `posthtml-extend` and `posthtml-modules` contributors, as part of code are ~~stolen~~ inspired from these plugins.
266
+
Huge thanks also to Laravel Blade template engine!
constexpected=`<div><div>Computed is true</div><div><h1>Custom title from JSON and String</h1></div><div><span>another item</span><span>yet another</span><span>first item</span><span>second item</span></div><div><span>title: This is default main title</span><span>subtitle: This is default subtitle</span><span>suptitle: This is custom suptitle</span></div></div>`;
0 commit comments