Skip to content

Commit

Permalink
Merge pull request #8 from ouun/master
Browse files Browse the repository at this point in the history
* enhance(sagesvg): Allow setting default SVG 'attributes' via config file
* chore(deps): Bump dependencies
* chore(license): Bump license year
* chore(deps): Bump minimum PHP version to match Acorn
  • Loading branch information
Log1x authored Apr 30, 2020
2 parents 074f8e1 + 7946b74 commit 40cf359
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 11 deletions.
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 Brandon Nifong
Copyright (c) 2020 Brandon Nifong

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
![CircleCI](https://img.shields.io/circleci/build/gh/Log1x/sage-svg.svg?style=flat-square)
[![Total Downloads](https://poser.pugx.org/log1x/sage-svg/downloads)](https://packagist.org/packages/log1x/sage-svg)

Sage SVG is a simple package for using inline SVGs in your Sage 10 projects.
Sage SVG is a simple package for using inline SVGs in your Sage 10 projects.

## Requirements

- [Sage](https://github.com/roots/sage) >= 10.0
- [PHP](https://secure.php.net/manual/en/install.php) >= 7.2
- [PHP](https://secure.php.net/manual/en/install.php) >= 7.2.5
- [Composer](https://getcomposer.org/download/)

## Installation
Expand Down Expand Up @@ -56,7 +56,7 @@ $image = get_svg('app/uploads/2019/07/logo.svg', 'w-32 h-auto');
$image = get_svg(
get_field('logo_svg'),
'my-logo'
);
);
```

### App Container
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
]
},
"require": {
"php": ">=7.2"
"php": ">=7.2.5"
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.5"
Expand Down
13 changes: 7 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions config/svg.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@

'class' => '',

/*
|--------------------------------------------------------------------------
| Attributes
|--------------------------------------------------------------------------
|
| Here you can specify default attributes to be added on all inlined SVGs.
| ↪ <https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute>
|
*/

'attributes' => [
// 'stroke-width' => '1.5',
],

/*
|--------------------------------------------------------------------------
| Directives
Expand Down
6 changes: 6 additions & 0 deletions src/SageSvg.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class SageSvg
'path' => '',
'class' => '',
'directives' => '',
'attributes' => [],
];

/**
Expand Down Expand Up @@ -161,6 +162,11 @@ protected function buildClass($class)
*/
protected function buildAttributes($attrs = [])
{
$attrs = array_merge(
$this->config->get('attributes', []),
$attrs
);

if (empty($attrs)) {
return '';
}
Expand Down
5 changes: 5 additions & 0 deletions src/helpers.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php

/**
* Sage SVG Helpers
*/

use Log1x\SageSvg\SageSvg;

use function Roots\app;
Expand All @@ -12,6 +16,7 @@
* @param array $attrs
* @return string
*/

if (! function_exists('get_svg')) {
function get_svg($image, $class = '', $attrs = [])
{
Expand Down

0 comments on commit 40cf359

Please sign in to comment.