Monday, June 27, 2016

Image Replacement Techniques in the Modern Age

If you are not familiar with the concept of image replacement in CSS, consider the following scenario. Let's say you want to display a fancy logo in your website header. Now, you might be tempted to use the typical <img> tag. That would work — however using images in such a manner will deprive your website of SEO benefits and will also compromise the accessibility of the website.

[caption id="attachment_133603" align="aligncenter" width="1024"]Image replacement magician Artwork by SitePoint/Natalia Balska[/caption]

Image replacement techniques allow you to replace a text element with an image while avoiding some of the above downsides. There are multiple ways to replace text with images, we will cover a range of these in this article.

Using Negative Text-indent — The Phark Method

This is the most common technique that most web developers have used at one point or another. The idea here is to move the text far outside the browser window by setting a large negative text-indent:

.replace-indent {
  width: 264px;
  height: 106px;
  background: url("assets/logo.png");
  text-indent: -9999px;
}

Here is a CodePen demo showing how two headings look with and without text-indent. The first contains text which is not hidden and the second has the text hidden using text-indent:

See the Pen Image replacement indenting by SitePoint (@SitePoint) on CodePen.

The text is still accessible by screen readers using this method and there is no SEO penalty. However, this solution won't work when the text is right aligned. Also, the browser needs to render a very large box for our header due to the text-indent value which can be problematic on very old devices.

The Scott Kellum Method

Instead of setting a large negative text-indent, you can set it to 100%. This way the browser won't need to create a large box and the performance will improve. You don't need any extra markup to use this method. Here is the CSS that you need:

.replace-scott {
  width: 264px;
  height: 106px;
  background: url("assets/logo.png");
  text-indent: 100%;
  white-space: nowrap;
  overflow: hidden;
}

Setting overflow to hidden hides the text and whitespace: nowrap keeps it from moving onto the next line. The text will still be read by screen readers in this method. Here is a demo of this technique:

See the Pen Image Replacement - Scott Kellum Technique by SitePoint (@SitePoint) on CodePen.

Using Margin — Radu Darvas Technique

This technique also forces the text outside of the browser window but uses margins to do so. The idea here is to apply very large negative left margin and give your header a correspondingly large width.

.replace-margin {
  width: 2264px;
  height: 106px;
  background: url("assets/logo.png") top right no-repeat;
  margin: 0 0 0 -2000px;
}

Just like the previous case, our logo is used as a background image for the heading. Here is a demo to show how this technique works, first without the margin and then with the margin applied:

See the Pen Image Replacement - Margin Technique by SitePoint (@SitePoint) on CodePen.

If you keep scrolling to the right you will eventually see the background for first heading. In reality, you won't have to worry about the scrollbar because the large negative margin compensates for the width (as you can see with the second heading). Keep in mind that this method is not as efficient for the browser to perform because the browser has to draw a really large box.

Using Padding — The Langridge Method

This time we push the text outside of our header using the padding-top property. The property is to be set to a value that is equal to the height of our logo. However, this alone is not enough and we also have to use overflow: hidden to hide the text.

.replace-padding {
  width: 264px;
  height: 0;
  background: url("assets/logo.png");
  padding: 106px 0 0 0;
  overflow: hidden;
} 

Compared to the previous two methods, this property does a much better job performance wise. It also offers the same level of accessibility as the previous two methods. Below is a demo of this technique, the first heading does not have the padding background, while the second one does:

See the Pen Image Replacement - Padding Technique by SitePoint (@SitePoint) on CodePen.

Using Small font-size — The Lindsay Method

Another way to hide text is make it very small and set its color to the background of your logo. This works without affecting accessibility but you might face SEO penalties because of the tiny font size and camouflaged color.

.replace-font {
  width: 264px;
  height: 106px;
  background: url("assets/logo.png");
  font-size: 1px;
  color: white;
}

Here is a demo for this method, the first image without the font-size fix and the second one with it in action:

See the Pen Image Replacement - font-size Technique by SitePoint (@SitePoint) on CodePen.

You will still face problems if your logo does not have a flat background color to allow perfect blending. In that case, you can set the color to transparent.

