Giter VIP home page Giter VIP logo

parser's Introduction

FuelPHP

Description

FuelPHP is a fast, lightweight PHP 5.4+ framework. In an age where frameworks are a dime a dozen, we believe that FuelPHP will stand out in the crowd. It will do this by combining all the things you love about the great frameworks out there, while getting rid of the bad.

FuelPHP is fully PHP 7.3 compatible.

More information

For more detailed information, see the development wiki.

Development Team

Want to join?

The FuelPHP development team is always looking for new team members, who are willing to help lift the framework to the next level, and have the commitment to not only produce awesome code, but also great documentation, and support to our users.

You can not apply for membership. Start by sending in pull-requests, work on outstanding feature requests or bugs, and become active in the #fuelphp IRC channel. If your skills are up to scratch, we will notice you, and will ask you to become a team member.

Alumni

parser's People

Contributors

adammbalogh avatar bakert avatar billmn avatar bobthecow avatar br0p0p avatar craighooghiem avatar dhrrgn avatar dmyers avatar evantishuk avatar feldsam avatar frankdejonge avatar iquito avatar it-can avatar kenjis avatar mrdlef avatar omoon avatar ounziw avatar phpwebnet avatar rickharris avatar sagikazarmark avatar stevewest avatar tgfjt avatar tomschlick avatar tyoshii avatar wanwizard avatar web2citizen 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

parser's Issues

Generic view is preferred above module.

I'm currently trying to get a basic web app working, seperating my admin into a module.

I'm using Twig and the Parser package to manage templating.

I have two view called base.twig in fuel/app/views/ and fuel/app/modules/admin/views.

When I want to extend the admin template (the one in /modules/admin...) (from a controller in the module) I keep getting the generic one (app/views).

I have read the docs regarding views and parser at least fifteen times, and couldn't come up with a solution. MY last resort (renaming the admin template to base2 and adjusting the extending view) resulted in this error.

Controller and extending template

Checked against 1.8/develop and verified it happening there too.

Mustache could use an update.

Fuel/Parser includes Mustache.php (yay 😄) but it's 8 versions out of date (boo 😦).

It's a fairly straightforward upgrade path, so I'm happy to provide a pull request, but I'm not quite sure what the best way to upgrade is.

Mustache.php v2.x consists of quite a few more files than v1.x, so it probably shouldn't be directly included in the repo. It also needs an autoloader: it either uses Composer, or some other PSR-0 compatible autoloader, or it ships with its own autoloader which could be used.

To complicate things a bit more, it looks like Fuel's headed toward using Composer for everything, and Composer solves both of the above problems. How will this move play out for Fuel/Parser?

Should I...

  1. hold off on a pull request until the Composer changes make it further into the pipeline?
  2. send a pull request to use the same "drop it in the vendor folder" strategy that the Twig integration currently uses?
  3. something else entirely?

ErrorException [ Notice ]: Undefined variable: file

parser/classes/view/jade.php:60

protected function process_file($file_override = false)
	{
		// update the cache path
		$this->cache_init($file);
		// determine the filename
		$file = $file_override ?: $this->file_name;

Missing dump() function for twig parser

I spent an hour or more trying to get the twig debug() function to work.
I read lots of documentations and all pointed to settings debug=true

This didnt work of course. However after manually tracing through the code i found the problem
The dump function is not included in the fuel twig extensions list.

Inside this file
/fuel/packages/parser/classes/twig/fuel/extension.php

You need to add this line inside getFunctions()
'dump' => new Twig_Function_Function('Debug::dump')

I think the dump() function is the most important function it is required for developers i think.

Previously fuelphp supported this function i think there must have been a recent upgrade which has lost this function from the listing.

I would be good if someone could revise the current list, or at least add the above line to future distributions as it is impossible to find it documented online otherwise.

unless you read this of course... lol

Thanks
Daniel

Smarty Template Inheritance and Includes

Including files or extending files require full path to templates directory:

For example:

{include '..\fuel\app\views\my_template.smarty'}

{extends file='..\fuel\app\views\header.smarty'}

Fatal Error on clean install

With a clean installation of Fuel RC3 and latest version of parser in "develop" branch, obtain :

"Fatal error: Exception thrown without a stack frame in Unknown on line 0 "

I think that problem is on line 28 ( $file = ... ) in parser/classes/view.php

Some config values can't be customized

Some of the config values are written as arrays with implicit numeric keys, for instance:

'delimiters' => array('{', '}'),

Such values can't be overwritten in app/config/parser.php because the array from app/config/parser.php is then just merged to the original value:

array(4) {
  [0]=> string(2) "{" 
  [1]=> string(2) "}" 
  [2]=> string(2) "{%" 
  [3]=> string(2) "%}" 
}

It would be better to use such config values:

'delimiters' => array('left'=>'{', 'right'=>'}'),

See http://fuelphp.com/forums/topics/view/4686/ .

Extension for template page

With a configuration like :

'extensions' => array(
        'php'       => 'View',
        'twig'      => array('class' => 'View_Twig', 'extension' => '.html'),
        'mustache'  => 'View_Mustache',
        'md'        => 'View_Markdown',
                ...
    ),

I expect that I can use Twig template page with ".html" extension so :

$view = \View::forge('page.twig');

that call 'views\page.html' using Twig class

But parser always search a 'page.twig' page and and if it doesn't exist I obatin a "view not found" error.

I think that the error can be in "parser\classes\view.php" in line 82 :

// Set extension when given
$extension and $view->extension = $extension;

When View class set the page extension ( .html ), the parser class has already searched and parsed the page with '.twig' extension

Need more Fuelphp classes and methods supports for Twig

I solved that by extending the \Parser\Twig_Fuel_Extension classes but maybe there is a better solution to have an exhaustive set of functions :

<?php

class Twig_Fuel_Extension extends \Parser\Twig_Fuel_Extension
{
    public function getFunctions()
    {
        return array(
            'fuel_version' => new Twig_Function_Method($this, 'fuel_version'),
            'url'           => new Twig_Function_Method($this, 'url'),

            'uri_base'      => new Twig_Function_Function('Uri::base'),
            'uri_segment'   => new Twig_Function_Function('Uri::segment'),
            'uri_segments'  => new Twig_Function_Function('Uri::segments'),
            'config'        => new Twig_Function_Function('Config::get'),
            'lang'          => new Twig_Function_Function('Lang::get'),

            'form_open'     => new Twig_Function_Function('Form::open'),
            'form_close'    => new Twig_Function_Function('Form::close'),
            'form_input'    => new Twig_Function_Function('Form::input'),
            'form_password' => new Twig_Function_Function('Form::password'),
            'form_hidden'   => new Twig_Function_Function('Form::hidden'),
            'form_radio'    => new Twig_Function_Function('Form::radio'),
            'form_checkbox' => new Twig_Function_Function('Form::checkbox'),
            'form_textarea' => new Twig_Function_Function('Form::textarea'),
            'form_file'     => new Twig_Function_Function('Form::file'),
            'form_button'   => new Twig_Function_Function('Form::button'),
            'form_reset'    => new Twig_Function_Function('Form::reset'),
            'form_submit'   => new Twig_Function_Function('Form::submit'),
            'form_select'   => new Twig_Function_Function('Form::select'),
            'form_label'    => new Twig_Function_Function('Form::label'),
            'form_val'      => new Twig_Function_Function('Input::param'),

            'asset_add_path' => new Twig_Function_Function('Asset::add_path'),
            'asset_css'     => new Twig_Function_Function('Asset::css'),
            'asset_js'      => new Twig_Function_Function('Asset::js'),
            'asset_img'     => new Twig_Function_Function('Asset::img'),
            'asset_render'  => new Twig_Function_Function('Asset::render'),

            'html_anchor'   => new Twig_Function_Function('Html::anchor'),

            'input_get'   => new Twig_Function_Function('Input::get'),
            'input_post'   => new Twig_Function_Function('Input::post'),

            'session_get_flash'   => new Twig_Function_Function('Session::get_flash')
        );
    }

    public function fuel_version()
    {
        return Fuel::VERSION;
    }
}

Parser Forge to default to Core View Extension

There is a protected variable on the \Fuel\Core\View called "extension" which when set, sets the default. It would be nice if the Parser View would default to that if no extension is detected when using the pathinfo($file).

So instead of:

$extension  = pathinfo($file, PATHINFO_EXTENSION);

It would be something like:

$extension  = pathinfo($file, PATHINFO_EXTENSION);

if (empty($extension)) {
   $extension = $this->extension;
}

What do you guys think?

View->set_filename() not working as expected

If I have
$this->view = View::forge();
and later I try to set filename like
$this->view->set_filename("template.twig"); it will search for template.twig.php,
but if I have
$this->view = View::forge("dummy.twig");
later I can do
$this->view->set_filename("template"); //notice that there's no .twig extension
and everything will work as expected.
I find this behavior littlebig strange.

Default include paths

The online docs for 1.6 (http://fuelphp.com/docs/packages/parser/intro.html) explain that if you don't want to change the "config they [template drivers] are expected in app/vendor/{Lib_name}".

It took me a while to figure out that recently the 'include' paths for some of the drivers have been removed or commented out. I was trying to get Twig to work so I placed the lib in app/vendor/Twig but Fuel couldn't find the Twig_Autoloader class.

After some investigating I copied the 'include' config item for 'View_Twig' in the config/parser.php from an earlier version of Fuel so that it reads:
APPPATH.'vendor'.DS.'Twig'.DS.'Autoloader.php'

Suddenly, everything works.

Is there a reason why the default include path has been removed but there is no mention of it in the docs?

Mustache Incompatibility with key indexed relationship arrays

I just thought I'd bring this up, not sure if it's worth fixing, or where it should be fixed.

The php mustache library is fairly clear about it's opinions in the differences of iterating hashes vs lists: https://github.com/bobthecow/mustache.php/wiki/Mustache-Tags#lists-vs-hashes

This causes a problem when iterating through a list of related models from the Fuel Orm because they are keyed off their indexes. They are evaluated as a hash, not iterable, and do not render as expected.

Example

<ol>
{{#comments}}
  <li>{{text}}</li>
{{/comments}}
</ol>

Mustache library requires that I convert the comments array to a non-sparse indexed array.

\Orm\Model::to_array() preserves these keys, with no option to remove them.

My current fix is to add a method called Model_Article::to_mustache() that is a copy of \Orm\Model::to_array() with one minor change; it doesn't preserve the keys.

Ideas? Opinions?

View_Markdown

There is a false path definition in the config.php for the parser who lead to compile errors if you use makdown files as template file (e.g. View::forge('xyz.md')).

'View_Markdown' => array(
    // 'include'     => \Package::exists('parser').'vendor'.DS.'markdown'.DS.'markdown.php', FALSE!!!
	'include'     => \Package::exists('parser').'classes'.DS.'view'.DS.'markdown.php',  //CORRECT
	'auto_encode' => true,
	'allow_php'   => true,
),

Changing view paths causes Twig to throw an error

Issue:

When I change paths (i.e. views/contacts to views/layouts) Twig throws an error)

Think it has something to do with Twig holding on to the paths from a previous instance. (I dunno if its a problem with Parser or Twig as a quick glance of each's internals revealed nothing to me.)

To recreate:

Call $data["content"] = render('contacts/show.twig', $data);
Then call $layout = View::factory('layouts/application.twig', $data, false);

Views Folder Structure:

views
| 
-- layouts
   |
   --application.twig
-- contacts
   |
   --show.twig

Error w/ Backtrace:

APPPATH actually showed my path in the error - I just removed it

Error!
Twig_Error_Loader [ Error ]: Unable to find template "application.twig" (looked into: APPPATH/views/contacts, APPPATH/views).

APPPATH/vendor/Twig/Loader/Filesystem.php @ line 129

124            if (is_file($path.'/'.$name)) {
125                return $this->cache[$name] = $path.'/'.$name;
126            }
127        }
128
129        throw new Twig_Error_Loader(sprintf('Unable to find template "%s" (looked into: %s).', $name, implode(', ', $this->paths)));
130    }
131
132    protected function validateName($name)
133    {
134        if (false !== strpos($name, "\0")) {
Backtrace

APPPATH/vendor/Twig/Loader/Filesystem.php @ line 98
APPPATH/vendor/Twig/Environment.php @ line 259
APPPATH/vendor/Twig/Environment.php @ line 294
PKGPATH/parser/classes/view/twig.php @ line 42
COREPATH/classes/view.php @ line 418
COREPATH/classes/view.php @ line 197
DOCROOT/index.php @ line 47

Something I tried

I var_dumped the $_parser_loader when the exception was caught (Around line 48 in parser/classes/view/twig.php) and got this

object(Twig_Loader_Filesystem)#16 (2) {
  ["paths":protected]=>
  array(2) {
    [0]=>
    string(51) "APPPATH/views/layouts"
    [1]=>
    string(43) "APPPATH/views"
  }
  ["cache":protected]=>
  array(0) {
  }
}

This leads me to believe that something "statically" being set is not in fact changing on the Twig side of things as the var_dump reveals the paths were set correctly in the Twig_Loader_Filesystem and in the Error w/Backtrace shows that the paths are different (i.e. APPPATH/views/layouts, APPPATH/views vs. APPPATH/views/contacts, APPPATH/views)

Let me know if you need other details, I tried to be as thorough as possible.
Thanks,
Matt

Error in config/parser.php for Twig

To avoid problems with Twig Autoloader, the name of the directory in app/vendor must be "Twig" ( not lower or upper )

So in the package there's an error in "config/parser.php", change the current configuration with :

'View_Twig' => array(
    'include'     => APPPATH.'vendor'.DS.'Twig'.DS.'Autoloader.php',
),

And it works fine

View's Forge Function doesn't work like Core View Forge Function

Something I noticed and I was wondering your guys thoughts on was that the Parser's View::Forge() function doesn't work the same as Core View::Forge() function.

Basically you can could store an instance of the View::forge() in say your controller and not pass any template file name or data for the template and later do it, this is useful for the flow of your application IMO, but with Parser's View::forge() it is optional as a null, but doesn't ignore empty files like the Core View::forge(). Confusing to explain, but maybe someone will understand.

Example:

public $view;

public function before()
{
    $this->view = View::forge();
}

public function after($response)
{
   return $request->body($this->view);
}

public function test_action()
{
   $this->view->set_filename('path/to/test');
   $this->view->variable = 'test';
}

I think the way to improve the Parser's View class is to change it from overriding the forge() and factory() functions and to actually override the __construct() and set_filename() instead, but I could be wrong. Looking for help. :)

Request: A way to render a view without it being parsed

JS libraries, such as handlebars, require the raw/unparsed template including in a <script></script> tag in order to use AJAX. The basic design pattern would be that a view.mustache would be created and data would be applied to it and it would be rendered parsed. You would then render it unparsed, wrapped in a script tag, and handlebars would handle the ajax request for JSON and the client side parsing of this.

Parser doesn't work with the last Twig release (1.12.0)

With the release 1.12.0 of Twig now we have this error :

LogicException [ Error ]: Unable to add global "%GLOBAL_VARIABLE%" as the runtime or the extensions have already been initialized.

This because with this release "Global Variables" must be initialized before the Lexer instance and then can be overwritten on render :

Check this discussion : https://groups.google.com/forum/?fromgroups=#!topic/silex-php/Ew-Fs5VXqlQ

The problem is the position of addGlobal() method :

if ( ! empty($global_data))
{
    foreach ($global_data as $key => $value)
    {
        static::parser()->addGlobal($key, $value);
    }
}

How can we solve this?

This param 'default' is optional in a function 'config_get', is not this?

Sorry,I'm not good at English.
Is the 9th line correct? ($default = ...)

    /**
     * Usage: {config item='' default=''}
     * Required: item
     *
     * @return  mixed string or array
     */
    public function config_get($params) {
        if (isset($params['item'])) {
            $default = $params['default'] ? null : $params['default'];
            return Config::get($params['item'], $default);
        }
        return '';
    }

Database results are read-only using Parser\View

Trying to upgrade a existing project for use Parser package give this error:
http://oi53.tinypic.com/2sb8jzm.jpg

Always when u try to pass a Database_Result into a var like this:

$data['rows'] = \DB::select('*')
                    ->from('table')
                    ->execute();

$this->response->body = View::factory('view', $data);

If i deactive Parser package that dosent happens.

Im using develop branch of fuel.( upgraded from rc1> rc2>rc3)
Greetz.

Smarty_Fuel_Extension::asset_find_file parameter miss.

I found a bug in asset_find_file method of Smarty_Fuel_Extension class.

- Asset :: find_file ($ params ['file'], $ params ['file'], $ folder);
+ Asset :: find_file ($ params ['file'], $ params ['type'], $ folder);

It will work correctly with this fix.

Undefined method Fuel\Core\View::_init()

With the latest CORE version ( 1.1 dev ) Parser View class is broken.

ErrorException [ Error ]: Call to undefined method Fuel\Core\View::_init()
PKGPATH/parser/classes/view.php @ line 27

In CORE View class was removed _init() method ...

Which method we can use?

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.