Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feature] opa-create: new tool to generate application skeletons
- Loading branch information
Showing
13 changed files
with
341 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ | |
### | ||
# jschecker | ||
<jschecker>: traverse | ||
<opa-create/**>: traverse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
Copyright © 2011 MLstate | ||
This file is part of OPA. | ||
OPA is free software: you can redistribute it and/or modify it under the | ||
terms of the GNU Affero General Public License, version 3, as published by | ||
the Free Software Foundation. | ||
OPA is distributed in the hope that it will be useful, but WITHOUT ANY | ||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for | ||
more details. | ||
You should have received a copy of the GNU Affero General Public License | ||
along with OPA. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/** | ||
* opa-create tool | ||
* | ||
* @category tools | ||
* @author Cedric Soulas | ||
* @destination PUBLIC | ||
* @stability experimental | ||
*/ | ||
|
||
import stdlib.{system, io.file} | ||
|
||
SRC_DIR = "tools/opa-create/template/mvc" | ||
resources = @static_content_directory("tools/opa-create/template/mvc") | ||
|
||
function CommandLine_ident(names,description,param_doc)(up) { | ||
{CommandLine.default_parser with | ||
~names, ~description, ~param_doc, | ||
function on_param(o) { parser { case int=Rule.ident : {no_params:up(int,o)} } } | ||
} | ||
} | ||
|
||
list(CommandLine.parser({string name})) cmdline_parsers = [ | ||
CommandLine_ident(["--name", "-n"], | ||
"Application name, without spaces, \"/\" or any other special characters", | ||
"app_name (no special characters)")({ function(name, r){ r with ~name}} | ||
) | ||
] | ||
|
||
options = | ||
cmdline = { | ||
init : { name : "wiki" }, | ||
parsers : cmdline_parsers, | ||
anonymous : [], | ||
title : "Opa Application Generator" | ||
} | ||
CommandLine.filter(cmdline) | ||
|
||
function write(file, content) { | ||
%%BslFile.of_string%%("./{file}", content) | ||
} | ||
|
||
function iter(file, f_content) { | ||
n = String.length(SRC_DIR) | ||
file = "{options.name}{String.sub(n, String.length(file) - n, file)}" | ||
if (File.exists(file)) { warning("File {file} already exists. \nPlease delete it and try again."); System.exit(1) } | ||
jlog("Generating {file}") | ||
content = String.replace("application_name", options.name, f_content()) | ||
write(file, content) | ||
} | ||
|
||
StringMap.iter(iter, resources) | ||
|
||
jlog("\nNow you can type:\n$ cd {options.name}\n$ make run") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
######################################## | ||
# USER VARIABLES | ||
|
||
EXE = application_name.exe | ||
PACKNAME = | ||
SRC = | ||
PCKDIR = ./plugins/ | ||
PCK = | ||
PLUGIN = | ||
PLUGINDIR = | ||
OTHER_DEPENDS = resources/* | ||
CONF_FILE = configuration | ||
|
||
#Compiler variables | ||
OPACOMPILER ?= opa | ||
FLAG = --opx-dir _build --import-package stdlib.database.mongo | ||
PORT = 8080 | ||
|
||
RUN_OPT = --db-local db/ | ||
|
||
default: exe | ||
|
||
run: exe | ||
./$(EXE) $(RUN_OPT) || true | ||
|
||
include Makefile.common |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
######################################## | ||
# MAKEFILE VARIABLES | ||
OPACOMPILER ?= opa | ||
OPA = $(OPACOMPILER) $(FLAG) $(OPAOPT) | ||
PWD ?= $(shell pwd) | ||
BUILDDIR ?= $(PWD)/_build | ||
export BUILDDIR | ||
OPAGENAPI ?= $(OPACOMPILER) --api-only | ||
DEPENDS = $(SRC) $(PCK:%=$(BUILDDIR)/%) $(PLUGIN:%=$(BUILDDIR)/%) | ||
|
||
ifdef CONF_FILE | ||
CONFIG = --conf $(CONF_FILE) --conf-opa-files | ||
else | ||
CONFIG = | ||
endif | ||
|
||
_ = $(shell mkdir -p $(BUILDDIR)) | ||
|
||
######################################## | ||
# MAIN RULE | ||
exe : $(EXE) | ||
pack : $(PACKNAME) | ||
doc : $(PACKDOC) doc.sub | ||
|
||
######################################## | ||
# MAIN PACKAGE BUILDING | ||
$(PACKNAME) : $(BUILDDIR)/$(PACKNAME) | ||
|
||
$(BUILDDIR)/$(PACKNAME) : $(DEPENDS) | ||
@echo "### Building package $(PACKNAME)" | ||
mkdir -p $(BUILDDIR) | ||
$(OPA) --autocompile $(SRC) $(PLUGIN:%=$(BUILDDIR)/%) --build-dir $(BUILDDIR) -I $(BUILDDIR) $(OPAOPT) | ||
@rm -rf $(BUILDDIR)/$(PACKNAME) | ||
@mv $(PACKNAME) $(BUILDDIR)/ | ||
|
||
######################################## | ||
# SUBS PACKAGE/PLUGIN BUILDING | ||
$(BUILDDIR)/%.opx : | ||
make $(@:$(BUILDDIR)/%.opx=-C $(PCKDIR)/%) pack | ||
|
||
$(BUILDDIR)/%.opp : | ||
make $(@:$(BUILDDIR)/%.opp=-C $(PLUGINDIR)/%) | ||
|
||
######################################## | ||
# EXECUTABLE BUILDING | ||
$(EXE) : pack $(SRC) $(MAINSRC) $(DEPENDS) $(OTHER_DEPENDS) | ||
@echo "### Building executable $(EXE) " | ||
mkdir -p $(BUILDDIR) | ||
$(OPA) $(COMPILOPT) $(MAINSRC) $(CONFIG) $(PLUGIN:%=$(BUILDDIR)/%) -o $@ --build-dir $(BUILDDIR)/$(EXE) | ||
|
||
$(EXE:%.exe=%.run) : $(EXE) | ||
./$(EXE) -p $(PORT) | ||
|
||
######################################## | ||
# Used by recursives makefile | ||
pack.depends : | ||
@echo $(PCK) $(PLUGIN) | ||
|
||
######################################## | ||
# CLEANING | ||
clean :: | ||
@$(PCK:%.opx=make -C $(PCKDIR)/% clean &&) $(PLUGIN:%.opp=make -C $(PLUGINDIR)/% clean &&) echo "### Cleaning $(BUILDDIR)"; | ||
@rm -rf $(BUILDDIR)/* _tracks/*; | ||
@if [ -n "$(EXE)" ]; then rm -rf $(EXE); fi | ||
@if [ -n "$(PACKDOC)" ]; then rm -rf $(PACKDOC); fi | ||
|
||
deep-clean :: clean | ||
@rm -rf opa-debug | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
application_name.controller: | ||
import application_name.view | ||
src/controller.opa | ||
|
||
application_name.view: | ||
import application_name.model | ||
import stdlib.themes.bootstrap | ||
src/view.opa | ||
|
||
application_name.model: | ||
src/model.opa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#main { | ||
margin-top: 50px; | ||
} | ||
|
||
textarea { | ||
width: 100%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
resources = @static_resource_directory("resources") | ||
|
||
custom = { | ||
parser { | ||
case r={Server.resource_map(resources)} : r | ||
case "/" : Resource.default_redirection_page("/index.html") | ||
case "/statistics" : Resource.page("Display", View.statistics()) | ||
case p=(.*) : path = Text.to_string(p); Resource.page(path, View.page(path)) | ||
} | ||
} | ||
|
||
Server.start(Server.http, [ | ||
{ register : | ||
[ { doctype : { html5 } }, | ||
{ js : [ ] }, | ||
{ css : [ "/resources/css/style.css"] } | ||
] | ||
}, | ||
{ ~custom } | ||
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
type page = { | ||
string path, | ||
string content, | ||
int counter | ||
} | ||
|
||
database application_name { | ||
page /page[{path}] | ||
} | ||
|
||
module Model { | ||
|
||
function get_content(path) { | ||
/application_name/page[{~path}]/counter++; | ||
/application_name/page[{~path}]/content | ||
} | ||
|
||
function set_content(path, content) { | ||
/application_name/page[{~path}]/content <- content | ||
} | ||
|
||
function statistics() { | ||
DbSet.iterator(/application_name/page) | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
module View { | ||
|
||
function template(content) { | ||
<div class="navbar navbar-fixed-top"> | ||
<div class="navbar-inner"> | ||
<div class="container"> | ||
<a class="brand" href="./index.html">application_name</a> | ||
<div class="nav-collapse collapse"> | ||
<ul class="nav"> | ||
<li><a href="/statistics">Statistics</a></li> | ||
</ul> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<div id=#main class="container-fluid"> | ||
<div class="row-fluid"> | ||
{content} | ||
</div> | ||
<hr> | ||
<footer> | ||
<p>application_name</p> | ||
</footer> | ||
</div> | ||
|
||
} | ||
|
||
function statistics() { | ||
tbody = Iter.fold( | ||
function(page, acc) { <>{acc}<tr><td>{page.path}</td><td>{page.counter}</td></tr></> }, | ||
Model.statistics(), <></> | ||
) | ||
content = | ||
<h3>Page statistics</h3> | ||
<table class="table table-bordered"> | ||
<thead><tr><td>Path</td><td>Counter</td></tr></thead> | ||
<tbody>{tbody}</tbody> | ||
</table> | ||
template(content) | ||
} | ||
|
||
function page(path) { | ||
content = | ||
<div class="hero-unit"> | ||
<h3>{path}</h3> | ||
<textarea id=#content rows="15">{ Model.get_content(path) }</textarea> | ||
<button class="btn" onclick={ function(_) Model.set_content(path, Dom.get_value(#content)) }> | ||
Save | ||
</button> | ||
</div>; | ||
template(content) | ||
} | ||
|
||
} | ||
|
Oops, something went wrong.