mirror of
https://github.com/servo/servo.git
synced 2025-08-02 20:20:14 +01:00
Use more named string interpolation.
This commit is contained in:
parent
77b3e911c1
commit
44822c364c
1 changed files with 13 additions and 10 deletions
|
@ -4011,33 +4011,36 @@ pub enum %s {
|
||||||
|
|
||||||
pairs = ",\n ".join(['("%s", super::%s::%s)' % (val, ident, getEnumValueName(val)) for val in enum.values()])
|
pairs = ",\n ".join(['("%s", super::%s::%s)' % (val, ident, getEnumValueName(val)) for val in enum.values()])
|
||||||
|
|
||||||
inner = """\
|
inner = string.Template("""\
|
||||||
use dom::bindings::conversions::ToJSValConvertible;
|
use dom::bindings::conversions::ToJSValConvertible;
|
||||||
use js::jsapi::{JSContext, MutableHandleValue};
|
use js::jsapi::{JSContext, MutableHandleValue};
|
||||||
use js::jsval::JSVal;
|
use js::jsval::JSVal;
|
||||||
|
|
||||||
pub const pairs: &'static [(&'static str, super::%s)] = &[
|
pub const pairs: &'static [(&'static str, super::${ident})] = &[
|
||||||
%s,
|
${pairs},
|
||||||
];
|
];
|
||||||
|
|
||||||
impl super::%s {
|
impl super::${ident} {
|
||||||
pub fn as_str(&self) -> &'static str {
|
pub fn as_str(&self) -> &'static str {
|
||||||
pairs[*self as usize].0
|
pairs[*self as usize].0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for super::%s {
|
impl Default for super::${ident} {
|
||||||
fn default() -> super::%s {
|
fn default() -> super::${ident} {
|
||||||
pairs[0].1
|
pairs[0].1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToJSValConvertible for super::%s {
|
impl ToJSValConvertible for super::${ident} {
|
||||||
unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
|
unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
|
||||||
pairs[*self as usize].0.to_jsval(cx, rval);
|
pairs[*self as usize].0.to_jsval(cx, rval);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
""" % (ident, pairs, ident, ident, ident, ident)
|
""").substitute({
|
||||||
|
'ident': ident,
|
||||||
|
'pairs': pairs
|
||||||
|
})
|
||||||
self.cgRoot = CGList([
|
self.cgRoot = CGList([
|
||||||
CGGeneric(decl),
|
CGGeneric(decl),
|
||||||
CGNamespace.build([ident + "Values"],
|
CGNamespace.build([ident + "Values"],
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue