Skip to content
This repository has been archived by the owner on Aug 1, 2019. It is now read-only.

Implement parse method #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Implement parse method #9

wants to merge 1 commit into from

Conversation

tadatuta
Copy link
Member

@tadatuta tadatuta commented Oct 7, 2016

No description provided.

@tadatuta
Copy link
Member Author

tadatuta commented Oct 7, 2016

cc @vithar @skad0 @blond @zxqfox

Copy link

@qfox qfox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А еще: почему parse?

var naming = bemNaming(options.naming),
splittedPath = path.split('.');

return {
Copy link

@qfox qfox Oct 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use here BemUnnamedObject? To reduce hidden classes quantity

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WAT?

Copy link

@qfox qfox Oct 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Object like {entity: {block, elem, mod}, tech: ?String} has no name atm so it's BemUnnamedObject.
You are free to call it somehow, but not BemEntityTech and not Tenorok.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand profit of such naming so such simple things. Can't we refactor it later when we end up with some name and found real cases for it?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we refactor it later when we

Yes, we can.

end up with some name

We decided to call it BemCell or BemCytus for now

and found real cases for it?

https://github.com/bem-sdk/bem-decl/blob/master/lib/normalize.js#L13
https://github.com/bem-sdk/bem-graph/blob/master/lib/vertex.js#L7
etc.

options || (options = {});
var naming = bemNaming(options.naming),
splittedPath = str.split(path.sep).filter(Boolean),
file = splittedPath.pop(),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

basename = path.basename(str);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need mutated splittedPath bellow


// support for paths without filename, e.g. 'b1/__e1/'
if (!entity) {
entity = naming.parse(splittedPath.join('') + splittedFile[0]);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But why?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what exactly confuses you?

Copy link

@qfox qfox Oct 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we should parse directories as entities? Any real life case for that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cd level1/b1/__e1
bem create _m1_v1.css # b1__e1_m1_v1.css

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about

cd level1/b1/b2/b3
bem create _m1_v1.css # b1b2b3_m1_v1.css

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch 👍


return {
entity: entity,
tech: splittedFile[1]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

splittedFile.slice(1).join('.');

describe('default', function() {
it('should return path + tech', function() {
expect('a/a.js')
.eql(scheme().path({ block: 'a' }, 'js'));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Swapped?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's exactly the way to make it render err messages right

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WAT? No.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you are right! And it's really strange 'cos I don't like the way it's done and I remember that when it was written intuitively actual and expected were swapped in error messages.
Will toggle them, thanks!

@@ -6,5 +6,15 @@ module.exports = {
var naming = bemNaming(options.naming);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I think this is not optimal to create the same thing many times per build.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but each level may have its own naming settings

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pass in naming object instead of creating it on each call

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


return {
entity: naming.parse(splittedPath[0]),
tech: splittedPath[1]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slice(1).join('.')

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

parse: function(path, options) {
options || (options = {});
var naming = bemNaming(options.naming),
splittedPath = path.split('.');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we check here that path is valid entity file? At least, can we get path.basename?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean something like

if (path.basename(str) !== str) return;

?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like... ;-( Can't imagine something better atm.

expect(expected).eql(scheme().parse('b1__e1'));
expect(expected).eql(scheme().parse('b1/__e1'));
expect(expected).eql(scheme().parse('b1/__e1/'));
expect(expected).eql(scheme().parse('b1/__e1/b1__e1'));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

each assertion should be in separate case ;-(

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sound like too much bureaucracy :)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just each assertion should describe a single case with some title.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А еще: почему parse?

А какие будут предложения?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fetch? ну не знаю.

@tadatuta
Copy link
Member Author

tadatuta commented Oct 7, 2016

🆙


module.exports = {
path: function(entity, tech, options) {
options || (options = {});
var naming = bemNaming(options.naming);

return naming.stringify(entity) + '.' + tech;
},
parse: function(str, options) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jsdoc

return {
entity: entity,
tech: tech
};
Copy link
Contributor

@a-x- a-x- Feb 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my implementation:

function parseBemPath(filePath) {
    const filePath_ = path.normalize(filePath);

    const cell = _parseComplexBemPath(filePath_); // With directories-technologies
    // null is a signal 'incorrect cell found'
    return cell || cell !== null && _parseSimpleBemPath(filePath_) || null;
}
function _parseComplexBemPath(filePath) {
    const chunks = filePath.split(path.sep);
    const block = chunks[1];
    const secondChunk = splitAtFirst(chunks[2], '.'); // E.g. ['suggest2', 'priv.js']

    if(!secondChunk[1]) { // Directory-technology, e.g. button2. < examples >/
        return; // skip, go to next processor
    }
    const cell = BemCell(secondChunk);
    return cell && !compareEntities(cell.entity, {block: block}).length ? cell : null;
}
function _parseSimpleBemPath(filePath) {
    const name = path.basename(filePath);
    const cellFromName = BemCell(splitAtFirst(name, '.'));

    if(!cellFromName) {
        return null;
    }
    const entityFromDir = parseDirAsBemCell(path.dirname(filePath));
    const diff = compareEntities(cellFromName.entity, entityFromDir);
    return !diff.length || _.isEqual(diff, ['modVal']) ? cellFromName : null;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compareEntities
parseDirAsBemCell
splitAtFirst
это какие то твои хелперы?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@a-x- а pr прислать ты не хочешь ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it's mine

yep, i can, but i afraid it useless and what would be changed if i do?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can see all of helpers in the internal pr: lego/islands-ci-helpers/pull/233

@@ -1,10 +1,25 @@
var bemNaming = require('bem-naming');
var path = require('path'),
bemNaming = require('bem-naming');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bem/naming


expect(scheme().parse('b1__e1')).eql(expected);
expect(scheme().parse('b1/__e1')).eql(expected);
expect(scheme().parse('b1/__e1/')).eql(expected);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure that it is a block_elem, but not block ?

if (i > 2) { return; }
}

return {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

result should be bem-cell

@Yeti-or Yeti-or mentioned this pull request May 6, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants