Commits

Lynn Rees committed 6433e55

- new scripts

  • Participants
  • Parent commits 0c9ae15

Comments (0)

Files changed (21)

File scripts/AttrsToChildren.groovy

+// @CacheScriptContent(true)
+// @ExecutionModes({ON_SINGLE_NODE})
+
+c.selecteds.each {
+	it.attributes.names.eachWithIndex { an, idx ->
+		def child = it.createChild(idx)
+		if (an == 'note')
+			child.note = it[an]
+		else
+			child.object = an
+		child.details = it[an]
+	}
+	it.attributes.clear()
+}

File scripts/CapitalizeNode.groovy

+// @CacheScriptContent(true)
+// @ExecutionModes({ON_SINGLE_NODE})
+
+c.selecteds.every { it.text = it.plainText.capitalize() }
+

File scripts/ChildrenToAttrs.groovy

+// @CacheScriptContent(true)
+// @ExecutionModes({ON_SINGLE_NODE})
+
+c.selecteds.each {
+	it.children.eachWithIndex { nc, idx ->
+		if (nc.details)
+			it.attributes.add(nc.plainText, nc.details)
+		else if (nc.link)
+			it.attributes.add(nc.plainText, nc.link)
+		if (nc.note)
+			it['note'] = nc.note
+		nc.delete()
+	}
+}
+

File scripts/JoinAndReplaceFirst.groovy

+// @CacheScriptContent(true)
+// @ExecutionModes({ON_SINGLE_NODE})
+
+def mark = ui.showInputDialog(node.delegate, 'Enter characters to join nodes and replace first node on...', '')
+c.selecteds.first().text = c.selecteds.tail().collect {
+	it.plainText.trim()
+}.join(mark ? mark : '')
+c.selecteds.tail().each { it.delete() }
+

File scripts/JoinAndReplaceLast.groovy

+// @CacheScriptContent(true)
+// @ExecutionModes({ON_SINGLE_NODE})
+
+def mark = ui.showInputDialog(node.delegate, 'Enter characters to join nodes and replace first node on...', '')
+c.selecteds.last().text = c.selecteds.head().collect {
+	it.plainText.trim()
+}.join(mark ? mark : '')
+c.selecteds.head().each { it.delete() }

File scripts/JoinOnChars.groovy

+// @CacheScriptContent(true)
+// @ExecutionModes({ON_SINGLE_NODE})
+
+def joinText(c, node, mark) {
+    node.text = c.selecteds.collect { it.plainText.trim() }.join(mark)
+    c.selecteds.tail().each { it.delete() }
+}
+def joinPrompt(c, ui, node, msg) {
+    def mark = ui.showInputDialog(node.delegate, msg, '')
+    joinText(c, node, (mark ? mark : ''))
+}
+joinPrompt(c, ui, node, 'Enter characters to join nodes on...')

File scripts/JoinOnComma.groovy

+// @CacheScriptContent(true)
+// @ExecutionModes({ON_SINGLE_NODE})
+
+def joinText(c, node, mark) {
+    node.text = c.selecteds.collect { it.plainText.trim() }.join(mark)
+    c.selecteds.tail().each { it.delete() }
+}
+joinText(c, node, ', ')
+

File scripts/JoinOnPeriod.groovy

+// @CacheScriptContent(true)
+// @ExecutionModes({ON_SINGLE_NODE})
+
+def joinText(c, node, mark) {
+    node.text = c.selecteds.collect { it.plainText.trim() }.join(mark)
+    c.selecteds.tail().each { it.delete() }
+}
+joinText(c, node, '. ')
+

File scripts/JoinOnSpace.groovy

+// @CacheScriptContent(true)
+// @ExecutionModes({ON_SINGLE_NODE})
+
+def joinText(c, node, mark) {
+    node.text = c.selecteds.collect { it.plainText.trim() }.join(mark)
+    c.selecteds.tail().each { it.delete() }
+}
+joinText(c, node, ' ')
+

File scripts/LocalLinkBack.groovy

+// @CacheScriptContent(true)
+// @ExecutionModes({ON_SINGLE_NODE})
+
+c.selecteds.every { it.text = it.plainText.toLowerCase() }

File scripts/LowerCaseNode.groovy

+// @CacheScriptContent(true)
+// @ExecutionModes({ON_SINGLE_NODE})
+
+c.selecteds.every {	it.text = it.plainText.toUpperCase() }

File scripts/SplitBeforeChars.groovy

+// @CacheScriptContent(true)
+// @ExecutionModes({ON_SINGLE_NODE})
+
+def splitText(c, mark) {
+	c.selecteds.every { ts ->
+		ts.plainText.split(mark).collect { it.trim() }.eachWithIndex {
+			txt, idx ->
+			if (idx == 0)
+    			ts.text = txt
+			ts.createChild(txt)
+		}
+	}
+}
+
+def splitPrompt(ui, node, pattern, msg) {
+	def mark = ui.showInputDialog(node.delegate, msg, '')
+	splitText(c, pattern ? (pattern + mark + ')') : (mark ? mark : ''))
+}
+
+splitPrompt(ui, node, '(?=', 'Enter characters to split node text before...')
+

File scripts/SplitOnChars.groovy

+// @CacheScriptContent(true)
+// @ExecutionModes({ON_SINGLE_NODE})
+
+def splitText(c, mark) {
+	c.selecteds.every { ts ->
+		ts.plainText.split(mark).collect { it.trim() }.eachWithIndex {
+			txt, idx ->
+			if (idx == 0)
+    			ts.text = txt
+			ts.createChild(txt)
+		}
+	}
+}
+
+def splitPrompt(ui, node, pattern, msg) {
+	def mark = ui.showInputDialog(node.delegate, msg, '')
+	splitText(c, pattern ? (pattern + mark + ')') : (mark ? mark : ''))
+}
+
+splitPrompt(ui, node, '', 'Enter characters to split node text on...')
+

File scripts/SplitOnComma.groovy

+// @CacheScriptContent(true)
+// @ExecutionModes({ON_SINGLE_NODE})
+
+def splitText(c, mark) {
+	c.selecteds.every { ts ->
+		ts.plainText.split(mark).collect { it.trim() }.eachWithIndex {
+			txt, idx ->
+			if (idx == 0)
+    			ts.text = txt
+			ts.createChild(txt)
+		}
+	}
+}
+
+
+splitText(c, ',')
+
+

File scripts/SplitOnPeriod.groovy

+// @CacheScriptContent(true)
+// @ExecutionModes({ON_SINGLE_NODE})
+
+def splitText(c, mark) {
+	c.selecteds.every { ts ->
+		ts.plainText.split(mark).collect { it.trim() }.eachWithIndex {
+			txt, idx ->
+			if (idx == 0)
+    			ts.text = txt
+			ts.createChild(txt)
+		}
+	}
+}
+
+
+splitText(c, '\\.')
+

File scripts/SplitOnSpace.groovy

+// @CacheScriptContent(true)
+// @ExecutionModes({ON_SINGLE_NODE})
+
+def splitText(c, mark) {
+	c.selecteds.every { ts ->
+		ts.plainText.split(mark).collect { it.trim() }.eachWithIndex {
+			txt, idx ->
+			if (idx == 0)
+    			ts.text = txt
+			ts.createChild(txt)
+		}
+	}
+}
+
+
+splitText(c, ' ')
+

File scripts/SyncStyleWithIcons.groovy

+// @CacheScriptContent(true)
+// @ExecutionModes({ON_SINGLE_NODE})
+
+def thisStyle = node?.style?.style
+def thisIcons = node?.icons?.icons
+def styleIcons = thisStyle ? node?.style?.styleNode?.icons?.icons : null
+c.selecteds.findAll { it?.id != node?.id }.each {
+   if (thisStyle)
+      it?.style?.style = thisStyle
+    // sync any local icons
+    if (thisIcons)
+      thisIcons?.every { icon -> it?.icons?.add(icon) }
+    // sync any style icons
+     if (styleIcons)
+       styleIcons?.every { icon -> it?.icons?.add(icon) }
+}
+

File scripts/TrimFirstChars.groovy

+// @CacheScriptContent(true)
+// @ExecutionModes({ON_SINGLE_NODE})
+
+
+def trimPrompt(c, ui, node, pattern, start, msg) {
+	def mark = ui.showInputDialog(node.delegate, msg, '')
+	mark = start ? pattern + (mark ? mark : '') : (mark ? mark : '') + pattern
+	c.selecteds.every { it.text = it.plainText.replaceFirst(mark, '') }
+}
+
+
+trimPrompt(c, ui, node, '^{1}', true, 'Enter characters to trim from start of node text...')
+

File scripts/TrimLastChars.groovy

+// @CacheScriptContent(true)
+// @ExecutionModes({ON_SINGLE_NODE})
+
+
+def trimPrompt(c, ui, node, pattern, start, msg) {
+	def mark = ui.showInputDialog(node.delegate, msg, '')
+	mark = start ? pattern + (mark ? mark : '') : (mark ? mark : '') + pattern
+	c.selecteds.every { it.text = it.plainText.replaceFirst(mark, '') }
+}
+
+
+trimPrompt(c, ui, node, '{1}$', false, 'Enter characters to trim from end of node text...')
+

File scripts/UpperCaseNode.groovy

+// @CacheScriptContent(true)
+// @ExecutionModes({ON_SINGLE_NODE})
+
+c.selecteds.every {	it.text = it.plainText.toUpperCase() }
 if __name__ == '__main__':
     for fn in os.listdir('spine'):
         if fn.endswith('spine'):
-            with open(fn, 'r') as f:
+            with open(os.path.join('spine', fn), 'r') as f:
                 with open(
                     os.path.join('scripts', fn.rstrip('.spine').lstrip('_')
                 ), 'w') as nf: