Sha256: 446002641ecc1dcd1f66879a95c25414b438a2c7b2cf847d3e356799e052011a

Contents?: true

Size: 1.14 KB

Versions: 9

Compression:

Stored size: 1.14 KB

Contents

module Nexmo
  module OAS
    module Renderer
      module Filters
        class Modal < Banzai::Filter
          def call(input)
            modals = []

            input.gsub!(/@\[(.+?)\]\((.+?)\)/) do |_s|
              id = 'M' + SecureRandom.hex(12)
              modals << { document: $2, id: id }
              "<a data-modal='#{id}' class='Vlt-modal-trigger'>#{$1}</a>"
            end

            modals = modals.map do |modal|
              filename = modal[:document]
              raise "Could not find modal #{filename}" unless File.exist? filename

              document = File.read(filename)
              output = MarkdownPipeline.new.call(document)

              modal = <<~HEREDOC
                <div class="Vlt-modal" id="#{modal[:id]}">
                  <div class="Vlt-modal__panel">
                    <div class="Vlt-modal__content">
                  #{output}
                    </div>
                  </div>
                </div>
              HEREDOC

              "FREEZESTART#{Base64.urlsafe_encode64(modal)}FREEZEEND"
            end

            input + modals.join("\n")
          end
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
nexmo-oas-renderer-0.3.2 lib/nexmo/oas/renderer/filters/modal.rb
nexmo-oas-renderer-0.3.1 lib/nexmo/oas/renderer/filters/modal.rb
nexmo-oas-renderer-0.3.0 lib/nexmo/oas/renderer/filters/modal.rb
nexmo-oas-renderer-0.2.2 lib/nexmo/oas/renderer/filters/modal.rb
nexmo-oas-renderer-0.2.1 lib/nexmo/oas/renderer/filters/modal.rb
nexmo-oas-renderer-0.2.0 lib/nexmo/oas/renderer/filters/modal.rb
nexmo-oas-renderer-0.1.2 lib/nexmo/oas/renderer/filters/modal.rb
nexmo-oas-renderer-0.1.1 lib/nexmo/oas/renderer/filters/modal.rb
nexmo-oas-renderer-0.1.0 lib/nexmo/oas/renderer/filters/modal.rb