Created
May 23, 2012 17:38
-
-
Save samwgoldman/2776582 to your computer and use it in GitHub Desktop.
Using smartlogic/html_builder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "html" | |
require "html/list" | |
require "html/map" | |
module HTML | |
class Article < Struct.new(:article) | |
def to_html | |
HTML.build(article) do |article| | |
tag(:article, tag(:h2, article.title) + map(:section, article.sections), id: article.id) | |
end | |
end | |
end | |
class Section < Struct.new(:section) | |
def to_html | |
HTML.build(section) do |section| | |
tag(:section, tag(:h3, section.title) + text(section.content)) | |
end | |
end | |
end | |
end | |
Article = Struct.new(:id, :title, :sections) | |
Section = Struct.new(:title, :content) | |
sections = { | |
"services" => [ | |
Section.new("Web Development", "We're a team of experienced developers..."), | |
Section.new("Mobile Development", "Leverage iOS, Android, and mobile web (HTML5)..."), | |
Section.new("Our Process", "Work directly with our team to manage how and when features get built...") | |
], | |
"process" => [ | |
Section.new("Scoping", "When working with SmartLogic, the client is in the driver's seat..."), | |
Section.new("Design and Development", "Whether we're your sole development resource or..."), | |
Section.new("Project Completion", "We take great pride in the applications we help create...") | |
] | |
} | |
articles = [ | |
Article.new("service", "Web and Mobile Application Development", sections["services"]), | |
Article.new("process", "Process", sections["process"]) | |
] | |
puts HTML.build(articles) { |articles| map(:article, articles) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment