-
Notifications
You must be signed in to change notification settings - Fork 2
Implement parse method #9
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WAT?
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
basename = path.basename(str);
There was a problem hiding this comment.
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]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what exactly confuses you?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Swapped?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WAT? No.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
slice(1).join('.')
There was a problem hiding this comment.
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('.'); |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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;
?
There was a problem hiding this comment.
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')); |
There was a problem hiding this comment.
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 ;-(
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А еще: почему parse?
А какие будут предложения?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fetch? ну не знаю.
00fc3ee
to
ed3be71
Compare
🆙 |
|
||
module.exports = { | ||
path: function(entity, tech, options) { | ||
options || (options = {}); | ||
var naming = bemNaming(options.naming); | ||
|
||
return naming.stringify(entity) + '.' + tech; | ||
}, | ||
parse: function(str, options) { |
There was a problem hiding this comment.
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 | ||
}; |
There was a problem hiding this comment.
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;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
compareEntities
parseDirAsBemCell
splitAtFirst
это какие то твои хелперы?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@a-x- а pr прислать ты не хочешь ?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
No description provided.