Skip to content

Commit

Permalink
Tweak standard generator
Browse files Browse the repository at this point in the history
  • Loading branch information
Pante committed May 20, 2024
1 parent 19f40f2 commit 8e1875f
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 44 deletions.
2 changes: 1 addition & 1 deletion flint/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repository: https://github.com/forus-labs/cauldron
topics: [lints]

environment:
sdk: '>=3.2.0 <4.0.0'
sdk: '>=3.4.0 <4.0.0'

dev_dependencies:
html: ^0.15.0
Expand Down
13 changes: 7 additions & 6 deletions nitrogen/lib/src/generators/assets/standard_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,16 @@ class StandardClass extends BasicClass {
ClassBuilder generate(AssetDirectory directory, {bool static = false, bool sealed = false}) =>
super.generate(directory, static: static)
..sealed = sealed
..fields.add(_contents(directory));
..methods.add(_contents(directory, static: static));


Field _contents(AssetDirectory directory) => Field((builder) => builder
..static = true
..modifier = FieldModifier.constant
..type = TypeReference((builder) => builder..symbol = 'Map'..types.addAll([refer('String'), assetType]))
Method _contents(AssetDirectory directory, {bool static = false}) => Method((builder) => builder
..static = static
..returns = TypeReference((builder) => builder..symbol = 'Map'..types.addAll([refer('String'), assetType]))
..type = MethodType.getter
..name = 'contents'
..assignment = Block.of([
..lambda = true
..body = Block.of([
const Code('{'),
for (final file in directory.children.values.whereType<AssetFile>())
Block.of([literal(file.asset.key).code, const Code(': '), files.invocation(file).code, const Code(', ')]),
Expand Down
15 changes: 8 additions & 7 deletions nitrogen/lib/src/generators/assets/theme_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,17 @@ class ThemeClass {
ClassBuilder generate(AssetDirectory directory, Class fallback) => _basic.generate(directory)
..extend = refer(fallback.name)
..modifier = ClassModifier.final$
..fields.add(_contents(directory, fallback));
..methods.add(_contents(directory, fallback));

Field _contents(AssetDirectory directory, Class fallback) => Field((builder) => builder
..static = true
..modifier = FieldModifier.final$
..type = TypeReference((builder) => builder..symbol = 'Map'..types.addAll([refer('String'), StandardClass.assetType]))
Method _contents(AssetDirectory directory, Class fallback, {bool static = false}) => Method((builder) => builder
..static = static
..returns = TypeReference((builder) => builder..symbol = 'Map'..types.addAll([refer('String'), StandardClass.assetType]))
..type = MethodType.getter
..name = 'contents'
..assignment = Block.of([
..lambda = true
..body = Block.of([
const Code('Map.unmodifiable({'),
Code('...${fallback.name}.contents,'),
Code('...${static ? fallback.name : 'const ${fallback.name}()'}.contents,'),
for (final file in directory.children.values.whereType<AssetFile>())
Block.of([literal(file.asset.key).code, const Code(': '), _basic.files.invocation(file).code, const Code(', ')]),
const Code('})'),
Expand Down
1 change: 1 addition & 0 deletions nitrogen/lib/src/generators/libraries.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ extension Libraries on Library {
// **************************************************************************
//
// ignore_for_file: type=lint
// ignore_for_file: deprecated_member_use
''');

Expand Down
7 changes: 6 additions & 1 deletion nitrogen/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ description: Type safe Flutter asset generation.
topics: [assets, generation]

version: 0.1.0
homepage: https://github.com/forus-labs/cauldron/nitrogen
homepage: https://github.com/forus-labs/cauldron/tree/master/nitrogen
repository: https://github.com/forus-labs/cauldron/

environment:
sdk: '>=3.3.0 <4.0.0'
Expand All @@ -29,3 +30,7 @@ dev_dependencies:
flutter_test:
sdk: flutter
mockito: ^5.4.2

dependency_overrides:
nitrogen_types:
path: ../nitrogen_types
4 changes: 2 additions & 2 deletions nitrogen_types/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
## 0.0.1
## 0.1.0

* TODO: Describe initial release.
Initial release.
27 changes: 2 additions & 25 deletions nitrogen_types/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,6 @@ and the Flutter guide for
[developing packages and plugins](https://flutter.dev/developing-packages).
-->

TODO: Put a short description of the package here that helps potential users
know whether this package might be useful for them.
Companion library for Nitrogen, modern, type-safe generated bindings for accessing your Flutter assets.

## Features

TODO: List what your package can do. Maybe include images, gifs, or videos.

## Getting started

TODO: List prerequisites and provide or point to information on how to
start using the package.

## Usage

TODO: Include short and useful examples for package users. Add longer examples
to `/example` folder.

```dart
const like = 'sample';
```

## Additional information

TODO: Tell users more about the package: where to find more information, how to
contribute to the package, how to file issues, what response they can expect
from the package authors, and more.
See Nitrogen for more information.
5 changes: 3 additions & 2 deletions nitrogen_types/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
name: nitrogen_types
description: Companion library for Nitrogen.
description: Companion library for Nitrogen. Provides shared types that generated bindings use.

version: 0.1.0
homepage: https://github.com/forus-labs/cauldron/nitrogen
homepage: https://github.com/forus-labs/cauldron/tree/master/nitrogen
repository: https://github.com/forus-labs/cauldron/

environment:
sdk: '>=3.3.0 <4.0.0'
Expand Down

0 comments on commit 8e1875f

Please sign in to comment.