Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#970 - Allow for additional template Modifiers #983

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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