Tuesday, June 14, 2016

Integrate Stylelint Into Your Workflow For Better CSS

Working within a team or solo can adjust the development priorities but one that should always be high on the agenda is producing the best code possible.

Working on a clean, well organised codebase is bliss. It’s enjoyable and productive. Working on an unorganised codebase is annoying to say the least. It’s often frustrating, painfully slow to change and test anything and invites laziness.

Thankfully as CSS developers we have a handy tool called Stylelint that can help us avoid the unorganised situation.

By dedicating a small amount of setup time initially we can enforce consistent conventions and reap the rewards for the duration of the project.


Getting setup

First we need to decide how we want to use Stylelint. Stylelint can be used via the command line, build tool (gulp, webpack etc), text editor (atom, sublime text etc), Node API or PostCSS.

For this example we will setup Stylelint using webpack. If you are new to webpack this post Diving Webpack should help get the ball rolling.

Ok let’s install the stylelint webpack plugin via npm like so:

npm install stylelint-webpack-plugin --save-dev

In our webpack configuration we need to “require” the plugin we just installed and add the default settings like so:


var styleLintPlugin = require('stylelint-webpack-plugin');

module.exports = {
  // ...
  plugins: [
    new styleLintPlugin({
      configFile: '.stylelintrc',
      context: 'src',
      files: '**/*.css',
      failOnError: false,
      quiet: false,
    })
  ],
  // ...
}

The above options may need to be adjusted to get things running on your end. That really depends on your current setup.

  • configFile: The config file location
  • context: The root of your SCSS files
  • files: Change the glob pattern for finding your files
  • failOnError: Have Webpack’s build process die on error
  • quiet: Don’t print Stylelint output to the console

The above example doesn’t include it but if you are using a different syntax for your stylesheets you can use the following rule:

  • syntax: Use ‘scss|less|sugarss’ to lint the appropriate syntax

This is only the beginning in setting up your webpack config. A full list of options can be seen here, which will no doubt become very handy.


Next we need to create a configuration object, which is just a fancy way of saying we need to create a .stylelintrc file in the root directory of our project and add some Stylelint rules and options.

There are various other ways to setup the configuration object, but for this entry level introduction, we will just roll with the above.

To get the ball rolling, I would recommend adding a generic configuration and adjusting it to suit your needs once things are all setup.

Add this content to your .stylelintrc file.


{
  "rules": {
    "selector-no-id": true
  }
}

The above rule will throw an error if it finds “id selectors” like so:

ID Errors

Stylelint has over 100 rules to make sure your CSS is of the highest quality. Dig into them here.

At first they might seem a little daunting but thankfully a selection of people have put together an example configuration to help – Example Config.


Time to run webpack from the command line and clean up our code.

webpack or webpack -w will do the trick.

With a little setup time we now have Stylelint keeping an eye on our code to make sure it stays organised.


Taking things to the next level

This post is just a small insight into the power of using Stylelint (or any linter for that matter) during development.

If you are working within a team or solo it’s a great habit to get into. It keeps you honest and on track to becoming a better developer.

Happy linting!


Further reading:
How Facebook use Stylelint

The post Integrate Stylelint Into Your Workflow For Better CSS appeared first on Web Design Weekly.


by Jake Bresnehan via Web Design Weekly

Type Terms

Type Terms the animated typographic cheat sheet. If you are new to typography or just want to refresh your memory, then Type Terms is the perfect tool for you.


by csreladm via CSSREEL | CSS Website Awards | World best websites | website design awards | CSS Gallery

Blisk: Your Next Web Development Browser?

Which browser do you use for daily web development tasks? If my recent Twitter poll is to be believed, three quarters of us use our default browser. Perhaps that's understandable:

  • it's the application we have open most often
  • we have it configured exactly as we like it
  • it offers excellent development tools (they all do!)
  • we are comfortable using those utilities, and
  • it's the browser we prefer.

But is it practical?

If you're anything like me, your default browser has 57 tabs open at any time with various applications, tools and articles you intend to read later (… but rarely do!). Development in that browser is possible, but the application already uses many resources. Memory and processing speed may be negatively compromised. A crash can be catastrophic!

You may also have plug-ins enabled which affect code --- for example, advertising or script modifiers. You can spend hours debugging a system only to realize the problem is caused by one of your extensions, which wouldn't be installed by "normal" users. You may be able to temporarily disable those plug-ins, but that choice can affect every tab.

You may also need to perform development actions such as removing cookies, clearing local storage or accepting insecure, self-signed SSL certificates. That can cause complications if you have more than one test application running on the same domain, or accidentally wipe data from a regularly used website.

Despite these issues, only a quarter of web developers open another browser for primary development tasks. Fewer than half of those use a dedicated application such as Firefox Developer Edition or Opera Developer Browser. Vendors work hard to provide these tools since they realize no browser can be successful without support from the web development community. They usually offer beta versions of the latest tools and rendering engines, so they're a great option. However, if you have an immediate delivery date, you'll need to test your application in the mainstream edition of that browser to ensure you're not dependent on a technology that's not yet available or has a different implementation.

