flr 1.1.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +1 -1
- data/lib/flr/checker.rb +11 -8
- data/lib/flr/command.rb +120 -65
- data/lib/flr/constant.rb +5 -1
- data/lib/flr/util/asset_util.rb +103 -32
- data/lib/flr/util/code_util.rb +65 -31
- data/lib/flr/util/file_util.rb +72 -17
- data/lib/flr/version.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf8e0a359356f8ea371d681026c47f7e4e649d144a0c1cda4acc051f07404cbd
|
4
|
+
data.tar.gz: fbf661e81c360e715695c2b9906ccb0328ed07163a208aab3b1d50ef024a5423
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6263917c0732cc4b6e772fe024267b8854d9b0f99c6868f2326caa6986dc68015db43f5e24be2bf0f06a3478d84de900099289c6b6ae2780542eb492d50ff93a
|
7
|
+
data.tar.gz: 87218e5d6f9d85fbce53246077b8a2e74e7e9df84fc45e221635b2b0c5980373177530b5bb6f4996d8cae1576f3ffc2d3beb741c49a99ee18f2a4c081f0444a8
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## 2.0.0
|
2
|
+
|
3
|
+
- New asset generation algorithm to support all kinds of standard or nonstandard image/text resource structure
|
4
|
+
- New asset-id generation algorithm to support assets with the same filename but different path
|
5
|
+
- New recommended flutter resource structure
|
6
|
+
|
1
7
|
## 1.1.0
|
2
8
|
|
3
9
|
- Improve generate-capability to support nonstandard image resource structure
|
data/Gemfile.lock
CHANGED
data/lib/flr/checker.rb
CHANGED
@@ -12,7 +12,7 @@ module Flr
|
|
12
12
|
#
|
13
13
|
# === Examples
|
14
14
|
#
|
15
|
-
# flutter_dir = "
|
15
|
+
# flutter_dir = "~path/to/flutter_r_demo"
|
16
16
|
# Checker.check_pubspec_file_is_existed(flutter_dir)
|
17
17
|
#
|
18
18
|
def self.check_pubspec_file_is_existed(flutter_dir)
|
@@ -63,7 +63,7 @@ module Flr
|
|
63
63
|
return true
|
64
64
|
end
|
65
65
|
|
66
|
-
# check_flr_assets_is_legal(flr_config) -> resource_dir_result_tuple
|
66
|
+
# check_flr_assets_is_legal(flutter_dir, flr_config) -> resource_dir_result_tuple
|
67
67
|
#
|
68
68
|
# 检测当前flr配置信息中的assets配置是否合法
|
69
69
|
# 若合法,返回资源目录结果三元组 resource_dir_result_triplet
|
@@ -88,11 +88,12 @@ module Flr
|
|
88
88
|
# 判断flr的assets配置合法的标准是:assets配置的resource_dir数组中的legal_resource_dir数量大于0。
|
89
89
|
#
|
90
90
|
# === Examples
|
91
|
-
#
|
92
|
-
#
|
93
|
-
#
|
91
|
+
# flutter_dir = "~/path/to/flutter_r_demo"
|
92
|
+
# assets_legal_resource_dir_array = ["~/path/to/flutter_r_demo/lib/assets/images", "~/path/to/flutter_r_demo/lib/assets/texts"]
|
93
|
+
# fonts_legal_resource_dir_array = ["~/path/to/flutter_r_demo/lib/assets/fonts"]
|
94
|
+
# illegal_resource_dir_array = ["~/path/to/flutter_r_demo/to/non-existed_folder"]
|
94
95
|
#
|
95
|
-
def self.check_flr_assets_is_legal(flr_config)
|
96
|
+
def self.check_flr_assets_is_legal(flutter_dir, flr_config)
|
96
97
|
core_version = flr_config["core_version"]
|
97
98
|
dartfmt_line_length = flr_config["dartfmt_line_length"]
|
98
99
|
assets_resource_dir_array = flr_config["assets"]
|
@@ -119,7 +120,8 @@ module Flr
|
|
119
120
|
fonts_legal_resource_dir_array = []
|
120
121
|
illegal_resource_dir_array = []
|
121
122
|
|
122
|
-
assets_resource_dir_array.each do |
|
123
|
+
assets_resource_dir_array.each do |relative_resource_dir|
|
124
|
+
resource_dir = flutter_dir + "/" + relative_resource_dir
|
123
125
|
if File.exist?(resource_dir) == true
|
124
126
|
assets_legal_resource_dir_array.push(resource_dir)
|
125
127
|
else
|
@@ -127,7 +129,8 @@ module Flr
|
|
127
129
|
end
|
128
130
|
end
|
129
131
|
|
130
|
-
fonts_resource_dir_array.each do |
|
132
|
+
fonts_resource_dir_array.each do |relative_resource_dir|
|
133
|
+
resource_dir = flutter_dir + "/" + relative_resource_dir
|
131
134
|
if File.exist?(resource_dir) == true
|
132
135
|
fonts_legal_resource_dir_array.push(resource_dir)
|
133
136
|
else
|
data/lib/flr/command.rb
CHANGED
@@ -43,46 +43,46 @@ Flr recommends the following flutter resource structure:
|
|
43
43
|
│ ├── ..
|
44
44
|
├── lib
|
45
45
|
│ ├── assets
|
46
|
-
│ │ ├──
|
47
|
-
│ │ │ ├── \#{
|
48
|
-
│ │ │ ├── \#{
|
49
|
-
│ │ │ │ ├── \#{
|
50
|
-
│ │ │ │
|
51
|
-
│ │
|
52
|
-
│ │ │ ├──
|
53
|
-
│ │ │ ├── home_badge.svg
|
54
|
-
│ │ │ ├── 3.0x #{"// image resources root directory of a 3.0x-ratio-variant".red}
|
46
|
+
│ │ ├── images #{"// image resource directory of all modules".red}
|
47
|
+
│ │ │ ├── \#{module} #{"// image resource directory of a module".red}
|
48
|
+
│ │ │ │ ├── \#{main_image_asset}
|
49
|
+
│ │ │ │ ├── \#{variant-dir} #{"// image resource directory of a variant".red}
|
50
|
+
│ │ │ │ │ ├── \#{image_asset_variant}
|
51
|
+
│ │ │ │
|
52
|
+
│ │ │ ├── home #{"// image resource directory of home module".red}
|
53
|
+
│ │ │ │ ├── home_badge.svg
|
55
54
|
│ │ │ │ ├── home_icon.png
|
56
|
-
│ │ │ │
|
57
|
-
│ │ ├──
|
55
|
+
│ │ │ │ ├── 3.0x #{"// image resource directory of a 3.0x-ratio-variant".red}
|
56
|
+
│ │ │ │ │ ├── home_icon.png
|
57
|
+
│ │ │ │
|
58
|
+
│ │ ├── texts #{"// text resource directory".red}
|
58
59
|
│ │ │ │ #{"// (you can also break it down further by module)".red}
|
59
60
|
│ │ │ └── test.json
|
60
61
|
│ │ │ └── test.yaml
|
61
|
-
│ │ │ │
|
62
|
-
│ │ ├── fonts #{"// font
|
63
|
-
│ │ │ ├── \#{font-family} #{"// font
|
62
|
+
│ │ │ │
|
63
|
+
│ │ ├── fonts #{"// font resource directory of all font-families".red}
|
64
|
+
│ │ │ ├── \#{font-family} #{"// font resource directory of a font-family".red}
|
64
65
|
│ │ │ │ ├── \#{font-family}-\#{font_weight_or_style}.ttf
|
65
|
-
│ │ │ │
|
66
|
-
│ │ │ ├── Amiri #{"// font
|
66
|
+
│ │ │ │
|
67
|
+
│ │ │ ├── Amiri #{"// font resource directory of Amiri font-family".red}
|
67
68
|
│ │ │ │ ├── Amiri-Regular.ttf
|
68
69
|
│ │ │ │ ├── Amiri-Bold.ttf
|
69
70
|
│ │ │ │ ├── Amiri-Italic.ttf
|
70
71
|
│ │ │ │ ├── Amiri-BoldItalic.ttf
|
71
72
|
│ ├── ..
|
72
|
-
|
73
|
+
|
73
74
|
#{"[*]: Then config the resource directories that need to be scanned as follows:".tips_style}
|
74
75
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
#{"fonts
|
85
|
-
#{"- lib/assets/fonts".tips_style}
|
76
|
+
#{"flr:".tips_style}
|
77
|
+
#{"core_version: #{Flr::CORE_VERSION}".tips_style}
|
78
|
+
#{"dartfmt_line_length: #{Flr::DARTFMT_LINE_LENGTH}".tips_style}
|
79
|
+
#{"# config the image and text resource directories that need to be scanned".tips_style}
|
80
|
+
#{"assets:".tips_style}
|
81
|
+
#{"- lib/assets/images".tips_style}
|
82
|
+
#{"- lib/assets/texts".tips_style}
|
83
|
+
#{"# config the font resource directories that need to be scanned".tips_style}
|
84
|
+
#{"fonts:".tips_style}
|
85
|
+
#{"- lib/assets/fonts".tips_style}
|
86
86
|
|
87
87
|
MESSAGE
|
88
88
|
|
@@ -145,7 +145,9 @@ Flr recommends the following flutter resource structure:
|
|
145
145
|
|
146
146
|
dependencies_config = pubspec_config["dependencies"]
|
147
147
|
|
148
|
-
# 添加
|
148
|
+
# 添加flr_config到pubspec.yaml:检测当前是否存在flr_config;若不存在,则添加flr_config;若存在,则按照以下步骤处理:
|
149
|
+
# - 读取dartfmt_line_length选项、assets选项和fonts选项的值(这些选项值若存在,则应用于新建的flr_config;需要注意,使用前需要判断选项值是否合法:dartfmt_line_length选项值 >=80;assets选项和fonts选项的值为数组)
|
150
|
+
# - 新建flr_config,然后使用旧值或者默认值设置各个选项
|
149
151
|
#
|
150
152
|
# flr_config: Flr的配置信息
|
151
153
|
# ```yaml
|
@@ -155,7 +157,33 @@ Flr recommends the following flutter resource structure:
|
|
155
157
|
# assets: []
|
156
158
|
# fonts: []
|
157
159
|
# ```
|
158
|
-
|
160
|
+
|
161
|
+
dartfmt_line_length = Flr::DARTFMT_LINE_LENGTH
|
162
|
+
asset_resource_dir_array = []
|
163
|
+
font_resource_dir_array = []
|
164
|
+
|
165
|
+
old_flr_config = pubspec_config["flr"]
|
166
|
+
if old_flr_config.is_a?(Hash)
|
167
|
+
dartfmt_line_length = old_flr_config["dartfmt_line_length"]
|
168
|
+
if dartfmt_line_length.nil? or dartfmt_line_length.is_a?(Integer) == false
|
169
|
+
dartfmt_line_length = Flr::DARTFMT_LINE_LENGTH
|
170
|
+
end
|
171
|
+
if dartfmt_line_length < Flr::DARTFMT_LINE_LENGTH
|
172
|
+
dartfmt_line_length = Flr::DARTFMT_LINE_LENGTH
|
173
|
+
end
|
174
|
+
|
175
|
+
asset_resource_dir_array = old_flr_config["assets"]
|
176
|
+
if asset_resource_dir_array.nil? or asset_resource_dir_array.is_a?(Array) == false
|
177
|
+
asset_resource_dir_array = []
|
178
|
+
end
|
179
|
+
|
180
|
+
font_resource_dir_array = old_flr_config["fonts"]
|
181
|
+
if font_resource_dir_array.nil? or font_resource_dir_array.is_a?(Array) == false
|
182
|
+
font_resource_dir_array = []
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
flr_config = Hash["core_version" => "#{Flr::CORE_VERSION}", "dartfmt_line_length" => dartfmt_line_length, "assets" => asset_resource_dir_array, "fonts" => font_resource_dir_array]
|
159
187
|
pubspec_config["flr"] = flr_config
|
160
188
|
|
161
189
|
# 添加 r_dart_library(https://github.com/YK-Unit/r_dart_library)的依赖声明
|
@@ -258,7 +286,7 @@ Flr recommends the following flutter resource structure:
|
|
258
286
|
|
259
287
|
flr_config = pubspec_config["flr"]
|
260
288
|
|
261
|
-
resource_dir_result_tuple = Checker.check_flr_assets_is_legal(flr_config)
|
289
|
+
resource_dir_result_tuple = Checker.check_flr_assets_is_legal(flutter_project_root_dir, flr_config)
|
262
290
|
|
263
291
|
rescue Exception => e
|
264
292
|
puts(e.message)
|
@@ -271,7 +299,10 @@ Flr recommends the following flutter resource structure:
|
|
271
299
|
|
272
300
|
# ----- Step-2 Begin -----
|
273
301
|
# 进行核心逻辑版本检测:
|
274
|
-
# 检测
|
302
|
+
# 检测flr_config中的core_version和当前工具的core_version是否一致;若不一致,则按照以下规则处理:
|
303
|
+
# - 更新flr_config中的core_version的值为当前工具的core_version;
|
304
|
+
# - 生成“核心逻辑版本不一致”的警告日志,存放到警告日志数组。
|
305
|
+
#
|
275
306
|
|
276
307
|
flr_core_version = flr_config["core_version"]
|
277
308
|
|
@@ -280,10 +311,12 @@ Flr recommends the following flutter resource structure:
|
|
280
311
|
end
|
281
312
|
|
282
313
|
if flr_core_version != Flr::CORE_VERSION
|
314
|
+
flr_config["core_version"] = Flr::CORE_VERSION
|
315
|
+
|
283
316
|
message = <<-MESSAGE
|
284
|
-
#{"[!]: warning,
|
285
|
-
#{"[*]: to fix it, you
|
286
|
-
#{"[*]:
|
317
|
+
#{"[!]: warning, some team members may be using Flr tool with core_version #{flr_core_version}, while you are using Flr tool with core_version #{Flr::CORE_VERSION}".warning_style}
|
318
|
+
#{"[*]: to fix it, you and your team members should use the Flr tool with same core_version".tips_style}
|
319
|
+
#{"[*]: \"core_version\" is the core logic version of Flr tool, you can run \"flr version\" to get it".tips_style}
|
287
320
|
|
288
321
|
MESSAGE
|
289
322
|
|
@@ -319,16 +352,18 @@ Flr recommends the following flutter resource structure:
|
|
319
352
|
puts("scan assets now ...")
|
320
353
|
|
321
354
|
# ----- Step-4 Begin -----
|
322
|
-
# 扫描assets_legal_resource_dir数组中的legal_resource_dir
|
355
|
+
# 扫描assets_legal_resource_dir数组中的legal_resource_dir,输出有序的image_asset数组、non_svg_image_asset数组、svg_image_asset数组、illegal_image_file数组:
|
323
356
|
# - 创建image_asset数组、illegal_image_file数组;
|
324
357
|
# - 遍历assets_legal_resource_dir数组,按照如下处理每个资源目录:
|
325
|
-
# -
|
358
|
+
# - 扫描当前资源目录和其所有层级的子目录,查找所有image_file;
|
326
359
|
# - 根据legal_resource_file的标准,筛选查找结果生成legal_image_file子数组和illegal_image_file子数组;illegal_image_file子数组合并到illegal_image_file数组;
|
327
360
|
# - 根据image_asset的定义,遍历legal_image_file子数组,生成image_asset子数;组;image_asset子数组合并到image_asset数组。
|
328
361
|
# - 对image_asset数组做去重处理;
|
329
362
|
# - 按照字典顺序对image_asset数组做升序排列(一般使用开发语言提供的默认的sort算法即可);
|
330
|
-
# -
|
331
|
-
#
|
363
|
+
# - 按照SVG分类,从image_asset数组筛选得到有序的non_svg_image_asset数组和svg_image_asset数组:
|
364
|
+
# - 按照SVG分类,从image_asset数组筛选得到non_svg_image_asset数组和svg_image_asset数组;
|
365
|
+
# - 按照字典顺序对non_svg_image_asset数组和svg_image_asset数组做升序排列(一般使用开发语言提供的默认的sort算法即可);
|
366
|
+
# - 输出有序的image_asset数组、non_svg_image_asset数组、svg_image_asset数组、illegal_image_file数组。
|
332
367
|
|
333
368
|
image_asset_array = []
|
334
369
|
illegal_image_file_array = []
|
@@ -340,13 +375,28 @@ Flr recommends the following flutter resource structure:
|
|
340
375
|
|
341
376
|
illegal_image_file_array += illegal_image_file_subarray
|
342
377
|
|
343
|
-
image_asset_subarray = AssetUtil.generate_image_assets(
|
378
|
+
image_asset_subarray = AssetUtil.generate_image_assets(flutter_project_root_dir, package_name, legal_image_file_subarray)
|
344
379
|
image_asset_array += image_asset_subarray
|
345
380
|
end
|
346
381
|
|
347
382
|
image_asset_array.uniq!
|
348
383
|
image_asset_array.sort!
|
349
384
|
|
385
|
+
non_svg_image_asset_array = []
|
386
|
+
svg_image_asset_array = []
|
387
|
+
|
388
|
+
image_asset_array.each do |image_asset|
|
389
|
+
if FileUtil.is_svg_image_resource_file?(image_asset)
|
390
|
+
svg_image_asset_array.push(image_asset)
|
391
|
+
else
|
392
|
+
non_svg_image_asset_array.push(image_asset)
|
393
|
+
end
|
394
|
+
|
395
|
+
end
|
396
|
+
|
397
|
+
non_svg_image_asset_array.sort!
|
398
|
+
svg_image_asset_array.sort!
|
399
|
+
|
350
400
|
# ----- Step-4 End -----
|
351
401
|
|
352
402
|
# ----- Step-5 Begin -----
|
@@ -371,7 +421,7 @@ Flr recommends the following flutter resource structure:
|
|
371
421
|
|
372
422
|
illegal_text_file_array += illegal_text_file_subarray
|
373
423
|
|
374
|
-
text_asset_subarray = AssetUtil.generate_text_assets(
|
424
|
+
text_asset_subarray = AssetUtil.generate_text_assets(flutter_project_root_dir, package_name, legal_text_file_subarray)
|
375
425
|
text_asset_array += text_asset_subarray
|
376
426
|
end
|
377
427
|
|
@@ -415,7 +465,7 @@ Flr recommends the following flutter resource structure:
|
|
415
465
|
next
|
416
466
|
end
|
417
467
|
|
418
|
-
font_asset_config_array = AssetUtil.generate_font_asset_configs(
|
468
|
+
font_asset_config_array = AssetUtil.generate_font_asset_configs(flutter_project_root_dir, package_name, legal_font_file_array)
|
419
469
|
font_asset_config_array.sort!{|a, b| a["asset"] <=> b["asset"]}
|
420
470
|
|
421
471
|
font_family_config = Hash["family" => font_family_name , "fonts" => font_asset_config_array]
|
@@ -475,26 +525,31 @@ Flr recommends the following flutter resource structure:
|
|
475
525
|
puts("specify scanned assets in pubspec.yaml done !!!")
|
476
526
|
|
477
527
|
# ----- Step-9 Begin -----
|
478
|
-
#
|
479
|
-
#
|
480
|
-
#
|
528
|
+
# 分别遍历non_svg_image_asset数组、svg_image_asset数组、text_asset数组,
|
529
|
+
# 根据asset_id生成算法,分别输出non_svg_image_asset_id字典、svg_image_asset_id 字典、text_asset_id字典。
|
530
|
+
# 字典的key为asset,value为asset_id。
|
481
531
|
#
|
532
|
+
non_svg_image_asset_id_dict = Hash[]
|
533
|
+
svg_image_asset_id_dict = Hash[]
|
534
|
+
text_asset_id_dict = Hash[]
|
535
|
+
|
536
|
+
non_svg_image_asset_array.each do |asset|
|
537
|
+
used_asset_id_array = non_svg_image_asset_id_dict.values
|
538
|
+
asset_id = CodeUtil.generate_asset_id(asset, used_asset_id_array, Flr::PRIOR_NON_SVG_IMAGE_FILE_TYPE)
|
539
|
+
non_svg_image_asset_id_dict[asset] = asset_id
|
540
|
+
end
|
482
541
|
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
file_extname = File.extname(image_asset).downcase
|
488
|
-
|
489
|
-
if file_extname.eql?(".svg")
|
490
|
-
svg_image_asset_array.push(image_asset)
|
491
|
-
else
|
492
|
-
non_svg_image_asset_array.push(image_asset)
|
493
|
-
end
|
542
|
+
svg_image_asset_array.each do |asset|
|
543
|
+
used_asset_id_array = svg_image_asset_id_dict.values
|
544
|
+
asset_id = CodeUtil.generate_asset_id(asset, used_asset_id_array, Flr::PRIOR_SVG_IMAGE_FILE_TYPE)
|
545
|
+
svg_image_asset_id_dict[asset] = asset_id
|
494
546
|
end
|
495
547
|
|
496
|
-
|
497
|
-
|
548
|
+
text_asset_array.each do |asset|
|
549
|
+
used_asset_id_array = text_asset_id_dict.values
|
550
|
+
asset_id = CodeUtil.generate_asset_id(asset, used_asset_id_array, Flr::PRIOR_TEXT_FILE_TYPE)
|
551
|
+
text_asset_id_dict[asset] = asset_id
|
552
|
+
end
|
498
553
|
|
499
554
|
# ----- Step-9 End -----
|
500
555
|
|
@@ -533,7 +588,7 @@ Flr recommends the following flutter resource structure:
|
|
533
588
|
#
|
534
589
|
|
535
590
|
r_dart_file.puts("\n")
|
536
|
-
g__R_Image_AssetResource_class_code = CodeUtil.generate__R_Image_AssetResource_class(non_svg_image_asset_array, package_name)
|
591
|
+
g__R_Image_AssetResource_class_code = CodeUtil.generate__R_Image_AssetResource_class(non_svg_image_asset_array, non_svg_image_asset_id_dict, package_name)
|
537
592
|
r_dart_file.puts(g__R_Image_AssetResource_class_code)
|
538
593
|
|
539
594
|
# ----- Step-13 End -----
|
@@ -543,7 +598,7 @@ Flr recommends the following flutter resource structure:
|
|
543
598
|
#
|
544
599
|
|
545
600
|
r_dart_file.puts("\n")
|
546
|
-
g__R_Svg_AssetResource_class_code = CodeUtil.generate__R_Svg_AssetResource_class(svg_image_asset_array, package_name)
|
601
|
+
g__R_Svg_AssetResource_class_code = CodeUtil.generate__R_Svg_AssetResource_class(svg_image_asset_array, svg_image_asset_id_dict, package_name)
|
547
602
|
r_dart_file.puts(g__R_Svg_AssetResource_class_code)
|
548
603
|
|
549
604
|
# ----- Step-14 End -----
|
@@ -553,7 +608,7 @@ Flr recommends the following flutter resource structure:
|
|
553
608
|
#
|
554
609
|
|
555
610
|
r_dart_file.puts("\n")
|
556
|
-
g__R_Text_AssetResource_class_code = CodeUtil.generate__R_Text_AssetResource_class(text_asset_array, package_name)
|
611
|
+
g__R_Text_AssetResource_class_code = CodeUtil.generate__R_Text_AssetResource_class(text_asset_array, text_asset_id_dict, package_name)
|
557
612
|
r_dart_file.puts(g__R_Text_AssetResource_class_code)
|
558
613
|
|
559
614
|
# ----- Step-15 End -----
|
@@ -564,7 +619,7 @@ Flr recommends the following flutter resource structure:
|
|
564
619
|
#
|
565
620
|
|
566
621
|
r_dart_file.puts("\n")
|
567
|
-
g__R_Image_class_code = CodeUtil.generate__R_Image_class(non_svg_image_asset_array, package_name)
|
622
|
+
g__R_Image_class_code = CodeUtil.generate__R_Image_class(non_svg_image_asset_array, non_svg_image_asset_id_dict, package_name)
|
568
623
|
r_dart_file.puts(g__R_Image_class_code)
|
569
624
|
|
570
625
|
# ----- Step-16 End -----
|
@@ -574,7 +629,7 @@ Flr recommends the following flutter resource structure:
|
|
574
629
|
#
|
575
630
|
|
576
631
|
r_dart_file.puts("\n")
|
577
|
-
g__R_Svg_class_code = CodeUtil.generate__R_Svg_class(svg_image_asset_array, package_name)
|
632
|
+
g__R_Svg_class_code = CodeUtil.generate__R_Svg_class(svg_image_asset_array, svg_image_asset_id_dict, package_name)
|
578
633
|
r_dart_file.puts(g__R_Svg_class_code)
|
579
634
|
|
580
635
|
# ----- Step-17 End -----
|
@@ -584,7 +639,7 @@ Flr recommends the following flutter resource structure:
|
|
584
639
|
#
|
585
640
|
|
586
641
|
r_dart_file.puts("\n")
|
587
|
-
g__R_Text_class_code = CodeUtil.generate__R_Text_class(text_asset_array, package_name)
|
642
|
+
g__R_Text_class_code = CodeUtil.generate__R_Text_class(text_asset_array, text_asset_id_dict, package_name)
|
588
643
|
r_dart_file.puts(g__R_Text_class_code)
|
589
644
|
|
590
645
|
# ----- Step-18 End -----
|
@@ -679,7 +734,7 @@ Flr recommends the following flutter resource structure:
|
|
679
734
|
|
680
735
|
flr_config = pubspec_config["flr"]
|
681
736
|
|
682
|
-
resource_dir_result_tuple = Checker.check_flr_assets_is_legal(flr_config)
|
737
|
+
resource_dir_result_tuple = Checker.check_flr_assets_is_legal(flutter_project_root_dir, flr_config)
|
683
738
|
|
684
739
|
rescue Exception => e
|
685
740
|
puts(e.message)
|
data/lib/flr/constant.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
module Flr
|
2
|
+
# Flr支持的非SVG类图片文件类型
|
3
|
+
NON_SVG_IMAGE_FILE_TYPES = %w(.png .jpg .jpeg .gif .webp .icon .bmp .wbmp)
|
4
|
+
# Flr支持的SVG类图片文件类型
|
5
|
+
SVG_IMAGE_FILE_TYPES = %w(.svg)
|
2
6
|
# Flr支持的图片文件类型
|
3
|
-
IMAGE_FILE_TYPES =
|
7
|
+
IMAGE_FILE_TYPES = NON_SVG_IMAGE_FILE_TYPES + SVG_IMAGE_FILE_TYPES
|
4
8
|
# Flr支持的文本文件类型
|
5
9
|
TEXT_FILE_TYPES = %w(.txt .json .yaml .xml)
|
6
10
|
# Flr支持的字体文件类型
|
data/lib/flr/util/asset_util.rb
CHANGED
@@ -6,87 +6,158 @@ module Flr
|
|
6
6
|
# 资产相关的工具类方法
|
7
7
|
class AssetUtil
|
8
8
|
|
9
|
-
#
|
9
|
+
# is_asset_variant?(legal_resource_file) -> true or false
|
10
|
+
#
|
11
|
+
# 判断当前的资源文件是不是资产变体(asset_variant)类型
|
12
|
+
#
|
13
|
+
# 判断的核心算法是:
|
14
|
+
# - 获取资源文件的父目录;
|
15
|
+
# - 判断父目录是否符合资产变体目录的特征
|
16
|
+
# 资产变体映射的的资源文件要求存放在“与 main_asset 在同一个目录下的”、“符合指定特征的”子目录中;
|
17
|
+
# 截止目前,Flutter只支持一种变体类型:倍率变体;
|
18
|
+
# 倍率变体只适用于非SVG类图片资源;
|
19
|
+
# 倍率变体目录特征可使用此正则来判断:“^((0\.[0-9]+)|([1-9]+[0-9]*(\.[0-9]+)?))[x]$”;
|
20
|
+
# 倍率变体目录名称示例:“0.5x”、“1.5x”、“2.0x”、“3.0x”,“2x”、“3x”;
|
21
|
+
#
|
22
|
+
def self.is_asset_variant?(legal_resource_file)
|
23
|
+
|
24
|
+
if FileUtil.is_non_svg_image_resource_file?(legal_resource_file)
|
25
|
+
dirname = File.dirname(legal_resource_file)
|
26
|
+
parent_dir_name = File.basename(dirname)
|
27
|
+
|
28
|
+
ratio_regex = /^((0\.[0-9]+)|([1-9]+[0-9]*(\.[0-9]+)?))[x]$/
|
29
|
+
if parent_dir_name =~ ratio_regex
|
30
|
+
return true
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
return false
|
35
|
+
end
|
36
|
+
|
37
|
+
# generate_main_asset(flutter_dir, package_name, legal_resource_file) -> main_asset
|
38
|
+
#
|
39
|
+
# 为当前资源文件生成 main_asset
|
40
|
+
#
|
41
|
+
# === Examples
|
42
|
+
# flutter_dir = "~/path/to/flutter_r_demo"
|
43
|
+
# package_name = "flutter_r_demo"
|
44
|
+
#
|
45
|
+
# === Example-1
|
46
|
+
# legal_resource_file = "~/path/to/flutter_r_demo/lib/assets/images/test.png"
|
47
|
+
# main_asset = "packages/flutter_r_demo/assets/images/test.png"
|
48
|
+
#
|
49
|
+
# === Example-2
|
50
|
+
# legal_resource_file = "~/path/to/flutter_r_demo/lib/assets/images/3.0x/test.png"
|
51
|
+
# main_asset = "packages/flutter_r_demo/assets/images/test.png"
|
52
|
+
#
|
53
|
+
# === Example-3
|
54
|
+
# legal_resource_file = "~/path/to/flutter_r_demo/lib/assets/texts/3.0x/test.json"
|
55
|
+
# main_asset = "packages/flutter_r_demo/assets/texts/3.0x/test.json"
|
56
|
+
#
|
57
|
+
# === Example-3
|
58
|
+
# legal_resource_file = "~/path/to/flutter_r_demo/lib/assets/fonts/Amiri/Amiri-Regular.ttf"
|
59
|
+
# main_asset = "packages/flutter_r_demo/fonts/Amiri/Amiri-Regular.ttf"
|
60
|
+
#
|
61
|
+
def self.generate_main_asset(flutter_dir, package_name, legal_resource_file)
|
62
|
+
# legal_resource_file: ~/path/to/flutter_r_demo/lib/assets/images/3.0x/test.png
|
63
|
+
# to get main_resource_file: ~/path/to/flutter_r_demo/lib/assets/images/test.png
|
64
|
+
main_resource_file = legal_resource_file
|
65
|
+
if is_asset_variant?(legal_resource_file)
|
66
|
+
# test.png
|
67
|
+
file_basename = File.basename(legal_resource_file)
|
68
|
+
# ~/path/to/flutter_r_demo/lib/assets/images/3.0x
|
69
|
+
file_dir = File.dirname(legal_resource_file)
|
70
|
+
# ~/path/to/flutter_r_demo/lib/assets/images
|
71
|
+
main_resource_file_dir = File.dirname(file_dir)
|
72
|
+
# ~/path/to/flutter_r_demo/lib/assets/images/test.png
|
73
|
+
main_resource_file = main_resource_file_dir + "/" + file_basename
|
74
|
+
end
|
75
|
+
|
76
|
+
# main_resource_file: ~/path/to/flutter_r_demo/lib/assets/images/test.png
|
77
|
+
# main_relative_resource_file: lib/assets/images/test.png
|
78
|
+
# to get main_implied_relative_resource_file: assets/images/test.png
|
79
|
+
flutter_dir_prefix = "#{flutter_dir}/"
|
80
|
+
main_relative_resource_file = main_resource_file
|
81
|
+
if main_relative_resource_file =~ /\A#{flutter_dir_prefix}/
|
82
|
+
main_relative_resource_file["#{flutter_dir_prefix}"] = ""
|
83
|
+
end
|
84
|
+
lib_prefix = "lib/"
|
85
|
+
main_implied_relative_resource_file = main_relative_resource_file;
|
86
|
+
if main_implied_relative_resource_file =~ /\A#{lib_prefix}/
|
87
|
+
main_implied_relative_resource_file[lib_prefix] = ""
|
88
|
+
end
|
89
|
+
|
90
|
+
main_asset = "packages/#{package_name}/#{main_implied_relative_resource_file}"
|
91
|
+
return main_asset
|
92
|
+
end
|
93
|
+
|
94
|
+
# generate_image_assets(flutter_dir, package_name, legal_image_file_array) -> image_asset_array
|
10
95
|
#
|
11
96
|
# 遍历指定资源目录下扫描找到的legal_image_file数组生成image_asset数组
|
12
97
|
#
|
13
98
|
# === Examples
|
14
|
-
#
|
15
|
-
# resource_dir = "lib/assets/images"
|
99
|
+
# flutter_dir = "~/path/to/flutter_r_demo"
|
16
100
|
# package_name = "flutter_r_demo"
|
101
|
+
# legal_image_file_array = ["~/path/to/flutter_r_demo/lib/assets/images/test.png", "~/path/to/flutter_r_demo/lib/assets/images/3.0x/test.png"]
|
17
102
|
# image_asset_array = ["packages/flutter_r_demo/assets/images/test.png"]
|
18
103
|
#
|
19
|
-
def self.generate_image_assets(
|
104
|
+
def self.generate_image_assets(flutter_dir, package_name, legal_image_file_array)
|
20
105
|
|
21
106
|
image_asset_array = []
|
22
107
|
|
23
|
-
# implied_resource_dir = "assets/images"
|
24
|
-
implied_resource_dir = resource_dir
|
25
|
-
if resource_dir.include?("lib/")
|
26
|
-
implied_resource_dir = resource_dir.split("lib/")[1]
|
27
|
-
end
|
28
|
-
|
29
108
|
legal_image_file_array.each do |legal_image_file|
|
30
|
-
|
31
|
-
image_asset = "packages/#{package_name}/#{implied_resource_dir}/#{file_basename}"
|
109
|
+
image_asset = generate_main_asset(flutter_dir, package_name, legal_image_file)
|
32
110
|
image_asset_array.push(image_asset)
|
33
111
|
end
|
34
112
|
|
113
|
+
image_asset_array.uniq!
|
35
114
|
return image_asset_array
|
36
115
|
end
|
37
116
|
|
38
|
-
# generate_text_assets(
|
117
|
+
# generate_text_assets(flutter_dir, package_name, legal_text_file_array) -> text_asset_array
|
39
118
|
#
|
40
119
|
# 遍历指定资源目录下扫描找到的legal_text_file数组生成text_asset数组
|
41
120
|
#
|
42
121
|
# === Examples
|
43
|
-
#
|
44
|
-
# resource_dir = "lib/assets/jsons"
|
122
|
+
# flutter_dir = "~/path/to/flutter_r_demo"
|
45
123
|
# package_name = "flutter_r_demo"
|
124
|
+
# legal_text_file_array = ["~path/to/flutter_r_demo/lib/assets/jsons/test.json"]
|
46
125
|
# text_asset_array = ["packages/flutter_r_demo/assets/jsons/test.json"]
|
47
126
|
#
|
48
|
-
def self.generate_text_assets(
|
127
|
+
def self.generate_text_assets(flutter_dir, package_name, legal_text_file_array)
|
49
128
|
|
50
129
|
text_asset_array = []
|
51
130
|
|
52
131
|
legal_text_file_array.each do |legal_text_file|
|
53
|
-
|
54
|
-
implied_resource_file = legal_text_file
|
55
|
-
if legal_text_file.include?("lib/")
|
56
|
-
implied_resource_file = legal_text_file.split("lib/")[1]
|
57
|
-
end
|
58
|
-
text_asset = "packages/#{package_name}/#{implied_resource_file}"
|
132
|
+
text_asset = generate_main_asset(flutter_dir, package_name, legal_text_file)
|
59
133
|
text_asset_array.push(text_asset)
|
60
134
|
end
|
61
135
|
|
136
|
+
text_asset_array.uniq!
|
62
137
|
return text_asset_array
|
63
138
|
end
|
64
139
|
|
65
|
-
# generate_font_asset_configs(
|
140
|
+
# generate_font_asset_configs(flutter_dir, package_name, legal_font_file_array) -> font_asset_config_array
|
66
141
|
#
|
67
142
|
# 遍历指定资源目录下扫描找到的legal_font_file数组生成font_asset_config数组
|
68
143
|
#
|
69
144
|
# === Examples
|
70
|
-
#
|
71
|
-
# resource_dir = "lib/assets/fonts/Amiri"
|
145
|
+
# flutter_dir = "~/path/to/flutter_r_demo"
|
72
146
|
# package_name = "flutter_r_demo"
|
147
|
+
# legal_font_file_array = ["~path/to/flutter_r_demo/lib/assets/fonts/Amiri/Amiri-Regular.ttf"]
|
73
148
|
# font_asset_config_array -> [{"asset": "packages/flutter_r_demo/assets/fonts/Amiri/Amiri-Regular.ttf"}]
|
74
149
|
#
|
75
|
-
def self.generate_font_asset_configs(
|
150
|
+
def self.generate_font_asset_configs(flutter_dir, package_name, legal_font_file_array)
|
76
151
|
|
77
152
|
font_asset_config_array = []
|
78
153
|
|
79
154
|
legal_font_file_array.each do |legal_font_file|
|
80
|
-
|
81
|
-
implied_resource_file = legal_font_file
|
82
|
-
if legal_font_file.include?("lib/")
|
83
|
-
implied_resource_file = legal_font_file.split("lib/")[1]
|
84
|
-
end
|
85
|
-
font_asset = "packages/#{package_name}/#{implied_resource_file}"
|
155
|
+
font_asset = generate_main_asset(flutter_dir, package_name, legal_font_file)
|
86
156
|
font_asset_config = Hash["asset" => font_asset]
|
87
157
|
font_asset_config_array.push(font_asset_config)
|
88
158
|
end
|
89
159
|
|
160
|
+
font_asset_config_array.uniq!{|config| config["asset"]}
|
90
161
|
return font_asset_config_array
|
91
162
|
end
|
92
163
|
|
data/lib/flr/util/code_util.rb
CHANGED
@@ -116,7 +116,7 @@ class AssetResource {
|
|
116
116
|
return code
|
117
117
|
end
|
118
118
|
|
119
|
-
# generate_asset_id (asset, prior_asset_type) -> string
|
119
|
+
# generate_asset_id (asset, used_asset_id_array, prior_asset_type) -> string
|
120
120
|
#
|
121
121
|
# - prior_asset_type: 优先的资源类型;默认值为 ".*",意味当前不存在任何优先的资源类型
|
122
122
|
# 对于优先的资源类型,其 asset_id 不会携带类型信息,详细见例子
|
@@ -126,26 +126,40 @@ class AssetResource {
|
|
126
126
|
# - 处理非法字符:把除了字母(a-z, A-Z)、数字(0-9)、'_' 字符、'$' 字符之外的字符转换为 '_' 字符
|
127
127
|
# - 首字母转化为小写
|
128
128
|
# - 处理首字符异常情况:检测首字符是不是数字、'_'、'$',若是则添加前缀字符"a"
|
129
|
+
# - 处理 asset_id 重名的情况
|
129
130
|
#
|
130
131
|
# === Examples
|
131
132
|
#
|
132
133
|
# ===== Example-1
|
133
|
-
#
|
134
|
-
#
|
134
|
+
# asset = "packages/flutter_r_demo/assets/images/test.png"
|
135
|
+
# asset = "packages/flutter_r_demo/assets/images/test.jpg"
|
136
|
+
# used_asset_id_array = []
|
135
137
|
# prior_asset_type = ".png"
|
136
|
-
#
|
137
|
-
# b_asset_id = "test_jpg"
|
138
|
+
# asset_id = "test"
|
138
139
|
#
|
139
140
|
# ===== Example-2
|
140
|
-
#
|
141
|
-
#
|
141
|
+
# asset = "packages/flutter_r_demo/assets/images/test.jpg"
|
142
|
+
# used_asset_id_array = [test]
|
143
|
+
# prior_asset_type = ".png"
|
144
|
+
# asset_id = "test_jpg"
|
145
|
+
#
|
146
|
+
# ===== Example-3
|
147
|
+
# asset = "packages/flutter_r_demo/assets/home-images/test.jpg"
|
148
|
+
# used_asset_id_array = [test, test_jpg]
|
149
|
+
# prior_asset_type = ".png"
|
150
|
+
# asset_id = "test_jpg_1"
|
151
|
+
#
|
152
|
+
# ===== Example-4
|
153
|
+
# asset = "packages/flutter_r_demo/assets/texts/test.json"
|
154
|
+
# used_asset_id_array = []
|
142
155
|
# prior_asset_type = ".*"
|
143
|
-
#
|
144
|
-
# b_asset_id = "test_yaml"
|
156
|
+
# asset_id = "test_json"
|
145
157
|
#
|
146
|
-
def self.generate_asset_id(asset, prior_asset_type = ".*")
|
158
|
+
def self.generate_asset_id(asset, used_asset_id_array, prior_asset_type = ".*")
|
147
159
|
file_extname = File.extname(asset).downcase
|
148
160
|
|
161
|
+
dirname = File.dirname(asset)
|
162
|
+
parent_dir_name = File.basename(dirname)
|
149
163
|
file_basename = File.basename(asset)
|
150
164
|
|
151
165
|
file_basename_no_extension = File.basename(asset, ".*")
|
@@ -168,6 +182,26 @@ class AssetResource {
|
|
168
182
|
asset_id = "a" + asset_id
|
169
183
|
end
|
170
184
|
|
185
|
+
# 处理 asset_id 重名的情况
|
186
|
+
if used_asset_id_array.include?(asset_id)
|
187
|
+
# 当前asset_id重名次数,初始值为1
|
188
|
+
repeat_count = 1
|
189
|
+
|
190
|
+
# 查找当前asset_id衍生出来的asset_id_brother(id兄弟)
|
191
|
+
# asset_id_brother = #{asset_id}$#{repeat_count}
|
192
|
+
# 其中,repeat_count >= 1
|
193
|
+
#
|
194
|
+
# Example:
|
195
|
+
# asset_id = test
|
196
|
+
# asset_id_brother = test$1
|
197
|
+
#
|
198
|
+
id_brother_regx = /^#{asset_id}\$[1-9][0-9]*$/
|
199
|
+
cur_asset_id_brothers = used_asset_id_array.select{ |id| id =~ id_brother_regx }
|
200
|
+
|
201
|
+
repeat_count += cur_asset_id_brothers.size
|
202
|
+
asset_id = "#{asset_id}$#{repeat_count}"
|
203
|
+
end
|
204
|
+
|
171
205
|
return asset_id
|
172
206
|
end
|
173
207
|
|
@@ -190,13 +224,13 @@ class AssetResource {
|
|
190
224
|
return asset_comment
|
191
225
|
end
|
192
226
|
|
193
|
-
# generate_AssetResource_property(asset, package_name, prior_asset_type) -> string
|
227
|
+
# generate_AssetResource_property(asset, asset_id_dict, package_name, prior_asset_type) -> string
|
194
228
|
#
|
195
229
|
# 为当前 asset 生成 AssetResource property 的代码
|
196
230
|
#
|
197
|
-
def self.generate_AssetResource_property(asset, package_name, prior_asset_type = ".*")
|
231
|
+
def self.generate_AssetResource_property(asset, asset_id_dict, package_name, prior_asset_type = ".*")
|
198
232
|
|
199
|
-
asset_id =
|
233
|
+
asset_id = asset_id_dict[asset]
|
200
234
|
asset_comment = generate_asset_comment(asset, package_name)
|
201
235
|
|
202
236
|
asset_name = asset.dup
|
@@ -213,17 +247,17 @@ class AssetResource {
|
|
213
247
|
return code
|
214
248
|
end
|
215
249
|
|
216
|
-
# generate__R_Image_AssetResource_class(non_svg_image_asset_array, package_name) -> string
|
250
|
+
# generate__R_Image_AssetResource_class(non_svg_image_asset_array, non_svg_image_asset_id_dict, package_name) -> string
|
217
251
|
#
|
218
252
|
# 根据模板,为 non_svg_image_asset_array(非svg类的图片资产数组)生成 _R_Image_AssetResource class 的代码
|
219
253
|
#
|
220
|
-
def self.generate__R_Image_AssetResource_class(non_svg_image_asset_array, package_name)
|
254
|
+
def self.generate__R_Image_AssetResource_class(non_svg_image_asset_array, non_svg_image_asset_id_dict, package_name)
|
221
255
|
|
222
256
|
all_g_AssetResource_property_code = ""
|
223
257
|
|
224
258
|
non_svg_image_asset_array.each do |image_asset|
|
225
259
|
all_g_AssetResource_property_code += "\n"
|
226
|
-
g_AssetResource_property_code = generate_AssetResource_property(image_asset, package_name, Flr::PRIOR_NON_SVG_IMAGE_FILE_TYPE)
|
260
|
+
g_AssetResource_property_code = generate_AssetResource_property(image_asset, non_svg_image_asset_id_dict, package_name, Flr::PRIOR_NON_SVG_IMAGE_FILE_TYPE)
|
227
261
|
all_g_AssetResource_property_code += g_AssetResource_property_code
|
228
262
|
end
|
229
263
|
|
@@ -238,17 +272,17 @@ class _R_Image_AssetResource {
|
|
238
272
|
return code
|
239
273
|
end
|
240
274
|
|
241
|
-
# generate__R_Svg_AssetResource_class(
|
275
|
+
# generate__R_Svg_AssetResource_class(svg_image_asset_array, svg_image_asset_id_dict, package_name) -> string
|
242
276
|
#
|
243
277
|
# 根据模板,为 svg_image_asset_array(svg类的图片资产数组)生成 _R_Svg_AssetResource class 的代码
|
244
278
|
#
|
245
|
-
def self.generate__R_Svg_AssetResource_class(svg_image_asset_array, package_name)
|
279
|
+
def self.generate__R_Svg_AssetResource_class(svg_image_asset_array, svg_image_asset_id_dict, package_name)
|
246
280
|
|
247
281
|
all_g_AssetResource_property_code = ""
|
248
282
|
|
249
283
|
svg_image_asset_array.each do |image_asset|
|
250
284
|
all_g_AssetResource_property_code += "\n"
|
251
|
-
g_AssetResource_property_code = generate_AssetResource_property(image_asset, package_name, Flr::PRIOR_SVG_IMAGE_FILE_TYPE)
|
285
|
+
g_AssetResource_property_code = generate_AssetResource_property(image_asset, svg_image_asset_id_dict, package_name, Flr::PRIOR_SVG_IMAGE_FILE_TYPE)
|
252
286
|
all_g_AssetResource_property_code += g_AssetResource_property_code
|
253
287
|
end
|
254
288
|
|
@@ -263,17 +297,17 @@ class _R_Svg_AssetResource {
|
|
263
297
|
return code
|
264
298
|
end
|
265
299
|
|
266
|
-
# generate__R_Text_AssetResource_class(text_asset_array, package_name) -> string
|
300
|
+
# generate__R_Text_AssetResource_class(text_asset_array, text_asset_id_dict, package_name) -> string
|
267
301
|
#
|
268
302
|
# 根据模板,为 text_asset_array(文本资产数组)生成 _R_Text_AssetResource class 的代码
|
269
303
|
#
|
270
|
-
def self.generate__R_Text_AssetResource_class(text_asset_array, package_name)
|
304
|
+
def self.generate__R_Text_AssetResource_class(text_asset_array, text_asset_id_dict, package_name)
|
271
305
|
|
272
306
|
all_g_AssetResource_property_code = ""
|
273
307
|
|
274
308
|
text_asset_array.each do |text_asset|
|
275
309
|
all_g_AssetResource_property_code += "\n"
|
276
|
-
g_AssetResource_property_code = generate_AssetResource_property(text_asset, package_name, Flr::PRIOR_TEXT_FILE_TYPE)
|
310
|
+
g_AssetResource_property_code = generate_AssetResource_property(text_asset, text_asset_id_dict, package_name, Flr::PRIOR_TEXT_FILE_TYPE)
|
277
311
|
all_g_AssetResource_property_code += g_AssetResource_property_code
|
278
312
|
end
|
279
313
|
|
@@ -288,18 +322,18 @@ class _R_Text_AssetResource {
|
|
288
322
|
return code
|
289
323
|
end
|
290
324
|
|
291
|
-
# generate__R_Image_class(non_svg_image_asset_array, package_name) -> string
|
325
|
+
# generate__R_Image_class(non_svg_image_asset_array, non_svg_image_asset_id_dict, package_name) -> string
|
292
326
|
#
|
293
327
|
# 根据模板,为 non_svg_image_asset_array(非svg类的图片资产数组)生成 _R_Image class 的代码
|
294
328
|
#
|
295
|
-
def self.generate__R_Image_class(non_svg_image_asset_array, package_name)
|
329
|
+
def self.generate__R_Image_class(non_svg_image_asset_array, non_svg_image_asset_id_dict, package_name)
|
296
330
|
|
297
331
|
all_g_Asset_method_code = ""
|
298
332
|
|
299
333
|
non_svg_image_asset_array.each do |image_asset|
|
300
334
|
all_g_Asset_method_code += "\n"
|
301
335
|
|
302
|
-
asset_id =
|
336
|
+
asset_id = non_svg_image_asset_id_dict[image_asset]
|
303
337
|
asset_comment = generate_asset_comment(image_asset, package_name)
|
304
338
|
|
305
339
|
g_Asset_method_code = <<-CODE
|
@@ -327,18 +361,18 @@ class _R_Image {
|
|
327
361
|
return code
|
328
362
|
end
|
329
363
|
|
330
|
-
# generate__R_Svg_class(
|
364
|
+
# generate__R_Svg_class(svg_image_asset_array, svg_image_asset_id_dict, package_name) -> string
|
331
365
|
#
|
332
366
|
# 根据模板,为 svg_image_asset_array(svg类的图片资产数组)生成 _R_Svg class 的代码
|
333
367
|
#
|
334
|
-
def self.generate__R_Svg_class(svg_image_asset_array, package_name)
|
368
|
+
def self.generate__R_Svg_class(svg_image_asset_array, svg_image_asset_id_dict, package_name)
|
335
369
|
|
336
370
|
all_g_Asset_method_code = ""
|
337
371
|
|
338
372
|
svg_image_asset_array.each do |image_asset|
|
339
373
|
all_g_Asset_method_code += "\n"
|
340
374
|
|
341
|
-
asset_id =
|
375
|
+
asset_id = svg_image_asset_id_dict[image_asset]
|
342
376
|
asset_comment = generate_asset_comment(image_asset, package_name)
|
343
377
|
|
344
378
|
g_Asset_method_code = <<-CODE
|
@@ -367,18 +401,18 @@ class _R_Svg {
|
|
367
401
|
return code
|
368
402
|
end
|
369
403
|
|
370
|
-
# generate__R_Text_class(text_asset_array, package_name) -> string
|
404
|
+
# generate__R_Text_class(text_asset_array, text_asset_id_dict, package_name) -> string
|
371
405
|
#
|
372
406
|
# 根据模板,为 text_asset_array(文本资产数组)生成 _R_Text class 的代码
|
373
407
|
#
|
374
|
-
def self.generate__R_Text_class(text_asset_array, package_name)
|
408
|
+
def self.generate__R_Text_class(text_asset_array, text_asset_id_dict, package_name)
|
375
409
|
|
376
410
|
all_g_Asset_method_code = ""
|
377
411
|
|
378
412
|
text_asset_array.each do |text_asset|
|
379
413
|
all_g_Asset_method_code += "\n"
|
380
414
|
|
381
|
-
asset_id =
|
415
|
+
asset_id = text_asset_id_dict[text_asset]
|
382
416
|
asset_comment = generate_asset_comment(text_asset, package_name)
|
383
417
|
|
384
418
|
g_Asset_method_code = <<-CODE
|
data/lib/flr/util/file_util.rb
CHANGED
@@ -79,6 +79,61 @@ module Flr
|
|
79
79
|
return true
|
80
80
|
end
|
81
81
|
|
82
|
+
# 判断当前文件是不是非SVG类图片资源文件
|
83
|
+
def self.is_non_svg_image_resource_file?(file)
|
84
|
+
file_extname = File.extname(file).downcase
|
85
|
+
|
86
|
+
if Flr::NON_SVG_IMAGE_FILE_TYPES.include?(file_extname)
|
87
|
+
return true;
|
88
|
+
end
|
89
|
+
|
90
|
+
return false
|
91
|
+
end
|
92
|
+
|
93
|
+
# 判断当前文件是不是SVG类图片资源文件
|
94
|
+
def self.is_svg_image_resource_file?(file)
|
95
|
+
file_extname = File.extname(file).downcase
|
96
|
+
|
97
|
+
if Flr::SVG_IMAGE_FILE_TYPES.include?(file_extname)
|
98
|
+
return true;
|
99
|
+
end
|
100
|
+
|
101
|
+
return false
|
102
|
+
end
|
103
|
+
|
104
|
+
# 判断当前文件是不是图片资源文件
|
105
|
+
def self.is_image_resource_file?(file)
|
106
|
+
file_extname = File.extname(file).downcase
|
107
|
+
|
108
|
+
if Flr::IMAGE_FILE_TYPES.include?(file_extname)
|
109
|
+
return true;
|
110
|
+
end
|
111
|
+
|
112
|
+
return false
|
113
|
+
end
|
114
|
+
|
115
|
+
# 判断当前文件是不是文本资源文件
|
116
|
+
def self.is_text_resource_file?(file)
|
117
|
+
file_extname = File.extname(file).downcase
|
118
|
+
|
119
|
+
if Flr::TEXT_FILE_TYPES.include?(file_extname)
|
120
|
+
return true;
|
121
|
+
end
|
122
|
+
|
123
|
+
return false
|
124
|
+
end
|
125
|
+
|
126
|
+
# 判断当前文件是不是字体资源文件
|
127
|
+
def self.is_font_resource_file?(file)
|
128
|
+
file_extname = File.extname(file).downcase
|
129
|
+
|
130
|
+
if Flr::FONT_FILE_TYPES.include?(file_extname)
|
131
|
+
return true;
|
132
|
+
end
|
133
|
+
|
134
|
+
return false
|
135
|
+
end
|
136
|
+
|
82
137
|
# is_legal_resource_file??(file) -> true or false
|
83
138
|
#
|
84
139
|
# 判断当前资源文件是否合法
|
@@ -87,8 +142,8 @@ module Flr
|
|
87
142
|
# 其file_basename_no_extension 由字母(a-z、A-Z)、数字(0-9)、其他合法字符('_', '+', '-', '.', '·', '!', '@', '&', '$', '¥')组成
|
88
143
|
#
|
89
144
|
# === Examples
|
90
|
-
# good_file = "lib/assets/images/test.png"
|
91
|
-
# bad_file = "lib/assets/images/~.png"
|
145
|
+
# good_file = "~/path/to/flutter_project/lib/assets/images/test.png"
|
146
|
+
# bad_file = "~/path/to/flutter_project/lib/assets/images/~.png"
|
92
147
|
# is_legal_resource_file?(good_file) -> true
|
93
148
|
# is_legal_resource_file?(bad_file) -> false
|
94
149
|
#
|
@@ -105,26 +160,25 @@ module Flr
|
|
105
160
|
|
106
161
|
# find_image_files(resource_dir) -> image_file_result_tuple
|
107
162
|
#
|
108
|
-
#
|
109
|
-
# v1.1.0: 放开图片资源扫描目录层级限制,以支持不标准的资源组织目录结构
|
163
|
+
# 扫描指定的资源目录和其所有层级的子目录,查找所有图片文件
|
110
164
|
# 返回图片文件结果二元组 image_file_result_tuple
|
111
165
|
# image_file_result_tuple = [legal_image_file_array, illegal_image_file_array]
|
112
166
|
#
|
113
167
|
# 判断文件合法的标准参考 self.is_legal_resource_file? 方法
|
114
168
|
#
|
115
169
|
# === Examples
|
116
|
-
# resource_dir = "lib/assets/images"
|
117
|
-
# legal_image_file_array = ["lib/assets/images/test.png", "lib/assets/images/2.0x/test.png"]
|
118
|
-
# illegal_image_file_array = ["lib/assets/images/~.png"]
|
170
|
+
# resource_dir = "~/path/to/flutter_project/lib/assets/images"
|
171
|
+
# legal_image_file_array = ["~/path/to/flutter_project/lib/assets/images/test.png", "~/path/to/flutter_project/lib/assets/images/2.0x/test.png"]
|
172
|
+
# illegal_image_file_array = ["~/path/to/flutter_project/lib/assets/images/~.png"]
|
119
173
|
#
|
120
174
|
def self.find_image_files(resource_dir)
|
121
175
|
legal_image_file_array = []
|
122
176
|
illegal_image_file_array = []
|
123
177
|
|
124
178
|
pattern_file_types = Flr::IMAGE_FILE_TYPES.join(",")
|
125
|
-
# dir/*{.png
|
126
|
-
# dir/*/*{.png
|
127
|
-
# dir/**/*{.png
|
179
|
+
# dir/*{.png,.jpg} : 查找当前目录的指定类型文件
|
180
|
+
# dir/*/*{.png,.jpg}: 查找当前目录的第1级子目录的指定类型文件
|
181
|
+
# dir/**/*{.png,.jpg}: 查找当前目录和其所有子目录的指定类型文件
|
128
182
|
Dir.glob(["#{resource_dir}/**/*{#{pattern_file_types}}"]).each do |file|
|
129
183
|
if is_legal_resource_file?(file)
|
130
184
|
legal_image_file_array.push(file)
|
@@ -146,9 +200,9 @@ module Flr
|
|
146
200
|
# 判断文件合法的标准参考 self.is_legal_resource_file? 方法
|
147
201
|
#
|
148
202
|
# === Examples
|
149
|
-
# resource_dir = "lib/assets/jsons"
|
150
|
-
# legal_text_file_array = ["lib/assets/jsons/city.json", "lib/assets/jsons/mock/city.json"]
|
151
|
-
# illegal_text_file_array = ["lib/assets/jsons/~.json"]
|
203
|
+
# resource_dir = "~/path/to/flutter_project/lib/assets/jsons"
|
204
|
+
# legal_text_file_array = ["~/path/to/flutter_project/lib/assets/jsons/city.json", "~/path/to/flutter_project/lib/assets/jsons/mock/city.json"]
|
205
|
+
# illegal_text_file_array = ["~/path/to/flutter_project/lib/assets/jsons/~.json"]
|
152
206
|
#
|
153
207
|
def self.find_text_files(resource_dir)
|
154
208
|
legal_text_file_array = []
|
@@ -173,7 +227,8 @@ module Flr
|
|
173
227
|
# 扫描指定的资源目录,返回其所有第一级子目录
|
174
228
|
#
|
175
229
|
# === Examples
|
176
|
-
#
|
230
|
+
# resource_dir = "~/path/to/flutter_project/lib/assets/fonts"
|
231
|
+
# top_child_dir_array = ["~/path/to/flutter_project/lib/assets/fonts/Amiri", "~/path/to/flutter_project/lib/assets/fonts/Open_Sans"]
|
177
232
|
#
|
178
233
|
def self.find_top_child_dirs(resource_dir)
|
179
234
|
top_child_dir_array = []
|
@@ -196,9 +251,9 @@ module Flr
|
|
196
251
|
# 判断文件合法的标准参考 self.is_legal_resource_file? 方法
|
197
252
|
#
|
198
253
|
# === Examples
|
199
|
-
# font_family_dir = "lib/assets/fonts/Amiri"
|
200
|
-
# legal_font_file_array = ["lib/assets/fonts/Amiri/Amiri-Regular.ttf", "lib/assets/fonts/Amiri/Amiri-Bold.ttf"]
|
201
|
-
# illegal_font_file_array = ["lib/assets/fonts/Amiri/~.ttf"]
|
254
|
+
# font_family_dir = "~/path/to/flutter_project/lib/assets/fonts/Amiri"
|
255
|
+
# legal_font_file_array = ["~/path/to/flutter_project/lib/assets/fonts/Amiri/Amiri-Regular.ttf", "~/path/to/flutter_project/lib/assets/fonts/Amiri/Amiri-Bold.ttf"]
|
256
|
+
# illegal_font_file_array = ["~/path/to/flutter_project/lib/assets/fonts/Amiri/~.ttf"]
|
202
257
|
#
|
203
258
|
def self.find_font_files_in_font_family_dir(font_family_dir)
|
204
259
|
legal_font_file_array = []
|
data/lib/flr/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- York
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-04-
|
11
|
+
date: 2020-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|