Class: LightningCSS::Transformer
- Inherits:
-
Object
- Object
- LightningCSS::Transformer
- Defined in:
- lib/lightningcss/transformer.rb,
sig/lightningcss/transformer.rbs
Overview
A set of options to transform many stylesheets with.
transformer = LightningCSS::Transformer.new(minify: true, targets: { chrome: 100 })
transformer.transform(".a { color: red }").code
transformer.transform(".b { color: red }", scope: "[data-scope-abc]").code
Options given to a call are merged over the ones it was built with, so the ones that belong to the project are written once and the ones that belong to a single stylesheet travel with it.
Instance Attribute Summary collapse
- #options ⇒ Hash[Symbol, untyped] readonly
Instance Method Summary collapse
-
#bundle(path, **overrides) ⇒ LightningCSS::Result
: (String, ?filename: String?, ?minify: bool, ?error_recovery: bool, ?targets: browsers?, ?css_modules: css_modules?, ?scope: String?) -> LightningCSS::Result.
-
#initialize(**options) ⇒ Transformer
constructor
: (?filename: String?, ?minify: bool, ?error_recovery: bool, ?targets: browsers?, ?css_modules: css_modules?, ?scope: String?) -> void.
-
#inspect ⇒ String
: () -> String.
-
#minify(code, **overrides) ⇒ String
: (String, ?filename: String?, ?error_recovery: bool, ?targets: browsers?, ?css_modules: css_modules?, ?scope: String?) -> String.
-
#transform(code, **overrides) ⇒ LightningCSS::Result
(also: #call)
: (String, ?filename: String?, ?minify: bool, ?error_recovery: bool, ?targets: browsers?, ?css_modules: css_modules?, ?scope: String?) -> LightningCSS::Result.
-
#transform_style_attribute(code, **overrides) ⇒ LightningCSS::Result
: (String, ?filename: String?, ?minify: bool, ?error_recovery: bool, ?targets: browsers?) -> LightningCSS::Result.
-
#with(**overrides) ⇒ LightningCSS::Transformer
: (?filename: String?, ?minify: bool, ?error_recovery: bool, ?targets: browsers?, ?css_modules: css_modules?, ?scope: String?) -> LightningCSS::Transformer.
Constructor Details
#initialize(**options) ⇒ Transformer
: (?filename: String?, ?minify: bool, ?error_recovery: bool, ?targets: browsers?, ?css_modules: css_modules?, ?scope: String?) -> void
18 19 20 21 22 |
# File 'lib/lightningcss/transformer.rb', line 18 def initialize(**) @options = .transform_keys(&:to_sym).freeze freeze end |
Instance Attribute Details
#options ⇒ Hash[Symbol, untyped] (readonly)
15 16 17 |
# File 'lib/lightningcss/transformer.rb', line 15 def @options end |
Instance Method Details
#bundle(path, **overrides) ⇒ LightningCSS::Result
: (String, ?filename: String?, ?minify: bool, ?error_recovery: bool, ?targets: browsers?, ?css_modules: css_modules?, ?scope: String?) -> LightningCSS::Result
32 33 34 |
# File 'lib/lightningcss/transformer.rb', line 32 def bundle(path, **overrides) LightningCSS.bundle(path, **, **overrides) end |
#inspect ⇒ String
: () -> String
52 53 54 |
# File 'lib/lightningcss/transformer.rb', line 52 def inspect "#<#{self.class.name} #{.inspect}>" end |
#minify(code, **overrides) ⇒ String
: (String, ?filename: String?, ?error_recovery: bool, ?targets: browsers?, ?css_modules: css_modules?, ?scope: String?) -> String
42 43 44 |
# File 'lib/lightningcss/transformer.rb', line 42 def minify(code, **overrides) transform(code, **overrides, minify: true).code end |
#transform(code, **overrides) ⇒ LightningCSS::Result Also known as: call
: (String, ?filename: String?, ?minify: bool, ?error_recovery: bool, ?targets: browsers?, ?css_modules: css_modules?, ?scope: String?) -> LightningCSS::Result
25 26 27 |
# File 'lib/lightningcss/transformer.rb', line 25 def transform(code, **overrides) LightningCSS.transform(code, **, **overrides) end |
#transform_style_attribute(code, **overrides) ⇒ LightningCSS::Result
: (String, ?filename: String?, ?minify: bool, ?error_recovery: bool, ?targets: browsers?) -> LightningCSS::Result
37 38 39 |
# File 'lib/lightningcss/transformer.rb', line 37 def transform_style_attribute(code, **overrides) LightningCSS.transform_style_attribute(code, **, **overrides) end |
#with(**overrides) ⇒ LightningCSS::Transformer
: (?filename: String?, ?minify: bool, ?error_recovery: bool, ?targets: browsers?, ?css_modules: css_modules?, ?scope: String?) -> LightningCSS::Transformer
47 48 49 |
# File 'lib/lightningcss/transformer.rb', line 47 def with(**overrides) self.class.new(**, **overrides) end |