ruby monstas
play

Ruby Monstas Session 16 Agenda Apro Recap ERB CSS Exercises - PowerPoint PPT Presentation

Ruby Monstas Session 16 Agenda Apro Recap ERB CSS Exercises Recap HTML <!DOCTYPE html> < html > < head > < title >This is shown in the browser's title bar</ title > </ head > < body > < h1


  1. Ruby Monstas Session 16

  2. Agenda Apéro Recap ERB CSS Exercises

  3. Recap

  4. HTML <!DOCTYPE html> < html > < head > < title >This is shown in the browser's title bar</ title > </ head > < body > < h1 >A really big title element</ h1 > < p >A paragraph of text</ p > These are some of my favourite things (in no particular order): < ul > < li >RubyMonstas</ li > < li >My little Pony: Friendship is Magic</ li > < li >sleeping in</ li > </ ul > A typical RubyMonstas session is structured thusly: < ol > < li >Recap of previous session</ li > < li >Topic of current session</ li > < li >Exercises</ li > </ ol > < h2 >A subtitle</ h2 > < strong >Strong</ strong > and < em >emphasized</ em > text styles are also supported. </ body > </ html >

  5. ERB Embedded Ruby

  6. The world without ERB class HtmlExporter def initialize (todos) @todos = todos end def export (file_name) File .open(file_name, 'wb') do |html| begin_html = " <!DOCTYPE html> <html> <head> <title>Todo List Export</title> </head> <body> <h1>Here's all the todos!</h1> <ul> " html << begin_html @todos.each do |todo| html << "<li>#{todo.title} (#{todo.completed?})</li> \n " end end_html = " </ul> </body> </html> " html << end_html end puts "Written HTML export to file #{file_name}." end end

  7. Enter: ERB! todos.html.erb erb_exporter.rb require 'erb' <!DOCTYPE html> <html> class ErbExporter <head> <title>Todo List Export</title> def initialize (todos) </head> @todos = todos end <body> <h1>Here's all the todos!</h1> def export (file_name) File .open(file_name, 'wb') do |output_file| <ul> template_source = File .new('todos.html.erb').read <% @todos.each do |todo| %> erb = ERB .new(template_source) <li> rendered_html = erb.result(binding) <%= todo.title %> (<%= todo.completed? %>) output_file.write(rendered_html) </li> end <% end %> </ul> puts "Written HTML export to file #{file_name}." </body> end </html> end

  8. CSS Cascading Style Sheets

  9. CSS HTML: Web site structure CSS: Web site appearance (JavaScript: Web site behaviour)

  10. CSS export.html <!DOCTYPE html> <html> <head> <title>Todo List Export</title> </head> <body> <h1>Here's all the todos!</h1> <ul> <li> Implemented storage class (true) </li> <li> Implemented Todo class (false) </li> <li> Implemented feature to add a new todo (false) </li> <li> Implemented feature to mark a todo as completed (false) </li> <li> Implemented feature to unmark a todo as completed (false) </li> </ul> </body> </html>

  11. Simple CSS Rules export.html export.css <!DOCTYPE html> <html> body { <head> <title>Todo List Export</title> font-family : "Arial"; <link rel="stylesheet" type="text/css" href="export.css" /> </head> } <body> <h1>Here's all the todos!</h1> h1 { <ul> font-variant : small-caps ; <li> color : grey; Implemented storage class (true) </li> } <li> Implemented Todo class (false) ul { </li> list-style-type : circle ; <li> Implemented feature to add a new todo (false) } </li> <li> li { Implemented feature to mark a todo as completed (false) </li> color : CadetBlue; <li> } Implemented feature to unmark a todo as completed (false) </li> </ul> </body> </html>

  12. Time to practice

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend