Sha256: b38fb50a1caf79c39986bcf50e77785f3f75f0c4b94570c9c4a48abe6add8f11

Contents?: true

Size: 1.78 KB

Versions: 5

Compression:

Stored size: 1.78 KB

Contents

module Voltron
  module Upload
    module Generators
      class InstallGenerator < Rails::Generators::Base

        source_root File.expand_path("../../../templates", __FILE__)

        desc "Add Voltron Upload initializer"

        def inject_initializer

          voltron_initialzer_path = Rails.root.join("config", "initializers", "voltron.rb")

          unless File.exist? voltron_initialzer_path
            unless system("cd #{Rails.root.to_s} && rails generate voltron:install")
              puts "Voltron initializer does not exist. Please ensure you have the 'voltron' gem installed and run `rails g voltron:install` to create it"
              return false
            end
          end

          current_initiailzer = File.read voltron_initialzer_path

          unless current_initiailzer.match(Regexp.new(/# === Voltron Upload Configuration ===/))
            inject_into_file(voltron_initialzer_path, after: "Voltron.setup do |config|\n") do
<<-CONTENT

  # === Voltron Upload Configuration ===

  # Whether or not calls to file_field should generate markup for dropzone uploads
  # If false, simply returns what file_field would return normally
  # config.upload.enabled = true

  # Global defaults for Dropzone's with a defined preview template
  # Should be a hash of keys matching a preview partial name,
  # with a value hash containing any of the Dropzone configuration options
  # found at http://www.dropzonejs.com/#configuration-options
  config.upload.previews = {
    vertical_tile: {
      thumbnailWidth: 200,
      thumbnailHeight: 175,
      dictRemoveFile: 'Remove',
      dictCancelUpload: 'Cancel'
    },
  
    horizontal_tile: {
      dictRemoveFile: 'Remove',
      dictCancelUpload: 'Cancel'
    }
  }
CONTENT
            end
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
voltron-upload-0.2.5 lib/generators/voltron/upload/install_generator.rb
voltron-upload-0.2.2 lib/generators/voltron/upload/install_generator.rb
voltron-upload-0.2.3 lib/generators/voltron/upload/install_generator.rb
voltron-upload-0.2.1 lib/generators/voltron/upload/install_generator.rb
voltron-upload-0.2.4 lib/generators/voltron/upload/install_generator.rb