Skip to content

Commit

Permalink
feat: Added Widget system.
Browse files Browse the repository at this point in the history
  • Loading branch information
mathrunet committed Feb 2, 2023
1 parent cde8c95 commit 8bf49ff
Show file tree
Hide file tree
Showing 8 changed files with 257 additions and 7 deletions.
6 changes: 6 additions & 0 deletions packages/katana_cli/lib/command/code/code.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ part 'value.dart';
part 'redirect_query.dart';
part 'boot.dart';
part 'prefs.dart';
part 'widget.dart';
part 'stateless.dart';
part 'stateful.dart';

class CodeCliCommand extends CliCommandGroup {
const CodeCliCommand();
Expand All @@ -41,5 +44,8 @@ class CodeCliCommand extends CliCommandGroup {
"value": CodeValueCliCommand(),
"redirect": CodeRedirectQueryCliCommand(),
"prefs": CodePrefsCliCommand(),
"widget": CodeWidgetCliCommand(),
"stateless": CodeStatelessCliCommand(),
"stateful": CodeStatefulCliCommand(),
};
}
2 changes: 1 addition & 1 deletion packages/katana_cli/lib/command/code/redirect_query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class CodeRedirectQueryCliCommand extends CliCodeCommand {
final path = context.args.get(2, "");
if (path.isEmpty) {
error(
"[path] is not specified. Please enter [path] according to the following command.\r\nkatana code page [path]\r\n",
"[path] is not specified. Please enter [path] according to the following command.\r\nkatana code redirect [path]\r\n",
);
return;
}
Expand Down
83 changes: 83 additions & 0 deletions packages/katana_cli/lib/command/code/stateful.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
part of katana_cli.code;

/// Create a base class to create a StatefulWidget.
///
/// StatefulWidgetを作成するベースクラスを作成します。
class CodeStatefulCliCommand extends CliCodeCommand {
/// Create a base class to create a StatefulWidget.
///
/// StatefulWidgetを作成するベースクラスを作成します。
const CodeStatefulCliCommand();

@override
String get name => "stateful";

@override
String get prefix => "stateful";

@override
String get directory => "lib/widgets";

@override
String get description =>
"Create a StatefulWidget in `$directory/(filepath).dart`. StatefulWidgetを`$directory/(filepath).dart`に作成します。";

@override
Future<void> exec(ExecContext context) async {
final path = context.args.get(2, "");
if (path.isEmpty) {
error(
"[path] is not specified. Please enter [path] according to the following command.\r\nkatana code stateful [path]\r\n",
);
return;
}
label("Create a StatefulWidget class in `$directory/$path.dart`.");
await generateDartCode("$directory/$path");
}

@override
String import(String path, String baseName, String className) {
return """
// ignore: unused_import, unnecessary_import
import 'package:flutter/material.dart';
// ignore: unused_import, unnecessary_import
import 'package:masamune/masamune.dart';
// ignore: unused_import, unnecessary_import
import '/main.dart';
""";
}

@override
String header(String path, String baseName, String className) {
return """
""";
}

@override
String body(String path, String baseName, String className) {
return """
/// StatefulWidget.
@immutable
class ${className}Widget extends StatefulWidget {
const ${className}Widget({
super.key,
// TODO: Set parameters for the widget.
\${1}
});
@override
State<StatefulWidget> createState() => _${className}State();
}
class _${className}State extends State<${className}Widget> {
@override
Widget build(BuildContext context) {
// Describes the structure of the widget.
// TODO: Implement the view.
return \${2:Empty()};
}
}
""";
}
}
78 changes: 78 additions & 0 deletions packages/katana_cli/lib/command/code/stateless.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
part of katana_cli.code;

/// Create a base class to create a StatelessWidget.
///
/// StatelessWidgetを作成するベースクラスを作成します。
class CodeStatelessCliCommand extends CliCodeCommand {
/// Create a base class to create a StatelessWidget.
///
/// StatelessWidgetを作成するベースクラスを作成します。
const CodeStatelessCliCommand();

@override
String get name => "stateless";

@override
String get prefix => "stateless";

@override
String get directory => "lib/widgets";

@override
String get description =>
"Create a StatelessWidget in `$directory/(filepath).dart`. StatelessWidgetを`$directory/(filepath).dart`に作成します。";

@override
Future<void> exec(ExecContext context) async {
final path = context.args.get(2, "");
if (path.isEmpty) {
error(
"[path] is not specified. Please enter [path] according to the following command.\r\nkatana code stateless [path]\r\n",
);
return;
}
label("Create a StatelessWidget class in `$directory/$path.dart`.");
await generateDartCode("$directory/$path");
}

@override
String import(String path, String baseName, String className) {
return """
// ignore: unused_import, unnecessary_import
import 'package:flutter/material.dart';
// ignore: unused_import, unnecessary_import
import 'package:masamune/masamune.dart';
// ignore: unused_import, unnecessary_import
import '/main.dart';
""";
}

@override
String header(String path, String baseName, String className) {
return """
""";
}

@override
String body(String path, String baseName, String className) {
return """
/// StatelessWidget.
@immutable
class ${className}Widget extends StatelessWidget {
const ${className}Widget({
super.key,
// TODO: Set parameters for the widget.
\${1}
});
@override
Widget build(BuildContext context) {
// Describes the structure of the widget.
// TODO: Implement the view.
return \${2:Empty()};
}
}
""";
}
}
2 changes: 1 addition & 1 deletion packages/katana_cli/lib/command/code/tmp/basic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class CodeTmpBasicCliCommand extends CliCodeCommand {
final path = context.args.get(3, "");
if (path.isEmpty) {
error(
"[path] is not specified. Please enter [path] according to the following command.\r\nkatana code tmp form [path]\r\n",
"[path] is not specified. Please enter [path] according to the following command.\r\nkatana code tmp basic [path]\r\n",
);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/katana_cli/lib/command/code/value.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class CodeValueCliCommand extends CliCodeCommand {
final path = context.args.get(2, "");
if (path.isEmpty) {
error(
"[path] is not specified. Please enter [path] according to the following command.\r\nkatana code page [path]\r\n",
"[path] is not specified. Please enter [path] according to the following command.\r\nkatana code value [path]\r\n",
);
return;
}
Expand Down
83 changes: 83 additions & 0 deletions packages/katana_cli/lib/command/code/widget.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
part of katana_cli.code;

/// Create a base class to create a ScopedWidget.
///
/// ScopedWidgetを作成するベースクラスを作成します。
class CodeWidgetCliCommand extends CliCodeCommand {
/// Create a base class to create a ScopedWidget.
///
/// ScopedWidgetを作成するベースクラスを作成します。
const CodeWidgetCliCommand();

@override
String get name => "widget";

@override
String get prefix => "widget";

@override
String get directory => "lib/widgets";

@override
String get description =>
"Create a ScopedWidget in `$directory/(filepath).dart`. ScopedWidgetを`$directory/(filepath).dart`に作成します。";

@override
Future<void> exec(ExecContext context) async {
final path = context.args.get(2, "");
if (path.isEmpty) {
error(
"[path] is not specified. Please enter [path] according to the following command.\r\nkatana code widget [path]\r\n",
);
return;
}
label("Create a ScopedWidget class in `$directory/$path.dart`.");
await generateDartCode("$directory/$path");
}

@override
String import(String path, String baseName, String className) {
return """
// ignore: unused_import, unnecessary_import
import 'package:flutter/material.dart';
// ignore: unused_import, unnecessary_import
import 'package:masamune/masamune.dart';
// ignore: unused_import, unnecessary_import
import '/main.dart';
""";
}

@override
String header(String path, String baseName, String className) {
return """
""";
}

@override
String body(String path, String baseName, String className) {
return """
/// ScopedWidget.
@immutable
class ${className}Widget extends ScopedWidget {
const ${className}Widget({
super.key,
// TODO: Set parameters for the widget.
\${1}
});
@override
Widget build(BuildContext context, WidgetRef ref) {
// Describes the process of loading
// and defining variables required for the widget.
// TODO: Implement the variable loading process.
\${2}
// Describes the structure of the widget.
// TODO: Implement the view.
return \${3:Empty()};
}
}
""";
}
}
8 changes: 4 additions & 4 deletions packages/katana_cli/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ packages:
dependency: "direct main"
description:
name: image
sha256: "1f9ecf99b08c92dedb699de1d28549f5d79b4423b48cf3f95d6968156db5dd67"
sha256: "3686865febd85c57a632d87a0fb1f0a8a9ef602fdb68d909c3e9aa29ec70fd24"
url: "https://pub.dev"
source: hosted
version: "4.0.12"
version: "4.0.13"
import_sorter:
dependency: "direct dev"
description:
Expand Down Expand Up @@ -157,10 +157,10 @@ packages:
dependency: transitive
description:
name: meta
sha256: "6c268b42ed578a53088d834796959e4a1814b5e9e164f147f580a386e5decf42"
sha256: "12307e7f0605ce3da64cf0db90e5fcab0869f3ca03f76be6bb2991ce0a55e82b"
url: "https://pub.dev"
source: hosted
version: "1.8.0"
version: "1.9.0"
path:
dependency: transitive
description:
Expand Down

0 comments on commit 8bf49ff

Please sign in to comment.