Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
da65f41
Update source file api.md
askvortsov1 Feb 16, 2023
8171e46
Update source file github-actions.md
askvortsov1 Feb 16, 2023
ef162f5
Update source file models.md
askvortsov1 Feb 16, 2023
cc94f85
Update source file routes.md
askvortsov1 Feb 16, 2023
62dab07
Update source file testing.md
askvortsov1 Feb 16, 2023
969eea1
New translations testing.md (Spanish)
askvortsov1 Feb 16, 2023
4f1b320
New translations models.md (Spanish)
askvortsov1 Feb 16, 2023
48321d8
New translations github-actions.md (Spanish)
askvortsov1 Feb 16, 2023
b113c1d
New translations testing.md (German)
askvortsov1 Feb 16, 2023
f14a26f
New translations models.md (German)
askvortsov1 Feb 16, 2023
4bad93c
New translations github-actions.md (German)
askvortsov1 Feb 16, 2023
419858c
New translations testing.md (Italian)
askvortsov1 Feb 16, 2023
af2b830
New translations models.md (Italian)
askvortsov1 Feb 16, 2023
09a31a8
New translations github-actions.md (Italian)
askvortsov1 Feb 16, 2023
7e8b93d
New translations testing.md (Turkish)
askvortsov1 Feb 16, 2023
a924e56
New translations models.md (Turkish)
askvortsov1 Feb 16, 2023
ccf6cf5
New translations github-actions.md (Turkish)
askvortsov1 Feb 16, 2023
bf08cbc
New translations testing.md (Chinese Simplified)
askvortsov1 Feb 16, 2023
3eb2801
New translations models.md (Chinese Simplified)
askvortsov1 Feb 16, 2023
7f6ce1d
New translations github-actions.md (Chinese Simplified)
askvortsov1 Feb 16, 2023
00b4108
New translations testing.md (Vietnamese)
askvortsov1 Feb 16, 2023
3948fff
New translations models.md (Vietnamese)
askvortsov1 Feb 16, 2023
47ca5bd
New translations github-actions.md (Vietnamese)
askvortsov1 Feb 16, 2023
0be1e3d
New translations routes.md (Spanish)
askvortsov1 Feb 16, 2023
09116d4
New translations api.md (Spanish)
askvortsov1 Feb 16, 2023
251f331
New translations routes.md (German)
askvortsov1 Feb 16, 2023
5279f5b
New translations api.md (German)
askvortsov1 Feb 16, 2023
5774595
New translations routes.md (Italian)
askvortsov1 Feb 16, 2023
cd592b0
New translations api.md (Italian)
askvortsov1 Feb 16, 2023
27618af
New translations routes.md (Turkish)
askvortsov1 Feb 16, 2023
444f4e2
New translations api.md (Turkish)
askvortsov1 Feb 16, 2023
129d6c1
New translations routes.md (Chinese Simplified)
askvortsov1 Feb 16, 2023
a2ee7e0
New translations api.md (Chinese Simplified)
askvortsov1 Feb 16, 2023
b1cb2eb
New translations routes.md (Vietnamese)
askvortsov1 Feb 16, 2023
30a2d19
New translations api.md (Vietnamese)
askvortsov1 Feb 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/extend/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ return [
(new Extend\ApiSerializer(UserSerializer::class))
// One attribute at a time
->attribute('firstName', function ($serializer, $user, $attributes) {
return $user->first_name
return $user->first_name
})
// Multiple modifications at once, more complex logic
->mutate(function($serializer, $user, $attributes) {
Expand Down
59 changes: 53 additions & 6 deletions docs/extend/github-actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ In public repos, [GitHub Actions](https://github.com/features/actions) allow you

In this guide, you will learn how to add pre-defined workflows to your extension.

## Setup

:::tip [Flarum CLI](https://github.com/flarum/cli)

You can use the CLI to automatically add and update workflows to your code:
Expand All @@ -15,6 +13,9 @@ $ flarum-cli infra githubActions

:::

## Backend


All you need to do is create a `.github/workflows/backend.yml` file in your extension, it will reuse a predefined workflow by the core development team which can be found [here](https://github.com/flarum/framework/blob/main/.github/workflows/REUSABLE_backend.yml). You need to specify the configuration as follows:

```yaml
Expand All @@ -34,9 +35,7 @@ jobs:
backend_directory: .
```

## Backend

Flarum provides a pre-defined workflow for running certain jobs for the backend of your extension. These are the currently available jobs:
These are the currently available jobs:

| Name | Key | Description |
|-------------------------------------------------|--------------------------|----------------------------------------|
Expand Down Expand Up @@ -69,4 +68,52 @@ For more details on parameters, [checkout the full predefined reusable workflow

## Frontend

Soon..
All you need to do is create a `.github/workflows/frontend.yml` file in your extension, it will reuse a predefined workflow by the core development team which can be found [here](https://github.com/flarum/framework/blob/main/.github/workflows/REUSABLE_frontend.yml). You need to specify the configuration as follows:

```yaml
name: Frontend

on: [workflow_dispatch, push, pull_request]

jobs:
run:
uses: flarum/framework/.github/workflows/REUSABLE_frontend.yml@main
with:
enable_bundlewatch: false
enable_prettier: true
enable_typescript: false

frontend_directory: ./js
backend_directory: .
js_package_manager: yarn
main_git_branch: main

secrets:
bundlewatch_github_token: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }}
```

Unlike the backend workflow, the frontend workflow runs everything in a single job. Here are the available parameters:

| Name | Key | Description | Format |
|-----------------------|-------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------|--------|
| Build Script | `build_script` | Script to run for production build. Empty value to disable. | string |
| Build Typings Script | `build_typings_script` | Script to run for typings build. Empty value to disable. | string |
| Format Script | `format_script` | Script to run for code formatting. Empty value to disable. | string |
| Check Typings Script | `check_typings_script` | Script to run for tyiping check. Empty value to disable. | string |
| Type Coverage Script | `type_coverage_script` | Script to run for type coverage. Empty value to disable. | string |
| Test Script | `test_script` | Script to run for tests. Empty value to disable. | string |
| Enable Bundlewatch | `enable_bundlewatch` | Enable Bundlewatch? | string |
| Enable Prettier | `enable_prettier` | Enable Prettier? | string |
| Enable Typescript | `enable_typescript` | Enable TypeScript? | string |
| Enable Tests | `enable_tests` | Enable Tests? | string |
| Backend Directory | `backend_directory` | The directory of the project where backend code is located. This should contain a `composer.json` file, and is generally the root directory of the repo. | string |
| Frontend Directory | `frontend_directory` | The directory of the project where frontend code is located. This should contain a `package.json` file. | string |
| Main Git Branch | `main_git_branch` | The main git branch to use for the workflow. | string |
| Node Version | `node_version` | The node version to use for the workflow. | string |
| JS Package Manager | `js_package_manager` | The package manager to use (ex. yarn) | string |
| Cache Dependency Path | `cache_dependency_path` | The path to the cache dependency file. | string |
:::tip

For more details on parameters, [checkout the full predefined reusable workflow file](https://github.com/flarum/framework/blob/main/.github/workflows/REUSABLE_frontend.yml).

:::
41 changes: 20 additions & 21 deletions docs/extend/models.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,38 +251,37 @@ export default class Tag extends Model {
}
```

You must then register your new model with the store:
You must then register your new model with the store using the frontend `Store` extender in a new `extend.js` module:

```js
app.store.models.tags = Tag;
```

<!-- You must then register your new model with the store using the `Model` extender:
import Extend from 'flarum/common/extenders';

```js
export const extend = [
new Extend.Model('tags', Tag)
export default [
new Extend.Store()
.add('tags', Tag),
];
``` -->
```

### Extending Models
:::info

To add attributes and relationships to existing models, modify the model class prototype:
Remember to export the `extend` module from your entry `index.js` file:

```js
Discussion.prototype.user = Model.hasOne('user');
Discussion.prototype.posts = Model.hasMany('posts');
Discussion.prototype.slug = Model.attribute('slug');
export { default as extend } from './extend';
```

<!-- To add attributes and relationships to existing models, use the `Model` extender:
:::

```js
new Extend.Model('discussions')
.attribute('slug')
.hasOne('user')
.hasMany('posts')
``` -->
### Extending Models

To add attributes and relationships to existing models, use the `Model` extender:

```ts
new Extend.Model(Discussion)
.attribute<string>('slug')
.hasOne<User>('user')
.hasMany<Post>('posts')
```

### Saving Resources

Expand Down
51 changes: 35 additions & 16 deletions docs/extend/routes.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,37 +160,41 @@ On the backend, instead of adding your frontend route via the `Routes` extender,

Now when `yourforum.com/users` is visited, the forum frontend will be displayed. However, since the frontend doesn't yet know about the `users` route, the discussion list will still be rendered.

Flarum builds on [Mithril's routing system](https://mithril.js.org/index.html#routing), adding route names and an abstract class for pages (`common/components/Page`). To register a new route, add an object for it to `app.routes`:
Flarum builds on [Mithril's routing system](https://mithril.js.org/index.html#routing), adding route names and an abstract class for pages (`common/components/Page`).

```js
app.routes['acme.users'] = { path: '/users', component: UsersPage };
```

<!-- To register the route on the frontend, there is a `Routes` extender which works much like the backend one. Instead of a controller, however, you pass a component instance as the third argument:
To register the route on the frontend, there is a `Routes` extender which works much like the backend one. Instead of a controller, however, you pass a component instance as the third argument:

```jsx
export const extend = [
import Extend from 'flarum/common/extenders';

export default [
new Extend.Routes()
.add('/users', 'acme.users', <UsersPage />)
.add('acme.users', '/users', <UsersPage />),
];
``` -->
```

:::info

Remember to export the `extend` module from your entry `index.js` file:

```js
export { default as extend } from './extend';
```

:::

Now when `yourforum.com/users` is visited, the forum frontend will be loaded and the `UsersPage` component will be rendered in the content area. For more information on frontend pages, please see [that documentation section](frontend-pages.md).

Advanced use cases might also be interested in using [route resolvers](frontend-pages.md#route-resolvers-advanced).

### Route Parameters

Frontend routes also allow you to capture segments of the URI, but the [Mithril route syntax](https://mithril.js.org/route.html) is slightly different:
Frontend routes also allow you to capture segments of the URI:

```jsx
app.routes['acme.user'] = { path: '/user/:id', component: UserPage };
```

<!-- ```jsx
new Extend.Routes()
.add('/user/:id', 'acme.user', <UsersPage />)
``` -->
.add('acme.user', '/user/:id', <UsersPage />)
```

Route parameters will be passed into the `attrs` of the route's component. They will also be available through [`m.route.param`](https://mithril.js.org/route.html#mrouteparam)

Expand All @@ -203,6 +207,21 @@ const url = app.route('acme.user', { id: 123, foo: 'bar' });
// http://yourforum.com/users/123?foo=bar
```

The extender also allows you to define a route helper method:

```js
new Extend.Routes()
.add('acme.user', '/user/:id', <UsersPage />)
.helper('acmeUser', (user) => app.route('acme.user', { id: user.id() }))
```

This allows you to generate URLs to the route using the `acmeUser` helper method:

```js
const url = app.route.acmeUser(user);
// http://yourforum.com/users/123
```

### Linking to Other Pages

A forum wouldn't be very useful if it only had one page.
Expand Down
Loading