Lasso Soft Inc. > Home

[file_pathfromroot]

Linkfile_pathfromroot
AuthorJason Huck
CategoryFile
Version8.x
Licensehttp://opensource.org/licenses/artistic-license.php
Posted26 Oct 2005
Updated16 Jan 2006
More by this author...

Description

Converts a relative path to a root path.

Sample Usage

file_pathfromroot('../../images/foo.gif');

-> /images/foo.gif

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.

define_tag(
	'pathfromroot',
	-namespace='file_',
	-priority='replace',
	-description='Converts a relative path to a root path.'
);
	fail_if(
		!params->size || !params->first->isa('string'),
		-1,
		'[file_pathfromroot] requires a file path as a parameter.'
	);
	
	local('in' = params->first);
	
	if(#in->beginswith('/'));
		return(#in);
	else(#in->beginswith('../'));
		local('steps' = #in->split('../')->size - 1);
		local('out' = '/');
		
		iterate(response_path->split('/'), local('i'));
			loop_count > 1 ? #out += #i + '/';
			loop_count == #steps ? loop_abort;
		/iterate;
		
		#out += #in;
		return(#in);
	else;
		return(response_path + #in);
	/if;
/define_tag;

Related Tags

Comments

No comments

Please log in to comment

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2014 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft