Merge branch 'master' into patch-1

This commit is contained in:
Olivier Lacan 2019-11-11 22:47:08 -05:00 committed by GitHub
commit 9d2bfbbfd1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 138 additions and 153 deletions

1
.gitignore vendored
View File

@ -4,3 +4,4 @@
gemfiles/*.lock
tmp/
/vendor/bundle
log

View File

@ -1,39 +1,22 @@
sudo: false
language: ruby
cache: bundler
before_install: "gem install bundler"
before_install:
- "gem update --system"
- "gem install bundler"
rvm:
- 2.4.1
- 2.3.1
- 2.2.5
- 2.1
- 2.0
- 1.9.3
- jruby-19mode
- 2.6.5
- 2.5.7
- 2.4.9
- 2.3.8
- jruby-9.2.8.0
gemfile:
- gemfiles/rails_5_2.gemfile
- gemfiles/rails_5_1.gemfile
- gemfiles/rails_5_0.gemfile
- gemfiles/rails_4_2.gemfile
- gemfiles/rails_4_1.gemfile
- gemfiles/rails_4_0.gemfile
- gemfiles/rails_6.gemfile
matrix:
exclude:
- rvm: 2.1
gemfile: gemfiles/rails_5_1.gemfile
- rvm: 2.1
gemfile: gemfiles/rails_5_0.gemfile
- rvm: 2.0
gemfile: gemfiles/rails_5_1.gemfile
- rvm: 2.0
gemfile: gemfiles/rails_5_0.gemfile
- rvm: 1.9.3
gemfile: gemfiles/rails_5_1.gemfile
- rvm: 1.9.3
gemfile: gemfiles/rails_5_0.gemfile
- rvm: 1.9.3
gemfile: gemfiles/rails_4_1.gemfile
- rvm: jruby-19mode
gemfile: gemfiles/rails_5_1.gemfile
- rvm: jruby-19mode
gemfile: gemfiles/rails_5_0.gemfile
- rvm: 2.3.8
gemfile: gemfiles/rails_6.gemfile
- rvm: 2.4.9
gemfile: gemfiles/rails_6.gemfile
script: "bundle exec rake test"

View File

@ -13,3 +13,15 @@ end
appraise "rails_5_0" do
gem "rails", "5.0"
end
appraise "rails_5_1" do
gem "rails", "5.1"
end
appraise "rails_5_2" do
gem "rails", "5.2"
end
appraise "rails_6.rc1" do
gem "rails", "6.0.0.rc1"
end

View File

@ -1,11 +1,11 @@
# Haml-rails
[![Build Status](https://travis-ci.org/indirect/haml-rails.svg)](https://travis-ci.org/indirect/haml-rails)
[![Build Status](https://travis-ci.org/haml/haml-rails.svg)](https://travis-ci.org/haml/haml-rails)
Haml-rails provides Haml generators for Rails 4. 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.
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.
To use it, add this line to your Gemfile:
gem "haml-rails", "~> 0.9"
gem "haml-rails", "~> 2.0"
This ensures that:
@ -31,19 +31,29 @@ start using `app/views/layouts/application.html.haml` instead.
If you want to convert all of your .erb views into .haml, you can do so using the following command:
$ rake haml:erb2haml
$ rails haml:erb2haml
If you already have .haml files for one or more of the .erb files, the rake task will give you the option of either
replacing these .haml files or leaving them in place.
Once the task is complete, you will have the option of deleting the original .erb files. Unless you are under
version control, it is recommended that you decline this option.
version control, it is recommended that you decline this option. If you are running in a script, you can use
an environment variable to answer this question.
$ HAML_RAILS_DELETE_ERB=true rails haml:erb2haml
Running the above will not prompt for the question and will delete the original .erb files. Setting this value to
false will also not prompt, however, will leave the .erb files intact.
### Older versions of Rails
The current version of Haml-rails requires 4.0.1 or later.
The current version of Haml-rails requires Rails 5.1 or later.
Haml-rails version 0.4 is the last version to support Rails 3. To use it, add this line to your Gemfile:
Haml-rails version 1.0.0 is the last version to support Rails 4. To use it, add this line to your Gemfile:
gem "haml-rails", "~> 1.0.0"
For Rails 3, use haml-rails version 0.4 by adding this line to your Gemfile instead:
gem "haml-rails", "~> 0.4.0"

View File

@ -1,10 +0,0 @@
# This file was generated by Appraisal
source "https://rubygems.org"
gem "rubysl", "~> 2.0", :platforms => :rbx
gem "minitest", :platforms => :rbx
gem "html2haml"
gem "rails", "4.2"
gemspec :path => "../"

View File

@ -1,10 +0,0 @@
# This file was generated by Appraisal
source "https://rubygems.org"
gem "rubysl", "~> 2.0", :platforms => :rbx
gem "minitest", :platforms => :rbx
gem "html2haml"
gem "rails", "5.0"
gemspec :path => "../"

View File

@ -5,6 +5,6 @@ source "https://rubygems.org"
gem "rubysl", "~> 2.0", :platforms => :rbx
gem "minitest", :platforms => :rbx
gem "html2haml"
gem "rails", "5.1"
gem "rails", "~> 5.1.5"
gemspec :path => "../"

View File

@ -5,6 +5,6 @@ source "https://rubygems.org"
gem "rubysl", "~> 2.0", :platforms => :rbx
gem "minitest", :platforms => :rbx
gem "html2haml"
gem "rails", "~> 4.0.1"
gem "rails", "~> 5.2.0"
gemspec :path => "../"

View File

@ -5,6 +5,6 @@ source "https://rubygems.org"
gem "rubysl", "~> 2.0", :platforms => :rbx
gem "minitest", :platforms => :rbx
gem "html2haml"
gem "rails", "4.1"
gem "rails", "6.0.0"
gemspec :path => "../"

View File

@ -7,22 +7,22 @@ Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.authors = ["André Arko"]
s.email = ["andre@arko.net"]
s.homepage = "http://github.com/indirect/haml-rails"
s.homepage = "https://github.com/haml/haml-rails"
s.summary = "let your Gemfile do the configuring"
s.description = "Haml-rails provides Haml generators for Rails 4. 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."
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."
s.licenses = ["MIT"]
s.rubyforge_project = "haml-rails"
s.required_rubygems_version = ">= 1.3.6"
s.required_rubygems_version = ">= 2.0.0"
s.required_ruby_version = ">= 2.3.0"
s.add_dependency "haml", [">= 4.0.6", "< 6.0"]
s.add_dependency "activesupport", [">= 4.0.1"]
s.add_dependency "actionpack", [">= 4.0.1"]
s.add_dependency "railties", [">= 4.0.1"]
s.add_dependency "activesupport", [">= 5.1"]
s.add_dependency "actionpack", [">= 5.1"]
s.add_dependency "railties", [">= 5.1"]
s.add_development_dependency "html2haml", [">= 1.0.1"]
s.add_development_dependency "rails", [">= 4.0.1"]
s.add_development_dependency "bundler", "~> 1.7"
s.add_development_dependency "rails", [">= 5.1"]
s.add_development_dependency "bundler"
s.add_development_dependency "rake"
s.add_development_dependency 'appraisal', '~> 1.0'

View File

@ -7,13 +7,13 @@ module Haml
def copy_view_files
if ::Rails.version.to_s >= "4.2.0"
view_base_path = File.join("app/views", class_path, file_name)
view_base_path = File.join("app/views", class_path, file_name + "_mailer")
empty_directory view_base_path
if self.behavior == :invoke
if behavior == :invoke
formats.each do |format|
layout_path = File.join("app/views/layouts", filename_with_extensions("mailer", format))
template filename_with_extensions(:layout, format), layout_path
layout_path = File.join("app/views/layouts", class_path, filename_with_extensions("mailer", format))
template filename_with_extensions(:layout, format), layout_path unless File.exist?(layout_path)
end
end

View File

@ -4,8 +4,6 @@ require 'haml/railtie'
module Haml
module Rails
class Engine < ::Rails::Engine
end
class Railtie < ::Rails::Railtie
config.app_generators.template_engine :haml
@ -46,7 +44,13 @@ module Haml
# provided directly by railties 3.2..4.1 but was dropped in 4.2.
if Gem::Requirement.new(">= 4.2").satisfied_by?(Gem::Version.new(::Rails.version))
initializer 'haml_rails.configure_source_annotation' do
SourceAnnotationExtractor::Annotation.register_extensions('haml') do |tag|
annotation_class = if ::Rails::VERSION::STRING >= '6.0'
require 'rails/source_annotation_extractor'
::Rails::SourceAnnotationExtractor::Annotation
else
::SourceAnnotationExtractor::Annotation
end
annotation_class.register_extensions('haml') do |tag|
/\s*-#\s*(#{tag}):?\s*(.*)/
end
end

View File

@ -1,5 +1,5 @@
module Haml
module Rails
VERSION = "1.0.0"
VERSION = "2.0.1"
end
end

View File

@ -58,8 +58,12 @@ namespace :haml do
puts '-'*80
begin
puts 'Would you like to delete the original .erb files? (This is not recommended unless you are under version control.) (y/n)'
should_delete = STDIN.gets.chomp.downcase[0]
if ENV.has_key?("HAML_RAILS_DELETE_ERB")
should_delete = ENV["HAML_RAILS_DELETE_ERB"] == "true" ? "y" : "n"
else
puts 'Would you like to delete the original .erb files? (This is not recommended unless you are under version control.) (y/n)'
should_delete = STDIN.gets.chomp.downcase[0]
end
end until ['y', 'n'].include?(should_delete)
if should_delete == 'y'

View File

@ -1,5 +1,6 @@
require 'test_helper'
require 'lib/generators/haml/testing_helper'
require 'rails/generators/rails/controller/controller_generator'
require 'generators/haml/controller/controller_generator'
class Haml::Generators::ControllerGeneratorTest < Rails::Generators::TestCase
destination Rails.root

View File

@ -1,5 +1,6 @@
require 'test_helper'
require 'lib/generators/haml/testing_helper'
require 'rails/generators/mailer/mailer_generator'
require 'generators/haml/mailer/mailer_generator'
class Haml::Generators::MailerGeneratorTest < Rails::Generators::TestCase
destination File.join(Rails.root)
@ -13,34 +14,55 @@ class Haml::Generators::MailerGeneratorTest < Rails::Generators::TestCase
run_generator
if ::Rails.version.to_s >= '4.2'
assert_file "app/views/layouts/mailer.text.haml" do |view|
assert_match /\= yield/, view
assert_match(/\= yield/, view)
end
assert_file "app/views/layouts/mailer.html.haml" do |view|
assert_match /\= yield/, view
assert_match(/\= yield/, view)
end
assert_file "app/views/notifier/foo.html.haml" do |view|
assert_match %r(app/views/notifier/foo\.html\.haml), view
assert_match /\= @greeting/, view
assert_file "app/views/notifier_mailer/foo.html.haml" do |view|
assert_match %r(app/views/notifier_mailer/foo\.html\.haml), view
assert_match(/\= @greeting/, view)
end
assert_file "app/views/notifier/bar.html.haml" do |view|
assert_match %r(app/views/notifier/bar\.html\.haml), view
assert_match /\= @greeting/, view
assert_file "app/views/notifier_mailer/bar.html.haml" do |view|
assert_match %r(app/views/notifier_mailer/bar\.html\.haml), view
assert_match(/\= @greeting/, view)
end
end
assert_file "app/views/notifier/foo.text.haml" do |view|
assert_match %r(app/views/notifier/foo\.text\.haml), view
assert_match /\= @greeting/, view
end
assert_file "app/views/notifier_mailer/foo.text.haml" do |view|
assert_match %r(app/views/notifier_mailer/foo\.text\.haml), view
assert_match(/\= @greeting/, view)
end
assert_file "app/views/notifier/bar.text.haml" do |view|
assert_match %r(app/views/notifier/bar\.text\.haml), view
assert_match /\= @greeting/, view
assert_file "app/views/notifier_mailer/bar.text.haml" do |view|
assert_match %r(app/views/notifier_mailer/bar\.text\.haml), view
assert_match(/\= @greeting/, view)
end
else
if ::Rails.version.to_s >= '4.1'
assert_file "app/views/notifier/foo.html.haml" do |view|
assert_match %r(app/views/notifier/foo\.html\.haml), view
assert_match(/\= @greeting/, view)
end
assert_file "app/views/notifier/bar.html.haml" do |view|
assert_match %r(app/views/notifier/bar\.html\.haml), view
assert_match(/\= @greeting/, view)
end
end
assert_file "app/views/notifier/foo.text.haml" do |view|
assert_match %r(app/views/notifier/foo\.text\.haml), view
assert_match(/\= @greeting/, view)
end
assert_file "app/views/notifier/bar.text.haml" do |view|
assert_match %r(app/views/notifier/bar\.text\.haml), view
assert_match(/\= @greeting/, view)
end
end
end
end

View File

@ -1,5 +1,6 @@
require 'test_helper'
require 'lib/generators/haml/testing_helper'
require 'rails/generators/rails/scaffold/scaffold_generator'
require 'generators/haml/scaffold/scaffold_generator'
class Haml::Generators::ScaffoldGeneratorTest < Rails::Generators::TestCase
destination File.join(Rails.root)

View File

@ -1 +0,0 @@
require_generators :haml => ['scaffold', 'controller', 'mailer']

View File

@ -1,79 +1,47 @@
require 'rubygems'
require 'minitest/autorun'
require 'rails/all'
require 'action_pack'
require 'action_controller'
require 'action_view'
require 'rails'
require 'rails/generators'
require 'rails/generators/test_case'
Bundler.require(:default)
class TestApp < Rails::Application
config.root = File.dirname(__FILE__)
config.eager_load = false
end
module Rails
def self.root
@root ||= File.expand_path(File.join(File.dirname(__FILE__), '..', 'tmp', 'rails'))
@root ||= Pathname.new(File.expand_path(File.join(File.dirname(__FILE__), '..', 'tmp', 'rails')))
end
end
# Call configure to load the settings from
# Rails.application.config.generators to Rails::Generators
Rails.application.load_generators
TestApp.initialize!
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
def copy_routes
routes = File.join(File.dirname(__FILE__), 'fixtures', 'routes.rb')
destination = File.join(Rails.root, "config")
FileUtils.mkdir_p(destination)
FileUtils.cp File.expand_path(routes), File.expand_path(destination)
end
module Haml
module Rails
module GeneratorTestHelpers
private
# Asserts the given class exists in the given content. When a block is given,
# it yields the content of the class.
#
# assert_file "test/functional/accounts_controller_test.rb" do |controller_test|
# assert_class "AccountsControllerTest", controller_test do |klass|
# assert_match /context "index action"/, klass
# end
# end
#
def assert_class(klass, content)
assert content =~ /class #{klass}(\(.+\))?(.*?)\nend/m, "Expected to have class #{klass}"
yield $2.strip if block_given?
end
def generator_list
{
:rails => ['scaffold', 'controller', 'mailer'],
:haml => ['scaffold', 'controller', 'mailer']
}
end
def path_prefix(name)
case name
when :rails
'rails/generators'
else
'generators'
end
end
def require_generators(generator_list)
generator_list.each do |name, generators|
generators.each do |generator_name|
if name.to_s == 'rails' && generator_name.to_s == 'mailer'
require File.join(path_prefix(name), generator_name.to_s, "#{generator_name}_generator")
else
require File.join(path_prefix(name), name.to_s, generator_name.to_s, "#{generator_name}_generator")
def copy_routes
routes = File.join(File.dirname(__FILE__), 'fixtures', 'routes.rb')
destination = File.join(::Rails.root, "config")
FileUtils.mkdir_p(destination)
FileUtils.cp File.expand_path(routes), File.expand_path(destination)
end
end
end
end
alias :require_generator :require_generators
require_generators generator_list
::Rails::Generators::TestCase.include Haml::Rails::GeneratorTestHelpers
# Remove tmp directory when test suite is completed
MiniTest::Unit.after_tests do
MiniTest.after_run do
tmp_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'tmp'))
FileUtils.rm_r(tmp_dir)
end