diff options
-rw-r--r-- | tasks/converter/less_conversion.rb | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/tasks/converter/less_conversion.rb b/tasks/converter/less_conversion.rb index 2609d5d..5e69d92 100644 --- a/tasks/converter/less_conversion.rb +++ b/tasks/converter/less_conversion.rb @@ -424,16 +424,16 @@ SASS # #scope > .mixin() -> @include scope-mixin() # &:extend(.mixin all) -> @include mixin() def replace_mixins(less, mixin_names) - mixin_pattern = /(\s+)(([#|\.][\w-]+\s*>\s*)*)\.([\w-]+\(.*\))(?!\s\{)/ - - less = less.gsub(mixin_pattern) do |match| - matches = match.scan(mixin_pattern).flatten - scope = matches[1] && matches[1] != '' ? matches[1].scan(/[\w-]+/).join('-') + '-' : '' - mixin_name = match.scan(/\.([\w-]+)\(.*\)\s?\{?/).first - if mixin_name && mixin_names.include?("#{scope}#{mixin_name.first}") - "#{matches.first}@include #{scope}#{matches.last.gsub(/;\s*\$/, ', $').sub(/;\)$/, ')').sub(/\(\)$/, '')}" + mixin_pattern = /(?<=^|\s)((?:[#|\.][\w-]+\s*>\s*)*)\.([\w-]+)\((.*)\)(?!\s\{)/ + + less = less.gsub(mixin_pattern) do |_| + scope, name, args = $1, $2, $3 + scope = scope.scan(/[\w-]+/).join('-') + '-' unless scope.empty? + args = "(#{args.tr(';', ',')})" unless args.empty? + if name && mixin_names.include?("#{scope}#{name}") + "@include #{scope}#{name}#{args}" else - "#{matches.first}@extend .#{scope}#{matches.last.gsub(/\(\)/, '')}" + "@extend .#{scope}#{name}" end end |