Skip to content

Commit

Permalink
added unicons and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
swapnilsarwe committed Mar 23, 2021
1 parent db7cb22 commit 93dc187
Show file tree
Hide file tree
Showing 1,887 changed files with 293 additions and 1,722 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [7.3, 7.4, 8.0]
laravel: [^8.0, ^7.0]
php: [7.4, 8.0]
laravel: [^8.0]

name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}

name: P${{ matrix.php }} - L${{ matrix.laravel }}

steps:
- name: Checkout code
Expand All @@ -33,6 +34,5 @@ jobs:
run: |
composer require "illuminate/contracts=${{ matrix.laravel }}" --prefer-dist --no-interaction --no-update
composer update --prefer-dist --no-interaction --no-progress
- name: Execute tests
run: vendor/bin/phpunit --verbose
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ For a full list of available icons see [the SVG directory](resources/svg) or pre

## Requirements

- PHP 7.3 or higher
- Laravel 7.14 or higher
- PHP 7.4 or higher
- Laravel 8.0 or higher

## Installation

Expand All @@ -41,19 +41,19 @@ Please refer to [`the upgrade guide`](UPGRADE.md) when updating the library.
Icons can be used as self-closing Blade components which will be compiled to SVG icons:

```blade
<x-uni-alarm-clock/>
<x-uni-paperclip/>
```

You can also pass classes to your icon components:

```blade
<x-uni-alarm-clock class="w-6 h-6 text-gray-500"/>
<x-uni-paperclip class="w-6 h-6 text-gray-500"/>
```

And even use inline styles:

```blade
<x-uni-alarm-clock style="color: #555"/>
<x-uni-paperclip style="color: #555"/>
```

### Raw SVG Icons
Expand All @@ -67,7 +67,7 @@ php artisan vendor:publish --tag=blade-uni --force
Then use them in your views like:

```blade
<img src="{{ asset('vendor/blade-uni/alarm-clock.svg') }}" width="10" height="10"/>
<img src="{{ asset('vendor/blade-uni/paperclip.svg') }}" width="10" height="10"/>
```

### Blade Icons
Expand Down
2 changes: 1 addition & 1 deletion UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ php artisan vendor:publish --tag=blade-uni --force
The new way to reference them is:

```blade
<img src="{{ asset('vendor/blade-uni/alarm-clock.svg') }}" width="10" height="10"/>
<img src="{{ asset('vendor/blade-uni/paperclip.svg') }}" width="10" height="10"/>
```
72 changes: 72 additions & 0 deletions bin/compile.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,81 @@ private function removeAttributes()
}
}

private function replaceSolidPatterns($svgText)
{

// check if exists
preg_match('/<svg.*(fill\=\"currentColor\".*?>)/', $svgText, $matches);

if (count($matches) == 2 && isset($matches[0])) {
return false;
}

// replace it

preg_match('/<svg.*?>/', $svgText, $matches);

if (count($matches) > 0 && isset($matches[0])) {
$source = $matches[0];
$replacement = str_replace('>', ' fill="currentColor">', $source);
$svgText = str_replace($source, $replacement, $svgText);
}
return $svgText;
}

//fill="none" stroke="currentColor"
private function replaceOutlinePatterns($svgText)
{

// check if exists
preg_match('/<svg.*(fill\=\"none\"\sstroke\=\"currentColor\".*?>)/', $svgText, $matches);

if (count($matches) == 2 && isset($matches[0])) {
return false;
}

// replace it

preg_match('/<svg.*?>/', $svgText, $matches);

if (count($matches) > 0 && isset($matches[0])) {
$source = $matches[0];
$replacement = str_replace('>', ' fill="none" stroke="currentColor">', $source);
$svgText = str_replace($source, $replacement, $svgText);
}
return $svgText;
}

private function addAttributes()
{
// for solid icons
$finder = new Finder();
$finder->files()->in(self::RESOURCE_DIR)->name('*.svg');
foreach ($finder as $file) {
$changedText = $this->replaceSolidPatterns($file->getContents());
if ($changedText !== false) {
file_put_contents($file->getRealPath(), $changedText);
} else {
echo 'no changes'.PHP_EOL;
}
}

// // for outline icons
// $finder = new Finder();
// $finder->files()->in(self::RESOURCE_DIR)->name('*-o.svg');
// foreach ($finder as $file) {
// $changedText = $this->replaceOutlinePatterns($file->getContents());
// if ($changedText !== false) {
// file_put_contents($file->getRealPath(), $changedText);
// }
// }
}

