Skip to content

Commit 7b08c63

Browse files
author
Jason Kim
committed
[bug #102] fix erb to haml conversion fails with spaces in the path
#102 Now rails generate haml:application_layout convert doesn't fail even if the file path has spaces.
1 parent cc363b2 commit 7b08c63

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lib/rails/generators/haml/application_layout/application_layout_generator.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
require 'rails'
2+
require 'shellwords'
23

34
module Haml
45
module Generators
56
class ApplicationLayoutGenerator < ::Rails::Generators::Base
67

8+
HTML_LAYOUT_PATH = 'app/views/layouts/application.html.erb'
9+
HAML_LAYOUT_PATH = 'app/views/layouts/application.html.haml'
10+
711
# Converts existing application.html.erb to haml format,
812
# and creates app/views/layouts/application.html.haml
913
# with some error checking.
1014
def convert
11-
app_layout_from = ::Rails.root.join('app/views/layouts/application.html.erb')
12-
app_layout_to = ::Rails.root.join('app/views/layouts/application.html.haml')
15+
app_layout_from = ::Rails.root.join(HTML_LAYOUT_PATH).to_s
16+
app_layout_to = ::Rails.root.join(HAML_LAYOUT_PATH).to_s
1317

1418
if File.exist?(app_layout_from)
1519

1620
if !File.exist?(app_layout_to)
17-
`html2haml #{app_layout_from} #{app_layout_to}`
21+
`html2haml #{app_layout_from.shellescape} #{app_layout_to.shellescape}`
1822
puts "Success! app/views/layouts/application.html.haml is created.\n" \
1923
"Please remove the erb file: app/views/layouts/application.html.erb"
2024
else

0 commit comments

Comments
 (0)