GithubHelp home page GithubHelp logo

hedzer / pathy Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 41.69 MB

A simple routing tool for Node-Webkit (http://nwjs.io) that allows folders and html files to act like URLs and CGI scripts.

Home Page: http://hedzer.github.io/Pathy

JavaScript 100.00%

pathy's Introduction

Pathy

     A simple routing tool for Node-Webkit (http://nwjs.io) that allows folders and html files to act like URLs and CGI scripts.

Usage

DOM Setup

Include the JavaScript file in your index HTML.

<html>
	<head>
		<script type="text/javascript" src="pathy.js"></script>
	</head>
	<body>
	</body>
</html>

Pathy will inject pages into the body tag by default. This can be changed by Pathy.container = '#id, or tag, or .class, etc.'.

Naviagtion

	window.location.hash = "users/load";
	//or
	Pathy.navigate("users/load");

The code above would look for users/load.html within the specified routes folder (the default is ./app/routes/); it would have a final path of ./app/routes/users/load.html. This file's contents would then be injected into the specified Pathy container (the default is body).

It's important to note that there's no need to include the ".html" file extension in the path.

Naviagtion + Arguments

	var args = {id:12345};
	window.location.hash = "users/load+"+JSON.stringify(args);
	//or
	Pathy.navigate("users/load", args);

The code above send the argument {id:12345} to the page ./app/routes/users/load.html. The code below shows the contents of the page, as well as how to recieve the argument.

Recieving Arguments

The following are the contents of the ./app/routes/users/load.html file.

<h1 id="greeter"></h1>
<script>
	(function($arguments){
		var greeter = document.getElementById("greeter");
		greeter.textContent = "User id:"+$arguments.id+" loaded";
	})($arguments);
</script>

Once navigation has occurred and all scripts have been run, the following would be the result:

<html>
	<head>
		<script type="text/javascript" src="pathy.js"></script>
	</head>
	<body>
		<h1 id="greeter">User id:12345 loaded</h1>
	</body>
</html>

The contents of ./app/routes/users/load.html were processed and added into the contents of the index.html from the DOM Setup example. If another path is called, the Pathy container (body) will be cleared and replaced with the processed contents of the new path.

Includes

Pathy can include other HTML files into the current one. Including appends the contents of the included file and runs all its included scripts. As far as receiving arguments are concerned, there's no difference between navigation and inclusion. Here's how to include:

	Pathy.include("includes/footer", args);

Alias And Unalias

Aliasing allows a route to point to another without being redirected.

	Pathy.alias("users/load", "admin/loadUser");
	window.location.hash = "admin/loadUser";

The admin/loadUser path doesn't really exist, but now it points to users/load. This is handy when you want to change access or prevent creating duplicate files. When an alias is ready to be removed, simply call Pathy.unalias("alias/path");. Following the example above, one would call Pathy.unalias("admin/loadUser"). After removing an alias, attempting to call it will produce an error if no route with that path exists.

Changing Settings

To change the default route path: Set Pathy.routes = './somewhere/anywhere/' The default path is ./app/routes/.

To change the default container where content is set: Set Pathy.container = '#id, or tag, or .class, etc.' The default container is body.

Live Reload

Pathy has a live reload feature! Yay! If you've navigated to a page and it is modified, it will automatically reload without disrupting your JavaScript state. This feature can be turned on and off by: Pathy.liveReload = true/false.

pathy's People

Contributors

hedzer avatar

Watchers

James Cloos avatar  avatar

pathy's Issues

Pathy.navigate - not navigating correctly

Command:
Pathy.navigate("general/menu");

Error Message: "ENOENT: no such file or directory, open 'path-to-nodewebkit\app\routes\ .html'"

Notes:

  • .\app\routes\general\menu.html : Exists
  • I believe its not receiving the "general/menu"

Pathy href - No Soft fails for "#" || ""

href="#" || href=""

They both activate pathy:

  • href="#" : throws error since app\routes.html : not found
  • href="" : always takes you to index.html instead staying where it is

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.