Commit ed59ac76 authored by Brian Egan's avatar Brian Egan

Generate Icons by original name

parent 06cc595a
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:font_awesome_flutter_example/icons.dart';
import 'package:font_awesome_flutter_example/icons_map.dart';
void main() {
runApp(new FontAwesomeGalleryApp());
......
This diff is collapsed.
library font_awesome_flutter;
import 'package:flutter/widgets.dart';
class IconDataBrands extends IconData {
......
import 'dart:convert';
import 'dart:io';
void main(List<String> arguments) {
var file = new File(arguments.first);
if (!file.existsSync()) {
print('Cannot find the file "${arguments.first}".');
}
var content = file.readAsStringSync();
Map<String, dynamic> icons = json.decode(content);
Map<String, String> iconDefinitions = {};
for (String iconName in icons.keys) {
var icon = icons[iconName];
List<String> styles = icon['styles'];
if (styles.length > 1) {
if (styles.contains('regular')) {
styles.remove('regular');
iconDefinitions[iconName] = generateExampleIcon(iconName);
}
for (String _ in styles) {
iconDefinitions.putIfAbsent(
iconName,
() => generateExampleIcon(iconName),
);
}
} else {
iconDefinitions[iconName] = generateExampleIcon(iconName);
}
}
List<String> generatedOutput = [
'',
"import 'package:font_awesome_flutter/font_awesome_flutter_original.dart';",
"import 'package:font_awesome_flutter_example/example_icon.dart';",
'',
'// THIS FILE IS AUTOMATICALLY GENERATED!',
'',
'final icons = <ExampleIcon>[',
];
generatedOutput.addAll(iconDefinitions.values);
generatedOutput.add('];');
File output = new File('example/lib/icons_map.dart');
output.writeAsStringSync(generatedOutput.join('\n'));
}
String generateExampleIcon(String iconName) {
return "ExampleIcon(FontAwesomeIconsOriginal.byName('$iconName'), '$iconName'),";
}
import 'dart:convert';
import 'dart:io';
void main(List<String> arguments) {
var file = new File(arguments.first);
if (!file.existsSync()) {
print('Cannot find the file "${arguments.first}".');
}
var content = file.readAsStringSync();
Map<String, dynamic> icons = json.decode(content);
Map<String, String> iconDefinitions = {};
for (String iconName in icons.keys) {
var icon = icons[iconName];
var unicode = icon['unicode'];
List<String> styles = icon['styles'];
if (styles.length > 1) {
if (styles.contains('regular')) {
styles.remove('regular');
iconDefinitions[iconName] = generateIconDefinition(
iconName,
'regular',
unicode,
);
}
for (String _ in styles) {
iconDefinitions.putIfAbsent(
iconName,
() => generateIconDefinition(
iconName,
styles.first,
unicode,
),
);
}
} else {
iconDefinitions[iconName] = generateIconDefinition(
iconName,
styles.first,
unicode,
);
}
}
List<String> generatedOutput = [
'library font_awesome_flutter_original;',
'',
"import 'package:flutter/widgets.dart';",
"import 'package:font_awesome_flutter/font_awesome_flutter.dart';",
"import 'package:font_awesome_flutter/icon_data.dart';",
'',
'// THIS FILE IS AUTOMATICALLY GENERATED!',
'',
'class FontAwesomeIconsOriginal {',
' static const Map<String, IconData> icons = {',
];
generatedOutput.addAll(iconDefinitions.values);
generatedOutput.addAll([
"};",
"",
" static IconData byName(String originalName) {",
" final icon = icons[originalName];",
"",
" if (icon == null) {",
" throw new ArgumentError(",
" 'The following icon was not found: \$originalName',",
" );",
" }",
" return icon;",
" }",
"",
" static IconData withFallback(",
" String originalName, {"
" IconData fallback = FontAwesomeIcons.question,"
" }) =>"
" icons[originalName] ?? fallback;"
"}",
"",
]);
File output = new File('lib/font_awesome_flutter_original.dart');
output.writeAsStringSync(generatedOutput.join('\n'));
}
String generateIconDefinition(String iconName, String style, String unicode) {
style = '${style[0].toUpperCase()}${style.substring(1)}';
String iconDataSource = 'IconData$style';
return "'$iconName': $iconDataSource(0x$unicode),";
}
......@@ -12,7 +12,10 @@ curl -o /tmp/icons.json "https://raw.githubusercontent.com/FortAwesome/Font-Awes
dart ./tool/generate_font.dart /tmp/icons.json
dart ./tool/generate_example.dart /tmp/icons.json
dart ./tool/generate_icon_map.dart /tmp/icons.json
dart ./tool/generate_example_map.dart /tmp/icons.json
dartfmt -w ./lib/font_awesome_flutter.dart
dartfmt -w ./example/lib/icons.dart
dartfmt -w ./lib/font_awesome_flutter_original.dart
dartfmt -w ./example/lib/icons_map.dart
rm /tmp/icons.json
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment