Editorial Workflows

Template...

public workflow

Install Workflow...

This workflow contains at least one Python script. Only use it if you trust the person who shared this with you, and if you know exactly what it does.

I understand, install the workflow!

This is a workflow for Editorial, a Markdown and plain text editor for iOS. To download it, you need to view this page on a device that has the app installed.

Description: This workflow inserts a taskpaper project from a template, which are defined in /Dropbox/Task Management/Templates.taskpaper.

When the workflow is run, the user will be asked to select a project from all the projects found in /Dropbox/Task Management/Templates.taskpaper, and if any variables are found in this project, the user will be asked to enter values for these variables. (Variables can be defined inside the project as a {variable name} inside curly braces.)

An example /Dropbox/Task Management/Templates.taskpaper file:

Brush teeth:
- Get out toothbrush and toothpaste
- Put toothpaste onto toothbrush
- Scrub teeth using toothbrush

Buy some {fruit type} from {store name}:
- Go to {store name}
- Walk to produce section
- Pick up some {fruit type}
- Pay for it

The Python code in this workflow is licensed under the MIT License:

Copyright (c) 2017 Duncan MacIntyre

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Shared by: Duncan MacIntyre

Comments: Comment Feed (RSS)

There are no comments yet.

+ Add Comment

Workflow Preview
Run Python Script ?
Source Code
# Insert Taskpaper Project from Template
# A workflow for the iOS text editor Editorial
# Copyright (c) 2017 Duncan MacIntyre

# It is recommended to have an understanding of taskpaper before continuing:
# http://omz-software.com/editorial/docs/ios/editorial_writing_todo_lists.html

# This script will allow the user to define taskpaper "templates" for projects, set in 
# /Task Management/Templates.taskpaper in Dropbox. (Their syntax is the same as for regular taskpaper
# projects.) "Variables" can be defined inside of {}

# some terms used in comments:
# - the Templates.taskpaper file is defined as /Task Management/Templates.taskpaper in Dropbox
# - a project is defined as a taskpaper project in Templates.taskpaper
# - a project name is defined as the first line of a taskpaper project, minus the :
# - a project's contents are defined as the whole project, including the first line, tasks, and notes
# - a variable is defined as {variable name} in the Templates.taskpaper file, and the text that will
#   eventually replace this
# - a variable name is defined as the text between { and } for each variable defined in the
#   Templates.taskpaper file

import re
import editor
import dialogs

# the following code:
# 1. gets the contents of the Templates.taskpaper file
# 2. uses a regular expression to find all occurences of a project
# 3. creates a dictionary called templates with items <project name>:<project contents>
templates = {i[1]:i[0] for i in re.findall('((.+):(?:\n.+)+)', editor.get_file_contents('/Task Management/Templates.taskpaper', 'dropbox'))}

# the following code:
# 1. gets the project names (the keys in the templates dictionary)
# 1. uses Editorial's built-in dialogs module to ask the user to choose from a list of these
chosenTemplate = dialogs.list_dialog(title = 'Choose a template:', items = templates.keys())

# if dialog was not cancelled
if chosenTemplate is not None:
	
	# get the project contents corresponding to the chosen project name (the value relating to the chosen key), store this under chosenTemplate
	chosenTemplate = templates[chosenTemplate]
	
	# set up a list to hold variable names
	# (the user will be asked to enter values for these)
	variableNames = []
	# use a regular expression to find each variable in the template contents
	for i in re.finditer('{(.+?)}', chosenTemplate):
		# unless it has already been done, append each variable name to the variableNames list
		if i.group(1) not in variableNames: variableNames.append(i.group(1))
	
	# uses Editorial's built-in dialogs module to ask the user to fill out a form,
	# where there is one text field for each variable found in the variableNames list, store
	# input in variableValues
	# (if no variables are used, an empty dictionary is stored in variableValues instead)
	variableValues = dialogs.form_dialog(title='Enter values for the following variables:', fields=[{'type':'text', 'key':i, 'title':(i.title() + ':')} for i in variableNames]) if len(variableNames) > 0 else {}
	
	# if dialog was not cancelled
	if variableValues is not None:
		# use str.format() to insert the variable values into the template, insert the resulting
		# text into the open document
		editor.insert_text(chosenTemplate.format(**variableValues))