Repository: secretGeek/dod
Branch: master
Commit: ee90397ecdc3
Files: 23
Total size: 49.6 KB
Directory structure:
gitextract_7mm5_scu/
├── Controllers/
│ ├── Home/
│ │ └── Index.bat
│ ├── _actionMissing.bat
│ └── _controllerMissing.bat
├── Default.aspx
├── Default.aspx.cs
├── DosOnDope.csproj
├── Global.asax
├── Global.asax.cs
├── LICENSE
├── Models/
│ └── split.vbs
├── Properties/
│ └── AssemblyInfo.cs
├── README.md
├── Views/
│ └── Shared/
│ └── _header.bat
├── Web.config
├── docs/
│ ├── GettingStarted.md
│ └── HowDoesItWork.md
├── dope.bat
└── h/
├── ToLower.cmd
├── a.bat
├── h1.bat
├── h2.bat
├── h3.bat
└── p.bat
================================================
FILE CONTENTS
================================================
================================================
FILE: Controllers/Home/Index.bat
================================================
@echo off
call ..\..\Views\Shared\_header DoD Congratulations
call ..\..\h\h1 Congratulations
echo [p]You've put [strong]DOS on DOPE[/strong][/p]
echo.
echo [p]Available controllers...[/p]
echo [blockquote]
echo [ul]
pushd %cd%
cd ..
FOR /F "delims=~" %%A IN (' DIR /B/a:d') DO (
echo [li][a href='%%A/']%%A[/a][/li]
)
echo [/ul]
echo [/blockquote]
echo [p]To Add a controller, navigate to:[/p]
echo [blockquote][pre]%cd%] [/pre][/blockquote]
popd
echo [p]and type:[/p]
echo [blockquote][pre]Dope Controller [em]ControllerName[/em][/pre][/blockquote]
echo.
echo [p]To change this default controller, edit:[/p]
echo [blockquote][pre]"%cd%\Index.bat"[/pre][/blockquote]
echo [p]To create new actions, add batchfiles to this folder, e.g. [/p]
echo [blockquote][pre]%cd%]Copy con About.bat
echo echo [[p]]Hello world![[/p]]
echo [[ctrl-Z]][/pre][/blockquote]
================================================
FILE: Controllers/_actionMissing.bat
================================================
@echo off
call ..\Views\Shared\_header Action Missing
call ..\h\h1 Action Missing
echo [p]Controller = %1[/p]
echo [p]Action = %2[/p]
echo [p]Parameters = %*[/p]
echo [p]Available Actions to GET for this controller...[p]
echo [blockquote][pre]
echo [OL]
FOR /F "delims=~" %%A IN (' DIR %1\*.bat /B/a:-d') DO (
echo [A href='%%~nA']%%~nA[/A]
)
echo [/OL]
echo [/blockquote][/pre]
echo [p]Available Actions to POST for this controller...[p]
echo [blockquote][pre]
echo [OL]
FOR /F "delims=~" %%A IN (' DIR %1\*.cmd /B/a:-d') DO (
echo [A href='%%~nA']%%~nA[/A]
)
echo [/OL]
echo [/blockquote][/pre]
exit 44
================================================
FILE: Controllers/_controllerMissing.bat
================================================
@echo off
call ..\Views\Shared\_header Controller Missing
call ..\h\h1 Controller Missing
echo [p]Controller = %1[/p]
echo [p]Action = %2[/p]
echo [p]Parameters = %*[/p]
echo [p]Available controllers...[/p]
echo [blockquote][pre]
echo [OL]
FOR /F "delims=~" %%A IN (' DIR /B/a:d') DO (
echo [A href='%%A/']%%A[/A]
)
echo [/OL]
echo [/blockquote][/pre]
exit 44
================================================
FILE: Default.aspx
================================================
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="DosOnDope._Default" %>
<%-- Please do not delete this file. It is used to ensure that ASP.NET MVC is activated by IIS when a user makes a "/" request to the server. --%>
================================================
FILE: Default.aspx.cs
================================================
using System.Web;
using System.Web.Mvc;
using System.Web.UI;
namespace DosOnDope
{
public partial class _Default : Page
{
public void Page_Load(object sender, System.EventArgs e)
{
HttpContext.Current.RewritePath(Request.ApplicationPath, false);
IHttpHandler httpHandler = new MvcHttpHandler();
httpHandler.ProcessRequest(HttpContext.Current);
}
}
}
================================================
FILE: DosOnDope.csproj
================================================
Debug
AnyCPU
9.0.21022
2.0
{80FA3DFC-363C-4B35-AAA5-0FD3C17B8ECB}
{603c0e0b-db56-11dc-be95-000d561079b0};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}
Library
Properties
DosOnDope
DosOnDope
v3.5
false
true
full
false
bin\
DEBUG;TRACE
prompt
4
pdbonly
true
bin\
TRACE
prompt
4
3.5
3.5
False
..\..\..\..\Program Files\Microsoft ASP.NET\ASP.NET MVC RC\Assemblies\System.Web.Routing.dll
3.5
Default.aspx
ASPXCodeBehind
Global.asax
False
True
11835
/
False
False
================================================
FILE: Global.asax
================================================
<%@ Application Codebehind="Global.asax.cs" Inherits="DosOnDope.MvcApplication" Language="C#" %>
================================================
FILE: Global.asax.cs
================================================
using System;
using System.Diagnostics;
using System.IO;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace DosOnDope
{
public class MvcApplication : System.Web.HttpApplication
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("favicon.ico");
routes.IgnoreRoute("Content/{*pathInfo}");
routes.Add(new Route("{controller}/{action}/{*id}", new DosOnDopeRouteHandler())
{
Defaults = new RouteValueDictionary(new
{
controller = "Home",
action = "Index",
id = ""
})
});
}
protected void Application_Start()
{
RegisterRoutes(RouteTable.Routes);
}
}
public class DosOnDopeRouteHandler : IRouteHandler
{
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
return new DosOnDopeHttpHandler(requestContext);
}
}
public class DosOnDopeHttpHandler : IHttpHandler
{
public RequestContext requestContext { get; set; }
public DosOnDopeHttpHandler(RequestContext requestContext)
{
this.requestContext = requestContext;
}
public bool IsReusable {get { return false; } }
public void ProcessRequest(HttpContext context)
{
var controller = this.requestContext.RouteData.Values["controller"] as string;
var action = this.requestContext.RouteData.Values["action"] as string;
string[] args = { this.requestContext.RouteData.Values["id"] as string };
int httpStatus;
if (context.Request.RequestType == "POST")
{
var result = Execute(controller, action, context.Request.Form.ToString().Split('&'), out httpStatus, true);
if (httpStatus == 301)
context.Response.Redirect(result.Trim("\r\n".ToCharArray()));
else
context.Response.Write(result);
}
else
{
context.Response.Write(Execute(controller, action, args, out httpStatus, false ));
}
context.Response.StatusCode = httpStatus;
}
public string Execute(string controllerName, string actionName, string[] newArgs, out int httpStatus, bool isPost)
{
var controllerPath = Path.Combine(requestContext.HttpContext.Server.MapPath("~/Controllers"), controllerName);
if (!Directory.Exists(controllerPath))
{
return ControllerNotFound(controllerName, actionName, newArgs, out httpStatus, isPost);
}
var actionFileName = Path.Combine(controllerPath, actionName + ".bat");
if (!File.Exists(actionFileName))
{
return ActionNotFound(controllerName, actionName, newArgs, out httpStatus, isPost);
}
return Execute(controllerPath, actionName, Join(" ", newArgs), out httpStatus, isPost);
}
private string Execute(string path, string file, string args, out int httpStatus, bool isPost)
{
var errorLevel = 50;
var result = string.Empty;
using (var proc = new Process())
{
proc.EnableRaisingEvents = false;
proc.StartInfo.FileName = Path.Combine(path, file + (isPost? ".cmd" : ".bat"));
if (args != null)
{
proc.StartInfo.Arguments = args;
}
proc.StartInfo.WorkingDirectory = path;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;// false;
proc.StartInfo.RedirectStandardOutput = true;
proc.Start();
string output = proc.StandardOutput.ReadToEnd();
result = Dope(output);
proc.WaitForExit();
errorLevel = proc.ExitCode;
}
httpStatus = ConvertErrorlevelToHttpStatus(errorLevel);
return result;
}
private string ActionNotFound(string controllerName, string actionName, string[] newArgs, out int httpStatus, bool isPost)
{
var controllerPath = Path.Combine(requestContext.HttpContext.Server.MapPath("~/Controllers"), controllerName);
if (!File.Exists(Path.Combine(controllerPath, "_actionMissing" + ".bat")))
{
controllerPath = requestContext.HttpContext.Server.MapPath("~/Controllers");
}
return Execute(controllerPath, "_ActionMissing", controllerName + " " + actionName + " " + Join(" ", newArgs), out httpStatus, false);
}
private string ControllerNotFound(string controllerName, string actionName, string[] newArgs, out int httpStatus, bool isPost)
{
var controllerPath = requestContext.HttpContext.Server.MapPath("~/Controllers");
return Execute(controllerPath, "_ControllerMissing", controllerName + " " + actionName + " " + Join(" ", newArgs), out httpStatus, false);
}
private int ConvertErrorlevelToHttpStatus(int errorLevel)
{
if (errorLevel == 0) return 200;
return ((errorLevel / 10) * 100) + (errorLevel % 10);
}
private string Join(string separator, params string[] strings)
{
if (strings == null) return string.Empty;
return string.Join(separator, strings);
}
///
/// Dopes the input.
/// i.e:
/// Turns square brackets into angle brackets
/// Turns pluses into spaces.
/// Escapes angle brackets
/// Turns escaped square brackets into regular square brackets
/// Turns url encoded CR/LF into spaces
///
/// The undoped.
///
private string Dope(string undoped)
{
if (undoped.IndexOf("[[") >= 0 || undoped.IndexOf("]]") >= 0)
{
var gOpen = Guid.NewGuid().ToString();
var gClose = Guid.NewGuid().ToString();
undoped = undoped.Replace("[[", gOpen).Replace("]]", gClose);
undoped = Dope(undoped);
return undoped.Replace(gOpen, "[").Replace(gClose, "]");
}
return undoped.Replace("<","<").Replace(">",">").Replace("[", "<").Replace("]", ">").Replace("+"," ").Replace("%0d"," ").Replace("%0a"," ");
}
}
}
================================================
FILE: LICENSE
================================================
The MIT License (MIT)
Copyright (c) 2010-2024 secretGeek
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.
================================================
FILE: Models/split.vbs
================================================
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objArgs = WScript.Arguments
str1 = objArgs(0)
s=Split(str1,"`")
For i=LBound(s) To UBound(s)
WScript.Echo s(i)
' WScript.Echo s(9) ' get the 10th element
Next
================================================
FILE: Properties/AssemblyInfo.cs
================================================
using System.Reflection;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of mad attributes. Change these attribute values to modify the information
// associated with an assembly. If. You. Dare.
[assembly: AssemblyTitle("DosOnDope")]
[assembly: AssemblyDescription("Built with DosOnDope")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("secretGeek")]
[assembly: AssemblyProduct("DosOnDope")]
[assembly: AssemblyCopyright("Copyright © Leon Bambrick 2010")]
[assembly: AssemblyTrademark("DosOnDope")]
[assembly: AssemblyCulture("")]
// COM is for old people.
[assembly: ComVisible(false)]
// This is my GUID. Mess with it: and I will hurt your face.
[assembly: Guid("667ff6b2-8224-45e2-b13d-0d02685520a3")]
// Version information for an assembly consists of the following five values:
//
// Major Version
// Minor Version
// Guild Number
// Karma points
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' wild-card. Are you wild? I'm not wild. I program.
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
================================================
FILE: README.md
================================================
# DOS on DOPE

