Ticket #1545 (new New Feature)
Support packing namespace constants ( jsMyObject.MYCONSTANT=1; )
| Reported by: | joewieloch | Owned by: | |
|---|---|---|---|
| Priority: | Normal | Milestone: | |
| Component: | Project : FCKpackager | Version: | |
| Keywords: | HasPatch | Cc: |
Description
Our project has many namespace constants which we want to be packed.
Below shows constant declarations we wish to have processed:
In the javascript:
jsTreeView.EXPAND = 1; jsTreeView.COLLAPSE = 2; jsTreeView.TOGGLE = 3;
In the FCKPackager.xml:
<Constant name="jsTreeView.EXPAND" value="1"/> <Constant name="jsTreeView.COLLAPSE" value="2"/> <Constant name="jsTreeView.TOGGLE" value="3"/>
We modified fckpackager.php to support packing these. I'm posting our changes here for consideration.
The following method was modified in class FCKConstantProcessor:
function Process( $script )
{
if ( !$this->HasConstants )
return $script;
$output = $script ;
if ( $this->RemoveDeclaration )
{
// /var\s+(?:BASIC_COLOR_RED|BASIC_COLOR_BLUE)\s*=.+?;/
// remove if global constant
$output = preg_replace(
'/var\\s+(?:' . $this->_ContantsRegexPart . ')\\s*=.+?;/m',
'', $output ) ;
// remove if namespace constant (jsMyObject.MYCONSTANT=1;)
$output = preg_replace(
'/(?<!\\w)(?:' . $this->_ContantsRegexPart . ')\\s*=[^=]+?;/m',
'', $output ) ;
}
$output = preg_replace_callback(
'/(?<!var\\s|...\.|\\w)(?:' . $this->_ContantsRegexPart . ')(?!\\w|\\s*=[^=])/',
array( &$this, '_Contant_Replace_Evaluator' ), $output ) ;
return $output ;
}
The above also includes the possible fix noted in #1244
Change History
Note: See
TracTickets for help on using
tickets.