-
Notifications
You must be signed in to change notification settings - Fork 0
/
svg-to-sass-variable.sh
executable file
·50 lines (42 loc) · 1.33 KB
/
svg-to-sass-variable.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
# Get the source name
function get_source_name() {
echo $1 | cut -d'.' -f 1 | rev | cut -d'/' -f 1 | rev
}
# Remove lines breaks and white spaces
function trim_content() {
tr -s '\n' ' ' < $1
}
# Create the Sass variable
function create_sass_variable() {
source_name=$( get_source_name "$1" )
icon_source=$( trim_content "$1" )
printf "\$svg-%s: \'%s\';\n" "$source_name" "$icon_source"
}
# Make a Sass variable for each SVG file
function create_sass_variables_from_svg() {
for svg_file in $(find $1 -type f -iname "*.svg")
do
create_sass_variable $svg_file >> $target_file
done
}
# Define target file
if [ -z $1 ]; then
echo "Please define a target file"
else
target_file="$1"
fi
# Clear the existing file
> $target_file
# Print comments
printf "// =============================================================================\n" >> $target_file
printf "// SVG TO SASS VARIABLES\n" >> $target_file
printf "// =============================================================================\n" >> $target_file
printf "// This file is automatically generated from svg-to-sass-variable.sh\n\n" >> $target_file
# Run function with import argument
if [ -z $2 ]; then
echo "Please define a input directory"
else
create_sass_variables_from_svg "$2"
echo "Your variables is located at $1"
fi