Class: ExtForm::Generators::InstallGenerator

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

Instance Method Summary collapse

Instance Method Details

#copy_assetsObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/generators/ext_form/install_generator.rb', line 33

def copy_assets

  #bootstrap install
  if options[:bootstrap]

    # I prefer if (file = 'app/assets/stylesheets/application.css') && File.exists?(file)
    # but it outputs a warning....
    file = 'app/assets/stylesheets/application.css'
    if File.exists?(file)
      inject_into_file file, before: " *= require_tree .\n" do
        " *= require ext_form/application_bootstrap\n"
      end
    end

    file = 'app/assets/stylesheets/application.css.scss'
    if File.exists?(file)
      inject_into_file file, before: " *= require_tree .\n" do
        " *= require ext_form/application_bootstrap\n"
      end
    end

    file = 'app/assets/javascripts/application.js'
    if File.exists?(file)
      locale = options[:locale]

      inject_into_file file, before: "//= require_tree .\n" do
        <<JS
//= require jquery_nested_form
//= require bootstrap-datetimepicker
//= require typeahead
//= require select2
//= require ext_form/application
JS
      end

      inject_into_file file, after: "//= require select2\n" do
        <<JS
//= require locales/bootstrap-datetimepicker.#{locale}
//= require select2_locale_#{locale}
JS
      end if locale
    end
  # non bootstrap install, no more css and js.
  else
    file = 'app/assets/stylesheets/application.css'
    if File.exists?(file)
      inject_into_file file, before: " *= require_tree .\n" do
        " *= require ext_form/application\n"
      end

    end

    file = 'app/assets/stylesheets/application.css.scss'
    if File.exists?(file)
      inject_into_file file, before: " *= require_tree .\n" do
        " *= require ext_form/application\n"
      end
    end

    file = 'app/assets/javascripts/application.js'
    if File.exists?(file)
      inject_into_file file, before: "//= require_tree .\n" do
        <<JS
//= require jquery_nested_form
//= require ext_form/application
JS
      end
    end
  end


end

#copy_configObject



18
19
20
21
22
23
24
25
26
# File 'lib/generators/ext_form/install_generator.rb', line 18

def copy_config
  template 'config/initializers/z_ext_form.rb'

  if options[:bootstrap]
    template 'config/initializers/z_ext_form_bootstrap.rb'
  end

  directory 'config/locales'
end

#copy_scaffold_templateObject



28
29
30
31
# File 'lib/generators/ext_form/install_generator.rb', line 28

def copy_scaffold_template
  engine = options[:template_engine]
  copy_file "_form.html.#{engine}", "lib/templates/#{engine}/scaffold/_form.html.#{engine}"
end

#info_bootstrapObject



11
12
13
14
15
16
# File 'lib/generators/ext_form/install_generator.rb', line 11

def info_bootstrap
  return if options.bootstrap?
  puts %q(ExtForm supports Twitter Bootstrap.
If you want a configuration that is compatible it,
then please re-run this generator with --bootstrap as an option.)
end

#show_readmeObject



106
107
108
109
110
# File 'lib/generators/ext_form/install_generator.rb', line 106

def show_readme
  if behavior == :invoke && options.bootstrap?
    readme 'README'
  end
end