Feature #23980 » 0001-Adds-rake-task-to-download-SVG-icons-from-Tabler-Git.patch
Gemfile | ||
---|---|---|
95 | 95 |
group :development do |
96 | 96 |
gem 'listen', '~> 3.3' |
97 | 97 |
gem 'yard', require: false |
98 |
gem 'svg_sprite', require: false |
|
98 | 99 |
end |
99 | 100 | |
100 | 101 |
group :test do |
config/icon_source.yml | ||
---|---|---|
1 |
- name: edit |
|
2 |
svg: pencil |
|
3 |
- name: add |
|
4 |
svg: circle-plus |
|
5 |
- name: copy |
|
6 |
svg: copy |
|
7 |
- name: del |
|
8 |
svg: trash |
|
9 |
- name: save |
|
10 |
svg: device-floppy |
|
11 |
- name: download |
|
12 |
svg: download |
|
13 |
- name: attachment |
|
14 |
svg: paperclip |
|
15 |
- name: time-add |
|
16 |
svg: clock-plus |
|
17 |
- name: time |
|
18 |
svg: clock |
|
19 |
- name: fav |
|
20 |
svg: star |
|
21 |
- name: copy-link |
|
22 |
svg: clipboard-copy |
|
23 |
- name: 3-bullets |
|
24 |
svg: dots |
|
25 |
- name: history |
|
26 |
svg: history |
|
27 |
- name: folder |
|
28 |
svg: folder |
|
29 |
- name: folder-open |
|
30 |
svg: folder-open |
|
31 |
- name: lock |
|
32 |
svg: lock |
|
33 |
- name: unlock |
|
34 |
svg: lock-open |
|
35 |
- name: link-break |
|
36 |
svg: link-off |
|
37 |
- name: zoom-in |
|
38 |
svg: zoom-in |
|
39 |
- name: zoom-out |
|
40 |
svg: zoom-out |
|
41 |
- name: settings |
|
42 |
svg: settings |
|
43 |
- name: news |
|
44 |
svg: news |
|
45 |
- name: user |
|
46 |
svg: user |
|
47 |
- name: group |
|
48 |
svg: users-group |
|
49 |
- name: bookmarked |
|
50 |
svg: bookmark |
|
51 |
- name: bookmark-delete |
|
52 |
svg: bookmark-off |
|
53 |
- name: bookmark-add |
|
54 |
svg: bookmark-plus |
|
55 |
- name: import |
|
56 |
svg: database-export |
|
57 |
- name: summary |
|
58 |
svg: bolt |
|
59 |
- name: angle-down |
|
60 |
svg: chevron-down |
|
61 |
- name: angle-right |
|
62 |
svg: chevron-right |
|
63 |
- name: angle-up |
|
64 |
svg: chevron-up |
|
65 |
- name: email |
|
66 |
svg: mail |
|
67 |
- name: email-disabled |
|
68 |
svg: mail-off |
|
69 |
- name: stats |
|
70 |
svg: chart-bar |
|
71 |
- name: reorder |
|
72 |
svg: menu-order |
|
73 |
- name: close |
|
74 |
svg: square-x |
|
75 |
- name: checked |
|
76 |
svg: check |
|
77 |
- name: reload |
|
78 |
svg: refresh |
|
79 |
- name: link |
|
80 |
svg: link |
|
81 |
- name: plugins |
|
82 |
svg: puzzle |
|
83 |
- name: roles |
|
84 |
svg: shield-cog |
|
85 |
- name: list |
|
86 |
svg: list |
|
87 |
- name: workflows |
|
88 |
svg: jump-rope |
|
89 |
- name: server-authentication |
|
90 |
svg: server |
|
91 |
- name: table-multiple |
|
92 |
svg: refresh |
|
93 |
- name: projects |
|
94 |
svg: packages |
|
95 |
- name: package |
|
96 |
svg: package |
|
97 |
- name: custom-fields |
|
98 |
svg: input-check |
|
99 |
- name: help |
|
100 |
svg: info-circle |
|
101 |
- name: changeset |
|
102 |
svg: code |
|
103 |
- name: clear-query |
|
104 |
svg: square-x |
|
105 |
- name: warning |
|
106 |
svg: alert-triangle |
|
107 |
- name: comments |
|
108 |
svg: message |
|
109 |
- name: comment |
|
110 |
svg: message |
|
111 |
- name: arrow-right |
|
112 |
svg: arrow-big-right |
|
113 |
- name: wiki-page |
|
114 |
svg: notebook |
|
115 |
- name: bullet-end |
|
116 |
svg: circle-arrow-left |
|
117 |
- name: bullet-go |
|
118 |
svg: circle-arrow-right |
|
119 |
- name: bullet-go-end |
|
120 |
svg: diamonds |
|
121 |
- name: move |
|
122 |
svg: arrow-forward-up |
|
123 |
- name: cancel |
|
124 |
svg: arrow-back-up |
|
125 |
- name: document |
|
126 |
svg: file-text |
|
127 |
- name: issue |
|
128 |
svg: note |
|
129 |
- name: issue-closed |
|
130 |
svg: square-check |
|
131 |
- name: issue-edit |
|
132 |
svg: edit |
|
133 |
- name: issue-note |
|
134 |
svg: message-plus |
|
135 |
- name: file |
|
136 |
svg: file |
|
137 |
- name: text-plain |
|
138 |
svg: file-text |
|
139 |
- name: text-x-c |
|
140 |
svg: file-code |
|
141 |
- name: text-x-csharp |
|
142 |
svg: brand-c-sharp |
|
143 |
- name: text-x-java |
|
144 |
svg: file-code |
|
145 |
- name: text-x-php |
|
146 |
svg: file-type-php |
|
147 |
- name: text-x-ruby |
|
148 |
svg: file-code |
|
149 |
- name: text-xml |
|
150 |
svg: file-type-xml |
|
151 |
- name: text-css |
|
152 |
svg: file-type-css |
|
153 |
- name: text-html |
|
154 |
svg: file-type-html |
|
155 |
- name: image-gif |
|
156 |
svg: file |
|
157 |
- name: image-jpeg |
|
158 |
svg: file-type-jpg |
|
159 |
- name: image-png |
|
160 |
svg: file-type-png |
|
161 |
- name: image-tiff |
|
162 |
svg: file |
|
163 |
- name: application-javascript |
|
164 |
svg: file-type-js |
|
165 |
- name: application-pdf |
|
166 |
svg: file-type-pdf |
|
167 |
- name: application-zip |
|
168 |
svg: file-type-zip |
|
169 |
- name: application-gzip |
|
170 |
svg: file-zip |
|
171 |
lib/tasks/icons.rake | ||
---|---|---|
1 |
# frozen_string_literal: true |
|
2 |
unless Rails.env.production? |
|
3 |
require "svg_sprite" |
|
4 | ||
5 |
SOURCE = URI.parse("https://raw.githubusercontent.com") |
|
6 |
SOURCE_PATH = "/tabler/tabler-icons/main/icons" |
|
7 |
ICON_VERSION = "outline" |
|
8 | ||
9 |
namespace :icons do |
|
10 | ||
11 |
desc 'Downloads default SVG icons' |
|
12 |
task :download do |
|
13 |
icons_mapping = YAML.load_file(Rails.root.join('config/icon_source.yml')) |
|
14 |
destination_path = Rails.root.join("tmp", "icons", "default") |
|
15 | ||
16 |
download_sgv_icons(icons_mapping, destination_path) |
|
17 |
end |
|
18 | ||
19 |
desc "Generates SVG sprite file default SVG icons" |
|
20 |
task :sprite do |
|
21 |
input_path = Rails.root.join("tmp", "icons", "default") |
|
22 |
sprite_path = Rails.root.join('app', 'assets', 'images', 'icons.svg') |
|
23 | ||
24 |
generate_svg_sprite(input_path, sprite_path) |
|
25 |
end |
|
26 | ||
27 |
desc 'Downloads default SVG icons and generates a SVG sprite from the icons' |
|
28 |
task :generate do |
|
29 |
Rake::Task["icons:download"].execute |
|
30 |
Rake::Task["icons:sprite"].execute |
|
31 |
end |
|
32 | ||
33 |
namespace :plugin do |
|
34 |
desc 'Downloads SVG icons for plugin' |
|
35 |
task :download do |
|
36 |
name = ENV['NAME'] |
|
37 | ||
38 |
if name.nil? |
|
39 |
abort "The VERSION argument requires a plugin NAME." |
|
40 |
end |
|
41 | ||
42 |
icons_mapping_path = Rails.root.join('plugins', name, 'config', 'icon_source.yml') |
|
43 |
unless File.file?(icons_mapping_path) |
|
44 |
abort "Icon source file for #{name} plugin not found in #{icons_mapping_path}." |
|
45 |
end |
|
46 | ||
47 |
icons_mapping = YAML.load_file(icons_mapping_path) |
|
48 |
destination_path = Rails.root.join("tmp", "icons", name) |
|
49 | ||
50 |
download_sgv_icons(icons_mapping, destination_path) |
|
51 |
end |
|
52 | ||
53 |
desc "Generates SVG sprite for plugin" |
|
54 |
task :sprite do |
|
55 |
name = ENV['NAME'] |
|
56 | ||
57 |
if name.nil? |
|
58 |
abort "The VERSION argument requires a plugin NAME." |
|
59 |
end |
|
60 | ||
61 |
input_path = Rails.root.join("tmp", "icons", name) |
|
62 |
sprite_path = Rails.root.join('plugins', name, 'app', 'assets', 'images', 'icons.svg') |
|
63 | ||
64 |
generate_svg_sprite(input_path, sprite_path) |
|
65 |
end |
|
66 | ||
67 |
desc 'Downloads SVG icons and generates sprite for plugin' |
|
68 |
task :generate do |
|
69 |
Rake::Task["icons:plugin:download"].execute |
|
70 |
Rake::Task["icons:plugin:sprite"].execute |
|
71 |
end |
|
72 |
end |
|
73 |
end |
|
74 | ||
75 |
def download_sgv_icons(icons_mapping, destination) |
|
76 |
http = Net::HTTP.new(SOURCE.host, SOURCE.port) |
|
77 |
http.use_ssl = true |
|
78 | ||
79 |
FileUtils.rm_rf(destination) |
|
80 |
FileUtils.mkdir_p(destination) |
|
81 | ||
82 |
icons_mapping.each do |v| |
|
83 |
name = v['name'] |
|
84 |
svg = v['svg'] |
|
85 | ||
86 |
http.start do |h| |
|
87 |
source = "#{SOURCE_PATH}/#{ICON_VERSION}/#{svg}.svg" |
|
88 | ||
89 |
puts "Downloading #{name} from #{source}..." |
|
90 |
req = Net::HTTP::Get.new(source) |
|
91 |
res = h.request(req) |
|
92 | ||
93 |
case res |
|
94 |
when Net::HTTPSuccess |
|
95 |
target = File.join(destination, "#{name}.svg") |
|
96 |
File.open(target, 'w') do |f| |
|
97 |
f.write res.body |
|
98 |
end |
|
99 |
else |
|
100 |
puts "Error when trying to download the icon for #{name}" |
|
101 |
puts res.inspect |
|
102 |
exit 1 |
|
103 |
end |
|
104 |
end |
|
105 |
end |
|
106 |
end |
|
107 | ||
108 |
def generate_svg_sprite(input_path, sprite_path) |
|
109 |
SvgSprite.call( |
|
110 |
input: input_path, |
|
111 |
name: 'icon', |
|
112 |
css_path: File.join(input_path, 'icons.css'), |
|
113 |
sprite_path: sprite_path, |
|
114 |
optimize: true |
|
115 |
) |
|
116 | ||
117 |
doc = Nokogiri::XML(sprite_path) |
|
118 | ||
119 |
doc.traverse do |node| |
|
120 |
node.keys.each do |attribute| |
|
121 |
node.delete attribute if ["fill", "stroke", "stroke-width"].include?(attribute) |
|
122 |
end |
|
123 |
end |
|
124 | ||
125 |
File.write(sprite_path, doc.to_xml) |
|
126 |
end |
|
127 |
end |