web 3d图形渲染器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

189 lines
3.4 KiB

  1. # RenderKid
  2. [![Build Status](https://secure.travis-ci.org/AriaMinaei/RenderKid.png)](http://travis-ci.org/AriaMinaei/RenderKid)
  3. RenderKid allows you to use HTML and CSS to style your CLI output, making it easy to create a beautiful, readable, and consistent look for your nodejs tool.
  4. ## Installation
  5. Install with npm:
  6. ```
  7. $ npm install renderkid
  8. ```
  9. ## Usage
  10. ```coffeescript
  11. RenderKid = require('renderkid')
  12. r = new RenderKid()
  13. r.style({
  14. "ul": {
  15. display: "block"
  16. margin: "2 0 2"
  17. }
  18. "li": {
  19. display: "block"
  20. marginBottom: "1"
  21. }
  22. "key": {
  23. color: "grey"
  24. marginRight: "1"
  25. }
  26. "value": {
  27. color: "bright-white"
  28. }
  29. })
  30. output = r.render("
  31. <ul>
  32. <li>
  33. <key>Name:</key>
  34. <value>RenderKid</value>
  35. </li>
  36. <li>
  37. <key>Version:</key>
  38. <value>0.2</value>
  39. </li>
  40. <li>
  41. <key>Last Update:</key>
  42. <value>Jan 2015</value>
  43. </li>
  44. </ul>
  45. ")
  46. console.log(output)
  47. ```
  48. ![screenshot of usage](https://github.com/AriaMinaei/RenderKid/raw/master/docs/images/usage.png)
  49. ## Stylesheet properties
  50. ### Display mode
  51. Elements can have a `display` of either `inline`, `block`, or `none`:
  52. ```coffeescript
  53. r.style({
  54. "div": {
  55. display: "block"
  56. }
  57. "span": {
  58. display: "inline" # default
  59. }
  60. "hidden": {
  61. display: "none"
  62. }
  63. })
  64. output = r.render("
  65. <div>This will fill one or more rows.</div>
  66. <span>These</span> <span>will</span> <span>be</span> in the same <span>line.</span>
  67. <hidden>This won't be displayed.</hidden>
  68. ")
  69. console.log(output)
  70. ```
  71. ![screenshot of usage](https://github.com/AriaMinaei/RenderKid/raw/master/docs/images/display.png)
  72. ### Margin
  73. Margins work just like they do in browsers:
  74. ```coffeescript
  75. r.style({
  76. "li": {
  77. display: "block"
  78. marginTop: "1"
  79. marginRight: "2"
  80. marginBottom: "3"
  81. marginLeft: "4"
  82. # or the shorthand version:
  83. "margin": "1 2 3 4"
  84. },
  85. "highlight": {
  86. display: "inline"
  87. marginLeft: "2"
  88. marginRight: "2"
  89. }
  90. })
  91. r.render("
  92. <ul>
  93. <li>Item <highlgiht>1</highlight></li>
  94. <li>Item <highlgiht>2</highlight></li>
  95. <li>Item <highlgiht>3</highlight></li>
  96. </ul>
  97. ")
  98. ```
  99. ### Padding
  100. See margins above. Paddings work the same way, only inward.
  101. ### Width and Height
  102. Block elements can have explicit width and height:
  103. ```coffeescript
  104. r.style({
  105. "box": {
  106. display: "block"
  107. "width": "4"
  108. "height": "2"
  109. }
  110. })
  111. r.render("<box>This is a box and some of its text will be truncated.</box>")
  112. ```
  113. ### Colors
  114. You can set a custom color and background color for each element:
  115. ```coffeescript
  116. r.style({
  117. "error": {
  118. color: "black"
  119. background: "red"
  120. }
  121. })
  122. ```
  123. List of colors currently supported are `black`, `red`, `green`, `yellow`, `blue`, `magenta`, `cyan`, `white`, `grey`, `bright-red`, `bright-green`, `bright-yellow`, `bright-blue`, `bright-magenta`, `bright-cyan`, `bright-white`.
  124. ### Bullet points
  125. Block elements can have bullet points on their margins. Let's start with an example:
  126. ```coffeescript
  127. r.style({
  128. "li": {
  129. # To add bullet points to an element, first you
  130. # should make some room for the bullet point by
  131. # giving your element some margin to the left:
  132. marginLeft: "4",
  133. # Now we can add a bullet point to our margin:
  134. bullet: '"-"'
  135. }
  136. })
  137. # The four hyphens are there for visual reference
  138. r.render("
  139. ----
  140. <li>Item 1</li>
  141. <li>Item 2</li>
  142. <li>Item 3</li>
  143. ----
  144. ")
  145. ```
  146. And here is the result:
  147. ![screenshot of bullet points, 1](https://github.com/AriaMinaei/RenderKid/raw/master/docs/images/bullets-1.png)