Giter VIP home page Giter VIP logo

metalsmith-servercomponents's Introduction

Metalsmith ServerComponents

A Metalsmith plugin for lightweight server-side custom HTML elements.

This plugins enables the usage of custom HTML elements – broadly following the spec – in Metalsmith projects.

Installation

Install in your metalsmith project using:

npm install metalsmith-servercomponents

Usage

To use it, add a custom components defined with the ServerComponents-API to your projects components folder.

// File: components/hello-world.js
module.exports = function(components) {
	var StaticElement = components.newElement();
	StaticElement.createdCallback = function () {
		this.innerHTML = "Hello world";
	};
	components.registerElement("hello-world", { prototype: StaticElement });
};

In your Metalsmith build script add the ServerComponents plugin.

// File: build.js
var Metalsmith = require('metalsmith');
var components = require('metalsmith-servercomponents');

Metalsmith(__dirname)
  .source('./src')
  .destination('./build')
  .clean(false)
  .use(components())
  .build(function(err, files) {
    if (err) { throw err; }
  });

Every occurence of the custom components you defined in your source files will be replaced by an instantiated entity.

<!-- File src/index.html -->
<!doctype html>
<html lang=en>
<head>
	<meta charset=utf-8>
	<title>Foobar</title>
</head>
<body>
	<hello-world />
</body>
</html>

…is converted to…

<!-- File src/index.html -->
<!doctype html>
<html lang=en>
<head>
	<meta charset=utf-8>
	<title>Foobar</title>
</head>
<body>
	<hello-world>Hello world</hello-world>
</body>
</html>

You can use the whole custom component API to define components, refer to the example components to see what is possible.

To Do

  • Handle styles per component: from unnamespaced, plain (S)CSS to automatically namespaced BEM selectors
  • Handle clientside JS per component

metalsmith-servercomponents's People

Contributors

bfncs avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.