Skip to content

Commit

Permalink
970 - Allow for additional template Modifiers
Browse files Browse the repository at this point in the history
* Templates now exist under templates/
* Templates can now have a directory and extension defined
* Added hrl template
* Updated supervisor template to include Child Specs
* Made some bootstrap templates generateable via new
  • Loading branch information
artman41 committed Jul 4, 2023
1 parent 04c473a commit 90a238b
Show file tree
Hide file tree
Showing 9 changed files with 469 additions and 418 deletions.
8 changes: 8 additions & 0 deletions build.config
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ core/docs
core/rel
core/test
core/compat
core/templates

# Templates
templates/bootstrap
templates/release
templates/erlang
templates/cowboy
templates/ranch

# Plugins.
plugins/asciidoc
Expand Down
60 changes: 60 additions & 0 deletions core/templates.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
new-app:
ifndef in
$(error Usage: $(MAKE) new-app in=APP)
endif
ifneq ($(wildcard $(APPS_DIR)/$in),)
$(error Error: Application $in already exists)
endif
$(eval p := $(in))
$(if $(shell echo $p | LC_ALL=C grep -x "[a-z0-9_]*"),,\
$(error Error: Invalid characters in the application name))
$(eval n := $(in))
$(verbose) mkdir -p $(APPS_DIR)/$p/src/
$(verbose) $(call core_render,bs_apps_Makefile,$(APPS_DIR)/$p/Makefile)
$(verbose) $(call core_render,tpl_supervisor,$(APPS_DIR)/$p/src/$p_sup.erl)
$(verbose) $(call core_render,tpl_app,$(APPS_DIR)/$p/src/$p_app.erl)
ifdef LEGACY
$(eval app := $(p)_app)
$(verbose) $(call core_render,tpl_appsrc,$(APPS_DIR)/$p/src/$p.app.src)
endif

new-lib:
ifndef in
$(error Usage: $(MAKE) new-lib in=APP)
endif
ifneq ($(wildcard $(APPS_DIR)/$in),)
$(error Error: Application $in already exists)
endif
$(eval p := $(in))
$(if $(shell echo $p | LC_ALL=C grep -x "[a-z0-9_]*"),,\
$(error Error: Invalid characters in the application name))
$(verbose) mkdir -p $(APPS_DIR)/$p/src/
$(verbose) $(call core_render,bs_apps_Makefile,$(APPS_DIR)/$p/Makefile)
ifdef LEGACY
$(verbose) $(call core_render,tpl_appsrc,$(APPS_DIR)/$p/src/$p.app.src)
endif

new:
ifeq ($(wildcard src/)$(in),)
$(error Error: src/ directory does not exist)
endif
ifndef t
$(error Usage: $(MAKE) new t=TEMPLATE n=NAME [in=APP])
endif
ifndef n
$(error Usage: $(MAKE) new t=TEMPLATE n=NAME [in=APP])
endif
$(eval dir := $(if $(tpl_$(t)_dir),$(tpl_$(t)_dir),./src))
$(eval ext := $(if $(tpl_$(t)_ext),$(tpl_$(t)_ext),.erl))
ifeq ($(wildcard $(dir)),)
$(verbose) mkdir -p $(dir)
endif
ifdef in
$(verbose) $(call core_render,tpl_$(t),$(APPS_DIR)/$(in)/$(dir)/$(n)$(ext))
else
$(verbose) $(call core_render,tpl_$(t),$(dir)/$(n)$(ext))
endif

list-templates:
$(verbose) @echo Available templates:
$(verbose) printf " %s\n" $(sort $(patsubst tpl_%,%,$(filter-out %_ext %_dir,$(filter tpl_%,$(.VARIABLES)))))
Loading

0 comments on commit 90a238b

Please sign in to comment.