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

ruby monstas
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Ruby Monstas

Session 16

slide-2
SLIDE 2

Agenda

Apéro Recap ERB CSS Exercises

slide-3
SLIDE 3

Recap

slide-4
SLIDE 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>
slide-5
SLIDE 5

Embedded Ruby

ERB

slide-6
SLIDE 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
slide-7
SLIDE 7

Enter: ERB!

<!DOCTYPE html> <html> <head> <title>Todo List Export</title> </head> <body> <h1>Here's all the todos!</h1> <ul> <% @todos.each do |todo| %> <li> <%= todo.title %> (<%= todo.completed? %>) </li> <% end %> </ul> </body> </html> require 'erb' class ErbExporter def initialize(todos) @todos = todos end def export(file_name) File.open(file_name, 'wb') do |output_file| template_source = File.new('todos.html.erb').read erb = ERB.new(template_source) rendered_html = erb.result(binding)

  • utput_file.write(rendered_html)

end puts "Written HTML export to file #{file_name}." end end

todos.html.erb erb_exporter.rb

slide-8
SLIDE 8

CSS

Cascading Style Sheets

slide-9
SLIDE 9

CSS

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

slide-10
SLIDE 10

CSS

<!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>

export.html

slide-11
SLIDE 11

Simple CSS Rules

body { font-family: "Arial"; } h1 { font-variant: small-caps; color: grey; } ul { list-style-type: circle; } li { color: CadetBlue; }

<!DOCTYPE html> <html> <head> <title>Todo List Export</title> <link rel="stylesheet" type="text/css" href="export.css" /> </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>

export.html export.css

slide-12
SLIDE 12

Time to practice