Drupal has CSS coding standards
The rest of the web has coding standards
There are tools to help you enforce coding standards
/*doc
---
title: Alert
name: alert
category: basics
---
I am a comment
```html_example
I am the example code
```
*/
/**
* Implements hook_menu().
*/
function sage_statics_menu() {
$items = array();
$items['statics/%'] = array(
'page callback' => 'sage_statics_page',
'page arguments' => array(1),
'access arguments' => array('access content'),
);
return $items;
}
/**
* Page callback: Statics pages
*/
function sage_statics_page($page) {
switch ($page) {
case SageStatics::PAGE_BOOK_PRODUCT:
return theme(SageStatics::THEME_BOOK_PRODUCT);
// etc...
}
}
(Mostly) Unchanged
.component,
%component {
content: 'component';
&--variant {
content: 'variant';
}
&__element {
content: 'element';
}
}
// Fugly selectors.
.my-fugly-selector {
@extend %component__element;
}
Source: https://gist.github.com/JohnAlbin/b4329a2a4fb4a5caf1f2
abstract class AbstractThemeProcessor {
/**
* @var array
*/
private $vars;
/**
* @param array $vars
*/
private function __construct(&$vars) {
$this->vars = &$vars;
if ($this->isApplicable()) {
$this->execute();
}
}
/**
* @param array $vars
* @return static
*/
public static function process(&$vars) {
return new static($vars);
}
/**
* @return mixed
*/
abstract public function execute();
/**
* @return bool
*/
abstract public function isApplicable();
}
class ArticleNodeProcessor extends AbstractNodeProcessor {
// Example variable.
const VAR_EXAMPLE = 'example';
const VAR_EXAMPLE_FROM_NODE = 'example_node';
/**
* {@inheritDoc}
*/
public function isApplicable() {
return $this->isNodeType(ArticleController::getClassEntityBundle());
}
/**
* {@inheritDoc}
*/
public function execute() {
$this->articleController = example_article_factory()->initWithEntity($this->getVar('node'));
$this->addExtraDisplayItems();
}
/**
* Add extra display items.
*/
public function addExtraDisplayItems() {
$this->setVar(self::VAR_EXAMPLE, 'Variable value');
$this->setVar(self::VAR_EXAMPLE_FROM_NODE, $this->articleController->getExampleValue());
}
}
/**
* Implements template_preprocess_node().
*/
function example_preprocess_node(&$vars) {
ArticleNodeProcessor::process($vars);
ArticleNodeTeaserProcessor::process($vars);ß
BlogNodeProcessor::process($vars);
CarouselItemNodeProcessor::process($vars);
}
"That hover colour isn't right"
"That slide transition is too slow"