Skip to content

Commit 922a422

Browse files
committed
minor #971 Updating documentation for newly merged recipes (weaverryan)
This PR was squashed before being merged into the 2.x branch. Discussion ---------- Updating documentation for newly merged recipes | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | Tickets | None | License | MIT See symfony/recipes#1213 Commits ------- cf6a9bd Updating documentation for newly merged recipes
2 parents 21d16ea + cf6a9bd commit 922a422

File tree

4 files changed

+61
-121
lines changed

4 files changed

+61
-121
lines changed

src/React/doc/index.rst

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,11 @@ Then install the bundle using Composer and Symfony Flex:
2525
2626
$ composer require symfony/ux-react
2727
28-
Next, in ``webpack.config.js``, enable React support:
28+
The Flex recipe will automatically set things up for you, like adding
29+
``.enableReactPreset()`` to your ``webpack.config.js`` file and adding code
30+
to load your React components inside ``assets/app.js``.
2931

30-
.. code-block:: javascript
31-
32-
// webpack.config.js
33-
// ...
34-
35-
Encore
36-
// ...
37-
.enableReactPreset()
38-
;
39-
40-
Install a package to help React:
32+
Next, install a package to help React:
4133

4234
.. code-block:: terminal
4335
@@ -48,45 +40,33 @@ Install a package to help React:
4840
$ yarn add @babel/preset-react --dev --force
4941
$ yarn watch
5042
51-
Finally, to load your React components, add the following lines to ``assets/app.js``:
43+
That's it! Any files inside ``assets/react/controllers/`` can now be rendered as
44+
React components.
45+
46+
Usage
47+
-----
48+
49+
The Flex recipe will have already added the ``registerReactControllerComponents()``
50+
code to your ``assets/app.js`` file:
5251

5352
.. code-block:: javascript
5453
5554
// assets/app.js
5655
import { registerReactControllerComponents } from '@symfony/ux-react';
5756
58-
// Registers React controller components to allow loading them from Twig
59-
//
60-
// React controller components are components that are meant to be rendered
61-
// from Twig. These component then rely on other components that won't be called
62-
// directly from Twig.
63-
//
64-
// By putting only controller components in `react/controllers`, you ensure that
65-
// internal components won't be automatically included in your JS built file if
66-
// they are not necessary.
67-
registerReactControllerComponents(require.context('./react/controllers', true, /\.(j|t)sx?$/));
68-
69-
That's it! Create an ``assets/react/controllers/`` directory and start creating your
70-
React components.
71-
72-
Usage
73-
-----
74-
75-
UX React works by using a system of **React controller components**: React components that
76-
are registered using ``registerReactControllerComponents`` and that are meant to be rendered
77-
from Twig.
57+
registerReactControllerComponents(require.context('./react/controllers', true, /\\.(j|t)sx?$/));
7858
79-
When using the ``registerReactControllerComponents`` configuration shown previously, all
80-
React components located in the directory ``assets/react/controllers`` are registered as
81-
React controller components.
59+
This will load all React components located in the ``assets/react/controllers``
60+
directory. These are known as **React controller components**: top-level
61+
components that are meant to be rendered from Twig.
8262

83-
You can then render any React controller component in Twig using the ``react_component``.
63+
You can render any React controller component in Twig using the ``react_component()``.
8464

8565
For example:
8666

