mirror of
https://github.com/okdana/twigc.git
synced 2024-06-15 20:25:21 +02:00
Compare commits
8 commits
Author | SHA1 | Date | |
---|---|---|---|
bb6feca8f4 | |||
05ce587f84 | |||
c7f9eb7514 | |||
c76ce18517 | |||
5de5948cdd | |||
3a89dfaf37 | |||
d855eca3cc | |||
dd16763ae9 |
7
Makefile
7
Makefile
|
@ -4,6 +4,9 @@
|
||||||
# @author dana <dana@dana.is>
|
# @author dana <dana@dana.is>
|
||||||
# @license MIT
|
# @license MIT
|
||||||
|
|
||||||
|
prefix ?= /usr/local
|
||||||
|
bindir ?= $(prefix)/bin
|
||||||
|
|
||||||
all: build
|
all: build
|
||||||
build: phar
|
build: phar
|
||||||
phar: clean twigc.phar
|
phar: clean twigc.phar
|
||||||
|
@ -40,7 +43,7 @@ test-integration: twigc.phar
|
||||||
echo 'hello {{ name }}' | ./twigc.phar -p name=foo | grep -qF 'hello foo'
|
echo 'hello {{ name }}' | ./twigc.phar -p name=foo | grep -qF 'hello foo'
|
||||||
|
|
||||||
install: twigc.phar
|
install: twigc.phar
|
||||||
cp twigc.phar /usr/local/bin/twigc
|
cp twigc.phar $(DESTDIR)$(bindir)/twigc
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f twigc.phar
|
rm -f twigc.phar
|
||||||
|
@ -48,4 +51,4 @@ clean:
|
||||||
distclean: clean
|
distclean: clean
|
||||||
rm -rf vendor/
|
rm -rf vendor/
|
||||||
|
|
||||||
.PHONY: all clean distclean install test test-integration test-unit
|
.PHONY: all build clean distclean help install phar test test-integration test-unit
|
||||||
|
|
51
complete/_twigc
Normal file
51
complete/_twigc
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
#compdef twigc
|
||||||
|
|
||||||
|
local ret=1
|
||||||
|
local -a context expl line state state_descr tmp
|
||||||
|
local -A opt_args
|
||||||
|
|
||||||
|
_arguments -s -S : \
|
||||||
|
'(: * -)'{-h,--help}'[display help information]' \
|
||||||
|
'(: * -)'{-V,--version}'[display version information]' \
|
||||||
|
'(: * -)--credits[display third-party dependency information]' \
|
||||||
|
'--cache=[specify cache directory]:cache directory:_directories' \
|
||||||
|
'*'{-d+,--dir=}'[add specified include directory]:include directory:_directories' \
|
||||||
|
'(-e --escape)'{-e+,--escape=}'[specify auto-escaping strategy]: :->strategies' \
|
||||||
|
'(-E --env)'{-E,--env}'[derive input data from environment]' \
|
||||||
|
'*'{-j+,--json=}'[derive input data from specified JSON dict/file]: :->json' \
|
||||||
|
'*'{-p+,--pair=}'[derive input data from specified key=value pair]:key=value pair' \
|
||||||
|
'*--query=[derive input data from specified URL query string]:URL query string' \
|
||||||
|
'(-s --strict)'{-s,--strict}'[throw exception when undefined variable is referenced]' \
|
||||||
|
'*:template file:_files' \
|
||||||
|
&& ret=0
|
||||||
|
|
||||||
|
case $state in
|
||||||
|
json)
|
||||||
|
if [[ $PREFIX$SUFFIX == [[:space:]]#\{* ]]; then
|
||||||
|
_message -e strings 'JSON dictionary string'
|
||||||
|
elif [[ -n $PREFIX$SUFFIX ]]; then
|
||||||
|
_description files expl 'JSON file'
|
||||||
|
_files "${(@)expl}" && ret=0
|
||||||
|
else
|
||||||
|
_alternative \
|
||||||
|
'strings: : _message -e strings "JSON dictionary string"' \
|
||||||
|
'files:JSON file:_files' \
|
||||||
|
&& ret=0
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
strategies)
|
||||||
|
tmp=(
|
||||||
|
'none:no escaping'
|
||||||
|
'css:CSS hex-escaping'
|
||||||
|
'html:HTML ampersand-escaping (for body)'
|
||||||
|
'html_attr:HTML ampersand-escaping (for attribute)'
|
||||||
|
'js:JavaScript hex-escaping'
|
||||||
|
'json:JSON serialization'
|
||||||
|
'sh:shell double-quoting and escaping'
|
||||||
|
'url:URL percent-escaping'
|
||||||
|
)
|
||||||
|
_describe -t strategies 'auto-escaping strategy' tmp && ret=0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
return ret
|
|
@ -1,9 +1,8 @@
|
||||||
{
|
{
|
||||||
"_comments": {
|
"_comments": {
|
||||||
"symfony/finder": [
|
"symfony/finder": [
|
||||||
"This is only required for the Phar build, actually!",
|
"This is only required for the Phar build, actually. Can't remember what",
|
||||||
"I added it to the regular requires just to fix a problem with Composer.",
|
"the problem was with making it require-dev, but some day i'll fix it..."
|
||||||
"Some day i'd like to put it back..."
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -14,11 +13,11 @@
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=7.0",
|
"php": ">=7.2.5",
|
||||||
"symfony/console": "^4.0",
|
"symfony/console": "^5.0",
|
||||||
"symfony/finder": "^4.0",
|
"symfony/finder": "^5.0",
|
||||||
"twig/twig": "^2.4",
|
"twig/twig": "^3.0",
|
||||||
"ulrichsg/getopt-php": "^3.1"
|
"ulrichsg/getopt-php": "^3.3"
|
||||||
},
|
},
|
||||||
|
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
|
|
636
composer.lock
generated
636
composer.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -13,6 +13,7 @@ use GetOpt\{Argument,GetOpt,Operand,Option};
|
||||||
use Symfony\Component\Console\Helper\Table;
|
use Symfony\Component\Console\Helper\Table;
|
||||||
use Symfony\Component\Console\Output\{ConsoleOutputInterface,OutputInterface};
|
use Symfony\Component\Console\Output\{ConsoleOutputInterface,OutputInterface};
|
||||||
use Twig\Environment;
|
use Twig\Environment;
|
||||||
|
use Twig\Extension\EscaperExtension;
|
||||||
use Twig\Loader\{ArrayLoader,FilesystemLoader};
|
use Twig\Loader\{ArrayLoader,FilesystemLoader};
|
||||||
|
|
||||||
use Dana\Twigc\ComposerHelper;
|
use Dana\Twigc\ComposerHelper;
|
||||||
|
@ -29,7 +30,7 @@ use Dana\Twigc\ComposerHelper;
|
||||||
*/
|
*/
|
||||||
class Application {
|
class Application {
|
||||||
const NAME = 'twigc';
|
const NAME = 'twigc';
|
||||||
const VERSION = '0.3.0';
|
const VERSION = '0.4.0';
|
||||||
const BUILD_DATE = '%BUILD_DATE%'; // Replaced during build
|
const BUILD_DATE = '%BUILD_DATE%'; // Replaced during build
|
||||||
|
|
||||||
protected $name;
|
protected $name;
|
||||||
|
@ -122,7 +123,7 @@ class Application {
|
||||||
$temp = false;
|
$temp = false;
|
||||||
|
|
||||||
// If we're receiving data on standard input, and we didn't get a template,
|
// If we're receiving data on standard input, and we didn't get a template,
|
||||||
// assume `-` — we'll make sure this doesn't conflict with `-j` below
|
// assume `-` — we'll make sure this doesn't conflict with `-j` below
|
||||||
if ( ! posix_isatty(\STDIN) ) {
|
if ( ! posix_isatty(\STDIN) ) {
|
||||||
$template = $template ?? '-';
|
$template = $template ?? '-';
|
||||||
}
|
}
|
||||||
|
@ -249,18 +250,18 @@ class Application {
|
||||||
),
|
),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$twig->getExtension('Twig_Extension_Core')->setEscaper(
|
$twig->getExtension(EscaperExtension::class)->setEscaper(
|
||||||
'json',
|
'json',
|
||||||
function($twigEnv, $string, $charset) {
|
function ($twigEnv, $string, $charset) {
|
||||||
return json_encode(
|
return json_encode(
|
||||||
$string,
|
$string,
|
||||||
\JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE
|
\JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
$twig->getExtension('Twig_Extension_Core')->setEscaper(
|
$twig->getExtension(EscaperExtension::class)->setEscaper(
|
||||||
'sh',
|
'sh',
|
||||||
function($twigEnv, $string, $charset) {
|
function ($twigEnv, $string, $charset) {
|
||||||
return '"' . addcslashes($string, '$`\\"') . '"';
|
return '"' . addcslashes($string, '$`\\"') . '"';
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -337,9 +338,9 @@ class Application {
|
||||||
|
|
||||||
$table = new Table($output);
|
$table = new Table($output);
|
||||||
$table->setStyle('compact');
|
$table->setStyle('compact');
|
||||||
$table->getStyle()->setVerticalBorderChar('');
|
$table->getStyle()->setVerticalBorderChars('');
|
||||||
$table->getStyle()->setCellRowContentFormat('%s ');
|
$table->getStyle()->setCellRowContentFormat('%s ');
|
||||||
$table->setHeaders(['name', 'version', 'licence']);
|
$table->setHeaders(['#name', 'version', 'licence']);
|
||||||
|
|
||||||
foreach ( $packages as $package ) {
|
foreach ( $packages as $package ) {
|
||||||
$table->addRow([
|
$table->addRow([
|
||||||
|
|
|
@ -178,7 +178,7 @@ class ApplicationTest extends TestCase {
|
||||||
['html_attr', 'testEnv: "<foo$bar>"'],
|
['html_attr', 'testEnv: "<foo$bar>"'],
|
||||||
|
|
||||||
// Escape method: js
|
// Escape method: js
|
||||||
['js', 'testEnv: \\x22\\x3Cfoo\\x24bar\\x3E\\x22'],
|
['js', 'testEnv: \\u0022\\u003Cfoo\\u0024bar\\u003E\\u0022'],
|
||||||
|
|
||||||
// Escape method: json
|
// Escape method: json
|
||||||
['json', 'testEnv: "\"<foo$bar>\""'],
|
['json', 'testEnv: "\"<foo$bar>\""'],
|
||||||
|
|
Loading…
Reference in a new issue