Skip to content

Commit

Permalink
never reduce artboard dimensions (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
bchmn authored Apr 26, 2018
1 parent 0deaf3a commit e2f6370
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 109 deletions.
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"printWidth": 120,
"printWidth": 100,
"tabWidth": 2,
"singleQuote": true,
"trailingComma": "es5"
Expand Down
40 changes: 0 additions & 40 deletions Legend.sketchplugin/Contents/Sketch/cleanUp.js

This file was deleted.

21 changes: 21 additions & 0 deletions Legend.sketchplugin/Contents/Sketch/cleanup/legends.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const { LEGEND_CONTENT_NAME, LEGEND_BADGES_NAME } = require('../constants');
const { restoreArtboardDimensions } = require('./restoreArtboardDimensions');
const { findLayer } = require('../utils/layers');

const getLayersToRemove = artboard => [
findLayer(artboard, LEGEND_CONTENT_NAME),
findLayer(artboard, LEGEND_BADGES_NAME),
].filter(Boolean);

function cleanUpLegend(artboard) {
restoreArtboardDimensions(artboard);
getLayersToRemove(artboard).forEach(layer => layer.removeFromParent());
}

function cleanUpLegends(artboards) {
artboards.forEach(cleanUpLegend);
}

module.exports = {
cleanUpLegends,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const { LEGEND_CONTENT_NAME } = require('../constants');
const { findLayer } = require('../utils/layers');
const adjustLayerFrame = require('../utils/adjustLayerFrame');

function restoreArtboardDimensions(artboard) {
const legendContentGroup = findLayer(artboard, LEGEND_CONTENT_NAME);
if (!legendContentGroup) {
return;
}

adjustLayerFrame(artboard, {
height: artboard.frame().height() - legendContentGroup.frame().height(),
});
}

module.exports = {
restoreArtboardDimensions,
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const createSymbolsDictionary = require('../utils/createSymbolsDictionary');
const Promifill = require('../utils/promifill');
const { sketchWaitForCompletion } = require('../utils/async');
const legendifyArtboards = require('../legendifyArtboard/legendifyArtboards');
const { cleanUpLegends } = require('../cleanUp');
const { cleanUpLegends } = require('../cleanup/legends');

const addLegends = ({ document }) => {
const symbolsDictionary = createSymbolsDictionary(document.documentData().allSymbols());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const legendifyArtboards = require('../legendifyArtboard/legendifyArtboards');
const { cleanUpLegends } = require('../cleanUp');
const { cleanUpLegends } = require('../cleanup/legends');
const getSelectedArtboards = require('../utils/getSelectedArtboards');
const createSymbolsDictionary = require('../utils/createSymbolsDictionary');
const { sketchWaitForCompletion } = require('../utils/async');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const adjustArtboardPositions = require('../utils/adjustArtboardPositions');
const { cleanUpLegends } = require('../cleanUp');
const { cleanUpLegends } = require('../cleanup/legends');

module.exports = ({ document }) => {
coscript.shouldKeepAround = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const getSelectedArtboards = require('../utils/getSelectedArtboards');
const adjustArtboardPositions = require('../utils/adjustArtboardPositions');
const { cleanUpLegends } = require('../cleanUp');
const { cleanUpLegends } = require('../cleanup/legends');

module.exports = context => {
coscript.shouldKeepAround = false;
Expand Down
64 changes: 0 additions & 64 deletions Legend.sketchplugin/Contents/Sketch/utils/calculateArtboardSize.js

This file was deleted.

6 changes: 6 additions & 0 deletions Legend.sketchplugin/Contents/Sketch/utils/layers.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const isSketchStringsEqual = require('./isSketchStringsEqual');

const getLayersCache = layer =>
Array.from(layer.layers())
.map(layer => {
Expand All @@ -11,6 +13,10 @@ const getLayersCache = layer =>
})
.sort((a, b) => a.y - b.y || a.x - b.x);

const findLayer = (layer, name) =>
Array.from(layer.layers()).find(l => isSketchStringsEqual(l.name(), name));

module.exports = {
getLayersCache,
findLayer,
};

0 comments on commit e2f6370

Please sign in to comment.