Class: CssProxy

Inherits:
Object show all
Defined in:
lib/atome/extensions/atome.rb

Instance Method Summary collapse

Constructor Details

#initialize(js, parent_key = nil, current_atome) ⇒ CssProxy

Returns a new instance of CssProxy.



790
791
792
793
794
795
796
# File 'lib/atome/extensions/atome.rb', line 790

def initialize(js, parent_key = nil, current_atome)
  @js = js
  @css = {}
  @parent_key = parent_key
  @style = {}
  @current_atome = current_atome
end

Instance Method Details

#[](key) ⇒ Object



798
799
800
801
802
803
804
# File 'lib/atome/extensions/atome.rb', line 798

def [](key)
  if @parent_key
    @current_atome.instance_variable_get('@css')[@parent_key]&.[](key)
  else
    CssProxy.new(@js, key, @current_atome)
  end
end

#[]=(key, value) ⇒ Object



806
807
808
809
810
811
812
813
814
815
816
817
818
# File 'lib/atome/extensions/atome.rb', line 806

def []=(key, value)
  if @parent_key
    @js[@parent_key][key] = value
    @current_atome.instance_variable_set('@css', { @parent_key => { key => value } })
    @css[@parent_key] = { key => value }
    puts "==> parent key: #{@parent_key}, Clé: #{key}, value: #{value}"
  else
    @style[key] = value
    @js[key] = value
  end

  @js.update_style(@style) if @parent_key.nil?
end

#receptor(msg, &bloc) ⇒ Object



824
825
826
827
# File 'lib/atome/extensions/atome.rb', line 824

def receptor(msg, &bloc)
  parsed = JSON.parse(msg)
  bloc.call(parsed)
end

#to_sObject



820
821
822
# File 'lib/atome/extensions/atome.rb', line 820

def to_s
  @current_atome.instance_variable_get('@css').to_s
end