Compare commits

...

8 commits

Author SHA1 Message Date
dana bb6feca8f4 Bump 0.3.1 -> 0.4.0 2020-04-22 12:49:50 -05:00
dana 05ce587f84 tests: Update expected output for js escape method 2020-04-22 12:49:50 -05:00
dana c7f9eb7514 Application: Update for new package versions, fix formatting 2020-04-22 12:49:50 -05:00
dana c76ce18517 Composer: Update dependencies (compatibility with PHP 7.4) 2020-04-22 12:49:50 -05:00
dana 5de5948cdd Makefile: Improve install target, update phonies 2020-04-22 12:46:10 -05:00
dana 3a89dfaf37 Bump 0.3.0 -> 0.3.1 2018-11-28 17:50:18 -06:00
dana d855eca3cc Update dependencies 2018-11-28 17:50:08 -06:00
dana dd16763ae9 Add zsh completion function 2018-06-27 18:38:13 -05:00
6 changed files with 533 additions and 195 deletions

View file

@ -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
View 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

View file

@ -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

File diff suppressed because it is too large Load diff

View file

@ -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([

View file

@ -178,7 +178,7 @@ class ApplicationTest extends TestCase {
['html_attr', 'testEnv: &quot;&lt;foo&#x24;bar&gt;&quot;'], ['html_attr', 'testEnv: &quot;&lt;foo&#x24;bar&gt;&quot;'],
// 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>\""'],