Skip to content

Commit d220e15

Browse files
committed
Initial commit
0 parents  commit d220e15

File tree

7 files changed

+458
-0
lines changed

7 files changed

+458
-0
lines changed

.github/workflows/deploy.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Sample workflow for building and deploying a VitePress site to GitHub Pages
2+
#
3+
name: Deploy VitePress site to GitHub Pages
4+
5+
on:
6+
# Runs on pushes targeting the `main` branch. Change this to `master` if you're
7+
# using the `master` branch as the default branch.
8+
push:
9+
branches: [main]
10+
11+
# Allows you to run this workflow manually from the Actions tab
12+
workflow_dispatch:
13+
14+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
15+
permissions:
16+
contents: read
17+
pages: write
18+
id-token: write
19+
20+
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
21+
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
22+
concurrency:
23+
group: pages
24+
cancel-in-progress: false
25+
26+
jobs:
27+
# Build job
28+
build:
29+
runs-on: ubuntu-latest
30+
steps:
31+
- name: Checkout
32+
uses: actions/checkout@v4
33+
with:
34+
fetch-depth: 0 # Not needed if lastUpdated is not enabled
35+
# - uses: pnpm/action-setup@v3 # Uncomment this block if you're using pnpm
36+
# with:
37+
# version: 9 # Not needed if you've set "packageManager" in package.json
38+
# - uses: oven-sh/setup-bun@v1 # Uncomment this if you're using Bun
39+
- name: Setup Node
40+
uses: actions/setup-node@v4
41+
with:
42+
node-version: 20
43+
cache: npm # or pnpm / yarn
44+
- name: Setup Pages
45+
uses: actions/configure-pages@v4
46+
- name: Install dependencies
47+
run: npm ci # or pnpm install / yarn install / bun install
48+
- name: Build with VitePress
49+
run: npm run docs:build # or pnpm docs:build / yarn docs:build / bun run docs:build
50+
- name: Upload artifact
51+
uses: actions/upload-pages-artifact@v3
52+
with:
53+
path: .vitepress/dist
54+
55+
# Deployment job
56+
deploy:
57+
environment:
58+
name: github-pages
59+
url: ${{ steps.deployment.outputs.page_url }}
60+
needs: build
61+
runs-on: ubuntu-latest
62+
name: Deploy
63+
steps:
64+
- name: Deploy to GitHub Pages
65+
id: deployment
66+
uses: actions/deploy-pages@v4

.vitepress/config.mts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { defineConfig } from 'vitepress'
2+
3+
export default defineConfig({
4+
title: "CodeSnap",
5+
description: "CodeSnap is a pure Rust tool for generating beautiful code snapshots, available as a CLI tool or library. It supports customization, multiple formats, and clipboard integration. More info: [GitHub Repo](https://github.com/mistricky/CodeSnap).",
6+
vite: {
7+
server : {
8+
allowedHosts: true,
9+
}
10+
},
11+
themeConfig: {
12+
nav: [
13+
{ text: 'Home', link: '/' },
14+
],
15+
16+
sidebar: [
17+
{
18+
text: 'Documentation',
19+
items: [
20+
{ text: 'Introduction and Features', link: '/' },
21+
{ text: 'Getting Started', link: '/getting-started' },
22+
{ text: 'Configuration and Examples', link: '/configuration-and-examples' },
23+
{ text: 'Tutorial', link: '/tutorial' },
24+
]
25+
}
26+
],
27+
socialLinks: [
28+
{ icon: 'github', link: 'https://github.com/codesnap-rs/codesnap' }
29+
],
30+
search: {
31+
provider: 'local'
32+
}
33+
}
34+
})

