Class: AttributesFor::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/attributes_for/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#copy_translationsObject



7
8
9
# File 'lib/generators/attributes_for/install_generator.rb', line 7

def copy_translations
  copy_file 'attributes_for.en.yml', 'config/locales/attributes_for.en.yml'
end

#inject_stylesheetsObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/generators/attributes_for/install_generator.rb', line 11

def inject_stylesheets
  in_root do
    {
      "css" => {
        require_string: " *= require font-awesome",
        where: {before: %r{.*require_self}},
      },
      "css.scss" => {
        require_string: "@import \"font-awesome\";",
        where: {after: %r{\A}},
      },
    }.each do |extension, strategy|
      file = "app/assets/stylesheets/application.#{extension}"

      if File.exists?(Rails.root.join(file))
        unless File.foreach(file).grep(/#{strategy[:require_string]}/).any?
          inject_into_file file, strategy[:require_string] + "\n", strategy[:where]
        end
      end
    end
  end
end