Class: Panda::Editor::FootnoteRegistry
- Inherits:
-
Object
- Object
- Panda::Editor::FootnoteRegistry
- Defined in:
- lib/panda/editor/footnote_registry.rb
Instance Attribute Summary collapse
-
#footnotes ⇒ Object
readonly
Returns the value of attribute footnotes.
Instance Method Summary collapse
- #add(id:, content:) ⇒ Object
- #any? ⇒ Boolean
-
#initialize(autolink_urls: false, markdown: false) ⇒ FootnoteRegistry
constructor
A new instance of FootnoteRegistry.
- #render_sources_section ⇒ Object
Constructor Details
#initialize(autolink_urls: false, markdown: false) ⇒ FootnoteRegistry
Returns a new instance of FootnoteRegistry.
10 11 12 13 14 15 |
# File 'lib/panda/editor/footnote_registry.rb', line 10 def initialize(autolink_urls: false, markdown: false) @footnotes = [] @footnote_ids = {} @autolink_urls = autolink_urls @markdown = markdown end |
Instance Attribute Details
#footnotes ⇒ Object (readonly)
Returns the value of attribute footnotes.
8 9 10 |
# File 'lib/panda/editor/footnote_registry.rb', line 8 def footnotes @footnotes end |
Instance Method Details
#add(id:, content:) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/panda/editor/footnote_registry.rb', line 17 def add(id:, content:) # Return existing number if this ID was already registered return @footnote_ids[id] if @footnote_ids[id] # Add new footnote @footnotes << { id: id, content: content } number = @footnotes.length # Cache the number for this ID @footnote_ids[id] = number number end |
#any? ⇒ Boolean
66 67 68 |
# File 'lib/panda/editor/footnote_registry.rb', line 66 def any? @footnotes.any? end |
#render_sources_section ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/panda/editor/footnote_registry.rb', line 31 def render_sources_section return '' if @footnotes.empty? footnote_items = @footnotes.map.with_index do |footnote, index| number = index + 1 content = process_content(footnote[:content]) <<~HTML.strip <li id="fn:#{number}"> <p> #{content} <a href="#fnref:#{number}" class="footnote-backref">↩</a> </p> </li> HTML end.join("\n") <<~HTML <div class="mx-6 lg:mx-8 mt-4 mb-8"> <div class="footnotes-section bg-gray-50 rounded-lg overflow-hidden"> <button class="footnotes-header w-full px-4 py-3 flex items-center justify-between cursor-pointer hover:bg-gray-100 transition-colors" data-footnotes-target="toggle" data-action="click->footnotes#toggle"> <h3 class="text-sm font-unbounded font-medium text-gray-900 m-0">Sources/References</h3> <svg class="footnotes-chevron w-5 h-5 text-gray-600" data-footnotes-target="chevron" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"></path> </svg> </button> <div class="footnotes-content" data-footnotes-target="content"> <ol class="footnotes text-sm text-gray-700 space-y-2 px-4 pb-3"> #{footnote_items} </ol> </div> </div> </div> HTML end |