Created
April 22, 2012 18:42
-
-
Save rossnelson/2466115 to your computer and use it in GitHub Desktop.
Yaml to object with Middleman
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
# get the yaml as a hash and pass it in to the new method | |
@sites = Portfolio::Site.new(data.sites) | |
# returns an array of Portfolio::Site objects | |
@sites.all |
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
module Portfolio | |
class Site | |
attr_accessor :name, :url, :content, :image, :all | |
def initialize(options={}) | |
@all = [] | |
@options = options | |
@name = options[:name] | |
@url = options[:url] | |
@content = options[:content] | |
@image = options[:image] | |
build_sites unless @options[:name] | |
end | |
def build_sites | |
@options.each do |site| | |
@all << Portfolio::Site.new(site[1]) | |
end | |
end | |
end | |
end |
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
1: | |
name: Ayurveda Manual Therapies | |
url: ayurvedamt.com | |
content: "Donec sed odio dui. Cras mattis consectetur purus sit amet fermentum. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor." | |
image: ayurveda.jpg | |
2: | |
name: Ayurveda Manual Therapies | |
url: ayurvedamt.com | |
content: "Donec sed odio dui. Cras mattis consectetur purus sit amet fermentum. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor." | |
image: ayurveda.jpg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment