Code Monkey home page Code Monkey logo

twigfiddle's Introduction

Down right nwo

I need to change twigfiddle's hosting but have no time to correctly reinstall it yet.

It will be back within a couple of weeks (probably mid-june to be sure).

Your data have been backed up.

Cheers

Welcome

This is the project's repository, come here if you found a bug, if you want to request new features or if you want to contribute.

If you need help to use twigfiddle, please read the twigfiddle's help page.

Some words about the project

The project is made of 2 applications:

  • cli directory contains the fiddle runner, an application built using Symfony components to execute a fiddle.

  • web directory contains the web application, built using the Symfony framework

About the other directories:

  • resources directory contains specification documentations, logo source and original integrated design.

  • samples contains exported fiddles (see app/console custom commands)

  • environment is the default directory containing fiddles at runtime

  • debug is the default directory where crashed fiddles are stored

Installation

Here are instructions to get started with the application. Of course, replace paths to fit with your own environment.

# Clone the project
git clone https://github.com/ninsuo/twigfiddle.git twigfiddle
cd twigfiddle

# install Composer
php -r "readfile('https://getcomposer.org/installer');" | php
sudo mv composer.phar /usr/bin/composer
sudo chmod 755 /usr/bin/composer

# Install the fiddle runner and prepare all twig versions
cd cli
composer install
cd twig
sh prepare.sh
cd ../../

# Install the web application
# composer update will fail when trying to remove apc cache, that's normal at this step
cd web
composer install

# Install the database
# You should create it yourself, from mysql, type:
# CREATE DATABASE twigfiddle
# GRANT ALL PRIVILEGES ON twigfiddle.* To '<user>'@'127.0.0.1' IDENTIFIED BY '<password>';
php app/console doctrine:schema:drop --force
php app/console doctrine:schema:create
php app/console twigfiddle:import ../samples/*

# Check that everything is working properly
composer update
php app/check.php
phpunit tests

# Launch the application
php app/console server:start
open http://127.0.0.1:8000/hello

Automatically download, install and configure new Twig releases

Simply run the following command:

php cli/run-prod.php twigfiddle:release:watcher

Upgrade for installs before 01/11/2016

User provider have been refactored ( see #18 ), you need to run the following queries to upgrade twigfiddle schema.

alter table user add column nickname varchar(255) not null after username;
update user set nickname = username;
update user set username = concat('["', resource_owner, '","', resource_owner_id, '"]');

Configure external services

Don't panic, that's optional.

twigfiddle's People

Contributors

alterphp avatar dependabot[bot] avatar erwannrobin avatar gromnan avatar johnnypeck avatar ninsuo avatar pavgup avatar stof avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

twigfiddle's Issues

[Feature Suggestion] Browse most popular fiddles

Hi and thanks for making twigfiddle, it's very useful.

While browsing fiddle, I noticed that there is no way of viewing the most popular fiddles whereas the number of views is displayed.
I think it could be a great way to find interesting twig tricks.

Thanks again,
Paul

[suggestion] enable strict variables by default for new fiddles

The option to enable strict variables is quite hidden in the UI.

twigfiddle is often used to report reproducing test cases for Twig (it is even the official recommendation). But enabling strict variables often allows to discover the issue (as Twig fails loudly rather than returning null for access to undefined methods or variables).

What do you think about enabling it by default for new fiddles (this is to ensure we don't change the behavior of existing fiddles), while keeping the option to disable it (in case you want to reproduce a bug happening only without strict mode) ?

Template limited to 8192 characters

Hi,

We can't run scripts longer than 8192 characters. Can that be changed, really inconvenient for our development.

Thanks much in advance,
Auke

Certificate issues - 31/10 and 01/11

The current gandi certificate is going to expire, and i'm going to replace it with a let's encrypt one.

But this old and sh*tty server is under plesk so this is of course very hard to do.

Waiting for the new server to be ready, I'll try to install it anyway but you may have issues during those 2 days.

Monitoring tools

Need some monitoring tools to check that the website is up and running.

Import samples command seems to be broken

Got the following message after a composer update

Imported: ../samples/for.1.json as fiddle ID = 57
Imported: ../samples/hello-world.json as fiddle ID = 58



  [InvalidArgumentException]                                                                                                                     
  Entity has to be managed or scheduled for removal for single computation Fuz\AppBundle\Entity\FiddleTemplate@000000005b5904ef0000000066e7bb34  



twigfiddle:import [files1] ... [filesN]

Add support for Twig extra packages

For Twig 2+, it would be great to provide the extensions available in twig/*-extra packages (I just tried using some filter from twig/intl-extra).

CSV format for data

I feel this fiddle should support CSV format as data format. how I plan to use this feature:

  • create some queries in MySQL for non-technical people
  • allow them to export as CSV to do their thing in Excel
  • copy paste here and then render the twig to do stuff that Excel is bad at

I can provide an implementation, if you want.

Null coalescing operator

Looks like an issue using the null coalescing operator.

This should work:

{{ variable ?? "Fallback" }}

But I receive an error instead:
The "defined" test only works with simple variables.

ugly security management

The OAuthUserProvider class has its own way to manage logged-in users, but we should only rely on Symfony security component.

As a User connecting from Google and Facebook creates 2 entities (no unified accounts), username should contain the resource_owner/resource_id couple and not user's nickname (so the user provider is able to get it back from db).

A generic implementation (to be adapted to twigfiddle specifically) could be:

<?php

namespace Fuz\AppBundle\Provider;

use HWI\Bundle\OAuthBundle\OAuth\Response\UserResponseInterface;
use HWI\Bundle\OAuthBundle\Security\Core\User\OAuthUserProvider as BaseUserProvider;
use Fuz\AppBundle\Entity\User;

class OAuthUserProvider extends BaseUserProvider
{
    protected $em;

    public function __construct($em)
    {
        $this->em = $em;
    }

    public function loadUserByUsername($username)
    {
        list($resourceOwner, $resourceOwnerId) = json_decode($username, true);

        $user = $this->em->getRepository('FuzAppBundle:User')
           ->getUserByResourceOwnerId($resourceOwner, $resourceOwnerId);

        if ($user) {
            $user->setUsername($username);
        }

        return $user;
    }

    public function loadUserByOAuthUserResponse(UserResponseInterface $response)
    {
        $resourceOwner   = $response->getResourceOwner()->getName();
        $resourceOwnerId = $response->getUsername();
        $name            = $response->getRealName();
        $json            = json_encode([$resourceOwner, $resourceOwnerId]);
        $user            = $this->loadUserByUsername($json);

        $reload = false;
        if (is_null($user)) {
            $user = new User();
            $user->setResourceOwner($resourceOwner);
            $user->setResourceOwnerId($resourceOwnerId);
            $user->setUsername($json);
            $user->setNickname($name);
            $user->setContact($response->getEmail());
            $user->setSigninCount(1);
            $this->em->persist($user);
            $this->em->flush($user);
            $reload = true;
        } else {
            $user->setUsername($json);
            $user->setNickname($name);
            $user->setContact($response->getEmail());
            $user->setSigninCount($user->getSigninCount() + 1);
            $this->em->persist($user);
            $this->em->flush($user);
        }

        if ($reload) {
            return $this->loadUserByUsername($json);
        }

        return $user;
    }

    public function supportsClass($class)
    {
        return $class === 'Fuz\\AppBundle\\Entity\\User';
    }
}

HTTPS support

It would be great if twigfiddle.com could support HTTPS (especially when you are dealing with authentication).

Twig 3.8.0: Uncaught Error: Call to undefined function Twig\Loader\str_contains()

It seems that the yesterday's Twig 3.8.0 release does not run fiddles because of php 8 requirement:

Uncaught Error: Call to undefined function Twig\Loader\str_contains() in twigfiddle:cli/twig/uncompressed/Twig-3.8.0/src/Loader/FilesystemLoader.php:253 Stack trace: #0 twigfiddle:cli/twig/uncompressed/Twig-3.8.0/src/Loader/FilesystemLoader.php(188): Twig\Loader\FilesystemLoader->validateName() #1 twigfiddle:cli/twig/uncompressed/Twig-3.8.0/src/Loader/FilesystemLoader.php(131): Twig\Loader\FilesystemLoader->findTemplate() #2 twigfiddle:cli/twig/uncompressed/Twig-3.8.0/src/Environment.php(264): Twig\Loader\FilesystemLoader->getCacheKey() #3 twigfiddle:cli/src/Fuz/Process/TwigEngine/AbstractTwigEngine.php(45): Twig\Environment->getTemplateClass() #4 twigfiddle:cli/src/Fuz/Process/Service/ExecuteManager.php(66): Fuz\Process\TwigEngine\AbstractTwigEngine->render() #5 twigfiddle:cli/src/Fuz/Process/Command/RunCommand.php(107): Fuz\Process\Service\ExecuteManager->executeFiddle() #6 /var/www/twigfid

twigfiddle runs normally in any other Twig version.

This Twig version is using symfony/polyfill-php80, it needs to be added to the project.

Recurring errors on sh prepare.sh

In file included from /Library/WebServer/Documents/twigfiddle/cli/twig/uncompressed/Twig-1.10.0/ext/twig/twig.c:22:
In file included from /usr/local/php5/include/php/ext/standard/php_smart_str.h:24:
/usr/local/php5/include/php/ext/standard/php_smart_str_public.h:30:3: error: typedef redefinition with different types
      ('struct smart_str' vs 'struct smart_str')

/Library/WebServer/Documents/twigfiddle/cli/twig/uncompressed/Twig-1.10.0/ext/twig/twig.c:80:54: error: too many arguments to
      function call, expected 2, have 3
        return zend_symtable_exists(Z_ARRVAL_P(array), key, key_len + 1);
               ~~~~~~~~~~~~~~~~~~~~                         ^~~~~~~~~~~

/Library/WebServer/Documents/twigfiddle/cli/twig/uncompressed/Twig-1.10.0/ext/twig/twig.c:97:35: error: too many arguments to
      function call, expected single argument 'name', have 3 arguments
        if (zend_lookup_class(interface, strlen(interface), &pce TSRMLS_CC) == FAILURE) {
            ~~~~~~~~~~~~~~~~~            ^~~~~~~~~~~~~~~~~~~~~~~

/Library/WebServer/Documents/twigfiddle/cli/twig/uncompressed/Twig-1.10.0/ext/twig/twig.c:110:34: warning: incompatible pointer
      types passing 'zval **' (aka 'struct _zval_struct **') to parameter of type 'zval *' (aka 'struct _zval_struct *'); remove &
      [-Wincompatible-pointer-types]
                zend_call_method_with_1_params(&object, ce, NULL, "offsetget", &retval, offset);
                                               ^~~~~~~                                   ^
/Library/WebServer/Documents/twigfiddle/cli/twig/uncompressed/Twig-1.10.0/ext/twig/twig.c:144:41: error: use of undeclared
      identifier 'IS_BOOL'
                return (retval && Z_TYPE_P(retval) == IS_BOOL && Z_LVAL_P(retval));
                                                      ^

etc. etc. Just a ton of errors when executing the sh prepare.sh command

v1.x error: "Uncaught Error: Class 'Twig_Loader_Filesystem' not found in"

1.x is erroring for me before it gets off the ground. The code

1

gives me

Uncaught Error: Class 'Twig_Loader_Filesystem' not found in twigfiddle:cli/src/Fuz/Process/TwigEngine/V2TwigEngine.php:114 Stack trace: #0 twigfiddle:cli/src/Fuz/Process/TwigEngine/V2TwigEngine.php(35): Fuz\Process\TwigEngine\V2TwigEngine->loadBefore270('/var/www/twigfi...', '/var/www/twigfi...', '/var/www/twigfi...') #1 twigfiddle:cli/src/Fuz/Process/Service/ExecuteManager.php(58): Fuz\Process\TwigEngine\V2TwigEngine->load('/var/www/twigfi...', '/var/www/twigfi...', '/var/www/twigfi...') #2 twigfiddle:cli/src/Fuz/Process/Command/RunCommand.php(107): Fuz\Process\Service\ExecuteManager->executeFiddle(Object(Fuz\Process\Agent\FiddleAgent)) #3 twigfiddle:cli/src/Fuz/Process/Command/RunCommand.php(141): Fuz\Process\Command\RunCommand->process() #4 twigfiddle:cli/vendor/symfony/console/Command/Command.php(266): Fuz\Process\Command\RunCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfon

Same error for anything else.

Fiddle: https://twigfiddle.com/lop40u

Maintenance on the night 19th and 20th of June 2018

I'm moving twigfiddle from an old server to a brand new one.

You may experience a few issues during that night:

  • SSL certificate issues (and even no SSL).
  • Data loss for new fiddles added during the maintenance period.

Thanks for understanding!

Twig 2.7.0 broke twigfiddle

Latest Twig release breaks the V2TwigEngine's spl_autoload_register logic.

Use up to date \Twig\Loader\FilesystemLoader instead if available.

Unable to load extensions

After enabling extensions v1.5.4 with Twig v3.3.7 I receive the below error message when I press Run:

#⁠1 Type 1
#⁠2 Message Uncaught TypeError: Argument 2 passed to Fuz\Process\Service\TwigExtensionsManager::loadTwigExtensions() must be an instance of Twig_Environment, instance of Twig\Environment given, called in twigfiddle:cli/src/Fuz/Process/Service/ExecuteManager.php on line 62 and defined in twigfiddle:cli/src/Fuz/Process/Service/TwigExtensionsManager.php:27 Stack trace: #⁠0 twigfiddle:cli/src/Fuz/Process/Service/ExecuteManager.php(62): Fuz\Process\Service\TwigExtensionsManager->loadTwigExtensions() #⁠1 twigfiddle:cli/src/Fuz/Process/Command/RunCommand.php(107): Fuz\Process\Service\ExecuteManager->executeFiddle() #⁠2 twigfiddle:cli/src/Fuz/Process/Command/RunCommand.php(141): Fuz\Process\Command\RunCommand->process() #⁠3 twigfiddle:cli/vendor/symfony/console/Command/Command.php(245): Fuz\Process\Command\RunCommand->execute() #⁠4 twigfiddle:cli/vendor/symfony/console/Application.php(835): Symfony\Component\Console\
#⁠3 File twigfiddle:cli/src/Fuz/Process/Service/TwigExtensionsManager.php
#⁠4 Line 27

image

Am I doing something incorrect (I'm learning twig) or is this a bug?

Support displaying results as HTML

Can be useful to add a "Show HTML result" button to interpret HTML results instead of displaying text.
See: http://twigfiddle.com/e88llr

Should wrap the feature inside an iframe endpointed elsewhere than on twigfiddle.com to secure against xss using cross origin request policies.

Add support for github auth

Supporting github oauth would make sense (I even think it is more relevant than facebook login for a tool aimed at devs)

Add a PHP pane so we can create twig extensions

This might be useful to integrate a PHP editor so we can develop and integrate custom twig extensions to fiddles.

This has not been scheduled for the first release as this leads to lots of questions about security. If you have ideas about the way to run arbitrary PHP code safely, don't hesitate to share.

Can't save fiddle for the first time if there are empty templates

I created a new fiddle with multiple templates. Some of the templates were empty. When I tried to save the fiddle, I got this this error message:

We're sorry, but an error occurred...

I added some text to the empty templates and tried saving again, which was then successful.

Then I tried removing that text and saving again, which was also successful.

So it seems that fiddles won't save empty templates only on the first save.

Add support to dump() function

It can be useful to debug variables when using twigfiddle.

Integrate a {{ dump() }} function, that will use the VarDumper component in order to dump variables in a new pane (below the Result pane for example).

As {{ dump() }} can be used several times, a line above showing where it was called (file:line) should be useful.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.