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.

README.md 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. rework-plugin-function
  2. ====================
  3. [![Build Status](https://travis-ci.org/reworkcss/rework-plugin-function.png)](https://travis-ci.org/reworkcss/rework-plugin-function)
  4. function() plugin for rework, formerly included in core
  5. Add user-defined CSS functions.
  6. For example create `black(0.5)` shortcut, to replace
  7. long `rgba(0, 0, 0, 0.5)`.
  8. ```js
  9. var rework = require('rework'),
  10. var reworkFunction = require('rework-plugin-function');
  11. var css = rework(css)
  12. .use(reworkFunction({ black: black }))
  13. .toString()
  14. function black(opacity) {
  15. return 'rgba(0, 0, 0, ' + opacity + ')';
  16. }
  17. ```
  18. User code will receive CSS arguments and replace user-defined function
  19. by returned code.
  20. ```css
  21. input {
  22. box-shadow: 0 0 5px black(0.7);
  23. }
  24. ```
  25. yields:
  26. ```css
  27. input {
  28. box-shadow: 0 0 5px rgba(0, 0, 0, 0.7);
  29. }
  30. ```
  31. Nested functions works well too:
  32. ```javascript
  33. var css = rework(css)
  34. .use(reworkFunction({
  35. subtract: function(a, b) { return a - b },
  36. multiply: function(a, b) { return a * b },
  37. divide: function(a, b) { return a / b },
  38. floor: Math.floor
  39. }))
  40. .toString()
  41. ```
  42. ```css
  43. input {
  44. top: divide(subtract(30, floor(multiply(20, 10))), 2);
  45. }
  46. ```
  47. Would yield:
  48. ```css
  49. input {
  50. top: -85;
  51. }
  52. ```