public function process()
{
$this->removeAttributes();

$this->addAttributes();
}
}
$svgCleaner = new SvgIconCleaner();
Expand Down
19 changes: 10 additions & 9 deletions bin/compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
set -e

# prepare the source of icons by cloning the repo
TEMP_DIR=tmp
# mkdir -p $TEMP_DIR
TEMP_DIR=blade-icon-temp-dir
DIRECTORY=$(cd `dirname $0` && pwd)

mkdir -p $TEMP_DIR
SOURCE=$TEMP_DIR/unicons
# git clone [email protected]:Iconscout/unicons.git $TEMP_DIR/unicons

DIRECTORY=$(cd `dirname $0` && pwd)
cd $SOURCE
git pull
cd $DIRECTORY/../
RESOURCES=$DIRECTORY/../resources/svg

echo $SOURCE
Expand All @@ -28,15 +31,15 @@ for CATEGORY_DIR in $SOURCE/svg/*; do
then
CONVERTED_ICON_DESTINATION_NAME="${ICON_NAME//\.svg/-o.svg}"
CP_COMMAND='cp '$ICON_DIR' '$RESOURCES/$CONVERTED_ICON_DESTINATION_NAME
$CP_COMMAND
# $CP_COMMAND
elif [[ $CATEGORY_NAME = 'monochrome' ]]
then
CONVERTED_ICON_DESTINATION_NAME="${ICON_NAME//\.svg/-m.svg}"
CP_COMMAND='cp '$ICON_DIR' '$RESOURCES/$CONVERTED_ICON_DESTINATION_NAME
$CP_COMMAND
# $CP_COMMAND
elif [[ $CATEGORY_NAME = 'solid' ]]
then
CONVERTED_ICON_DESTINATION_NAME="${ICON_NAME//\.svg/-s.svg}"
CONVERTED_ICON_DESTINATION_NAME=$ICON_NAME
CP_COMMAND='cp '$ICON_DIR' '$RESOURCES/$CONVERTED_ICON_DESTINATION_NAME
$CP_COMMAND
fi
Expand All @@ -46,8 +49,6 @@ for CATEGORY_DIR in $SOURCE/svg/*; do
done

echo "copied all svgs!"
echo "Removing "$TEMP_DIR
# rm -rf $TEMP_DIR

echo "All Done!"
# echo "Run `php bin/compile.php` to update the svgs"
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
}
],
"require": {
"php": "^7.3|^8.0",
"blade-ui-kit/blade-icons": "^0.5.0",
"illuminate/support": "^7.14|^8.0"
"php": "^7.4|^8.0",
"blade-ui-kit/blade-icons": "^1.0",
"illuminate/support": "^8.0"
},
"require-dev": {
"orchestra/testbench": "^5.0|^6.0",
"phpunit/phpunit": "^8.0|^9.0",
"orchestra/testbench": "^6.0",
"phpunit/phpunit": "^9.0",
"symfony/finder": "^5.2"
},
"autoload": {
Expand Down
1 change: 0 additions & 1 deletion resources/svg/0-plus-o.svg

This file was deleted.

1 change: 0 additions & 1 deletion resources/svg/10-plus-o.svg

This file was deleted.

1 change: 0 additions & 1 deletion resources/svg/12-plus-o.svg

This file was deleted.

1 change: 0 additions & 1 deletion resources/svg/13-plus-o.svg

This file was deleted.

1 change: 0 additions & 1 deletion resources/svg/16-plus-o.svg

This file was deleted.

1 change: 0 additions & 1 deletion resources/svg/17-plus-o.svg

This file was deleted.

1 change: 0 additions & 1 deletion resources/svg/18-plus-o.svg

This file was deleted.

1 change: 0 additions & 1 deletion resources/svg/21-plus-o.svg

This file was deleted.

1 change: 0 additions & 1 deletion resources/svg/3-plus-o.svg

This file was deleted.

1 change: 0 additions & 1 deletion resources/svg/500px-m.svg

This file was deleted.

1 change: 0 additions & 1 deletion resources/svg/500px-o.svg

This file was deleted.

1 change: 0 additions & 1 deletion resources/svg/6-plus-o.svg

This file was deleted.

1 change: 0 additions & 1 deletion resources/svg/abacus-o.svg

This file was deleted.

1 change: 0 additions & 1 deletion resources/svg/accessible-icon-alt-o.svg

This file was deleted.

1 change: 0 additions & 1 deletion resources/svg/adjust-alt-o.svg

This file was deleted.

1 change: 0 additions & 1 deletion resources/svg/adjust-circle-o.svg

This file was deleted.

Loading

0 comments on commit 93dc187

Please sign in to comment.