Skip to content

Instantly share code, notes, and snippets.

Created November 23, 2013 13:52
Show Gist options
  • Save anonymous/7614833 to your computer and use it in GitHub Desktop.
Save anonymous/7614833 to your computer and use it in GitHub Desktop.
def display_attributes(lawyer, args={})
args = {
:attributes => [:fields, :services],
:class_prefix => "ll"
}.merge(args)
attributes = args[:attributes]
# short: :fields, :services
# extended: :oab, :site, :address, :cities
html = attributes.select { |attr| attr!=:observations }.map do |attr|
name = lawyer.class.human_attribute_name attr
value = lawyer.send attr
if value.class == Address
addr = "#{value.street}"
addr += ", #{value.number}" unless value.number.blank?
addr += "/#{value.complement}" unless value.complement.blank?
addr += " - #{value.area}" unless value.area.blank?
addr += " - #{value.city.name}, #{value.city.state.short}" unless value.city.blank?
addr += " - #{value.cep}" unless value.cep.blank?
value = addr
name = "Endereço"
elsif value.class == Date
value = l(value)
elsif value.class == Array
value = value.map { |v| v.name }.join(', ')
end
if attr == :site && !value.blank?
if !value.start_with? 'http://'
link = 'http://'+value
else
link = value
end
value = "<a href=\"#{link}\">#{value}</a>"
end
if value.blank?
""
else
"<li><div class=\"#{args[:class_prefix]}-attr-label\">#{name}:</div>
<div class=\"#{args[:class_prefix]}-attr-value\">#{value}</div></li>"
end
end.join
if args[:attributes].include?(:observations) && !lawyer.observations.blank?
html += lawyer.observations.split(/\r\n|\r|\n/).select{|x|!x.blank?}.map do |obs|
sanitize "<p class=\"#{args[:class_prefix]}-observations\">#{obs}</p>", tags:%w(p br)
end.join
end
return html.html_safe
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment