Can't insert Javascript/CSS string into HTML

Microsoft Windows xp professional editio...
September 21, 2009 at 01:18:31
Specs: Windows XP
I'm trying to write a build script that will:
1. Minify JS and CSS files
2. Read them into variables
3. Insert those strings into HTML

The first 2 steps are successful, but I am unable to successfully insert the strings. I've found that if I just try to insert a string with no spaces or special characters, it will work. But once I try to insert the JS or CSS strings, it seems they are being expanded during the call and then parsed.

Here is my code:

SETLOCAL EnableDelayedExpansion

:: Minify JS
java -jar yuicompressor-2.4.2.jar --type js --nomunge "%~dp0src\main.js" > temp1.txt
SET /p MAINJS= < temp1.txt

:: Minify CSS
java -jar yuicompressor-2.4.2.jar --type css "%~dp0src\main.css" > temp3.txt
SET /p MAINCSS= < temp3.txt

:: Insert Strings
BatchSubstitute.bat ^<!--MAINCSS--^> "%MAINCSS%" "%~dp0src\main.html" > temp.txt


Here is the BatchSubstitute.bat code:

@echo off
REM -- Prepare the Command Processor --

::BatchSubstitude - parses a File line by line and replaces a substring"
::syntax: BatchSubstitude.bat OldStr NewStr File
::          OldStr [in] - string to be replaced
::          NewStr [in] - string to replace with
::          File   [in] - file to be parsed
if "%*"=="" findstr "^::" "%~f0"&GOTO:EOF
for /f "tokens=1,* delims=]" %%A in ('"type %3|find /n /v """') do (
    set "line=%%B"
    if defined line (
        call set "line=echo.%%line:%~1=%~2%%"
        for /f "delims=" %%X in ('"echo."%%line%%""') do %%~X
    ) ELSE echo.

I've tried wrapping %MAINCSS% with no quotes, 1 quote, 2 quotes and all fail. No quotes and 2 quotes fail with "System can't find specified file" and 1 quote fails with "body shouldn't be used at this time" (translated from Chinese).

Can anybody point me in the right direction here? Any help would be appreciate, thanks!

See More: Cant insert Javascript/CSS string into HTML

Report •

September 29, 2009 at 01:03:09
Well, in the end, somebody told me about Windows Scripting host and ended up using Javascript to write the string insertion part.

Report •
Related Solutions

Ask Question