Continue reading %Image Replacement Techniques in the Modern Age%


by Baljeet Rathi via SitePoint

Web Design Weekly #241

Headlines

Craftsmanship, design and code

Jonathan White sees valid points to both sides of the debate about whether designers should learn to code or whether developers should learn to design. But rather than the usual angle most articles on this topic take about what companies want in the way of skill-sets, he encourages developers and designers to focus on doing what they enjoy and make it part of their craft. (medium.freecodecamp.com)

Typography for User Interfaces (viljamis.com)

HipChat

Group Chat for Designers. A chat tool that’s actually built for teams and businesses. Try HipChat for free today! (hipchat.com)

Articles

Style Guide Driven Development with Atomic Docs

Style guide driven development has proven a valuable addition to Wishnet’s workflow over the last few years. Here’s an introduction to style guides, their team’s experience with SDD and how Atomic Docs is an essential part of their workflow. (css-tricks.com)

How to use code as your primary design tool

Learn about the beauty of designing in code from this interview with Chris Gannon, an immensely talented interaction and motion designer from the UK who straight out “designs in code”. (stories.uplabs.com)

Apps are faltering. But progressive web apps seem pretty legit.

There has been considerable debate about the future of native apps. Over the last few years, Cameron Moll has been pitching the idea of Unified Design at many conferences. He sees it as a solution to the growing disconnect between a product’s native app and its web app (or website) counterpart. (medium.com)

SSL Your WordPress Site

How to set up HTTPS quickly and for free. Be part of the movement to protect your users’ sensitive information, whether or not you are processing payments on your website. (smashingmagazine.com)

Tools / Resources

How well do you know CSS display?

A detailed post all about CSS display layouts, from the well-known, to the “new kids on the block” like flex and grid, to the relatively obscure and experimental. (chenhuijing.com)

Run npm scripts in a git pre-commit Hook

How to use pre-commit to easily run linting (or whatever npm scripts you want) before code is committed to a git repository. A way to easily improve the consistency and quality of your code. (elijahmanor.com)

Neob

A React/Webpack/(S)CSS Modules/testing application boilerplate. (github.com)

Tips For Improving Your Productivity With Sublime Text (smashingmagazine.com.com)

Inspiration

Medium’s engineering interview process (medium.engineering)

Reimagining Google Fonts (design.google.com)

One video, article or side project can change your life. (medium.com)

Jobs

Web Designer at GitHub

GitHub’s web design team works closely with other designers, product managers, engineers, and our marketing team to design, build and ship inspiring and approachable websites to our growing community of superfans across the world. (github.com)

Front End Developer at Booking.com

We are looking for the world’s best Front End Developers all around the globe. Join us at our beautiful headquarters in Amsterdam and work on planet Earth’s #1 accommodation website with some of the industry’s smartest people. (booking.com)

Have an Web Design related position you need to fill?

From The Blog

WDW Shop

If you enjoy WDW why not check out the store and treat yourself to a few stickers or a t-shirt. (shop.web-design-weekly.com)

Last but not least…

console.frog

Tim Holman taking console.log to the next level. Classic. (tholman.com)

The post Web Design Weekly #241 appeared first on Web Design Weekly.


by Jake Bresnehan via Web Design Weekly

5 Digital Nomad Lessons from Jacob Laukaitis

Jacob Laukaitis Motorbiking

Just a couple of decades ago, a job used to mean so much more than a source of income. Since few jobs could be done effectively without physical presence in the workplace, having a job meant living somewhere nearby. Since offices usually have working schedules (the “eight-to-five”), a job used to define one’s schedule as well. Our friends were mostly our colleagues, just because we spent so much time in a room with them.

But then the Internet revolution happened. Paperwork was no longer on paper — it was on a cloud server. Drawings were no longer born on canvas — they were made with Photoshop. We started having team meetings via Skype calls and began to manage our projects via Trello.

Nostalgic, change-resistant folks will tell you that they miss the good ol’ smell of paper, but you shouldn’t really listen to them, since they’re missing the point. And the point is: you sacrifice the smell of your desk for the smell of a rainforest somewhere in Taiwan, where you spontaneously decided to stay and work for a couple of weeks.

Yes, I’m talking about digital nomads. It’s truly hard to think of another group of people who make better use of what the world has to offer today. Digital nomads have it all: freedom to travel wherever they want, whenever they want; a good, stable income; a flexible work schedule. Of course, it takes work to set everything up, but it’s possible for almost anyone.

Today, I had the pleasure of talking to a purebred digital nomad, Jacob Laukaitis. Just 22 years old, he is a co-founder of ChameleonJohn.com, a fast-growing online coupons website operating in the United States, who has been to 45+ countries over the last three years while running his business online.

We discussed traveling and working, and Jacob shared some of the major realizations that he had during his travels. Here they are:

1. The world is a much safer, more civilized place than it is portrayed to be.

In movies, any place that’s not in the US or Western Europe is probably going to be painted somewhat negatively. If it’s Asia, the main accents will probably be obsession with tradition, lack of technology, and unsanitary food.

If the action takes place in South America or Eastern Europe, the place will probably look poor and devastated from criminal activity, war, and/or oppression.

In the reality of globalization, people live pretty similarly across much of the globe. Sure, there are cultural differences, like jokes, manners and clothes. The buildings might look different. But you’ll find familiar brands or similar products even in the farthest corners of Earth. You’ll find pre-paid phones, hostels, taxis, supermarkets, drugstores, Wi-Fi and Western Union outposts in major cities all around the globe.

Jacob Laukaitis in Asia

2. Experiencing things yourself can be extremely fulfilling and useful.

Not seeing someone else do it, not hearing about it, not reading comments. Doing all the stuff yourself.

Take motorbiking, for example. Inconvenient, dangerous, expensive, impractical due to weather — those are the main reasons people don’t buy motorbikes.

But in Asia, you can rent a bike for as low as $5/day, make an epic trip across the mountains for two weeks, and come back a happier person.

Or there’s surfing. We all know that it should feel awesome, but have you ever tried watching the sunrise on a board, still catching your breath, with the wind caressing your back and your legs in the chill of the ocean? The smell, the sound…

But it’s not all just for pleasure. While traveling, you meet people, you see how they live, you learn how they think. Those experiences offer invaluable lessons that you couldn’t get any other way.

Continue reading %5 Digital Nomad Lessons from Jacob Laukaitis%


by Tomas Šlimas via SitePoint

Single Page Apps Using AngularJS and the WordPress REST API

Automattic is working on integrating the WordPress REST API plugin into the WP core, which means that the API will be available without the actual plugin, and we could see more of WordPress integration with front-end JavaScript frameworks.

This would allow a faster time to market for applications, since some basic functionality that is often implemented from scratch in JavaScript apps is already implemented; we could use WordPress' user management, WooCommerce for product handling, static pages, and the list goes on! It is also possible to add custom endpoints to the API.

One way to use this API would be to include a front-end JS framework as part of a WordPress theme. This can be inconvenient, though, as it enforces a non-standard directory structure and is generally not a best-practice use of either the framework or the WordPress theme.

A better solution is to use a REST API to expose WP data and make two apps that are completely structurally separated, but connected with a "session sharing" technique, in order to use the best from both.

In this tutorial, I will show you how to do this "session sharing", where WordPress is used for user management and login, and on the client-side, an Angular app that allows easy, SPA-like (Single Page Application) post editing for authorized users.

You can find the code for the WordPress child theme and the Angular client app on GitHub:

Requirements

Before starting this tutorial, it is recommended that you already have some experience with the following:

Additionally, we will be using:

  • Vagrant (two virtual machines, one for WP and the other for running the Angular app on a grunt server)
  • Yeoman (to scaffold our Angular app)
  • Grunt

as development tools, but you should be also fine if you use some other way to run your local WP site and other or no scaffolding tool.

A WordPress REST API

In order to achieve our goal architecture, we have to install the WordPress REST API plugin, which is currently in it's beta phase and there are things to consider, see here.

