Skip to content

Commit

Permalink
Backwards compatibility with Sketch 43
Browse files Browse the repository at this point in the history
  • Loading branch information
rihardsgravis committed May 18, 2017
1 parent 5fcb96b commit f92b664
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
14 changes: 10 additions & 4 deletions Slinky.sketchplugin/Contents/Sketch/Slinky.js

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

4 changes: 3 additions & 1 deletion source/slinky/Slinky.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ function exportHTML(context?: SketchContext) {
const artboard = context.document.currentPage().currentArtboard()
const command = context.command

const sketchVersion = parseFloat(context.api().version)

if(!artboard){
dialog("Select an artboard first!", "⚠️ Slinky")
return
Expand All @@ -22,7 +24,7 @@ function exportHTML(context?: SketchContext) {

if(!exportPath) return

const content = convert(artboard, command)
const content = convert(artboard, command, sketchVersion)

const result = saveFile(content.table, exportPath)

Expand Down
7 changes: 4 additions & 3 deletions source/slinky/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import clone from "lodash-es/clone"
import { rgbaToHex, NSrgbaToHex, isURL, formatLink, indent, expandCSS, contractCSS, isCircle } from "./helpers"
import { template } from "./layout"

export function convert(artboard: MSArtboardGroup, command: MSPluginCommand){
export function convert(artboard: MSArtboardGroup, command: MSPluginCommand, sketchVersion: number){

// Get all visible layers from the artboard
const data = sketchToLayers(artboard.layers(), null, command)
Expand Down Expand Up @@ -38,10 +38,11 @@ export function convert(artboard: MSArtboardGroup, command: MSPluginCommand){
depth: 3
})

const bodyBackground = rgbaToHex(artboard.backgroundColor())

const bodyBackground = (sketchVersion < 44) ? artboard.backgroundColorGeneric() : artboard.backgroundColor()

return {
table: template(bodyBackground, table),
table: template(rgbaToHex(bodyBackground), table),
assets: data.assets
}

Expand Down
6 changes: 6 additions & 0 deletions source/typings/Sketch.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ interface MSArtboardGroup{
objectID(): string
layers(): MSLayer[]
name(): string
backgroundColorGeneric(): {
red(): number,
green(): number,
blue(): number,
alpha(): number
}
backgroundColor(): {
red(): number,
green(): number,
Expand Down

0 comments on commit f92b664

Please sign in to comment.