Code Monkey home page Code Monkey logo

html4j's Introduction

#HTML4J# ##Developed by Eyeballcode##

Here's how to use it:

HTML html = new HTML();
BODY body = new BODY();
html.addElement(body);

This makes the basic framework for everything.

A link = new A();
link.href = "http://github.com/Eyeballcode";
body.addElement(link);

Up to this point, no real work is done. To get the source, do

String source = html.getSource(0);

The 0 is to tell the API the initial indentation. We normally start with 0, but you can use whatever you want.


Here's how to have your own element:

  1. Define a class for the element

public class MyHTMLElement extends HTMLElement

Now, declare all the methods using whatever you want. The most important is:

public String getElementTagName();

The value is what comes out in the HTML. So returning hello results in <hello></hello>

For getSource(int spaces), I use SourceHelper.getSource(spaces, this) as it helps reduce and dry code.

  1. Define your own attributes

Now we made a class. Cool! But...

<hello myName="eyeball" location="Singapore" id="helloText" class="myCSSClass"></hello>

How do we do that? Good question! Put this in your element's class:

@Attribute
public String myAttribute = "";
// The field's name is the attribute's name!

Simple! Now when generating the source, it does:

  • Get everything with @Attribute and store it in an array
  • Go through each field.
  • If it is empty or null, skip.
  • Otherwise append it the the tag and it's value. Done!

Happy hacking away...

html4j's People

Contributors

eyeballcode avatar

Watchers

James Cloos 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.