Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
d8f7c3d3
Unverified
Commit
d8f7c3d3
authored
Mar 13, 2023
by
Pierre-Louis
Committed by
GitHub
Mar 13, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor icon update script (#122392)
* x * docs
parent
376d8baa
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
42 deletions
+47
-42
update_icons_test.dart
dev/tools/test/update_icons_test.dart
+4
-1
update_icons.dart
dev/tools/update_icons.dart
+43
-41
No files found.
dev/tools/test/update_icons_test.dart
View file @
d8f7c3d3
...
...
@@ -17,6 +17,9 @@ Map<String, String> codepointsC = <String, String>{
'airplane'
:
'111'
,
'train'
:
'444'
,
};
Map
<
String
,
String
>
codepointsUnderscore
=
<
String
,
String
>{
'airplane__123'
:
'111'
,
};
void
main
(
)
{
group
(
'safety checks'
,
()
{
...
...
@@ -38,7 +41,7 @@ void main() {
});
test
(
'no double underscores'
,
()
{
expect
(
Icon
.
generateFlutterId
(
'abc__123'
),
'abc_123'
);
expect
(
Icon
(
codepointsUnderscore
.
entries
.
first
),
'abc_123'
);
});
test
(
'usage string is correct'
,
()
{
...
...
dev/tools/update_icons.dart
View file @
d8f7c3d3
...
...
@@ -2,8 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Regenerates
the material icons file
.
// Regenerates
a Dart file with a class containing IconData constants
.
// See https://github.com/flutter/flutter/wiki/Updating-Material-Design-Fonts-&-Icons
// Should be idempotent with:
// dart dev/tools/update_icons.dart --new-codepoints bin/cache/artifacts/material_fonts/codepoints
import
'dart:collection'
;
import
'dart:convert'
show
LineSplitter
;
...
...
@@ -18,6 +20,7 @@ const String _iconsTemplatePathOption = 'icons-template';
const
String
_newCodepointsPathOption
=
'new-codepoints'
;
const
String
_oldCodepointsPathOption
=
'old-codepoints'
;
const
String
_fontFamilyOption
=
'font-family'
;
const
String
_possibleStyleSuffixesOption
=
'style-suffixes'
;
const
String
_classNameOption
=
'class-name'
;
const
String
_enforceSafetyChecks
=
'enforce-safety-checks'
;
const
String
_dryRunOption
=
'dry-run'
;
...
...
@@ -26,6 +29,11 @@ const String _defaultIconsPath = 'packages/flutter/lib/src/material/icons.dart';
const
String
_defaultNewCodepointsPath
=
'codepoints'
;
const
String
_defaultOldCodepointsPath
=
'bin/cache/artifacts/material_fonts/codepoints'
;
const
String
_defaultFontFamily
=
'MaterialIcons'
;
const
List
<
String
>
_defaultPossibleStyleSuffixes
=
<
String
>[
'_outlined'
,
'_rounded'
,
'_sharp'
,
];
const
String
_defaultClassName
=
'Icons'
;
const
String
_defaultDemoFilePath
=
'/tmp/new_icons_demo.dart'
;
...
...
@@ -91,7 +99,7 @@ const Map<String, String> _identifierExactRewrites = <String, String>{
const
Set
<
String
>
_iconsMirroredWhenRTL
=
<
String
>{
// This list is obtained from:
// http
://google.github.io/material-design-icons/#icons-in-
rtl
// http
s://developers.google.com/fonts/docs/material_icons#which_icons_should_be_mirrored_for_
rtl
'arrow_back'
,
'arrow_back_ios'
,
'arrow_forward'
,
...
...
@@ -248,6 +256,10 @@ ArgResults _handleArguments(List<String> args) {
..
addOption
(
_fontFamilyOption
,
defaultsTo:
_defaultFontFamily
,
help:
'The font family to use for the IconData constants'
)
..
addMultiOption
(
_possibleStyleSuffixesOption
,
defaultsTo:
_defaultPossibleStyleSuffixes
,
help:
'A comma-separated list of suffixes (typically an optional '
'family + a style) e.g. _outlined, _monoline_filled'
)
..
addOption
(
_classNameOption
,
defaultsTo:
_defaultClassName
,
help:
'The containing class for all icons'
)
...
...
@@ -444,67 +456,60 @@ class Icon {
// Parse tokenPair (e.g. {"6_ft_apart_outlined": "e004"}).
Icon
(
MapEntry
<
String
,
String
>
tokenPair
,
{
this
.
fontFamily
=
_defaultFontFamily
,
this
.
possibleStyleSuffixes
=
_defaultPossibleStyleSuffixes
,
this
.
className
=
_defaultClassName
,
})
{
id
=
tokenPair
.
key
;
hexCodepoint
=
tokenPair
.
value
;
// Determine family and
htmlSuffix
.
// Determine family and
HTML class suffix for Dartdoc
.
if
(
id
.
endsWith
(
'_gm_outlined'
))
{
f
amily
=
'GM'
;
h
tmlSuffix
=
'-outlined'
;
dartdocF
amily
=
'GM'
;
dartdocH
tmlSuffix
=
'-outlined'
;
}
else
if
(
id
.
endsWith
(
'_gm_filled'
))
{
f
amily
=
'GM'
;
h
tmlSuffix
=
'-filled'
;
dartdocF
amily
=
'GM'
;
dartdocH
tmlSuffix
=
'-filled'
;
}
else
if
(
id
.
endsWith
(
'_monoline_outlined'
))
{
f
amily
=
'Monoline'
;
h
tmlSuffix
=
'-outlined'
;
dartdocF
amily
=
'Monoline'
;
dartdocH
tmlSuffix
=
'-outlined'
;
}
else
if
(
id
.
endsWith
(
'_monoline_filled'
))
{
f
amily
=
'Monoline'
;
h
tmlSuffix
=
'-filled'
;
dartdocF
amily
=
'Monoline'
;
dartdocH
tmlSuffix
=
'-filled'
;
}
else
{
f
amily
=
'material'
;
dartdocF
amily
=
'material'
;
if
(
id
.
endsWith
(
'_baseline'
))
{
id
=
_removeLast
(
id
,
'_baseline'
);
h
tmlSuffix
=
''
;
dartdocH
tmlSuffix
=
''
;
}
else
if
(
id
.
endsWith
(
'_outlined'
))
{
h
tmlSuffix
=
'-outlined'
;
dartdocH
tmlSuffix
=
'-outlined'
;
}
else
if
(
id
.
endsWith
(
'_rounded'
))
{
h
tmlSuffix
=
'-round'
;
dartdocH
tmlSuffix
=
'-round'
;
}
else
if
(
id
.
endsWith
(
'_sharp'
))
{
h
tmlSuffix
=
'-sharp'
;
dartdocH
tmlSuffix
=
'-sharp'
;
}
}
shortId
=
_generateShortId
(
id
);
flutterId
=
generateFlutterId
(
id
);
_generateShortId
(
);
_generateFlutterId
(
);
}
static
const
List
<
String
>
_idSuffixes
=
<
String
>[
'_gm_outlined'
,
'_gm_filled'
,
'_monoline_outlined'
,
'_monoline_filled'
,
'_outlined'
,
'_rounded'
,
'_sharp'
,
];
late
String
id
;
// e.g. 5g, 5g_outlined, 5g_rounded, 5g_sharp
late
String
shortId
;
// e.g. 5g
late
String
flutterId
;
// e.g. five_g, five_g_outlined, five_g_rounded, five_g_sharp
late
String
family
;
// e.g. material
late
String
hexCodepoint
;
// e.g. e547
late
String
htmlSuffix
=
''
;
// The suffix for the 'material-icons' HTML class.
late
String
dartdocFamily
;
// e.g. material
late
String
dartdocHtmlSuffix
=
''
;
// The suffix for the 'material-icons' HTML class.
String
fontFamily
;
// The IconData font family.
List
<
String
>
possibleStyleSuffixes
;
// A list of possible suffixes e.g. _outlined, _monoline_filled.
String
className
;
// The containing class.
String
get
name
=>
shortId
.
replaceAll
(
'_'
,
' '
).
trim
();
String
get
style
=>
htmlSuffix
==
''
?
''
:
' (
${h
tmlSuffix.replaceFirst('-', '')}
)'
;
String
get
style
=>
dartdocHtmlSuffix
==
''
?
''
:
' (
${dartdocH
tmlSuffix.replaceFirst('-', '')}
)'
;
String
get
dartDoc
=>
'<i class="material-icons
$
htmlSuffix
md-36">
$shortId
</i> —
$f
amily
icon named "
$name
"
$style
'
;
'<i class="material-icons
$
dartdocHtmlSuffix
md-36">
$shortId
</i> —
$dartdocF
amily
icon named "
$name
"
$style
'
;
String
get
usage
=>
'Icon(
$className
.
$flutterId
),'
;
...
...
@@ -543,23 +548,22 @@ class Icon {
return
string
.
replaceAll
(
RegExp
(
'
$toReplace
\$
'
),
''
);
}
static
String
_generateShortId
(
String
id
)
{
String
shortId
=
id
;
for
(
final
String
styleSuffix
in
_idSuffixes
)
{
/// See [shortId].
void
_generateShortId
()
{
shortId
=
id
;
for
(
final
String
styleSuffix
in
possibleStyleSuffixes
)
{
shortId
=
_removeLast
(
shortId
,
styleSuffix
);
if
(
shortId
!=
id
)
{
break
;
}
}
return
shortId
;
}
///
Given some icon's raw id, returns a valid Dart icon identifier
static
String
generateFlutterId
(
String
id
)
{
String
flutterId
=
id
;
///
See [flutterId].
void
_generateFlutterId
(
)
{
flutterId
=
id
;
// Exact identifier rewrites.
for
(
final
MapEntry
<
String
,
String
>
rewritePair
in
_identifierExactRewrites
.
entries
)
{
final
String
shortId
=
Icon
.
_generateShortId
(
id
);
if
(
shortId
==
rewritePair
.
key
)
{
flutterId
=
id
.
replaceFirst
(
rewritePair
.
key
,
...
...
@@ -579,7 +583,5 @@ class Icon {
// Prevent double underscores.
flutterId
=
flutterId
.
replaceAll
(
'__'
,
'_'
);
return
flutterId
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment