Skip to content

Commit

Permalink
Merge branch 'removeDimensionsPlugin' of git://github.com/bennyschude…
Browse files Browse the repository at this point in the history
…l/svgo into addClassesToSVGElement
  • Loading branch information
GreLI committed Jun 21, 2015
2 parents a7f62d8 + 0a3ee55 commit 62a0547
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .svgo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ plugins:
- sortAttrs
- removeTitle
- removeDesc
- addClassesToSVGElement
- removeDimensions
- addClassesToSVGElement
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Today we have:
* [ [ convertShapeToPath](https://github.com/svg/svgo/blob/master/plugins/convertShapeToPath.js) ] convert some basic shapes to path
* [ [ sortAttrs](https://github.com/svg/svgo/blob/master/plugins/sortAttrs.js) ] sort element attributes for epic readability (disabled by default)
* [ [ transformsWithOnePath](https://github.com/svg/svgo/blob/master/plugins/transformsWithOnePath.js) ] apply transforms, crop by real width, center vertical alignment and resize SVG with one Path inside (disabled by default)
* [ [ removeDimensions](https://github.com/svg/svgo/blob/master/plugins/removeDimensions.js) ] remove width/height attributes if viewBox is present (disabled by default)

Want to know how it works and how to write your own plugin? [Of course you want to](https://github.com/svg/svgo/blob/master/docs/how-it-works/en.md).

Expand Down
1 change: 1 addition & 0 deletions README.ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ SVGO имеет расширяемую архитектуру, в которой
* [ [ convertShapeToPath](https://github.com/svg/svgo/blob/master/plugins/convertShapeToPath.js) ] конвертирование простых форм в Path
* [ [ sortAttrs](https://github.com/svg/svgo/blob/master/plugins/sortAttrs.js) ] сортировка атрибутов элементов для удобочитаемости (выключено по умолчанию)
* [ [ transformsWithOnePath](https://github.com/svg/svgo/blob/master/plugins/transformsWithOnePath.js) ] применение трансформаций, обрезка по реальной ширине, вертикальное выравнивание по центру и изменение размеров SVG с одним Path внутри
* [ [ removeDimensions](https://github.com/svg/svgo/blob/master/plugins/removeDimensions.js) ] удаляет атрибуты width/height при наличии viewBox (выключено по умолчанию)

Хотите узнать, как это работает и как написать свой плагин? [Конечно же, да!](https://github.com/svg/svgo/blob/master/docs/how-it-works/ru.md).

Expand Down
32 changes: 32 additions & 0 deletions plugins/removeDimensions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict';

exports.type = 'perItem';

exports.active = false;

exports.description = 'removes width and height in presence of viewBox';

/**
* Remove width/height attributes when a viewBox attribute is present.
*
* @example
* <svg width="100" height="50" viewBox="0 0 100 50">
* ↓
* <svg viewBox="0 0 100 50">
*
* @param {Object} item current iteration item
* @return {Boolean} if true, with and height will be filtered out
*
* @author Benny Schudel
*/
exports.fn = function(item) {

if (
item.isElem('svg') &&
item.hasAttr('viewBox')
) {
item.removeAttr('width');
item.removeAttr('height');
}

};
9 changes: 9 additions & 0 deletions test/plugins/removeDimensions.01.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions test/plugins/removeDimensions.02.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions test/plugins/removeDimensions.03.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 62a0547

Please sign in to comment.