Coder Social home page Coder Social logo

jsonbuilder's Introduction

JSONBuilder

Build JSON files into static HTML

Example

// create new JSONBuilder object and set it render on document.body
const renderer = new JSONBuilder({
    attachTo: document.body
});

// create basic page
const _page = {
  tag: 'div',
  attributes: [{ name: 'style', value: 'color: blue;' }],
  classes: ['class1', 'class2', 'class3  class4'],
  children: [
    {
      tag: 'p',
      id: 'my-paragraph',
      children: ['Basic paragraph element']
    }
  ]
}

// mount our JSON code
renderer.mount(_page)

Elements

  • tag: the HTML tag to be used, defaults to jsb-element
  • attributes: each attributes to be applied to the element [{ name: '', value: ''}, ...]
  • classes: an array of each class to be applied to the element
  • children: an array of elements defined in a similar style
  • id: the ID to apply to the element

Special Properties

  • import: (syntax: { import: [_other_code_here_usually_from_another_file_] }) used to embed code from other files in page
  • read: (syntax: { read: [_atom_code_from_other_file_] }) used to read "atoms" (or small template elements defined by using only the atom property in an exported JSON object)
// other file
export const btn_primary = {
    atom: {
        tag: 'btn1',
        classes: ['btn_primary']
    }
}

// page file
import { btn_primary } from './other_file.js';

export default {
  tag: 'div',
  children: [
    { read: [btn_primary] } 
  ]
}

Notes

Licensed under the MIT license. See ./LICENSE for more information.

jsonbuilder's People

Contributors

0aoq 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.