Skip to content

Commit

Permalink
fix(jinja): fix #10
Browse files Browse the repository at this point in the history
close #10
  • Loading branch information
cathaysia committed Nov 24, 2023
1 parent 0d7798b commit 6394f38
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 3 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/gate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: "gate"

on:
pull_request:
push:
workflow_dispatch:

permissions:
contents: write

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}
submodules: true
fetch-depth: "0"
- uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: make fonts-noto-cjk fonts-noto-cjk-extra
version: 1.0
- name: Cache cargo
uses: actions/cache@v3
with:
path: |
~/.cargo/git/db/
~/.cargo/registry/index/
~/.cargo/registry/cache/
key: cargo_cache-${{ runner.os }}
- name: Install Nix
uses: cachix/install-nix-action@v18
with:
extra_nix_config: |
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
- name: Build Packages
run: |
mkdir -p public/
export RUST_LOG=DEBUG
nix develop --impure --command bash -c "cargo run -- config.toml -o example/vscode_plugins.nix"
nix develop --impure --command bash -c "cd example && nix develop --build"
6 changes: 5 additions & 1 deletion config.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
vscode_version = "1.84.2"
vscode_version = "1.84.2"
autogen_warning = "# Warning, this file is autogenerated by nix4vscode. Don't modify this manually."

[[extensions]]
publisher_name = "42crunch"
extension_name = "vscode-openapi"

[[extensions]]
publisher_name = "aaron-bond"
extension_name = "better-comments"
Expand Down
30 changes: 30 additions & 0 deletions example/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
description = "nix4vscode test flake";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
nixpkgs-stable.url = "github:nixos/nixpkgs/22.11";
flake-utils = {
url = "github:numtide/flake-utils";
};
};

outputs = { self, ... }@inputs: with inputs;
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
config.allowUnfree = true;
};
plugins = (import ./vscode_plugins.nix) { pkgs = pkgs; lib = lib; };
in
{
devShell = pkgs.mkShell {
buildInputs = [
plugins.eamodio.gitlens
(builtins.getAttr "42crunch" plugins).vscode-openapi
];
};
}
);
}
1 change: 1 addition & 0 deletions src/jinja.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ impl<'a> Generator<'a> {
.unwrap();

engine.add_filter("nixfmt", nixfmt);
engine.add_filter("to_string", to_string);

Self { engine }
}
Expand Down
5 changes: 5 additions & 0 deletions src/jinja/filters.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
use minijinja::Value;
use nixpkgs_fmt::reformat_string;

pub fn nixfmt(value: &str) -> String {
reformat_string(value)
}

pub fn to_string(value: Value) -> String {
format!(r#""{value}""#)
}
4 changes: 2 additions & 2 deletions src/jinja/template/nix_expression.nix.j2
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ in
{
{%- for item in extensions %}
{% if item.asset_url != None %}
{%- with uniqueId = [ item.publisher_name, '.', item.extension_name ] | join %}
{%- with uniqueId = [ item.publisher_name | to_string, '.', item.extension_name | to_string ] | join %}
{{ uniqueId }} = (vscode-utils.buildVscodeExtension {
name = "{{ uniqueId }}";
vscodeExtPublisher = "{{ item.publisher_name }}";
Expand All @@ -29,7 +29,7 @@ in

{%- for item in extensions %}
{% if item.asset_url == None %}
{%- with uniqueId = [ item.publisher_name, '.', item.extension_name ] | join %}
{%- with uniqueId = [ item.publisher_name | to_string, '.', item.extension_name | to_string ] | join %}
{{ uniqueId }} = vscode-utils.extensionFromVscodeMarketplace {
name = "{{ item.extension_name }}";
publisher = "{{ item.publisher_name }}";
Expand Down

0 comments on commit 6394f38

Please sign in to comment.