It comes from git or the metadata
TODO get more things from github by using the email as a key
"https://api.github.com/search/users?q={email}+in:email"
nitc :: Person :: defaultinit
nitc :: json_model $ Person :: core_serialize_to
Actual serialization ofself
to serializer
nitc :: json_model $ Person :: from_deserializer
Create an instance of this class from thedeserializer
serialization :: Serializable :: accept_inspect_serializer_core
serialization :: Serializable :: accept_json_serializer
Refinable service to customize the serialization of this class to JSONserialization :: Serializable :: accept_msgpack_attribute_counter
Hook to customize the behavior of theAttributeCounter
serialization :: Serializable :: accept_msgpack_serializer
Hook to customize the serialization of this class to MessagePackserialization :: Serializable :: add_to_bundle
Called by[]=
to dynamically choose the appropriate method according
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
serialization :: Serializable :: core_serialize_to
Actual serialization ofself
to serializer
core :: Object :: defaultinit
nitc :: Person :: defaultinit
serialization :: Serializable :: from_deserializer
Create an instance of this class from thedeserializer
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
serialization :: Serializable :: msgpack_extra_array_items
Hook to request a larger than usual metadata arraycore :: Object :: native_class_name
The class name of the object in CString format.core :: Object :: output_class_name
Display class name on stdout (debug only).serialization :: Serializable :: serialize_msgpack
Serializeself
to MessagePack bytes
serialization :: Serializable :: serialize_to
Serializeself
to serializer
serialization :: Serializable :: serialize_to_json
Serializeself
to JSON
serialization :: Serializable :: serialize_to_or_delay
Accept references or force direct serialization (usingserialize_to
)
serialization :: Serializable :: to_pretty_json
Serializeself
to plain pretty JSON
Serializer::serialize
# A contributor/author/etc.
#
# It comes from git or the metadata
#
# TODO get more things from github by using the email as a key
# "https://api.github.com/search/users?q={email}+in:email"
class Person
# The name. Eg "John Doe"
var name: String is writable
# The email, Eg "john.doe@example.com"
var email: nullable String is writable
# Some homepage. Eg "http://example.com/~jdoe"
var page: nullable String is writable
# Gravatar id
var gravatar: nullable String is lazy do
var email = self.email
if email == null then return null
return email.md5.to_lower
end
# The standard representation of a person.
#
# ~~~
# var jd = new Person("John Doe", "john.doe@example.com", "http://example.com/~jdoe")
# assert jd.to_s == "John Doe <john.doe@example.com> (http://example.com/~jdoe)"
# ~~~
#
# It can be used as the input of `parse`.
#
# ~~~
# var jd2 = new Person.parse(jd.to_s)
# assert jd2.to_s == jd.to_s
# ~~~
redef fun to_s
do
var res = name
var email = self.email
if email != null then res += " <{email}>"
var page = self.page
if page != null then res += " ({page})"
return res
end
# Crete a new person from its standard textual representation.
#
# ~~~
# var jd = new Person.parse("John Doe <john.doe@example.com> (http://example.com/~jdoe)")
# assert jd.name == "John Doe"
# assert jd.email == "john.doe@example.com"
# assert jd.page == "http://example.com/~jdoe"
# ~~~
#
# Emails and page are optional.
#
# ~~~
# var jd2 = new Person.parse("John Doe")
# assert jd2.name == "John Doe"
# assert jd2.email == null
# assert jd2.page == null
# ~~~
init parse(person: String)
do
var name = person
var email = null
var page = null
# Regular expressions are broken, need to investigate.
# So split manually.
#
#var re = "([^<(]*?)(<([^>]*?)>)?(\\((.*)\\))?".to_re
#var m = (person+" ").search(re)
#print "{person}: `{m or else "?"}` `{m[1] or else "?"}` `{m[3] or else "?"}` `{m[5] or else "?"}`"
do
var sp1 = person.split_once_on("<")
if sp1.length < 2 then
break
end
var sp2 = sp1.last.split_once_on(">")
if sp2.length < 2 then
break
end
name = sp1.first.trim
email = sp2.first.trim
var sp3 = sp2.last.split_once_on("(")
if sp3.length < 2 then
break
end
var sp4 = sp3.last.split_once_on(")")
if sp4.length < 2 then
break
end
page = sp4.first.trim
end
init(name, email, page)
end
end
src/catalog/catalog.nit:145,1--243,3
redef class Person
# HTML uniq id
fun html_id: String do return name.to_cmangle
# HTML default URL
#
# Should be redefined in clients.
fun html_url: String do return "person_{html_id}.html"
# Link to this person `html_url`
fun html_link: Link do return new Link(html_url, name)
# Render `self` as HTML
fun to_html: String do
var tpl = new Template
tpl.addn "<span>"
var gravatar = self.gravatar
if gravatar != null then
tpl.addn "<img class='avatar' src='https://secure.gravatar.com/avatar/{gravatar}?size=14&default=retro' />"
end
tpl.addn html_link
tpl.addn "</span>"
return tpl.write_to_string
end
end
src/doc/templates/html_model.nit:356,1--381,3
redef class Person
redef fun to_html do
var res = ""
var e = name.html_escape
var page = self.page
if page != null then
res += "<a href=\"{page.html_escape}\">"
end
var gravatar = self.gravatar
if gravatar != null then
res += "<img src=\"https://secure.gravatar.com/avatar/{gravatar}?size=20&default=retro\"> "
end
res += e
if page != null then res += "</a>"
return res
end
end
src/nitcatalog.nit:535,1--551,3
redef class Person
serialize
redef fun core_serialize_to(v) do
super
v.serialize_attribute("name", name)
v.serialize_attribute("email", email)
v.serialize_attribute("gravatar", gravatar)
end
end
src/doc/templates/json_model.nit:438,1--447,3