-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposed changes luca #2
Conversation
assets/scss/bacon.scss
Outdated
@@ -1,6 +1,6 @@ | |||
// | |||
// Bacon | |||
// -------------------------------------------------- | |||
// ----------------------------------------------------------------------------- |
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.
👎 This is the primary reason for why we should use C-style / CSSDoc syntax for comment blocks instead:
/**
* Bacon
*
* Some optional description here. And you can use most of
* the generic *Doc tags/directives, too:
*
* @param int $font-size
*
* @see http://www.stack.nl/~dimitri/doxygen/
* @see https://timkadlec.com/2008/12/manageable-css-with-cssdoc/
* @author netzstrategen
* @license MIT
*/
//
is the inline comment syntax in all mature programming languages including SCSS; it is wrong to use them for block-level documentation.
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.
Ok but using /* */
the comments will be preserved in the CSS output. 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.
However to generate documentation with SassDoc you need to use ///
.
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.
No, when configured correctly, only the special syntax /*!
for package file headers & legal / license information is retained in the compiled CSS.
To summarize code comment syntaxes:
/*!
* Package name header with author and license info.
*
* Retained in compiled CSS as-is.
*
* @license MIT
*/
/**
* CSSDoc block-level comment for files, sections, components.
*
* First summary line is separated with a blank line from description.
* Not included in compiled CSS.
*/
/*
var commented = out.code();
*/
// Inline comment explaining internal / detailed reasons.
// Should be placed on its own line above the commented line.
font-size: 100%;
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.
SassDoc uses https://github.com/SassDoc/scss-comment-parser which uses https://github.com/FWeinb/CDocParser, which normally parses C-style comments, but CDocParser was seemingly enhanced specifically for SassDoc to also support the triple-slash ///
syntax. 💩
See blockCommentStyle
and lineCommentStyle
options here: https://github.com/FWeinb/CDocParser#user-content-new-commentextractorcontextparser-opts
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.
Apparently, SassDoc specifically disables block-level comments:
https://github.com/SassDoc/scss-comment-parser/blob/f93499709fd5180950504df4e6f41433c4f91983/index.js#L198-L200
🤦♂️
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.
So? Which would be the solution? I never use something different that SassDoc and I didn't find valid alternatives.
Should we:
A. Not create a Sass documentation;
B. Keep using the 💩 ///
syntax;
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 is a good and interesting question.
We will actually define and document most of our styles in the form of components in the design system, which produces a styleguide on its own.
What's the purpose of SassDoc in relation to that? Which problem are you trying to solve?
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.
Was not really a problem to solve, instead, was more like something to add.
It's true that components structure is pretty clear but SassDoc will document mixins and functions extrapolating Sass comments (unfortunately not C-Styled one) into a page like this one:
I found it extremely useful in some projects I worked with and so I thought could be a cool stuff to introduce.
Maybe should I change idea about? Cons of using it are more than pros?
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.
This is great, thanks Luca. The comment style I used is from Bootstrap which I find to be easy-to-read and have been using for six months or so - there was no real decision-making behind it. I'm aware of Sassdoc (although I've never used it) and it seems to be a good way to go. Automatically generated documentation is a big win. I should get time later in the week to review this properly 👍
sassdoc/assets/js/main.js
Outdated
@@ -0,0 +1,56 @@ | |||
/* global document */ |
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.
Did you intend to commit this package? 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.
True, sorry. We can exclude the whole sassdoc
folder since it will be auto generated from gulp
.
a9db5cc
to
41c043a
Compare
gulpfile.js
Outdated
'android 4', | ||
'opera 12' | ||
] | ||
}) |
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.
Autoprefixer uses Browserslist which allows you to specify browser support in an external file. They recommend adding the block to package.json so I'll do that. https://github.com/ai/browserslist
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.
Super, agree with you. 👍
Added a bunch of commits which take in this PR as well as #3 and #6.
@LucaPipolo @fabianmarz Could you take a look at the latest commits and comment please? Let's get all this merged in so we can get started with the component building :) |
@colourgarden — looks really good to me, as we discussed during last days on Slack. Great job! 👍 Just one question. I saw you decided to adopt the |
Of course before merging we should clean the tree removing:
Instead of reverting them. :) |
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.
Awesome job! 👍
@@ -82,6 +83,18 @@ | |||
"number-leading-zero": "always", | |||
"number-no-trailing-zeros": true, | |||
|
|||
"plugin/selector-bem-pattern": { | |||
"componentName": "(([a-z0-9]+(?!-$)-?)+)", |
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 is this regex trying to match/achieve?
Just the following? [a-z][a-z0-9_-]*[a-z0-9]
If so, let's keep it simple and use something like that instead, because it's also more accurate:
In CSS, identifiers (including element names, classes, and IDs in selectors) can contain only the characters [a-zA-Z0-9] and ISO 10646 characters U+00A0 and higher, plus the hyphen (-) and the underscore (_); they cannot start with a digit, two hyphens, or a hyphen followed by a digit.
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.
@LucaPipolo added this.
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.
https://github.com/postcss/postcss-bem-linter#user-content-componentselectors
Describes all valid selector sequences for the stylesheet
So componentName only matches the "block" part of a class, and only these that we consider valid.
This would be a matching regex: \.(?:(?!--)[a-z0-9-])+
But according to https://github.com/davidtheclark/stylelint-selector-bem-pattern#user-content-usage, it seems like componentName
just needs to specify the allowed characters for the block element, in our case simply: [a-z0-9-]+
// -------------------------------------------------- | ||
@charset "utf-8"; | ||
|
||
/*! #copyright DO NOT REMOVE# */ |
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's going on here? Some placeholder magic, I assume?
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.
Yep, in the gulpfile I added a task (sass-prod
) to compile production-ready CSS. It replaces this line with a copyright message which sources its information from package.json
so we don't need to remember to update the version number in the Sass files every time.
There are gulp packages where you can just add a message to the start of the compiled file (so avoiding the need for this placeholder line) but the @charset
declaration must be the first thing in the file. Because there are some non-alphanumeric characters included (embedded SVG) then Sass will always automatically add a @charset
declaration.
assets/scss/base/_document.scss
Outdated
// -------------------------------------------------- | ||
/* ========================================================================== | ||
Base page styling | ||
========================================================================== */ |
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.
Wondering how many of these files actually contain just a single selector… Would it be possible to omit these "banners" altogether?
If necessary, we could group multiple things as files in subdirectories instead.
And we could give each file a meaningful name, such as:
/elements/border-box.scss
/elements/table-width.scss
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 do you want to remove them? They won't be included in production CSS and provide clear separators in compiled but expanded CSS generated by the standard scss
gulp task. I'd rather enforce a convention of having a banner comment at the top of every file for the few occasions where it is useful (for further explanation) rather than sometimes having one, sometimes not.
Splitting up elements
is a good idea - I'll do 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.
Elements now split into separate files within base/elements
folder.
assets/scss/base/_document.scss
Outdated
* 2. Set everything to border-box by default but allow per-component changes. | ||
* http:/css-tricks.com/inheriting-box-sizing-probably-slightly-better-best-practice | ||
* 3. Ensure the page always fills at least the entire height of the viewport. | ||
*/ |
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.
All of these docs —> ❤️❤️❤️ !!!
This is how we should be documenting most of our code, as it helps others to understand what's really going on and make decisions.
assets/scss/base/_document.scss
Outdated
* navigating between pages that do/do not have enough content to produce | ||
* scrollbars naturally. | ||
* 2. Set everything to border-box by default but allow per-component changes. | ||
* http:/css-tricks.com/inheriting-box-sizing-probably-slightly-better-best-practice |
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.
This actually appears to be style affecting all elements, shouldn't it be in elements instead?
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.
It's kinda both but I'll move it into an elements folder as per previous comment.
assets/scss/base/_elements.scss
Outdated
* 2. Emphasise `alt` text if shown. | ||
* 3. Setting `vertical-align` removes the whitespace that appears under `img`. | ||
* elements. Safer alternative to using `display: block;`. | ||
* 4. If an image has explicit dimensions set then don't make it responsive. |
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.
The CMS will always output dimensions for all images by default (unless we start to make very very granular template variable overrides), so I doubt this rule makes sense?
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 for responsive images where we want them to fill the container (width and height)? Explicit dimensions wouldn't be ideal in those scenarios.
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.
Regular image output produced by the CMS will either use srcset
or <picture>
(not sure whether the upgrade to picture happened in Drupal core already).
Of course, there might be custom output scenarios in custom templates (such as setting a background-image instead), but we should rather assume that there will be dimensions all images by default.
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.
Ok so should I add height: auto
to all images as well then? If we're adding dimensions to all images then they're not going to work properly responsively because the height will stay the same as the width changes = distorted image.
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 believe that's what we're doing in all the (WP) projects, yes. I don't know whether that is the best solution.
Here are the current image output templates of Drupal core:
https://github.com/drupal/drupal/blob/8.5.x/core/modules/system/templates/image.html.twig
https://github.com/drupal/drupal/blob/8.5.x/core/modules/responsive_image/templates/responsive-image.html.twig
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.
The best solution would be to remove width
and height
attributes. But if we can't do this reliably then we should add height: auto
as standard to cover 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.
JavaScript libraries for lazy-loading, galleries, and lightboxes usually need the image dimensions before loading an image in order to calculate and prepare the content layout, so I think we can only omit them in limited special cases?
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.
Fixed in fixup commit.
assets/scss/base/forms/_choice.scss
Outdated
|
||
[type='checkbox'] | ||
/** | ||
* Shared choice element styling |
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.
Missing trailing period. (also elsewhere)
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.
Ok will make this a convention by changing throughout and adding to index.html
docs.
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.
Corrected throughout. All block-level comments should require a full stop but Sass double-slash comments don't.
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.
In PHP and JS, we require full sentences starting with an uppercase letter and ending in a trailing period for any kind of comment, including inline comments.
The only exceptions to that are @see
(because what follows is a URL or function or some other kind of resource identifier) and inline comments that are not natural language (values or references).
Furthermore, inline comments always have to be on their own line, above the commented line of code; i.e.:
$foo = $bar; // wrong
// Right.
$foo = $bar;
The SCSS footnotes would fall under the exception of references.
'base/elements/box-sizing', | ||
'base/elements/shared', | ||
'base/elements/links', | ||
'base/elements/images', |
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.
@LucaPipolo What was the reason for deleting _elements.scss
and including the files individually here?
Forms work in the same way so we should at least be consistent. But I prefer the method of having the additional include file in the folder as it feels neater and should also cut down on dead files.
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.
We investigated base/elements/*
as an alternative, but weren't sure whether you intended to have these elements in a particular order.
A separate include file that includes further files is "obscuring" the intended final configuration. I would definitely recommend to keep all the includes in a single place to maintain a clear overview of what is being included in which order.
For a baseline/starter framework like this, it makes more sense to be more explicit, so as to give a better understanding to new users/developers.
Implemented C-style comment blocks and hierarchy. Improved documentation of blocks at the same time.
Fixes pr#3.
Implemented Clean CSS to improve compression. Moved supported browsers to package.json as recommended by browserslist library which autoprefixer uses. Implemented gulp-replace to add copyright notice generated by package.json file. Extends pr#6.
Previously all in one file, now in separate files per subject. Includes moving box-sizing from _document into own file under /elements.
30987b5
to
7a0219a
Compare
No description provided.