Sha256: 6e666d51c15984dc82be6bd540299c4b1df0ccca2d83f238c39f042c87cb37bf

Contents?: true

Size: 1.96 KB

Versions: 3

Compression:

Stored size: 1.96 KB

Contents

module BootstrapIt
  #
  module Assets
    #
    class JSDirectiveProcessor < Sprockets::DirectiveProcessor
      def process_require_directive file
        if file == 'bootstrap_it'
          super 'bootstrap'
        else
          super
        end
      end
    end

    #
    class CSSDirectiveProcessor < Sprockets::DirectiveProcessor
      def process_require_directive(file)
        if file == 'bootstrap_it'
          super 'bootstrap'
          super 'font-awesome' if BootstrapIt.config.font_awesome
        else
          super
        end
      end
    end

    def self.register(assets)
      assets.unregister_preprocessor(
        'application/javascript',
        Sprockets::DirectiveProcessor
      )
      assets.register_preprocessor(
        'application/javascript',
        JSDirectiveProcessor
      )
      assets.unregister_preprocessor('text/css', Sprockets::DirectiveProcessor)
      assets.register_preprocessor('text/css', CSSDirectiveProcessor)
      config = BootstrapIt.config
      Rails.application.config.assets.paths << Engine.root.join(
        'upstream', 'bootstrap', config.bootstrap_version, 'javascript'
      )
      Rails.application.config.assets.paths << Engine.root.join(
        'upstream', 'bootstrap', config.bootstrap_version, 'stylesheets'
      )
      if config.font_awesome
        Rails.application.config.assets.paths << Engine.root.join(
          'upstream', 'font-awesome',
          config.font_awesome_version, 'stylesheets'
        )
      end
      Rails.application.config.assets.precompile << proc do |file, path|
        path == Engine.root.join(
          'upstream', 'bootstrap',
          config.bootstrap_version,
          'fonts'
        ) &&
          file =~ /\.(otf|eot|svg|ttf|woff)/ ||
            path == Engine.root.join(
              'upstream', 'font-awesome',
              config.font_awesome_version,
              'fonts'
            ) &&
            file =~ /\.(otf|eot|svg|ttf|woff)/
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bootstrap_it-0.1.2 lib/bootstrap_it/assets.rb
bootstrap_it-0.1.1 lib/bootstrap_it/assets.rb
bootstrap_it-0.1.0 lib/bootstrap_it/assets.rb