Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/luckey-elijah/inserter
Tooling for inserting String into Files given their respective strategies.
https://github.com/luckey-elijah/inserter
Last synced: 10 days ago
JSON representation
Tooling for inserting String into Files given their respective strategies.
- Host: GitHub
- URL: https://github.com/luckey-elijah/inserter
- Owner: Luckey-Elijah
- License: gpl-3.0
- Created: 2023-04-28T20:51:03.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-09-09T19:41:18.000Z (5 months ago)
- Last Synced: 2025-01-27T17:58:00.063Z (16 days ago)
- Language: Dart
- Homepage:
- Size: 61.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Inserter
Tooling for inserting `String` into `File`s given their respective strategies.
## Install
```sh
dart pub add inserter
```## Usage
```dart
Future main() async {
final replaceWithAwesome = MatcherBuilder(
// Use this to determine which line to trigger the line builder.
matcher: (file, line) async => line.contains('// REPLACE WITH AWESOME'),// The line to be written.
builder: (file, line) async => 'bool isAwesome() => true;',// Where the line will go
strategy: BuilderStrategy.replace, // also below & above
);
await Inserter.run(
files: [File('update_me.dart')],
builders: [replaceWithAwesome]
);
}
```**What changed in _`update_me.dart`_?**
```diff
void main() {
print(isAwesome());
}
- // REPLACE WITH AWESOME
+ bool isAwesome() => true;
```### Non UTF-8 encodings
Extend the `InserterBase` and provide you own `LineConverter` method:
```dart
class MyOtherInserter extends InserterBase {
MyOtherInserter({
required this.files,
required this.builders,
}) : super({
buffer: StringBuffer(), // typically, allow injecting this for testing.
readLines: (file) {
/// .... not a real method
return Stream.fromFile(file);
}
});
}
```