Skip to content

Commit

Permalink
feat: Merge pull request #1 from sidebase/inital-implementation
Browse files Browse the repository at this point in the history
Added initial implementation of `nuxt-pdf`
  • Loading branch information
BracketJohn authored Jan 31, 2023
2 parents 74cf749 + 94bb8e1 commit 30ea28f
Show file tree
Hide file tree
Showing 38 changed files with 20,671 additions and 46 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
dist
node_modules
docs
Binary file added .github/preview.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions .github/sync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
sidebase/nuxt-pdf:
- docs/content
- docs/public
sidebase/docs:
- source: docs/content/
dest: content/6.nuxt-pdf/
- source: docs/public/
dest: public/
33 changes: 33 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: nodejs CI

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Use Node.js 16.14.2
uses: actions/setup-node@v3
with:
node-version: 16.14.2

# Install locked dependencies and prepare types
- run: npm ci
- run: npm run dev:prepare

# Check if build and package artifacts can still be generated
- run: npm run prepack

# Check linting and typing
- run: npm run lint
- run: npm run types

# Check building
- run: npm run build:module
- run: npm run build:playground
16 changes: 16 additions & 0 deletions .github/workflows/sync.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Sync docs
on:
push:
branches:
- main
workflow_dispatch:
jobs:
sync:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@master
- name: Run GitHub File Sync
uses: BetaHuhn/repo-file-sync-action@v1
with:
GH_PAT: ${{ secrets.GH_TOKEN }}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 SIDESTREAM GmbH

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
55 changes: 51 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,53 @@
# 📄 nuxt-pdf-export
![nuxt-pdf](.github/preview.jpg)

## Development
# 📄 nuxt-pdf

- Run `npm run dev:prepare` to generate type stubs.
- Use `npm run dev` to start [playground](./playground) in development mode.
[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![GitHub stars](https://badgen.net/github/stars/sidebase/nuxt-pdf)](https://GitHub.com/sidebase/nuxt-pdf/)
[![License][license-src]][license-href]
[![Follow us on Twitter](https://badgen.net/badge/icon/twitter?icon=twitter&label)](https://twitter.com/sidebase_io)
[![Join our Discord](https://badgen.net/badge/icon/discord?icon=discord&label)](https://discord.gg/NDDgQkcv3s)

> `nuxt-pdf` is a easy to use, pdf exporting module to convert Nuxt 3 components into downloadable PDFs.
## Quick Start

```sh
npm i -D @sidebase/nuxt-pdf
```

Then visit the [Quick Start documentation](https://sidebase.io/nuxt-pdf/getting-started/quick-start) to setup the module.

## Features

- Easily export your Nuxt 3 components into PDFs
- Guides for PDF specific styles
- Track exporting progress

### Module Playground

This module also has it's own playground:
```sh
> git clone https://github.com/sidebase/nuxt-pdf

> cd nuxt-pdf

> npm i

> npm run dev:prepare

> npm run dev

# -> open http://localhost:3000
```

<!-- Badges -->
[npm-version-src]: https://img.shields.io/npm/v/@sidebase/nuxt-pdf/latest.svg
[npm-version-href]: https://npmjs.com/package/@sidebase/nuxt-pdf

[npm-downloads-src]: https://img.shields.io/npm/dt/@sidebase/nuxt-pdf.svg
[npm-downloads-href]: https://npmjs.com/package/@sidebase/nuxt-pdf

[license-src]: https://img.shields.io/npm/l/@sidebase/nuxt-pdf.svg
[license-href]: https://npmjs.com/package/@sidebase/nuxt-pdf
12 changes: 12 additions & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
node_modules
*.iml
.idea
*.log*
.nuxt
.vscode
.DS_Store
coverage
dist
sw.*
.env
.output
2 changes: 2 additions & 0 deletions docs/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
shamefully-hoist=true
strict-peer-dependencies=false
57 changes: 57 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Docus Starter

Starter template for [Docus](https://docus.dev).

## Clone

Clone the repository (using `nuxi`):

```bash
npx nuxi init docs -t nuxt-themes/docus-starter
```

## Setup

Install dependencies:

```bash
yarn install
```

## Development

```bash
yarn dev
```

## Edge Side Rendering

Can be deployed to Vercel Functions, Netlify Functions, AWS, and most Node-compatible environments.

Look at all the available presets [here](https://v3.nuxtjs.org/guide/deploy/presets).

```bash
yarn build
```

## Static Generation

Use the `generate` command to build your application.

The HTML files will be generated in the .output/public directory and ready to be deployed to any static compatible hosting.

```bash
yarn generate
```

## Preview build

You might want to preview the result of your build locally, to do so, run the following command:

```bash
yarn preview
```

---

For a detailed explanation of how things work, check out [Docus](https://docus.dev).
6 changes: 6 additions & 0 deletions docs/app.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// @ts-ignore
export default defineAppConfig({
docus: {
title: 'My Docs'
}
})
25 changes: 25 additions & 0 deletions docs/content/1.getting-started/1.index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
description: "Introduction to `nuxt-pdf` and its features for exporting html pages to pdf."
---

# Introduction

`nuxt-pdf` is a Nuxt 3 wrapper around [html2pdf.js](https://ekoopmans.github.io/html2pdf.js/), a package that allows you to export HTMLElements as a PDF document.

::list{type="success"}
- Adds built in Nuxt 3 support to export components to a PDF Document
- Works with native Nuxt 3 refs, allowing you to keep your clean Nuxt 3 code free from any external package
::

After installing the module you will be able to access the function like so:
```ts
// file: ~/app.vue
const { $exportToPDF } = useNuxtApp()

await $exportToPDF(HTMLElement, {
margin: 10,
// other options
})
```

See more in the [Quick Start section](/nuxt-pdf/getting-started/quick-start).
20 changes: 20 additions & 0 deletions docs/content/1.getting-started/2.installation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
description: "How to install nuxt-pdf."
---

# Installation

To install the module begin by installing our package
::code-group
```bash [npm]
npm install -D @sidebase/nuxt-pdf
```
```bash [yarn]
yarn add --dev @sidebase/nuxt-pdf
```
```bash [pnpm]
pnpm i -D @sidebase/nuxt-pdf
```
::

`nuxt-pdf` only requires a Nuxt 3 app to run.
58 changes: 58 additions & 0 deletions docs/content/1.getting-started/3.quick-start.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
description: "How to use nuxt-pdf."
---

# Quick Start
In this quick start guide you can find an overview of how to use `nuxt-pdf`. For more advanced use cases please refer to our [specialized recipes](/nuxt-pdf/recipes).

## Usage
After [installing the package](/nuxt-pdf/getting-started/installation), we offer two primary ways to interact with our module.

### Via composable

```vue
<template>
<MyComponent ref="pdfExport" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const { usePDFExport } = usePDFExport()
const pdfExport = ref<HTMLElement | null>(null)
usePDFExport(pdfExport, {
'fileName': 'myCoolExport.pdf',
// any other options
})
</script>
```

### Via injected variable

```vue
<template>
<MyComponent ref="pdfExport" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const { $exportToPDF } = useNuxtApp()
const pdfExport = ref<HTMLElement | null>(null)
$exportToPDF(pdfExport, {
'fileName': 'myCoolExport.pdf',
// any other options
})
</script>
```

## Parameters

`nuxt-pdf` takes two parameters. The first is a HTMLElement and the second being an options object.
We recommend making use of vue's ref system to pass a component into the function. You can see an example of this below:

The second parameter is an options object. You can find all available options and their purpose on the [official html2pdf docs](https://ekoopmans.github.io/html2pdf.js/#options).

::alert{type="info"}
You can find more information on the functionality of `nuxt-pdf` on the [official html2pdf docs](https://ekoopmans.github.io/html2pdf.js/).
::
15 changes: 15 additions & 0 deletions docs/content/1.getting-started/4.getting-help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
description: "How to get help when using `nuxt-pdf` in your Vue / Nuxt 3 application."
---

# Getting Help

At some point, you may find that there's an issue you need some help with.

But don't worry! We're a friendly community of developers and we'd love to help. Concretely this means to:
- Checkout the docs (page that you are currently viewing),
- Search open issues and discussions: https://github.com/sidebase/nuxt-pdf/issues
- Hop on Discord to ask us directly: https://discord.gg/VzABbVsqAc,
- Open an issue to file a bug, ask for an enhancement or get an answer to a question: https://github.com/sidebase/nuxt-pdf/issues/new/choose

We aim to follow the getting-help standards of the nuxt-project as described here and ask you to do the same when opening an issue or pinging us for help: https://nuxt.com/docs/community/getting-help#getting-help.
2 changes: 2 additions & 0 deletions docs/content/1.getting-started/_dir.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
title: Getting Started
icon: heroicons-outline:sparkles
4 changes: 4 additions & 0 deletions docs/content/1.index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
navigation: false
redirect: /nuxt-pdf/getting-started
---
5 changes: 5 additions & 0 deletions docs/content/2.recipes/1.index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Overview

The following pages contain some recipes for commonly asked patterns, questions and implementations. The recipes are mostly provided by the community and can serve as guidelines to implement something similar in your Nuxt 3 application. The recipes are not all tested through by the sidebase team. If you have any concerns, questions or improvement proposals or want to contribute a recipe yourself, we'd be very happy if you open an issue on our repository: https://github.com/sidebase/nuxt-pdf/issues/new/choose

Thanks to everybody who contributed so far ❤️
Loading

0 comments on commit 30ea28f

Please sign in to comment.