Sha256: d33c1d9ab9565c937f59a7f4f43371cf28340b4e7e5c22a5aaa8d10bd4bb1381

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

module Unpoly
  module Rails
    class Engine < ::Rails::Engine
      initializer 'unpoly-rails.assets' do |app|
        # The gem package has a dist folder with the pre-built unpoly.js/.css.
        # The folder may be empty in the local repository, or contain a stale build.
        dist_folder = root.join('dist')

        # The local repository has a lib/assets folder, but the gem package does not.
        # The Rails asset pipeline can require unpoly.js/.css from there and compile
        # it within the Rails process.
        source_folder = root.join('lib', 'assets')

        is_local_gem = source_folder.directory?

        # If someone has required the local gem (e.g. `gem 'unpoly', path: '../unpoly'`)
        # we use the local path. This way changes in the source are immediately picked
        # up by the application.
        if is_local_gem
          app.config.assets.paths << source_folder.join('javascripts').to_s
          app.config.assets.paths << source_folder.join('stylesheets').to_s
        else
          app.config.assets.paths << dist_folder.to_s
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
unpoly-rails-2.0.0.pre.rc10 lib/unpoly/rails/engine.rb