8767
.. code-block:: javascript
8868
89-
// assets/react/controllers/MyComponent.jsx
69+
// assets/react/controllers/Hello.jsx
9070
import React from 'react';
9171
9272
export default function (props) {
@@ -99,7 +79,7 @@ For example:
9979
{% extends 'base.html.twig' %}
10080

10181
{% block body %}
102-
<div {{ react_component('MyComponent', { 'fullName': number }) }}>
82+
<div {{ react_component('Hello', { 'fullName': number }) }}>
10383
Loading... <i class="fas fa-cog fa-spin fa-3x"></i>
10484
</div>
10585

src/Svelte/doc/index.rst

Lines changed: 22 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,11 @@ Then install the bundle using Composer and Symfony Flex:
3333
$ yarn install --force
3434
$ yarn watch
3535
36-
You also need to add the following lines at the end to your ``assets/app.js`` file:
36+
The Flex recipe will automatically set things up for you, like adding
37+
``.enableSvelte()`` to your ``webpack.config.js`` file and adding code
38+
to load your Vue components inside ``assets/app.js``.
3739

38-
.. code-block:: javascript
39-
40-
// assets/app.js
41-
import { registerSvelteControllerComponents } from '@symfony/ux-svelte';
42-
43-
// Registers Svelte controller components to allow loading them from Twig
44-
//
45-
// Svelte controller components are components that are meant to be rendered
46-
// from Twig. These component can then rely on other components that won't be
47-
// called directly from Twig.
48-
//
49-
// By putting only controller components in `svelte/controllers`, you ensure that
50-
// internal components won't be automatically included in your JS built file if
51-
// they are not necessary.
52-
registerSvelteControllerComponents(require.context('./svelte/controllers', true, /\.svelte$/));
53-
54-
To make sure Svelte components can be loaded by Webpack Encore, you need to add and configure
55-
the `svelte-loader`_ library in your project :
40+
Next, install a package to help Svelte:
5641

5742
.. code-block:: terminal
5843
@@ -61,32 +46,33 @@ the `svelte-loader`_ library in your project :
6146
# or use yarn
6247
$ yarn add svelte svelte-loader --dev
6348
64-
Enable it in your ``webpack.config.js`` file :
49+
That's it! Any files inside ``assets/svelte/controllers/`` can now be rendered as
50+
Svelte components.
51+
52+
Usage
53+
-----
54+
55+
The Flex recipe will have already added the ``registerSvelteControllerComponents()``
56+
code to your ``assets/app.js`` file:
6557

6658
.. code-block:: javascript
6759
68-
// webpack.config.js
69-
Encore
70-
// ...
71-
.enableSvelte()
72-
;
60+
// assets/app.js
61+
import { registerSvelteControllerComponents } from '@symfony/ux-svelte';
7362
74-
Usage
75-
-----
63+
registerSvelteControllerComponents(require.context('./svelte/controllers', true, /\\.(j|t)sx?$/));
7664
77-
UX Svelte works by using a system of **Svelte controller components**: Svelte components that
78-
are registered using ``registerSvelteControllerComponents()`` and that are meant to be rendered
79-
from Twig.
65+
This will load all Svelte components located in the ``assets/svelte/controllers``
66+
directory. These are known as **Svelte controller components**: top-level
67+
components that are meant to be rendered from Twig.
8068

81-
When using the ``registerSvelteControllerComponents()`` configuration shown previously, all
82-
Svelte components located in the directory ``assets/svelte/controllers`` are registered as
83-
Svelte controller components.
69+
You can render any Svelte controller component in Twig using the ``svelte_component()``.
8470

85-
You can then render any Svelte controller component in Twig using the ``svelte_component()`` function:
71+
For example:
8672

8773
.. code-block:: javascript
8874
89-
// assets/svelte/controllers/MyComponent.svelte
75+
// assets/svelte/controllers/Hello.svelte
9076
<script>
9177
export let name = "Svelte";
9278
</script>
@@ -97,7 +83,7 @@ You can then render any Svelte controller component in Twig using the ``svelte_c
9783
.. code-block:: html+twig
9884

9985
{# templates/home.html.twig #}
100-
<div {{ svelte_component('MyComponent', { 'name': app.user.fullName }) }}></div>
86+
<div {{ svelte_component('Hello', { 'name': app.user.fullName }) }}></div>
10187

10288
If your Svelte component has a transition that you want to play on initial render, you can use
10389
the third argument ``intro`` of the ``svelte_component()`` function like you would do with the
@@ -156,6 +142,5 @@ the Symfony framework:
156142
https://symfony.com/doc/current/contributing/code/bc.html
157143

158144
.. _`Svelte`: https://svelte.dev/
159-
.. _`svelte-loader`: https://github.com/sveltejs/svelte-loader/blob/master/README.md
160145
.. _`the Symfony UX initiative`: https://symfony.com/ux
161146
.. _StimulusBundle configured in your app: https://symfony.com/bundles/StimulusBundle/current/index.html

src/TwigComponent/src/Test/InteractsWithTwigComponents.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected function mountTwigComponent(string $name, array $data = []): object
3030
/**
3131
* @param array<string,string> $blocks
3232
*/
33-
protected function renderTwigComponent(string $name, array $data = [], ?string $content = null, array $blocks = []): RenderedComponent
33+
protected function renderTwigComponent(string $name, array $data = [], string $content = null, array $blocks = []): RenderedComponent
3434
{
3535
if (!$this instanceof KernelTestCase) {
3636
throw new \LogicException(sprintf('The "%s" trait can only be used on "%s" classes.', __TRAIT__, KernelTestCase::class));

src/Vue/doc/index.rst

Lines changed: 19 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,11 @@ Then install the bundle using Composer and Symfony Flex:
2525
2626
$ composer require symfony/ux-vue
2727
28-
Next, in ``webpack.config.js``, enable Vue.js support:
28+
The Flex recipe will automatically set things up for you, like adding
29+
``.enableVueLoader()`` to your ``webpack.config.js`` file and adding code
30+
to load your Vue components inside ``assets/app.js``.
2931

30-
.. code-block:: javascript
31-
32-
// webpack.config.js
33-
// ...
34-
35-
Encore
36-
// ...
37-
.enableVueLoader()
38-
;
39-
40-
Install a package to help Vue:
32+
Next, install a package to help Vue:
4133

4234
.. code-block:: terminal
4335
@@ -48,48 +40,31 @@ Install a package to help Vue:
4840
$ yarn add vue-loader --dev --force
4941
$ yarn watch
5042
51-
Finally, to load your Vue components, add the following lines to ``assets/app.js``:
43+
That's it! Any files inside ``assets/vue/controllers/`` can now be rendered as
44+
Vue components.
45+
46+
Usage
47+
-----
48+
49+
The Flex recipe will have already added the ``registerVueControllerComponents()``
50+
code to your ``assets/app.js`` file:
5251

5352
.. code-block:: javascript
5453
5554
// assets/app.js
5655
import { registerVueControllerComponents } from '@symfony/ux-vue';
5756
58-
// Registers Vue.js controller components to allow loading them from Twig
59-
//
60-
// Vue.js controller components are components that are meant to be rendered
61-
// from Twig. These component can then rely on other components that won't be
62-
// called directly from Twig.
63-
//
64-
// By putting only controller components in `vue/controllers`, you ensure that
65-
// internal components won't be automatically included in your JS built file if
66-
// they are not necessary.
67-
registerVueControllerComponents(require.context('./vue/controllers', true, /\.vue$/));
68-
69-
// If you prefer to lazy-load your Vue.js controller components, in order to keep the JavaScript bundle the smallest as possible,
70-
// and improve performance, you can use the following line instead:
71-
//registerVueControllerComponents(require.context('./vue/controllers', true, /\.vue$/, 'lazy'));
72-
73-
That's it! Create an ``assets/vue/controllers/`` directory and start creating your
74-
Vue components.
75-
76-
Usage
77-
-----
78-
79-
UX Vue.js works by using a system of **Vue.js controller components**: Vue.js components that
80-
are registered using ``registerVueControllerComponents`` and that are meant to be rendered
81-
from Twig.
57+
registerVueControllerComponents(require.context('./vue/controllers', true, /\\.(j|t)sx?$/));
8258
83-
When using the ``registerVueControllerComponents`` configuration shown previously, all
84-
Vue.js components located in the directory ``assets/vue/controllers`` are registered as
85-
Vue.js controller components.
59+
This will load all Vue components located in the ``assets/vue/controllers``
60+
directory. These are known as **Vue controller components**: top-level
61+
components that are meant to be rendered from Twig.
8662

87-
You can then render any Vue.js controller component in Twig using the ``vue_component``.
88-
For example:
63+
You can render any Vue controller component in Twig using the ``vue_component()``.
8964

9065
.. code-block:: javascript
9166
92-
// assets/vue/controllers/MyComponent.vue
67+
// assets/vue/controllers/Hello.vue
9368
<template>
9469
<div>Hello {{ name }}!</div>
9570
</template>
@@ -103,7 +78,7 @@ For example:
10378
.. code-block:: html+twig
10479

10580
{# templates/home.html.twig #}
106-
<div {{ vue_component('MyComponent', { 'name': app.user.fullName }) }}></div>
81+
<div {{ vue_component('Hello', { 'name': app.user.fullName }) }}></div>
10782

10883
Events
10984
~~~~~~

0 commit comments

Comments
 (0)