Skip to content

Commit

Permalink
chore: add docs, gh workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
weskoerber committed May 20, 2024
1 parent 0db143b commit 1b9f029
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 8 deletions.
27 changes: 27 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: bug
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**OS & OS version**
The target operating system and its version (e.g. Arch Linux 6.8.9-arch1-2).

** Zig version **
The output of `zig version`.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: enhancement
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
32 changes: 32 additions & 0 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: docs
on:
workflow_dispatch:
push:
branches:
- main
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
deploy:
runs-on:
- ubuntu-latest
steps:
- name: install zig
uses: weskoerber/setup-zig@main
- name: checkout
uses: actions/checkout@v4
- name: generate docs
run: zig build docs
- name: setup pages
uses: actions/configure-pages@v5
- name: upload artifacts
uses: actions/upload-pages-artifact@v3
with:
path: ./zig-out/docs/
- name: deploy pages
uses: actions/deploy-pages@v4
16 changes: 16 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: test
on:
pull_request:
push:
branches:
- main
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: install zig
uses: weskoerber/setup-zig@main
- name: checkout
uses: actions/checkout@v4
- name: test
run: zig build test
21 changes: 21 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,25 @@ pub fn build(b: *std.Build) void {

const run_tests = b.addRunArtifact(tests);
test_step.dependOn(&run_tests.step);

addDocsStep(b, .{ .target = target, .optimize = optimize });
}

fn addDocsStep(b: *std.Build, options: anytype) void {
const docs_step = b.step("docs", "Emit docs");

const lib = b.addStaticLibrary(.{
.name = "mac_address",
.root_source_file = b.path("lib/root.zig"),
.target = options.target,
.optimize = options.optimize,
});

const docs_install = b.addInstallDirectory(.{
.install_dir = .prefix,
.install_subdir = "docs",
.source_dir = lib.getEmittedDocs(),
});

docs_step.dependOn(&docs_install.step);
}
9 changes: 1 addition & 8 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,5 @@
.version = "0.1.1",
.minimum_zig_version = "0.12.0",
.dependencies = .{},
.paths = .{
"./lib/",
"./test/",
"./build.zig",
"./build.zig.zon",
"./LICENSE",
"./README.md",
},
.paths = .{""},
}
9 changes: 9 additions & 0 deletions lib/QueryParamIterator.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/// The inner iterator
inner_iterator: TokenIterator(u8, .scalar),

/// Returns a slice of the current token, or null if tokenization is
/// complete, and advances to the next token.
pub fn next(self: *Self) ?QueryParam {
const field = self.inner_iterator.next() orelse return null;

Expand All @@ -14,6 +17,8 @@ pub fn next(self: *Self) ?QueryParam {
};
}

/// Returns a slice of the current token, or null if tokenization is
/// complete. Does not advance to the next token.
pub fn peek(self: *Self) ?QueryParam {
const field = self.inner_iterator.peek() orelse return null;

Expand All @@ -37,7 +42,11 @@ const Uri = std.Uri;

const Self = @This();

/// A structure representing a query parameter.
const QueryParam = struct {
/// The name of the query parameter.
name: []const u8,

/// The value of the query parameter.
value: []const u8,
};
4 changes: 4 additions & 0 deletions lib/root.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ const Uri = std.Uri;

pub const QueryParamIterator = @import("QueryParamIterator.zig");

/// Takes a `Uri` and attempts to parse the query parameter part into a
/// `StringHashMap`. This function allocates the hash map, so the caller must
/// free the returned memory after use.
pub fn parse(ally: Allocator, uri: Uri) Allocator.Error!StringHashMap([]const u8) {
var parsed = StringHashMap([]const u8).init(ally);

Expand All @@ -32,6 +35,7 @@ pub fn parse(ally: Allocator, uri: Uri) Allocator.Error!StringHashMap([]const u8
return parsed;
}

/// Takes a `Uri` and returns a `QueryParamIterator`.
pub fn iter(uri: Uri) QueryParamIterator {
const query = if (uri.query) |query| switch (query) {
.raw => query.raw,
Expand Down

0 comments on commit 1b9f029

Please sign in to comment.