-
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
33 changed files
with
884 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
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,31 @@ | ||
# 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 | ||
|
||
# @param value [::String] | ||
def initialize(value) | ||
@value = value | ||
end | ||
|
||
# @return [::String] | ||
attr_reader :value | ||
|
||
# @return [::Boolean] | ||
def ==(other) | ||
other.is_a?(Sass::CalculationValue::CalculationInterpolation) && | ||
other.value == value | ||
end | ||
|
||
# @return [Integer] | ||
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,52 @@ | ||
# 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 | ||
|
||
# @param operator [::String] | ||
# @param left [CalculationValue] | ||
# @param right [CalculationValue] | ||
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 | ||
|
||
# @return [::String] | ||
attr_reader :operator | ||
|
||
# @return [CalculationValue] | ||
attr_reader :left | ||
|
||
# @return [CalculationValue] | ||
attr_reader :right | ||
|
||
# @return [::Boolean] | ||
def ==(other) | ||
other.is_a?(Sass::CalculationValue::CalculationOperation) && | ||
other.operator == operator && | ||
other.left == left && | ||
other.right == right | ||
end | ||
|
||
# @return [Integer] | ||
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
Oops, something went wrong.