Giter VIP home page Giter VIP logo

mthaml's People

Contributors

amouhzi avatar antoinelafontaine avatar arnaud-lb avatar dracony avatar ezekg avatar hason avatar jacmoe avatar linc01n avatar lolmaus avatar mervick avatar pwhelan avatar scil avatar stfalcon avatar thelucre avatar vendethiel avatar weotch 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mthaml's Issues

Add new tag

Can you please add a new tag and create new release?

Redundant indentation inside Run block

Suppose we have the following template:

%body
  - $options = [ 'One', 'Two', 'Three', 'Four', 'Five' ]

  - if (count($options))
    %ul
      - foreach ($options as $item)
        %li= $item
  - else
    %div No options!

Now it generates well-indented PHP code like this:

<body>
  <?php $options = [ 'One', 'Two', 'Three', 'Four', 'Five' ]; ?>
  <?php if (count($options)) { ?>
    <ul>
      <?php foreach ($options as $item) { ?>
        <li><?php echo htmlspecialchars($item,ENT_QUOTES,'UTF-8'); ?></li>
      <?php } ?>
    </ul>
  <?php } else { ?>
    <div>No options!</div>
  <?php } ?>
</body>

But in fact the output HTML code has some redundant indentation:

<body>
        <ul>
              <li>One</li>
              <li>Two</li>
              <li>Three</li>
              <li>Four</li>
              <li>Five</li>
          </ul>
  </body>

It would be nice to have something like this:

<body>
  <ul>
    <li>One</li>
    <li>Two</li>
    <li>Three</li>
    <li>Four</li>
    <li>Five</li>
  </ul>
</body>

This HTML code is much more pretty :)

Recognize `catch` as middle-block statement

Currently, the following code is rendered properly in PHP by recognizing that else is a middle-block statement:

- if ($foo)
    A
- else
    B

try/catch should be recognized too:

- try something()
    A
- catch(Exception $e)
    B

Doctype parsing doesn't output anything

A doctype declaration of '!!!' renders to a standard html5 doctype of but anything else gives a blank output.

I've tested with '!!! 5' and '!!! Strict' resulting in the same blank output.

Looking into it and will comment if I find anything enlightening.

Simple cache

I would also like to use MtHaml in very small projects, so a basic lightweight cache implementation would be great. It should compile template files to HTML and save the HTML files to a cache directory. When a (HTML) file is requested, the cache checks if the HAML file has changed and updates the HTML file if neccessary.

Would you mind adding such a cache or would you prefer to keep the cache generic and separate to MtHaml?

Greetings,
Andy

Code documentation

Hi, this project is really interesting, and I would really enjoy to use it in some project.

But it lacks code documentation, so it is really difficult to understand the whole flow of the rendering. Can you provide some in-code documentantion to make easier to integrate it?

Thank you,
Edoardo Tenani

Error on `switch` syntax

A switch block like below

- switch ($this->params['action']):
    - case 'edit'
        = $this->Html->tag('label', 'Username')
        = $this->Html->tag('p', $this->data['User']['username'])
        - break
    - case 'add'
        = $this->Form->input('username')
        = $this->Form->input('password')
        - break
- endswitch

is being rendered to

<?php switch ($this->params['action']): { ?>
<?php case 'edit' { ?>
  <?php echo $this->Html->tag('label', 'Username'); ?>
  <?php echo $this->Html->tag('p', $this->data['User']['username']); ?>
  <?php break; ?>
<?php } ?>
<?php case 'add' { ?>
  <?php echo $this->Form->input('username'); ?>
  <?php echo $this->Form->input('password'); ?>
  <?php break; ?>
<?php } ?>
<?php } ?>
<?php endswitch; ?>

which is produce a fatal error.

If switch syntax is not supported yet, I would like to patch a fix for that. Please give me some clue on where should I start.

Using namespaces [syntax error, unexpected 'use' (T_USE)]

mervick/yii2-mthaml#1

May be necessary to parse all used namespaces and paste them before the function definition in the cache file.
Something like this
Input:

- use yii\helpers\Url
%a{:href => Url::toRoute(['shopping/ping', 'id' => (string)$item->productId, 'category' => (string)$item->primaryCategory->categoryId])} test

Output (cache file):

<?php
use yii\helpers\Url;
function __MtHamlTemplate_3d0018f2469c15708ab379082527f7c90b6b28b9be2e47a1e7d794562143a903($__variables) 
{
    extract($__variables);
?><a <?php echo MtHaml\Runtime::renderAttributes(array(array('href', (Url::toRoute(['shopping/ping', 'id' => (string)$item->productId, 'category' =>  (string)$item->primaryCategory->categoryId])))), 'html5', 'UTF-8'); ?>>test</a>
}

MultiLine ruby style attr not working if the "runtime" helpers are triggered

%script{:src => "js/paypal-button.min.js?merchant=XYZZY",
          :data-button        => "subscribe",
          :data-name          => "My product",
          :data-cancel_return => get_url("merchant/"),
          :data-notify_url    => get_url("merchant/paypal_confirm.php?id=1&plan=pm"),
          :data-a1            => "0",
          :data-p1            => $pricing['trial_period'],
          :data-t1            => "W",
          :data-amount        => "1.00",
          :data-recurrence    => "1",
          :data-period        => "M"}

Generates

<script <?php echo MtHaml\Runtime::renderAttributes(array(array('src', 'js/paypal-button.min.js?merchant=BHHDAMWL44YUE'), array((:data-button), 'subscribe'), array((:data-name), 'My product'), array((:data-cancel_return), (get_url("merchant/"))), array((:data-notify_url), (get_url("merchant/paypal_confirm.php?id=1&plan=pm"))), array((:data-a1), '0'), array((:data-p1), ($pricing['trial_period'])), array((:data-t1), 'W'), array((:data-amount), '1.00'), array((:data-recurrence), '1'), array((:data-period), 'M')), 'html5', 'UTF-8'); ?>></script>

Which causes an error Parse error: syntax error, unexpected ':'

Just using

%script{:src => "js/paypal-button.min.js?merchant=XYZZY"}

works nicely

Allow line breaking after commas

Vanilla Haml allows line breaking after commas:

%script{:type => "text/javascript",
        :src  => "javascripts/script_#{2 + 7}"}

This allows breaking long lines (sometimes with nested objects) into multiple lines.

It drastically improves readability and prevents horizontal scrolling.

The function "mthaml_attributes" does not exist

I think I got it - I understand how it works now ! It's a nice job, but I'm still not completely sure I understand ...

I get this exception : External exception (app/themes/yuuki/views/News/index.html.taml) : The function "mthaml_attributes" does not exist in "layouts/layout.html" at line 21

This is my layouts/layout.html file : https://gist.github.com/c9db16e337a254b5e046

Thanks for your fast answer ;)

Allow empty block ?

Hey - I got it all working, and it's really nice to have it so far !

I just wanted to know if you plan on supporting empty blocks.
This is my use case :

        %script
            - block script
                "";

I'd like the block just to be empty if the page didn't specified some js :). Thanks for your good work !

Parser hangs on input

The parser seems to hang when fed with the following input:

foo  |

^ previous line is just one space

Conditional attribute interpolation

Sometimes I need to handle conditional minified attributes, such as hidden and it requires interpolation outside of attribute value, because this will still be make element hidden even if attribute value is empty:

%section(id="foo" hidden="#{$hidden ? 'hidden' : ''}")

So, I've tried this and it worked, which makes me happy:

