Sha256: 78c55cacbd5a9016340883eb04c554ae3da703e124989485f07d21d15e58db81

Contents?: true

Size: 1.49 KB

Versions: 6

Compression:

Stored size: 1.49 KB

Contents

require "sprockets"
  
module Middleman::CoreExtensions::Sprockets
  class << self
    def registered(app)      
      app.set :js_compressor, false
      
      app.map "/#{app.js_dir}" do
        run JavascriptEnvironment.new(app)
      end
      # app.map "/#{app.css_dir}" do
      #   run StylesheetEnvironment.new(app)
      # end
    end
    alias :included :registered
  end

  class MiddlemanEnvironment < ::Sprockets::Environment
    def initialize(app)
      full_path = app.views
      full_path = File.join(app.root, app.views) unless app.views.include?(app.root)
      
      super File.expand_path(full_path)
    end
  end
    
  class JavascriptEnvironment < MiddlemanEnvironment
    def initialize(app)
      super

      # Disable css
      unregister_processor "text/css", ::Sprockets::DirectiveProcessor
      
      self.js_compressor = app.settings.js_compressor

      # configure search paths
      append_path app.js_dir
      
      # jQuery for Sprockets
      # begin
      #   require "jquery-rails"
      #   jquery-rails / vendor / assets / javascripts
      # rescue LoadError
      # end
    end
  end
  
  # class StylesheetEnvironment < MiddlemanEnvironment
  #   def initialize(app)
  #     super
  # 
  #     # Disable js
  #     unregister_processor "application/javascript", ::Sprockets::DirectiveProcessor
  # 
  #     # configure search paths
  #     stylesheets_path = File.join(File.expand_path(app.views), app.css_dir)
  #     append_path stylesheets_path
  #   end
  # end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
middleman-2.0.0 lib/middleman/core_extensions/sprockets.rb
middleman-2.0.0.rc99 lib/middleman/core_extensions/sprockets.rb
middleman-2.0.0.rc98 lib/middleman/core_extensions/sprockets.rb
middleman-2.0.0.rc97 lib/middleman/core_extensions/sprockets.rb
middleman-2.0.0.rc96 lib/middleman/core_extensions/sprockets.rb
middleman-2.0.0.rc95 lib/middleman/core_extensions/sprockets.rb