Module: Stylus
- Defined in:
- lib/stylus.rb,
lib/stylus/railtie.rb,
lib/stylus/version.rb,
lib/rails/generators/stylus/assets/assets_generator.rb,
lib/rails/generators/stylus/scaffold/scaffold_generator.rb
Overview
‘Stylus.compile(File.read(’application.styl’), :compress => true)‘
Defined Under Namespace
Modules: Generators Classes: Railtie
Constant Summary collapse
- VERSION =
"0.3.0"
- @@compress =
false
- @@debug =
false
- @@paths =
[]
- @@imports =
[]
- @@plugins =
{}
Class Method Summary collapse
-
.compile(source, options = {}) ⇒ Object
Compiles a given input - a plain String, ‘File` or some sort of IO object that responds to `read`.
-
.compress ⇒ Object
(also: compress?)
Returns the global compress flag.
-
.compress=(val) ⇒ Object
Sets the global flag for the ‘compress` option.
-
.convert(source) ⇒ Object
Converts back an input of plain CSS to the ‘Stylus` syntax.
-
.debug ⇒ Object
(also: debug?)
Returns the ‘debug` flag used to set the `linenos` and `firebug` option for Stylus.
-
.debug=(val) ⇒ Object
Sets the ‘debug` flag.
-
.debug_options ⇒ Object
Returns a Hash with the debug options to pass to Stylus.
-
.defaults ⇒ Object
Returns the default ‘Hash` of options: the compress flag and the global load path.
-
.import(*paths) ⇒ Object
(also: imports)
Stores a list of stylesheets to import on every compile process.
-
.merge_options(options) ⇒ Object
Returns a ‘Hash` of the given `options` merged with the default configuration.
-
.nib=(flag) ⇒ Object
Marks the ‘nib` plugin to be loaded and included on every stylesheet.
-
.paths ⇒ Object
Returns the global load path ‘Array` for your stylesheets.
-
.paths=(val) ⇒ Object
Replaces the global load path ‘Array` of paths.
-
.plugins ⇒ Object
Retrieves all the registered plugins.
-
.use(*options) ⇒ Object
(also: plugin)
Stores a list of plugins to import inside ‘Stylus`, with an optional hash.
-
.version ⇒ Object
Return the gem version alongside with the current ‘Stylus` version of your system.
Class Method Details
.compile(source, options = {}) ⇒ Object
Compiles a given input - a plain String, ‘File` or some sort of IO object that responds to `read`. It accepts a hash of options that will be merged with the global configuration. If the source has a `path`, it will be expanded and used as the :filename option So the debug options can be used.
100 101 102 103 104 105 106 107 |
# File 'lib/stylus.rb', line 100 def compile(source, = {}) if source.respond_to?(:path) && source.path [:filename] ||= File.(source.path) end source = source.read if source.respond_to?(:read) = () context.call('compiler', source, , plugins, imports) end |
.compress ⇒ Object Also known as: compress?
Returns the global compress flag.
85 86 87 |
# File 'lib/stylus.rb', line 85 def compress @@compress end |
.compress=(val) ⇒ Object
Sets the global flag for the ‘compress` option.
91 92 93 |
# File 'lib/stylus.rb', line 91 def compress=(val) @@compress = val end |
.convert(source) ⇒ Object
Converts back an input of plain CSS to the ‘Stylus` syntax. The source object can be
a `File`, `StringIO`, `String` or anything that responds to `read`.
111 112 113 114 |
# File 'lib/stylus.rb', line 111 def convert(source) source = source.read if source.respond_to?(:read) context.call('convert', source) end |
.debug ⇒ Object Also known as: debug?
Returns the ‘debug` flag used to set the `linenos` and `firebug` option for Stylus.
66 67 68 |
# File 'lib/stylus.rb', line 66 def debug @@debug end |
.debug=(val) ⇒ Object
Sets the ‘debug` flag.
80 81 82 |
# File 'lib/stylus.rb', line 80 def debug=(val) @@debug = val end |
.debug_options ⇒ Object
Returns a Hash with the debug options to pass to Stylus.
138 139 140 |
# File 'lib/stylus.rb', line 138 def { :linenos => self.debug?, :firebug => self.debug? } end |
.defaults ⇒ Object
Returns the default ‘Hash` of options: the compress flag and the global load path.
132 133 134 |
# File 'lib/stylus.rb', line 132 def defaults { :compress => self.compress?, :paths => self.paths } end |
.import(*paths) ⇒ Object Also known as: imports
Stores a list of stylesheets to import on every compile process.
42 43 44 45 46 47 |
# File 'lib/stylus.rb', line 42 def import(*paths) if paths.any? @@imports = @@imports.concat(paths) end @@imports end |
.merge_options(options) ⇒ Object
Returns a ‘Hash` of the given `options` merged with the default configuration. It also concats the global load path with a given `:paths` option.
118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/stylus.rb', line 118 def () filename = [:filename] _paths = .delete(:paths) = defaults.merge() [:paths] = paths.concat(Array(_paths)) if filename = .merge() end end |
.nib=(flag) ⇒ Object
Marks the ‘nib` plugin to be loaded and included on every stylesheet.
72 73 74 75 76 77 |
# File 'lib/stylus.rb', line 72 def nib=(flag) if flag use :nib import :nib end end |
.paths ⇒ Object
Returns the global load path ‘Array` for your stylesheets.
56 57 58 |
# File 'lib/stylus.rb', line 56 def paths @@paths end |
.paths=(val) ⇒ Object
Replaces the global load path ‘Array` of paths.
61 62 63 |
# File 'lib/stylus.rb', line 61 def paths=(val) @@paths = Array(val) end |
.plugins ⇒ Object
Retrieves all the registered plugins.
51 52 53 |
# File 'lib/stylus.rb', line 51 def plugins @@plugins end |
.use(*options) ⇒ Object Also known as: plugin
Stores a list of plugins to import inside ‘Stylus`, with an optional hash.
33 34 35 36 37 38 |
# File 'lib/stylus.rb', line 33 def use(*) arguments = .last.is_a?(Hash) ? .pop : {} .each do |plugin| @@plugins[plugin] = arguments end end |
.version ⇒ Object
Return the gem version alongside with the current ‘Stylus` version of your system.
143 144 145 |
# File 'lib/stylus.rb', line 143 def version "Stylus - gem #{VERSION} library #{context.call('version')}" end |