Name

jsqn — return a string for use in JavaScript, quoted, without variables substituted

ATTRIBUTES

Attribute Pos. Req. Default Description
interpolate     0 interpolate input?
reparse     0 interpolate output?
hide     0 Hide the tag return value?

DESCRIPTION

[jsqn] tag quotes (escapes) strings (without performing variable substitution), for use in JavaScript code blocks.

This is mostly used for long strings which are hard to prepare manually.

BEHAVIOR

This tag does not appear to be affected by, or affect, the rest of Interchange.

EXAMPLES

Example: Basic example

Here's an example of JavaScript code and the output it would generate, once expanded by Interchange:

<script>
  var astring = 'just an insert';
  var somevar = [jsqn] Big long string you don't
  want to have to quote for JS, and you don't want to
  insert the variable $astring.[/jsqn];
</script>

Expands to:

<script>
var astring = 'just an insert';
var somevar = " Big long string you don't" +
  '  want to have to quote for JS, and you don't want to' +
  '  insert the variable $astring.';
</script>

NOTES

AVAILABILITY

jsqn is available in Interchange versions:

4.6.0-5.9.0 (git-head)

SOURCE

Interchange 5.9.0:

Source: code/UI_Tag/jsqn.coretag
Lines: 30


# Copyright 2002-2007 Interchange Development Group and others
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.  See the LICENSE file for details.
# 
# $Id: jsqn.coretag,v 1.7 2007-03-30 23:40:54 pajamian Exp $

UserTag jsqn hasEndTag
UserTag jsqn NoReparse
UserTag jsqn PosNumber 0
UserTag jsqn Version   $Revision: 1.7 $
UserTag jsqn Routine   <<EOR
sub {
my $text = shift;
$text =~ s/^[ \t\r]*\n//;
my @lines = split /\r?\n/, $text;

for(@lines) {
  ( $_ !~ /'/ and s/\r/\\r/g, $_ = qq{'$_'} )
    or
  ( $_ !~ /"/ and s/\r/\\r/g, $_ = qq{"$_"} )
    or 
  ( s/'/\\'/g,  s/\r/\\r/g, $_ = qq{'$_'} );
}
@lines = "''" unless @lines;
return join (" +\n", @lines);
}
EOR

AUTHORS

Mike Heins, Interchange Development Group

SEE ALSO

jsq(7ic)

DocBook! Interchange!