*The last MVC Web framework you'll ever need*
When you've done everything you can with [Ruby On Rails](http://rubyonrails.org/)
When you've reached the limits of *Haskell on a Horse* and *Cobol on Cogs*...
It's time to meet _the MVC Web Framework to end all MVC Web frameworks._
## DOS on DOPE is the modern MVC framework built on the awesome power of batch files.
All of the controllers in DoD are batch files.
All of the views are batch files.
The model is based on batch files. The helper functions are... you guessed it! Beautiful batch files!
(Okay, I'm no purist. There's a few lines of C# for url routing and batch file execution. Everything else is either a .bat or a .cmd file. With a liberal helping of .csv mixed in.)
# [Getting Started](docs/GettingStarted.md)
_See how to build a site in just seconds!_
## [How Does It Work?](docs/HowDoesItWork.md)
_Look behind the curtain to see how the magic is made_
### [Introduction at secretGeek](http://secretgeek.net/dod_intro)

================================================
FILE: Views/Shared/_header.bat
================================================
@echo off
echo [html]
echo [head]
echo [style]body{background-color:#000;color:#C0C0C0;font-family:"fixed sys","Lucida console",monospace}input,textarea{background-color:#222;color:#FFF}h1,h2,h3,h4{font-size:medium}h1{color:white}strong{font-size:medium;color:yellow}pre{font-family:"fixed sys","Lucida console"}em{font-style:normal;color:#808080}ul{list-style-image: url(Content/li.png);}a{text-decoration:none;color:008080}[/style]
IF x"%*"==x"" GOTO DEFAULT
echo [title]%*[/title]
goto END
:DEFAULT
echo [title]DosOnDope[/title]
goto END
:END
echo [/head]
echo [body]
echo [img src='Content/Logo.png' style='float:right' /]
================================================
FILE: Web.config
================================================
================================================
FILE: docs/GettingStarted.md
================================================
# Getting started
To get started open a `cmd` window.
If you're not familiar with a `cmd` window, you soon will be. ;-)
Make sure `dope.bat` file is in your `PATH`.
If you're not familiar with your `PATH`, you soon will be. Wait a second. Read this 'Quick tip,'
## QuickTip: Adding dope to your path
If `dope.bat` is in the folder `C:\DoD` then type this:
PATH=%PATH%;c:\DoD;
`dope` will then be in your path.
# Create a web application
Okay. Moving on.
First step, navigate to a folder where you want to create your web application.
e.g.
C:\>cd Temp
C:\Temp>
Temp is a great place to do all your work. It implies the kind of permanence that a Dos On Dope project deserves.
**To create a site called `Blog` we use the
`dope` command. It's as simple as this:**
C:\Temp>dope site Blog
Time for another quick tip:
## QuickTip: Help from the Command Line
Issue the `dope` command (i.e. call `dope.bat`) without any parameters, to get help.
For help with a particular command, try `dope help _commandname_`,
e.g.
dope help site
# Wrestling with IIS
IIS is a little hard to control from the console, so you'll need to open IIS manager and register your site manually. Read the sidebar about how to do that.
*(If we were using apache, tomcat or webrick we'd be able to do this from the command-line with ease. If I took this project more seriously, I would have written a custom DOS-based web-server. But then I guess I would've been an even more depraved individual, so for now we're stuck with IIS.)*
## QuickTip: Registering Manually with IIS
Add a virtual directory under the `Default Web Site`
Then right click and 'convert to application'
Browse to the newly created application.
# Did that work??
Let's check in a browser that our new site is built.

Oops. It worked. We're up and running.
# Exploring our new app
It's generated the complete skeleton of the application. Here's what we see in the console:

Let's see what's been created for us. We now have these folders:
C:\temp\blog>dir /s/a:d/b
C:\temp\blog\Content
C:\temp\blog\Controllers
C:\temp\blog\h
C:\temp\blog\Models
C:\temp\blog\Scripts
C:\temp\blog\Views
C:\temp\blog\Controllers\Home
C:\temp\blog\Views\Shared
And these files:
C:\temp\blog>dir /s/a:-d/b
C:\temp\blog\Default.aspx
C:\temp\blog\favicon.ico
C:\temp\blog\Global.asax
C:\temp\blog\web.config
C:\temp\blog\Content\Site.css
C:\temp\blog\Content\li.png
C:\temp\blog\Content\Logo.png
C:\temp\blog\Controllers\_actionMissing.bat
C:\temp\blog\Controllers\_controllerMissing.bat
C:\temp\blog\Controllers\Home\Index.bat
C:\temp\blog\h\a.bat
C:\temp\blog\h\h1.bat
C:\temp\blog\h\h2.bat
C:\temp\blog\h\h3.bat
C:\temp\blog\h\p.bat
C:\temp\blog\Models\split.vbs
C:\temp\blog\Views\Shared\_header.bat
All the files you need for a modern MVC application. Built on batch files.
We have our site, and it shows the starting application. Let's create a new controller action, and see that it renders as expected..

# Making it betterer
In this case, our batch file is basically a series of echo statements that write html to the screen. Instead of angle brackets we use square brackets. (This is because DOS uses angle brackets for re-direction.)
We can do a little better than that.
We can apply a theme by including a 'partial' view, called `_header.bat.`
And we can use helper methods to create clean markup.

Now, let's create a location for holding our data.
In DoD we embrace the NoSQL movement and jump straight to the data-store of the future: a CSV file.
C:\temp>CD Blog\Models
C:\temp\Blog\Models>copy con Posts.csv
ID`Title`Article
^Z
`Posts.csv` is both the model that describes our data, and the store which will contain the data itself.
(We use back-ticks rather than commas, so that there's no need to qualify our data with double-quotes. Back-ticks can never ever appear in real data in the wild, so this is perfectly safe forever.)
Now we can generate actions for administering our Posts. This is similar to the 'scaffolding' feature of Ruby On Rails.
C:\temp\blog\Models>dope gen Post
Generating actions for MODEL Post in Controller Home...
Now, if we look in the Home controller we see four batch files that have been created.
C:\temp\blog\Controllers\Home>dir /b
add.bat
add.cmd
Index.bat
view.bat
Notice there is an `add.bat` as well as an `add.cmd`. What's the difference?
# The secret behind DoD... shhh... don't tell anyone.....
**In DosOnDope, `GET` verbs are handled by Batch files (.bat), while `POST` verbs are handled by `.cmd` files.**
Let's see what they look like. We browse to see the add action:

The generator has created a nice page for us, with a name and textbox for every field, so we can create new posts.
We enter some details...

...click submit and see what happens.

We're back at the index page. But now it's a list of all the articles. There's only one for now.
Let's see what it looks like if we've added another article:

Behind the scenes when we pressed 'submit' the Http-Post was handled by `add.cmd` which unpacked the form variables and added the details to the file Posts.csv
C:\temp\blog\Models>type Posts.csv
ID`Title`Article
1`Hello Brazil!`Yes, yes, hello indeed!
2`Let's add a second for good measure`Oh yeah
That's about it. We've demonstrated all the components you need to make wonderful apps.
Best of luck. I hope dope is good to you.
Now you might want to read about [How does it work?](HowDoesItWork.md)
Are you look for David? David is not here currently. Man.
Maybe go and read some of the stuff at [secretGeek](http://secretGeek.net)
================================================
FILE: docs/HowDoesItWork.md
================================================
# How does it work?
## How *does* it work!?
## HOW does IT work!?
## (how can it work?)
In DosOnDope all URLs are constructed like this:
`http://YourSite.com/Controller/Action/*id`
Where:
* `"Controller"` is the name of a **folder** in the Controllers folder.
* `"Action"` is the name of a **batch file** in the relevant controller folder.
* `"*id"` is an optional set of **parameters** passed to the batch file.
(Turning a URL into a batch file call is performed by a custom C# router, `DosOnDopeRouteHandler` which hands off to the http handler `DosOnDopeHttpHandler`)
If the subfolder "`Controller`" in the `Controllers` folder is not found, `_controllerMissing.bat` is called.
This is the default `_controllerMissing` batch file included in every DosOnDope application. It sits in the `Controllers` folder. It returns a web page telling you what controllers are available, and you will usually customize it to suit your own purposes.
If there is no batch file matching the name of the `action` that was called, then the `_actionMissing` batch file is executed.
This is the default `_actionMissing` batch file included in every DosOnDope application. It returns a web page telling you what actions are available for the controller you requested. You are free to customize it however you wish.
* If the request is a `GET` method, the handler looks for a `.bat` batch file.
* If the request is a `POST` method, the handler looks for a `.cmd` batch file.
So for example a `GET` request to `http://YourSite.com/Blog/Add` would cause the handler to execute a batch file located at
C:\Temp\YourSite\Controllers\Blog\Add.bat
A `POST` to `http://YourSite.com/Blog/Add` would cause the handler to execute a batch file located at:
C:\Temp\YourSite\Controllers\Blog\Add.cmd
A `GET` to `http://YourSite.com/Blog/View/Yes` would cause the handler to execute a batch file `View.bat` with the parameter "Yes"
C:\Temp\YourSite\Controllers\Blog\View.bat Yes
So, inside the `View.bat` script, you could say:
@echo [p]Hello! You said %1.[/p]
Which would be converted into:
Hello! You said Yes.
And be rendered by a browser as:
> Hello! You said Yes.
(By the way, echoing user input from a URL to the screen is a very safe and wise thing to do. Do that any chance you can.)
Why not read about [Getting started](GettingStarted.md)
Dave's not here currently. Man. etc.
Maybe read the original blog post about this nonsense at [secretGeek: dos on dope](http://secretgeek.net/dod_intro)
================================================
FILE: dope.bat
================================================
@echo off
SET LOCN="%~dp0"
if x'%2'==x'/?' goto COMMAND_HELP
if x'%2'==x'?'goto COMMAND_HELP
if x'%2'==x'-?'goto COMMAND_HELP
if x'%2'==x'--?'goto COMMAND_HELP
if x'%1'==x'' goto UNKNOWN
if '%1'=='site' goto SITE
if '%1'=='controller' goto CONTROLLER
if '%1'=='gen' goto GEN
if '%1'=='help' goto HELP
if '%1'=='?' goto HELP
if '%1'=='/?' goto HELP
if '%1'=='-?' goto HELP
if '%1'=='--?' goto HELP
if '%1'=='SITE' goto SITE
if '%1'=='CONTROLLER' goto CONTROLLER
if '%1'=='GEN' goto GEN
if '%1'=='HELP' goto HELP
if '%1'=='Help' goto HELP
goto UNKNOWN
:COMMAND_HELP
if '%1'=='site' goto HELP_SITE
if '%1'=='controller' goto HELP_CONTROLLER
if '%1'=='model' goto HELP_MODEL
if '%1'=='gen' goto HELP_GEN
if '%1'=='help' goto HELP
if '%1'=='SITE' goto HELP_SITE
if '%1'=='CONTROLLER' goto HELP_CONTROLLER
if '%1'=='MODEL' goto HELP_MODEL
if '%1'=='GEN' goto HELP_GEN
if '%1'=='HELP' goto HELP
ECHO Unknown command %1
GOTO HELP
:HELP_SITE
echo dope SITE [[name]]
echo will create a SITE named 'name'
echo in the current folder.
echo e.g:
echo dope SITE Blog
echo will create a site named 'Blog'
echo.
echo The site will, by default, include
echo sufficient files (styles, helpers etc)
echo to get you started.
echo.
echo A good next step is to create a controller
echo using the 'dope CONTROLLER' command
goto EXIT
:HELP_CONTROLLER
echo dope CONTROLLER [[name]]
echo Create a CONTROLLER named 'name'
echo in the SITE\Controllers\ folder
echo e.g.
echo dope CONTROLLER About
echo Creates a controller folder named 'About'
echo in the current site's 'Controllers' folder
echo containing a default action, 'Index.bat'
echo To navigate to the new action goto
echo http://YourSite/About/
echo or
echo http://YourSite/About/Index
echo.
echo To create more actions, navigate into
echo the newly created folder and create more
echo batch files. No wiring required.
goto EXIT
:HELP_GEN
echo dope GEN [[name]] [[controller]]
echo Generate actions for the model named 'name'
echo (singular) in the controller specified.
echo.
echo (The controller name is optional. If no
echo controller is specified, the default
echo controller, 'home', will be used.)
echo.
echo Before generating the actions, you need
echo to create the model file.
goto HELP_MODEL
goto EXIT
:HELP_MODEL
echo.
echo A model file is a CSV file in the models
echo folder. The first line of the file is a
echo lists of fields, separated with backtick `
echo characters, e.g. Emails.csv might contain:
echo ID`FirstName`LastName`Age`Email
echo.
echo The file name is plural.
goto EXIT
:SITE
echo Creating SITE... %2
if not exist %2 MD %2
echo ...Created Content folder (for CSS and images)
if not exist %2\Content MD %2\Content
echo ...Created Controllers folder (for Controllers)
if not exist %2\Controllers MD %2\Controllers
echo ...Created Controllers\Home folder (Default Controller)
if not exist %2\Controllers\Home MD %2\Controllers\Home
echo ...Created h folder (for html helpers)
if not exist %2\h MD %2\h
echo ...Created Models folder (for Models)
if not exist %2\Models MD %2\Models
echo ...Created Scripts folder (for javascript)
if not exist %2\Scripts MD %2\Scripts
echo ...Created Views folder (for views)
if not exist %2\Views MD %2\Views
echo ...Created Views\Shared folder (for Shared views)
if not exist %2\Views\Shared MD %2\Views\Shared
echo ...Created bin folder
if not exist %2\bin MD %2\bin
echo ...adding Web.config
Copy %LOCN%Web.config %2%\web.config
echo ...adding Default.aspx
Copy %LOCN%Default.aspx %2%\Default.aspx
echo ...adding Global.asax
Copy %LOCN%Global.asax %2%\Global.asax
echo ...adding logo and favicon
Copy %LOCN%Content\logo.png %2%\Content\logo.png
Copy %LOCN%Content\li.png %2%\Content\li.png
Copy %LOCN%favicon.ico %2%\favicon.ico
echo ...adding partial for header
Copy %LOCN%Views\Shared\_header.bat %2%\Views\Shared\_header.bat
echo ...adding handlers for 'action missing' and 'controller missing'
Copy %LOCN%Controllers\_actionMissing.bat %2%\Controllers\_actionMissing.bat
Copy %LOCN%Controllers\_controllerMissing.bat %2%\Controllers\_controllerMissing.bat
echo ...adding default action (Index)
Copy %LOCN%Controllers\Home\Index.bat %2%\Controllers\Home\Index.bat
echo ...adding binaries
Copy %LOCN%bin\*.dll %2%\bin\
echo ...adding html helper functions
Copy %LOCN%h\*.bat %2%\h\
echo Registering http://localhost/%2 with webserver
echo SITE created.
goto EXIT
:CONTROLLER
REM First determine our location... tricky!
pushd %cd%
if NOT EXIST ..\Controllers goto NOT_IN_CONTROLLERS
if NOT EXIST ..\Models goto NOT_IN_CONTROLLERS
if NOT EXIST ..\Views goto NOT_IN_CONTROLLERS
cd ..\Controllers
goto Make_Controller
:NOT_IN_CONTROLLERS
if EXIST Controllers goto IN_ROOT
if EXIST Models goto IN_ROOT
if EXIST Views goto IN_ROOT
ECHO This command must be run from the root
ECHO of your website, or from the Controllers
ECHO folder.
popd
goto :EOF
goto Make_Controller
:IN_ROOT
cd Controllers
goto Make_Controller
:Make_Controller
echo Creating CONTROLLER %2...
IF NOT EXIST %2 md %2
echo Creating default action (index.bat)...
Copy %LOCN%\Controllers\Home\Index.bat %2%\Index.bat
popd
goto EXIT
:GEN
SET controller=%3
if x%3==x SET controller=Home
echo Generating actions for MODEL %2 in Controller %controller%...
REM First determine our location... tricky!
pushd %cd%
if NOT EXIST ..\..\Controllers goto KeepLooking
if NOT EXIST ..\..\Models goto KeepLooking
if NOT EXIST ..\..\Views goto KeepLooking
cd ..\..\Models
goto Gen_Model
:KeepLooking
if NOT EXIST ..\Controllers goto NOT_IN_MODELS
if NOT EXIST ..\Models goto NOT_IN_MODELS
if NOT EXIST ..\Views goto NOT_IN_MODELS
cd ..\Models
goto Gen_Model
:NOT_IN_MODELS
if EXIST Controllers goto IN_ROOT2
if EXIST Models goto IN_ROOT2
if EXIST Views goto IN_ROOT2
ECHO This command must be run from the root
ECHO of your website, or from the Models
ECHO or Controllers folder
popd
goto :EOF
goto Gen_Model
:IN_ROOT2
cd Models
goto Gen_Model
:Gen_Model
FOR /F "eol=; tokens=1,* delims=`" %%A in (%2s.csv) DO (
(SET FIELDS=%%B)
GOTO DETAILS
)
:DETAILS
cscript /nologo split.vbs %FIELDS% > "%2s.fields"
echo @echo off > ..\Controllers\%controller%\add.bat
echo call ..\..\Views\Shared\_header New %2 >> ..\Controllers\%controller%\add.bat
echo call ..\..\h\h1 New %2 >> ..\Controllers\%controller%\add.bat
echo echo [form method='POST' action='add'] >> ..\Controllers\%controller%\add.bat
echo echo [input type='hidden' id='title' name='ID' value='%2'][/input] >> ..\Controllers\%controller%\add.bat
SET /A ID=1
SET outy=".."
for /F %%C in (%2s.fields) do (
echo echo %%C >> ..\Controllers\%controller%\add.bat
echo echo [br /] >> ..\Controllers\%controller%\add.bat
echo echo [input type='textbox' id='%%C' name='%%C' value='%2' style='width:350px'][/input] >> ..\Controllers\%controller%\add.bat
echo echo [br /] >> ..\Controllers\%controller%\add.bat
SET /A ID=%ID+1
(SET outy=%outy%+""+%ID%)
)
echo echo [input type='submit' value='submit' /] >> ..\Controllers\%controller%\add.bat
echo echo [/form] >> ..\Controllers\%controller%\add.bat
echo echo [hr /] >> ..\Controllers\%controller%\add.bat
echo echo [a href='index']back[/a] >> ..\Controllers\%controller%\add.bat
echo @echo off > ..\Controllers\%controller%\add.cmd
echo REM Determine the next ID value... >> ..\Controllers\%controller%\add.cmd
echo SET /A ID=1 >> ..\Controllers\%controller%\add.cmd
echo FOR /F "eol=; tokens=1,2,3,* skip=1 delims=`" %%%%i in (..\..\Models\Posts.csv) do ( >> ..\Controllers\%controller%\add.cmd
echo (SET /A ID=%%ID+1) >> ..\Controllers\%controller%\add.cmd
echo ) >> ..\Controllers\%controller%\add.cmd
set rst=%%ID%%
SET /A UPPER=(%ID%-1)*2+1
for /L %%i in (3,2,%UPPER%) do call :Loop2 %%i
goto :EchoResults
:Loop2
Set RST=%RST%`%%~%1
goto :EOF
:EchoResults
echo ECHO %RST% ^>^> ..\..\Models\%2s.csv >> ..\Controllers\%controller%\add.cmd
echo ECHO View/%%ID%% >> ..\Controllers\%controller%\add.cmd
echo EXIT 31 >> ..\Controllers\%controller%\add.cmd
echo @echo off > ..\Controllers\%controller%\view.bat
echo IF x"%%1"==x"" GOTO EMPTY >> ..\Controllers\%controller%\view.bat
echo FOR /F "eol=; tokens=1-20 skip=1 delims=`" %%%%1 in (..\..\Models\%2s.csv) do ( >> ..\Controllers\%controller%\view.bat
echo IF %%%%1==%%1 ( >> ..\Controllers\%controller%\view.bat
echo call ..\..\Views\Shared\_header %%%%2 >> ..\Controllers\%controller%\view.bat
echo call ..\..\h\h1 %%%%2 >> ..\Controllers\%controller%\view.bat
for /L %%i in (3,1,%ID%) do (
echo ECHO [p]%%%%%%i[/p] >> ..\Controllers\%controller%\view.bat
)
echo ) >> ..\Controllers\%controller%\view.bat
echo ) >> ..\Controllers\%controller%\view.bat
echo GOTO EXIT >> ..\Controllers\%controller%\view.bat
echo :EMPTY >> ..\Controllers\%controller%\view.bat
echo call ..\..\Views\Shared\_header Invalid ID >> ..\Controllers\%controller%\view.bat
echo call ..\..\h\h1 Invalid ID >> ..\Controllers\%controller%\view.bat
echo GOTO EXIT >> ..\Controllers\%controller%\view.bat
echo :EXIT >> ..\Controllers\%controller%\view.bat
echo ECHO [a href='/%controller%/index']back...[/a] >> ..\Controllers\%controller%\view.bat
echo @echo off > ..\Controllers\%controller%\index.bat
echo call ..\..\Views\Shared\_header %controller% %2s >> ..\Controllers\%controller%\index.bat
echo call ..\..\h\h1 %controller% %2s >> ..\Controllers\%controller%\index.bat
echo echo [blink][em]Built with DOS on Dope[/em][/blink] >> ..\Controllers\%controller%\index.bat
echo FOR /F "eol=; tokens=1-20 skip=1 delims=`" %%%%1 in (..\..\Models\%2s.csv) do ( >> ..\Controllers\%controller%\index.bat
echo call ..\..\h\h1 %%%%2 >> ..\Controllers\%controller%\index.bat
for /L %%i in (3,1,%ID%) do (
echo ECHO [p]%%%%%%i[/p] >> ..\Controllers\%controller%\index.bat
)
echo ECHO [a href='view/%%%%1']more...[/a] >> ..\Controllers\%controller%\index.bat
echo ECHO [hr /] >> ..\Controllers\%controller%\index.bat
echo ) >> ..\Controllers\%controller%\index.bat
echo echo. >> ..\Controllers\%controller%\index.bat
echo echo [a href='add']Add[/a] >> ..\Controllers\%controller%\index.bat
popd
goto EXIT
:HELP
if '%2'=='site' goto HELP_SITE
if '%2'=='controller' goto HELP_CONTROLLER
if '%2'=='model' goto HELP_MODEL
if '%2'=='gen' goto HELP_GEN
echo.
echo *******************
echo *** DOS ON DOPE ***
echo *** The MVC web ***
echo *** frame work ***
echo *** built on ***
echo *** batch files ***
echo *******************
echo.
echo Commands are:
echo dope SITE [[name]] -- to create a SITE named 'name'
echo dope CONTROLLER [[name]] -- to create a CONTROLLER named 'name'
echo dope GEN [[name]] -- to generate controllers and action for a model named 'name' (singular)
echo dope HELP [[command]] -- to request HELP on 'command'
echo ** Always keep Dope in your Path. **
goto exit
:UNKNOWN
echo ERROR: Unknown command. %1
GOTO HELP
goto EXIT
:EXIT
================================================
FILE: h/ToLower.cmd
================================================
@echo off
FOR %%B IN ("%~1") DO (
FOR /F "delims=~" %%A IN ('ECHO %%B^> ~%%B ^& DIR /L /B ~%%B') DO (
SET LoCaseText=%%A
DEL /Q ~%%B
)
)
ECHO %LoCaseText%
================================================
FILE: h/a.bat
================================================
@echo off
echo [a href='%~1']%~2[/a]
================================================
FILE: h/h1.bat
================================================
@echo off
echo [h1]%*[/h1]
================================================
FILE: h/h2.bat
================================================
@echo off
echo [h2]%*[/h2]
================================================
FILE: h/h3.bat
================================================
@echo off
echo [h3]%*[/h3]
================================================
FILE: h/p.bat
================================================
@echo off
echo [p]%*[/p]