Skip to content

Commit d26b783

Browse files
committed
Move some of the header code from compile into it's own module
1 parent aa00138 commit d26b783

File tree

4 files changed

+41
-16
lines changed

4 files changed

+41
-16
lines changed

fnl/nfnl/compile.fnl

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,16 @@
44
(local fennel (autoload :nfnl.fennel))
55
(local notify (autoload :nfnl.notify))
66
(local config (autoload :nfnl.config))
7+
(local header (autoload :nfnl.header))
78

89
(local mod {})
910

10-
(local header-marker "[nfnl]")
11-
12-
(fn with-header [file src]
13-
(.. "-- " header-marker " " file "\n" src))
14-
1511
(fn safe-target? [path]
1612
"Reads the given file and checks if it contains our header marker on the
1713
first line. Returns true if it contains the marker, we're allowed to
1814
overwrite this file."
19-
(let [header (fs.read-first-line path)]
20-
(or (core.nil? header)
21-
(not (core.nil? (header:find header-marker 1 true))))))
15+
(let [line (fs.read-first-line path)]
16+
(or (not line) (header.tagged? line))))
2217

2318
(fn macro-source? [source]
2419
(string.find source "%s*;+%s*%[nfnl%-macro%]"))
@@ -74,7 +69,7 @@
7469
{:status :ok
7570
:source-path path
7671
:result (.. (if (cfg [:header-comment])
77-
(with-header rel-file-name res)
72+
(header.with-header rel-file-name res)
7873
res)
7974
"\n")})
8075
(do

fnl/nfnl/header.fnl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
(local {: autoload : define} (require :nfnl.module))
2+
(local core (autoload :nfnl.core))
3+
4+
(local M (define :nfnl.header))
5+
6+
(local tag "[nfnl]")
7+
8+
(fn M.with-header [file src]
9+
"Return the source with an nfnl header prepended."
10+
(.. "-- " tag " " file "\n" src))
11+
12+
(fn M.tagged? [s]
13+
"Is the line an nfnl tagged header line?"
14+
(core.string? (s:find tag 1 true)))
15+
16+
(fn M.source-path []
17+
"")
18+
19+
M

lua/nfnl/compile.lua

Lines changed: 4 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lua/nfnl/header.lua

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)