haml-rails 0.1 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/ruby.yml +64 -0
  3. data/.gitignore +7 -0
  4. data/Appraisals +19 -0
  5. data/Gemfile +6 -0
  6. data/LICENSE +21 -0
  7. data/README.md +64 -1
  8. data/Rakefile +12 -0
  9. data/gemfiles/rails_5_1.gemfile +8 -0
  10. data/gemfiles/rails_5_2.gemfile +8 -0
  11. data/gemfiles/rails_6_0.gemfile +8 -0
  12. data/gemfiles/rails_6_1.gemfile +8 -0
  13. data/gemfiles/rails_7_0.gemfile +8 -0
  14. data/haml-rails.gemspec +32 -0
  15. data/lib/generators/haml/controller/controller_generator.rb +5 -6
  16. data/lib/generators/haml/controller/templates/view.html.haml +1 -1
  17. data/lib/generators/haml/mailer/mailer_generator.rb +15 -0
  18. data/lib/generators/haml/mailer/templates/layout.html.haml +8 -0
  19. data/lib/generators/haml/mailer/templates/layout.text.haml +1 -0
  20. data/lib/generators/haml/mailer/templates/view.html.haml +4 -0
  21. data/lib/generators/haml/mailer/templates/view.text.haml +3 -0
  22. data/lib/generators/haml/scaffold/scaffold_generator.rb +11 -19
  23. data/lib/generators/haml/scaffold/templates/_form.html.haml +15 -0
  24. data/lib/generators/haml/scaffold/templates/edit.html.haml +7 -0
  25. data/lib/generators/haml/scaffold/templates/index.html.haml +25 -0
  26. data/lib/generators/haml/scaffold/templates/new.html.haml +5 -0
  27. data/lib/generators/haml/scaffold/templates/show.html.haml +11 -0
  28. data/lib/haml-rails/version.rb +5 -0
  29. data/lib/haml-rails.rb +58 -1
  30. data/lib/rails/generators/haml/application_layout/application_layout_generator.rb +32 -0
  31. data/lib/tasks/erb2haml.rake +83 -0
  32. data/test/fixtures/routes.rb +58 -0
  33. data/test/lib/generators/haml/controller_generator_test.rb +19 -0
  34. data/test/lib/generators/haml/mailer_generator_test.rb +87 -0
  35. data/test/lib/generators/haml/scaffold_generator_test.rb +32 -0
  36. data/test/test_helper.rb +47 -0
  37. metadata +187 -56
  38. data/lib/generators/haml/install/install_generator.rb +0 -14
  39. data/lib/generators/haml/install/templates/config/initializers/haml.rb.tt +0 -4
  40. data/lib/generators/haml/scaffold/templates/_form.html.haml.erb +0 -15
  41. data/lib/generators/haml/scaffold/templates/edit.html.haml.erb +0 -7
  42. data/lib/generators/haml/scaffold/templates/index.html.haml.erb +0 -23
  43. data/lib/generators/haml/scaffold/templates/new.html.haml.erb +0 -5
  44. data/lib/generators/haml/scaffold/templates/show.html.haml.erb +0 -9
  45. data/lib/generators/haml.rb +0 -9
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c92791c4d02db70961e18508ae709bd86a9bae7325eb8afd6f7c8286c3d7824f
4
+ data.tar.gz: 0a4ad454a0c72f707159ee95c4a529cdf3c4194a64b13a690b475a1ff72687c1
5
+ SHA512:
6
+ metadata.gz: e3232df46c3893fab9e0cec861ddb8d88bfd9fe3c40bc0e05a4c67915ef58bd4f54ff9e39a4cc040853cd42fe421942629a46f31294b1622098047e42d5a89a2
7
+ data.tar.gz: d25c5e7ff3ef9fb3e0879129ffe8689c9e06d2b945b404d2be3775573142645304189440deb9ca755b1d5684df1775ea707acd046d6c31f77abdb750bcd98677
@@ -0,0 +1,64 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on:
11
+ push:
12
+ branches: [ master ]
13
+ pull_request:
14
+ branches: [ master ]
15
+
16
+ jobs:
17
+ test:
18
+
19
+ runs-on: ubuntu-latest
20
+ strategy:
21
+ matrix:
22
+ ruby-version:
23
+ - 3.1
24
+ - 3.0
25
+ - 2.7
26
+ - jruby
27
+ gemfile:
28
+ - rails_7_0
29
+ - rails_6_1
30
+ - rails_6_0
31
+
32
+ include:
33
+ - ruby-version: 2.7
34
+ gemfile: rails_5_2
35
+ - ruby-version: 2.7
36
+ gemfile: rails_5_1
37
+
38
+ - ruby-version: 2.6
39
+ gemfile: rails_6_1
40
+ - ruby-version: 2.6
41
+ gemfile: rails_6_0
42
+ - ruby-version: 2.6
43
+ gemfile: rails_5_2
44
+ - ruby-version: 2.6
45
+ gemfile: rails_5_1
46
+
47
+ exclude:
48
+ - ruby-version: jruby
49
+ gemfile: rails_7_0
50
+
51
+ env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps
52
+ BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile
53
+ steps:
54
+ - uses: actions/checkout@v3
55
+ - name: Set up Ruby
56
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
57
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
58
+ uses: ruby/setup-ruby@v1
59
+ # uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
60
+ with:
61
+ ruby-version: ${{ matrix.ruby-version }}
62
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
63
+ - name: Run tests
64
+ run: bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ *.gem
2
+ .bundle/
3
+ *.lock
4
+ gemfiles/*.lock
5
+ tmp/
6
+ /vendor/bundle
7
+ log
data/Appraisals ADDED
@@ -0,0 +1,19 @@
1
+ appraise "rails_5_1" do
2
+ gem "rails", "~> 5.1.0"
3
+ end
4
+
5
+ appraise "rails_5_2" do
6
+ gem "rails", "~> 5.2.0"
7
+ end
8
+
9
+ appraise "rails_6_0" do
10
+ gem "rails", "~> 6.0.0"
11
+ end
12
+
13
+ appraise "rails_6_1" do
14
+ gem "rails", "~> 6.1.0"
15
+ end
16
+
17
+ appraise "rails_7_0" do
18
+ gem "rails", "~> 7.0.0"
19
+ end
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in haml-rails.gemspec
4
+ gemspec
5
+
6
+ gem 'html2haml'
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2010-2015 André Arko
2
+
3
+ MIT Licence
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,3 +1,66 @@
1
1
  # Haml-rails
2
+ [![Build Status](https://travis-ci.org/haml/haml-rails.svg)](https://travis-ci.org/haml/haml-rails)
2
3
 
3
- Haml-rails provides Haml generators for Rails 3. It also enables Haml as the templating engine for you, so you don't have to screw around in your own application.rb when your Gemfile already clearly indicated what templating engine you have installed. Hurrah.
4
+ Haml-rails provides Haml generators for Rails 5. It also enables Haml as the templating engine for you, so you don't have to screw around in your own application.rb when your Gemfile already clearly indicated what templating engine you have installed. Hurrah.
5
+
6
+ To use it, add this line to your Gemfile:
7
+
8
+ gem "haml-rails", "~> 2.0"
9
+
10
+ This ensures that:
11
+
12
+ * Any time you generate a resource, view, or mailer, you'll get Haml templates (instead of ERB)
13
+ * When your Rails application loads, Haml will be loaded and initialized automatically
14
+ * Haml templates will be respected by the view template cache digestor
15
+
16
+ Pretty fancy, eh? The modern world is just so amazing.
17
+
18
+ ### Converting Rails application layout file to haml format
19
+
20
+ Once Haml-rails is installed on the Rails application,
21
+ you can convert the erb layout file, `app/views/layouts/application.html.erb`
22
+ to `app/views/layouts/application.html.haml` using this command:
23
+
24
+ $ rails generate haml:application_layout convert
25
+
26
+ After the application layout file is converted successfully,
27
+ make sure to delete `app/views/layouts/application.html.erb`, so Rails can
28
+ start using `app/views/layouts/application.html.haml` instead.
29
+
30
+ ### Converting all .erb views to haml format
31
+
32
+ If you want to convert all of your .erb views into .haml, you can do so using the following command:
33
+
34
+ $ rails haml:erb2haml
35
+
36
+ If you already have .haml files for one or more of the .erb files, the rake task will give you the option of either
37
+ replacing these .haml files or leaving them in place.
38
+
39
+ Once the task is complete, you will have the option of deleting the original .erb files. Unless you are under
40
+ version control, it is recommended that you decline this option. If you are running in a script, you can use
41
+ an environment variable to answer this question.
42
+
43
+ $ HAML_RAILS_DELETE_ERB=true rails haml:erb2haml
44
+
45
+ Running the above will not prompt for the question and will delete the original .erb files. Setting this value to
46
+ false will also not prompt, however, will leave the .erb files intact.
47
+
48
+ ### Older versions of Rails
49
+
50
+ The current version of Haml-rails requires Rails 5.1 or later.
51
+
52
+ Haml-rails version 1.0.0 is the last version to support Rails 4. To use it, add this line to your Gemfile:
53
+
54
+ gem "haml-rails", "~> 1.0.0"
55
+
56
+ For Rails 3, use haml-rails version 0.4 by adding this line to your Gemfile instead:
57
+
58
+ gem "haml-rails", "~> 0.4.0"
59
+
60
+ ### Contributors
61
+
62
+ Haml generators originally from [rails3-generators](http://github.com/indirect/rails3-generators), and written by José Valim, André Arko, Paul Barry, Anuj Dutta, Louis T, and Chris Rhoden. Tests originally written by Louis T.
63
+
64
+ ### License
65
+
66
+ Ruby license or MIT license, take your pick.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ Bundler::GemHelper.install_tasks
4
+
5
+ require 'rake/testtask'
6
+ Rake::TestTask.new(:test) do |test|
7
+ test.libs << 'lib' << 'test'
8
+ test.pattern = 'test/**/*_test.rb'
9
+ test.verbose = true
10
+ end
11
+
12
+ task :default => :test
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "html2haml"
6
+ gem "rails", "~> 5.1.0"
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "html2haml"
6
+ gem "rails", "~> 5.2.0"
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "html2haml"
6
+ gem "rails", "~> 6.0.0"
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "html2haml"
6
+ gem "rails", "~> 6.1.0"
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "html2haml"
6
+ gem "rails", "~> 7.0.0"
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path("../lib/haml-rails/version", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "haml-rails"
6
+ s.version = Haml::Rails::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["André Arko"]
9
+ s.email = ["andre@arko.net"]
10
+ s.homepage = "https://github.com/haml/haml-rails"
11
+ s.summary = "let your Gemfile do the configuring"
12
+ s.description = "Haml-rails provides Haml generators for Rails 5. It also enables Haml as the templating engine for you, so you don't have to screw around in your own application.rb when your Gemfile already clearly indicated what templating engine you have installed. Hurrah."
13
+ s.licenses = ["MIT"]
14
+
15
+ s.required_rubygems_version = ">= 2.0.0"
16
+ s.required_ruby_version = ">= 2.3.0"
17
+
18
+ s.add_dependency "haml", [">= 4.0.6"]
19
+ s.add_dependency "activesupport", [">= 5.1"]
20
+ s.add_dependency "actionpack", [">= 5.1"]
21
+ s.add_dependency "railties", [">= 5.1"]
22
+
23
+ s.add_development_dependency "html2haml", [">= 1.0.1"]
24
+ s.add_development_dependency "rails", [">= 5.1"]
25
+ s.add_development_dependency "bundler"
26
+ s.add_development_dependency "rake"
27
+ s.add_development_dependency 'appraisal'
28
+
29
+ s.files = `git ls-files`.split("\n")
30
+ s.executables = `git ls-files`.split("\n").select{|f| f =~ /^bin/}
31
+ s.require_path = 'lib'
32
+ end
@@ -1,16 +1,15 @@
1
- require 'generators/haml'
2
1
  require 'rails/generators/erb/controller/controller_generator'
3
2
 
4
3
  module Haml
5
4
  module Generators
6
5
  class ControllerGenerator < Erb::Generators::ControllerGenerator
7
- extend TemplatePath
6
+ source_root File.expand_path("../templates", __FILE__)
8
7
 
9
- protected
8
+ private
10
9
 
11
- def handler
12
- :haml
13
- end
10
+ def handler
11
+ :haml
12
+ end
14
13
  end
15
14
  end
16
15
  end
@@ -1,2 +1,2 @@
1
1
  %h1 <%= class_name %>#<%= @action %>
2
- %p Find me in <%= @path %>
2
+ %p Find me in <%= @path %>
@@ -0,0 +1,15 @@
1
+ require 'rails/generators/erb/mailer/mailer_generator'
2
+
3
+ module Haml
4
+ module Generators
5
+ class MailerGenerator < Erb::Generators::MailerGenerator
6
+ source_root File.expand_path("../templates", __FILE__)
7
+
8
+ private
9
+
10
+ def handler
11
+ :haml
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,8 @@
1
+ !!!
2
+ %html
3
+ %head
4
+ %meta{:content => "text/html; charset=utf-8", "http-equiv" => "Content-Type"}/
5
+ :css
6
+ /* Email styles need to be inline */
7
+ %body
8
+ = yield
@@ -0,0 +1,4 @@
1
+ %h1= class_name + "#" + @action
2
+
3
+ %p
4
+ = @greeting + ", find me in <%= @path %>"
@@ -0,0 +1,3 @@
1
+ <%= class_name %>#<%= @action %>
2
+
3
+ = @greeting + ", find me in <%= @path %>"
@@ -1,18 +1,14 @@
1
- require 'generators/haml'
2
1
  require 'rails/generators/erb/scaffold/scaffold_generator'
3
2
 
4
3
  module Haml
5
4
  module Generators
6
5
  class ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
7
- extend TemplatePath
6
+ source_root File.expand_path("../templates", __FILE__)
8
7
 
9
8
  def copy_view_files
10
- views = available_views
11
- views.delete("index") if options[:singleton]
12
-
13
- views.each do |view|
9
+ available_views.each do |view|
14
10
  filename = filename_with_extensions(view)
15
- template template_filename_with_extensions(view), File.join("app/views", controller_file_path, filename)
11
+ template "#{view}.html.haml", File.join("app/views", controller_file_path, filename)
16
12
  end
17
13
  end
18
14
 
@@ -21,23 +17,19 @@ module Haml
21
17
  def copy_form_file
22
18
  if options[:form_builder].nil?
23
19
  filename = filename_with_extensions("_form")
24
- template template_filename_with_extensions("_form"), File.join("app/views", controller_file_path, filename)
20
+ template "_form.html.haml", File.join("app/views", controller_file_path, filename)
25
21
  end
26
22
  end
27
23
 
28
- protected
29
-
30
- def available_views
31
- %w(index edit show new)
32
- end
24
+ private
33
25
 
34
- def handler
35
- :haml
36
- end
26
+ def available_views
27
+ %w(index edit show new)
28
+ end
37
29
 
38
- def template_filename_with_extensions(name)
39
- [name, format, handler, :erb].compact.join(".")
40
- end
30
+ def handler
31
+ :haml
32
+ end
41
33
  end
42
34
  end
43
35
  end
@@ -0,0 +1,15 @@
1
+ = form_for @<%= singular_table_name %> do |f|
2
+ - if @<%= singular_table_name %>.errors.any?
3
+ #error_explanation
4
+ %h2= "#{pluralize(@<%= singular_table_name %>.errors.count, "error")} prohibited this <%= singular_table_name %> from being saved:"
5
+ %ul
6
+ - @<%= singular_table_name %>.errors.full_messages.each do |message|
7
+ %li= message
8
+
9
+ <% for attribute in attributes -%>
10
+ .field
11
+ = f.label :<%= attribute.name %>
12
+ = f.<%= attribute.field_type %> :<%= attribute.name %>
13
+ <% end -%>
14
+ .actions
15
+ = f.submit 'Save'
@@ -0,0 +1,7 @@
1
+ %h1 Editing <%= singular_table_name %>
2
+
3
+ = render 'form'
4
+
5
+ = link_to 'Show', @<%= singular_table_name %>
6
+ \|
7
+ = link_to 'Back', <%= index_helper %>_path
@@ -0,0 +1,25 @@
1
+ %h1 Listing <%= plural_table_name %>
2
+
3
+ %table
4
+ %thead
5
+ %tr
6
+ <% for attribute in attributes -%>
7
+ %th <%= attribute.human_name %>
8
+ <% end -%>
9
+ %th
10
+ %th
11
+ %th
12
+
13
+ %tbody
14
+ - @<%= plural_table_name %>.each do |<%= singular_table_name %>|
15
+ %tr
16
+ <% for attribute in attributes -%>
17
+ %td= <%= singular_table_name %>.<%= attribute.name %>
18
+ <% end -%>
19
+ %td= link_to 'Show', <%= singular_table_name %>
20
+ %td= link_to 'Edit', edit_<%= singular_table_name %>_path(<%= singular_table_name %>)
21
+ %td= link_to 'Destroy', <%= singular_table_name %>, method: :delete, data: { confirm: 'Are you sure?' }
22
+
23
+ %br
24
+
25
+ = link_to 'New <%= human_name %>', new_<%= singular_table_name %>_path
@@ -0,0 +1,5 @@
1
+ %h1 New <%= singular_table_name %>
2
+
3
+ = render 'form'
4
+
5
+ = link_to 'Back', <%= index_helper %>_path
@@ -0,0 +1,11 @@
1
+ %p#notice= notice
2
+
3
+ <% for attribute in attributes -%>
4
+ %p
5
+ %b <%= attribute.human_name %>:
6
+ = @<%= singular_table_name %>.<%= attribute.name %>
7
+ <% end -%>
8
+
9
+ = link_to 'Edit', edit_<%= singular_table_name %>_path(@<%= singular_table_name %>)
10
+ \|
11
+ = link_to 'Back', <%= index_helper %>_path
@@ -0,0 +1,5 @@
1
+ module Haml
2
+ module Rails
3
+ VERSION = "2.1.0"
4
+ end
5
+ end
data/lib/haml-rails.rb CHANGED
@@ -1,7 +1,64 @@
1
+ require 'haml'
2
+ require 'rails'
3
+ require 'haml/railtie'
4
+
1
5
  module Haml
2
6
  module Rails
3
7
  class Railtie < ::Rails::Railtie
4
- config.generators.template_engine :haml
8
+ config.app_generators.template_engine :haml
9
+
10
+ config.before_initialize do
11
+ Haml::Template.options[:format] = :html5
12
+ end
13
+
14
+ initializer 'haml_rails.configure_template_digestor' do
15
+ # Configure cache digests to parse haml view templates
16
+ # when calculating cache keys for view fragments
17
+
18
+ ActiveSupport.on_load(:action_view) do
19
+ ActiveSupport.on_load(:after_initialize) do
20
+ begin
21
+ if defined?(CacheDigests::DependencyTracker)
22
+ # 'cache_digests' gem being used (overrides Rails 4 implementation)
23
+ CacheDigests::DependencyTracker.register_tracker :haml, CacheDigests::DependencyTracker::ERBTracker
24
+
25
+ if ::Rails.env.development?
26
+ # recalculate cache digest keys for each request
27
+ CacheDigests::TemplateDigestor.cache = ActiveSupport::Cache::NullStore.new
28
+ end
29
+ else
30
+ # will only apply if Rails 4, which includes 'action_view/dependency_tracker'
31
+ require 'action_view/dependency_tracker'
32
+ ActionView::DependencyTracker.register_tracker :haml, ActionView::DependencyTracker::ERBTracker
33
+ ActionView::Base.cache_template_loading = false if ::Rails.env.development?
34
+ end
35
+ rescue
36
+ # likely this version of Rails doesn't support dependency tracking
37
+ # so, we can't parse haml templates without 'cache_digests' gem anyway :)
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ # Configure source annotation on haml files (support for HAML was
44
+ # provided directly by railties 3.2..4.1 but was dropped in 4.2.
45
+ if Gem::Requirement.new(">= 4.2").satisfied_by?(Gem::Version.new(::Rails.version))
46
+ initializer 'haml_rails.configure_source_annotation' do
47
+ annotation_class = if ::Rails::VERSION::STRING >= '6.0'
48
+ require 'rails/source_annotation_extractor'
49
+ ::Rails::SourceAnnotationExtractor::Annotation
50
+ else
51
+ ::SourceAnnotationExtractor::Annotation
52
+ end
53
+ annotation_class.register_extensions('haml') do |tag|
54
+ /\s*-#\s*(#{tag}):?\s*(.*)/
55
+ end
56
+ end
57
+ end
58
+
59
+ rake_tasks do
60
+ load 'tasks/erb2haml.rake'
61
+ end
5
62
  end
6
63
  end
7
64
  end
@@ -0,0 +1,32 @@
1
+ require 'rails'
2
+ require 'shellwords'
3
+
4
+ module Haml
5
+ module Generators
6
+ class ApplicationLayoutGenerator < ::Rails::Generators::Base
7
+ HTML_LAYOUT_PATH = 'app/views/layouts/application.html.erb'
8
+ HAML_LAYOUT_PATH = 'app/views/layouts/application.html.haml'
9
+
10
+ # Converts existing application.html.erb to haml format,
11
+ # and creates app/views/layouts/application.html.haml
12
+ # with some error checking.
13
+ def convert
14
+ app_layout_from = ::Rails.root.join(HTML_LAYOUT_PATH).to_s
15
+ app_layout_to = ::Rails.root.join(HAML_LAYOUT_PATH).to_s
16
+
17
+ if File.exist?(app_layout_from)
18
+
19
+ if !File.exist?(app_layout_to)
20
+ `html2haml #{app_layout_from.shellescape} #{app_layout_to.shellescape}`
21
+ puts "Success! app/views/layouts/application.html.haml is created.\n" \
22
+ "Please remove the erb file: app/views/layouts/application.html.erb"
23
+ else
24
+ puts "Error! There is a file named app/views/layouts/application.html.haml already."
25
+ end
26
+ else
27
+ puts "Error! There is no file named app/views/layouts/application.html.erb."
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end