1 |
|
2 | /*!
|
3 | * Stylus
|
4 | * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
|
5 | * MIT Licensed
|
6 | */
|
7 |
|
8 | /**
|
9 | * Module dependencies.
|
10 | */
|
11 |
|
12 | var Renderer = require('./renderer')
|
13 | , nodes = require('./nodes')
|
14 | , utils = require('./utils');
|
15 |
|
16 | /**
|
17 | * Export render as the module.
|
18 | */
|
19 |
|
20 | exports = module.exports = render;
|
21 |
|
22 | /**
|
23 | * Library version.
|
24 | */
|
25 |
|
26 | exports.version = '0.7.2';
|
27 |
|
28 | /**
|
29 | * Expose nodes.
|
30 | */
|
31 |
|
32 | exports.nodes = nodes;
|
33 |
|
34 | /**
|
35 | * Expose BIFs.
|
36 | */
|
37 |
|
38 | exports.functions = require('./functions');
|
39 |
|
40 | /**
|
41 | * Expose utils.
|
42 | */
|
43 |
|
44 | exports.utils = require('./utils');
|
45 |
|
46 | /**
|
47 | * Expose middleware.
|
48 | */
|
49 |
|
50 | exports.middleware = require('./middleware');
|
51 |
|
52 | /**
|
53 | * Convert the given `css` to `stylus` source.
|
54 | *
|
55 | * @param {String} css
|
56 | * @return {String}
|
57 | * @api public
|
58 | */
|
59 |
|
60 | exports.convertCSS = require('./convert/css');
|
61 |
|
62 | /**
|
63 | * Parse the given `str` with `options` and return the AST.
|
64 | *
|
65 | * Examples:
|
66 | *
|
67 | * css.parse(str);
|
68 | * // raw ast comprised of nodes
|
69 | *
|
70 | * css.parse(str).toObject();
|
71 | * // plain object representation
|
72 | *
|
73 | * css.parse(str).toJSON();
|
74 | * // JSON representation
|
75 | *
|
76 | * @param {String} str
|
77 | * @param {Object} options
|
78 | * @return {Object}
|
79 | * @api public
|
80 | */
|
81 |
|
82 | exports.parse = function(str, options){
|
83 | var renderer = new Renderer(str, options);
|
84 | try {
|
85 | return renderer.parser.parse();
|
86 | } catch (err) {
|
87 | throw utils.formatException(
|
88 | renderer
|
89 | , err
|
90 | , options);
|
91 | }
|
92 | };
|
93 |
|
94 | /**
|
95 | * Render the given `str` with `options` and callback `fn(err, css)`.
|
96 | *
|
97 | * @param {String} str
|
98 | * @param {Object|Function} options
|
99 | * @param {Function} fn
|
100 | * @api public
|
101 | */
|
102 |
|
103 | exports.render = function(str, options, fn){
|
104 | if ('function' == typeof options) fn = options, options = {};
|
105 | new Renderer(str, options).render(fn);
|
106 | };
|
107 |
|
108 | /**
|
109 | * Return a new `Renderer` for the given `str` and `options`.
|
110 | *
|
111 | * @param {String} str
|
112 | * @param {Object} options
|
113 | * @return {Renderer}
|
114 | * @api public
|
115 | */
|
116 |
|
117 | function render(str, options) {
|
118 | return new Renderer(str, options);
|
119 | }
|
120 |
|
121 | /**
|
122 | * Expose optional functions.
|
123 | */
|
124 |
|
125 | exports.url = require('./functions/url');
|