From 3f86f6c9e288f1b58591a278038a9043c1ad156f Mon Sep 17 00:00:00 2001 From: Jasper Moelker Date: Sun, 3 Apr 2016 15:45:56 +0200 Subject: [PATCH] feat(media/embed): preset or custom ratio with nested item or iframe (incl. variations) macros + demo + docs --- README.md | 1 + src/media/embed/README.md | 70 +++++++++++++++++++++++++++++++++ src/media/embed/embed.demo.html | 47 ++++++++++++++++++++++ src/media/embed/embed.html | 31 +++++++++++++++ 4 files changed, 149 insertions(+) create mode 100644 src/media/embed/README.md create mode 100644 src/media/embed/embed.demo.html create mode 100644 src/media/embed/embed.html diff --git a/README.md b/README.md index 018b0a4..382b1b8 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ You can [view the demos of all available modules](https://jbmoelker.github.io/nu * **media** * [carousel](https://jbmoelker.github.io/nunjucks-bootstrap/#media/carousel/carousel.demo.html) + * [embed](https://jbmoelker.github.io/nunjucks-bootstrap/#media/embed/embed.demo.html) * [figure](https://jbmoelker.github.io/nunjucks-bootstrap/#media/figure/figure.demo.html) * [image](https://jbmoelker.github.io/nunjucks-bootstrap/#media/image/image.demo.html) * **nav** diff --git a/src/media/embed/README.md b/src/media/embed/README.md new file mode 100644 index 0000000..ca30454 --- /dev/null +++ b/src/media/embed/README.md @@ -0,0 +1,70 @@ +# Embed + +## Functionality + +> Allow browsers to determine video or slideshow dimensions based on the width of their containing block by creating an intrinsic ratio that will properly scale on any device. +> +> -- [Bootstrap > Responsive embeds](http://v4-alpha.getbootstrap.com/components/utilities/#responsive-embeds) + +## Usage + +Import the macros: + +```html +{% import "media/embed/embed.html" as embed %} +``` + +Wrap content in a fixed ratio (preset or custom) element: + +```html +{% call embed.ratio16by9() %} +
content
+{% endcall %} +``` + +Optionally use `item()` or `iframe()` helper to create content. + +### `.ratio21by9()`, `.ratio16by9()`, `.ratio4by3()`, `.ratio1by1()` + +Creates an element with a fixed aspect ratio. + +Use as [`call` block](http://mozilla.github.io/nunjucks/templating.html#call). +Content inside block is displayed inside the element. + +### `.ratio()` + +Creates an element with a custom aspect ratio. + +Use as [`call` block](http://mozilla.github.io/nunjucks/templating.html#call). +Content inside block is displayed inside the element. + +index | parameter | type | description +--- | --- | --- | --- +0 | ratio | number | Aspect ratio (width:height) as number (between 0 and 1). E.g. `.4` or `2/1`. + +### `.sizes()` + +Creates an element with a custom aspect ratio based on the given width and height. + +Use as [`call` block](http://mozilla.github.io/nunjucks/templating.html#call). +Content inside block is displayed inside the element. + +index | parameter | type | description +--- | --- | --- | --- +0 | width | number | Relative to height. Used to calculate aspect ratio. E.g. `width = 640`. +1 | height | number | Relative to width. Used to calculate aspect ratio. E.g. `height = 400`. + +### `.item()` + +Creates an item which takes the full with and height of the parent element. + +Use as [`call` block](http://mozilla.github.io/nunjucks/templating.html#call). +Content inside block is displayed inside the item. + +### `.iframe()` + +Creates an iframe which takes the full with and height of the parent element. + +index | parameter | type | description +--- | --- | --- | --- +0 | src | string | Url of the source. \ No newline at end of file diff --git a/src/media/embed/embed.demo.html b/src/media/embed/embed.demo.html new file mode 100644 index 0000000..7e69fe7 --- /dev/null +++ b/src/media/embed/embed.demo.html @@ -0,0 +1,47 @@ +{% extends "demo/module/module.html" %} +{% import "./embed.html" as embed %} + +{% block content %} + + {% call embed.ratio21by9() %} +
content
+ {% endcall %} +
+ + + {% call embed.ratio16by9() %} +
content
+ {% endcall %} +
+ + + {% call embed.ratio4by3() %} +
content
+ {% endcall %} +
+ + + {% call embed.ratio1by1() %} +
content
+ {% endcall %} +
+ + + {% call embed.ratio(2/1) %} +
content
+ {% endcall %} +
+ + + {% call embed.sizes(2, 1) %} +
content
+ {% endcall %} +
+ + + {% call embed.ratio16by9() %} + {{ embed.iframe('https://www.youtube.com/embed/zpOULjyy-n8?rel=0') }} + {% endcall %} + + +{% endblock %} \ No newline at end of file diff --git a/src/media/embed/embed.html b/src/media/embed/embed.html new file mode 100644 index 0000000..d1cc88c --- /dev/null +++ b/src/media/embed/embed.html @@ -0,0 +1,31 @@ +{%- macro ratio21by9() -%} +
{{ caller() }}
+{%- endmacro -%} + +{%- macro ratio16by9() -%} +
{{ caller() }}
+{%- endmacro -%} + +{%- macro ratio4by3() -%} +
{{ caller() }}
+{%- endmacro -%} + +{%- macro ratio1by1() -%} +
{{ caller() }}
+{%- endmacro -%} + +{%- macro ratio(ratio) -%} +
{{ caller() }}
+{%- endmacro -%} + +{%- macro sizes(width, height) -%} + {{ ratio(width/height) }} +{%- endmacro -%} + +{%- macro item() -%} +
{{ caller() }}
+{%- endmacro -%} + +{%- macro iframe(src) -%} + +{%- endmacro -%} \ No newline at end of file