Sha256: fecc20b0e612572b130df4e68306ddc593baf21bdc965d3537b0656682f6936e

Contents?: true

Size: 984 Bytes

Versions: 8

Compression:

Stored size: 984 Bytes

Contents

module JqueryCdn
  # Tell Ruby on Rails to add vendor/assets to Assets Pipeline
  class Engine < ::Rails::Engine
  end

  module RailsHelpers
    # Return <script> tags to add jQuery in Rails
    def include_jquery(options = { })
      options = { env: Rails.env.to_sym }.merge(options)
      JqueryCdn.local_url = proc { javascript_path("jquery.js") }
      JqueryCdn.include_jquery(options).html_safe
    end
  end

  class Railtie < Rails::Railtie
    initializer 'jquery-cdn' do |app|
      # Ensure that we before jquery-rails to fix name conflict
      root   = Pathname(__FILE__).dirname.join('../..').expand_path
      vendor = root.join('vendor/assets/javascripts')
      Rails.application.assets.prepend_path(vendor)

      # Add include_jquery helper
      ActiveSupport.on_load(:action_view) do
        include JqueryCdn::RailsHelpers
      end

      # Precompile all JS/CSS in root of app assets dirs.
      app.config.assets.precompile << 'jquery.js'
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
jquery-cdn-2.1.4 lib/jquery-cdn/railties.rb
jquery-cdn-1.11.3 lib/jquery-cdn/railties.rb
jquery-cdn-1.11.2 lib/jquery-cdn/railties.rb
jquery-cdn-2.1.3 lib/jquery-cdn/railties.rb
jquery-cdn-2.1.1 lib/jquery-cdn/railties.rb
jquery-cdn-1.11.1 lib/jquery-cdn/railties.rb
jquery-cdn-2.1.0 lib/jquery-cdn/railties.rb
jquery-cdn-1.11.0 lib/jquery-cdn/railties.rb