Is Blisk Beta Better?

Blisk logo

Blisk is a new browser aimed solely at professional web developers for prototyping, coding, debugging and testing tasks.

The Blisk Beta is available for Windows only, but Mac and Linux editions are in the pipeline. Installation is slightly disconcerting since there are no dialogs or options: Blisk simply installs and runs immediately. (The website suggests registering. It's not necessary to do so, although future features may require it.)

The application uses the same Blink rendering engine you'll find in Chrome, Opera and Vivaldi. That's a safe option, providing the standard development tools you find in those browsers (and, yes, the tools are dockable). That's where the similarity ends and Blisk enhances your web development workflow …

Scroll-synchronized Device View

Pages display in a dual window consisting of:

  • a standard desktop view, and
  • an emulated mobile/tablet view.

Nine smartphones and four tablets are currently supported. You can switch by clicking the device icon to emulate screen resolutions, pixel ratios, user agents and touch events. The devices are provided within the browser, so they work offline and don't require a cloud-based service.

Scrolling is automatically synchronized (although you can disable it):

Blisk synchronized scrolling

Auto-refresh on Change

You can associate a URL with a folder location. Blisk will monitor for file updates and auto-refresh both devices as soon as a change occurs:

Blisk auto-refresh

If you've not used similar systems before, it's the web equivalent of witchcraft. It saves considerable time, since you no longer need to switch between your editor and browser to see updates.

Continue reading %Blisk: Your Next Web Development Browser?%


by Craig Buckler via SitePoint

Vanessa

Vanessa

'Vanessa' is a long-scrolling One Page Joomla template suited for a clean landing page. The responsive template could be used quite well to promote your new app or website. Sections include big image/slide/video intro, feature infographics, pricing tables, newsletter signup, testimonial slider and nice big Google Map footer. Great to see another One Pager in the Joomla template category.

by Rob Hope via One Page Love

Building a Chart Component with Angular 2 and FusionCharts

As a web developer, if there is something that you can't miss, it is Angular 2. It is a complete rewrite of the popular JavaScript framework from Google and is constantly in news for all the right reasons. It offers some major improvements over the previous versions and that's why we're choosing it today to build some beautiful charts.

For the charts, we will use the JavaScript chart library provided by FusionCharts. It offers a good collection of charts and is compatible with all major browsers. Although FusionCharts offers a dedicated plugin for Angular, it is not yet compatible with Angular 2. So I am not going to use it and instead code directly using JavaScript and Angular 2. (Note: it is recommended you use the plugin if you are using Angular 1 in your app).

The chart we are going to plot will depict an interesting statistic—the revenue of five top tech companies (Amazon, Apple, Facebook, Google and Microsoft) and will have an option to switch between revenue data for 2014 and 2015. We will first go through the step-by-step process of creating charts in Angular 2. After building a basic chart, we will cover some advanced topics such as adding annotations and updating chart data.

As ever, you can download the code for this tutorial from our GitHub repo, or you can jump to a demo of the finished chart at the end of the article.

Angular 2 vs Angular 1.x

Angular 2 has some significant changes over its previous major version (Angular 1.x), for example its support for languages such as TypeScript and Dart, and the way it computes updates to the DOM. If you'd like to learn more about how Angular 1 concepts and techniques map to Angular 2, you can check out the official quick reference. If you are interested in migrating your app from Angular 1.x to Angular 2, you can read the official migration guide.

Although Angular 2 supports TypeScript and Dart, we will use native JavaScript to write the Angular 2 application in this tutorial because of its familiarity. Using TypeScript or Dart would also introduce an unnecessary build step.

Setup

There are number of ways to get up and running with an Angular 2 project. The easiest is probably to head over to the official site and follow their 5 Min Quickstart tutorial.

One slight caveat to this approach however, is that it relies on you having Node and npm installed on your machine. We do have a guide for this, but if you'd prefer to follow this tutorial without installing these, you can use the following template:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>Angular 2 FusionCharts Demo</title>

    <!-- 1. Load custom CSS & fonts-->
    <link rel="stylesheet" href="styles.css">
    <link href='http://ift.tt/1RrSx5U' rel='stylesheet'>

    <!-- 2. Load Angular 2 specific libraries -->
    <script src="http://ift.tt/1ZOYKgC"></script>
    <script src="http://ift.tt/1Q245Rj"></script>
    <script src="http://ift.tt/1ZOZ2UC"></script>

    <!-- 3. Load FusionCharts library-->
    <script src="http://ift.tt/1Q24fYR"></script>

    <!-- 4. Load component -->
    <script src='main.js'></script>
  </head>
  <body>

    <!-- 5. Display the application -->
    <angular-chart>Loading...</angular-chart>
  </body>
</html>

Creating the Chart Component

Components are the building blocks of any Angular 2 application. They are reusable pieces of code consisting of a view, and some logic. If you're familiar with Angular 1, you can think of them as directives with a template and a controller.

Here's the basis of our chart component:

(function(chartApp){
  chartApp.AppComponent = ng.core.Component({
    selector: 'angular-chart',
    template: '<div>Chart will render here</div>'
  }).Class({
    constructor: function(){}
  });

  document.addEventListener('DOMContentLoaded', function() {
    ng.platform.browser.bootstrap(chartApp.AppComponent);
  });
})(window.chartApp || (window.chartApp = {}));

Let's take a second to see what's going on.

We start with an IIFE (immediately invoked function expression) which we use to namespace our app. We pass it window.chartApp as an argument, which is initialized to an empty object if it isn't defined. This is where our application is going to live—in a single property on the global object.

Inside the IIFE we create our component (AppComponent) by chaining the Component and Class methods from ng.core (a collection of Angular's core components). We're passing the Component method a configuration object containing the following propeties:

  • selector: a simple CSS selector which specifies a host HTML element. Angular will create and display an instance of the component whenever it encounters a HTML element matching this selector.

  • template: the template to be used when the component is rendered. Currently we're passing a string containing a placeholder <div> element, but ideally we should move this out into its own template.

The Class method is where we add behavior and event bindings for the template.

Having defined our basic component, we initialize it using Angular's browser bootstrap function.

You should be able to run the code in your browser at this point and see the message "Chart will render here".

Creating the Chart

Let's move on to creating the chart and displaying some data for 2014.

Continue reading %Building a Chart Component with Angular 2 and FusionCharts%


by Rohit Boggarapu via SitePoint

Faster WordPress Theme Development with the Beans Framework

If you can’t wait to build your own custom WordPress theme, using a well coded, solid theme framework is a great way to start. Frameworks provide WordPress themes with common functionality and components for you to then create your own unique designs. This speeds up development time enormously.

In this post I’m going to experiment with one of the newer kids on the WordPress frameworks block, Beans, created by Thierry Muller. James George has also previously covered this topic on SitePoint in his article Introducing Beans.

More about the Beans Theme Framework

Beans is an Open Source, free WordPress theme framework boasting a lot of awesome features, which make it a great fit for both budding and experienced developers. Here are the main features below:

  • Beans is mobile-first, fully responsive, and smart enough to create and serve images at the resolution most appropriate to the device in use.
  • Lean code, caching, selective loading of assets, and minification techniques make Beans an amazingly light-weight and fast loading theme. This is great when it comes to Google page ranking and your website visitors’ happiness.
  • The UIkit front end framework lends the theme its clean and modern appearance. However, if you’re wondering whether developing with Beans will tie you to UIkit, fear not. Beans is highly flexible and lets you load assets as you need them.

It’s time to get your copy of Beans and take it for a test drive.

Continue reading %Faster WordPress Theme Development with the Beans Framework%


by Maria Antonietta Perna via SitePoint

7 PostCSS Plugins to Ease You into PostCSS

We've featured PostCSS many times before on SitePoint, yet it continues to confuse many. To summarize it in one sentence:

PostCSS handles tedious jobs so you don't have to.

It is subtly different to a pre-processor such as Sass, Less and Stylus which provide an alternative, more concise programming language which compiles to CSS. Part of the confusion is caused by:

  • Its name. PostCSS can perform actions on files either before and/or after a pre-processor has compiled its source code to real CSS.

  • PostCSS could replace your pre-processor. There are plugins which implement constructs such as variables, nesting, mixins and extends.

However, while you can build your own pre-processor, there's little reason to do so unless you want to limit the functionality and increase compilation speed. Personally, I use Sass followed by a sprinkling of PostCSS seasoning to enhance my CSS.

How Do You Use PostCSS?

PostCSS can be used within standalone JavaScript files, Gulp, Grunt, Broccoli, Brunch and a wide range of task runners I've never heard of!

On its own, PostCSS does nothing but parse a CSS file into JavaScript objects and tokens. The real magic happens with plugins which examine, manipulate, add or change properties and values before the final CSS file is written.

To use PostCSS in Gulp, you need to set-up your project then install both modules:

[code language="bash"]
npm init
npm install --save-dev gulp gulp-postcss
[/code]

You can then add the plugins you require, e.g. autoprefixer and cssnano:

[code language="bash"]
npm install --save-dev autoprefixer cssnano
[/code]

A gulpfile.js can be created. It defines a task which loads the CSS source and pipes it through PostCSS. Plugins and any required options are passed to PostCSS in an array. Finally, the CSS is output to a destination file:

[code language="js"]
// Gulp.js configuration
var gulp = require('gulp'),
postcss = require('gulp-postcss');

// apply PostCSS plugins
gulp.task('css', function() {
return gulp.src('src/main.css')
.pipe(postcss([
require('autoprefixer')({}),
require('cssnano')
]))
.pipe(gulp.dest('dest/main.css'));
});
[/code]

The task can be run from the console with:

[code language="bash"]
gulp css
[/code]

All we need now is a handy list of PostCSS plugins...

Continue reading %7 PostCSS Plugins to Ease You into PostCSS%


by Craig Buckler via SitePoint