Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from inVoltag/google-api-v4-migration
Google api v4 migration
- Loading branch information
Showing
6 changed files
with
73 additions
and
99 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,38 @@ | ||
import sketch from 'sketch'; | ||
import {getPreference, getValues, sortedData, getIpsum} from './index'; | ||
import {text, document,selectedLayers, selectedCount, canvasView, selectedArtboard, selectedPage, pluginCache} from './index'; | ||
import syncIpsum from './syncIpsum'; | ||
import { getPreference, getValues, sortedData, getIpsum } from './index'; | ||
import { text, document,selectedLayers, selectedCount, canvasView, selectedArtboard, selectedPage, pluginCache } from './index'; | ||
|
||
var ID = getPreference('spreadsheetID'); | ||
var ID = getPreference('spreadsheetID'), | ||
SHEET = getPreference('sheetName'); | ||
|
||
function createIpsum() { | ||
|
||
var datas = getValues(ID, 1); | ||
var datas = getValues(ID, SHEET); | ||
var awesomeIpsum = getIpsum(datas); | ||
var origin = canvasView.viewCenterInAbsoluteCoordinatesForViewPort(canvasView.viewPort()); | ||
var newText = new text({ | ||
parent: selectedPage, | ||
text: awesomeIpsum[1], | ||
name: 'New ipsum', | ||
style: { | ||
alignment: 0, | ||
borders: [], | ||
alignment: 'left', | ||
borders: [] | ||
}, | ||
frame: { | ||
width: 400, | ||
height: 400 | ||
}, | ||
fixedWidth: 2 | ||
fixedWidth: true | ||
}) | ||
|
||
newText.frame.x = Math.floor((origin.x) - (newText.frame.width / 2)); | ||
newText.frame.y = Math.floor((origin.y) - (newText.frame.height / 2)) | ||
|
||
}; | ||
|
||
if(ID !== 'empty') { | ||
if (ID != null || SHEET != null) { | ||
createIpsum() | ||
} else { | ||
sketch.UI.alert('Synchronize first your ipsums', 'Link your Google spreadsheet via the Sync. menu') | ||
syncIpsum() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,49 @@ | ||
import sketch from 'sketch'; | ||
import {getPreference, savePreference, pluginCache} from './index'; | ||
console.log(getPreference('spreadsheetID')); | ||
|
||
sketch.UI.getInputFromUser( | ||
"Sync. your awesome ipsums from your Google spreadsheet", | ||
{ | ||
description: 'Get collaborative! First publish on the Web (File > Publish on the Web), then copy the URL and paste it below 👇', | ||
numberOfLines: 3, | ||
initialValue: alreadySync() | ||
}, | ||
(err, value) => { | ||
var google = validateURL(); | ||
if (err || value.indexOf(google) == -1) { | ||
return sketch.UI.alert('Houston, there\'s a problem 😓', 'Please, try again.') | ||
} else { | ||
import { getPreference, savePreference, pluginCache } from './index'; | ||
|
||
export default function syncIpsum() { | ||
sketch.UI.getInputFromUser( | ||
"Sync. your awesome ipsums from your Google spreadsheet (1/2)", | ||
{ | ||
description: 'First publish on the Web (File > Publish on the Web), then copy the URL and paste it below 👇', | ||
numberOfLines: 3, | ||
initialValue: getPreference('spreadsheetID') == null ? '' : `https://docs.google.com/spreadsheets/d/${getPreference('spreadsheetID')}` | ||
}, | ||
(err, value) => { | ||
if (err) { | ||
return | ||
} else if (value.indexOf('https://docs.google.com') == -1 || value == undefined) { | ||
return sketch.UI.alert('Watch your URL!', 'Copy and paste the Google spreadsheet URL from your browser bar') | ||
} else { | ||
var ID = getID(value); | ||
savePreference('spreadsheetID', ID); | ||
sketch.UI.message('The ipsums are on the track! 🔥'); | ||
console.log(getPreference('spreadsheetID')) | ||
sketch.UI.getInputFromUser( | ||
"Sync. your awesome ipsums from your Google spreadsheet (2/2)", | ||
{ | ||
description: 'Type the name of the ipsums sheet (⚠️ case sensitive)', | ||
numberOfLines: 1, | ||
initialValue: getPreference('sheetName') == null ? '' : getPreference('sheetName') | ||
}, | ||
(err, value) => { | ||
if (err) { | ||
return | ||
} else if (value == undefined) { | ||
return sketch.UI.alert('Cannot be empty!', 'Copy and paste the name of the sheet') | ||
} else { | ||
savePreference('sheetName', value); | ||
sketch.UI.message('The ipsums are on the track! 🔥') | ||
} | ||
} | ||
) | ||
} | ||
} | ||
} | ||
) | ||
) | ||
}; | ||
|
||
function getID(input) { | ||
|
||
var splitURL = input.split('/'); | ||
var ID = splitURL[5]; | ||
return ID | ||
|
||
}; | ||
|
||
function alreadySync() { | ||
|
||
var ID = getPreference('spreadsheetID'); | ||
var google = validateURL(); | ||
var url = 'https://docs.google.com/spreadsheets/d/'+ ID; | ||
|
||
if (ID == 'empty' || url.indexOf(google) == -1) { | ||
return | ||
} else { | ||
return url | ||
} | ||
|
||
} | ||
|
||
function validateURL() { | ||
|
||
var standardURL = 'https://docs.google.com/'; | ||
var splitURL = standardURL.split('/'); | ||
var getGoogle = splitURL[2]; | ||
return getGoogle | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters