Class: Sass::Media::Query
- Inherits:
-
Object
- Object
- Sass::Media::Query
- Defined in:
- .ruby-sass/lib/sass/media.rb
Overview
A single media query.
[ [ONLY | NOT]? S* media_type S* | expression ] [ AND S* expression ]*
Instance Attribute Summary (collapse)
-
#expressions ⇒ Array<Array<String, Sass::Script::Tree::Node>>
The trailing expressions in the query.
-
#modifier ⇒ Array<String, Sass::Script::Tree::Node>
The modifier for the query.
-
#type ⇒ Array<String, Sass::Script::Tree::Node>
The type of the query (e.g. `“screen”` or `“print”`).
Instance Method Summary (collapse)
-
#deep_copy ⇒ Query
Returns a deep copy of this query and all its children.
-
#initialize(modifier, type, expressions) ⇒ Query
constructor
A new instance of Query.
-
#merge(other) ⇒ Query?
Merges this query with another.
-
#resolved_modifier ⇒ String
See #modifier.
-
#resolved_type ⇒ String
See #type.
- #to_a ⇒ Object
-
#to_css ⇒ String
Returns the CSS for the media query.
-
#to_src(options) ⇒ String
Returns the Sass/SCSS code for the media query.
Constructor Details
#initialize(modifier, type, expressions) ⇒ Query
Returns a new instance of Query
96 97 98 99 100 |
# File '.ruby-sass/lib/sass/media.rb', line 96 def initialize(modifier, type, expressions) @modifier = modifier @type = type @expressions = expressions end |
Constructor Details
#initialize(modifier, type, expressions) ⇒ Query
Returns a new instance of Query
96 97 98 99 100 |
# File '.ruby-sass/lib/sass/media.rb', line 96 def initialize(modifier, type, expressions) @modifier = modifier @type = type @expressions = expressions end |
Instance Attribute Details
#expressions ⇒ Array<Array<String, Sass::Script::Tree::Node>>
The trailing expressions in the query.
When parsed as Sass code, each expression contains strings and SassScript nodes. When parsed as CSS, each one contains a single string.
91 92 93 |
# File '.ruby-sass/lib/sass/media.rb', line 91 def expressions @expressions end |
#modifier ⇒ Array<String, Sass::Script::Tree::Node>
The modifier for the query.
When parsed as Sass code, this contains strings and SassScript nodes. When parsed as CSS, it contains a single string (accessible via #resolved_modifier).
74 75 76 |
# File '.ruby-sass/lib/sass/media.rb', line 74 def modifier @modifier end |
#type ⇒ Array<String, Sass::Script::Tree::Node>
The type of the query (e.g. `“screen”` or `“print”`).
When parsed as Sass code, this contains strings and SassScript nodes. When parsed as CSS, it contains a single string (accessible via #resolved_type).
83 84 85 |
# File '.ruby-sass/lib/sass/media.rb', line 83 def type @type end |
Instance Method Details
#deep_copy ⇒ Query
Returns a deep copy of this query and all its children.
194 195 196 197 198 199 |
# File '.ruby-sass/lib/sass/media.rb', line 194 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}}) end |
#merge(other) ⇒ Query?
Merges this query with another. The returned query queries for the intersection between the two inputs.
Both queries should be resolved.
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File '.ruby-sass/lib/sass/media.rb', line 123 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' ? m2 : m1 elsif m1 == 'not' && m2 == 'not' # CSS has no way of representing "neither screen nor print" return unless t1 == t2 type = t1 mod = 'not' elsif t1 != t2 return else # t1 == t2, neither m1 nor m2 are "not" type = t1 mod = m1.empty? ? m2 : m1 end Query.new([mod], [type], other.expressions + expressions) end |
#resolved_modifier ⇒ String
See #modifier.
104 105 106 107 |
# File '.ruby-sass/lib/sass/media.rb', line 104 def resolved_modifier # modifier should contain only a single string modifier.first || '' end |
#resolved_type ⇒ String
See #type.
111 112 113 114 |
# File '.ruby-sass/lib/sass/media.rb', line 111 def resolved_type # type should contain only a single string type.first || '' end |
#to_a ⇒ Object
181 182 183 184 185 186 187 188 189 |
# File '.ruby-sass/lib/sass/media.rb', line 181 def to_a res = [] res += modifier res << ' ' unless modifier.empty? res += type res << ' and ' unless type.empty? || expressions.empty? res += Sass::Util.intersperse(expressions, ' and ').flatten res end |
#to_css ⇒ String
Returns the CSS for the media query.
149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File '.ruby-sass/lib/sass/media.rb', line 149 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| # It's possible for there to be script nodes in Expressions even when # we're converting to CSS in the case where we parsed the document as # CSS originally (as in css_test.rb). e.map {|c| c.is_a?(Sass::Script::Tree::Node) ? c.to_sass : c.to_s}.join end.join(' and ') css end |
#to_src(options) ⇒ String
Returns the Sass/SCSS code for the media query.
168 169 170 171 172 173 174 175 176 177 178 |
# File '.ruby-sass/lib/sass/media.rb', line 168 def to_src() src = '' src << Sass::Media._interp_to_src(modifier, ) src << ' ' unless modifier.empty? src << Sass::Media._interp_to_src(type, ) src << ' and ' unless type.empty? || expressions.empty? src << expressions.map do |e| Sass::Media._interp_to_src(e, ) end.join(' and ') src end |