Олег Мохов
templates/ └── index.html └── index.css
a {
color: red;
}
html,
body
{
margin: 0;
padding: 0;
width: 100%;
font-family: Arial, sans-serif;
}
header
{
position: relative;
border: 3px solid #000;
width: 952px;
height: 551px;
margin: 18px auto 0;
}
/* далее ещё 400 строчек кода */
/* сброс умолчаний */
/* общие стили */
/* шапка */
/* основная часть */
/* футер */
/* страница печати */
/* мобильная версия */
/* какие-то правки */
/* новая страница */
/* ещё какие-то правки */
/* стили новой шапки */
button/ └── button.html └── button.css └── button.ie.css └── button.js └── _hovered/ └── button_hovered.css └── button_hovered.png └── __icon/ └── button__icon.css └── _color/ └── button__icon_color_blue.css └── button__icon_color_red.css
common/ └── header/ └── header.css └── header.js
desktop/ └── header/ └── header.css
touch/ └── header/ └── header.css └── header.js
@import (common/header/header.css);
@import (desktop/header/header.css);
header.desktop.css
@import (common/header/header.css);
@import (touch/header/header.css);
header.touch.css
({
block: 'page'
})
index.bemjson.js
({
mustDeps: [
{ block: 'header' }
],
shouldDeps: [
{ block: 'button' },
{ block: 'icon', mods: ['warning', 'error'] }
]
})
page.deps.js
res.render('template', data);
Данные
↓
HTML
Данные
↓
БЭМ-дерево
↓
HTML
{
block: 'page'
}
{
block: 'page',
mods: { type: 'main' }
}
{
block: 'page',
mods: { type: 'main' },
content: {
block: 'header'
}
}
«языки программирования, в которых описывается процесс вычисления в виде инструкций, изменяющих состояние программы (состояние памяти, состояние переменных...)»
«языки высокого уровня, в которых не задается пошаговый алгоритм решения задачи ("как" решить задачу), а описывается, "что" требуется получить в качестве результата»
bh.match('page', (ctx) => {
ctx.tag('main');
});
bh.match('page', (ctx) => {
ctx.content({
elem: 'content',
content: ctx.content()
});
});
bh.match('page', (ctx) => {
ctx.content([
{ elem: 'header' },
ctx.content(),
{ elem: 'footer' }
]);
});
bh.match('page__footer', (ctx) => {
ctx.content('THIS IS FOOOOTER!');
});
bh.match('page', (ctx) => {
ctx.content('CONTENT');
});
bh.match('page', (ctx) => {
ctx.tag('div');
});
«Method of declaring a portion of reusable markup that is parsed but not rendered until cloned»http://caniuse.com/#feat=template
var template = document.querySelector('#template1');
document.body.appendChild(template.cloneNode(true));
...
...
...
...
...
...
...
...
...
var Folders = Object.create(HTMLElement.prototype);
Folders.createdCallback = function() {
this.addEventListener('click', function(e) {
alert('Thanks!');
});
};
document.registerElement('folders', {prototype: Folders});
createdCallback // экземпляр элемента создан
enteredViewCallback // экземпляр элемента добавлен в документ
leftViewCallback // экземпляр элемента удалён из документа
attributeChangedCallback(attrName, oldVal, newVal) // добавление/удаление/изменение аттрибута attrName
var Shadow = Object.create(HTMLElement.prototype);
Shadow.createdCallback = function() {
var shadow = this.createShadowRoot();
shadow.innerHTML = "Ололо";
};
document.registerElement('my-element', {prototype: Shadow});
var Shadow = Object.create(HTMLElement.prototype);
Shadow.createdCallback = function() {
var shadow = this.createShadowRoot();
var template = document
.querySelector('template#myTemplate');
shadow.appendChild(template.content);
};
document.registerElement('my-element', {
prototype: Shadow
});
<head>
</head>