Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve re-usability of parser #3

Merged
merged 2 commits into from Mar 13, 2017
Merged

Conversation

mike42
Copy link
Contributor

@mike42 mike42 commented Mar 13, 2017

This pull request contains improvements to parser re-usability.

Highlights-

  • Perform I/O inside a new "Parser" class
  • Include escpos-php as dependency to pass a CapabilityProfile available to command parsers for later use (eg text encoding).
  • Added a new esc2html command, which repeats the esc2text command, but HTML output.
$ php esc2html.php receipt-with-logo.bin
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <style>
  .esc-receipt {
    border: 1px solid #888;
    font-family: monospace;
    margin: 1em;
    padding: 1em;
    display: inline-block;
  }
  .esc-line {
    white-space: pre;
  }
  </style>
</head>
<body>
  <div class="esc-receipt">
    <div class="esc-line">ExampleMart Ltd.</div>
    <div class="esc-line">Shop No. 42.</div>
    <div class="esc-line">&nbsp;</div>
    <div class="esc-line">SALES INVOICE</div>
    <div class="esc-line">                                               $</div>
    <div class="esc-line">Example item #1                             4.00</div>
    <div class="esc-line">Another thing                               3.50</div>
    <div class="esc-line">Something else                              1.00</div>
    <div class="esc-line">A final item                                4.45</div>
    <div class="esc-line">Subtotal                                   12.95</div>
    <div class="esc-line">&nbsp;</div>
    <div class="esc-line">A local tax                                 1.30</div>
    <div class="esc-line">Total            $ 14.25</div>
    <div class="esc-line">&nbsp;</div>
    <div class="esc-line">Thank you for shopping at ExampleMart</div>
    <div class="esc-line">For trading hours, please visit example.com</div>
    <div class="esc-line">&nbsp;</div>
    <div class="esc-line">Monday 6th of April 2015 02:56:25 PM</div>
  </div>
</body>
</html>

This renders as-

screenshot from 2017-03-13 16-16-21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant