Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement raw #35

Open
panosru opened this issue Jul 15, 2012 · 6 comments
Open

implement raw #35

panosru opened this issue Jul 15, 2012 · 6 comments

Comments

@panosru
Copy link

panosru commented Jul 15, 2012

Hi, as I see {% raw %} is not implemented, I tried to use angular js which uses {{ }} as well so I realized that raw is not there :/

Any workaround for that?

@ceymard
Copy link
Member

ceymard commented Jul 15, 2012

Nope, have to implement it.

@panosru
Copy link
Author

panosru commented Jul 15, 2012

if you guide me a little bit because I don't feel quite comfortable with Coco I could implement it :)

@panosru
Copy link
Author

panosru commented Jul 15, 2012

@ceymard from what I saw, the @child_node.compile method need to be modified in order to return raw string and not compiled but I can't find the compile method.

I was thinking for something like that:

/**
 * Raw Node
 */
class NodeRaw extends NodeTagContainer
    @tag = \raw
    @until = \endraw

    (specs) ->
        super ...

    compile : function (opts, ctx)
        return @child_code opts, ctx

Where the true in third parameter will indicate that we need raw output.

@panosru
Copy link
Author

panosru commented Jul 16, 2012

I really struggled a lot by trying to make raw node work, from what I understood the template engine compiles the template and breaks it into nodes, once this step happens then nodes take place but in case you want to have a raw node you have to change the compilation process, am I right? Is there any other easier way to have raw node?

Thanks

@panosru
Copy link
Author

panosru commented Jul 19, 2012

After lots of hours I gave up on this...

I ended up altering advance method from lexer.co file:

    advance: function (to_position)
        res = @input.slice @position, to_position
        @position = to_position

        _res = res.trim()

        if NodeRaw.tag is _res
            @_raw_enable++
        if NodeRaw.until is _res
            @_raw_str = @_raw_str.substr(0, @_raw_str.length - 2)
            @_raw_enable = -5

        if 3 < @_raw_enable
            @_raw_str += res
        else if 1 <= @_raw_enable or @_raw_enable < 0
            @_raw_enable++

        if 4 > @_raw_enable and @_raw_enable >= -4
            if 0 < @_raw_str.length
                res = @_raw_str
                @_raw_str = ''

            switch @_raw_enable
                case -3
                    res = '{%'
                case -2
                    res = " #{NodeRaw.until} "
                case -1
                    res = "%}"
            return res
        else
            return ''

So this tpl

=====================

{% raw %}
  {% for name in ['foo', 'bar'] -%}
    Hello {{name}}!
  {% endfor %}
{% endraw %}

{% if true %}Yeah!!!{% endif %}

result into this:

=====================

  {% for name in ['foo', 'bar'] -%}
    Hello {{name}}!
  {% endfor %}
Yeah!!!

but this:

=====================

{% raw %}{% for name in ['foo', 'bar'] -%}Hello {{name}}!{% endfor %}{% endraw %}

{% if true %}Yeah!!!{% endif %}

result into this:

=====================

 for name in ['foo', 'bar'] -%}Hello {{name}}!{% endfor %}Yeah!!!

:(

@ceymard
Copy link
Member

ceymard commented Jul 19, 2012

Well, no, this is exactly it.

*

Christophe Eymard
(+34) 63 389 98 18
(+34) 93 390 61 47
[email protected]
http://www.ravelsoft.com/
http://www.ravelsoft.com

Aviso Legal: El contenido de este mensaje de correo electrónico, incluidos
los ficheros adjuntos, es confidencial y está protegido por el artículo
18.3 de la Constitución Española, que garantiza el secreto de las
comunicaciones. Si usted recibe este mensaje por error, por favor póngase
en contacto con el remitente para informarle de este hecho, y no difunda su
contenido ni haga copias.

Legal Notice: The information transmitted is intended only for the person
to whom or entity to which it is addressed and may contain confidential
and/or privileged material. Any review, retransmission, dissemination or
other use of, or taking of any action in reliance upon, this information by
persons or entities other than the intended recipient is prohibited. If you
received this in error, please contact the sender by e-mail reply or by
phone and delete all copies of the material.

Mentions Légales: Ce message et toutes les pièces jointes sont
confidentiels ou même couverts par le secret professionnel et transmis à
l'intention exclusive de leurs destinataires. Toute modification, édition,
utilisation ou diffusion non autorisée est interdite. Si vous avez reçu ce
Message par erreur, merci de nous en avertir immédiatement soit en
répondant à ce courrier, soit par téléphone. RavelSoft décline toute
responsabilité au titre de ce Message s'il a été altéré, déformé, falsifié
ou encore édité ou diffusé sans autorisation.

On Mon, Jul 16, 2012 at 4:09 PM, Panagiotis Kosmidis <
[email protected]

wrote:

I really struggled a lot by trying to make raw node work, from what I
understood the template engine compiles the template and breaks it into
nodes, once this step happens then nodes take place but in case you want to
have a raw node you have to change the compilation process, am I right? Is
there any other easier way to have raw node?

Thanks


Reply to this email directly or view it on GitHub:
#35 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants