Skip to content

Commit

Permalink
Added examples
Browse files Browse the repository at this point in the history
  • Loading branch information
felixgirault committed Jun 13, 2018
1 parent 5c5893c commit ce77ed8
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 40 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ A calm and clutter-free theme for VSCode, originally based on [DuoTone](https://

## Examples

### JavaScript
### JavaScript/JSX

![](https://raw.githubusercontent.com/felixgirault/grapes-theme/master/examples/javascript.png)

### CSS/Sass

![](https://raw.githubusercontent.com/felixgirault/grapes-theme/master/examples/sass.png)

### PHP

![](https://raw.githubusercontent.com/felixgirault/grapes-theme/master/examples/php.png)
Binary file modified examples/javascript.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 29 additions & 39 deletions examples/php.php
Original file line number Diff line number Diff line change
@@ -1,49 +1,39 @@
<?php

namespace GrapesTheme\Middleware;

use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Log\LoggerInterface;
namespace Essence\Utility;

/**
* A middleware that logs each requested URL.
* An utility class to compile templates.
*/
class AccessLog
{
/**
* @var LoggerInterface
*/
private $logger;
class Template {

/**
* @param LoggerInterface $logger
*/
public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
}
/**
* A regex to identify variables in a template.
*
* @var string
*/
const variablePattern = '~\{?:(?<variable>[a-z0-9_]+)\}?~i';

/**
* Executes the middleware.
*
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @param callable $next
*
* @return ResponseInterface
*/
public function __invoke(
ServerRequestInterface $request,
ResponseInterface $response,
callable $next
) {
$response = $next($request, $response);
$path = $request->getUri()->getPath();
$date = date('c');
/**
* Compiles a template with variables.
*
* @param string $template Template.
* @param array $variables Variables.
* @return string Compiled template.
*/
public static function compile($template, array $variables) {
$compile = function ($matches) use ($variables) {
$name = $matches['variable'];

$this->logger->info("$date: Accessed $path");
return isset($variables[$name])
? $variables[$name]
: '';
};

return $response;
}
return preg_replace_callback(
self::variablePattern,
$compile,
$template
);
}
}
Binary file added examples/php.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/sass.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions examples/sass.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
}

.Article-body {
@include mixin();
padding: 1.5rem;
}

0 comments on commit ce77ed8

Please sign in to comment.