adam
adam

Reputation: 2968

Correct indentation for COFFEE SCRIPT?

I am getting an error on line 371 which is the last line below - basically, I want to override the popup when you click the link REQUEST ADMIN PRIVILEGES here http://www.albumpl.us/gallery/trial/photos

extraTestButtons.append('<a href="mailto:[email protected]">Request Admin Privileges</a> |  | <a href="#">Turn SMART BROWSE (ON)</a> | ' + 
                ' | <a href="#">Purchase prints and other merchandise</a>|| <a href="http://www.albumpl.us/gallery/#{gal_code}/live">Live View</a>')


            extraTestButtons.find('a').click ->
            if $(this).text() == 'Request Admin Privileges'
              return false
            showNotYetAvailableMessage($(this).text())

Upvotes: 2

Views: 8297

Answers (2)

Brian Genisio
Brian Genisio

Reputation: 48147

By cracking open your post (using the edit feature of Stack Overflow), I saw that your second line andextraTestButtons.find line is using tabs where everything below it is using spaces.

You need to be consistent with your whitespace. Either use tabs everywhere or use spaces everywhere, but once you start mixing, bad things happen. It completely confuses the compiler because your whitespace is "significant". It would be like having a language that allows { foo() } or [ foo() ] for block specification, but you were to use { foo() ]. The compiler doesn't know what you mean.

Oftentimes, the CS compiler will barf on you because it doesn't make sense. Other times, it makes sense to the compiler but it wasn't what you wanted. Other times, the result is what you expected but not for the reason you intended.

Whatever the case, you should use an editor that will let you know of these issues. In my case, I prefer spaces always and I tell my editor to turn my tabs into spaces so that I never use a tab character anywhere in my CS code.

Everybody's preferences are different with this, but the one rule is solid: Don't mix your whitespace :)

Upvotes: 17

mu is too short
mu is too short

Reputation: 434765

You're indenting the .click binding but that isn't inside a block so the indentation doesn't make any sense. Perhaps you're looking for something like this:

extraTestButtons.append('<a href="mailto:[email protected]">Request Admin Privileges</a> |  | <a href="#">Turn SMART BROWSE (ON)</a> | ' + ' | <a href="#">Purchase prints and other merchandise</a>|| <a href="http://www.albumpl.us/gallery/#{gal_code}/live">Live View</a>')
extraTestButtons.find('a').click ->
  if $(this).text() == 'Request Admin Privileges'
    return false
  showNotYetAvailableMessage($(this).text())

Upvotes: 3

Related Questions