-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
846 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
module Sass | ||
# The type of values that can be arguments to a SassCalculation. | ||
# | ||
# @see https://sass-lang.com/documentation/js-api/types/calculationvalue/ | ||
module CalculationValue | ||
# @return [CalculationValue] | ||
# @raise [ScriptError] | ||
def assert_calculation_value(_name = nil) | ||
self | ||
end | ||
end | ||
end | ||
|
||
require_relative 'calculation_value/calculation_interpolation' | ||
require_relative 'calculation_value/calculation_operation' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
module Sass | ||
module CalculationValue | ||
# A string injected into a SassCalculation using interpolation. | ||
# | ||
# @see https://sass-lang.com/documentation/js-api/classes/calculationinterpolation/ | ||
class CalculationInterpolation | ||
include CalculationValue | ||
|
||
def initialize(value) | ||
@value = value | ||
end | ||
|
||
attr_reader :value | ||
|
||
def ==(other) | ||
other.is_a?(Sass::CalculationValue::CalculationInterpolation) && | ||
other.value == value | ||
end | ||
|
||
def hash | ||
@hash ||= value.hash | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# frozen_string_literal: true | ||
|
||
module Sass | ||
module CalculationValue | ||
# A binary operation that can appear in a SassCalculation. | ||
# | ||
# @see https://sass-lang.com/documentation/js-api/classes/calculationoperation/ | ||
class CalculationOperation | ||
include CalculationValue | ||
|
||
OPERATORS = ['+', '-', '*', '/'].freeze | ||
|
||
private_constant :OPERATORS | ||
|
||
def initialize(operator, left, right) | ||
raise Sass::ScriptError, "Invalid operator: #{operator}" unless OPERATORS.include?(operator) | ||
|
||
left.assert_calculation_value | ||
right.assert_calculation_value | ||
|
||
@operator = operator.freeze | ||
@left = left.freeze | ||
@right = right.freeze | ||
end | ||
|
||
attr_reader :operator, :left, :right | ||
|
||
def ==(other) | ||
other.is_a?(Sass::CalculationValue::CalculationOperation) && | ||
other.operator == operator && | ||
other.left == left && | ||
other.right == right | ||
end | ||
|
||
def hash | ||
@hash ||= [operator, left, right].hash | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.