Module: Bridgetown::ViewComponentARCHIVED

Defined in:
lib/bridgetown-view-component/bridgetown/view_component.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



23
24
25
# File 'lib/bridgetown-view-component/bridgetown/view_component.rb', line 23

def self.included(klass)
  klass.extend ClassMethods
end

.setup_hooksObject

NOTE: Currently not in use…might need to revisit when dual Rails/Bridgetown installs are present



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/bridgetown-view-component/bridgetown/view_component.rb', line 7

def self.setup_hooks
  Bridgetown::Hooks.register :site, :pre_render, reloadable: false do
    ::ViewComponent::CompileCache.cache.each do |component_class|
      component_class.undef_method(:call)
    end
    ::ViewComponent::CompileCache.cache.clear
  end

  Bridgetown::Hooks.register :site, :post_render, reloadable: false do |_post|
    ::ViewComponent::CompileCache.cache.each do |component_class|
      component_class.undef_method(:call)
    end
    ::ViewComponent::CompileCache.cache.clear
  end
end

Instance Method Details

#contentObject



37
38
39
40
41
42
43
# File 'lib/bridgetown-view-component/bridgetown/view_component.rb', line 37

def content
  if self.class.format_for_content == :markdown && view_context.respond_to?(:markdownify)
    view_context.markdownify(@content).html_safe
  else
    super
  end
end

#render_in(view_context, &block) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/bridgetown-view-component/bridgetown/view_component.rb', line 45

def render_in(view_context, &block)
  if view_context.class.name&.start_with? "Bridgetown"
    singleton_class.include ViewComponentHelpers
  end

  super
end