package ONO::FW::Apps::Dev;
################################################################################
# COPYRIGHT / LICENSE #
################################################################################
#
# This file is part of the ONO Software Project.
#
# Copyright (C) 2000-2025 Jos KIRPS [ www.kirps.com | jos_AT_kirps_DOT_com ]
# and The Joopita Project [ www.joopita.org | contact_AT_joopita_DOT_com ]
#
# This file, as well as other parts of the ONO Software Project or related
# elements, are FREE SOFTWARE available under the ARTISTIC LICENSE 2.0.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# For the full license, see /ono/osr/license/LICENSE.txt, or write to
# jos_AT_kirps_DOT_com or contact_AT_joopita_DOT_com.
#
################################################################################
# END OF COPYRIGHT / LICENSE, HERE COMES THE CODE ... #
################################################################################
use strict;
use ONO::IO;
###############################################################################
# js compiler
###############################################################################
sub js_compiler {
my (
$self,
$SCRIPT,
$DIR,
$MOD,
$EXP,
$INPUT_ref,
$ACTIONS_ref,
) = @_;
#: The JS compiler can turn HTML/JS pages into a Perl script that can then
#: be loaded into common Perl-based ONO applications.
my $REPORT;
if (ONO::IO->devstation) {
my $APP = $MOD;
$APP =~ s~^(.*):~~;
$MOD =~ s~:~::~g;
$EXP =~ s~:~::~g;
$REPORT .= "# This is an auto-generated file created by ONO_FW_Apps_Dev\n";
$REPORT .= "# DIR = $DIR, APP = $APP, MOD = $MOD\n#\n";
$REPORT .= "# Make sure this will pass mksys error checking: disable_subcall_checking_file\n#\n\n";
my @INPUT = @$INPUT_ref;
my $INCODE;
foreach my $IN (@INPUT) {
if ($IN =~ /[A-Za-z0-9]/) {
$REPORT .= "# INPUT VAR : $IN\n";
$INCODE .= ",\n \$$IN";
}
}
my @ACTIONS = @$ACTIONS_ref;
foreach my $ACT (@ACTIONS) {
$REPORT .= "# ACTION : $ACT\n";
}
# if ($INCODE) {
$INCODE = qq~\n\nmy (\n \$self$INCODE\n) = \@_;\n~;
# }
$REPORT .= "# FILEDIR search in: $DIR/$APP\n";
foreach my $FILE (ONO::IO->ls("$DIR/$APP")) {
if ($FILE =~ /[A-Za-z0-9]/ && $FILE !~ /\./) {
$REPORT .= "# FILEDIR found: $FILE\n";
my ($DATA,@LINES);
foreach my $file (sort ONO::IO->ls("$DIR/$APP/$FILE")) {
if ($file =~ /[A-Za-z0-9]/ && $file =~ /\.html$/) {
@LINES = ONO::IO->list("$DIR/$APP/$FILE/$file");
}
}
foreach my $LINE (@LINES) {
$LINE =~ s~(\n|\r|\t)~~g;
$LINE =~ s~\$~\\\$~g;
$LINE =~ s~\@~\\\@~g;
$LINE =~ s~\%~\\\%~g;
$LINE =~ s~\[~\\\[~g;
$LINE =~ s~\]~\\\]~g;
foreach my $IN (@INPUT) {
if ($LINE =~ /\'/) {
$LINE =~ s~const $IN = '(.*?)';~const $IN = '\$$IN';~;
} else {
$LINE =~ s~const $IN = (.*?);~const $IN = \$$IN;~;
}
}
foreach my $ACT (@ACTIONS) {
my @AP = split(/\^/,$ACT);
if ($AP[0] eq "alert_you_won") {
$LINE =~ s~alert\('You won!'\);~$AP[1]();~gi;
}
}
if ($LINE =~ /while/) {
$LINE .= qq~ // disable_whilecounter_protection~;
}
$DATA .= "$LINE\n";
}
$DATA =~ s~\n~###_BREAK_###~g;
$DATA =~ s~\<!DOCTYPE(.*?)\>~~g;
$DATA =~ s~\<html(.*?)\>~~g;
$DATA =~ s~\<\/html(.*?)\>~~g;
$DATA =~ s~\<head(.*?)\>(.*)\<\/head(.*?)\>~~g;
$DATA =~ s~\<script src="(.*?)"\>\<\/script\>~~g;
$DATA =~ s~\<body(.*?)\>~~g;
$DATA =~ s~\<\/body(.*?)\>~~g;
$DATA =~ s~###_BREAK_###~\n~g;
# $DATA =~ s~###_BACKSPACE_###~\\~g;
my $LICENSE_INFO = "#:";
$LICENSE_INFO .= "LICENSE";
$LICENSE_INFO .= ":#\n\n";
$LICENSE_INFO .= "#: ";
$LICENSE_INFO .= "This file contains an auto-generated module that have been compiled using pure HTML / JS files created for the Morzino Project (morzino.com) and that have been released as Open Source software.\n\n";
if ($DATA) {
ONO::IO->store("$DIR/$APP$FILE.pm",qq~package $EXP$FILE;\n$LICENSE_INFO\nuse strict;\n\n$REPORT\n\nsub code {$INCODE\n\nreturn qq\~$DATA\n\~;\n\n}\n\n1;\n\n__END__~);
$REPORT .= "ONO_FW_Apps_Dev OUTPUT = $DIR/$APP$FILE.pm<br>";
}
}
}
$REPORT =~ s~#~-~g;
$REPORT =~ s~\n~<br>~g;
}
return $REPORT;
}
###############################################################################
# app builder
###############################################################################
sub builder {
#: Deprecated.
return "";
}
###############################################################################
# end of script
###############################################################################
1;
__END__