Class: Decidim::DecidimAwesome::ParseContentBlock

Inherits:
Object
  • Object
show all
Defined in:
lib/decidim/decidim_awesome/parse_content_block.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cell) ⇒ ParseContentBlock

Returns a new instance of ParseContentBlock.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/decidim/decidim_awesome/parse_content_block.rb', line 6

def initialize(cell)
  @cell = cell
  # Force the cell to render any missing method to empty content
  def cell.method_missing(name, *, &)
    "{missing method #{name}}"
  end

  def cell.respond_to_missing?(_name, *)
    true
  end
end

Instance Attribute Details

#cellObject (readonly)

Returns the value of attribute cell.



18
19
20
# File 'lib/decidim/decidim_awesome/parse_content_block.rb', line 18

def cell
  @cell
end

Instance Method Details

#idObject



20
21
22
23
24
25
26
# File 'lib/decidim/decidim_awesome/parse_content_block.rb', line 20

def id
  @id ||= begin
    Nokogiri::HTML::DocumentFragment.parse(cell.call).css("[id]").first&.attribute("id")&.value
  rescue StandardError
    nil
  end
end