Inherits from NSObject
Declared in GMTheme.h

Overview

GMTheme represents a syntax highlighting theme. The responsibilities of this class include loading a representation of a theme from a stored file system location as well as actually formatting strings.

If you wish to subclass or replace GMTheme in your application (a usefull alternative in some applications would surely be a NSUserDefaults based variant for allowing users to customize the theme), the only method that this object has to respond to is formatString:forToken:. This method must return an appropriately formated NSAttributedString based on the token name. It also must set the custom attribute GMToken to the value of the token.

Serialization Format

d

Tasks

Creating a theme from a filesystem representation

Creating a theme programatically

Using a theme

Class Methods

themeAtPath:

Loads a theme plist from a given path.

+ (id)themeAtPath:(NSString *)path

Parameters

path

The accessible filesystem path where to find the theme declaration.

Return Value

Returns a new GMTheme instance if the file was found and parsed properly, otherwise nil.

Declared In

GMTheme.h

themeAtURL:

Loads a theme plist from a given URL.

+ (id)themeAtURL:(NSURL *)url

Parameters

url

The accessible url where to find the theme declaration.

Return Value

Returns a new GMTheme instance if the file was found and parsed properly, otherwise nil.

Declared In

GMTheme.h

themeFromBundleWithName:

Loads a theme plist from the application bundle.

+ (id)themeFromBundleWithName:(NSString *)name

Parameters

name

The name of the theme.

Return Value

Returns a new GMTheme dictionary instance if the file was found and parsed properly, otherwise nil.

Discussion

This is a useful shorthand method when using the provided theme bundles as these will by default reside in the applications resource folder and have the .theme extension. This method thus allows to find such bundles simply by their theme name.

Declared In

GMTheme.h

Instance Methods

defaultAttributes

Returns the attributes that should be used for the default string.

- (NSDictionary *)defaultAttributes

Return Value

A dictionary of attributes that go into NSAttributedString

Discussion

The default string is the string that isn’t categorized as any particular token.

Declared In

GMTheme.h

formatString:forToken:

Returns a formatted string based on the theme settings for the given token.

- (NSAttributedString *)formatString:(NSAttributedString *)string forToken:(NSString *)token

Parameters

string

The input string that should be formatted.

token

The name of the token which should match the language definition.

Return Value

An attributed string with appropriate formatting applied.

Discussion

Also has to set the custom attribute GMToken with the token string in order for other methods to be able to directly understand the parse.

Declared In

GMTheme.h

initWithDictionary:

Processes a dictionary, turning certain key value pairs into the appropriate data types for NSAttributedString.

- (id)initWithDictionary:(NSDictionary *)dict

Parameters

dict

The theme definition dictionary.

Return Value

Returns a new GMTheme.

Declared In

GMTheme.h

setValue:forAttribute:inToken:

Modifies a property for a token without processing.

- (void)setValue:(id)value forAttribute:(NSString *)attribute inToken:(NSString *)token

Parameters

value

The value of the attribute.

attribute

A key that will go into NSAttributedString’s attributes property.

token

The token you want this setting to apply to. Use * to modify the defaultAttributes.

Discussion

This is usefull for specifying things that the current format doesn’t support like colors with alpha values or fonts created with a matrix.

Declared In

GMTheme.h