Sha256: c00c5518ef60431fbd4d8aaf9c684cfc8d58d8591393511983657c72a584bc58

Contents?: true

Size: 1.77 KB

Versions: 1

Compression:

Stored size: 1.77 KB

Contents

require 'sprockets/railtie'

module Packr
  module Rails
    class Railtie < ::Rails::Railtie

      # == References:
      #   - http://edgeguides.rubyonrails.org/asset_pipeline.html
      #   - https://github.com/rails/sass-rails/blob/3-1-stable/lib/sass/rails/railtie.rb

      DEFAULTS = {
        :template_extension => '.packr',      # File-extension for the template files that should be packed automatically.
        :packed_extension   => '.packed.js',  # File-extension for the packed javascript file.
        :pack_options => {
          :shrink_vars  => true,      # Compress local variable names.
          :private      => true,      # Obfuscate 'private' identifiers, i.e. names beginning with a single underscore.
          :base62       => false,     # Encode the program using base 62.
          :protect      => []         # Variable names to protect from compression. Example: ['_this', 'that']
        }
      }

      module PackrContext
        attr_accessor :packr_config
      end

      config.packr = ActiveSupport::OrderedOptions.new(DEFAULTS)
      config.packr.defaults = config.packr.dup

      config.before_initialize do
        require 'sprockets/engines'
        Sprockets::Engines # force autoloading
        Sprockets.register_engine config.packr.template_extension, Packr::Rails::Template
      end

      initializer :setup_packr do |app|
        app.assets.context_class.extend(PackrContext)
        app.assets.context_class.packr_config = app.config.packr
      end

      # == NOTE: Example of replacing default JS-compressor (optional):
      #
      #   initializer :setup_compression do |app|
      #     if app.config.assets.compress
      #       app.config.assets.js_compressor = Packr::Rails::Compressor.new
      #     end
      #   end
      #

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
packr-rails-0.0.1 lib/packr/rails/railtie.rb