Module: Stylus
- Defined in:
- lib/stylus.rb,
lib/stylus/railtie.rb,
lib/stylus/runtime.rb,
lib/stylus/version.rb,
lib/stylus/sprockets.rb,
lib/stylus/import_processor.rb,
lib/rails/generators/stylus/assets/assets_generator.rb,
lib/rails/generators/stylus/scaffold/scaffold_generator.rb
Overview
Based on the ImportProcessor from the less-rails gem, by @metaskills
Defined Under Namespace
Modules: Generators, Runtime, Sprockets Classes: ImportProcessor, Railtie
Constant Summary collapse
- VERSION =
"0.7.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.
Methods included from Sprockets
Methods included from Runtime
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.
101 102 103 104 105 106 107 108 |
# File 'lib/stylus.rb', line 101 def compile(source, = {}) if source.respond_to?(:path) && source.path [:filename] ||= File.(source.path) end source = source.read if source.respond_to?(:read) = () exec('compile', source, , plugins, imports) end |
.compress ⇒ Object Also known as: compress?
Returns the global compress flag.
86 87 88 |
# File 'lib/stylus.rb', line 86 def compress @@compress end |
.compress=(val) ⇒ Object
Sets the global flag for the ‘compress` option.
92 93 94 |
# File 'lib/stylus.rb', line 92 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`.
112 113 114 115 |
# File 'lib/stylus.rb', line 112 def convert(source) source = source.read if source.respond_to?(:read) exec('convert', source) end |
.debug ⇒ Object Also known as: debug?
Returns the ‘debug` flag used to set the `linenos` and `firebug` option for Stylus.
67 68 69 |
# File 'lib/stylus.rb', line 67 def debug @@debug end |
.debug=(val) ⇒ Object
Sets the ‘debug` flag.
81 82 83 |
# File 'lib/stylus.rb', line 81 def debug=(val) @@debug = val end |
.debug_options ⇒ Object
Returns a Hash with the debug options to pass to Stylus.
139 140 141 |
# File 'lib/stylus.rb', line 139 def { :linenos => self.debug?, :firebug => self.debug? } end |
.defaults ⇒ Object
Returns the default ‘Hash` of options: the compress flag and the global load path.
133 134 135 |
# File 'lib/stylus.rb', line 133 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.
43 44 45 46 47 48 |
# File 'lib/stylus.rb', line 43 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.
119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/stylus.rb', line 119 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.
73 74 75 76 77 78 |
# File 'lib/stylus.rb', line 73 def nib=(flag) if flag use :nib import :nib end end |
.paths ⇒ Object
Returns the global load path ‘Array` for your stylesheets.
57 58 59 |
# File 'lib/stylus.rb', line 57 def paths @@paths end |
.paths=(val) ⇒ Object
Replaces the global load path ‘Array` of paths.
62 63 64 |
# File 'lib/stylus.rb', line 62 def paths=(val) @@paths = Array(val) end |
.plugins ⇒ Object
Retrieves all the registered plugins.
52 53 54 |
# File 'lib/stylus.rb', line 52 def plugins @@plugins end |
.use(*options) ⇒ Object Also known as: plugin
Stores a list of plugins to import inside ‘Stylus`, with an optional hash.
34 35 36 37 38 39 |
# File 'lib/stylus.rb', line 34 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.
144 145 146 |
# File 'lib/stylus.rb', line 144 def version "Stylus - gem #{VERSION} library #{exec('version')}" end |