Code Monkey home page Code Monkey logo

dna-engine's Introduction

dna-engine

logo

An uncomplicated user interface library for cloning semantic templates

License:MIT npm Hits Build

dna-engine is a lightweight easy-to-use UI library enabling developers to rapidly build maintainable JavaScript applications.

A) Bookstore Example

Designate templates with the dna-template class, and put the templates directly into the HTML of your web page.  Use the element's id to indicate the name of the template.  Enclose data fields in double tildes ~~.

1. HTML for book template

<h1>Featured Books</h1>
<section class=books>
   <div id=book class=dna-template>
      <h2>~~title~~</h2>
      Author: <cite>~~author~~</cite>
   </div>
</section>

Then call the dna.clone() function to insert a copy of the template into the DOM.  The supplied JSON data object populates the fields of the template.

2. JavaScript call to add book node

dna.clone('book', { title: 'The DOM', author: 'Jan' });

The new clone element replaces the template.  The original template is detached from the DOM and kept for additional cloning.

3. Resulting HTML with clone

<h1>Featured Books</h1>
<section class=books>
   <div class=book>
      <h2>The DOM</h2>
      Author: <cite>Jan</cite>
   </div>
</section>

Need to clone the template multiple times?  Simply pass an array of data objects into the dna.clone() function.

B) Additional Information

C) Contributor Notes

To be a contributor, fork the project and run the commands npm install and npm test on your local clone.  Make your edits and rerun the tests.

Pull requests welcome.  Since the pacakge version number is updated during the release process, you can leave the version number unchanged.

D) Build Environment

Check out the runScriptsConfig section in package.json for an interesting approach to organizing build tasks.

CLI Build Tools for package.json

  • 🎋 add-dist-headerPrepend a one-line banner comment (with license notice) to distribution files
  • 📄 copy-file-utilCopy or rename a file with optional package version number
  • 📂 copy-folder-utilRecursively copy files from one folder to another folder
  • 🪺 recursive-execRun a command on each file in a folder and its subfolders
  • 🔍 replacer-utilFind and replace strings or template outputs in text files
  • 🔢 rev-web-assetsRevision web asset filenames with cache busting content hash fingerprints
  • 🚆 run-scripts-utilOrganize npm package.json scripts into named groups of easy to manage commands
  • 🚦 w3c-html-validatorCheck the markup validity of HTML files using the W3C validator


Feel free to submit questions at:
github.com/dna-engine/dna-engine/issues

dna-engine is open source under the MIT License.  The website and documentation are published under the CC BY-SA 4.0 license.

dna-engine's People

Contributors

aalpar avatar adzo261 avatar bykiandra avatar calvinsettachatgul avatar dependabot[bot] avatar dilekuzulmez avatar dmwesterhoff avatar dpilafian avatar feargalobo avatar geekgirl2017 avatar giteshk11 avatar hcamdclk8 avatar jlangdesign avatar likannp avatar mcglaser avatar milroc avatar mindheist avatar mmoorebrg avatar mtchllng avatar nikmijic avatar oozygrub avatar paulord avatar prakal avatar rjayroso avatar selva-oscura avatar tcco avatar teddytesafa avatar thisisjeron avatar timgluz avatar tpduong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dna-engine's Issues

Add support for simple (literal) arrays

It would be useful to clone from an array of simple values.

Example usage:

<div id=book class=dna-template>
   Title #<span>~~[count]~~</span>: <span>~~[value]~~</span>
</div>
dna.clone('book', ['CSS3', 'HTML5']);

result:

<div>Title #<span>1</span>: <span>CSS3</span></div>
<div>Title #<span>2</span>: <span>HTML5</span></div>

Support transform as a passed in option

Currently, data transformation functions are specified in HTML:

<div id=book class=dna-template data-transform=enhanceBook>

It might be more intuitive in JS:

dna.clone('book', books, { transform: enhanceBook });

Undefined variable.

dna.js: line 311, col 7, 'sessionStorage' is not defined.
dna.js: line 317, col 19, 'sessionStorage' is not defined.

Add error checking for missing data parameter

If the data field is missing when cloning a template, the current error message is very confusing. There should be an clear, explicit error message when data is undefined.

const data = undefined;
dna.clone('book', data);  //should immediately throw an error

Use non global functions from templates

Hey guys, I was checking the docs, but I can't find a way to use a function in the data-click (or any attribute that expects a function) that is not exposed to the window object. I'm using webpack to ship my files so I don't use object namespaces (like window.MyApp.module.func). Any help is appreciated, Thanks!

Support smart update at the template level

Currently, smart update callbacks are specified at the element level:

<input value=~~title~~ data-smart-update=saveTitle>

This often necessitates annotating many input tags in the template with data-smart-update (or data-change).

It would be more convenient to annotate higher up at the template level:

<div id=book class=dna-template data-smart-update=saveBook>

The callback could be sent the clone's updated data model and the input element that triggered the update:

const saveBook = (dataModel, targetElem) => { ... }

https://dnajs.org/docs/#event-smart

Add support for HTML5 values like "color" in type attribute of input tags

Currently data-attr-type only supports the value date. We need to add support for color, time, etc.

Example:

<input data-attr-type=color value=~~profileColor~~>

becomes

<input type=color value=#DAA520>

Note:

<input type=color value=~~profileColor~~>

results in the warning:
The specified value "~~profileColor~~" does not conform to the required format. The format is "#rrggbb" where rr, gg, bb are two-digit hexadecimal numbers.

Conditionals

Are you planning on adding new features? I'd suggest adding simple support for conditionals, something like

<div>
   <h2>Featured Books</h2>
   <div id=book class=dna-template>
      <div>Title:  <span>~~title~~</span></div>
      ~~#author?~~<div>Author: <span>~~author~~</span></div>~~/author?~~
   </div>
</div>

to check if some object is missing or empty and act in consequence.

That would be really helpful for prototyping ;)

Need new logo for dna.js open source project

Logo Design Contest

The current project logo for dna.js is pretty uninspiring and is just a placeholder until a real graphic artist creates an inspiring logo.

dnajs-logo
dnajs-logo.png

Logo Goals:

  1. Clean, simple, and modern
  2. Scalable so it looks good at different sizes
  3. Incorporation of an animal mascot would be cool (but not required)
  4. Slots nicely into the dna.js website: dnajs.org

Some words for design inspiration:
Clone, template, DNA, data, easy, clean, fast, JavaScript, HTML, jQuery

The artist who's logo is used for the project will get recognized on the dna.js website with a link to your portfolio (and if you can get to San Francisco, a drink of your choice plus an Apple Store Gift Card for a hundred dollars).

Attach your artwork to this GitHub issue. Also, feel free to post any questions or comments below.

Important Note:
dna.js is an open source project and graphics contributed to the project are licensed under MIT/GPL.

Redefinition of 'dna' on line 5.

Problem description:

[15:09:40] Starting 'default'...
[15:09:40] Finished 'default' after 15 μs
[15:09:40] Size dna.min.js : 16.06 kB
dna.js: line 5, col 5, Redefinition of 'dna'.

1 error

Problem fixed when:

There is no redefinition of dna.

Add function to check if template exists

Create a new function dna.templateExists() to support checking if a template exists before cloning the template.

Example usage:

if (dna.templateExists('book'))
   dna.clone('book', { title: 'JavaScript: The Good Parts' });

Create dna.templateExists() function in dna.js

Add a new function dna.templateExists() to check if a template is present.

Below are the steps to follow to build this feature using Test-Driven Development (TDD).

1. Verify all existing tests pass

$ npm test

2. Create a test case in spec/dom.js for the new feature
Add this code:

describe('Function dna.templateExists()', () => {
   it('identifies if a template is present', () => {
      const actual =   [dna.templateExists('book'), dna.templateExists('bogus')];
      const expected = [true, false];
      assert.deepEqual(actual, expected);
      });
   });

3. Verify the new test case FAILS
The feature is not built yet, but you can still run the test case:

$ npm test

4. Create the new function in dna.js
At line 71, insert:

templateExists: (name) => {
   return !!dna.store.templates[name] || $('.dna-template#' + name).length > 0;
   },

5. Verify the new test case PASSES

$ npm test

template rendering bug ?

Hello,

i just began to "play" with dna.js, and i find it is great
but i think i may have found a bug, or at least something i do not understand.

in the attached example, ( test.txt - to be renamed as test.html )
the second template is rendered AFTER the last HR despite it is positioned before.
and more, if you remove or comment the last HR the template is not rendered at all !

tested on firefox and chromium.
reproduce problem with dna.js 1.3.4 and 1.3.7

test.txt

Nesting (dots) breaks updating

Hello,

dna.js worked great for me until i tried to use nested objects. I see there is a TODO at Spec runner source code. Is it easy to implement? It would be really cool if i won't have to flatten all nested object from model to allow editing through input fields.

Thanks!

select data-option

Hi,
in a select, when I use data-option doesn't work. This is the error:

dna.js:672 Uncaught TypeError: Cannot read property 'option' of undefined
at updateModel (dna.js:672)

If I use data-dnaRules-option works....

Could be a bug here?

...... else if (target.is('input') || target.data().dnaRules.option)

Convert spec.js to ES6

convert spec.js to ES6.
-- var to let or const (as appropriate)
-- require to import (not yet supported natively in Node (not supported in V8); would need to wait for next engine or babel-ify the tests)

Use case: conditionals on array being populated

First off - I'm really liking this library so far - I find it very easy to grok!

This may be a bit off topic, and I apologise if I missed something in the docs, but how would you conditionally show or hide something based on whether an array was populated or not. I can see this is available at the field level using the data-require attribute, but what if you wanted to show a button to remove all cloned elements, but only if elements had been cloned.

Is there a way with dnajs? I'm used to angular, where this functionality is available using the native ng-show and ng-hide directives.

Cheers, Rob

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.