Showing posts with label LargeEdit Scripting. Show all posts
Showing posts with label LargeEdit Scripting. Show all posts

Friday, May 9, 2008

HTML Style Sections to Inline Style Tags

//***** LargeEdit Scripting *****
//
// Title: HTML Style Sections to Inline Style Tags
// Author: Tim O'Brien
// Date: May 8, 2008
// Purpose: Performs a JScript regular expression search on the HTML document for
// style attributes and replace class references.
//
//*******************************

function Run() {
var scanlines= "(.+)\\s\\x7b([^\\x7d]*)";
var scansection="<(style).+>(.+)[^\/\1]*"

LargeEdit.ResultLog(' HTML Style Section to Inline Style Tags (Start)');

var styletext;
var inpStr = LargeEdit.CurrentFile.Text;
var newtext = inpStr;

//Update InpStr to only Style Sections
var arrStyle;
var oReSections;
var oRe;
oReSections =
new RegExp(scansection, "gmi");

var retStr;
var objtag;
var objval;
var classidx;
var classname;
while ((arrStyle = oReSections.exec(inpStr)) != null) {
styletext = arrStyle[
0];

// Get the Matches collection
oRe = new RegExp(scanlines, "gmi");

retStr =
'';
objtag =
'';
objval =
'';
classidx = -
1;
classname =
'';
while ((arr = oRe.exec(styletext)) != null) {
//retStr = arr[1] + ' = ' + arr[2];
objtag = arr[1];
objval = arr[
2];
//LargeEdit.ResultLog(retStr);

//Do Replacement of class ids
classidx = objtag.indexOf(".");
if (classidx >= 0) {
classname = objtag.substr(classidx+
1);
LargeEdit.ResultLog(
'Class Tab Found: ' + classname);
newtext = newtext.rep(
'class="' + classname + '"', 'style="' + objval.trim() + '"');
}

}
}
//Each Style Section

LargeEdit.New();
LargeEdit.CurrentFile.Text = newtext;
LargeEdit.ResultLog(
' HTML Style Section to Inline Style Tags (Finish)');
}

function StringReplace(findstr, replacestr) {
var regEx, strout;
regEx =
new RegExp(findstr, "igm");
strout =
this.replace(regEx, replacestr);
return strout;
}
String.
prototype.rep = StringReplace;

function StringTrim()
{
return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.
prototype.trim = StringTrim;

//copyright 2008 All rights reserved

Delimited Line Template

//***** LargeEdit Scripting *****
//
// Title: Delimited Line Template
// Author: Tim O'Brien
// Date: May 8, 2008
// Purpose: Merges lines of text containing delimited fields into a template.
// Usage: Create a SQL insert statement and merge the fields of text
// into the correct position for inserting into a database.
// Example: Insert into table(id, name, date) values ( {F1}, '{F3}', {F2} );
// the field tags {F1} will be replaces with the actual values.
//*******************************
var Delimiter = 9;
//Tab = 9, Comma = 44, Pipe = 124.
//(see LargeEdit | Tools | ASCII Codes | View ASCII Code, for a complete list.

function Run() {
LargeEdit.ResultLog(
' Start - Delimited Line Template ');

var tmp = '';
tmp = LargeEdit.InputBox(
'Delimited Line Template','Enter Template:','')
if (tmp.length <= 0) {
LargeEdit.ResultLog(
' Canceled - Enter a Template ');
return;
}

//Variables used
var line, newline;
var flds, fld, fldidx, lineidx, findtxt;
var newtext = "";

//Loop for Lines of text
for (var i = 0; i < LargeEdit.CurrentFile.LineCount; i++) {
line = LargeEdit.CurrentFile.Line( i );
lineidx = i +
1;
flds = line.split(String.fromCharCode(Delimiter));
//Tab default

//Replace Line Index Reference
newline = tmp; //Reset newline to base template
findtxt = '{LIDX}';
newline = newline.rep(findtxt, lineidx);

//Loop for Fields to do replacements
for (var j = 0; j < flds.length; j++) {
fld = flds[j]
//Get Field Value
fldidx = j + 1;
fld = fld.rep(
"'", "''");
findtxt =
'{F' + fldidx.toString() + '}';
newline = newline.rep(findtxt, fld);
}
newtext += newline +
"\r\n";

}

LargeEdit.New();
LargeEdit.CurrentFile.Text = newtext;

LargeEdit.ResultLog(
' Finish - Delimited Line Template ');

}

function StringReplace(findstr, replacestr) {
var regEx, strout;
regEx =
new RegExp(findstr, "igm");
strout =
this.replace(regEx, replacestr);
return strout;
}
String.
prototype.rep = StringReplace;

//copyright 2008 All rights reserved


Thursday, May 8, 2008

Reverse Delimited Field Order


//***** LargeEdit Scripting *****
//
// Title: Reverse Fields
// Author: Tim O'Brien
// Date: May 7, 2008
// Purpose: Reverse the order of Delimited Fields in a document.
// Useful for switch lists like City, State, Country so Sorting
// by Country, State, City can be preformed.
//
// From: Field1, Field2, Field3
// To: Field3, Field2, Field1
//
//Note: Delimiter var below is defaulted to "Tab" char 9.
//*******************************
var Delimiter = 9;
//Tab = 9, Comma = 44, Pipe = 124.
//(see LargeEdit | Tools | ASCII Codes | View ASCII Code, for a complete list.

function Run() {

LargeEdit.ResultLog(
' Reverse Fields ');

var line;
var flds;
var newtext = "";
for (var i = 0; i < LargeEdit.CurrentFile.LineCount; i++) {
line = LargeEdit.CurrentFile.Line( i );
flds = line.split(String.fromCharCode(Delimiter));
//Tab
for (var j = flds.length-1; j >= 0; j--) {
newtext += flds[j]
if (j > 0) newtext += String.fromCharCode(Delimiter);
}
newtext +=
"\r\n";
}

LargeEdit.New();
LargeEdit.CurrentFile.Text = newtext;

}

//copyright 2008 All rights reserved