4 Commits

6 changed files with 153 additions and 530 deletions

1
.gitignore vendored
View File

@@ -29,6 +29,7 @@
.pub-cache/
.pub/
build/
pubspec.lock
# Android related
**/android/**/gradle-wrapper.jar

View File

@@ -3,8 +3,7 @@ import 'dart:convert';
import 'package:build/build.dart';
import 'package:code_builder/code_builder.dart';
import 'package:dart_style/dart_style.dart';
import 'package:meta/meta.dart';
import 'package:recase/recase.dart';
import 'recase4.0.0/recase.dart';
import 'models.dart';
@@ -18,8 +17,8 @@ Builder genFromJson(BuilderOptions options) {
class GeneratorOptions {
GeneratorOptions({
@required this.fontName,
@required this.selectionJsonPath,
required this.fontName,
required this.selectionJsonPath,
});
factory GeneratorOptions.fromOptions(BuilderOptions options) {
@@ -32,12 +31,12 @@ class GeneratorOptions {
return GeneratorOptions(
fontName: config['font_name'] as String,
selectionJsonPath: config['selection_json_path'] as String,
selectionJsonPath: config['selection_json_path'],
);
}
final String fontName;
final String selectionJsonPath;
final String? selectionJsonPath;
}
class IcomoonBuilder implements Builder {
@@ -80,7 +79,7 @@ class IcomoonBuilder implements Builder {
..fields.addAll(fields));
final content = Library(
(b) => b.body..add(icomoonClass),
).accept(DartEmitter(Allocator()));
).accept(DartEmitter(allocator: Allocator()));
await buildStep.writeAsString(
buildStep.inputId.changeExtension('.dart'),

View File

@@ -1,8 +1,7 @@
import 'package:meta/meta.dart';
class SelectionModel {
SelectionModel({
@required this.icons,
required this.icons,
});
factory SelectionModel.fromJson(Map<String, dynamic> json) {
@@ -18,7 +17,7 @@ class SelectionModel {
}
class IcomoonIcon {
IcomoonIcon({@required this.properties});
IcomoonIcon({required this.properties});
factory IcomoonIcon.fromJson(Map<String, dynamic> json) {
final properties = json['properties'] as Map<String, dynamic>;
@@ -30,7 +29,7 @@ class IcomoonIcon {
}
class IconProperties {
IconProperties({@required this.name, @required this.code});
IconProperties({required this.name, required this.code});
factory IconProperties.fromJson(Map<String, dynamic> json) {
return IconProperties(

134
lib/recase4.0.0/recase.dart Normal file
View File

@@ -0,0 +1,134 @@
/// An instance of text to be re-cased.
class ReCase {
final RegExp _upperAlphaRegex = RegExp(r'[A-Z]');
final symbolSet = {' ', '.', '/', '_', '\\', '-'};
late String originalText;
late List<String> _words;
ReCase(String text) {
this.originalText = text;
this._words = _groupIntoWords(text);
}
List<String> _groupIntoWords(String text) {
StringBuffer sb = StringBuffer();
List<String> words = [];
bool isAllCaps = text.toUpperCase() == text;
for (int i = 0; i < text.length; i++) {
String char = text[i];
String? nextChar = i + 1 == text.length ? null : text[i + 1];
if (symbolSet.contains(char)) {
continue;
}
sb.write(char);
bool isEndOfWord = nextChar == null ||
(_upperAlphaRegex.hasMatch(nextChar) && !isAllCaps) ||
symbolSet.contains(nextChar);
if (isEndOfWord) {
words.add(sb.toString());
sb.clear();
}
}
return words;
}
/// camelCase
String get camelCase => _getCamelCase();
/// CONSTANT_CASE
String get constantCase => _getConstantCase();
/// Sentence case
String get sentenceCase => _getSentenceCase();
/// snake_case
String get snakeCase => _getSnakeCase();
/// dot.case
String get dotCase => _getSnakeCase(separator: '.');
/// param-case
String get paramCase => _getSnakeCase(separator: '-');
/// path/case
String get pathCase => _getSnakeCase(separator: '/');
/// PascalCase
String get pascalCase => _getPascalCase();
/// Header-Case
String get headerCase => _getPascalCase(separator: '-');
/// Title Case
String get titleCase => _getPascalCase(separator: ' ');
String _getCamelCase({String separator: ''}) {
List<String> words = this._words.map(_upperCaseFirstLetter).toList();
if (_words.isNotEmpty) {
words[0] = words[0].toLowerCase();
}
return words.join(separator);
}
String _getConstantCase({String separator: '_'}) {
List<String> words = this._words.map((word) => word.toUpperCase()).toList();
return words.join(separator);
}
String _getPascalCase({String separator: ''}) {
List<String> words = this._words.map(_upperCaseFirstLetter).toList();
return words.join(separator);
}
String _getSentenceCase({String separator: ' '}) {
List<String> words = this._words.map((word) => word.toLowerCase()).toList();
if (_words.isNotEmpty) {
words[0] = _upperCaseFirstLetter(words[0]);
}
return words.join(separator);
}
String _getSnakeCase({String separator: '_'}) {
List<String> words = this._words.map((word) => word.toLowerCase()).toList();
return words.join(separator);
}
String _upperCaseFirstLetter(String word) {
return '${word.substring(0, 1).toUpperCase()}${word.substring(1).toLowerCase()}';
}
}
extension StringReCase on String {
String get camelCase => ReCase(this).camelCase;
String get constantCase => ReCase(this).constantCase;
String get sentenceCase => ReCase(this).sentenceCase;
String get snakeCase => ReCase(this).snakeCase;
String get dotCase => ReCase(this).dotCase;
String get paramCase => ReCase(this).paramCase;
String get pathCase => ReCase(this).pathCase;
String get pascalCase => ReCase(this).pascalCase;
String get headerCase => ReCase(this).headerCase;
String get titleCase => ReCase(this).titleCase;
}

View File

@@ -1,509 +0,0 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
_fe_analyzer_shared:
dependency: transitive
description:
name: _fe_analyzer_shared
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.0"
analyzer:
dependency: transitive
description:
name: analyzer
url: "https://pub.dartlang.org"
source: hosted
version: "0.39.8"
args:
dependency: transitive
description:
name: args
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.0"
async:
dependency: transitive
description:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.1"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
build:
dependency: "direct main"
description:
name: build
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
build_config:
dependency: "direct main"
description:
name: build_config
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.2"
build_daemon:
dependency: transitive
description:
name: build_daemon
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.4"
build_resolvers:
dependency: transitive
description:
name: build_resolvers
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.9"
build_runner:
dependency: "direct dev"
description:
name: build_runner
url: "https://pub.dartlang.org"
source: hosted
version: "1.10.0"
build_runner_core:
dependency: transitive
description:
name: build_runner_core
url: "https://pub.dartlang.org"
source: hosted
version: "5.2.0"
build_test:
dependency: "direct dev"
description:
name: build_test
url: "https://pub.dartlang.org"
source: hosted
version: "0.10.12+1"
built_collection:
dependency: transitive
description:
name: built_collection
url: "https://pub.dartlang.org"
source: hosted
version: "4.3.2"
built_value:
dependency: transitive
description:
name: built_value
url: "https://pub.dartlang.org"
source: hosted
version: "7.1.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.3"
checked_yaml:
dependency: transitive
description:
name: checked_yaml
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.2"
code_builder:
dependency: "direct main"
description:
name: code_builder
url: "https://pub.dartlang.org"
source: hosted
version: "3.3.0"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.14.12"
convert:
dependency: transitive
description:
name: convert
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
coverage:
dependency: transitive
description:
name: coverage
url: "https://pub.dartlang.org"
source: hosted
version: "0.13.9"
crypto:
dependency: transitive
description:
name: crypto
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.4"
csslib:
dependency: transitive
description:
name: csslib
url: "https://pub.dartlang.org"
source: hosted
version: "0.16.1"
dart_style:
dependency: "direct main"
description:
name: dart_style
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.6"
fixnum:
dependency: transitive
description:
name: fixnum
url: "https://pub.dartlang.org"
source: hosted
version: "0.10.11"
glob:
dependency: transitive
description:
name: glob
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
graphs:
dependency: transitive
description:
name: graphs
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.0"
html:
dependency: transitive
description:
name: html
url: "https://pub.dartlang.org"
source: hosted
version: "0.14.0+3"
http:
dependency: transitive
description:
name: http
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.1"
http_multi_server:
dependency: transitive
description:
name: http_multi_server
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.0"
http_parser:
dependency: transitive
description:
name: http_parser
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.4"
io:
dependency: transitive
description:
name: io
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.4"
js:
dependency: transitive
description:
name: js
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.1+1"
json_annotation:
dependency: transitive
description:
name: json_annotation
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.1"
logging:
dependency: transitive
description:
name: logging
url: "https://pub.dartlang.org"
source: hosted
version: "0.11.4"
matcher:
dependency: transitive
description:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.6"
meta:
dependency: "direct main"
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.8"
mime:
dependency: transitive
description:
name: mime
url: "https://pub.dartlang.org"
source: hosted
version: "0.9.6+3"
multi_server_socket:
dependency: transitive
description:
name: multi_server_socket
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.2"
node_interop:
dependency: transitive
description:
name: node_interop
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.1"
node_io:
dependency: transitive
description:
name: node_io
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.1"
node_preamble:
dependency: transitive
description:
name: node_preamble
url: "https://pub.dartlang.org"
source: hosted
version: "1.4.9"
package_config:
dependency: transitive
description:
name: package_config
url: "https://pub.dartlang.org"
source: hosted
version: "1.9.3"
package_resolver:
dependency: transitive
description:
name: package_resolver
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.10"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.4"
pedantic:
dependency: transitive
description:
name: pedantic
url: "https://pub.dartlang.org"
source: hosted
version: "1.9.0"
pool:
dependency: transitive
description:
name: pool
url: "https://pub.dartlang.org"
source: hosted
version: "1.4.0"
pub_semver:
dependency: transitive
description:
name: pub_semver
url: "https://pub.dartlang.org"
source: hosted
version: "1.4.4"
pubspec_parse:
dependency: transitive
description:
name: pubspec_parse
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.5"
quiver:
dependency: transitive
description:
name: quiver
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.3"
recase:
dependency: "direct main"
description:
name: recase
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
shelf:
dependency: transitive
description:
name: shelf
url: "https://pub.dartlang.org"
source: hosted
version: "0.7.5"
shelf_packages_handler:
dependency: transitive
description:
name: shelf_packages_handler
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
shelf_static:
dependency: transitive
description:
name: shelf_static
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.8"
shelf_web_socket:
dependency: transitive
description:
name: shelf_web_socket
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.3"
source_map_stack_trace:
dependency: transitive
description:
name: source_map_stack_trace
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
source_maps:
dependency: transitive
description:
name: source_maps
url: "https://pub.dartlang.org"
source: hosted
version: "0.10.9"
source_span:
dependency: transitive
description:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.dartlang.org"
source: hosted
version: "1.9.3"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
stream_transform:
dependency: transitive
description:
name: stream_transform
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.5"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
test:
dependency: transitive
description:
name: test
url: "https://pub.dartlang.org"
source: hosted
version: "1.14.6"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.16"
test_core:
dependency: transitive
description:
name: test_core
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.6"
timing:
dependency: transitive
description:
name: timing
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.1+2"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.6"
vm_service:
dependency: transitive
description:
name: vm_service
url: "https://pub.dartlang.org"
source: hosted
version: "4.0.4"
watcher:
dependency: transitive
description:
name: watcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.9.7+15"
web_socket_channel:
dependency: transitive
description:
name: web_socket_channel
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
webkit_inspection_protocol:
dependency: transitive
description:
name: webkit_inspection_protocol
url: "https://pub.dartlang.org"
source: hosted
version: "0.7.3"
yaml:
dependency: transitive
description:
name: yaml
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.1"
sdks:
dart: ">=2.7.0 <3.0.0"

View File

@@ -1,21 +1,20 @@
name: icomoon_selection_gen
description: A code generator for flutter that reads icomoon selection.json and generate the icon classes
version: 0.0.1
version: 0.0.3
author: Gabriel Rohden
homepage:
environment:
sdk: ">=2.7.0 <3.0.0"
sdk: ">=2.17.1 <3.0.0"
dependencies:
meta: ^1.1.7
build: ^1.1.4
build_config: ^0.4.0
recase: ^2.0.1
code_builder: ^3.3.0
dart_style: ^1.0.0
build: ^2.3.0
build_config: ^1.0.0
dev_dependencies:
build_runner: ^1.5.0
build_test: ^0.10.7+3
# recase: ^4.0.0
dart_style: ^2.2.3
code_builder: ^4.1.0
build_runner: ^2.1.11
build_test: ^2.1.5