Sha256: 4781bddb92a9789b9f81addc55b99b80f93fd948c7eef7541bece159c1508a3d

Contents?: true

Size: 1.15 KB

Versions: 3

Compression:

Stored size: 1.15 KB

Contents

require 'rails'
require 'shellwords'

module Haml
  module Generators
    class ApplicationLayoutGenerator < ::Rails::Generators::Base
      HTML_LAYOUT_PATH = 'app/views/layouts/application.html.erb'
      HAML_LAYOUT_PATH = 'app/views/layouts/application.html.haml'

      # Converts existing application.html.erb to haml format,
      # and creates app/views/layouts/application.html.haml
      # with some error checking.
      def convert
        app_layout_from = ::Rails.root.join(HTML_LAYOUT_PATH).to_s
        app_layout_to   = ::Rails.root.join(HAML_LAYOUT_PATH).to_s

        if File.exist?(app_layout_from)

          if !File.exist?(app_layout_to)
            `html2haml #{app_layout_from.shellescape} #{app_layout_to.shellescape}`
            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
    end
  end
end

Version data entries

3 entries across 2 versions & 2 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.1.0/gems/haml-rails-2.1.0/lib/rails/generators/haml/application_layout/application_layout_generator.rb
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/haml-rails-2.1.0/lib/rails/generators/haml/application_layout/application_layout_generator.rb
haml-rails-2.1.0 lib/rails/generators/haml/application_layout/application_layout_generator.rb