diff options
-rw-r--r-- | Makefile | 44 | ||||
-rw-r--r-- | bin/jimmy.scm | 48 | ||||
-rw-r--r-- | jimmy.egg | 25 | ||||
-rw-r--r-- | lib/emit.scm (renamed from src/emit.scm) | 5 | ||||
-rw-r--r-- | lib/html.scm (renamed from src/html.scm) | 0 | ||||
-rw-r--r-- | lib/main.scm | 19 | ||||
-rw-r--r-- | lib/read.scm (renamed from src/read.scm) | 0 | ||||
-rw-r--r-- | lib/util.scm (renamed from src/util.scm) | 0 | ||||
-rw-r--r-- | lib/wrap.scm (renamed from src/wrap.scm) | 4 |
9 files changed, 119 insertions, 26 deletions
diff --git a/Makefile b/Makefile index 8eead3a..d2a1003 100644 --- a/Makefile +++ b/Makefile | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | NAME = jimmy | 3 | NAME = jimmy |
4 | CSC = /usr/bin/csc | 4 | CSC = /usr/bin/csc |
5 | CSC_OPTIONS = -setup-mode -host -I $(PWD) -C -I$(PWD) | 5 | CSC_OPTIONS = -setup-mode -host -I $(PWD) -C -I$(BUILD) |
6 | CSC_LIB_OPTIONS = -D compiling-extension -emit-all-import-libraries -dynamic -regenerate-import-libraries | 6 | CSC_LIB_OPTIONS = -D compiling-extension -emit-all-import-libraries -dynamic -regenerate-import-libraries |
7 | CSC_OPTIONS_EXTRA = -X utf8 -X module-declarations | 7 | CSC_OPTIONS_EXTRA = -X utf8 -X module-declarations |
8 | CSI = /usr/bin/csi | 8 | CSI = /usr/bin/csi |
@@ -12,7 +12,7 @@ TEST_ENV = env BUILD=$(BUILD) TESTS=$(TESTS) | |||
12 | TEST_ENV_EXTRA = TEST_USE_ANSI=0 | 12 | TEST_ENV_EXTRA = TEST_USE_ANSI=0 |
13 | 13 | ||
14 | .PHONY: all test clean install uninstall | 14 | .PHONY: all test clean install uninstall |
15 | all: build/jimmy.util.so build/jimmy.read.so build/jimmy.emit.so build/jimmy.html.so build/jimmy.wrap.so | 15 | all: build/jimmy.util.so build/jimmy.read.so build/jimmy.emit.so build/jimmy.html.so build/jimmy.wrap.so build/jimmy.main.so build/jimmy |
16 | test: all | 16 | test: all |
17 | cd $(BUILD) && $(TEST_ENV) $(TEST_ENV_EXTRA) $(CSI) -setup-mode -s $(TESTS)/run.scm $(NAME) | 17 | cd $(BUILD) && $(TEST_ENV) $(TEST_ENV_EXTRA) $(CSI) -setup-mode -s $(TESTS)/run.scm $(NAME) |
18 | clean: | 18 | clean: |
@@ -24,28 +24,38 @@ uninstall: | |||
24 | 24 | ||
25 | # jimmy | 25 | # jimmy |
26 | 26 | ||
27 | build/jimmy.util.so: src/util.scm | 27 | build/jimmy.util.so: lib/util.scm |
28 | @mkdir -p $(BUILD) | 28 | @mkdir -p $(BUILD) |
29 | cd $(BUILD) && \ | 29 | $(CSC) $(CSC_OPTIONS) $(CSC_LIB_OPTIONS) $(CSC_OPTIONS_EXTRA) $< -o $@ |
30 | $(CSC) $(CSC_OPTIONS) $(CSC_LIB_OPTIONS) $(CSC_OPTIONS_EXTRA) ../$< -o $(@F) | ||
31 | @test -f jimmy.util.import.scm &&mv jimmy.util.import.scm $(BUILD)/||true | 30 | @test -f jimmy.util.import.scm &&mv jimmy.util.import.scm $(BUILD)/||true |
32 | build/jimmy.read.so: src/read.scm src/util.scm | 31 | |
32 | build/jimmy.read.so: lib/read.scm lib/util.scm | ||
33 | @mkdir -p $(BUILD) | 33 | @mkdir -p $(BUILD) |
34 | cd $(BUILD) && \ | 34 | $(CSC) $(CSC_OPTIONS) $(CSC_LIB_OPTIONS) $(CSC_OPTIONS_EXTRA) $< -o $@ |
35 | $(CSC) $(CSC_OPTIONS) $(CSC_LIB_OPTIONS) $(CSC_OPTIONS_EXTRA) ../$< -o $(@F) | ||
36 | @test -f jimmy.read.import.scm &&mv jimmy.read.import.scm $(BUILD)/||true | 35 | @test -f jimmy.read.import.scm &&mv jimmy.read.import.scm $(BUILD)/||true |
37 | build/jimmy.emit.so: src/emit.scm src/util.scm | 36 | |
37 | build/jimmy.emit.so: lib/emit.scm lib/util.scm | ||
38 | @mkdir -p $(BUILD) | 38 | @mkdir -p $(BUILD) |
39 | cd $(BUILD) && \ | 39 | $(CSC) $(CSC_OPTIONS) $(CSC_LIB_OPTIONS) $(CSC_OPTIONS_EXTRA) $< -o $@ |
40 | $(CSC) $(CSC_OPTIONS) $(CSC_LIB_OPTIONS) $(CSC_OPTIONS_EXTRA) ../$< -o $(@F) | ||
41 | @test -f jimmy.emit.import.scm &&mv jimmy.emit.import.scm $(BUILD)/||true | 40 | @test -f jimmy.emit.import.scm &&mv jimmy.emit.import.scm $(BUILD)/||true |
42 | build/jimmy.html.so: src/html.scm src/util.scm src/emit.scm | 41 | |
42 | build/jimmy.html.so: lib/html.scm lib/util.scm lib/emit.scm | ||
43 | @mkdir -p $(BUILD) | 43 | @mkdir -p $(BUILD) |
44 | cd $(BUILD) && \ | 44 | $(CSC) $(CSC_OPTIONS) $(CSC_LIB_OPTIONS) $(CSC_OPTIONS_EXTRA) $< -o $@ |
45 | $(CSC) $(CSC_OPTIONS) $(CSC_LIB_OPTIONS) $(CSC_OPTIONS_EXTRA) ../$< -o $(@F) | ||
46 | @test -f jimmy.html.import.scm &&mv jimmy.html.import.scm $(BUILD)/||true | 45 | @test -f jimmy.html.import.scm &&mv jimmy.html.import.scm $(BUILD)/||true |
47 | build/jimmy.wrap.so: src/wrap.scm src/util.scm src/emit.scm | 46 | |
47 | build/jimmy.wrap.so: lib/wrap.scm lib/util.scm lib/emit.scm | ||
48 | @mkdir -p $(BUILD) | 48 | @mkdir -p $(BUILD) |
49 | cd $(BUILD) && \ | 49 | $(CSC) $(CSC_OPTIONS) $(CSC_LIB_OPTIONS) $(CSC_OPTIONS_EXTRA) $< -o $@ |
50 | $(CSC) $(CSC_OPTIONS) $(CSC_LIB_OPTIONS) $(CSC_OPTIONS_EXTRA) ../$< -o $(@F) | ||
51 | @test -f jimmy.wrap.import.scm &&mv jimmy.wrap.import.scm $(BUILD)/||true | 50 | @test -f jimmy.wrap.import.scm &&mv jimmy.wrap.import.scm $(BUILD)/||true |
51 | |||
52 | build/jimmy.main.so: lib/main.scm lib/util.scm lib/emit.scm lib/read.scm lib/wrap.scm | ||
53 | @mkdir -p $(BUILD) | ||
54 | $(CSC) $(CSC_OPTIONS) $(CSC_LIB_OPTIONS) $(CSC_OPTIONS_EXTRA) $< -o $@ | ||
55 | @test -f jimmy.main.import.scm &&mv jimmy.main.import.scm $(BUILD)/||true | ||
56 | |||
57 | build/jimmy: bin/jimmy.scm lib/main.scm | ||
58 | @mkdir -p $(BUILD) | ||
59 | $(CSC) $(CSC_OPTIONS) $(CSC_OPTIONS_EXTRA) $< -o $@ | ||
60 | @test -f jimmy.import.scm &&mv jimmy.import.scm $(BUILD)/||true | ||
61 | |||
diff --git a/bin/jimmy.scm b/bin/jimmy.scm new file mode 100644 index 0000000..17e12ba --- /dev/null +++ b/bin/jimmy.scm | |||
@@ -0,0 +1,48 @@ | |||
1 | ;;; (jimmy main) --- the program | ||
2 | |||
3 | (import (chicken file) | ||
4 | (chicken port) | ||
5 | (chicken process-context) | ||
6 | (jimmy main) | ||
7 | args) | ||
8 | |||
9 | (define opts | ||
10 | (list (args:make-option (t to) (required: "FORMAT") | ||
11 | (string-append "Translate input to FORMAT." | ||
12 | " One of `gemini', `html', or" | ||
13 | " a filename.")) | ||
14 | (args:make-option (n no-extensions) #:none | ||
15 | "Don't use gemtext extensions.") | ||
16 | (args:make-option (T template) (required: "TEMPLATE") | ||
17 | "Wrap the generated text in TEMPLATE.") | ||
18 | (args:make-option (h help) #:none "Display this text" | ||
19 | (usage 0)))) | ||
20 | |||
21 | (define (usage #!optional (exit-code 1)) | ||
22 | (with-output-to-port (current-error-port) | ||
23 | (lambda () | ||
24 | (print "Usage: " (car (argv)) " [OPTIONS...] [FILE]") | ||
25 | (newline) | ||
26 | (print (args:usage options)) | ||
27 | (print "Report bugs to acdw@acdw.net."))) | ||
28 | (exit exit-code)) | ||
29 | |||
30 | (define (main args) | ||
31 | (receive (options operands) (args:parse args opts) | ||
32 | (let ((to (alist-ref 'to options)) | ||
33 | (template (alist-ref 'template options))) | ||
34 | |||
35 | (cond | ||
36 | ((not to)) ; default: gemini | ||
37 | ((equal? to "html") | ||
38 | (import (jimmy html))) | ||
39 | ((file-exists? to) | ||
40 | (load to)) | ||
41 | (else (error "File does not exist" to))) | ||
42 | |||
43 | (print (apply jimmy (list (car operands) template)))))) | ||
44 | |||
45 | (cond-expand | ||
46 | (compiling | ||
47 | (main (command-line-arguments))) | ||
48 | (else)) | ||
diff --git a/jimmy.egg b/jimmy.egg index 84bf83c..be5b680 100644 --- a/jimmy.egg +++ b/jimmy.egg | |||
@@ -2,6 +2,7 @@ | |||
2 | (synopsis "The ssg king") | 2 | (synopsis "The ssg king") |
3 | (license "BSD-3-clause") | 3 | (license "BSD-3-clause") |
4 | (dependencies (chicken "5.3.0") | 4 | (dependencies (chicken "5.3.0") |
5 | args ; for (jimmy main) | ||
5 | module-declarations | 6 | module-declarations |
6 | utf8) | 7 | utf8) |
7 | (test-dependencies test) | 8 | (test-dependencies test) |
@@ -10,22 +11,34 @@ | |||
10 | (components | 11 | (components |
11 | ;; Utility library | 12 | ;; Utility library |
12 | (extension jimmy.util | 13 | (extension jimmy.util |
13 | (source src/util.scm)) | 14 | (source lib/util.scm)) |
14 | ;; Read gemini files into internal format | 15 | ;; Read gemini files into internal format |
15 | (extension jimmy.read | 16 | (extension jimmy.read |
16 | (source src/read.scm) | 17 | (source lib/read.scm) |
17 | (component-dependencies jimmy.util)) | 18 | (component-dependencies jimmy.util)) |
18 | ;; Emit the output format (includes gemini) | 19 | ;; Emit the output format (includes gemini) |
19 | (extension jimmy.emit | 20 | (extension jimmy.emit |
20 | (source src/emit.scm) | 21 | (source lib/emit.scm) |
21 | (component-dependencies jimmy.util)) | 22 | (component-dependencies jimmy.util)) |
22 | ;; Emit HTML -- import this *after* emit (is this the best way?) | 23 | ;; Emit HTML -- import this *after* emit (is this the best way?) |
23 | (extension jimmy.html | 24 | (extension jimmy.html |
24 | (source src/html.scm) | 25 | (source lib/html.scm) |
25 | (component-dependencies jimmy.util | 26 | (component-dependencies jimmy.util |
26 | jimmy.emit)) | 27 | jimmy.emit)) |
27 | ;; Wrap output in templates | 28 | ;; Wrap output in templates |
28 | (extension jimmy.wrap | 29 | (extension jimmy.wrap |
29 | (source src/wrap.scm) | 30 | (source lib/wrap.scm) |
30 | (component-dependencies jimmy.util | 31 | (component-dependencies jimmy.util |
31 | jimmy.emit)))) | 32 | jimmy.emit)) |
33 | ;; Main entry point (for command line) | ||
34 | (extension jimmy.main | ||
35 | (source lib/main.scm) | ||
36 | (component-dependencies jimmy.util | ||
37 | jimmy.emit | ||
38 | jimmy.read | ||
39 | jimmy.wrap)) | ||
40 | ;; Command-line program | ||
41 | (program jimmy | ||
42 | (csc-options -static) | ||
43 | (source bin/jimmy.scm) | ||
44 | (component-dependencies jimmy.main)))) | ||
diff --git a/src/emit.scm b/lib/emit.scm index 4c3581f..2a8ab97 100644 --- a/src/emit.scm +++ b/lib/emit.scm | |||
@@ -3,6 +3,7 @@ | |||
3 | (import scheme (chicken base) | 3 | (import scheme (chicken base) |
4 | (chicken format) | 4 | (chicken format) |
5 | (chicken irregex) | 5 | (chicken irregex) |
6 | (chicken port) | ||
6 | (chicken string) | 7 | (chicken string) |
7 | (only utf8-srfi-13 string-join) | 8 | (only utf8-srfi-13 string-join) |
8 | (jimmy util)) | 9 | (jimmy util)) |
@@ -10,6 +11,10 @@ | |||
10 | (define-public (emit doc) | 11 | (define-public (emit doc) |
11 | (for-each display (map format-stanza doc))) | 12 | (for-each display (map format-stanza doc))) |
12 | 13 | ||
14 | (define-public (emit-string doc) | ||
15 | (with-output-to-string | ||
16 | (lambda () (emit doc)))) | ||
17 | |||
13 | (define-public formats | 18 | (define-public formats |
14 | (make-parameter | 19 | (make-parameter |
15 | ;; (TYPE (line . LINE-FMT) (stanza . STANZA-FMT) (inline . INLINE-FMT)) | 20 | ;; (TYPE (line . LINE-FMT) (stanza . STANZA-FMT) (inline . INLINE-FMT)) |
diff --git a/src/html.scm b/lib/html.scm index 07cd921..07cd921 100644 --- a/src/html.scm +++ b/lib/html.scm | |||
diff --git a/lib/main.scm b/lib/main.scm new file mode 100644 index 0000000..b97d66a --- /dev/null +++ b/lib/main.scm | |||
@@ -0,0 +1,19 @@ | |||
1 | (declare (module (jimmy main))) | ||
2 | |||
3 | (import scheme (chicken base) | ||
4 | (chicken port) | ||
5 | (jimmy util) | ||
6 | (jimmy read) | ||
7 | (jimmy emit) | ||
8 | (jimmy wrap)) | ||
9 | |||
10 | (define-public (jimmy #!optional file template) | ||
11 | (parameterize ((current-input-port | ||
12 | (if file | ||
13 | (open-input-file file) | ||
14 | (current-input-port)))) | ||
15 | (let ((doc (parse)) | ||
16 | (post-proc (if template | ||
17 | (cut wrap-with <> template) | ||
18 | emit-string))) | ||
19 | (post-proc doc)))) | ||
diff --git a/src/read.scm b/lib/read.scm index 1b611bb..1b611bb 100644 --- a/src/read.scm +++ b/lib/read.scm | |||
diff --git a/src/util.scm b/lib/util.scm index c71c600..c71c600 100644 --- a/src/util.scm +++ b/lib/util.scm | |||
diff --git a/src/wrap.scm b/lib/wrap.scm index aa077d8..f801029 100644 --- a/src/wrap.scm +++ b/lib/wrap.scm | |||
@@ -14,9 +14,7 @@ | |||
14 | (cons (string-append "{{" (car el) "}}") | 14 | (cons (string-append "{{" (car el) "}}") |
15 | (string-intersperse (cdr el) " "))) | 15 | (string-intersperse (cdr el) " "))) |
16 | (alist-walk document 'meta))) | 16 | (alist-walk document 'meta))) |
17 | (body (cons "{{body}}" | 17 | (body (cons "{{body}}" (emit-string document)))) |
18 | (with-output-to-string | ||
19 | (lambda () (emit document)))))) | ||
20 | (string-translate* template (cons body meta)))) | 18 | (string-translate* template (cons body meta)))) |
21 | 19 | ||
22 | (define-public (wrap-with document file) | 20 | (define-public (wrap-with document file) |