Skip to content

Instantly share code, notes, and snippets.

@nov
Created June 8, 2009 04:43
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 nov/125623 to your computer and use it in GitHub Desktop.
Save nov/125623 to your computer and use it in GitHub Desktop.
# environment.rb
VERSION_DEFAULT = Version1
# user.rb
class User
include Builder::UserMarkup
end
# builder/base.rb
module Builder
class Base
def to_markup(markup, options = {})
case options[:version]
when 'v3'
Version3.to_markup(self, markup, options)
when 'v2'
Version2.to_markup(self, markup, options)
when 'v1'
Version1.to_markup(self, markup, options)
else # Default
DefaultVersion.to_markup(self, markup, options)
end
end
def to_xml
self.to_markup(Builder::XmlBuilder.new, options)
end
def to_json
self.to_markup(Builder::JsonBuilder.new, options)
end
end
end
# builder/user_markup.rb
module Builder
class UserMarkup < Base
class Version1
def to_markup(user, markup, options = {})
end
end
class Version2
def to_markup(user, markup, options = {})
end
end
class Version3
def to_markup(user, markup, options = {})
end
end
class DefaultVersion < VERSION_DEFAULT
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment