Skip to content

Commit

Permalink
Add place-items shorthand property (it fails unit-test)
Browse files Browse the repository at this point in the history
  • Loading branch information
tamamu committed Apr 9, 2017
1 parent b6cbd31 commit bfa4082
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
32 changes: 32 additions & 0 deletions components/style/properties/shorthand/position.mako.rs
Expand Up @@ -210,3 +210,35 @@
}
}
</%helpers:shorthand>

<%helpers:shorthand name="place-items" sub_properties="align-items justify-items"
spec="https://drafts.csswg.org/css-align/#place-items-property"
products="gecko">
use values::specified::align::{AlignItems, JustifyItems};
use parser::Parse;

impl From<AlignItems> for JustifyItems {
fn from(align: AlignItems) -> JustifyItems {
JustifyItems(align.0)
}
}

pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result<Longhands, ()> {
let align = AlignItems::parse(context, input)?;
let justify = input.try(|input| JustifyItems::parse(context, input))
.unwrap_or(JustifyItems::from(align));

Ok(Longhands {
align_items: align,
justify_items: justify,
})
}

impl<'a> ToCss for LonghandsToSerialize<'a> {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
self.align_items.to_css(dest)?;
dest.write_str(" ")?;
self.justify_items.to_css(dest)
}
}
</%helpers:shorthand>
17 changes: 17 additions & 0 deletions tests/unit/style/properties/serialization.rs
Expand Up @@ -1280,4 +1280,21 @@ mod shorthand_serialization {
let serialization = shorthand_properties_to_string(properties);
assert_eq!(serialization, "place-self: auto baseline;");
}

#[test]
fn place_items_serialize_all_available_properties() {
use style::properties::longhands::align_items::SpecifiedValue as AlignItems;
use style::properties::longhands::justify_items::SpecifiedValue as JustifyItems;

let mut properties = Vec::new();

let align = AlignItems::flex_start;
let justify = JustifyItems::baseline;

properties.push(PropertyDeclaration::AlignItems(align));
properties.push(PropertyDeclaration::JustifyItems(justify));

let serialization = shorthand_properties_to_string(properties);
assert_eq!(serialization, "place-items: flex-start baseline;");
}
}

0 comments on commit bfa4082

Please sign in to comment.