idx
int64
0
24.9k
question
stringlengths
68
4.14k
target
stringlengths
9
749
4,700
def add_rules ( node ) @rule = Sass :: Util . strip_string_array ( Sass :: Util . merge_adjacent_strings ( @rule + [ "\n" ] + node . rule ) ) try_to_parse_non_interpolated_rules end
Compares the contents of two rules .
4,701
def map_vals ( hash ) rv = hash . class . new hash = hash . as_stored if hash . is_a? ( NormalizedMap ) hash . each do | k , v | rv [ k ] = yield ( v ) end rv end
Maps the values in a hash according to a block .
4,702
def map_hash ( hash ) rv = hash . class . new hash . each do | k , v | new_key , new_value = yield ( k , v ) new_key = hash . denormalize ( new_key ) if hash . is_a? ( NormalizedMap ) && new_key == k rv [ new_key ] = new_value end rv end
Maps the key - value pairs of a hash according to a block .
4,703
def powerset ( arr ) arr . inject ( [ Set . new ] . to_set ) do | powerset , el | new_powerset = Set . new powerset . each do | subset | new_powerset << subset new_powerset << subset + [ el ] end new_powerset end end
Computes the powerset of the given array . This is the set of all subsets of the array .
4,704
def restrict ( value , range ) [ [ value , range . first ] . max , range . last ] . min end
Restricts a number to falling within a given range . Returns the number if it falls within the range or the closest value in the range if it doesn t .
4,705
def merge_adjacent_strings ( arr ) return arr if arr . size < 2 arr . inject ( [ ] ) do | a , e | if e . is_a? ( String ) if a . last . is_a? ( String ) a . last << e else a << e . dup end else a << e end a end end
Concatenates all strings that are adjacent in an array while leaving other elements as they are .
4,706
def replace_subseq ( arr , subseq , replacement ) new = [ ] matched = [ ] i = 0 arr . each do | elem | if elem != subseq [ i ] new . push ( * matched ) matched = [ ] i = 0 new << elem next end if i == subseq . length - 1 matched = [ ] i = 0 new . push ( * replacement ) else matched << elem i += 1 end end new . push ( *...
Non - destructively replaces all occurrences of a subsequence in an array with another subsequence .
4,707
def substitute ( ary , from , to ) res = ary . dup i = 0 while i < res . size if res [ i ... i + from . size ] == from res [ i ... i + from . size ] = to end i += 1 end res end
Substitutes a sub - array of one array with another sub - array .
4,708
def paths ( arrs ) arrs . inject ( [ [ ] ] ) do | paths , arr | arr . map { | e | paths . map { | path | path + [ e ] } } . flatten ( 1 ) end end
Return an array of all possible paths through the given arrays .
4,709
def lcs ( x , y , & block ) x = [ nil , * x ] y = [ nil , * y ] block ||= proc { | a , b | a == b && a } lcs_backtrace ( lcs_table ( x , y , & block ) , x , y , x . size - 1 , y . size - 1 , & block ) end
Computes a single longest common subsequence for x and y . If there are more than one longest common subsequences the one returned is that which starts first in x .
4,710
def caller_info ( entry = nil ) entry ||= caller [ 1 ] info = entry . scan ( / / ) . first info [ 1 ] = info [ 1 ] . to_i info [ 2 ] . sub! ( / \{ \} \Z / , '' ) if info [ 2 ] info end
Returns information about the caller of the previous method .
4,711
def version_gt ( v1 , v2 ) Array . new ( [ v1 . length , v2 . length ] . max ) . zip ( v1 . split ( "." ) , v2 . split ( "." ) ) do | _ , p1 , p2 | p1 ||= "0" p2 ||= "0" release1 = p1 =~ / / release2 = p2 =~ / / if release1 && release2 p1 , p2 = p1 . to_i , p2 . to_i next if p1 == p2 return p1 > p2 elsif ! release1 && ...
Returns whether one version string represents a more recent version than another .
4,712
def deprecated ( obj , message = nil ) obj_class = obj . is_a? ( Class ) ? "#{obj}." : "#{obj.class}#" full_message = "DEPRECATION WARNING: #{obj_class}#{caller_info[2]} " + "will be removed in a future version of Sass.#{("\n" + message) if message}" Sass :: Util . sass_warn full_message end
Prints a deprecation warning for the caller method .
4,713
def silence_sass_warnings old_level , Sass . logger . log_level = Sass . logger . log_level , :error yield ensure Sass . logger . log_level = old_level end
Silences all Sass warnings within a block .
4,714
def rails_root if defined? ( :: Rails . root ) return :: Rails . root . to_s if :: Rails . root raise "ERROR: Rails.root is nil!" end return RAILS_ROOT . to_s if defined? ( RAILS_ROOT ) nil end
Cross Rails Version Compatibility Returns the root of the Rails application if this is running in a Rails context . Returns nil if no such root is defined .
4,715
def ap_geq? ( version ) return false unless defined? ( ActionPack ) && defined? ( ActionPack :: VERSION ) && defined? ( ActionPack :: VERSION :: STRING ) version_geq ( ActionPack :: VERSION :: STRING , version ) end
Returns whether this environment is using ActionPack of a version greater than or equal to that specified .
4,716
def glob ( path ) path = path . tr ( '\\' , '/' ) if windows? if block_given? Dir . glob ( path ) { | f | yield ( f ) } else Dir . glob ( path ) end end
Like Dir . glob but works with backslash - separated paths on Windows .
4,717
def realpath ( path ) path = Pathname . new ( path ) unless path . is_a? ( Pathname ) begin path . realpath rescue SystemCallError path end end
Returns path with all symlinks resolved .
4,718
def relative_path_from ( path , from ) pathname ( path . to_s ) . relative_path_from ( pathname ( from . to_s ) ) rescue NoMethodError => e raise e unless e . name == :zero? path = path . to_s from = from . to_s raise ArgumentError ( "Incompatible path encodings: #{path.inspect} is #{path.encoding}, " + "#{from.inspect...
Returns path relative to from .
4,719
def extract! ( array ) out = [ ] array . reject! do | e | next false unless yield e out << e true end out end
Destructively removes all elements from an array that match a block and returns the removed elements .
4,720
def with_extracted_values ( arr ) str , vals = extract_values ( arr ) str = yield str inject_values ( str , vals ) end
Allows modifications to be performed on the string form of an array containing both strings and non - strings .
4,721
def json_escape_string ( s ) return s if s !~ / \\ \b \f \n \r \t / result = "" s . split ( "" ) . each do | c | case c when '"' , "\\" result << "\\" << c when "\n" then result << "\\n" when "\t" then result << "\\t" when "\r" then result << "\\r" when "\f" then result << "\\f" when "\b" then result << "\\b" else resu...
Escapes certain characters so that the result can be used as the JSON string value . Returns the original string if no escaping is necessary .
4,722
def json_value_of ( v ) case v when Integer v . to_s when String "\"" + json_escape_string ( v ) + "\"" when Array "[" + v . map { | x | json_value_of ( x ) } . join ( "," ) + "]" when NilClass "null" when TrueClass "true" when FalseClass "false" else raise ArgumentError . new ( "Unknown type: #{v.class.name}" ) end en...
Converts the argument into a valid JSON value .
4,723
def atomic_create_and_write_file ( filename , perms = 0666 ) require 'tempfile' tmpfile = Tempfile . new ( File . basename ( filename ) , File . dirname ( filename ) ) tmpfile . binmode if tmpfile . respond_to? ( :binmode ) result = yield tmpfile tmpfile . close ATOMIC_WRITE_MUTEX . synchronize do begin File . chmod ( ...
This creates a temp file and yields it for writing . When the write is complete the file is moved into the desired location . The atomicity of this operation is provided by the filesystem s rename operation .
4,724
def options = ( options ) super value . each do | k , v | k . options = options v . options = options end end
Creates a new map .
4,725
def perform ( environment ) _perform ( environment ) rescue Sass :: SyntaxError => e e . modify_backtrace ( :line => line ) raise e end
Evaluates the node .
4,726
def _perform ( environment ) args = @args . each_with_index . map { | a , i | perform_arg ( a , environment , signature && signature . args [ i ] ) } keywords = Sass :: Util . map_hash ( @keywords ) do | k , v | [ k , perform_arg ( v , environment , k . tr ( '-' , '_' ) ) ] end splat = Sass :: Tree :: Visitors :: Perfo...
Evaluates the function call .
4,727
def caller return @caller if @caller env = super @caller ||= env . is_a? ( ReadOnlyEnvironment ) ? env : ReadOnlyEnvironment . new ( env , env . options ) end
The read - only environment of the caller of this environment s mixin or function .
4,728
def content return @content if @content_cached read_write_content = super if read_write_content tree , env = read_write_content if env && ! env . is_a? ( ReadOnlyEnvironment ) env = ReadOnlyEnvironment . new ( env , env . options ) end @content_cached = true @content = [ tree , env ] else @content_cached = true @conten...
The content passed to this environment . If the content s environment isn t already read - only it s made read - only .
4,729
def to_string_interpolation ( node_or_interp ) unless node_or_interp . is_a? ( Interpolation ) node = node_or_interp return string_literal ( node . value . to_s ) if node . is_a? ( Literal ) if node . is_a? ( StringInterpolation ) return concat ( string_literal ( node . quote ) , concat ( node , string_literal ( node ....
Converts a script node into a corresponding string interpolation expression .
4,730
def concat ( string_or_interp1 , string_or_interp2 ) if string_or_interp1 . is_a? ( Literal ) && string_or_interp2 . is_a? ( Literal ) return string_literal ( string_or_interp1 . value . value + string_or_interp2 . value . value ) end if string_or_interp1 . is_a? ( Literal ) string = string_or_interp1 interp = string_o...
Concatenates two string literals or string interpolation expressions .
4,731
def string_literal ( string ) Literal . new ( Sass :: Script :: Value :: String . new ( string , :string ) ) end
Returns a string literal with the given contents .
4,732
def process_result require 'sass' if ! @options [ :update ] && ! @options [ :watch ] && @args . first && colon_path? ( @args . first ) if @args . size == 1 @args = split_colon_path ( @args . first ) else @fake_update = true @options [ :update ] = true end end load_compass if @options [ :compass ] return interactive if ...
Processes the options set by the command - line arguments and runs the Sass compiler appropriately .
4,733
def warn ( filename , line , column_or_message , message = nil ) return if ! @@allow_double_warnings && @seen . add? ( [ filename , line ] ) . nil? if message column = column_or_message else message = column_or_message end location = "line #{line}" location << ", column #{column}" if column location << " of #{filename}...
Prints message as a deprecation warning associated with filename line and optionally column .
4,734
def update_stylesheets ( individual_files = [ ] ) Sass :: Plugin . checked_for_updates = true staleness_checker = StalenessChecker . new ( engine_options ) files = file_list ( individual_files ) run_updating_stylesheets ( files ) updated_stylesheets = [ ] files . each do | file , css , sourcemap | if options [ :always_...
Updates out - of - date stylesheets .
4,735
def file_list ( individual_files = [ ] ) files = individual_files . map do | tuple | if engine_options [ :sourcemap ] == :none tuple [ 0 .. 1 ] elsif tuple . size < 3 [ tuple [ 0 ] , tuple [ 1 ] , Sass :: Util . sourcemap_name ( tuple [ 1 ] ) ] else tuple . dup end end template_location_array . each do | template_locat...
Construct a list of files that might need to be compiled from the provided individual_files and the template_locations .
4,736
def clean ( individual_files = [ ] ) file_list ( individual_files ) . each do | ( _ , css_file , sourcemap_file ) | if File . exist? ( css_file ) run_deleting_css css_file File . delete ( css_file ) end if sourcemap_file && File . exist? ( sourcemap_file ) run_deleting_sourcemap sourcemap_file File . delete ( sourcemap...
Remove all output files that would be created by calling update_stylesheets if they exist .
4,737
def with ( attrs ) attrs = attrs . reject { | _k , v | v . nil? } hsl = ! ( [ :hue , :saturation , :lightness ] & attrs . keys ) . empty? rgb = ! ( [ :red , :green , :blue ] & attrs . keys ) . empty? if hsl && rgb raise ArgumentError . new ( "Cannot specify HSL and RGB values for a color at the same time" ) end if hsl ...
Returns a copy of this color with one or more channels changed . RGB or HSL colors may be changed but not both at once .
4,738
def to_s ( opts = { } ) return smallest if options [ :style ] == :compressed return representation if representation return rgba_str if Number . basically_equal? ( alpha , 0 ) return name if name alpha? ? rgba_str : hex_str end
Returns a string representation of the color . This is usually the color s hex value but if the color has a name that s used instead .
4,739
def shift_output_lines ( delta ) return if delta == 0 @data . each do | m | m . output . start_pos . line += delta m . output . end_pos . line += delta end end
Shifts all output source ranges forward one or more lines .
4,740
def shift_output_offsets ( delta ) return if delta == 0 @data . each do | m | break if m . output . start_pos . line > 1 m . output . start_pos . offset += delta m . output . end_pos . offset += delta if m . output . end_pos . line > 1 end end
Shifts any output source ranges that lie on the first line forward one or more characters on that line .
4,741
def lines @value . inject ( 0 ) do | s , e | next s + e . count ( "\n" ) if e . is_a? ( String ) next s end end
Returns the number of lines in the comment .
4,742
def force_update_stylesheets ( individual_files = [ ] ) Compiler . new ( options . dup . merge ( :never_update => false , :always_update => true , :cache => false ) ) . update_stylesheets ( individual_files ) end
Updates all stylesheets even those that aren t out - of - date . Ignores the cache .
4,743
def ie_hex_str ( color ) assert_type color , :Color , :color alpha = Sass :: Util . round ( color . alpha * 255 ) . to_s ( 16 ) . rjust ( 2 , '0' ) identifier ( "##{alpha}#{color.send(:hex_str)[1..-1]}" . upcase ) end
Converts a color into the format understood by IE filters .
4,744
def adjust_color ( color , kwargs ) assert_type color , :Color , :color with = Sass :: Util . map_hash ( "red" => [ - 255 .. 255 , "" ] , "green" => [ - 255 .. 255 , "" ] , "blue" => [ - 255 .. 255 , "" ] , "hue" => nil , "saturation" => [ - 100 .. 100 , "%" ] , "lightness" => [ - 100 .. 100 , "%" ] , "alpha" => [ - 1 ...
Increases or decreases one or more properties of a color . This can change the red green blue hue saturation value and alpha properties . The properties are specified as keyword arguments and are added to or subtracted from the color s current value for that property .
4,745
def change_color ( color , kwargs ) assert_type color , :Color , :color with = Sass :: Util . map_hash ( 'red' => [ 'Red value' , 0 .. 255 ] , 'green' => [ 'Green value' , 0 .. 255 ] , 'blue' => [ 'Blue value' , 0 .. 255 ] , 'hue' => [ ] , 'saturation' => [ 'Saturation' , 0 .. 100 , '%' ] , 'lightness' => [ 'Lightness'...
Changes one or more properties of a color . This can change the red green blue hue saturation value and alpha properties . The properties are specified as keyword arguments and replace the color s current value for that property .
4,746
def mix ( color1 , color2 , weight = number ( 50 ) ) assert_type color1 , :Color , :color1 assert_type color2 , :Color , :color2 assert_type weight , :Number , :weight Sass :: Util . check_range ( "Weight" , 0 .. 100 , weight , '%' ) p = ( weight . value / 100.0 ) . to_f w = p * 2 - 1 a = color1 . alpha - color2 . alph...
Mixes two colors together . Specifically takes the average of each of the RGB components optionally weighted by the given percentage . The opacity of the colors is also considered when weighting the components .
4,747
def quote ( string ) assert_type string , :String , :string if string . type != :string quoted_string ( string . value ) else string end end
Add quotes to a string if the string isn t quoted or returns the same string if it is .
4,748
def to_upper_case ( string ) assert_type string , :String , :string Sass :: Script :: Value :: String . new ( Sass :: Util . upcase ( string . value ) , string . type ) end
Converts a string to upper case .
4,749
def to_lower_case ( string ) assert_type string , :String , :string Sass :: Script :: Value :: String . new ( Sass :: Util . downcase ( string . value ) , string . type ) end
Convert a string to lower case
4,750
def type_of ( value ) value . check_deprecated_interp if value . is_a? ( Sass :: Script :: Value :: String ) identifier ( value . class . name . gsub ( / / , '' ) . downcase ) end
Returns the type of a value .
4,751
def comparable ( number1 , number2 ) assert_type number1 , :Number , :number1 assert_type number2 , :Number , :number2 bool ( number1 . comparable_to? ( number2 ) ) end
Returns whether two numbers can added subtracted or compared .
4,752
def percentage ( number ) unless number . is_a? ( Sass :: Script :: Value :: Number ) && number . unitless? raise ArgumentError . new ( "$number: #{number.inspect} is not a unitless number" ) end number ( number . value * 100 , '%' ) end
Converts a unitless number to a percentage .
4,753
def min ( * numbers ) numbers . each { | n | assert_type n , :Number } numbers . inject { | min , num | min . lt ( num ) . to_bool ? min : num } end
Finds the minimum of several numbers . This function takes any number of arguments .
4,754
def max ( * values ) values . each { | v | assert_type v , :Number } values . inject { | max , val | max . gt ( val ) . to_bool ? max : val } end
Finds the maximum of several numbers . This function takes any number of arguments .
4,755
def set_nth ( list , n , value ) assert_type n , :Number , :n Sass :: Script :: Value :: List . assert_valid_index ( list , n ) index = n . to_i > 0 ? n . to_i - 1 : n . to_i new_list = list . to_a . dup new_list [ index ] = value list . with_contents ( new_list ) end
Return a new list based on the list provided but with the nth element changed to the value given .
4,756
def nth ( list , n ) assert_type n , :Number , :n Sass :: Script :: Value :: List . assert_valid_index ( list , n ) index = n . to_i > 0 ? n . to_i - 1 : n . to_i list . to_a [ index ] end
Gets the nth item in a list .
4,757
def join ( list1 , list2 , separator = identifier ( "auto" ) , bracketed = identifier ( "auto" ) , kwargs = nil , * rest ) if separator . is_a? ( Hash ) kwargs = separator separator = identifier ( "auto" ) elsif bracketed . is_a? ( Hash ) kwargs = bracketed bracketed = identifier ( "auto" ) elsif rest . last . is_a? ( ...
Joins together two lists into one .
4,758
def append ( list , val , separator = identifier ( "auto" ) ) assert_type separator , :String , :separator unless %w( auto space comma ) . include? ( separator . value ) raise ArgumentError . new ( "Separator name must be space, comma, or auto" ) end list . with_contents ( list . to_a + [ val ] , separator : if separat...
Appends a single value onto the end of a list .
4,759
def zip ( * lists ) length = nil values = [ ] lists . each do | list | array = list . to_a values << array . dup length = length . nil? ? array . length : [ length , array . length ] . min end values . each do | value | value . slice! ( length ) end new_list_value = values . first . zip ( * values [ 1 .. - 1 ] ) list (...
Combines several lists into a single multidimensional list . The nth value of the resulting list is a space separated list of the source lists nth values .
4,760
def index ( list , value ) index = list . to_a . index { | e | e . eq ( value ) . to_bool } index ? number ( index + 1 ) : null end
Returns the position of a value within a list . If the value isn t found returns null instead .
4,761
def map_remove ( map , * keys ) assert_type map , :Map , :map hash = map . to_h . dup hash . delete_if { | key , _ | keys . include? ( key ) } map ( hash ) end
Returns a new map with keys removed .
4,762
def map_has_key ( map , key ) assert_type map , :Map , :map bool ( map . to_h . has_key? ( key ) ) end
Returns whether a map has a value associated with a given key .
4,763
def unique_id generator = Sass :: Script :: Functions . random_number_generator Thread . current [ :sass_last_unique_id ] ||= generator . rand ( 36 ** 8 ) value = ( Thread . current [ :sass_last_unique_id ] += ( generator . rand ( 10 ) + 1 ) ) identifier ( "u" + value . to_s ( 36 ) . rjust ( 8 , '0' ) ) end
Returns a unique CSS identifier . The identifier is returned as an unquoted string . The identifier returned is only guaranteed to be unique within the scope of a single Sass run .
4,764
def variable_exists ( name ) assert_type name , :String , :name bool ( environment . caller . var ( name . value ) ) end
Check whether a variable with the given name exists in the current scope or in the global scope .
4,765
def function_exists ( name ) assert_type name , :String , :name exists = Sass :: Script :: Functions . callable? ( name . value . tr ( "-" , "_" ) ) exists ||= environment . caller . function ( name . value ) bool ( exists ) end
Check whether a function with the given name exists .
4,766
def content_exists mixin_frame = environment . stack . frames [ - 2 ] unless mixin_frame && mixin_frame . type == :mixin raise Sass :: SyntaxError . new ( "Cannot call content-exists() except within a mixin." ) end bool ( ! environment . caller . content . nil? ) end
Check whether a mixin was passed a content block .
4,767
def inspect ( value ) value . check_deprecated_interp if value . is_a? ( Sass :: Script :: Value :: String ) unquoted_string ( value . to_sass ) end
Return a string containing the value as its Sass representation .
4,768
def selector_unify ( selector1 , selector2 ) selector1 = parse_selector ( selector1 , :selector1 ) selector2 = parse_selector ( selector2 , :selector2 ) return null unless ( unified = selector1 . unify ( selector2 ) ) unified . to_sass_script end
Unifies two selectors into a single selector that matches only elements matched by both input selectors . Returns null if there is no such selector .
4,769
def numeric_transformation ( value ) assert_type value , :Number , :value Sass :: Script :: Value :: Number . new ( yield ( value . value ) , value . numerator_units , value . denominator_units ) end
This method implements the pattern of transforming a numeric value into another numeric value with the same units . It yields a number to a block to perform the operation and return a number
4,770
def merge ( other ) m1 , t1 = resolved_modifier . downcase , resolved_type . downcase m2 , t2 = other . resolved_modifier . downcase , other . resolved_type . downcase t1 = t2 if t1 . empty? t2 = t1 if t2 . empty? if ( m1 == 'not' ) ^ ( m2 == 'not' ) return if t1 == t2 type = m1 == 'not' ? t2 : t1 mod = m1 == 'not' ? m...
Merges this query with another . The returned query queries for the intersection between the two inputs .
4,771
def to_css css = '' css << resolved_modifier css << ' ' unless resolved_modifier . empty? css << resolved_type css << ' and ' unless resolved_type . empty? || expressions . empty? css << expressions . map do | e | e . map { | c | c . is_a? ( Sass :: Script :: Tree :: Node ) ? c . to_sass : c . to_s } . join end . join ...
Returns the CSS for the media query .
4,772
def deep_copy Query . new ( modifier . map { | c | c . is_a? ( Sass :: Script :: Tree :: Node ) ? c . deep_copy : c } , type . map { | c | c . is_a? ( Sass :: Script :: Tree :: Node ) ? c . deep_copy : c } , expressions . map { | e | e . map { | c | c . is_a? ( Sass :: Script :: Tree :: Node ) ? c . deep_copy : c } } )...
Returns a deep copy of this query and all its children .
4,773
def element_needs_parens? ( element ) if element . is_a? ( ListLiteral ) return false if element . elements . length < 2 return false if element . bracketed return Sass :: Script :: Parser . precedence_of ( element . separator || :space ) <= Sass :: Script :: Parser . precedence_of ( separator || :space ) end return fa...
Returns whether an element in the list should be wrapped in parentheses when serialized to Sass .
4,774
def is_literal_number? ( value ) value . is_a? ( Literal ) && value . value . is_a? ( ( Sass :: Script :: Value :: Number ) ) && ! value . value . original . nil? end
Returns whether a value is a number literal that shouldn t be divided .
4,775
def build_tree root = Sass :: SCSS :: CssParser . new ( @template , @options [ :filename ] , nil ) . parse parse_selectors ( root ) expand_commas ( root ) nest_seqs ( root ) parent_ref_rules ( root ) flatten_rules ( root ) bubble_subject ( root ) fold_commas ( root ) dump_selectors ( root ) root end
Parses the CSS template and applies various transformations
4,776
def nest_seqs ( root ) current_rule = nil root . children . map! do | child | unless child . is_a? ( Tree :: RuleNode ) nest_seqs ( child ) if child . is_a? ( Tree :: DirectiveNode ) next child end seq = first_seq ( child ) seq . members . reject! { | sseq | sseq == "\n" } first , rest = seq . members . first , seq . m...
Make rules use nesting so that
4,777
def parent_ref_rules ( root ) current_rule = nil root . children . map! do | child | unless child . is_a? ( Tree :: RuleNode ) parent_ref_rules ( child ) if child . is_a? ( Tree :: DirectiveNode ) next child end sseq = first_sseq ( child ) next child unless sseq . is_a? ( Sass :: Selector :: SimpleSequence ) firsts , r...
Make rules use parent refs so that
4,778
def flatten_rules ( root ) root . children . each do | child | case child when Tree :: RuleNode flatten_rule ( child ) when Tree :: DirectiveNode flatten_rules ( child ) end end end
Flatten rules so that
4,779
def flatten_rule ( rule ) while rule . children . size == 1 && rule . children . first . is_a? ( Tree :: RuleNode ) child = rule . children . first if first_simple_sel ( child ) . is_a? ( Sass :: Selector :: Parent ) rule . parsed_rules = child . parsed_rules . resolve_parent_refs ( rule . parsed_rules ) else rule . pa...
Flattens a single rule .
4,780
def visit ( node ) if respond_to? ( node . class . visit_method , true ) send ( node . class . visit_method , node ) { visit_children ( node ) } else visit_children ( node ) end end
Runs the visitor on the given node . This can be overridden by subclasses that need to do something for each node .
4,781
def process_result require 'sass' if @options [ :recursive ] process_directory return end super input = @options [ :input ] if File . directory? ( input ) raise "Error: '#{input.path}' is a directory (did you mean to use --recursive?)" end output = @options [ :output ] output = input if @options [ :in_place ] process_f...
Processes the options set by the command - line arguments and runs the CSS compiler appropriately .
4,782
def mod ( other ) if other . is_a? ( Number ) return Number . new ( Float :: NAN ) if other . value == 0 operate ( other , :% ) else raise NoMethodError . new ( nil , :mod ) end end
The SassScript % operation .
4,783
def eq ( other ) return Bool :: FALSE unless other . is_a? ( Sass :: Script :: Value :: Number ) this = self begin if unitless? this = this . coerce ( other . numerator_units , other . denominator_units ) else other = other . coerce ( @numerator_units , @denominator_units ) end rescue Sass :: UnitConversionError return...
The SassScript == operation .
4,784
def gt ( other ) raise NoMethodError . new ( nil , :gt ) unless other . is_a? ( Number ) operate ( other , :> ) end
Hash - equality works differently than == equality for numbers . Hash - equality must be transitive so it just compares the exact value numerator units and denominator units . The SassScript > operation .
4,785
def gte ( other ) raise NoMethodError . new ( nil , :gte ) unless other . is_a? ( Number ) operate ( other , :>= ) end
The SassScript > = operation .
4,786
def lt ( other ) raise NoMethodError . new ( nil , :lt ) unless other . is_a? ( Number ) operate ( other , :< ) end
The SassScript < operation .
4,787
def lte ( other ) raise NoMethodError . new ( nil , :lte ) unless other . is_a? ( Number ) operate ( other , :<= ) end
The SassScript < = operation .
4,788
def inspect ( opts = { } ) return original if original value = self . class . round ( self . value ) str = value . to_s str = ( "%0.#{self.class.precision}f" % value ) . gsub ( / / , '' ) if str . include? ( 'e' ) if str =~ / \. / str = $1 end if @options && options [ :style ] == :compressed str . sub! ( / \. / , '\1.'...
Returns a readable representation of this number .
4,789
def is_unit? ( unit ) if unit denominator_units . size == 0 && numerator_units . size == 1 && numerator_units . first == unit else unitless? end end
Checks whether the number has the numerator unit specified .
4,790
def plus ( other ) type = other . is_a? ( Sass :: Script :: Value :: String ) ? other . type : :identifier Sass :: Script :: Value :: String . new ( to_s ( :quote => :none ) + other . to_s ( :quote => :none ) , type ) end
The SassScript + operation .
4,791
def with_contents ( contents , separator : self . separator , bracketed : self . bracketed ) Sass :: Script :: Value :: List . new ( contents , separator : separator , bracketed : bracketed ) end
Creates a new list containing contents but with the same brackets and separators as this object when interpreted as a list .
4,792
def _perform ( environment ) val = environment . var ( name ) raise Sass :: SyntaxError . new ( "Undefined variable: \"$#{name}\"." ) unless val if val . is_a? ( Sass :: Script :: Value :: Number ) && val . original val = val . dup val . original = nil end val end
Evaluates the variable .
4,793
def get_line ( exception ) if exception . is_a? ( :: SyntaxError ) return ( exception . message . scan ( / \d / ) . first || [ "??" ] ) . first end ( exception . backtrace [ 0 ] . scan ( / \d / ) . first || [ "??" ] ) . first end
Finds the line of the source template on which an exception was raised .
4,794
def encoding_option ( opts ) encoding_desc = 'Specify the default encoding for input files.' opts . on ( '-E' , '--default-encoding ENCODING' , encoding_desc ) do | encoding | Encoding . default_external = encoding end end
Set an option for specifying Encoding . default_external .
4,795
def color ( color , str ) raise "[BUG] Unrecognized color #{color}" unless COLORS [ color ] return str if ENV [ "TERM" ] . nil? || ENV [ "TERM" ] . empty? || ! STDOUT . tty? "\e[#{COLORS[color]}m#{str}\e[0m" end
Wraps the given string in terminal escapes causing it to have the given color . If terminal escapes aren t supported on this platform just returns the string instead .
4,796
def hsl_color ( hue , saturation , lightness , alpha = nil ) attrs = { :hue => hue , :saturation => saturation , :lightness => lightness } attrs [ :alpha ] = alpha if alpha Color . new ( attrs ) end
Construct a Sass Color from hsl values .
4,797
def rgb_color ( red , green , blue , alpha = nil ) attrs = { :red => red , :green => green , :blue => blue } attrs [ :alpha ] = alpha if alpha Color . new ( attrs ) end
Construct a Sass Color from rgb values .
4,798
def parse_selector ( value , name = nil , allow_parent_ref = false ) str = normalize_selector ( value , name ) begin Sass :: SCSS :: StaticParser . new ( str , nil , nil , 1 , 1 , allow_parent_ref ) . parse_selector rescue Sass :: SyntaxError => e err = "#{value.inspect} is not a valid selector: #{e}" err = "$#{name.to...
Parses a user - provided selector .
4,799
def parse_complex_selector ( value , name = nil , allow_parent_ref = false ) selector = parse_selector ( value , name , allow_parent_ref ) return seq if selector . members . length == 1 err = "#{value.inspect} is not a complex selector" err = "$#{name.to_s.tr('_', '-')}: #{err}" if name raise ArgumentError . new ( err ...
Parses a user - provided complex selector .