The official recommendation is not to use version 2 in production, as the latest stable version is version 1. Also, the rumor is that the plugin will never get a stable version, but instead when the plugin is ready to move out of beta, it will be released as part of the WordPress core. In this tutorial we will use the version 2 plugin nonetheless.

Authentication

There are several authentication methods that can be used to secure the REST API (see here for details), but let's take a brief look at the pros and cons of each:

Basic Authentication

This is the most basic authentication type, where we would send the username and password in the header with every request. It requires SSL, as otherwise we would open the username and password to attack. Also, we are giving the Client ID and secret to the client.

Cookie Authentication

The standard, built-in wordpress login system also works. The trouble with this approach is that in order to avoid CSRF issues, we have to use it on the inside of WP. Since we need to access the API from outside, from another app, this approach is not for us.

OAuth Authentication

We are going to be using a non-standard way of implementing OAuth here. We will not let the user authorize an application explicitly, but instead we will seamlessly hook into the WordPress login function, authorize our Angular app for the user and retrieve an access token, which we forward to the JS app in order to authorize the API requests.

It's very important to mention that, even with this approach, we need SSL. Since this is an educational tutorial we will not be introducing the complexity of SSL even though, regarding the code itself, there would be no difference with or without SSL.

This approach should be preferred over basic auth, since we do not have to store the username and password of the user in the browser or give the Client ID and Secret to the user. The OAuth approach is only possible with a plugin, and for this reason we are going to use WP OAuth Server.

Sharing the Token

After we generate the token upon logging in to WP, we need to somehow share it with our JS app. There are multiple ways to do this, depending on your needs and personal preferences. In this tutorial we will describe two of these approaches. It's worth mentioning that both of these approaches might be constrained by browser version.

Setting Wildcard Domain Cookie

The first option, which is possible only if both apps are on same subdomain, is to set a wildcard cookie and then use that cookie on Angular side. If using this approach, it's important to take care of your local hosts file, in order to have the same subdomain.

I personally use Vagrant and Vagrant host manager, and then set the hostname of the WordPress VM to sitepoint.local and the other Vagrant VM's hostname to app.sitepoint.local. This will automatically edit your hosts file like this:

192.168.33.16  app.sitepoint.local  # VAGRANT: 297067a67f66f631aa1962e3b49ab73c (default) / cc52bb5a-3972-4b55-8e0c-0c805b9c6f1c
192.168.33.15  sitepoint.local  # VAGRANT: 6a5b8c757547fe9f0a32a0c747a91a79 (default) / b08c3e7d-cba8-4130-a11b-b26494574280

This is the approach we will use in this tutorial, but if you feel that this is an additional complication for you, consider the iframe option.

Posting to localStorage via iframe

This approach is better for someone who wants to avoid handling cookies and/or does not have the WP app and Angular app on same sub-domains. We expose an iframe from the SPA to WP and then we post a message to the iframe, inside which there is a listener waiting for incoming messages to take the access token and store it in the JS app's localStorage, for later use. I will explain the modifications needed in a separate section at the end of the article. See here for browser compatibility.

The Server

First we are going to create a template for the login screen containing the code to generate the access token. Then, we will hook into some login/logout functions in order to handle the cookie (or iframe, if you go with that option).

Create the server VM

Time to grease some elbows! I like starting out a WordPress project by cloning the Scotchbox Vagrantfile .

Open your favorite terminal application and navigate to the folder where you wish to keep the project. In my case this is /boxes. Then, clone the Scotchbox repo and navigate inside.

cd /boxes
git clone http://ift.tt/1uFOPMK sitepoint-wp-rest-api
cd sitepoint-wp-rest-api

# remove .git folder in order not to get confused if you later initialise your own repository
rm -rf .git

# Initialise a vagrant machine
vagrant up

At this point, you may want to open the sitepoint-wp-rest-api folder in your favorite IDE or text editor, since we need to edit the Vagrantfile.

This is how the Vagrantfile looks by default when cloned:

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|

    config.vm.box = "scotch/box"
    config.vm.network "private_network", ip: "192.168.33.10"
    config.vm.hostname = "scotchbox"
    config.vm.synced_folder ".", "/var/www", :mount_options => ["dmode=777", "fmode=666"]

    # Optional NFS. Make sure to remove other synced_folder line too
    #config.vm.synced_folder ".", "/var/www", :nfs => { :mount_options => ["dmode=777","fmode=666"] }

end

There are two thing to take care of here:

  1. Change the IP
  2. Change the hostname

In case you already have a network device or another VM running on 192.168.33.10, make sure to change that. You can choose any IP address as long as it's in the private address space.

If you want to use the approach with sub-domain cookie, it is also important to change the hostname to a FQDN.

Optional: You can also increase the RAM/CPU of the VM. This can be especially handy later for the second VM ,when we will need to run bash npm install - it will take less time if we increase the performance of the VM. Check the commented-out part at the end of the code snippet for how to achieve this. Although it's sometimes good to see how the system runs on 512MB RAM and 1 CPU (Vagrant's default), for development purposes we want it to be fast. Later when testing/optimizing speed of the WP site, you can tune this down again.

The final Vagrantfile looks like this

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|

    config.vm.box = "scotch/box"
    config.vm.network "private_network", ip: "172.31.255.254"
    config.vm.hostname = "sitepoint-wp-rest-api.test"
    config.vm.synced_folder ".", "/var/www", :mount_options => ["dmode=777", "fmode=666"]

    # Optional NFS. Make sure to remove other synced_folder line too
    #config.vm.synced_folder ".", "/var/www", :nfs => { :mount_options => ["dmode=777","fmode=666"] }

    # Optional performance tweaking
    #config.vm.provider "virtualbox" do |v|
    #   v.memory = 2048
    #   v.cpus = 2
    #end
end

One last step before we turn on the VM: the vagrant-hostupdater plugin install. What this plugin does is, when you run vagrant up, it updates your local hosts file with the IP and hostname given in the Vagrantfile, you will see what that means in a few moments.

# Install Vagrant host udpater plugin
vagrant plugin install vagrant-hostsupdater

Now it's time to boot up the machine:

vagrant up

You may get asked for the sudo password since vagrant-hostupdater will be editing the /etc/hosts file, which requires admin permissions.

This will take a minute (or a few minutes!) depending on whether you already have the scotch/box image locally - it has to be downloaded first if you do not.

Now, visit http://172.31.255.254/ and you should see the Scotchbox information page (what you actually see is the index.php located in the public folder of the cloned Scotchbox repository).

The result of what the hostupdater plugin did can be seen if you visit http://ift.tt/28YusYP - it's still the same page. Sitepoint-wp-rest-api.test resolves to 172.31.255.254 via your local hosts file. From now on we will use this FQDN to access our REST API.

Install WordPress

Now that we have a server running, it's time to install WordPress. Go into your local user's folder and download WordPress. Unpack it, create a configuration file and then copy raw files to the public folder inside of sitepoint-wp-rest-api.

cd ~
curl -OL http://ift.tt/zUVk1t
tar xzvf latest.tar.gz
cd ~/wordpress
cp wp-config-sample.php wp-config.php

# Do not forget to change /boxes to the actual folder onb *your* system
sudo rsync -avP ~/wordpress/ /boxes/sitepoint-wp-rest-api/public

Now, head back to your IDE and open wp-config.php. Fill in the DB credentials as found here. Additionally, it is a good practice to add WP_HOME and WP_SITEURL variables in the configuration files. They will override the values from the database, making it easier for versioning and changing between environments/hosts.

// wp-config.php

/** The name of the database for WordPress */
define('DB_NAME', 'scotchbox');

/** MySQL database username */
define('DB_USER', 'root');

/** MySQL database password */
define('DB_PASSWORD', 'root');

/** This is new, WP SiteURL and Home globals override */
define('WP_SITEURL', 'http://ift.tt/28YusYP');
define('WP_HOME', WP_SITEURL);

Change these values, and save the file.

Visit http://ift.tt/28YusYP again, and this time you should see a WordPress install wizard.

WordPress install - step 2

Click next a few times and finally you should see a default WP site with the twentysixteen theme running.

Install the REST API plugin

Head to the WordPress REST API plugin page and download the plugin. Unzip the downloaded file and copy it to wp-content/plugins/. Go to http://ift.tt/28YuEXW, click Plugins on the left menu, find WordPress REST API and activate it. No additional configuration or setup is needed for the API - it just works!

Now, if you visit http://ift.tt/28ZaXeK you should get a JSON array containing all the posts:

Continue reading %Single Page Apps Using AngularJS and the WordPress REST API%


by Almir Bijedic via SitePoint

Quick Read: Blockchain’s Future after Bitcoin

In January 2016, fellow Bitcoin developer, Mike Hearn, dropped the bomb — Bitcoin has failed. While "failing" might be a bit overdramatic, his reasoning is far from an overstatement. Hearn explained why Bitcoin and its community has failed like so:

What was meant to be a new, decentralized form of money that lacked “systemically important institutions” and [was] “too big to fail” has become something even worse: a system completely controlled by just a handful of people. Worse still, the network is on the brink of technical collapse. The mechanisms that should have prevented this outcome have broken down, and as a result there’s no longer much reason to think Bitcoin can actually be better than the existing financial system.

What happened? Essentially, Bitcoin's blockchain is full. An artificial capacity cap of one megabyte per block, utilized as a temporary kludge a long time ago, has not been removed and results to the network’s capacity to be almost completely exhausted.

As an effect, over 95% of Bitcoin mining hashing power is controlled by a handful of people.

But What About The Blockchain?

Bitcoin is to blockchain what currency is to money. Just because a certain currency has failed, doesn't mean money has failed.

Blockchain logo

Continue reading %Quick Read: Blockchain’s Future after Bitcoin%


by Elio Qoshi via SitePoint

Angular 2 Tutorial: Create a CRUD App with Angular CLI

Angular 2 is an open source framework for building mobile and desktop applications.

Rather than a successor of AngularJS 1.x, Angular 2 can be considered an entirely new framework built on learnings from AngularJS 1.x. Hence the name change where Angular is used to denote Angular 2 and AngularJS refers to AngularJS 1.x. In this article we will use Angular and Angular 2 interchangeably but they both refer to Angular 2.

In this article we'll be building an Angular 2 Todo web application that allows users to:

  • quickly create new todo's using an input field and hitting the enter key
  • toggle todo's as complete or incomplete
  • remove todo's that are no longer needed

Animated GIF of finished Angular 2 tutorial application

Here is a live demo of the application we will be building.

All code is publicly available right here so feel free to fork and play with the code yourself.

Let's get started!

The Angular CLI

One of the easiest ways start a new Angular 2 application is to use the brand new Angular command-line interface (CLI) that allows you to:

  • generate boilerplate code for new Angular 2 applications
  • add features (components, directives, services, pipes, etc) to existing Angular 2 applications

To install Angular CLI, run:

$ npm install -g angular-cli

which will install the ng command globally on your system.

To verify whether your installation completed successfully, you can run:

$  ng version

which should display the version you have installed.

You can visit the official installation notes for more information if needed.

Generating Our Todo Application

Now that we have Angular CLI installed, we can use it to generate our Todo application:

$ ng new angular2-todo-app

This will create a new directory for us with everything we need to get started:


├── angular-cli-build.js
├── angular-cli.json
├── config
│   ├── environment.dev.ts
│   ├── environment.js
│   ├── environment.prod.ts
│   ├── karma.conf.js
│   ├── karma-test-shim.js
│   └── protractor.conf.js
├── e2e
│   ├── app.e2e-spec.ts
│   ├── app.po.ts
│   ├── tsconfig.json
│   └── typings.d.ts
├── package.json
├── public
├── README.md
├── src
│   ├── app
│   │   ├── app.component.css
│   │   ├── app.component.html
│   │   ├── app.component.spec.ts
│   │   ├── app.component.ts
│   │   ├── environment.ts
│   │   ├── index.ts
│   │   └── shared
│   │       └── index.ts
│   ├── favicon.ico
│   ├── index.html
│   ├── main.ts
│   ├── system-config.ts
│   ├── tsconfig.json
│   └── typings.d.ts
├── tslint.json
├── typings
│   └── ...
└── typings.json

You can now:

# enter new directory the CLI created for you
$ cd angular2-todo-app

# start the development server
$ ng serve

which will start a local development server that you can navigate to in your browser on http://localhost:4200/.

The application will automatically reload when a source file has changed.

How convenient is that!

Angular Ingredients

Angular CLI already generated the entire Angular 2 application boilerplate for us when we used the ng new command. But it doesn't stop there. It can also help us add ingredients to our existing Angular application using the ng generate command:

# Generate a new component
$ ng generate component my-new-component

# Generate a new directive
$ ng generate directive my-new-directive

# Generate a new pipe
$ ng generate pipe my-new-pipe

# Generate a new service
$ ng generate service my-new-service

# Generate a new class
$ ng generate class my-new-class

# Generate a new interface
$ ng generate interface my-new-interface

# Generate a new enum
$ ng generate enum my-new-enum

If you are not familiar with the basic building blocks of an Angular 2 application, it is highly recommended that you read the Angular 2 QuickStart first.

To meet the needs of our Todo application, we will need:

  • a Todo class to represent individual todo's
  • a TodoService to create, update and remove todo's
  • a TodoApp component to display the user interface

So let's add these ingredients one by one.

Creating the Todo Class

Because we use TypeScript, we can use a class to represent Todo items, so let's use Angular CLI to generate a Todo class for us:

$ ng generate class Todo

which will create:

src/app/todo.spec.ts
src/app/todo.ts

Let's open up src/app/todo.ts and replace its contents with:

export class Todo {
  id: number;
  title: string = '';
  complete: boolean = false;

  constructor(values: Object = {}) {
    Object.assign(this, values);
  }
}

Each Todo item has 3 properties:

  • id: number, unique ID of the todo item
  • title: string, title of the todo item
  • complete: boolean, whether or not the todo item is complete

The constructor logic allows us to specify property values during instantiation:

let todo = new Todo({
  title: 'Read SitePoint article',
  complete: false
});

In fact, Angular CLI generated src/app/todo.spec.ts for us so let's add a unit test to make sure the constructor logic works as expected:

import {
  beforeEach, beforeEachProviders,
  describe, xdescribe,
  expect, it, xit,
  async, inject
} from '@angular/core/testing';
import {Todo} from './todo';

describe('Todo', () => {

  it('should create an instance', () => {
    expect(new Todo()).toBeTruthy();
  });

  it('should accept values in the constructor', () => {
    let todo = new Todo({
      title: 'hello',
      complete: true
    });
    expect(todo.title).toEqual('hello');
    expect(todo.complete).toEqual(true);
  });

});

To verify whether our code works as expected, we can now run the unit tests:

Continue reading %Angular 2 Tutorial: Create a CRUD App with Angular CLI%


by Todd Motto via SitePoint

Can Symfony Apps Be Fast on Vagrant? Let’s Check with SuluCMS!

In this short tutorial, we’ll set up Sulu and optimize on a Vagrant environment. Why a dedicated tutorial handling this? Besides the fact that Sulu has a rather complex initialization procedure, it is based on Symfony which is infamously slow on virtual machines with shared filesystems, and thus needs additional optimizations post-install. The performance hacks in this post, while Sulu-specific, can be applied to any Symfony application to make it faster on Vagrant.


Would you like to learn more about Symfony and/or SuluCMS? Come join us at WebSummerCamp - the only conference filled to the brim with long, hands-on workshops. The program is out and it’s awesome! Super early bird tickets available until the end of June!


sulu logo

As usual, we’ll be using our Homestead Improved box as the base, but the steps below are explained in enough detail for you to follow them on any environment.

New Box and Folder Sharing

We start by downloading a fresh box and setting up folder sharing.

git clone https://github.com/swader/homestead_improved hi_sulu
cd hi_sulu; bin/folderfix.sh

Once this is done, it’s recommended to set the file sharing type to nfs, due to this known issue, also described here.

Continue reading %Can Symfony Apps Be Fast on Vagrant? Let’s Check with SuluCMS!%


by Bruno Skvorc via SitePoint