-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
executable file
·282 lines (265 loc) · 18.8 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
<html><head>
<!--
This file autogenerated by docbat.js (https://npmjs.com/docbat)
Any manual edits may be lost.
-->
<link rel="stylesheet" href="https://unpkg.com/@highlightjs/cdn-assets@11.7.0/styles/default.min.css">
<script src="https://unpkg.com/@highlightjs/cdn-assets@11.7.0/highlight.min.js"></script>
<script>hljs.highlightAll();</script>
<style>
*{box-sizing:border-box;}
.bw-def-page-setup{height:100%;width:90%;margin:0 auto;padding-left:2%;padding-right:2%;left:0;top:1%;box-sizing:border-box;}
.bw-font-serif{font-family:Times New Roman, Times, serif;}
.bw-font-sans-serif{font-family:Arial, Helvetica, sans-serif;}
.bw-left{text-align:left;}
.bw-right{text-align:right;}
.bw-center{text-align:center;margin:0 auto;}
.bw-justify{text-align:justify;}
.bw-code{font-family:monospace;white-space:pre-wrap;}
.bw-pad1{padding-left:1%;padding-right:1%;}
.bw-table{border-collapse:collapse;border-spacing:0;border:1px solid #444;}
.bw-table th{background-color:#bbb;padding:4px;border:1px solid #444;}
.bw-table td{padding:4px;border:1px solid #444;}
.bw-table-stripe tr:nth-child(even){background-color:#f0f0f0;}
.bw-table tr td:first-child{font-weight:700;}
.bw-table-border-round{border-radius:2px;}
.bw-table-sort-upa::after{content:"\2191";}
.bw-table-sort-dna::after{content:"\2193";}
.bw-table-sort-xxa::after{content:"\00a0";}
.bw-tab-item-list{margin:0;padding-inline-start:0;}
.bw-tab-item{display:inline;padding-top:0.5em;padding-left:0.75em;padding-right:0.75em;border-top-right-radius:7px;border-top-left-radius:7px;}
.bw-tab-active{font-weight:700;}
.bw-tab:hover{cursor:pointer;font-weight:700;}
.bw-tab-content-list{margin:0;padding-top:0.0em;}
.bw-tab-content{display:none;border-radius:0;}
.bw-tab-content, .bw-tab-active{background-color:#ddd;padding:0.5em;}
.bw-accordian-container > div{padding:0.5em;}
.bw-container{margin:0 auto;}
.bw-row{width:100%;display:block;}
.bw-row [class^="bw-col"]{float:left;}
.bw-row::after{content:"";display:table;clear:both;}
.bw-box-1{padding-top:10px;padding-bottom:10px;border-radius:8px;}
.bw-sign{position:inherit;display:table;height:100%;width:100%;}
.bw-sign > div{display:table-cell;vertical-align:middle;}
.bw-sign > div > div{text-align:center;}
.bw-hide{display:none;}
.bw-show{display:block;}
.bw-h1{font-size:2.312rem;}
.bw-h2{font-size:1.965rem;}
.bw-h3{font-size:1.67rem;}
.bw-h4{font-size:1.419rem;}
.bw-h5{font-size:1.206rem;}
.bw-h6{font-size:1.025rem;}
.bw-col-1{width:8.333%;}
.bw-col-2{width:16.666%;}
.bw-col-3{width:25%;}
.bw-col-4{width:33.333%;}
.bw-col-5{width:41.666%;}
.bw-col-6{width:50%;}
.bw-col-7{width:58.333%;}
.bw-col-8{width:66.666%;}
.bw-col-9{width:75%;}
.bw-col-10{width:83.333%;}
.bw-col-11{width:91.666%;}
.bw-col-12{width:100%;}
.bw-color-color {color:#000}
.bw-color-background-color {background-color:#ddd}
.bw-color-active {active:#222}
.bw-thm-light
{
color: #020202 !important;;
background-color: #e2e2e2 !important;;
}
.bw-thm-dark
{
color: #e2e2e2 !important;;
background-color: #020202 !important;;
}
@media only screen and (min-width: 540px) {.bw-def-page-setup {width: 96%;}}
@media only screen and (min-width: 720px) {.bw-def-page-setup {width: 92%;}}
@media only screen and (min-width: 960px) {.bw-def-page-setup {width: 88%;}}
@media only screen and (min-width: 1100px){.bw-def-page-setup {width: 86%;}}
@media only screen and (min-width: 1600px){.bw-def-page-setup {width: 84%;}}
</style><style>
.dbat {padding-left: 10%; padding-right: 10%;}
</style><link rel="stylesheet" href="https://unpkg.com/@highlightjs/cdn-assets@11.7.0/styles/default.min.css">
<script src="https://unpkg.com/@highlightjs/cdn-assets@11.7.0/highlight.min.js"></script>
<script>hljs.highlightAll();</script>
</head>
<body class="bw-def-page-setup bw-font-sans-serif dbat" ><br><br><p><a href="https://opensource.org/licenses/BSD-2-Clause"><img src="https://img.shields.io/badge/License-BSD%202--Clause-blue.svg" alt="License"></a>
<a href="https://www.npmjs.com/package/bitwrench"><img src="https://img.shields.io/npm/v/bitwrench.svg?style=flat-square" alt="NPM version"></a>
<a href="https://travis-ci.org/deftio/fifostr"><img src="https://travis-ci.org/deftio/bitwrench.svg?branch=master" alt="Build Status"></a></p>
<p><a href="http://www.deftio.com/bitwrench"><img src="./images/bitwrench-logo-med.png" alt="bitwrench"></a></p>
<h2 id="welcome-to-bitwrenchjs">Welcome to bitwrench.js</h2>
<p>bitwrench.js is a javascript library for for creating quick demos with almost no depedancies. With bitwrench one can create web pages and components with pure json or javascript dictionaries including handlers (e.g. onclick="...code.." ==> onclick:function_ref, css , etc. )
bitwrench.js also has handyman functions such as loremIpsum generation, ranged random numbers and interpolaters, and color blenders. Use it for throwing up quick web pages which don't depend on any server side framework but need a little prettyifcation or for visualizing quick data. For example when debugging C/C++ embedded projects where we don't want to clutter the build dirs with lots of "weird web stuff" - just write a simple HTML page with bitwrench and still load and view raw text files, JSON, arrays and other bits of embedded files with no extra dependancies.</p>
<p>For those used to modern frameworks such as react / vue / svelte etc. bitwrench.js comes from a pre 2011 time period - so it has more of a jquery like feel, but with a declaritve syntax. See example code and page below for more. bitwrench.js does work in older browsers such Internet Explorer (v7 and later).</p>
<h3 id="features">Features</h3>
<ul>
<li><strong>HTML quick emits</strong> -- create HTML objects either client or server side from pure JSON. useful for making quick components or dynamic content w/o any inline HTML<ul>
<li>html(["div", {class:"class1 class2", onclick:"myFunction(this)","This is the content"}] </li>
<li>DOM selects and applies e.g. <ul>
<li>bw.DOM("h3","tada") // set all "h3" tags to have the content "tada"</li>
<li>bw.DOM(".myClass",function(x){... do something on each element described by CSS selector .myClass})</li>
</ul>
</li>
<li>supports "deep" hieararchical JSON constructs and arrays</li>
<li>registerFunction abilities allow functions to be passed statically to HTML elements (see docs)</li>
<li>Useful as a "onefile" framework which an interpret rich JSON in to full web pages.</li>
</ul>
</li>
<li><strong>Color conversions and interpolation</strong><ul>
<li>RGB, RGBa, HSL, HSLa, and theme generation both as numeric values also as CSS outputs</li>
</ul>
</li>
<li><strong>setting/getting cookies</strong> </li>
<li><strong>pretty printing json</strong></li>
<li><strong>Saving/Loading application data files</strong> (works in both browser or node)<ul>
<li>save / load files as raw or JSON</li>
</ul>
</li>
<li><strong>Getting URL parameters with defaults</strong><ul>
<li>simple parsing of URL params, also can be used for command line scripts, also packs simple dicts back to URLs. note that this functionality predated modern URL libs so you might want to use those for modern apps. However bitwrench versions do work on old browers such as IE8 and iPodTouch 4th generation</li>
</ul>
</li>
<li><strong>Data manipulation functions</strong> and other "random" things <ul>
<li>numeric interpolation & clipping</li>
<li>create multi-d arrays</li>
<li>random(4,11) ==> put out a random number in the range 4-11, also provides multidim arrays of random numbers useful for testing tables etc</li>
<li>prandom() ==> pseudorandom numbers with range settings, also provides multidim arrays of random numbers useful for testing tables etc</li>
</ul>
</li>
<li><strong>Logging</strong> with time-stamps, messaging, and pretty printing (raw, HTML, and text) <ul>
<li>Logging also has auto dissolve so one can log a process and then dump later or suppress in 'production'</li>
</ul>
</li>
<li><strong>Built-in docString parsing</strong> with extraction support <ul>
<li>bitwrench.js self-documents in that from the browser DOM one can pull out a given function's doc strings such as bw.docString("DOM") ==> gives docString inforfor that function.</li>
<li>note that bitwrench.min.js strips comments so built-in help is not available.</li>
</ul>
</li>
</ul>
<p>There is no great structure here, just a bunch of kitchen sink things that seemed to be handy in alot of quick web dev situations. All non-dom specific calls can be run either server side or client side.</p>
<p>A minified form bitwrench.min.js is provided with identical functionality</p>
<h2 id="usage">Usage</h2>
<p>See the quick docs here:
<a href="./quick-docs.html">bitwrench quick docs</a></p>
<p>other examples here:
<a href="./examples">bitwrench examples</a></p>
<h3 id="nodejs">node.js</h3>
<pre><code class="language-bash">#Installation (server side)
npm install bitwrench --save
</code></pre>
<pre><code class="language-javascript">//usage in nodejs
var bw = require('./bitwrench.js'); //adds to current scope
var s = bw.html(["div",{"class":"foo"},"This is some HTML"]); // now... ===> s = "<div class='foo'>This is some HTML</div>
</code></pre>
<h3 id="browser">browser</h3>
<p>In the browser bitwrench is loaded like any script library. Note that parameters can be passed to bitwrench to control the loading process.
bitwrench generates its own default css from javascript and loads those. You can see these statically in the bitwrench.css file (note that bitwrench.css can also be used standalone without the bitwrench.js library).
<a href="./examples/example5.html">Example Page</a> source code here:</p>
<pre><code class="language-html">
<!DOCTYPE html>
<html lang="en">
<head>
<script src="../bitwrench.js" ></script>
</head>
<body class="bw-def-page-setup bw-font-sans-serif">
<script>
var htmlData = {c: //for more on the format, see docs github.com/deftio/bitwrench
[
["h1" ,{"class":"bw-h1"},"Bitwrench Test Area" ],
"bitwrench version: "+bw.version().version +"<br><br>",
["div",{"class":"foo"} ,"This page has HTML content which is entirely written as Javascript objects (JSON-like but with support for functions) by content using "+bw.html(["a",{href:"https://github.com/deftio/bitwrench"},"bitwrench.js"])+". Bitwrench has built-in grids, tables,headings, and other quick-n-dirty html prototyping tasks. Bitwrench html generation runs either client or server side."],
"<hr>",
["h2","Lorem Ipsum Generator"],
"Good for testing simple layout ideas.<br><br>",
["div",{},bw.loremIpsum(230)],
"<hr>",
["h2",{},"Sample Content with 3 Columns"],
["div",{"class":"bw-row"},
[
["div",{"class":"bw-col-4 bw-left "},"<h3>Left justified</h3>"+bw.loremIpsum(95)], //mix text and html freely
["div",{"class":"bw-col-4 bw-center bw-pad1"},"<h3>Centered</h3>"+bw.loremIpsum(95,3)],
["div",{"class":"bw-col-4 bw-right "},"<h3>Right justified</h3>"+bw.loremIpsum(95,2)],
],
],
"<br><hr>",
["h2", {}, "Example Sortable Table"],
bw.htmlTable( // json to table (note table data can be functions as well)
[
["Name","Age", "Prof", "Fav Color"], // just an 2D array
["Sue", 34, "Engineer", {a:{style:"color:red"},c:"red"}], // inline json-html objects
["Bob" ,35, "Teacher", {a:{style:"color:green"},c:"green"}],
["Vito",23, "Mechanic", {a:{style:"color:blue",onclick:"alert('blue!')"},c:"blue"}],
["Hank",73, "Retired", {a:{style:"color:purple"},c:"purple"}]
],{sortable:true}),
"<br><hr>",
["h2",{},"Sample Buttons"],
"These buttons have function handlers attached.<br><br>",
["button",{onclick:"alert('button pressed!')"},"Alert Button"], // staight js
"&nbsp;&nbsp;",
["button",{onclick:myFunc},"Time Button"], // bitwrench maps and registers event functions
"<br><hr>",
["h2","Built in Headings"],
[1,2,3,4,5,6].map( function(x){return bw.html(["h"+x,"Heading "+x])}).join(""), // Headings
"<br><hr>",
["h2","Grid System (responsive)"],
"Grid system (just uses css so can use either bitwrench.js loader or just bitwrench.css with no javascript. Use -fluid for responsive<br><br>",
["style",{},"\n.boxEv {background-color: #aaa; height: 30px; border-radius:5px; border:1px solid black;}\n.boxOd {background-color: #ddd; height:30px; border-radius:5px;border:1px solid black;;}\n"], // some styles (note bw has CSS generation shown in another example)
["div",{class:"bw-row bw-center"},[{a:{class:"bw-col-1 boxEv"},c:"bw-col-1"},{a:{class:"bw-col-1 boxOd"},c:"bw-col-1"},{a:{class:"bw-col-1 boxEv"},c:"bw-col-1"},{a:{class:"bw-col-1 boxOd"},c:"bw-col-1"},{a:{class:"bw-col-1 boxEv"},c:"bw-col-1"},{a:{class:"bw-col-1 boxOd"},c:"bw-col-1"},{a:{class:"bw-col-1 boxEv"},c:"bw-col-1"},{a:{class:"bw-col-1 boxOd"},c:"bw-col-1"},{a:{class:"bw-col-1 boxEv"},c:"bw-col-1"},{a:{class:"bw-col-1 boxOd"},c:"bw-col-1"},{a:{class:"bw-col-1 boxEv"},c:"bw-col-1"},{a:{class:"bw-col-1 boxOd"},c:"bw-col-1"}]],
["div",{class:"bw-row bw-center"},[{a:{class:"bw-col-2 boxEv"},c:"bw-col-2"},{a:{class:"bw-col-2 boxOd"},c:"bw-col-2"},{a:{class:"bw-col-2 boxEv"},c:"bw-col-2"},{a:{class:"bw-col-2 boxOd"},c:"bw-col-2"},{a:{class:"bw-col-2 boxEv"},c:"bw-col-2"},{a:{class:"bw-col-2 boxOd"},c:"bw-col-2"}]],
["div",{class:"bw-row bw-center"},[{a:{class:"bw-col-3 boxEv"},c:"bw-col-3"},{a:{class:"bw-col-3 boxOd"},c:"bw-col-3"},{a:{class:"bw-col-3 boxEv"},c:"bw-col-3"},{a:{class:"bw-col-3 boxOd"},c:"bw-col-3"}]],
["div",{class:"bw-row bw-center"},[{a:{class:"bw-col-4 boxEv"},c:"bw-col-4"},{a:{class:"bw-col-4 boxOd"},c:"bw-col-4"},{a:{class:"bw-col-4 boxEv"},c:"bw-col-4"}]],
["div",{class:"bw-row bw-center"},[{a:{class:"bw-col-5 boxEv"},c:"bw-col-5"},{a:{class:"bw-col-7 boxOd"},c:"bw-col-7"}]],
["div",{class:"bw-row bw-center"},[{a:{class:"bw-col-6 boxEv"},c:"bw-col-6"},{a:{class:"bw-col-6 boxOd"},c:"bw-col-6"}]],
["div",{class:"bw-row bw-center"},[{a:{class:"bw-col-7 boxEv"},c:"bw-col-7"},{a:{class:"bw-col-5 boxOd"},c:"bw-col-5"}]],
["div",{class:"bw-row bw-center"},[{a:{class:"bw-col-8 boxEv"},c:"bw-col-8"},{a:{class:"bw-col-4 boxOd"},c:"bw-col-4"}]],
["div",{class:"bw-row bw-center"},[{a:{class:"bw-col-9 boxEv"},c:"bw-col-9"},{a:{class:"bw-col-3 boxOd"},c:"bw-col-3"}]],
["div",{class:"bw-row bw-center"},[{a:{class:"bw-col-10 boxEv"},c:"bw-col-10"},{a:{class:"bw-col-2 boxOd"},c:"bw-col-2"}]],
["div",{class:"bw-row bw-center"},[{a:{class:"bw-col-11 boxEv"},c:"bw-col-11"},{a:{class:"bw-col-1 boxOd"},c:"bw-col-1"}]],
["div",{class:"bw-row bw-center"},[{a:{class:"bw-col-12 boxEv"},c:"bw-col-12"}]],
"<br><hr>",
["h2",{},"Simple Sign"],
["div",{style:"padding:10%; border:1px solid black;"},bw.htmlSign("This is a big sign!")],
"<br><hr>",
["h2",{},"Tabbed Content"],
bw.htmlTabs([
["Tab1",bw.loremIpsum(300)],
["Tab2",bw.loremIpsum(300,20)],
["Tab3",bw.loremIpsum(300,50)]],{tab_atr:{style:""}}) ,
"<br>",
]};
bw.DOMInsertElement("body",bw.html(htmlData),true);
function myFunc(x){return x.innerHTML = (new Date()).toLocaleTimeString();} // button function
bw.DOMInsertElement("head",bw.html(bw.htmlFavicon("\u266C","teal"))); // insert a favicon on the top tab of the page, "X" for a single letter
bw.DOMInsertElement("head",bw.html({t:"title",c:"Bitwrench HTML Gen "})); // insert a page title on the browser tab
</script>
</body>
</html>
</code></pre>
<h2 id="source-code-home">Source code home</h2>
<p>all source is at github:<br><a href="http://github.com/deftio/bitwrench">bitwrench on github</a> </p>
<h2 id="linting">Linting</h2>
<p>bitwrench uses eslint for static code checking and analysis. Due to bitwrench's age we've kept ";" as a required part of the linting process. After running lint you should see no errors or warnings.</p>
<pre><code class="language-bash">npm install eslint --save-dev
./node_modules/.bin/eslint --init
</code></pre>
<p>Now run the lint test like this:</p>
<pre><code class="language-bash">npm run lint
</code></pre>
<h2 id="tests--requires-mocha-and-chai-test-suites">Tests (requires mocha and chai test suites)</h2>
<p>bitwrench is tested with the mocha framework installed locally using npm along with instanbul for code / line coverage</p>
<pre><code class="language-bash">npm install mocha --save-dev mocha
</code></pre>
<p>Run the tests as follows:</p>
<pre><code class="language-bash">npm run test
</code></pre>
<h2 id="release-history">Release History</h2>
<ul>
<li>1.2x Initial release</li>
</ul>
<h2 id="license">License</h2>
<p>bitwrench is released under the OSI Approved FreeBSD 2-clause license </p>
<p>see LICENSE.txt file</p>
</body></html>