commit
f57ca28684
@ -0,0 +1 @@ |
|||||||
|
mocks |
||||||
@ -0,0 +1,22 @@ |
|||||||
|
The MIT License |
||||||
|
|
||||||
|
Copyright (c) 2021 Robert Strutts |
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining |
||||||
|
a copy of this software and associated documentation files (the |
||||||
|
"Software"), to deal in the Software without restriction, including |
||||||
|
without limitation the rights to use, copy, modify, merge, publish, |
||||||
|
distribute, sublicense, and/or sell copies of the Software, and to |
||||||
|
permit persons to whom the Software is furnished to do so, subject to |
||||||
|
the following conditions: |
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be |
||||||
|
included in all copies or substantial portions of the Software. |
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
||||||
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
||||||
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
||||||
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
||||||
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
||||||
@ -0,0 +1,9 @@ |
|||||||
|
#mocks |
||||||
|
|
||||||
|
Go Templates used with tts_project. |
||||||
|
|
||||||
|
## Creates mockups. |
||||||
|
|
||||||
|
Jump into this folder and then run: |
||||||
|
|
||||||
|
$ build go |
||||||
@ -0,0 +1,206 @@ |
|||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"flag" |
||||||
|
"fmt" |
||||||
|
"io" |
||||||
|
"log" |
||||||
|
"os" |
||||||
|
"path/filepath" |
||||||
|
"text/template" |
||||||
|
) |
||||||
|
|
||||||
|
const version = "1.0.0" |
||||||
|
|
||||||
|
var root string |
||||||
|
var app_dir string |
||||||
|
var method_name string |
||||||
|
var main_file string |
||||||
|
var root_in string |
||||||
|
var verbose bool |
||||||
|
|
||||||
|
type PhpTemplate struct { |
||||||
|
Root string |
||||||
|
Subfolder string |
||||||
|
File string |
||||||
|
Method string |
||||||
|
} |
||||||
|
|
||||||
|
// Declare type pointer to a template
|
||||||
|
var temp_ctrl *template.Template |
||||||
|
var temp_inputs *template.Template |
||||||
|
var temp_models *template.Template |
||||||
|
var temp_outputs *template.Template |
||||||
|
var temp_views *template.Template |
||||||
|
var php_tpl PhpTemplate |
||||||
|
|
||||||
|
func init_template() { |
||||||
|
// template.Must takes the reponse of template.ParseFiles and does error checking
|
||||||
|
temp_ctrl = template.Must(template.ParseFiles(root + "/go_text_templates/ctrl.txt")) |
||||||
|
temp_inputs = template.Must(template.ParseFiles(root + "/go_text_templates/inputs.txt")) |
||||||
|
temp_models = template.Must(template.ParseFiles(root + "/go_text_templates/models.txt")) |
||||||
|
temp_outputs = template.Must(template.ParseFiles(root + "/go_text_templates/outputs.txt")) |
||||||
|
temp_views = template.Must(template.ParseFiles(root + "/go_text_templates/views.txt")) |
||||||
|
} |
||||||
|
|
||||||
|
func make_a_dir(mydir string) { |
||||||
|
if _, err := os.Stat(root + "/" + mydir); os.IsNotExist(err) { |
||||||
|
os.Mkdir(root+"/"+mydir, 0775) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
func use_file(filename string) io.Writer { |
||||||
|
if verbose { |
||||||
|
fmt.Println("------------") |
||||||
|
return os.Stdout |
||||||
|
} |
||||||
|
|
||||||
|
_, err_fnf := os.Stat(root + filename) |
||||||
|
if !os.IsNotExist(err_fnf) { |
||||||
|
log.Fatalf("Sorry, %s already exists!", root+filename) |
||||||
|
} |
||||||
|
|
||||||
|
file, err := os.Create(root + filename) |
||||||
|
if err != nil { |
||||||
|
log.Fatal(err) |
||||||
|
} |
||||||
|
return file |
||||||
|
} |
||||||
|
|
||||||
|
func ctrl() { |
||||||
|
mydir := "/controllers/" + app_dir |
||||||
|
make_a_dir(mydir) |
||||||
|
file := use_file(mydir + "/" + main_file + "_ctrl.php") |
||||||
|
|
||||||
|
temp_err := temp_ctrl.Execute(file, php_tpl) |
||||||
|
if temp_err != nil { |
||||||
|
log.Fatalln(temp_err) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
func inputs() { |
||||||
|
mydir := "/inputs/" + app_dir |
||||||
|
make_a_dir(mydir) |
||||||
|
file := use_file(mydir + "/" + main_file + "_in.php") |
||||||
|
|
||||||
|
temp_err := temp_inputs.Execute(file, php_tpl) |
||||||
|
if temp_err != nil { |
||||||
|
log.Fatalln(temp_err) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
func models() { |
||||||
|
mydir := "/models/" + app_dir |
||||||
|
make_a_dir(mydir) |
||||||
|
file := use_file(mydir + "/" + main_file + "_model.php") |
||||||
|
|
||||||
|
temp_err := temp_models.Execute(file, php_tpl) |
||||||
|
if temp_err != nil { |
||||||
|
log.Fatalln(temp_err) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
func outputs() { |
||||||
|
mydir := "/outputs/" + app_dir |
||||||
|
make_a_dir(mydir) |
||||||
|
file := use_file(mydir + "/" + main_file + "_out.php") |
||||||
|
|
||||||
|
temp_err := temp_outputs.Execute(file, php_tpl) |
||||||
|
if temp_err != nil { |
||||||
|
log.Fatalln(temp_err) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
func views() { |
||||||
|
mydir := "/views/default/" + app_dir |
||||||
|
make_a_dir(mydir) |
||||||
|
file := use_file(mydir + "/" + main_file + "_" + method_name + "_view.php") |
||||||
|
|
||||||
|
temp_err := temp_views.Execute(file, php_tpl) |
||||||
|
if temp_err != nil { |
||||||
|
log.Fatalln(temp_err) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
func grab_input() { |
||||||
|
var sub_in string |
||||||
|
var file_in string |
||||||
|
var method_in string |
||||||
|
|
||||||
|
fmt.Print("Enter SubFolder (app): ") |
||||||
|
fmt.Scanln(&sub_in) |
||||||
|
if sub_in == "" { |
||||||
|
sub_in = "app" |
||||||
|
} |
||||||
|
|
||||||
|
fmt.Print("Enter File (home): ") |
||||||
|
fmt.Scanln(&file_in) |
||||||
|
if file_in == "" { |
||||||
|
file_in = "home" |
||||||
|
} |
||||||
|
|
||||||
|
fmt.Print("Enter Method (index): ") |
||||||
|
fmt.Scanln(&method_in) |
||||||
|
if method_in == "" { |
||||||
|
method_in = "index" |
||||||
|
} |
||||||
|
|
||||||
|
app_dir = sub_in |
||||||
|
main_file = file_in |
||||||
|
method_name = method_in |
||||||
|
|
||||||
|
php_tpl = PhpTemplate{ |
||||||
|
Root: root_in, |
||||||
|
Subfolder: sub_in, |
||||||
|
File: file_in, |
||||||
|
Method: method_in, |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
func usage() { |
||||||
|
progName := filepath.Base(os.Args[0]) |
||||||
|
fmt.Printf(`%s version %s, (c) 2022 Robert Strutts |
||||||
|
|
||||||
|
Usage: |
||||||
|
%s [-www] [-app] [-root] [-v] |
||||||
|
-h Print this help message. |
||||||
|
-v Verbose mode, Display output instead of making files. |
||||||
|
-www Web Dir IE /var/www |
||||||
|
-app App Dir IE tts_project/src |
||||||
|
-root Root Dir IE mockup |
||||||
|
`, progName, version, progName) |
||||||
|
} |
||||||
|
|
||||||
|
func main() { |
||||||
|
help := flag.Bool("h", false, "Help Page") |
||||||
|
web_path := flag.String("www", "/var/www", "Web Dir") |
||||||
|
app_path := flag.String("app", "tts_project/src", "App Dir") |
||||||
|
root_path := flag.String("root", "mockup", "Root Dir") |
||||||
|
v := flag.Bool("v", false, "Verbose output") |
||||||
|
flag.Parse() |
||||||
|
|
||||||
|
if *help { |
||||||
|
usage() |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
verbose = *v |
||||||
|
|
||||||
|
root = *web_path + "/" + *app_path + "/" + *root_path |
||||||
|
root_in = *root_path |
||||||
|
|
||||||
|
_, err := os.Stat(root) |
||||||
|
if os.IsNotExist(err) { |
||||||
|
log.Fatal("Missing root folders: mkdir -p " + root) |
||||||
|
} |
||||||
|
fmt.Println("Please wait...") |
||||||
|
|
||||||
|
init_template() |
||||||
|
grab_input() |
||||||
|
ctrl() |
||||||
|
inputs() |
||||||
|
models() |
||||||
|
outputs() |
||||||
|
views() |
||||||
|
} |
||||||
Loading…
Reference in new issue