Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davo/9fcfdbbb3c4cfa75731d199df8ce2880 to your computer and use it in GitHub Desktop.
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.
# 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