Code Monkey home page Code Monkey logo

technical-challange's Introduction

DocSales

Introduction

This is a demo application, the specifications can be found at the project's README.md.

Requirements

Those are mostly the main ones:

  • Ruby
  • Rails
  • PostgreSQL
  • TeX Live

A working install of Ruby and Rails is required to run the app (I've used the latest versions of everything). TeX Live is used to generate the PDF.

Installation

$ bundle install

Usage

There are two routes (as defined in the specification).

  • GET /api/v1/documents/list
  • POST /api/v1/documents

The routes will either respond with 200 or 400, depending on what is being sent to the server.

To make a POST request:

$ xh post http://localhost:3000/api/v1/documents \
description="test" \
document_data='{"customer_name": "Joe", "contract_value": 1000}' \
template="$(cat template.html)"

The API also understands the remote:=true parameter, in this mode the PDF file will be stored remotely and the pdf_url field will be updated accordingly. Note that uploads are set to expire after 24 hours and the server is hard-coded to 0x0.st but more providers can be added later.

Please be mindful when using this parameter, note that 0x0.st is a free of charge service and abusing it is discouraged.

Similarly, to make a GET request:

$ xh http://localhost:3000/api/v1/documents/list

Running tests

Tests can be run with rake.

Notes

You might be wondering why TeX Live is used to produce the final PDF document and not some gem.

I've found that most of the well-known gems to convert HTML into PDF use the wkhtmltopdf utility, which has been discontinued.

TeX Live (LaTeX) is fully supported on my Linux distribution, produces the highest quality documents I've ever seen and LaTeX offers a high degree of control over the presentation.

On my system (Arch Linux) those packages were required to get xelatex to work:

  • texlive-basic 2024.2-1
  • texlive-bin 2024.2-1
  • texlive-fontsrecommended 2024.2-1
  • texlive-latex 2024.2-1
  • texlive-xetex 2024.2-1

On macOS, TeX Live can be installed from Homebrew, the instructions can be found here.

technical-challange's People

Contributors

diegoviola avatar tomascco avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.