Class: Speedo::Generators::InstallGenerator

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

Instance Method Summary collapse

Instance Method Details

#alter_application_jsObject



74
75
76
77
78
79
80
81
82
# File 'lib/generators/speedo/install_generator.rb', line 74

def alter_application_js
  if_file 'app/assets/javascripts/application.js' do |path|
    unless File.read(path).match /require speedo/
      inject_into_file path, before: '//= require_tree .' do
        "//= require speedo\n"
      end
    end
  end
end

#bootstrap_formtasticObject



106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/generators/speedo/install_generator.rb', line 106

def bootstrap_formtastic
  if File.exist? 'config/initializers/formtastic.rb'
    unless File.read('config/initializers/formtastic.rb').match /FormtasticBootstrap/
      append_file 'config/initializers/formtastic.rb' do
        "\n# config/initializers/formtastic.rb"
        "\nFormtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder"
      end
    end
  else
    say "Make sure to add `Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder` to config/initializers/formtastic.rb."
  end
end

#copy_application_cssObject

app/assets/stylesheets/application.css.scss



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/generators/speedo/install_generator.rb', line 48

def copy_application_css
  if File.exist? 'app/assets/stylesheets/application.css.scss'
    if yes? 'application.css.scss already exists. Do you want to replace it? [yN]'
      copy_file 'app/assets/stylesheets/application.css.scss', 
                'app/assets/stylesheets/application.css.scss'
    else
      say 'Make sure to @import "speedo"; in your application.css.scss, and @import other files - do NOT use *=require.'
    end
  else
    copy_file 'app/assets/stylesheets/application.css.scss', 
              'app/assets/stylesheets/application.css.scss'
  end
  
  if File.exist? 'app/assets/stylesheets/application.css'
    if yes? 'Do you want to remove application.css (otherwise delete it manually)? [yN]'
      remove_file 'app/assets/stylesheets/application.css'
    end
  end
end

#copy_stylesheetsObject

app/assets/stylesheets/speedo.css.scss



38
39
40
41
42
43
44
# File 'lib/generators/speedo/install_generator.rb', line 38

def copy_stylesheets
  css = ['speedo','base','plugins','theme','helpers']
  css.each do |file|
    copy_file "app/assets/stylesheets/speedo/#{file}.css.scss", 
              "app/assets/stylesheets/speedo/#{file}.css.scss"
  end
end

#javascriptObject

app/assets/javascripts/swim.js.coffee



69
70
71
72
# File 'lib/generators/speedo/install_generator.rb', line 69

def javascript
  copy_file 'app/assets/javascripts/swim.js.coffee', 
            'app/assets/javascripts/swim.js.coffee'
end

#layoutObject

app/views/layouts/application.html.haml



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/generators/speedo/install_generator.rb', line 9

def layout
  if File.exist? 'app/views/layouts/application.html.haml'
    if yes? 'application.html.haml already exists. Do you want the template as speedo.html.haml (for manual integration)? [yN]'
      template 'app/views/layouts/speedo/application.html.haml', 
               'app/views/layouts/speedo.html.haml'
    end
  else
    template 'app/views/layouts/speedo/application.html.haml', 
             'app/views/layouts/application.html.haml'
  end
  
  if File.exist? 'app/views/layouts/application.html.erb'
    if yes? 'Do you want to remove the application.html.erb layout (otherwise delete it manually)? [yN]'
      remove_file 'app/views/layouts/application.html.erb'
    end
  end
end

#localesObject

config/locales/speedo.en.yml



85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/generators/speedo/install_generator.rb', line 85

def locales
  if File.exist? 'config/locales/en.yml'
    unless File.read('config/locales/en.yml').match /app_name/
      inject_into_file 'config/locales/en.yml', after: 'en:' do
        "\n  app_name: 'See config/locales to name this app'"
      end
    end
  else
    copy_file 'config/locales/speedo.en.yml', 
              'config/locales/speedo.en.yml'
  end
end


27
28
29
30
31
32
33
34
35
# File 'lib/generators/speedo/install_generator.rb', line 27

def navbar
  template 'app/views/layouts/speedo/_navbar.html.haml', 
           'app/views/layouts/_navbar.html.haml'
  if_file 'app/views/layouts/application.html.haml' do |path|
    if File.read(path).match /render 'layouts\/speedo\/navbar'/
      gsub_file path, /render 'layouts\/speedo\/navbar'/, "render 'layouts/navbar'"
    end
  end
end

#routesObject



98
99
100
# File 'lib/generators/speedo/install_generator.rb', line 98

def routes
  route 'mount Speedo::Engine => "/speedo"'
end

#run_formtastic_generatorObject



102
103
104
# File 'lib/generators/speedo/install_generator.rb', line 102

def run_formtastic_generator
  generate "formtastic:install"
end