Module: Sinatra::Footnotes::Helpers

Defined in:
lib/sinatra-footnotes.rb

Instance Method Summary collapse

Instance Method Details

#close_helper(note) ⇒ Object

Process notes to get javascript code to close them.



15
16
17
# File 'lib/sinatra-footnotes.rb', line 15

def close_helper(note)
  "Footnotes.hide(document.getElementById('#{note.to_sym}_debug_info'));\n"
end

#each_with_rescue(notes) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/sinatra-footnotes.rb', line 31

def each_with_rescue(notes)
  notes.each do |note|
    begin
      yield note
    rescue Exception => e
      STDERR.puts "FootNotes #{note.to_s.camelize}NoteException"
      STDERR.puts e
    end
  end
end

#fieldsets(notes) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/sinatra-footnotes.rb', line 42

def fieldsets(notes)
  content = ''
  each_with_rescue(notes) do |note|
    next unless note.has_fieldset?
    content << <<-HTML
      <fieldset id="#{note.to_sym}_debug_info" style="display: none">
        <legend>#{note.legend}</legend>
        <div>#{note.content}</div>
      </fieldset>
    HTML
  end
  content
end

Helper that creates the link and javascript code when note is clicked



21
22
23
24
25
26
27
28
29
# File 'lib/sinatra-footnotes.rb', line 21

def link_helper(note)
  onclick = note.onclick
  unless href = note.link
    href = '#'
    onclick ||= "Footnotes.hideAllAndToggle('#{note.to_sym}_debug_info');return false;" if note.has_fieldset?
  end

  "<a href=\"#{href}\" onclick=\"#{onclick}\">#{note.title}</a>"
end