Skip to content

Commit

Permalink
Merge pull request #20 from dimko/patch-1
Browse files Browse the repository at this point in the history
Fix Rails integration
  • Loading branch information
ai committed Mar 4, 2016
2 parents 4af6a65 + 055a480 commit 77956f6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
19 changes: 11 additions & 8 deletions lib/visibilityjs.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
# Used only for Ruby on Rails gem to tell, that gem contain `lib/assets` with
# visibility.js file.

module VisibilityJs

def self.install(sprockets)
sprockets.append_path(Pathname(__FILE__).dirname)
# Path where is the visibility.js located.
def self.assets_path
Pathname(__FILE__).dirname
end

module Rails
class Engine < ::Rails::Engine
initializer 'visibilityjs' do |app|
VisibilityJs.install(app.config.assets)
end
end
# Add assets path to standalone Sprockets environment.
def self.install(sprockets)
sprockets.append_path(assets_path)
end
end

if defined?(Rails)
require 'visibilityjs/railtie'
end
7 changes: 7 additions & 0 deletions lib/visibilityjs/railtie.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Add visibility.js path to the Rails assets paths.

module VisibilityJs
class Railtie < Rails::Railtie
config.assets.configure { |env| VisibilityJs.install(env) }
end
end
1 change: 1 addition & 0 deletions visibilityjs.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Gem::Specification.new do |s|
'lib/visibility.timers.js',
'lib/visibility.fallback.js',
'lib/visibilityjs.rb',
'lib/visibilityjs/railtie.rb',
'LICENSE', 'README.md', 'ChangeLog.md']
s.extra_rdoc_files = ['LICENSE', 'README.md', 'ChangeLog.md']
s.require_path = 'lib'
Expand Down

0 comments on commit 77956f6

Please sign in to comment.