configuration-and-examples.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Configuration and Examples
2+
3+
This documentation provides a guide for setting up CodeSnap with JSON configurations and includes examples for practical use.
4+
5+
## ⚙️ Configuration
6+
7+
CodeSnap is customizable using JSON configurations so you can personalize snapshots with themes, backgrounds, watermarks, and more.
8+
9+
### Library Configuration
10+
11+
To integrate CodeSnap as a library, use the `CodeSnap::from_config` method:
12+
13+
```rust
14+
CodeSnap::from_config("Your config")?;
15+
```
16+
17+
### CLI Configuration
18+
19+
For CLI users, CodeSnap will create a default configuration file at `~/.config/CodeSnap`. You can personalize it as needed:
20+
21+
```jsonc
22+
{
23+
"theme": "candy",
24+
"window": {
25+
"mac_window_bar": true,
26+
"shadow": {
27+
"radius": 20,
28+
"color": "#00000040"
29+
}
30+
},
31+
"code_config": {
32+
"font_family": "CaskaydiaCove Nerd Font"
33+
},
34+
"watermark": {
35+
"content": "CodeSnap"
36+
},
37+
"background": {
38+
"start": { "x": 0, "y": 0 },
39+
"end": { "x": "max", "y": 0 },
40+
"stops": [
41+
{ "position": 0, "color": "#6bcba5" },
42+
{ "position": 1, "color": "#caf4c2" }
43+
]
44+
}
45+
}
46+
```
47+
48+
For more configuration options, see [config.rs](https://github.com/mistricky/CodeSnap/blob/main/core/src/config.rs).
49+
50+
## 🌰 Examples
51+
52+
Here are some example use cases for CodeSnap. More can be found in the [examples](https://github.com/mistricky/CodeSnap/tree/main/cli/examples) directory.
53+
54+
### CLI Usage
55+
56+
```bash
57+
# Generate a snapshot from a Haskell file
58+
codesnap -f ./code_snippet.hs -o "./output.png"
59+
```
60+
61+
### Using the Library
62+
63+
```rust
64+
let snapshot = CodeSnap::from_default_theme()
65+
.content(Content::Code(
66+
CodeBuilder::from_t.content(r#"print "Hello, World!""#)
67+
.language("python")
68+
.build()?,
69+
))
70+
.build()?
71+
.create_snapshot()?;
72+
73+
// Copy to clipboard
74+
snapshot.raw_data()?.copy()
75+
```
76+
77+
With these configurations and examples, you can efficiently create personalized code snapshots. 🔧✨

getting-started.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Getting Started
2+
3+
Welcome to the "Getting Started" guide for CodeSnap! 🎉 This page will help you get started with CodeSnap, whether you want to use it as a Command Line Interface (CLI) tool or integrate it as a library into your own projects.
4+
5+
## Installation
6+
7+
### CLI Tool
8+
9+
CodeSnap can be installed using various methods depending on your system:
10+
11+
- **Arch Linux**: Use the command:
12+
```bash
13+
pacman -S codesnap
14+
```
15+
16+
- **Nix/NixOS**: Install with:
17+
```bash
18+
nix-env -i codesnap
19+
```
20+
21+
- **Cargo**: Run the following command:
22+
```bash
23+
cargo install codesnap-cli
24+
```
25+
26+
Alternatively, use the precompiled binary:
27+
```bash
28+
cargo binstall codesnap-cli
29+
```
30+
31+
- **Homebrew**: Use:
32+
```bash
33+
brew install mistricky/tap/CodeSnap
34+
```
35+
36+
After installation, you can generate code snapshots with:
37+
38+
```bash
39+
codesnap -f ./code_snippet.rs -o "./output.png"
40+
```
41+
42+
Use `codesnap -h` for more options and information.
43+
44+
### Library Integration
45+
46+
To add CodeSnap to your Rust project, include it as a dependency via Cargo:
47+
48+
```bash
49+
cargo add codesnap
50+
```
51+
52+
Use CodeSnap's builder pattern to create snapshots:
53+
54+
```rust
55+
let code_content = Content::Code(
56+
CodeBuilder::from_text()
57+
.content(r#"print "Hello, World!""#)
58+
.language("python")
59+
.build()?,
60+
);
61+
62+
let snapshot = CodeSnap::from_default_theme()
63+
.content(code_content)
64+
.build()?
65+
.create_snapshot()?;
66+
```
67+
68+
Check out CodeSnap's examples repository for more detailed usage scenarios. Enjoy creating your code snapshots! 🖼️

index.md

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# Introduction to CodeSnap
2+
3+
Welcome to CodeSnap! This is a Rust-based tool for creating beautiful code snapshots quickly. It uses a direct graphics engine, eliminating the need for network or browser-based rendering. You can use it from the command line with our CLI tool or incorporate it into your project via our library.
4+
5+
## Main Features
6+
7+
<!-- - **⚡ Fast**: Built with Rust for quick snapshot generation.
8+
- **🖥️ CLI Tool**: Command-line interface for ease of use.
9+
- **📚 Library**: Easily integrates into projects as a library.
10+
- **🔢 Line Numbers**: Adds line numbers for better clarity.
11+
- **💧 Watermark**: Customize snapshots with personal watermarks.
12+
- **🎨 Themes**: Supports a variety of Sublime Text themes.
13+
- **🔍 Scale**: Adjustable scale factors for high-quality snapshots.
14+
- **🖼️ Custom Backgrounds**: Choose from solid or gradient backgrounds.
15+
- **📁 Multiple Formats**: Save snapshots in PNG, SVG, or HTML.
16+
- **📋 Clipboard Support**: Copy snapshots to and from the clipboard.
17+
- **🏷️ Breadcrumbs**: Share snapshots with code paths for traceability. -->
18+
19+
### 🚀 Performance
20+
- **Fast**: Built with Rust, CodeSnap efficiently generates snapshots using its graphics engine for swift operations.
21+
22+
### 📜 Versatility
23+
- **CLI Tool**: Create snapshots directly from the command line with ease.
24+
- **Library Integration**: Integrate CodeSnap into your projects to use its features within your development environment.
25+
26+
### 📐 Customization
27+
- **Line Numbers**: Snapshots can include line numbers, helping to contextualize code snippets.
28+
- **Watermarks**: Add custom watermarks to your snapshots for personalization.
29+
- **Themes**: Supports Sublime Text syntax definitions, offering a variety of theme options.
30+
31+
### 🖼️ Flexibility
32+
- **Scalability**: Adjust the scale factor for snapshots; high-quality outputs are the default.
33+
- **Backgrounds**: Choose from default or custom background colors for visual enhancement.
34+
35+
### 📁 Formats & Clipboard
36+
- **Snapshot Formats**: Save snapshots in formats like PNG, SVG, HTML, or ASCII.
37+
- **Clipboard Integration**: Copy snapshots directly to or from the clipboard.
38+
39+
### 🎯 Breadcrumbs
40+
- **Navigation**: Use CodeSnap's breadcrumb feature for easy attribution and code context sharing.
41+
42+
## Quick Start
43+
44+
### CLI Installation
45+
46+
CodeSnap can be installed on various platforms:
47+
48+
<details>
49+
<summary>Arch Linux</summary>
50+
51+
```bash
52+
pacman -S codesnap
53+
```
54+
55+
</details>
56+
57+
<details>
58+
<summary>Nix/NixOS</summary>
59+
60+
```bash
61+
nix-env -i codesnap
62+
```
63+
64+
</details>
65+
66+
<details>
67+
<summary>Cargo</summary>
68+
69+
```bash
70+
cargo install codesnap-cli
71+
```
72+
73+
Or via precompiled binary:
74+
75+
```bash
76+
cargo binstall codesnap-cli
77+
```
78+
79+
</details>
80+
81+
<details>
82+
<summary>Homebrew</summary>
83+
84+
```bash
85+
brew install mistricky/tap/CodeSnap
86+
```
87+
88+
</details>
89+
90+
View our [Getting Started](/getting-started) page for more information.
91+
92+
### Library Integration
93+
94+
Add CodeSnap to your Cargo project with:
95+
96+
```bash
97+
cargo add codesnap
98+
```
99+
100+
Build snapshots programmatically using:
101+
102+
```rust
103+
let code_content = Content::Code(
104+
CodeBuilder::from_t
105+
.content(r#"print "Hello, World!""#)
106+
.language("python")
107+
.build()?,
108+
);
109+
110+
let snapshot = CodeSnap::from_default_theme()
111+
.content(code_content)
112+
.build()?
113+
.create_snapshot()?;
114+
115+
// Copy the snapshot data to the clipboard
116+
snapshot.raw_data()?.copy()
117+
```
118+
119+
Explore more by visiting the [Getting Started](/getting-started) page.

package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"scripts": {
3+
"docs:dev": "vitepress dev",
4+
"docs:build": "vitepress build",
5+
"docs:preview": "vitepress preview"
6+
},
7+
"devDependencies": {
8+
"vitepress": "^1.6.1"
9+
}
10+
}

0 commit comments

Comments
 (0)