refactoring
- keep using find-exec (more bin files) - parse_convert command with spaces works
This commit is contained in:
parent
ad7a86f1c5
commit
7be7041aa2
7
Makefile
7
Makefile
@ -7,15 +7,18 @@ all:
|
||||
@echo Compiled
|
||||
|
||||
install: all
|
||||
@echo Installing zod executable to ${PREFIX}/bin
|
||||
@echo Installing zod executables to ${PREFIX}/bin
|
||||
@mkdir -p ${PREFIX}/bin
|
||||
@cp bin/zod ${PREFIX}/bin
|
||||
@cp bin/zod-render ${PREFIX}/bin
|
||||
@cp bin/zod-copy ${PREFIX}/bin
|
||||
@cp bin/zod-internal ${PREFIX}/bin
|
||||
@echo Installing awk lib files to ${AWKLIB}
|
||||
@mkdir -p ${AWKLIB}
|
||||
@cp lib/render.awk ${AWKLIB}
|
||||
@cp lib/markdown.awk ${AWKLIB}
|
||||
@cp lib/config.awk ${AWKLIB}
|
||||
@cp lib/opt_builder.awk ${AWKLIB}
|
||||
@cp lib/find_cmd.awk ${AWKLIB}
|
||||
@echo Installation Complete
|
||||
|
||||
uninstall:
|
||||
|
33
bin/zod
Executable file
33
bin/zod
Executable file
@ -0,0 +1,33 @@
|
||||
#!/bin/sh
|
||||
|
||||
# ZODIAC - a simple static site generator
|
||||
# Copyright (c) 2011 Chase Allen James <nx-zodiac@nu-ex.com>
|
||||
|
||||
zod_lib=/home/nuex/_dev/zodiac/lib
|
||||
proj="$1"
|
||||
target="$2"
|
||||
|
||||
. zod-internal
|
||||
|
||||
_zod_error() {
|
||||
echo -e ">>> ERROR: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
_zod_exec() {
|
||||
phase="$1"; shift
|
||||
__zod_config |
|
||||
awk -f "$zod_lib/config.awk" \
|
||||
-f "$zod_lib/find_cmd.awk" \
|
||||
-v phase="$phase" \
|
||||
-v zod_lib="$zod_lib" \
|
||||
-v proj="$proj" \
|
||||
-v target="$target" | sh
|
||||
}
|
||||
|
||||
[ "$#" -ne 2 ] && { echo "usage: zod projectdir targetdir"; exit; }
|
||||
[ ! -d "$proj" ] && _zod_error "project directory does not exist"
|
||||
[ ! -d "$target" ] && _zod_error "target directory does not exist"
|
||||
|
||||
_zod_exec "render"
|
||||
_zod_exec "copy"
|
11
bin/zod-copy
Executable file
11
bin/zod-copy
Executable file
@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
|
||||
. zod-internal
|
||||
|
||||
zod_lib="$1"; shift
|
||||
proj="$1"; shift
|
||||
target="$1"; shift
|
||||
file="$1"
|
||||
destination="$(__zod_destination "$file")"
|
||||
|
||||
cp "$file" "$destination"
|
31
bin/zod-internal
Executable file
31
bin/zod-internal
Executable file
@ -0,0 +1,31 @@
|
||||
#!/bin/sh
|
||||
|
||||
__zod_config() {
|
||||
cat - "$proj/.zod/config" <<! 2>/dev/null
|
||||
[parse]
|
||||
htm,html
|
||||
[parse_convert]
|
||||
md awk -f "/home/nuex/_dev/zodiac/lib/markdown.awk"
|
||||
[ignore]
|
||||
helpers.awk
|
||||
*.layout
|
||||
*.meta
|
||||
config
|
||||
!
|
||||
}
|
||||
|
||||
__zod_destination() {
|
||||
file="$1"
|
||||
# Find the target directory if one must be created
|
||||
subdir="${file%/*}"
|
||||
subdir="${subdir#$proj}"
|
||||
if [ "$subdir" ]; then
|
||||
destination="$target$subdir"
|
||||
mkdir -p "$destination"
|
||||
else
|
||||
# There is no directory to create in target,
|
||||
# i.e. file is in the root of the project
|
||||
destination="$target"
|
||||
fi
|
||||
echo $destination;
|
||||
}
|
24
bin/zod-render
Executable file
24
bin/zod-render
Executable file
@ -0,0 +1,24 @@
|
||||
#!/bin/sh
|
||||
|
||||
. zod-internal
|
||||
|
||||
zod_lib="$1"; shift
|
||||
proj="$1"; shift
|
||||
target="$1"; shift
|
||||
file="$1"; shift
|
||||
ext="${file##*.}"
|
||||
meta="${file%.$ext}.meta"
|
||||
page="${file##*/}"
|
||||
page="${page%.$ext}.html"
|
||||
destination=$(__zod_destination "$file")
|
||||
|
||||
set -- -f "$zod_lib/render.awk"
|
||||
set -- "$@" -f "$zod_lib/config.awk"
|
||||
[ -f "$proj/helpers.awk" ] && set -- "$@" -f "$proj/helpers.awk"
|
||||
set -- "$@" -
|
||||
[ -f "$proj/global.meta" ] && set -- "$@" "$proj/global.meta"
|
||||
[ -f "$meta" ] && set -- "$@" "$meta"
|
||||
set -- "$@" "$file"
|
||||
[ -f "$proj/main.layout" ] && set -- "$@" "$proj/main.layout"
|
||||
|
||||
__zod_config | awk "$@" > "$destination/$page"
|
@ -4,103 +4,30 @@
|
||||
# Copyright (c) 2011 Chase Allen James <nx-zodiac@nu-ex.com>
|
||||
|
||||
zod_lib=ZODLIB_PATH
|
||||
|
||||
proj="$1"
|
||||
target="$2"
|
||||
|
||||
. zod-internal
|
||||
|
||||
_zod_error() {
|
||||
echo -e ">>> ERROR: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
_zod_config() {
|
||||
cat - "$cfg" <<!
|
||||
[parse]
|
||||
htm,html
|
||||
[parse_convert]
|
||||
md awk -f "$zod_lib/markdown.awk"
|
||||
[ignore]
|
||||
helpers.awk
|
||||
*.layout
|
||||
*.meta
|
||||
config
|
||||
!
|
||||
}
|
||||
|
||||
_zod_find_opt_builder() {
|
||||
phase="$1"
|
||||
_zod_config |
|
||||
awk -f "$zod_lib/config.awk" \
|
||||
-f "$zod_lib/opt_builder.awk" \
|
||||
-v phase="$phase"
|
||||
}
|
||||
|
||||
_zod_destination() {
|
||||
file="$1"
|
||||
# Find the target directory if one must be created
|
||||
subdir="${file%/*}"
|
||||
subdir="${subdir#$proj}"
|
||||
if [ "$subdir" ]; then
|
||||
destination="$target$subdir"
|
||||
mkdir -p "$destination"
|
||||
else
|
||||
# There is no directory to create in target,
|
||||
# i.e. file is in the root of the project
|
||||
destination="$target"
|
||||
fi
|
||||
echo $destination;
|
||||
}
|
||||
|
||||
_zod_render() {
|
||||
file="$1"
|
||||
ext="${file##*.}"
|
||||
meta="${file%.$ext}.meta"
|
||||
|
||||
set -- -f "$zod_lib/config.awk"
|
||||
set -- "$@" -f "$zod_lib/render.awk"
|
||||
[ -f "$proj/helpers.awk" ] && set -- "$@" -f "$proj/helpers.awk"
|
||||
set -- "$@" -
|
||||
[ -f "$proj/global.meta" ] && set -- "$@" "$proj/global.meta"
|
||||
[ -f "$meta" ] && set -- "$@" "$meta"
|
||||
set -- "$@" "$file"
|
||||
[ -f "$proj/main.layout" ] && set -- "$@" "$proj/main.layout"
|
||||
|
||||
page="${file##*/}"
|
||||
page="${page%.$ext}.html"
|
||||
destination=$(_zod_destination "$file")
|
||||
_zod_config | awk "$@" > "$destination/$page"
|
||||
}
|
||||
|
||||
_zod_copy() {
|
||||
file="$1"
|
||||
destination="$(_zod_destination "$file")"
|
||||
cp "$file" "$destination"
|
||||
}
|
||||
|
||||
_zod_exec() {
|
||||
phase="$@"
|
||||
set -- "$proj" -type f
|
||||
for instruction in $(_zod_find_opt_builder "$phase" "$cfg"); do
|
||||
inst=$(echo $instruction | sed 's/"//g')
|
||||
case $inst in
|
||||
or ) set -- "$@" -o;;
|
||||
not ) set -- "$@" !;;
|
||||
* ) set -- "$@" -name "$inst";;
|
||||
esac
|
||||
done
|
||||
find "$@" | while read -r file; do
|
||||
case "$phase" in
|
||||
render ) _zod_render "$file";;
|
||||
copy ) _zod_copy "$file";;
|
||||
esac
|
||||
done
|
||||
phase="$1"; shift
|
||||
__zod_config |
|
||||
awk -f "$zod_lib/config.awk" \
|
||||
-f "$zod_lib/find_cmd.awk" \
|
||||
-v phase="$phase" \
|
||||
-v zod_lib="$zod_lib" \
|
||||
-v proj="$proj" \
|
||||
-v target="$target" | sh
|
||||
}
|
||||
|
||||
[ "$#" -ne 2 ] && { echo "usage: zod projectdir targetdir"; exit; }
|
||||
[ ! -d "$proj" ] && _zod_error "project directory does not exist"
|
||||
[ ! -d "$target" ] && _zod_error "target directory does not exist"
|
||||
|
||||
[ -f "$proj/.zod/config" ] && cfg="$proj/.zod/config"
|
||||
|
||||
_zod_exec "render"
|
||||
_zod_exec "copy"
|
||||
|
@ -2,18 +2,15 @@
|
||||
# Parse zodiac config
|
||||
#
|
||||
|
||||
# Ignore comments and empty lines
|
||||
action == "config" && (NF == 0 || /^;/) {
|
||||
next
|
||||
}
|
||||
|
||||
# Get the current section
|
||||
action == "config" && (/^\[/ && match($0, /\[([[:alnum:]_]).*\]/)) {
|
||||
action == "config" && match($0, /\[([[:alnum:]_]).*\]/) {
|
||||
section = substr($0, (RSTART + 1), (RLENGTH - 2))
|
||||
next
|
||||
}
|
||||
|
||||
# Get filters in the parse section
|
||||
action == "config" && section == "parse" {
|
||||
n = split($0, exts, ",")
|
||||
for (i in exts) {
|
||||
@ -24,21 +21,19 @@ action == "config" && section == "parse" {
|
||||
next
|
||||
}
|
||||
|
||||
# Get filters in the parse_convert section
|
||||
action == "config" && section == "parse_convert" && (NF > 1) {
|
||||
ext_list = $1
|
||||
cmd = $2
|
||||
cmd = substr($0, length(ext_list) + 1)
|
||||
n = split(ext_list, exts, ",")
|
||||
for (i in exts) {
|
||||
ext = exts[i]
|
||||
gsub(/ /, "", ext)
|
||||
filter[ext] = cmd
|
||||
print cmd >> "awk.log"
|
||||
}
|
||||
next
|
||||
}
|
||||
|
||||
# Get ignore patterns
|
||||
action == "config" && section == "ignore" {
|
||||
ignore[ignore_count++] = $0
|
||||
next
|
||||
}
|
||||
|
30
lib/find_cmd.awk
Normal file
30
lib/find_cmd.awk
Normal file
@ -0,0 +1,30 @@
|
||||
BEGIN {
|
||||
section = "none"
|
||||
action = "config"
|
||||
}
|
||||
|
||||
END {
|
||||
for (ext in filter) {
|
||||
exts[ext_count++] = "-name \"*." ext "\""
|
||||
}
|
||||
for (i = 0; i < length(ignore); i++) {
|
||||
opts[opt_count++] = "!"
|
||||
opts[opt_count++] = "-name \"" ignore[i] "\""
|
||||
}
|
||||
if (phase == "render") {
|
||||
opts[opt_count++] = exts[0]
|
||||
for (i = 1; i < length(exts); i++) {
|
||||
opts[opt_count++] = "-o"
|
||||
opts[opt_count++] = exts[i]
|
||||
}
|
||||
} else if (phase == "copy") {
|
||||
for (i = 0; i < length(exts); i++) {
|
||||
opts[opt_count++] = "!"
|
||||
opts[opt_count++] = exts[i]
|
||||
}
|
||||
}
|
||||
for (i = 0; i < length(opts); i++) {
|
||||
optpart = optpart " " opts[i]
|
||||
}
|
||||
printf "find \"%s\" -type f \\( %s \\) -exec zod-%s \"%s\" \"%s\" \"%s\" {} \\;", proj, optpart, phase, zod_lib, proj, target
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
#
|
||||
# Build find options
|
||||
#
|
||||
|
||||
BEGIN {
|
||||
section = "none"
|
||||
action = "config"
|
||||
}
|
||||
|
||||
END {
|
||||
for (ext in filter) {
|
||||
exts[ext_count++] = "\"" "*." ext "\""
|
||||
}
|
||||
for (i = 0; i < length(ignore); i++) {
|
||||
instructions[inst_count++] = "not"
|
||||
instructions[inst_count++] = "\"" ignore[i] "\""
|
||||
}
|
||||
if (phase == "render") {
|
||||
instructions[inst_count++] = exts[0]
|
||||
for (i = 1; i < length(exts); i++) {
|
||||
instructions[inst_count++] = "or"
|
||||
instructions[inst_count++] = exts[i]
|
||||
}
|
||||
} else if (phase == "copy") {
|
||||
for (i = 0; i < length(exts); i++) {
|
||||
instructions[inst_count++] = "not"
|
||||
instructions[inst_count++] = exts[i]
|
||||
}
|
||||
}
|
||||
# print all instructions
|
||||
for (i = 0; i < length(instructions); i++) {
|
||||
instruction = instruction " " instructions[i]
|
||||
}
|
||||
print instruction
|
||||
}
|
@ -13,7 +13,7 @@ BEGIN {
|
||||
{
|
||||
split(FILENAME, parts, ".")
|
||||
ext = parts[length(parts)]
|
||||
if ((FILENAME == "config") || (FILENAME == "-")) {
|
||||
if (FILENAME == "-") {
|
||||
action = "config"
|
||||
} else if (ext == "meta") {
|
||||
action = "meta"
|
||||
|
Loading…
Reference in New Issue
Block a user