Skip to content

Commit

Permalink
feat(bricks): add bloc brick (#3293)
Browse files Browse the repository at this point in the history
  • Loading branch information
felangel authored Mar 26, 2022
1 parent a75a1d8 commit ae7fe06
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ coverage_badge.svg
*.lcov
nohup.out

# Mason
mason-lock.json
.mason

# Exceptions to above rules.
!.vscode/launch.json
!**/ios/**/default.mode1v3
Expand Down
3 changes: 3 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
analyzer:
exclude:
- bricks/**
17 changes: 17 additions & 0 deletions bricks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Bloc Bricks 🧱

[Mason](https://github.com/felange/mason) support for the [Bloc Library](https://bloclibrary.dev). A collection of bricks for effectively working with the bloc state management library.

## Installation

Ensure you have the [mason_cli](https://github.com/felangel/mason/packages/mason_cli) installed. Bricks can be installed from [brickhub.dev](https://brickhub.dev).

```sh
mason add <BRICK>
```

## Bricks

| Brick | Description |
| ------ | ------------------- |
| `bloc` | Generate a new Bloc |
3 changes: 3 additions & 0 deletions bricks/bloc/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 0.1.0

- feat: initial release with support for basic bloc generation
21 changes: 21 additions & 0 deletions bricks/bloc/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Felix Angelov

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
26 changes: 26 additions & 0 deletions bricks/bloc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# bloc

Generate a new Bloc in [Dart][1]. Built for the [bloc state management library][2].

## Usage 🚀

```sh
mason make bloc --name counter
```

## Variables ✨

| Variable | Description | Default | Type |
| -------- | -------------------------- | --------- | -------- |
| `name` | The name of the bloc class | `counter` | `string` |

## Output 📦

```sh
├── counter_bloc.dart
├── counter_event.dart
└── counter_state.dart
```

[1]: https://dart.dev
[2]: https://github.com/felangel/bloc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:bloc/bloc.dart';

part '{{#snakeCase}}{{name}}{{/snakeCase}}_event.dart';
part '{{#snakeCase}}{{name}}{{/snakeCase}}_state.dart';

class {{#pascalCase}}{{name}}{{/pascalCase}}Bloc extends Bloc<{{#pascalCase}}{{name}}{{/pascalCase}}Event, {{#pascalCase}}{{name}}{{/pascalCase}}State> {
{{#pascalCase}}{{name}}{{/pascalCase}}Bloc() : super(const {{#pascalCase}}{{name}}{{/pascalCase}}State()) {
on<{{#pascalCase}}{{name}}{{/pascalCase}}Event>((event, emit) {
// TODO: implement event handler
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
part of '{{#snakeCase}}{{name}}{{/snakeCase}}_bloc.dart';

abstract class {{#pascalCase}}{{name}}{{/pascalCase}}Event {
const {{#pascalCase}}{{name}}{{/pascalCase}}Event();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
part of '{{#snakeCase}}{{name}}{{/snakeCase}}_bloc.dart';

class {{#pascalCase}}{{name}}{{/pascalCase}}State {
const {{#pascalCase}}{{name}}{{/pascalCase}}State();
}
13 changes: 13 additions & 0 deletions bricks/bloc/brick.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: bloc
description: Generate a new Bloc in Dart | Built for the bloc state management library.
version: 0.1.0

environment:
mason: ">=0.1.0-dev <0.1.0"

vars:
name:
type: string
description: The name of the bloc class.
default: counter
prompt: Please enter the bloc name.
3 changes: 3 additions & 0 deletions bricks/mason.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bricks:
bloc:
path: ./bloc

0 comments on commit ae7fe06

Please sign in to comment.