Skip to content

Instantly share code, notes, and snippets.

@samwgoldman
Created May 23, 2012 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samwgoldman/2776582 to your computer and use it in GitHub Desktop.
Save samwgoldman/2776582 to your computer and use it in GitHub Desktop.
Using smartlogic/html_builder
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