Sha256: bdf555ceb08ccdc69062bc739c2ea7fef6a4a664c2bbb4db6bcde24acda5a386

Contents?: true

Size: 1.12 KB

Versions: 7

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

require 'action_view'
require 'stringio'

module ActionView
  module Template::Handlers
    class AxlsxBuilder

      def default_format
        case
        when Rails.version.to_f >= 6
          Mime[:xlsx].symbol
        when Rails.version.to_f >= 5
          Mime[:xlsx]
        else
          Mime::XLSX
        end
      end

      def call(template, source = nil)
        builder = StringIO.new
        builder << "require 'axlsx';"
        builder << "xlsx_author = defined?(xlsx_author).nil? ? nil : xlsx_author;"
        builder << "xlsx_created_at = defined?(xlsx_created_at).nil? ? nil : xlsx_created_at;"
        builder << "xlsx_use_shared_strings = defined?(xlsx_use_shared_strings).nil? ? nil : xlsx_use_shared_strings;"
        builder << "xlsx_package = Axlsx::Package.new("
        builder << ":author => xlsx_author,"
        builder << ":created_at => xlsx_created_at,"
        builder << ":use_shared_strings => xlsx_use_shared_strings);"
        builder << (source || template.source)
        builder << ";xlsx_package.to_stream.string;"
        builder.string
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 3 rubygems

Version Path
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/caxlsx_rails-0.6.3/lib/axlsx_rails/template_handler.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/caxlsx_rails-0.6.3/lib/axlsx_rails/template_handler.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/caxlsx_rails-0.6.3/lib/axlsx_rails/template_handler.rb
caxlsx_rails-0.6.3 lib/axlsx_rails/template_handler.rb
caxlsx_rails-0.6.2 lib/axlsx_rails/template_handler.rb
axlsx_rails-0.6.1 lib/axlsx_rails/template_handler.rb
axlsx_rails-0.6.0 lib/axlsx_rails/template_handler.rb