Coder Social home page Coder Social logo

erb-templating's Introduction

Templating with ERB

Description

In this lab, you'll practice generating a simple site using ERB (Embedded Ruby). First, you'll create an index page by manually building up a string of html. Then, because that's a real pain in the butt, you'll use ERB to generate an html page each for about 25 movies.

Instructions

Movie Specs

Before anything, you're going to need to create a simple Movie class. Instances of this class will have some basic attributes (title, release date, director, and summary). The class itself will need to implement a method that parses through a text file and creates Movie instances based upon the data in that file. Data does not need to be persisted in a database.

#url

In the URI standard there are reserved characters and unsafe characters. The purpose of these reserved characters is to provide a set of delimiting characters that are distinguishable from other data within a URL. The unsafe characters can easily be misunderstood within your URL which can cause vulnerabilities such as HTML-injection and SQL-injection. You'll want to either remove these characters completely or better yet convert them to their encoded counterpart. For example ' turns into %27 and '&' turns into '%26'.

Check out this awesome blog post on URL Encoding.

SiteGenerator Specs

#make_index!

You'll create a class, SiteGenerator, that is reponsible for, well, generating our site. You won't be jumping directly into using ERB righ away, though. The first method you'll need to write is make_index!. This method will, based upon your Movie instances, generate an index page. (Note: You will have to pay very close attention to formatting!)

For this method, you will build up a string and manually write it to a file, _site/index.html. It's going to be difficult to match the formatting that the test expects, but you can do it!

#generate_pages!

At this point, you should probably be annoyed about that whole make_index! method. Building up a string like that is lame. So we aren't going to be doing that again. For the generate_pages! method, you'll want to create an ERB template (in lib/templates/movie.html.erb) and use it to generate a page for each Movie instance. You should use one ERB instance inside of your block.

Remember that you'll need to pass your current binding as an argument to the ERB#result method like this:

template.result(binding)

Generate the Site!

Once you've passed all of the specs, your site generator should work. Run bin/generate from your command line and then open _site/index.html to check it out.

Resources

View Templating with ERB on Learn.co and start learning to code for free.

erb-templating's People

Contributors

ahimmelstoss avatar annjohn avatar changamanda avatar deniznida avatar fislabstest avatar fs-lms-test-bot avatar kthffmn avatar loganhasson avatar sarogers avatar vinnyalfieri avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

erb-templating's Issues

Handraise Issue - StevenNunez

We should figure out a way to either force students to use instance variables for ERB templates, or allow them to use locals.

Explaining 'it's for rails' is weak. Let's think about either using another gem, wrapping Ruby's erb library, or something else.

Use of apostrophes in test

User: Gabi O'Connor

Batch: web-0715

Current Lesson: An Introduction to ERB

Location: https://learn.co/tracks/web-development-with-ruby-on-rails-2015/erb/displaying-data/an-introduction-to-erb?track_id=9683&batch_id=81

Bug Description: Hi, in the 'Introduction to ERB' lab, for the #make_index! test, the test expects the movie url to include apostrophes, even though urls should not include apostrophes. Example: the test expects the Pan's Labyrinth link to equal:

  • <a href="movies/pan's_labyrinth.html">Pan's Labyrinth
  • ...instead of
  • <a href="movies/pans_labyrinth.html">Pan's Labyrinth
  • spec is unnecessary picky

    The test in site_generator_spec.rb, on lines 46-51, is too specific. It should not include white spaces and exact matching. For instance, a student had an otherwise perfect HTML file generated and it failed the test because there was one extra blank line at the end of the file.

    Solution should be able to handle all url escapes

    Hey! So this is almost correct. In your README you say it should be able to handle all special letters that don't work in urls...yet in this solution you're just accounting for spaces and apostrophes. There are others! Can you write a more robust solution?

    Check out url encoding.

    Adding on to pr #15

    Support Multiple ERB Instances

    Test requires student put ERB instantiation outside of block for last test. Maybe figure out way to either support both initializing Multiple ERB instances or erroing out

    Broken Link

    Rasmus Ron Nielsen's Blog - Ruby's ERB Templating System: How Does It Work?

    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.