Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 0dc062917efec6613536cdbe600f1f9e46845fc3 @tj committed Jul 26, 2012
Showing with 401 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +4 −0 .npmignore
  3. +5 −0 History.md
  4. +8 −0 Makefile
  5. +103 −0 Readme.md
  6. +36 −0 benchmark.js
  7. +15 −0 examples/pet.css
  8. +24 −0 examples/pet.js
  9. +15 −0 examples/report.css
  10. +30 −0 examples/report.js
  11. +149 −0 index.js
  12. +11 −0 package.json
@@ -0,0 +1 @@
+node_modules
@@ -0,0 +1,4 @@
+support
+test
+examples
+*.sock
@@ -0,0 +1,5 @@
+
+0.0.1 / 2010-01-03
+==================
+
+ * Initial release
@@ -0,0 +1,8 @@
+
+test:
+ @node test
+
+benchmark:
+ @node benchmark
+
+.PHONY: test benchmark
103 Readme.md
@@ -0,0 +1,103 @@
+
+# term-css
+
+ Terminal CSS styling using [node-css](https://github.com/visionmedia/node-css).
+
+## Installation
+
+ $ npm install term-css
+
+## Example
+
+js:
+
+```js
+
+var css = require('term-css')
+ , fs = require('fs')
+ , style = fs.readFileSync('pet.css', 'utf8');
+
+var tobi = {
+ name: 'tobi',
+ species: 'ferret',
+ age: 2
+};
+
+var loki = {
+ name: 'loki',
+ species: 'ferret',
+ age: 1
+};
+
+var fn = css.compile(' "{name}" is a {species}, he is {age} years old', style);
+
+console.log();
+console.log(fn(tobi));
+console.log(fn(loki));
+console.log();
+
+```
+
+css:
+
+```css
+name {
+ color: blue;
+ font-weight: bold;
+}
+
+species {
+ color: gray;
+ font-style: italic;
+}
+
+age {
+ color: green;
+ text-decoration: underline;
+}
+```
+
+## CSS properties
+
+ The following CSS properties / values are understood:
+
+ - `text-decoration: <underline|inverse>`
+ - `font-weight: <bold>`
+ - `font-style: <italic>`
+ - `color: <grey|gray|black|blue|cyan|green|red|magenta|yellow>`
+ - `background: <grey|gray|black|blue|cyan|green|red|magenta|yellow>`
+
+## Substitution
+
+ term-css substitutes tokens with properties in the object passed,
+ for example `{name}` will access `{ name: "tobi" }`, whereas
+ `{labels.visits}` will access `{ labels: { visits: 'Visits' } }`.
+
+ For styling purposes you may also assign a classname, for example
+ instead of styling "labels.visits", "labels.uptime" separately,
+ you may use `{label labels.visits}` and `{label labels.uptime}`.
+
+## License
+
+(The MIT License)
+
+Copyright (c) 2012 TJ Holowaychuk &lt;tj@vision-media.ca&gt;
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,36 @@
+
+var css = require('./')
+ , fs = require('fs')
+ , read = fs.readFileSync
+ , str = read('examples/ui.css', 'utf8');
+
+var n = 5000;
+var ops = 200;
+var t = process.hrtime(t);
+var results = [];
+
+while (n--) {
+ css.stringify(css.parse(str));
+ if (n % ops == 0) {
+ t = process.hrtime(t);
+ var ms = t[1] / 1000 / 1000;
+ var persec = (ops * (1000 / ms) | 0);
+ results.push(persec);
+ process.stdout.write('\r [' + persec + ' ops/s] [' + n + ']');
+ t = process.hrtime();
+ }
+}
+
+function sum(arr) {
+ return arr.reduce(function(sum, n){
+ return sum + n;
+ });
+}
+
+function mean(arr) {
+ return sum(arr) / arr.length | 0;
+}
+
+console.log();
+console.log(' avg: %d ops/s', mean(results));
+console.log(' size: %d kb', (str.length / 1024).toFixed(2));
@@ -0,0 +1,15 @@
+
+name {
+ color: blue;
+ font-weight: bold;
+}
+
+species {
+ color: gray;
+ font-style: italic;
+}
+
+age {
+ color: green;
+ text-decoration: underline;
+}
@@ -0,0 +1,24 @@
+
+var css = require('..')
+ , fs = require('fs')
+ , read = fs.readFileSync
+ , style = read('examples/pet.css', 'utf8');
+
+var tobi = {
+ name: 'tobi',
+ species: 'ferret',
+ age: 2
+};
+
+var loki = {
+ name: 'loki',
+ species: 'ferret',
+ age: 1
+};
+
+var fn = css.compile(' "{name}" is a {species}, he is {age} years old', style);
+
+console.log();
+console.log(fn(tobi));
+console.log(fn(loki));
+console.log();
@@ -0,0 +1,15 @@
+
+title {
+ font-weight: bold;
+}
+
+users,
+visits,
+uptime {
+ color: cyan;
+}
+
+label {
+ color: gray;
+ text-decoration: underline;
+}
@@ -0,0 +1,30 @@
+
+var css = require('..')
+ , fs = require('fs')
+ , read = fs.readFileSync
+ , style = read('examples/report.css', 'utf8');
+
+var stats = {
+ title: 'stats',
+ users: 150000,
+ visits: 5000000,
+ uptime: '50 days',
+ labels: {
+ user: 'users',
+ visits: 'visits',
+ uptime: 'uptime'
+ }
+}
+
+var str = '\
+ {title}:\n\
+ {label labels.user}: {users}\n\
+ {label labels.visits}: {visits}\n\
+ {label labels.uptime}: {uptime}\n\
+'
+
+var fn = css.compile(str, style);
+
+console.log();
+console.log(fn(stats));
+console.log();
Oops, something went wrong.

0 comments on commit 0dc0629

Please sign in to comment.