Skip to content

Commit 7a04a1b

Browse files
committed
Merge pull request #73 from serv/master
Added Rails generator command: rails g haml:application_layout convert
2 parents 4860cab + 6bfa796 commit 7a04a1b

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ gemspec
55

66
gem 'rubysl', '~> 2.0', platforms: :rbx
77
gem 'minitest', platforms: :rbx
8+
gem 'html2haml'

haml-rails.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
1919
s.add_dependency "activesupport", [">= 4.0.1"]
2020
s.add_dependency "actionpack", [">= 4.0.1"]
2121
s.add_dependency "railties", [">= 4.0.1"]
22+
s.add_dependency "html2haml", [">= 1.0.1"]
2223

2324
s.add_development_dependency "rails", [">= 4.0.1"]
2425
s.add_development_dependency "bundler", "~> 1.2"
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
require 'rails'
2+
3+
module Haml
4+
module Generators
5+
class ApplicationLayoutGenerator < ::Rails::Generators::Base
6+
7+
# Converts existing application.html.erb to haml format,
8+
# and creates app/views/layouts/application.html.haml
9+
# with some error checking.
10+
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')
13+
14+
if File.exist?(app_layout_from)
15+
16+
if !File.exist?(app_layout_to)
17+
`html2haml #{app_layout_from} #{app_layout_to}`
18+
puts "Success! app/views/layouts/application.html.haml is created.\n" \
19+
"Please remove the erb file: app/views/layouts/application.html.erb"
20+
else
21+
puts "Error! There is a file named app/views/layouts/application.html.haml already."
22+
end
23+
else
24+
puts "Error! There is no file named app/views/layouts/application.html.erb."
25+
end
26+
27+
end
28+
29+
end
30+
end
31+
end

0 commit comments

Comments
 (0)