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.7.1 lib/nexmo/oas/renderer/filters/columns.rb
nexmo-oas-renderer-0.7.0 lib/nexmo/oas/renderer/filters/columns.rb
nexmo-oas-renderer-0.6.6 lib/nexmo/oas/renderer/filters/columns.rb
nexmo-oas-renderer-0.6.5 lib/nexmo/oas/renderer/filters/columns.rb
nexmo-oas-renderer-0.6.4 lib/nexmo/oas/renderer/filters/columns.rb
nexmo-oas-renderer-0.6.3 lib/nexmo/oas/renderer/filters/columns.rb
nexmo-oas-renderer-0.6.2 lib/nexmo/oas/renderer/filters/columns.rb
nexmo-oas-renderer-0.6.1 lib/nexmo/oas/renderer/filters/columns.rb
nexmo-oas-renderer-0.5.6 lib/nexmo/oas/renderer/filters/columns.rb
nexmo-oas-renderer-0.5.5 lib/nexmo/oas/renderer/filters/columns.rb
nexmo-oas-renderer-0.5.4 lib/nexmo/oas/renderer/filters/columns.rb
nexmo-oas-renderer-0.5.2 lib/nexmo/oas/renderer/filters/columns.rb
nexmo-oas-renderer-0.5.1 lib/nexmo/oas/renderer/filters/columns.rb
nexmo-oas-renderer-0.5.0 lib/nexmo/oas/renderer/filters/columns.rb
nexmo-oas-renderer-0.4.1 lib/nexmo/oas/renderer/filters/columns.rb
nexmo-oas-renderer-0.4.0 lib/nexmo/oas/renderer/filters/columns.rb
nexmo-oas-renderer-0.3.7 lib/nexmo/oas/renderer/filters/columns.rb
nexmo-oas-renderer-0.3.6 lib/nexmo/oas/renderer/filters/columns.rb
nexmo-oas-renderer-0.3.5 lib/nexmo/oas/renderer/filters/columns.rb
nexmo-oas-renderer-0.3.4 lib/nexmo/oas/renderer/filters/columns.rb