asset pipeline which Section A8 discusses further automates this compilation so

Asset pipeline which section a8 discusses further

This preview shows page 248 - 250 out of 517 pages.

asset pipeline, which Section A.8 discusses further, automates this compilation so you don’t need to manually generate the .js files or include them in your source tree. Since CoffeeScript compiles to JavaScript, it can’t do anything that JavaScript doesn’t already do, but it provides more concise syntactic notation for many common constructs. As an example, Figure 6.30 shows the much less noisy CoffeeScript version of the Jasmine spec in Figure 6.21 . Unfortunately, after a few years “in the wild,” CoffeeScript’s design has been criticized for fundamental design problems that limit its usefulness in large projects. Two major objections are its scoping of all outer variables as global and a sensitivity to whitespace that results in ambiguous interpretations of source code , violating the “Principle of Least Surprise” that is one of the cornerstones of Ruby’s design. Time will tell whether CoffeeScript will largely displace JavaScript or remain a “niche language” used only in smaller projects. 1 describe ’MoviePopup’, -> 2 describe ’setup’, -> 3 it ’adds popup Div to main page’, -> expect $(’#movieInfo’).toExist 4 it ’hides the popup Div’, -> expect $(’#movieInfo’).toBeHidden 5 describe ’AJAX call to server’, -> 6 beforeEach -> loadFixtures(’movie_row.html’) 7 it ’calls correct URL’, -> 8 spyOn $, ’ajax’ 9 $(’#movies a’).trigger ’click’ 10 expect($.ajax.mostRecentCall.args[0][’url’]).toEqual ’/movies/1’ 11 describe ’when successful’, -> 12 beforeEach ->
Image of page 248
13 @htmlResponse = readFixtures ’movie_info.html’ 14 spyOn($, ’ajax’).andCallFake (ajaxArgs) -> 15 ajaxArgs.success(htmlResponse, ’200’) 16 $(’#movies a’).trigger ’click’ 17 it ’makes #movieInfo visible’, -> expect $(’#movieInfo’).toBeVisible 18 it ’places movie title in #movieInfo’, -> 19 expect($(’#movieInfo’).text).toContain ’Casablanca’ Figure 6.30: The CoffeeScript version of Figure 6.21 . Among other differences, CoffeeScript provides the Haskell -like concise syntax -> for functions, uses Haml-like indentation rather than braces to indicate structure, and allows Ruby-like omission of most parentheses as well as borrowing the @ instance-variable notation to refer to properties of this . Some find the resulting code easier to read, as it has 1⁄3 fewer lines and a lot less punctuation than the plain JavaScript version. Tools for SPA developers creating JSON-centric apps are improving as well. For example, Yahoo’s open-source Mojito framework allows the same JavaScript code to render HTML from JSON on either the client or a Node-based server. However, there is a potential huge downside to apps taking this route: their content will be neither indexable nor searchable by search engines, without which the Web loses a great deal of its utility. There are technological solutions to this problem, but at the moment there is little discussion about them.
Image of page 249
Image of page 250

You've reached the end of your free preview.

Want to read all 517 pages?

  • Spring '19
  • Dr.Marcos

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors