Browse Source

rename dev-inline-svg to dev-util

Byron Jones 6 years ago
parent
commit
02a45033f3
2 changed files with 35 additions and 40 deletions
  1. 34 39
      dev-util
  2. 1 1
      makefile

+ 34 - 39
dev-inline-svg → dev-util

@@ -7,36 +7,29 @@ use warnings;
 use File::Find qw( find );
 use FindBin qw( $RealBin );
 use Mojo::File ();
-use Mojo::Util qw( getopt trim );
+use Mojo::Util qw( trim );
 use YAML::Tiny ();
 
 $| = 1;
 
-my ($inline, $import);
-#<<<
-getopt
-    'inline'   => \$inline,
-    'import:s' => \$import;
-#>>>
-die <<'EOF' unless $inline || $import;
-syntax:
-    dev-inline-svg --inline
-    dev-inline-svg --import <font-awesome pro path>
-EOF
+my ($command, @args) = (lc(shift // ''), @ARGV);
+$command || die <<'EOF';
+syntax: dev-util <command> [command args]
 
-my $templates_path = "$RealBin/web/templates";
+commands:
+    svg-inline          update templates to inline svg
+    svg-import <path>   update svg source from font-awesome
+EOF
 
-my $svg_path = $RealBin . '/web/svg';
-my $fa_path  = $svg_path . '/font-awesome';
-die "failed to find $fa_path\n" unless -d $fa_path;
+#my $templates_path = "$RealBin/web/templates";
+#my $svg_path = $RealBin . '/web/svg';
+#my $fa_path  = $svg_path . '/font-awesome';
+#die "failed to find $fa_path\n" unless -d $fa_path;
 
-if ($inline) {
-    inline_svg();
-} else {
-    import_svg($import);
-}
-
-sub inline_svg {
+if ($command eq 'svg-inline') {
+    my $svg_path       = $RealBin . '/web/svg';
+    my $fa_path        = $svg_path . '/font-awesome';
+    my $templates_path = "$RealBin/web/templates";
 
     # inlines svg images into templates
     # to use, create an svg element with a class name "svg-filename"
@@ -45,6 +38,19 @@ sub inline_svg {
     # other classes and ids will be lost
     # eg. <svg class="svg-sidebar-collapse"></svg>
 
+    sub load_svg {
+        my ($name) = @_;
+        my $file =
+            -e "$fa_path/$name.svg"
+            ? "$fa_path/$name.svg"
+            : "$svg_path/$name.svg";
+        die "failed to find $name.svg\n" unless -e $file;
+        my $svg = Mojo::File->new($file)->slurp();
+        $svg =~ s/^<svg /<svg class="svg-$name" /;
+        $svg =~ s/\s+$//;
+        return $svg;
+    }
+
     my @files;
     find(
         sub {
@@ -70,23 +76,12 @@ sub inline_svg {
         Mojo::File->new($file)->spurt($tmpl);
         say "inline-svg: \e[34mupdated\e[0m ", substr($file, length($RealBin) + 1);
     }
-}
-
-sub load_svg {
-    my ($name) = @_;
-    my $file =
-        -e "$fa_path/$name.svg"
-        ? "$fa_path/$name.svg"
-        : "$svg_path/$name.svg";
-    die "failed to find $name.svg\n" unless -e $file;
-    my $svg = Mojo::File->new($file)->slurp();
-    $svg =~ s/^<svg /<svg class="svg-$name" /;
-    $svg =~ s/\s+$//;
-    return $svg;
-}
 
-sub import_svg {
-    my ($source_path) = @_;
+} elsif ($command eq 'svg-import') {
+    my ($source_path)  = @_;
+    my $svg_path       = $RealBin . '/web/svg';
+    my $fa_path        = $svg_path . '/font-awesome';
+    my $templates_path = "$RealBin/web/templates";
 
     # update svg icons from font-awesome pro
 

+ 1 - 1
makefile

@@ -94,7 +94,7 @@ web/build/hind.min.css: web/hind/hind.sass
 # templates
 
 web/build/inline-svg.updated: web/svg/*.svg web/svg/font-awesome/*.svg web/templates/*.html.ep web/templates/layouts/*.html.ep
-	./dev-inline-svg --inline
+	./dev-util svg-inline
 	touch web/build/inline-svg.updated
 
 # svg