-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
44 changed files
with
1,357 additions
and
295 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[*.php] | ||
indent_style = space | ||
indent_size = 2 |
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 |
---|---|---|
@@ -1,2 +1,8 @@ | ||
/vendor/ | ||
composer.lock | ||
.idea | ||
.couscous | ||
/_main.php | ||
/index.php | ||
/functions.php | ||
/style.css |
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 |
---|---|---|
|
@@ -24,4 +24,4 @@ matrix: | |
|
||
before_script: composer install | ||
|
||
script: phpunit --configuration phpunit.dist.xml | ||
script: composer test |
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 |
---|---|---|
@@ -1,100 +1,45 @@ | ||
--- | ||
layout: home | ||
--- | ||
|
||
& (ampersand) | ||
============= | ||
|
||
[![Build Status](https://travis-ci.org/alterfw/ampersand.svg)](https://travis-ci.org/alterfw/ampersand) | ||
|
||
A microframework for Wordpress based on [Slim](http://www.slimframework.com/). | ||
|
||
## Routes | ||
|
||
You can register and handle custom routes with &: | ||
|
||
```php | ||
<?php | ||
|
||
Route::get('/hello', function(){ | ||
// your code here | ||
}); | ||
|
||
Route::post('/subscribe/newsletter', function($req, $res){ | ||
$email = $req->params('email'); // Get $_POST['email']; | ||
}); | ||
|
||
Route::get('/user/:id', function($req, $res){ | ||
$user_id = $req->params('id'); // Get $_GET['id']; | ||
}); | ||
``` | ||
|
||
## Templates | ||
|
||
Ampersand uses [Twig](http://twig.sensiolabs.org/) to render templates. | ||
## Instalation | ||
|
||
You can render templates using routes: | ||
|
||
```php | ||
<?php | ||
Route::get('/hello/:name', function($req, $res){ | ||
$res->render('hello', ['name' => $req->params('name')]); // will render views/hello.html | ||
}); | ||
``` | ||
composer require alterfw/ampersand | ||
|
||
Or just render a json: | ||
Require the composer autoload file into your `functions.php`: | ||
|
||
```php | ||
<?php | ||
Route::get('/hello/:name', function($req, $res){ | ||
$res->toJSON($req->params()); // will render views/hello.html | ||
}); | ||
require "vendor/autoload.php"; | ||
``` | ||
|
||
You can also use layouts and template blocks, read more in [Twig documentation](http://twig.sensiolabs.org/documentation). | ||
|
||
### Wordpress templates | ||
|
||
Don't want to use Ampersand templates? Not problem. You can also use Wordpress templates: | ||
|
||
```php | ||
<?php | ||
|
||
Route::get('/search', function($req, $res){ | ||
$res->template('search'); // Will render your-theme/search.php | ||
}); | ||
``` | ||
|
||
## Models | ||
|
||
Ampersand does not include features related to models but it works well with [Hero](http://alterfw.github.io/hero/). | ||
|
||
Just include hero into your theme composer.json | ||
|
||
composer require alterfw/hero | ||
## Documentation | ||
|
||
And should work fine: | ||
You can read more about how Ampersand works in the [documentation page](http://alterfw.github.io/ampersand/docs/). | ||
|
||
```php | ||
<?php | ||
|
||
$hero = new Hero(); | ||
$model = $hero::get(); | ||
## Contributing | ||
|
||
$books = $model->books->find(); | ||
``` | ||
This project doesn't have an styleguide yet but you should follow the existing code. | ||
Before create any pull requests make sure that all tests are passing. | ||
|
||
Read more about how to use Hero in [Alter's documentation](http://alter-framework.readthedocs.org/en/latest/models.html). | ||
### Development Environment | ||
|
||
## Configuration | ||
To setup de development environment first download [Docker](https://www.docker.com/) and create a virtual machine: | ||
|
||
You can override Amperstand default configuration creating a `config.php` in the root of your theme: | ||
docker-machine create --driver virtualbox default | ||
eval "$(docker-machine env default)" | ||
|
||
```php | ||
<?php | ||
Then run: | ||
|
||
return [ | ||
'views' => 'views', | ||
'cache' => false | ||
]; | ||
``` | ||
docker-compose up | ||
|
||
## Documentation | ||
This will create a WordPress and a theme with Ampersand installed as dependency. | ||
|
||
You can read more about how Ampersand works in the [documentation page](http://alterfw.github.io/ampersand/docs/). | ||
If you want to modify the theme files, take a look at the `test/theme` directory. These files are copied during the `docker-compose up` command, so if you change anything in these files you need to terminate the process and run again. |
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 |
---|---|---|
@@ -0,0 +1,83 @@ | ||
template: | ||
url: https://github.com/alterfw/docs-template.git | ||
|
||
exclude: | ||
- vendor | ||
- src | ||
- test | ||
|
||
github: | ||
user: alterfw | ||
repo: ampersand | ||
|
||
title: Ampersand | ||
baseUrl: http://alterfw.github.io/ampersand/ | ||
name: Ampersand | ||
composer: alterfw/ampersand | ||
subTitle: Ampersand, a micro framework for WordPress. | ||
logo_title: & | ||
logo_subtitle: Ampersand, a micro framework for WordPress. | ||
decription_full: Ampersand is a micro framework for WordPress based on <a href="http://www.slimframework.com/" target="_blank">Slim</a> that helps you quickly write websites and themes as real web applications. | ||
footer: footer: Developed by <a href="http://vilar.cc">Sergio Vilar</a> and <a href="https://github.com/alterfw/ampersand/graphs/contributors" target="_blank">contributors</a>. | ||
code: | | ||
Route::get("/hello/:name", function ($name) { | ||
echo "Hello, ".$name; | ||
}); | ||
example: <i class="fa fa-question-circle"></i><span>See the example theme</span> | ||
example_repo: https://github.com/alterfw/ampersand-example | ||
|
||
# The left menu bar | ||
show_menu_sub: true | ||
menu_sub: | ||
- title: Get Started | ||
items: | ||
- [/docs/index.html, Installation] | ||
- [/docs/config.html, Configuration] | ||
- title: Features | ||
items: | ||
- [/docs/features/routes.html, Routes] | ||
- [/docs/features/views.html, Views and Layouts] | ||
- [/docs/features/wordpress.html, WordPress Templates] | ||
- [/docs/features/models.html, Models] | ||
- title: Helpers | ||
items: | ||
- [/docs/helpers/session.html, Session] | ||
- [/docs/helpers/url.html, URL] | ||
- title: Request | ||
items: | ||
- [/docs/request/overview.html, Overview] | ||
- [/docs/request/helpers.html, Helpers] | ||
- [/docs/request/methods.html, Methods] | ||
- title: Response | ||
items: | ||
- [/docs/response/overview.html, Overview] | ||
- [/docs/response/helpers.html, Helpers] | ||
|
||
features: | ||
1: | ||
title: Router | ||
icon: plane | ||
description: | | ||
Ampersand provides a simple router built in the WordPress rewrite API that maps | ||
route callbacks to specific HTTP request | ||
methods and URIs. | ||
2: | ||
title: HTTP | ||
icon: exchange | ||
description: | | ||
Ampersand has easy-to-use request and response abstractions | ||
that let you inspect and manipulate | ||
HTTP messages' method, status, URI, headers, cookies, and body. | ||
3: | ||
title: Templates | ||
icon: file-text | ||
description: | | ||
Ampersand uses Twig as built-in as template engine, so you can create | ||
powerful templates using layouts, template blocks, etc. | ||
4: | ||
title: Models (with hero) | ||
icon: database | ||
description: | | ||
Ampersand doesn't have native support to models but works well with | ||
<a href="http://alterfw.github.io/hero" target="_blank">Hero</a>, | ||
a model-binding system to WordPress Post Types and Taxonomies. |
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,19 @@ | ||
ampersand_wp: | ||
image: wordpress | ||
links: | ||
- ampersand_db:mysql | ||
ports: | ||
- 8080:80 | ||
working_dir: /var/www/html | ||
volumes: | ||
- .:/var/www/html/wp-content/themes/development/ | ||
- ./test/theme/functions.php:/var/www/html/wp-content/themes/development/functions.php | ||
- ./test/theme/_main.php:/var/www/html/wp-content/themes/development/_main.php | ||
- ./test/theme/index.php:/var/www/html/wp-content/themes/development/index.php | ||
- ./test/theme/style.css:/var/www/html/wp-content/themes/development/style.css | ||
|
||
|
||
ampersand_db: | ||
image: mariadb | ||
environment: | ||
MYSQL_ROOT_PASSWORD: example |
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 @@ | ||
--- | ||
title: Configuration | ||
--- | ||
|
||
Ampersand defaults configuration is located under `vendor/alterfw/ampersand/config.php`. | ||
|
||
To override the default configuration just copy the `config.php` file to your theme's root directory and made the changes you need. |
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,21 @@ | ||
--- | ||
title: Models | ||
--- | ||
|
||
Ampersand does not include features related to models but it works well with [Hero](http://alterfw.github.io/hero). | ||
|
||
To install Hero, just run the bash below in your theme's root: | ||
|
||
composer require alterfw/hero | ||
|
||
Hero is Alter's main dependency and take cares of all model-binding to WordPress Post Types and taxonomies. | ||
|
||
### How to use Hero in Routes | ||
|
||
```php | ||
Route::get('/', function() { | ||
$this->render('cars.index', ['cars' => Car::all()]); | ||
}); | ||
``` | ||
|
||
Read more about how to use Hero in the [documentation](http://alterfw.github.io/hero). |
Oops, something went wrong.