Module: Parcels::Fortitude::Enabling::ClassMethods

Defined in:
lib/parcels/fortitude/enabling.rb

Instance Method Summary collapse

Instance Method Details

#_parcels_ensure_all_tag_methods_overridden!Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/parcels/fortitude/enabling.rb', line 45

def _parcels_ensure_all_tag_methods_overridden!
  tags.each do |tag_name, tag_object|
    done = _parcels_tag_method_overridden?(tag_name)
    next if done

    tag_object.all_method_names.each do |tag_method_name|
      @_parcels_tag_methods_module.send(:define_method, tag_method_name) do |*args, &block|
        content_or_attributes = args[0]
        attributes = args[1]

        directly_inside = rendering_context.current_element_nesting.last
        if directly_inside.kind_of?(::Fortitude::Widget) && (css_wrapper_classes = directly_inside.class.try(:_parcels_widget_outer_element_classes))
          if attributes || content_or_attributes.kind_of?(String)
            super(content_or_attributes, self.class._parcels_add_wrapper_css_classes_to(attributes, css_wrapper_classes), &block)
          else
            super(self.class._parcels_add_wrapper_css_classes_to(content_or_attributes, css_wrapper_classes), attributes, &block)
          end
        else
          super(content_or_attributes, attributes, &block)
        end
      end
    end
  end
end

#_parcels_tag_method_overridden!(tag_name) ⇒ Object



41
42
43
# File 'lib/parcels/fortitude/enabling.rb', line 41

def _parcels_tag_method_overridden!(tag_name)
  @_parcels_tag_methods_overridden[tag_name.to_sym] = true
end

#_parcels_tag_method_overridden?(tag_name) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
39
# File 'lib/parcels/fortitude/enabling.rb', line 36

def _parcels_tag_method_overridden?(tag_name)
  @_parcels_tag_methods_overridden ||= { }
  @_parcels_tag_methods_overridden[tag_name.to_sym]
end

#enable_parcels!Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/parcels/fortitude/enabling.rb', line 17

def enable_parcels!
  raise "Already enabled on #{self}!" if @_parcels_enabled

  record_tag_emission true

  @_parcels_tag_methods_module = Module.new
  const_set(:ParcelsEnablingModule, @_parcels_tag_methods_module)
  include @_parcels_tag_methods_module

  _parcels_ensure_all_tag_methods_overridden!

  @_parcels_enabled = true
end

#parcels_enabled?Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
# File 'lib/parcels/fortitude/enabling.rb', line 10

def parcels_enabled?
  out = false
  out = true if superclass.respond_to?(:parcels_enabled?) && superclass.parcels_enabled?
  out = true if @_parcels_enabled
  out
end

#tags_changed!(tags) ⇒ Object



31
32
33
34
# File 'lib/parcels/fortitude/enabling.rb', line 31

def tags_changed!(tags)
  super
  _parcels_ensure_all_tag_methods_overridden! if parcels_enabled?
end