Module: Klenod::Build::Plugins::CSSPlugin::Transformer

Defined in:
lib/klenod/plugin/css/transformer.rb

Class Method Summary collapse

Class Method Details

.native?Boolean

Returns:

  • (Boolean)


104
105
106
# File 'lib/klenod/plugin/css/transformer.rb', line 104

def native?
  !native_transformer.nil?
end

.native_transformerObject



135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/klenod/plugin/css/transformer.rb', line 135

def native_transformer
  @native_transformer =
    if defined?(@native_transformer)
      @native_transformer
    else
      begin
        require "klenod/plugin/css/native"
        Klenod::Build::Plugins::CSSPlugin::Native
      rescue LoadError
        nil
      end
    end
end

.transform(file, code, minify: true, transform_names: true, class_pattern: "[component].[local]?[hash]", tag_pattern: "[component]_[local]?[hash]", local_css_variables: false, variable_pattern: "[component]-[local]?[hash]") ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/klenod/plugin/css/transformer.rb', line 108

def transform(
  file,
  code,
  minify: true,
  transform_names: true,
  class_pattern: "[component].[local]?[hash]",
  tag_pattern: "[component]_[local]?[hash]",
  local_css_variables: false,
  variable_pattern: "[component]-[local]?[hash]"
)
  native = native_transformer || raise(Error, "CSS support requires the klenod-plugin-css native extension. Run `bundle exec rake compile` in gems/klenod-plugin-css.")
  TransformResult.from_ext(
    native.transform_native(
      code,
      file,
      {
        "minify" => minify,
        "transform_names" => transform_names,
        "class_pattern" => class_pattern,
        "tag_pattern" => tag_pattern,
        "local_css_variables" => local_css_variables,
        "variable_pattern" => variable_pattern
      }
    )
  )
end