This commit is contained in:
Oleg Mokhov
2015-06-20 12:26:08 +03:00
committed by mokhov
parent a716969f4e
commit f3546ef3a5
85 changed files with 16682 additions and 1 deletions

View File

@@ -0,0 +1,162 @@
module.exports = function (bt) {
/**
* @param {Bemjson} body Содержимое страницы. Следует использовать вместо `content`.
* @param {String} doctype Доктайп. По умолчанию используется HTML5 doctype.
* @param {Object[]} styles Набор CSS-файлов для подключения.
* Каждый элемент массива должен содержать ключ `url`, содержащий путь к файлу.
* @param {Object[]} scripts Набор JS-файлов для подключения.
* Каждый элемент массива должен содержать ключ `url`, содержащий путь к файлу.
* @param {Bemjson} head Дополнительные элементы для заголовочной части страницы.
* @param {String} favicon Путь к фавиконке.
*/
bt.setDefaultView('y-page', 'islet');
bt.match('y-page_islet*', function (ctx) {
var styleElements;
var styles = ctx.getParam('styles');
if (styles) {
styleElements = styles.map(function (style) {
return {
elem: 'css',
url: style.url,
ie: style.ie
};
});
}
return [
ctx.getParam('doctype') || '<!DOCTYPE html>',
{
elem: 'html',
content: [
{
elem: 'head',
content: [
[
{
elem: 'meta',
charset: 'utf-8'
},
ctx.getParam('x-ua-compatible') === false ?
false :
{
elem: 'meta',
'http-equiv': 'X-UA-Compatible',
content: ctx.getParam('x-ua-compatible') || 'IE=edge'
},
{
elem: 'title',
content: ctx.getParam('title')
},
ctx.getParam('favicon') ?
{
elem: 'favicon',
url: ctx.getParam('favicon')
} :
'',
{
block: 'y-ua'
}
],
styleElements,
ctx.getParam('head')
]
},
ctx.getJson()
]
}
];
});
bt.match('y-page_islet*', function (ctx) {
ctx.setTag('body');
ctx.enableAutoInit();
var scriptElements;
var scripts = ctx.getParam('scripts');
if (scripts) {
var global = bt.lib.global;
scriptElements = scripts.map(function (script) {
return {
elem: 'js',
url: script.url ? script.url.replace('{lang}', global.lang) : undefined,
source: script.source
};
});
}
ctx.setContent([ctx.getParam('body'), scriptElements]);
});
bt.match('y-page_islet*__title', function (ctx) {
ctx.disableCssClassGeneration();
ctx.setTag('title');
ctx.setContent(ctx.getParam('content'));
});
bt.match('y-page_islet*__html', function (ctx) {
ctx.setTag('html');
ctx.disableCssClassGeneration();
ctx.setAttr('class', 'y-ua_js_no y-ua_css_standard');
ctx.setContent(ctx.getParam('content'));
});
bt.match('y-page_islet*__head', function (ctx) {
ctx.setTag('head');
ctx.disableCssClassGeneration();
ctx.setContent(ctx.getParam('content'));
});
bt.match('y-page_islet*__meta', function (ctx) {
ctx.setTag('meta');
ctx.disableCssClassGeneration();
ctx.setAttr('content', ctx.getParam('content'));
ctx.setAttr('http-equiv', ctx.getParam('http-equiv'));
ctx.setAttr('charset', ctx.getParam('charset'));
});
bt.match('y-page_islet*__favicon', function (ctx) {
ctx.disableCssClassGeneration();
ctx.setTag('link');
ctx.setAttr('rel', 'shortcut icon');
ctx.setAttr('href', ctx.getParam('url'));
});
bt.match('y-page_islet*__js', function (ctx) {
ctx.disableCssClassGeneration();
ctx.setTag('script');
var url = ctx.getParam('url');
if (url) {
ctx.setAttr('src', url);
}
var source = ctx.getParam('source');
if (source) {
ctx.setContent(source);
}
ctx.setAttr('type', 'text/javascript');
});
bt.match('y-page_islet*__css', function (ctx) {
ctx.disableCssClassGeneration();
var url = ctx.getParam('url');
if (url) {
ctx.setTag('link');
ctx.setAttr('rel', 'stylesheet');
ctx.setAttr('href', url);
} else {
ctx.setTag('style');
}
var ie = ctx.getParam('ie');
if (ie !== undefined) {
if (ie === true) {
return ['<!--[if IE]>', ctx.getJson(), '<![endif]-->'];
} else if (ie === false) {
return ['<!--[if !IE]> -->', ctx.getJson(), '<!-- <![endif]-->'];
} else {
return ['<!--[if ' + ie + ']>', ctx.getJson(), '<![endif]-->'];
}
}
});
};

View File

@@ -0,0 +1,4 @@
- y-global
- block: y-design
required: true
- block: y-ua

View File

@@ -0,0 +1,17 @@
# y-page: страница
Используется в качестве контейнера для всех остальных блоков.
Содержимое страницы следует задавать параметром `body` в `bemjson`.
## Варианты представления
| view | Описание
| --------------- | ---------
| `islet` | Дефолтное представление. Содержит глобальные стили для ссылок
## Настройки шаблона
<!--BTJSON_API-->

View File

@@ -0,0 +1,40 @@
modules.define(
'test',
['bt'],
function (provide, bt) {
describe('y-page', function () {
describe('bt', function () {
describe('doctype', function () {
it('should should render HTML5 doctype by default', function () {
bt.processBtJson({block: 'y-page'})[0].should.equal('<!DOCTYPE html>');
});
it('should should render given doctype', function () {
bt.processBtJson({block: 'y-page', doctype: '<!DOCTYPE>'})[0].should.equal('<!DOCTYPE>');
});
});
describe('layout', function () {
it('should render html tag', function () {
bt.processBtJson({block: 'y-page'})[1]._tag.should.equal('html');
});
it('should render head tag', function () {
bt.processBtJson({block: 'y-page'})[1].content[0]._tag.should.equal('head');
});
it('should render body tag', function () {
bt.processBtJson({block: 'y-page'})[1].content[1]._tag.should.equal('body');
});
});
describe('js', function () {
bt.apply({
block: 'y-page',
scripts: [{url: '1.js'}, {source: 'alert("Hello World!");'}]
}).should.contain(
'<script src="1.js" type="text/javascript"></script>' +
'<script type="text/javascript">alert("Hello World!");</script>'
);
});
});
});
provide();
});

View File

@@ -0,0 +1,8 @@
.y-page_islet {
margin: 0;
padding: 0;
background: #F6F5F3;
font-family: $y-design.common['font-family'];
}