Class: Inkcite::View::MediaQuery
- Inherits:
-
Object
- Object
- Inkcite::View::MediaQuery
- Defined in:
- lib/inkcite/view/media_query.rb
Instance Method Summary collapse
- #<<(rule) ⇒ Object
- #active_styles ⇒ Object
- #blank? ⇒ Boolean
- #find_by_declaration(declarations) ⇒ Object
- #find_by_klass(klass) ⇒ Object
- #find_by_tag_and_klass(tag, klass) ⇒ Object
-
#initialize(view, max_width) ⇒ MediaQuery
constructor
A new instance of MediaQuery.
- #to_a ⇒ Object
- #to_css ⇒ Object
Constructor Details
#initialize(view, max_width) ⇒ MediaQuery
Returns a new instance of MediaQuery.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/inkcite/view/media_query.rb', line 5 def initialize view, max_width @view = view @max_width = max_width # Initialize the responsive styles used in this email. This will hold # an array of Responsive::Rule objects. @responsive_styles = Renderer::Responsive.presets(view) end |
Instance Method Details
#<<(rule) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/inkcite/view/media_query.rb', line 16 def << rule # Rules only get added once @responsive_styles << rule unless @responsive_styles.include?(rule) rule end |
#active_styles ⇒ Object
24 25 26 |
# File 'lib/inkcite/view/media_query.rb', line 24 def active_styles @responsive_styles.select(&:active?) end |
#blank? ⇒ Boolean
28 29 30 |
# File 'lib/inkcite/view/media_query.rb', line 28 def blank? @responsive_styles.none?(&:active?) end |
#find_by_declaration(declarations) ⇒ Object
32 33 34 |
# File 'lib/inkcite/view/media_query.rb', line 32 def find_by_declaration declarations @responsive_styles.detect { |r| r.declarations == declarations } end |
#find_by_klass(klass) ⇒ Object
36 37 38 |
# File 'lib/inkcite/view/media_query.rb', line 36 def find_by_klass klass @responsive_styles.detect { |r| r.klass == klass } end |
#find_by_tag_and_klass(tag, klass) ⇒ Object
40 41 42 |
# File 'lib/inkcite/view/media_query.rb', line 40 def find_by_tag_and_klass tag, klass @responsive_styles.detect { |r| r.klass == klass && r.include?(tag) } end |
#to_a ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/inkcite/view/media_query.rb', line 44 def to_a css = [] css << "@media only screen and (max-width: #{Inkcite::Renderer::px(@max_width)}) {" css += active_styles.collect(&:to_css) css << '}' css end |
#to_css ⇒ Object
54 55 56 |
# File 'lib/inkcite/view/media_query.rb', line 54 def to_css to_a.join("\n") end |