Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions app/src/Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
use Twig_Environment;
use Twig_Extension_Escaper;
use Twig_Loader_Filesystem;
use Twig_SimpleFilter;

/**
* `Setup` is a static class for use with the Composer post-create-project event.
Expand All @@ -43,7 +43,13 @@ public static function wizard(Event $event)
$finder = new Finder();

$twig = static::getTwigEnvironment();
$twig->addFilter(new Twig_SimpleFilter('addslashes', 'addslashes'));
/** @var Twig_Extension_Escaper $extension */
$extension = $twig->getExtension(Twig_Extension_Escaper::class);
$extension->setEscaper('json', static function ($env, string $string) {
$encoded = json_encode($string, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);

return $encoded ? substr($encoded, 1, -1) : '';
});

$prompt = static::getPrompt($io, $filesystem, $finder);
$prompt->setQuestions(new Questions\InstallQuestions());
Expand Down
5 changes: 4 additions & 1 deletion app/tests/SetupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ public function testWizard()
'packageName' => 'foo/bar',
];

$extension = \Mockery::mock(\Twig_Extension::class);
$extension->expects()->setEscaper('json', anInstanceOf(\Closure::class));

$twig = \Mockery::mock(\Twig_Environment::class, [
'addFilter' => null,
'getExtension' => $extension,
]);

$prompt = \Mockery::mock(Prompt::class, [
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
},
"require": {
"php": "^7.2",
"ext-json": "*",
"symfony/filesystem": "^4.2",
"symfony/finder": "^4.2",
"twig/twig": "^2.10"
Expand Down
28 changes: 14 additions & 14 deletions skeleton/composer.json.twig
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"name": "{{ packageName|escape('js') }}",
"description": "{{ packageDescription|escape('js') }}",
"name": "{{ packageName|escape('json') }}",
"description": "{{ packageDescription|escape('json') }}",
"type": "library",
"keywords": [{% for keyword in keywords|split(',') %}"{{ keyword|trim|escape('js') }}"{% if not loop.last %}, {% endif %}{% endfor %}],
"homepage": "https://github.com/{{ githubUsername|escape('js') }}/{{ githubProject|escape('js') }}",
"keywords": [{% for keyword in keywords|split(',') %}"{{ keyword|trim|escape('json') }}"{% if not loop.last %}, {% endif %}{% endfor %}],
"homepage": "https://github.com/{{ githubUsername|escape('json') }}/{{ githubProject|escape('json') }}",
"license": "MIT",
"authors": [
{
"name": "{{ authorName|escape('js') }}",
"email": "{{ authorEmail|escape('js') }}",
"homepage": "{{ authorUrl|escape('js') }}"
"name": "{{ authorName|escape('json') }}",
"email": "{{ authorEmail|escape('json') }}",
"homepage": "{{ authorUrl|escape('json') }}"
}
],
"support": {
"docs": "https://{{ githubUsername|escape('js') }}.github.io/{{ githubProject|escape('js') }}/",
"issues": "https://github.com/{{ githubUsername|escape('js') }}/{{ githubProject|escape('js') }}/issues",
"rss": "https://github.com/{{ githubUsername|escape('js') }}/{{ githubProject|escape('js') }}/releases.atom",
"source": "https://github.com/{{ githubUsername|escape('js') }}/{{ githubProject|escape('js') }}.git",
"wiki": "https://github.com/{{ githubUsername|escape('js') }}/{{ githubProject|escape('js') }}/wiki"
"docs": "https://{{ githubUsername|escape('json') }}.github.io/{{ githubProject|escape('json') }}/",
"issues": "https://github.com/{{ githubUsername|escape('json') }}/{{ githubProject|escape('json') }}/issues",
"rss": "https://github.com/{{ githubUsername|escape('json') }}/{{ githubProject|escape('json') }}/releases.atom",
"source": "https://github.com/{{ githubUsername|escape('json') }}/{{ githubProject|escape('json') }}.git",
"wiki": "https://github.com/{{ githubUsername|escape('json') }}/{{ githubProject|escape('json') }}/wiki"
},
"require": {
"php": "^7.2"
Expand All @@ -32,12 +32,12 @@
},
"autoload": {
"psr-4": {
"{{ namespace|escape('js') }}\\": "src/"
"{{ namespace|escape('json') }}\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"{{ namespace|escape('js') }}\\Test\\": "tests/"
"{{ namespace|escape('json') }}\\Test\\": "tests/"
}
},
"scripts": {
Expand Down