Forked from isaacw/Layer.createChildrenRefs.coffee
Last active
March 5, 2018 20:19
-
-
Save davo/9fcfdbbb3c4cfa75731d199df8ce2880 to your computer and use it in GitHub Desktop.
Creates convenience refs on targeted layers from the design tab so that we don't have to use Layer::childrenWithName.
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
# Layer::createChildrenRefs | |
# Creates convenience refs on targetd layers from the design tab so that we don't have to use Layer::childrenWithName. | |
# Pass recursive=true to do this for all descendant layers while maintaining hierarchy. | |
Layer::createChildrenRefs = (recursive=false, camelCase=true, ignoreLayers=true) -> | |
for layer in @children | |
# Filter any layer with a name starting with '_' as 'private layers'. | |
unless ignoreLayers is false | |
if _.startsWith(layer.name, '_') | |
return true | |
# Get layer name for the key while converting the input to camelCase | |
unless camelCase is false | |
key = _.camelCase layer.name | |
else | |
key = layer.name | |
# Set reference | |
@[key] = layer | |
# Should we also do this for current layer's children? | |
if recursive and layer.children.length > 0 | |
layer.createChildrenRefs(recursive) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment