Class: Haml::Generators::ApplicationLayoutGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/rails/generators/haml/application_layout/application_layout_generator.rb

Instance Method Summary collapse

Instance Method Details

#convertObject

Converts existing application.html.erb to haml format, and creates app/views/layouts/application.html.haml with some error checking.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rails/generators/haml/application_layout/application_layout_generator.rb', line 10

def convert
  app_layout_from = ::Rails.root.join('app/views/layouts/application.html.erb')
  app_layout_to   = ::Rails.root.join('app/views/layouts/application.html.haml')

  if File.exist?(app_layout_from)

    if !File.exist?(app_layout_to)
      `html2haml #{app_layout_from} #{app_layout_to}`
      puts "Success! app/views/layouts/application.html.haml is created.\n" \
           "Please remove the erb file: app/views/layouts/application.html.erb"
    else
      puts "Error! There is a file named app/views/layouts/application.html.haml already."
    end
  else
    puts "Error! There is no file named app/views/layouts/application.html.erb."
  end

end