View Single Post
Old 03-07-2016, 04:24 PM   #10
fidvo
Addict
fidvo ought to be getting tired of karma fortunes by now.fidvo ought to be getting tired of karma fortunes by now.fidvo ought to be getting tired of karma fortunes by now.fidvo ought to be getting tired of karma fortunes by now.fidvo ought to be getting tired of karma fortunes by now.fidvo ought to be getting tired of karma fortunes by now.fidvo ought to be getting tired of karma fortunes by now.fidvo ought to be getting tired of karma fortunes by now.fidvo ought to be getting tired of karma fortunes by now.fidvo ought to be getting tired of karma fortunes by now.fidvo ought to be getting tired of karma fortunes by now.
 
Posts: 309
Karma: 1645952
Join Date: Jun 2012
Device: none
Quote:
Originally Posted by eschwartz View Post
Invoking templates inside GPM is ugly (and slower) why not use this?

Code:
program:

# Initialize repetitive and/or complicated values for later use.
path = re(
	field('#path'),
	'\.',
	'/'
);
seriesid = re(
	field('#seriesid'),
	'\.',
	'/'
);
titleid = re(
	field('#titleid'),
	'\.',
	'/'
);

sidx = finish_formatting(
	field('series_index'),
	'0>3s',
	'',
	'_'
);
subsidx = finish_formatting(
	field('#subseries_index'),
	'0>3s',
	'',
	'_'
);

# Compute final return value.
switch(
	current_library_name(),
	'Library - Main',
	strcat(
		path, '/', sidx, field('#subseries'), subsidx, field('title')
	),
	'Library - Special',
	strcat(
		path, '/', sidx, field('title')
	),
	'Library - In Progress',
	strcat(
		field('author_sort'), '/', field('series'), '/', sidx, field('title')
	),
	strcat(
		path, '/', seriesid, titleid
	)
)
You're right; that does look a lot cleaner, especially since I tend to use similar custom fields in all my libraries, so setting those values outside the main code block makes sense.

I'll have to give this a try.

fidvo is offline   Reply With Quote