Class: Inkcite::Renderer::Responsive::Rule
- Inherits:
-
Object
- Object
- Inkcite::Renderer::Responsive::Rule
- Defined in:
- lib/inkcite/renderer/responsive.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#declarations ⇒ Object
readonly
Returns the value of attribute declarations.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
Instance Method Summary collapse
- #<<(tag) ⇒ Object
- #activate! ⇒ Object
- #active? ⇒ Boolean
- #att_selector_string ⇒ Object
- #block? ⇒ Boolean
- #declaration_string ⇒ Object
- #include?(tag) ⇒ Boolean
-
#initialize(tags, klass, declarations, active = true) ⇒ Rule
constructor
A new instance of Rule.
- #to_css ⇒ Object
- #universal? ⇒ Boolean
Constructor Details
#initialize(tags, klass, declarations, active = true) ⇒ Rule
Returns a new instance of Rule.
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/inkcite/renderer/responsive.rb', line 39 def initialize , klass, declarations, active=true @klass = klass @declarations = declarations = Set.new [*] # By default, a rule isn't considered active until it has # been marked used. This allows the view to declare built-in # styles (such as hide or stack) that don't show up in the # rendered HTML unless the author references them. @active = active end |
Instance Attribute Details
#declarations ⇒ Object (readonly)
Returns the value of attribute declarations.
36 37 38 |
# File 'lib/inkcite/renderer/responsive.rb', line 36 def declarations @declarations end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
37 38 39 |
# File 'lib/inkcite/renderer/responsive.rb', line 37 def klass @klass end |
Instance Method Details
#<<(tag) ⇒ Object
53 54 55 |
# File 'lib/inkcite/renderer/responsive.rb', line 53 def << tag << tag end |
#activate! ⇒ Object
57 58 59 |
# File 'lib/inkcite/renderer/responsive.rb', line 57 def activate! @active = true end |
#active? ⇒ Boolean
61 62 63 |
# File 'lib/inkcite/renderer/responsive.rb', line 61 def active? @active end |
#att_selector_string ⇒ Object
65 66 67 |
# File 'lib/inkcite/renderer/responsive.rb', line 65 def att_selector_string ".#{@klass}" end |
#block? ⇒ Boolean
69 70 71 |
# File 'lib/inkcite/renderer/responsive.rb', line 69 def block? declaration_string.downcase.include?('block') end |
#declaration_string ⇒ Object
73 74 75 76 77 78 79 80 81 |
# File 'lib/inkcite/renderer/responsive.rb', line 73 def declaration_string if @declarations.is_a?(Hash) Renderer.render_styles(@declarations) elsif @declarations.is_a?(Array) @declarations.join(' ') else @declarations.to_s end end |
#include?(tag) ⇒ Boolean
83 84 85 |
# File 'lib/inkcite/renderer/responsive.rb', line 83 def include? tag universal? || .include?(tag) end |
#to_css ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/inkcite/renderer/responsive.rb', line 87 def to_css rule = "" att_selector = att_selector_string if universal? # Only the attribute selector is needed when the rule is universal. # http://www.w3.org/TR/CSS2/selector.html#universal-selector rule << att_selector else # Create an attribute selector that targets each tag. .sort.each do |tag| rule << ',' unless rule.blank? rule << tag rule << att_selector end end rule << " { " rule << declaration_string rule << " }" rule end |
#universal? ⇒ Boolean
117 118 119 |
# File 'lib/inkcite/renderer/responsive.rb', line 117 def universal? .include?(UNIVERSAL) end |