Skip to content

Commit

Permalink
Merge branch 'release/0.2.12'
Browse files Browse the repository at this point in the history
  • Loading branch information
jpaulobneto committed Jan 15, 2016
2 parents 2589c42 + b86ed44 commit d61bb73
Show file tree
Hide file tree
Showing 44 changed files with 1,357 additions and 295 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[*.php]
indent_style = space
indent_size = 2
6 changes: 6 additions & 0 deletions .gitignore
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ matrix:

before_script: composer install

script: phpunit --configuration phpunit.dist.xml
script: composer test
97 changes: 21 additions & 76 deletions README.md
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.
21 changes: 12 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@
"minimum-stability": "dev",
"require": {
"twig/twig": "~1.0",
"slim/slim": "~2.0"
"slim/slim": "~2.0",
"aura/session": "~2.0",
"nikic/fast-route": "dev-master"
},
"require-dev": {
"phpunit/phpunit": "3.x"
},
"autoload": {
"psr-4": {
"Ampersand\\": "src/",
"Ampersand\\Http\\": "src/http"
},
"files": [
"main.php",
"src/router.php",
"src/renderer.php"
]
"Ampersand\\": "src/"
}
},
"scripts": {
"test": "AMPERSAND_ENV=TEST phpunit --stderr",
"open": "DIP='http://'$(docker-machine ip default); DIP+=':8080'; open $DIP"
}
}
6 changes: 3 additions & 3 deletions config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

return [

'views' => 'views',
'views' => get_template_directory().'/views',
'cache' => false,
// Debugging
'debug' => true,
Expand All @@ -15,8 +15,8 @@
'cookies.httponly' => false,
// Encryption
'cookies.secret_key' => 'CHANGE_ME',
'cookies.cipher' => MCRYPT_RIJNDAEL_256,
'cookies.cipher_mode' => MCRYPT_MODE_CBC,
// 'cookies.cipher' => MCRYPT_RIJNDAEL_256,
// 'cookies.cipher_mode' => MCRYPT_MODE_CBC,
// HTTP
'http.version' => '1.1',

Expand Down
83 changes: 83 additions & 0 deletions couscous.yml
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.
19 changes: 19 additions & 0 deletions docker-compose.yml
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
7 changes: 7 additions & 0 deletions docs/config.md
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.
21 changes: 21 additions & 0 deletions docs/features/models.md
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).
Loading

0 comments on commit d61bb73

Please sign in to comment.