Cannot prepend and append to a block all at once #733

Closed
iamdustan opened this Issue Aug 7, 2012 · 10 comments

Comments

Projects
None yet
6 participants

In jade 0.26.0 attempting to do the following will append all content into the block, instead of doing the the expected prepending and appending, respectively.

prepend scripts
  script(src='/js/plupload/js/plupload.full.js')

append scripts
  script(src='/js/page.js')
Contributor

tj commented Aug 7, 2012

hmm ill take a look

Contributor

tj commented Aug 7, 2012

works for me.

index.jade:

extend layout

append head
  script(src='jquery.js')

prepend head
  script(src='foo.js')

layout.jade:

html
  head
    script(src='/app.js')
    block head
  body
    block content

Try this...

index.jade:

extend layout

append head
  script(src='jquery.js')

prepend head
  script(src='foo.js')

layout.jade:

html
  head
    block head
      script(src='/app.js')
  body
    block content

Would expect the head to be

html
  head
    script(src='foo.js')
    script(src='/app.js')
    script(src='jquery.js')

but I get

head
    script(src='foo.js')
    script(src='jquery.js')
    script(src='/app.js')

It appears as though the append/prepend blocks get combined and follow the behavior of the last stated addition. (e.g. if append is last, both blocks get appended to the targeted block, if prepend is last, both blocks get prepended to the targeted blcok)

Contributor

tj commented Aug 7, 2012

ah I see, yeah I didn't notice that but you're right my case has that as well. I think there was a weird implemtnation detail with this, I'll have a look in a bit

Sweet. I should have some time to look into after next week, but until that I’m living in the belly of a beast.

Experiencing this issue as well. Have you guys made any progress?

mcauser commented Jan 14, 2013

Seems to still be an issue in 0.28.1
I can successfully prepend or append a single block, but not both, and not more than once.

@ghost
Contributor

ghost commented Jan 21, 2013

I think this is because of this.blocks in parse* methods is Object, not Array, thus we have not index-safe storage for block objects.

@ghost
Contributor

ghost commented Jan 21, 2013

Just fixed this. Hope this is not so hacky.

@ghost ghost pushed a commit to SE7ENSKY/jade that referenced this issue Jan 21, 2013

Se7enSky studio added more tests, more accurate code [closes #733] 3f01247

@ghost ghost pushed a commit to SE7ENSKY/jade that referenced this issue Jan 21, 2013

Se7enSky studio minor fix [closes #733] 0b0db03

arpan88 commented Mar 13, 2015

Does this work inside body ? I tried to write the following

layout.jade

doctype html
html(lang=en)
  head
    block head
        title= title
        link(rel="stylesheet", href="/stylesheets/libs/bootstrap/bootstrap.min.css")
        link(rel="stylesheet", href="/stylesheets/fonts.min.css")
        link(rel="stylesheet", href="/stylesheets/style.min.css")
  body
    block content

    script(src="javascripts/core/jquery-2.1.3.min.js",type="text/javascript")
    script(src="javascripts/libs/angular/angular.min.js",type="text/javascript")
    script(src="javascripts/libs/bootstrap/bootstrap.min.js",type="text/javascript")

and index.jade

extends layout

prepend content
  h1= title

  | Welcome to Node js application page

append content

  script(type="text/javascript" src="abcd.js")

but all I got is following html

<!DOCTYPE html>
<html>
   <head>
      <title>Welcome to first express web app</title>
      <link rel="stylesheet" href="/stylesheets/libs/bootstrap/bootstrap.min.css">
      <link rel="stylesheet" href="/stylesheets/fonts.min.css">
      <link rel="stylesheet" href="/stylesheets/style.min.css">
   </head>
   <body>
      <h1>Welcome to first express web app</h1>
      Welcome to Node js application page
      <script type="text/javascript" src="abcd.js"></script>
      <script src="javascripts/core/jquery-2.1.3.min.js" type="text/javascript"></script>
      <script src="javascripts/libs/angular/angular.min.js" type="text/javascript"></script>
      <script src="javascripts/libs/bootstrap/bootstrap.min.js" type="text/javascript"></script>
   </body>
</html>

Where the new file is getting added at the first. Please tell me what I am doing wrong ? I am using jade 1.9.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment