Sha256: d67dfdb19955bac31a3ff6ef0f390e1c321d032179cd810838ad30d90539ab45

Contents?: true

Size: 1.19 KB

Versions: 30

Compression:

Stored size: 1.19 KB

Contents

module Nexmo
  module OAS
    module Renderer
      module Filters
        class Columns < Banzai::Filter
          def call(input)
            input.gsub!(%r{{column\:([1-4])\/([1-4])}\n(.+?){end}}m) do
              s = []
              s << row_start if $1 == '1'
              s << column_start($2)
              s << $3
              s << column_end
              s << row_end if $1 == $2
              s.join('')
            end

            input
          end

          private

          def row_start
            "FREEZESTART#{Base64.urlsafe_encode64('<div class="row">')}FREEZEEND\n"
          end

          def row_end
            close_tag
          end

          def close_tag
            "FREEZESTART#{Base64.urlsafe_encode64('</div>')}FREEZEEND"
          end

          def column_start(columns)
            html = "<div class='column small-12 medium-#{part_size(columns)}'>"
            "FREEZESTART#{Base64.urlsafe_encode64(html)}FREEZEEND\n"
          end

          def column_end
            "FREEZESTART#{Base64.urlsafe_encode64('</div>')}FREEZEEND\n"
          end

          def part_size(columns)
            12 / Integer(columns)
          end
        end
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

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