Ferreteria/v0.6/clade/boot/Screen/Web

From Woozle Writes Code
< Ferreteria‎ | v0.6‎ | clade‎ | boot‎ | Screen
Jump to navigation Jump to search
clade: boot\Screen\Web
Clade Family
Screen Web (none)
Clade Aliases
Alias Clade
Base* [ca,i] boot\Screen
FallStyleClass Config\Style\General\StandardWeb
ElementClass IO\O\View\Web\Screen
Subpages

About

  • Purpose: screen-output variant for Web (HTML)

History

  • 2024-05-27 Moving this stuff into loaders/screen/, because it keeps being unavailable for the autoloader.
    • TODO: The table stuff should be in another class. Not sure how to structure this yet. Leaving it here for now.
  • 2024-08-13 added interface, RenderHTML(); removed DoesLinks()

Code

interface iWeb extends BaseIface {
    // CSS stuff

    function InlineClass(string $sText, string $sClass) : string;
}

class cWeb extends BaseClass implements iWeb {

    // ++ CONFIG ++ //

    protected function ElementClass() : string { return ElementClass::class; }
    protected function FallbackStyleClass() : string { return FallStyleClass::class; }

    // ++ CONFIG: marks ++ //

    public function OpenFixed() : string { return ''"`UNIQ--pre-00000001-QINU`"''; }
    protected function MarkForBold(bool $bOn) : string { return $bOn ? '<b>' : '</b>'; }
    protected function MarkForItal(bool $bOn) : string { return $bOn ? '<i>' : '</i>'; }
    protected function MarkForSmall(bool $bOn) : string { return $bOn ? '<small>' : '</small>'; }

    // -- CONFIG -- //
    // ++ MAIN ++ //

    // information
    #public function DoesLinks() : bool { return TRUE; }

    // CSS bits
    protected function TitleStyle() : string { return 'border-top: 2px solid black; border-bottom: 1px solid black; background: rgba(128,128,128,128)'; }

    // text formatting

    public function NewLine() : string { return "<br>\n"; }
    public function LineBreaks(string $s) : string { throw new \exception('Call NewLineIt() instead.'); }

    // ++ CHAR FORMATS ++ //

    public function BoldIt(?string $s) : string { return is_null($s) ? '' : "<b>$s</b>"; }
    public function ItalIt(?string $s) : string { return is_null($s) ? '' : "<i>$s</i>"; }
    public function SmallIt(?string $s) : string { return is_null($s) ? '' : "<small>$s</small>"; }
    public function UBarIt(?string $s) : string { return is_null($s) ? '' : "<u>$s</u>"; }

    // styles
    public function InfoIt(string $s) : string { return "<span style='color:blue'>$s</span>"; }
    public function FaintIt(string $s) : string { return "<span class=faint style='color: gray;'>$s</span>"; }
    public function ErrorIt(string $s) : string { return "<span style='color:red'>$s</span>"; }
    public function TitleIt(string $s) : string {
        $sStyle = $this->TitleStyle();
        return "<h1 style='$sStyle'>$s</h1>";
    }
    public function LinkIt(string $sText, string $sURL) : string { return "<a href='$sUrl'>$sText</a>"; }
    public function XMLTagIt(string $s) : string { return "<span style='color:gray;'>&gt;<span style='color:blue;'>$s</span></span>"; }

    // colors
    public function GreenIt(string $s) : string { return "<span style='color:green;'>$s</span>"; }
    public function BlueIt(string $s) : string { return "<span style='color:blue;'>$s</span>"; }
    public function YellowIt(string $s) : string { return "<span style='color:yellow;'>$s</span>"; }


    // -- CHAR FORMATS -- //
    // ++ BLOCK FORMATS ++ //

    public function BoxIt(string $s) : string {
        $cssStyle = 'border: 1px solid orange; background: #ffd;';
        return "<table style='$cssStyle'><tr><td>$s</td></tr></table>";
    }
    public function FixPitchIt(string $s) : string { return $this->OpenFixed().$s.$this->ShutFixed(); }
    public function NewLineIt(string $s) : string { return str_replace("\n",'<br />',$s); }
    /*----
      NOTE
        2022-04-23 When using with MW, there must not be spaces before the tags.
          Apparently even when supposedly emitting raw HTML, MW is still noticing that
          and interpreting it as a request for <pre> tags. Go figure.
      HISTORY:
        2022-04-23 Fixed leading-space issue with MW. (Do we need a MW-specific Env?)
    */
    public function HideDrop(string $sSummary, string $sContent) : string {
        // TODO 2021-11-28 maybe have this emit CSS one time, on first call?
#<details style='border: 1px solid #aaa; border-radius: 4px; padding: .5em .5em 0;'>
        return <<<__END__
<details>
<summary>$sSummary</summary>
$sContent
</details>
__END__;
    }

    // -- BLOCK FORMATS -- //

    // CSS stuff

    /* 2025-04-09 Style is an object (and If Day is for everyone) now.
    public function Style(string $s) : string { return "<style>\n$s\n</style>"; }
    // TODO 2025-02-19: replace this with a Style system call
    */
    public function InlineClass(string $sText, string $sClass) : string {
        return "<span class='$sClass'>$sText</span>";
    }

    // bulk text formatting

    // crude list conversion:
    public function MakeList(string $s) : string {
        $sOut = str_replace("\n","\n<li>",$s,$nRepl);
        if ($nRepl > 2) {
            $sOut = "<ul>$sOut</ul>\n";
        }
        return $sOut;
    }

    // graphic elements

    public function HorizLine() : string { return "\n<hr>\n"; }

    // characters

    public function LeftArrow() : string { return '&lArr;'; }
    public function RightArrow() : string { return '&rArr;'; }

    // markup

    public function StripMarkup(string $s) : string { return htmlspecialchars($s); }

    public function RenderHTML(string $ht) : string { return $ht; }

}