Skip to content

Commit

Permalink
Refactoring: rename namespace to Contributte, simplify CI & composer
Browse files Browse the repository at this point in the history
  • Loading branch information
f3l1x committed Jul 31, 2017
1 parent 715ace1 commit 9c53ea1
Show file tree
Hide file tree
Showing 12 changed files with 217 additions and 131 deletions.
26 changes: 26 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# EditorConfig is awesome: http://EditorConfig.org

# Top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true

# JS / PHP
[*.{js,php,phpt}]
charset = utf-8
indent_style = tab
indent_size = 4

# NEON
[*.neon]
charset = utf-8
indent_style = tab
indent_size = 4

# Composer, NPM, Travis, BitbucketPipelines
[{composer.json,package.json,.travis.yml,bitbucket-pipelines.yml}]
indent_style = space
indent_size = 2
51 changes: 37 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
language: php

php:
- 5.6
- 7.0
- hhvm
- hhvm-nightly
- 5.6
- 7.0
- 7.1
- hhvm

matrix:
fast_finish: true

allow_failures:
- php: hhvm-nightly
- php: hhvm

include:
- php: 5.6
Expand All @@ -18,18 +21,38 @@ matrix:
env: COMPOSER_FLAG=--prefer-lowest
- php: 7.0
env: COMPOSER_FLAG=--prefer-stable
- php: 7.1
env: COMPOSER_FLAG=--prefer-lowest
- php: 7.1
env: COMPOSER_FLAG=--prefer-stable

before_script:
# Update Composer
- composer self-update

# Install Nette Tester
- composer update --no-interaction --prefer-source $COMPOSER_FLAG
# Composer
- travis_retry composer install --no-interaction
# Coverage
- if [[ "$TRAVIS_PHP_VERSION" == "7.1" && "$COMPOSER_FLAG" == "" ]]; then COVERAGE=1; fi

script:
- vendor/bin/tester -i -p php
- vendor/bin/tester tests/ParsedownExtra -s -p php
# Quality Assurance
- travis_retry composer qa

# Nette\Tester
- composer run-script tester

# Nette\Tester + CodeCoverage
- if [ "$COVERAGE" != "" ]; then composer tester-coverage; fi

after_script:
# Coverage (Coveralls)
- if [ "$COVERAGE" != "" ]; then wget https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar; fi
- if [ "$COVERAGE" != "" ]; then php coveralls.phar --verbose --config tests/.coveralls.yml; fi

after_failure:
# Print *.actual content
- 'for i in $(find tests -name \*.actual); do echo "--- $i"; cat $i; echo; echo; done'
# Print *.actual content
- for i in $(find tests -name \*.actual); do echo "--- $i"; cat $i; echo; echo; done

sudo: false

cache:
directories:
- $HOME/.composer/cache
21 changes: 21 additions & 0 deletions LICENCE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2016 Contributte

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.
31 changes: 23 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,41 @@
{
"name": "minetro/latte-parsedown-extra",
"name": "contributte/latte-parsedown-extra",
"description": "ParsedownExtra parser for Latte",
"type": "library",
"license": ["BSD-3-Clause"],
"homepage": "https://github.com/minetro/latte-parsedown-extra",
"homepage": "https://github.com/contributte/latte-parsedown-extra",
"authors": [
{
"name": "Milan Felix Sulc",
"homepage": "http://jfx.cz"
"homepage": "https://f3l1x.io"
}
],
"require": {
"php": ">=5.6.0",
"nette/di": "~2.4.0",
"nette/utils": "~2.4.0",
"nette/di": "^2.4.9",
"nette/utils": "^2.4.7",
"erusev/parsedown-extra": "^0.7.1",
"erusev/parsedown": "^1.6.0"
"erusev/parsedown": "^1.6.3"
},
"require-dev": {
"nette/tester": "~1.7.0"
"ninjify/qa": "^0.4.0",
"ninjify/nunjuck": "^0.1.4"
},
"autoload": {
"classmap": ["src/"]
"psr-4": {
"Contributte\\Parsedown\\": "src/"
}
},
"scripts": {
"qa": [
"linter src tests",
"codesniffer src tests"
],
"tester": [
"tester -s -p php --colors 1 -c tests/php-unix.ini tests/cases"
],
"tester-coverage": [
"tester -s -p php --colors 1 -c tests/php-unix.ini -d extension=xdebug.so --coverage ./coverage.xml --coverage-src ./src tests/cases"
]
}
}
66 changes: 39 additions & 27 deletions src/DI/ParsedownExtraExtension.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php

namespace Minetro\Parsedown\DI;
namespace Contributte\Parsedown\DI;

use Contributte\Parsedown\ParsedownExtraAdapter;
use Nette\DI\CompilerExtension;
use Nette\InvalidStateException;

Expand All @@ -13,31 +14,42 @@
class ParsedownExtraExtension extends CompilerExtension
{

/** @var array */
private $defaults = [
'helper' => 'parsedown',
];

public function loadConfiguration()
{
$config = $this->validateConfig($this->defaults);
$builder = $this->getContainerBuilder();

$builder->addDefinition($this->prefix('parsedown'))
->setClass('Minetro\Parsedown\ParsedownExtraAdapter');
}

public function beforeCompile()
{
$config = $this->validateConfig($this->defaults);
$builder = $this->getContainerBuilder();

if (!($templateFactory = $builder->getByType('Nette\Bridges\ApplicationLatte\ILatteFactory'))) {
throw new InvalidStateException('Service implemented ILatteFactory not found.');
}

$builder->getDefinition($templateFactory)
->addSetup('addFilter', [$config['helper'], ['@' . $this->prefix('parsedown'), 'process']]);
}
/** @var array */
private $defaults = [
'helper' => 'parsedown',
];

/**
* Register services
*
* @return void
*/
public function loadConfiguration()
{
$config = $this->validateConfig($this->defaults);
$builder = $this->getContainerBuilder();

$builder->addDefinition($this->prefix('parsedown'))
->setClass(ParsedownExtraAdapter::class);
}

/**
* Decorate services
*
* @return void
*/
public function beforeCompile()
{
$config = $this->validateConfig($this->defaults);
$builder = $this->getContainerBuilder();

$templateFactory = $builder->getByType('Nette\Bridges\ApplicationLatte\ILatteFactory');
if (!$templateFactory) {
throw new InvalidStateException('Service implemented ILatteFactory not found.');
}

$builder->getDefinition($templateFactory)
->addSetup('addFilter', [$config['helper'], ['@' . $this->prefix('parsedown'), 'process']]);
}

}
78 changes: 43 additions & 35 deletions src/ParsedownExtraAdapter.php
Original file line number Diff line number Diff line change
@@ -1,47 +1,55 @@
<?php

namespace Minetro\Parsedown;
namespace Contributte\Parsedown;

use Nette\Object;
use Nette\SmartObject;
use ParsedownExtra;

/**
* ParsedownExtra Adapter
*
* @author Milan Felix Sulc <[email protected]>
* @method onProcess(string $text, ParsedownExtraAdapter $adapter);
* @method void onProcess(string $text, ParsedownExtraAdapter $adapter)
*/
class ParsedownExtraAdapter extends Object
class ParsedownExtraAdapter
{

/** @var ParsedownExtra */
private $parsedown;

/** @var array */
public $onProcess = [];

public function __construct()
{
$this->parsedown = new ParsedownExtra();
}

/**
* @param mixed $text
* @param string
*/
public function process($text)
{
$this->onProcess($text, $this);
return $this->parsedown->parse($text);
}

/**
* @param mixed $line
* @param string
*/
public function processLine($line)
{
$this->onProcess($line, $this);
return $this->parsedown->line($line);
}
}
use SmartObject;

/** @var ParsedownExtra */
private $parsedown;

/** @var array */
public $onProcess = [];

/**
* Creates adapter
*/
public function __construct()
{
$this->parsedown = new ParsedownExtra();
}

/**
* @param mixed $text
* @return mixed
*/
public function process($text)
{
$this->onProcess($text, $this);

return $this->parsedown->parse($text);
}

/**
* @param mixed $line
* @return string
*/
public function processLine($line)
{
$this->onProcess($line, $this);

return $this->parsedown->line($line);
}

}
21 changes: 0 additions & 21 deletions tests/ParsedownExtra/ParsedownExtraAdapterTest.phpt

This file was deleted.

21 changes: 6 additions & 15 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,13 @@
/**
* Test bootstrap.
*/

use Ninjify\Nunjuck\Environment;

if (@!include __DIR__ . '/../vendor/autoload.php') {
echo 'Install Nette Tester using `composer update --dev`';
exit(1);
echo 'Install Nette Tester using `composer update --dev`';
exit(1);
}

// Configure environment
Tester\Environment::setup();
date_default_timezone_set('Europe/Prague');

// Create temporary directory
define('TEMP_DIR', __DIR__ . '/tmp/' . getmypid());
@mkdir(dirname(TEMP_DIR)); // @ - directory may already exist
Tester\Helpers::purge(TEMP_DIR);

// Test functions
function test(\Closure $function)
{
$function();
}
Environment::setup(__DIR__);
Loading

0 comments on commit 9c53ea1

Please sign in to comment.