[css_normalizeurls]

Description

Link: [css_normalizeurls]
Author: Jason Huck
Category: File
Version: 8.5.x
License: Public Domain
Posted: Sep. 22, 2008
Updated: Sep. 22, 2008
More by this author...

Returns a version of the given CSS file with all relative URLs converted to absolute ones. Requires [url_normalize].

Parameters

none


Sample Usage

var('newcss') = css_normalizeurls('/path/to/file.css');
						

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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
define_tag(
	'normalizeurls',
	-namespace='css_',
	-req='in',
	-priority='replace',
	-encodenone,
	-description='Returns a version of the given CSS file with all relative URLs converted to absolute ones.'
);
	fail_if(!#in->endswith('.css'), -1, 'File does not have a .css extension.');

	local('file') = string(include_raw(#in));
	local('base') = string(#in)->removetrailing(#in->split('/')->last)&;
	local('regex') = regexp('url\\([\'"]?(?!/|http)(.+)?[\'"]?\\)', -input=#file);

	while(#regex->find);
		local('replacement') = 'url(' + url_normalize(#regex->matchstring(1), #base) + ')';
		#regex->appendreplacement(#replacement);
	/while;
	
	#regex->appendtail;
	return(#regex->output);
/define_tag;

 

Related Tags



Comments

none

Email:


Password:



Newest

Most Popular

Support tagSwap.net