%section(id="foo" #{$hidden ? 'hidden="hidden"' : ''})

But it works only if there's another attribute in front of it, as this doesn't work:

%section(#{$hidden ? 'hidden="hidden"' : ''})

This makes me think - am I using an undocumented feature, which might be lost at some point?

Thanks

Twig: Missing endblock in empty block

- block content

renders to

{% block content %}

instead of

{% block content %}
{% endblock %}

This works however:

- block content
  Hi

renders to

{% block content %}
  Hi
{% endblock %}

Workaround:

- block content
- endblock

Disable $indent and $break inside tags where whitespace is significant

For example, here the resulting <textarea> value will have unintended whitespace around actual value:

%textarea( many long attributes here )
    = $some_long_variable_or_expression

I could write this, but it would introduce too long and wrapping source code lines:

%textarea( many long attributes here ) = $some_long_variable_or_expression

I'm not sure if there are other whitespace significant tags, but %textarea definitely shouldn't be auto-breaked and auto-indented.

I didn't find an Environment $option to disable resulting HTML breaks and indentation globally.

Won't compile on Linux

Hi!
Yesterday I'm trying to complie very simple template:

!!!
%html
  %head
    %title test
  %body

On Windows it's compiles, but on Ubuntu (XAMPP for Linux 1.8.1) I've got:

preg_match(): Compilation failed: internal error: previously-checked referenced subpattern not found at offset 358
/opt/lampp/htdocs/modules/haml/vendor/MtHaml/Parser/Buffer.php
...
74 if ($count = preg_match($pattern, $this->line, $match, PREG_OFFSET_CAPTURE)) {
...

Twig trans tag badly parsed

Hi,

There're some issues with the trans tag :

- trans with {'%x%': elem.courses.count}
    %x% courses are sharing the same %element%.

In both case I get the following message: « A message inside a trans tag must be a simple text ».

Attributes are always escaped

Even when disabling escaper and setting escape_attrs to false, dynamic attributes are always escaped in resultant php/html file. Here is my environment options:

array('enable_escaper' => false, 'escape_attrs' => false)

Haml:
%div(class="#{body_class()}")
%p test

Output:
<div <?php echo MtHaml\Runtime::renderAttributes(array(array('class', (body_class()))), 'html5', 'UTF-8'); ?>>
<p>test</p>
</div>

I would expect it to work just as disabling escaper worked, where the echo is left in directly. So the output would be closer to <div class="<?php echo body_class(); ?>">

Not HTML escaped interpolation

Is it possible to have non-escaped output from interpolation, for example within :javascript filter?

:javascript
     var data = #{$json};

Enable github's wiki

Hi,

this project is really useful and interesting and I think it'd be better with a wiki rather than a single README file, for some examples, split up some explanations, allow users to add their "project using", binding to frameworks, another target and such.

Please continue your great work :).

Support for Smarty templates

I'm working on an older project right now that relies heavily on the Smarty tempting engine. I'm curious if you can point me in the right direction to figure out how to plug Smarty into MtHaml.

Using MtHaml will let us iteratively re-write the templates, while still using Smarty, until we can switch to Twig down the line.

Thanks :)

Pass twig options?

Hello, I'm looking for a way to interact with the Twig_Environment object, to set options etc :).

Empty block gives parse error

Example code :

- if a

- else
 1

Gives :

Notice: Undefined property: Twig_TokenStream::$token in blah\twig\lib\Twig\TokenStream.php on line 61
Fatal error: Call to a member function getLine() on a non-object in blah\twig\lib\Twig\TokenStream.php on line 61

Error occurs when using grunt-haml-php

Hi, I have issue using filters with the php convertor, it says javascript filters is missing and I see it loaded by default on the Haml/Enviroment class, even I create and link it manually. do I have to some thing in the grunt file ?
Thanks for the tool.

Allow anything in -# comments

HAML allows anything in -# comments, as long as indentation is consistent.

This should compile fine:

-#
  first line
    indented line
  %p(syntax error

exeption thrown although valid haml-code

In order to get this result in HTML:

<a href="/demo/secured/hello/admin/World">Hello resource secured for <strong>admin</strong> only.</a>

usually haml should look like this:

%a{:href => "/demo/secured/hello/admin/World"}
Hello resource secured for
%strong admin
only.

instead of result Symfony throws an exeption:

CRITICAL - Twig_Error_Runtime: An exception has been thrown during the compilation of a template ("Inconsistent indentation: 6 is not a multiple of 4 in AcmeDemoBundle:Secured:hello.html.haml on line 8, column 7") in "/projects/symfony-test/src/Acme/DemoBundle/Resources/views/Secured/hello.html.haml". (uncaught exception) at /projects/symfony-test/app/cache/dev/classes.php line 6880

question:

why is it not possible to put nested haml tags inside of an anchor-tag?

`/` is not automatically escaped inside a comment line

I've noticed this difference while working with both, the ruby implementation and MtHaml. The ruby implementation of Haml supports this kind of comments

/ /end of block

and converts it to

<!-- /end of block -->

MtHaml on the other hand, does converts it to

<!-- <!-- end of block --> -->

Laravel service provider

Hello folks,

for easy integration with the Laravel framework's view system, we'd need two classes: a compiler adapter for Laravel's compiler interface, and a "service provider" to set up the necessary instances (compiler and an instance of MtHaml\Environment).

That would allow for people adding this to their Laravel 4 projects just by adding one line to their composer.json and one line to their config file.

I've got this working locally - if you're interested, I can submit a pull request.

Great package! =)

HAML 3.2 hash

I'd like to know when you plan to get onto 3.2 features :) ?

(the only real new feature is the deeply-nested hash syntax .foo{:data => {:a => "b", :c => {:d => "e", :f => "g"}}} to ... data-c-f='g').

It's really not the usefulest feature in HAML, but that'd allow you to say "HAML 3.2 compliant" (and it looks damn good for data- attributes)

whitespace removal syntax not working with php-statements

Hi,

the php-renderer does not respect the whitespace-removal-settings of parent-nodes, which will introduce unwanted whitespaces.

Here's an example:

  %a<>
    - foreach(array(1,2,3) as $ndx)
      %span<>
        =$ndx

should render to something like

<a><span>1</span><span>2</span><span>3</span></a>

It looks not that easy to fix the underlying problem, so I replaced all write with raw in my fork. Is there an easy way to fix this?

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.