Session 21: User code and scripting

Preparation

  • There are no external assets required for this session.

Description

This tutorial examines the use of user code to extend the capabilities of templates in Swift.

Session specific objectives

Adding simple ruby scripts to understand the principles behind its uses. Provide an overview of the Ruby Basics topic guide. User Code tab first look L1.

Chapter 1: Forcing the case of text strings to either upper or lowercase

  • Defining the input and a simple command with user code

Chapter 2: Resizing a word on a text string

  • Finding specific words in a string
  • Using the scale vector command

Chapter 3: Resizing a word on a text string and forcing upper case

  • Mitigating for errors on dynamic text strings

Chapter 4: Concatenating two text strings with different fonts

  • Changing fonts in 1 line of text with 2 inputs

Examples:

# Chapter 1
_textUpper = _textUpper.upcase
_textLower = _textLower.downcase

#Chapter 2
_text.gsub!(/am/,"<sv 30.0>am</sv>")

#Chapter 3
_text.gsub!(/am/,"<sv 30.0>AM</sv>")
_text.gsub!(/AM/,"<sv 30.0>AM</sv>")
_text.gsub!(/pm/,"<sv 30.0>PM</sv>")
_text.gsub!(/PM/,"<sv 30.0>PM</sv>")

#Chapter 4
_userName = "<f FrutigerNext_LT_MediumCn_Bold>" + _userName + "</f> " + _userID  + "<f FrutigerNext_LT_MediumCn_Regular>"

Expected duration

30 minutes

User Level

All new users

Ruby Basics by Darrell James

You can view the Ruby Basics guide here.

 

Session Project

If you want to review Justin Avery's instructor project at this point in the course, you can download the project zip here.