File: install_generator.rb

package info (click to toggle)
ruby-jquery-atwho-rails 1.5.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 160 kB
  • sloc: ruby: 84; sh: 12; makefile: 5
file content (45 lines) | stat: -rw-r--r-- 2,169 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
require 'rails'
require 'jquery-atwho-rails/version'

# Supply generator for Rails 3.0.x or if asset pipeline is not enabled
if ::Rails.version < "3.1" || !::Rails.application.config.assets.enabled
  module Atwho
    module Generators
      class InstallGenerator < ::Rails::Generators::Base

        desc "This generator installs jquery.atwho.js #{Jquery::Atwho::Rails::VERSION}"
        source_root File.expand_path('../../../assets', __FILE__)

        def copy_js
          say_status("copying js", " jquery.atwho.js (#{Jquery::Atwho::Rails::VERSION})", :green)
          copy_file "javascripts/jquery.atwho/jquery.caret.js", "public/javascripts/jquery.atwho/jquery.caret.js"
          copy_file "javascripts/jquery.atwho/jquery.atwho.js", "public/javascripts/jquery.atwho/jquery.atwho.js"
          #copy_file "javascripts/jquery.atwho.min.js", "public/javascripts/jquery.atwho.min.js"
        end

        def copy_css
          say_status("copying css"," jquery.atwho.css",:green)
          copy_file "stylesheets/jquery.atwho.css", "public/stylesheets/jquery.atwho.css"
          #copy_file "stylesheets/jquery.atwho.min.css", "public/stylesheets/jquery.atwho.min.css"
        end
      end
    end
  end
else
  module Atwho
    module Generators
      class InstallGenerator < ::Rails::Generators::Base
        desc "Just show instructions so people will know what to do when mistakenly using generator for Rails 3.1 apps"

        def do_nothing
          say_status("deprecated", "You are using Rails 3.1 with the asset pipeline enabled, so this generator is not needed.")
          say_status("", "The necessary files are already in your asset pipeline.")
          say_status("", "Just add `//= require jquery.atwho` to your app/assets/javascripts/application.js and app/assets/stylesheets/application.css")
          say_status("", "If you upgraded your app from Rails 3.0 and still have jquery.atwho.js in your javascripts, be sure to remove them.")
          say_status("", "If you do not want the asset pipeline enabled, you may turn it off in application.rb and re-run this generator.")
          # ok, nothing
        end
      end
    end
  end
end