haml-rails 2.0.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +83 -0
- data/.gitignore +1 -0
- data/Gemfile +17 -2
- data/README.md +14 -5
- data/haml-rails.gemspec +8 -8
- data/lib/generators/haml/controller/controller_generator.rb +3 -2
- data/lib/generators/haml/mailer/mailer_generator.rb +7 -33
- data/lib/generators/haml/scaffold/scaffold_generator.rb +25 -11
- data/lib/generators/haml/scaffold/templates/5_1/_form.html.haml +26 -0
- data/lib/generators/haml/scaffold/templates/5_1/edit.html.haml +7 -0
- data/lib/generators/haml/scaffold/templates/5_1/index.html.haml +25 -0
- data/lib/generators/haml/scaffold/templates/5_1/new.html.haml +5 -0
- data/lib/generators/haml/scaffold/templates/5_1/show.html.haml +11 -0
- data/lib/generators/haml/scaffold/templates/5_2/_form.html.haml +26 -0
- data/lib/generators/haml/scaffold/templates/5_2/edit.html.haml +7 -0
- data/lib/generators/haml/scaffold/templates/5_2/index.html.haml +25 -0
- data/lib/generators/haml/scaffold/templates/5_2/new.html.haml +5 -0
- data/lib/generators/haml/scaffold/templates/5_2/show.html.haml +11 -0
- data/lib/generators/haml/scaffold/templates/6_0/_form.html.haml +29 -0
- data/lib/generators/haml/scaffold/templates/6_0/edit.html.haml +7 -0
- data/lib/generators/haml/scaffold/templates/6_0/index.html.haml +25 -0
- data/lib/generators/haml/scaffold/templates/6_0/new.html.haml +5 -0
- data/lib/generators/haml/scaffold/templates/6_0/show.html.haml +18 -0
- data/lib/generators/haml/scaffold/templates/6_1/_form.html.haml +29 -0
- data/lib/generators/haml/scaffold/templates/6_1/edit.html.haml +7 -0
- data/lib/generators/haml/scaffold/templates/6_1/index.html.haml +25 -0
- data/lib/generators/haml/scaffold/templates/6_1/new.html.haml +5 -0
- data/lib/generators/haml/scaffold/templates/6_1/show.html.haml +18 -0
- data/lib/generators/haml/scaffold/templates/7_0/_form.html.haml +29 -0
- data/lib/generators/haml/scaffold/templates/7_0/edit.html.haml +10 -0
- data/lib/generators/haml/scaffold/templates/7_0/index.html.haml +11 -0
- data/lib/generators/haml/scaffold/templates/7_0/new.html.haml +8 -0
- data/lib/generators/haml/scaffold/templates/7_0/partial.html.haml +14 -0
- data/lib/generators/haml/scaffold/templates/7_0/show.html.haml +10 -0
- data/lib/generators/haml/scaffold/templates/7_1 +1 -0
- data/lib/generators/haml/scaffold/templates/7_2/_form.html.haml +29 -0
- data/lib/generators/haml/scaffold/templates/7_2/edit.html.haml +12 -0
- data/lib/generators/haml/scaffold/templates/7_2/index.html.haml +13 -0
- data/lib/generators/haml/scaffold/templates/7_2/new.html.haml +10 -0
- data/lib/generators/haml/scaffold/templates/7_2/partial.html.haml +14 -0
- data/lib/generators/haml/scaffold/templates/7_2/show.html.haml +10 -0
- data/lib/generators/haml/scaffold/templates/8_0 +1 -0
- data/lib/generators/haml/scaffold/templates/_form.html.haml +1 -0
- data/lib/generators/haml/scaffold/templates/edit.html.haml +1 -0
- data/lib/generators/haml/scaffold/templates/index.html.haml +1 -0
- data/lib/generators/haml/scaffold/templates/new.html.haml +1 -0
- data/lib/generators/haml/scaffold/templates/partial.html.haml +1 -0
- data/lib/generators/haml/scaffold/templates/show.html.haml +1 -0
- data/lib/haml-rails/version.rb +3 -1
- data/lib/haml-rails.rb +2 -2
- data/lib/rails/generators/haml/application_layout/application_layout_generator.rb +8 -6
- data/lib/tasks/erb2haml.rake +22 -18
- data/test/fixtures/routes.rb +2 -0
- data/test/lib/generators/haml/controller_generator_test.rb +6 -3
- data/test/lib/generators/haml/mailer_generator_test.rb +23 -1
- data/test/lib/generators/haml/scaffold_generator_test.rb +4 -1
- data/test/lib/generators/haml/scaffold_template_contents_test.rb +76 -0
- data/test/test_helper.rb +44 -53
- metadata +52 -43
- data/.travis.yml +0 -23
- data/Appraisals +0 -27
- data/gemfiles/rails_5_1.gemfile +0 -10
- data/gemfiles/rails_5_2.gemfile +0 -10
- data/gemfiles/rails_6.beta2.gemfile +0 -10
- data/lib/generators/haml/scaffold/templates/_form.html.haml +0 -15
- data/lib/generators/haml/scaffold/templates/edit.html.haml +0 -7
- data/lib/generators/haml/scaffold/templates/index.html.haml +0 -25
- data/lib/generators/haml/scaffold/templates/new.html.haml +0 -5
- data/lib/generators/haml/scaffold/templates/show.html.haml +0 -11
- data/test/lib/generators/haml/testing_helper.rb +0 -1
@@ -0,0 +1,18 @@
|
|
1
|
+
%p{id: "notice"}= notice
|
2
|
+
|
3
|
+
<% attributes.reject(&:password_digest?).each do |attribute| -%>
|
4
|
+
%p
|
5
|
+
%strong <%= attribute.human_name %>:
|
6
|
+
<% if attribute.attachment? -%>
|
7
|
+
= link_to @<%= singular_table_name %>.<%= attribute.column_name %>.filename, @<%= singular_table_name %>.<%= attribute.column_name %> if @<%= singular_table_name %>.<%= attribute.column_name %>.attached?
|
8
|
+
<% elsif attribute.attachments? -%>
|
9
|
+
- @<%= singular_table_name %>.<%= attribute.column_name %>.each do |<%= attribute.singular_name %>|
|
10
|
+
%div= link_to <%= attribute.singular_name %>.filename, <%= attribute.singular_name %>
|
11
|
+
<% else -%>
|
12
|
+
= @<%= singular_table_name %>.<%= attribute.column_name %>
|
13
|
+
<% end -%>
|
14
|
+
|
15
|
+
<% end -%>
|
16
|
+
= link_to 'Edit', edit_<%= singular_table_name %>_path(@<%= singular_table_name %>)
|
17
|
+
|
|
18
|
+
= link_to 'Back', <%= index_helper %>_path
|
@@ -0,0 +1,29 @@
|
|
1
|
+
= form_with(model: <%= model_resource_name %>) do |form|
|
2
|
+
- if <%= singular_table_name %>.errors.any?
|
3
|
+
%div{style: "color: red"}
|
4
|
+
%h2= "#{pluralize(<%= singular_table_name %>.errors.count, "error")} prohibited this <%= singular_table_name %> from being saved:"
|
5
|
+
|
6
|
+
%ul
|
7
|
+
- <%= singular_table_name %>.errors.each do |error|
|
8
|
+
%li= error.full_message
|
9
|
+
|
10
|
+
<% attributes.each do |attribute| -%>
|
11
|
+
%div
|
12
|
+
<% if attribute.password_digest? -%>
|
13
|
+
= form.label :password, style: "display: block"
|
14
|
+
= form.password_field :password
|
15
|
+
|
16
|
+
%div
|
17
|
+
= form.label :password_confirmation, style: "display: block"
|
18
|
+
= form.password_field :password_confirmation
|
19
|
+
<% elsif attribute.attachments? -%>
|
20
|
+
= form.label :<%= attribute.column_name %>, style: "display: block"
|
21
|
+
= form.<%= attribute.field_type %> :<%= attribute.column_name %>, multiple: true
|
22
|
+
<% else -%>
|
23
|
+
= form.label :<%= attribute.column_name %>, style: "display: block"
|
24
|
+
= form.<%= attribute.field_type %> :<%= attribute.column_name %>
|
25
|
+
<% end -%>
|
26
|
+
|
27
|
+
<% end -%>
|
28
|
+
%div
|
29
|
+
= form.submit
|
@@ -0,0 +1,10 @@
|
|
1
|
+
%h1 Editing <%= human_name.downcase %>
|
2
|
+
|
3
|
+
= render "form", <%= singular_table_name %>: @<%= singular_table_name %>
|
4
|
+
|
5
|
+
%br
|
6
|
+
|
7
|
+
%div
|
8
|
+
= link_to "Show this <%= human_name.downcase %>", <%= model_resource_name(prefix: "@") %>
|
9
|
+
|
|
10
|
+
= link_to "Back to <%= human_name.pluralize.downcase %>", <%= index_helper(type: :path) %>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
%p{style: "color: green"}= notice
|
2
|
+
|
3
|
+
%h1 <%= human_name.pluralize %>
|
4
|
+
|
5
|
+
%div{id: "<%= plural_table_name %>"}
|
6
|
+
- @<%= plural_table_name %>.each do |<%= singular_table_name %>|
|
7
|
+
= render <%= singular_table_name %>
|
8
|
+
%p
|
9
|
+
= link_to "Show this <%= human_name.downcase %>", <%= model_resource_name(singular_table_name) %>
|
10
|
+
|
11
|
+
= link_to "New <%= human_name.downcase %>", <%= new_helper(type: :path) %>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
%div{id: dom_id(<%= singular_name %>)}
|
2
|
+
<% attributes.reject(&:password_digest?).each do |attribute| -%>
|
3
|
+
%p
|
4
|
+
%strong <%= attribute.human_name %>:
|
5
|
+
<% if attribute.attachment? -%>
|
6
|
+
= link_to <%= singular_name %>.<%= attribute.column_name %>.filename, <%= singular_name %>.<%= attribute.column_name %> if <%= singular_name %>.<%= attribute.column_name %>.attached?
|
7
|
+
<% elsif attribute.attachments? -%>
|
8
|
+
- <%= singular_name %>.<%= attribute.column_name %>.each do |<%= attribute.singular_name %>|
|
9
|
+
%div= link_to <%= attribute.singular_name %>.filename, <%= attribute.singular_name %>
|
10
|
+
<% else -%>
|
11
|
+
= <%= singular_name %>.<%= attribute.column_name %>
|
12
|
+
<% end -%>
|
13
|
+
|
14
|
+
<% end -%>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
%p{style: "color: green"}= notice
|
2
|
+
|
3
|
+
= render @<%= singular_table_name %>
|
4
|
+
|
5
|
+
%div
|
6
|
+
= link_to "Edit this <%= human_name.downcase %>", <%= edit_helper(type: :path) %>
|
7
|
+
|
|
8
|
+
= link_to "Back to <%= human_name.pluralize.downcase %>", <%= index_helper(type: :path) %>
|
9
|
+
|
10
|
+
= button_to "Destroy this <%= human_name.downcase %>", <%= model_resource_name(prefix: "@") %>, method: :delete
|
@@ -0,0 +1 @@
|
|
1
|
+
7_0
|
@@ -0,0 +1,29 @@
|
|
1
|
+
= form_with(model: <%= model_resource_name %>) do |form|
|
2
|
+
- if <%= singular_table_name %>.errors.any?
|
3
|
+
%div{style: "color: red"}
|
4
|
+
%h2= "#{pluralize(<%= singular_table_name %>.errors.count, "error")} prohibited this <%= singular_table_name %> from being saved:"
|
5
|
+
|
6
|
+
%ul
|
7
|
+
- <%= singular_table_name %>.errors.each do |error|
|
8
|
+
%li= error.full_message
|
9
|
+
|
10
|
+
<% attributes.each do |attribute| -%>
|
11
|
+
%div
|
12
|
+
<% if attribute.password_digest? -%>
|
13
|
+
= form.label :password, style: "display: block"
|
14
|
+
= form.password_field :password
|
15
|
+
|
16
|
+
%div
|
17
|
+
= form.label :password_confirmation, style: "display: block"
|
18
|
+
= form.password_field :password_confirmation
|
19
|
+
<% elsif attribute.attachments? -%>
|
20
|
+
= form.label :<%= attribute.column_name %>, style: "display: block"
|
21
|
+
= form.<%= attribute.field_type %> :<%= attribute.column_name %>, multiple: true
|
22
|
+
<% else -%>
|
23
|
+
= form.label :<%= attribute.column_name %>, style: "display: block"
|
24
|
+
= form.<%= attribute.field_type %> :<%= attribute.column_name %>
|
25
|
+
<% end -%>
|
26
|
+
|
27
|
+
<% end -%>
|
28
|
+
%div
|
29
|
+
= form.submit
|
@@ -0,0 +1,12 @@
|
|
1
|
+
- content_for :title, "Editing <%= human_name.downcase %>"
|
2
|
+
|
3
|
+
%h1 Editing <%= human_name.downcase %>
|
4
|
+
|
5
|
+
= render "form", <%= singular_table_name %>: @<%= singular_table_name %>
|
6
|
+
|
7
|
+
%br
|
8
|
+
|
9
|
+
%div
|
10
|
+
= link_to "Show this <%= human_name.downcase %>", <%= model_resource_name(prefix: "@") %>
|
11
|
+
|
|
12
|
+
= link_to "Back to <%= human_name.pluralize.downcase %>", <%= index_helper(type: :path) %>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
%p{style: "color: green"}= notice
|
2
|
+
|
3
|
+
- content_for :title, "<%= human_name.pluralize %>"
|
4
|
+
|
5
|
+
%h1 <%= human_name.pluralize %>
|
6
|
+
|
7
|
+
%div{id: "<%= plural_table_name %>"}
|
8
|
+
- @<%= plural_table_name %>.each do |<%= singular_table_name %>|
|
9
|
+
= render <%= singular_table_name %>
|
10
|
+
%p
|
11
|
+
= link_to "Show this <%= human_name.downcase %>", <%= model_resource_name(singular_table_name) %>
|
12
|
+
|
13
|
+
= link_to "New <%= human_name.downcase %>", <%= new_helper(type: :path) %>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
- content_for :title, "New <%= human_name.downcase %>"
|
2
|
+
|
3
|
+
%h1 New <%= human_name.downcase %>
|
4
|
+
|
5
|
+
= render "form", <%= singular_table_name %>: @<%= singular_table_name %>
|
6
|
+
|
7
|
+
%br
|
8
|
+
|
9
|
+
%div
|
10
|
+
= link_to "Back to <%= human_name.pluralize.downcase %>", <%= index_helper(type: :path) %>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
%div{id: dom_id(<%= singular_name %>)}
|
2
|
+
<% attributes.reject(&:password_digest?).each do |attribute| -%>
|
3
|
+
%p
|
4
|
+
%strong <%= attribute.human_name %>:
|
5
|
+
<% if attribute.attachment? -%>
|
6
|
+
= link_to <%= singular_name %>.<%= attribute.column_name %>.filename, <%= singular_name %>.<%= attribute.column_name %> if <%= singular_name %>.<%= attribute.column_name %>.attached?
|
7
|
+
<% elsif attribute.attachments? -%>
|
8
|
+
- <%= singular_name %>.<%= attribute.column_name %>.each do |<%= attribute.singular_name %>|
|
9
|
+
%div= link_to <%= attribute.singular_name %>.filename, <%= attribute.singular_name %>
|
10
|
+
<% else -%>
|
11
|
+
= <%= singular_name %>.<%= attribute.column_name %>
|
12
|
+
<% end -%>
|
13
|
+
|
14
|
+
<% end -%>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
%p{style: "color: green"}= notice
|
2
|
+
|
3
|
+
= render @<%= singular_table_name %>
|
4
|
+
|
5
|
+
%div
|
6
|
+
= link_to "Edit this <%= human_name.downcase %>", <%= edit_helper(type: :path) %>
|
7
|
+
|
|
8
|
+
= link_to "Back to <%= human_name.pluralize.downcase %>", <%= index_helper(type: :path) %>
|
9
|
+
|
10
|
+
= button_to "Destroy this <%= human_name.downcase %>", <%= model_resource_name(prefix: "@") %>, method: :delete
|
@@ -0,0 +1 @@
|
|
1
|
+
7_2
|
@@ -0,0 +1 @@
|
|
1
|
+
8_0/_form.html.haml
|
@@ -0,0 +1 @@
|
|
1
|
+
8_0/edit.html.haml
|
@@ -0,0 +1 @@
|
|
1
|
+
8_0/index.html.haml
|
@@ -0,0 +1 @@
|
|
1
|
+
8_0/new.html.haml
|
@@ -0,0 +1 @@
|
|
1
|
+
8_0/partial.html.haml
|
@@ -0,0 +1 @@
|
|
1
|
+
8_0/show.html.haml
|
data/lib/haml-rails/version.rb
CHANGED
data/lib/haml-rails.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rails'
|
2
4
|
require 'shellwords'
|
3
5
|
|
4
6
|
module Haml
|
5
7
|
module Generators
|
6
8
|
class ApplicationLayoutGenerator < ::Rails::Generators::Base
|
7
|
-
|
8
9
|
HTML_LAYOUT_PATH = 'app/views/layouts/application.html.erb'
|
9
10
|
HAML_LAYOUT_PATH = 'app/views/layouts/application.html.haml'
|
10
11
|
|
@@ -16,20 +17,21 @@ module Haml
|
|
16
17
|
app_layout_to = ::Rails.root.join(HAML_LAYOUT_PATH).to_s
|
17
18
|
|
18
19
|
if File.exist?(app_layout_from)
|
19
|
-
|
20
20
|
if !File.exist?(app_layout_to)
|
21
21
|
`html2haml #{app_layout_from.shellescape} #{app_layout_to.shellescape}`
|
22
|
-
|
23
|
-
|
22
|
+
if $?.success?
|
23
|
+
puts "Success! app/views/layouts/application.html.haml is created.\n" \
|
24
|
+
"Please remove the erb file: app/views/layouts/application.html.erb"
|
25
|
+
else
|
26
|
+
puts "Error! Failed to execute html2haml command."
|
27
|
+
end
|
24
28
|
else
|
25
29
|
puts "Error! There is a file named app/views/layouts/application.html.haml already."
|
26
30
|
end
|
27
31
|
else
|
28
32
|
puts "Error! There is no file named app/views/layouts/application.html.erb."
|
29
33
|
end
|
30
|
-
|
31
34
|
end
|
32
|
-
|
33
35
|
end
|
34
36
|
end
|
35
37
|
end
|
data/lib/tasks/erb2haml.rake
CHANGED
@@ -10,6 +10,8 @@ namespace :haml do
|
|
10
10
|
exit
|
11
11
|
end
|
12
12
|
|
13
|
+
erb_files_to_convert = erb_files.dup
|
14
|
+
|
13
15
|
haml_files_w_out_ext = haml_files.map { |f| f.gsub(/\.haml\z/, '') }
|
14
16
|
|
15
17
|
# Get a list of all those erb files that already seem to have .haml equivalents
|
@@ -22,21 +24,24 @@ namespace :haml do
|
|
22
24
|
puts "Some of your .html.erb files seem to already have .haml equivalents:"
|
23
25
|
already_existing.map { |f| puts "\t#{f}" }
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
if ENV.has_key?("HAML_RAILS_OVERWRITE_HAML") && (ENV["HAML_RAILS_OVERWRITE_HAML"] == "false")
|
28
|
+
should_overwrite = 'n'
|
29
|
+
else
|
30
|
+
# Ask the user whether he/she would like to overwrite them.
|
31
|
+
begin
|
32
|
+
puts "Would you like to overwrite these .haml files? (y/n)"
|
33
|
+
should_overwrite = STDIN.gets.chomp.downcase[0]
|
34
|
+
end until ['y', 'n'].include?(should_overwrite)
|
35
|
+
end
|
30
36
|
puts '-'*80
|
31
37
|
|
32
38
|
# If we are not overwriting, remove each already_existing from our erb_files list
|
33
39
|
if should_overwrite == 'n'
|
34
|
-
|
40
|
+
erb_files_to_convert = erb_files - already_existing
|
35
41
|
|
36
|
-
if
|
42
|
+
if erb_files_to_convert.empty?
|
37
43
|
# It is possible no .erb files remain, after we remove already_existing
|
38
|
-
puts "No .erb files
|
39
|
-
return
|
44
|
+
puts "No .erb files to convert"
|
40
45
|
end
|
41
46
|
else
|
42
47
|
# Delete the current .haml
|
@@ -44,7 +49,7 @@ namespace :haml do
|
|
44
49
|
end
|
45
50
|
end
|
46
51
|
|
47
|
-
|
52
|
+
erb_files_to_convert.each do |file|
|
48
53
|
puts "Generating HAML for #{file}..."
|
49
54
|
`html2haml #{file} #{file.gsub(/\.erb\z/, '.haml')}`
|
50
55
|
end
|
@@ -52,20 +57,19 @@ namespace :haml do
|
|
52
57
|
puts '-'*80
|
53
58
|
|
54
59
|
puts "HAML generated for the following files:"
|
55
|
-
|
60
|
+
erb_files_to_convert.each do |file|
|
56
61
|
puts "\t#{file}"
|
57
62
|
end
|
58
63
|
|
59
64
|
puts '-'*80
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
65
|
+
if ENV.has_key?("HAML_RAILS_DELETE_ERB") && (ENV["HAML_RAILS_DELETE_ERB"] == "true")
|
66
|
+
should_delete = 'y'
|
67
|
+
else
|
68
|
+
begin
|
64
69
|
puts 'Would you like to delete the original .erb files? (This is not recommended unless you are under version control.) (y/n)'
|
65
70
|
should_delete = STDIN.gets.chomp.downcase[0]
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
71
|
+
end until ['y', 'n'].include?(should_delete)
|
72
|
+
end
|
69
73
|
if should_delete == 'y'
|
70
74
|
puts "Deleting original .erb files."
|
71
75
|
File.delete(*erb_files)
|
data/test/fixtures/routes.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
|
-
require '
|
4
|
+
require 'rails/generators/rails/controller/controller_generator'
|
5
|
+
require 'generators/haml/controller/controller_generator'
|
3
6
|
|
4
7
|
class Haml::Generators::ControllerGeneratorTest < Rails::Generators::TestCase
|
5
8
|
destination Rails.root
|
@@ -11,8 +14,8 @@ class Haml::Generators::ControllerGeneratorTest < Rails::Generators::TestCase
|
|
11
14
|
arguments %w(Account foo bar --template-engine haml)
|
12
15
|
|
13
16
|
test "should invoke haml engine" do
|
14
|
-
run_generator
|
17
|
+
run_generator
|
15
18
|
assert_file "app/views/account/foo.html.haml"
|
16
19
|
assert_file "app/views/account/bar.html.haml"
|
17
|
-
end
|
20
|
+
end
|
18
21
|
end
|
@@ -1,5 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
|
-
require '
|
4
|
+
require 'rails/generators/mailer/mailer_generator'
|
5
|
+
require 'generators/haml/mailer/mailer_generator'
|
3
6
|
|
4
7
|
class Haml::Generators::MailerGeneratorTest < Rails::Generators::TestCase
|
5
8
|
destination File.join(Rails.root)
|
@@ -64,4 +67,23 @@ class Haml::Generators::MailerGeneratorTest < Rails::Generators::TestCase
|
|
64
67
|
end
|
65
68
|
end
|
66
69
|
end
|
70
|
+
|
71
|
+
test 'suffix is not duplicated' do
|
72
|
+
if ::Rails.version.to_s >= '4.2'
|
73
|
+
run_generator ['notifier_mailer', 'foo', 'bar', '--template-engine', 'haml']
|
74
|
+
|
75
|
+
assert_no_file 'app/views/notifier_mailer_mailer/'
|
76
|
+
assert_file 'app/views/notifier_mailer/'
|
77
|
+
|
78
|
+
assert_no_file 'app/views/notifier_mailer_mailer/foo.text.haml'
|
79
|
+
assert_file 'app/views/notifier_mailer/foo.text.haml'
|
80
|
+
assert_no_file 'app/views/notifier_mailer_mailer/foo.html.haml'
|
81
|
+
assert_file 'app/views/notifier_mailer/foo.html.haml'
|
82
|
+
|
83
|
+
assert_no_file 'app/views/notifier_mailer_mailer/bar.text.haml'
|
84
|
+
assert_file 'app/views/notifier_mailer/bar.text.haml'
|
85
|
+
assert_no_file 'app/views/notifier_mailer_mailer/bar.html.haml'
|
86
|
+
assert_file 'app/views/notifier_mailer/bar.html.haml'
|
87
|
+
end
|
88
|
+
end
|
67
89
|
end
|
@@ -1,5 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
|
-
require '
|
4
|
+
require 'rails/generators/rails/scaffold/scaffold_generator'
|
5
|
+
require 'generators/haml/scaffold/scaffold_generator'
|
3
6
|
|
4
7
|
class Haml::Generators::ScaffoldGeneratorTest < Rails::Generators::TestCase
|
5
8
|
destination File.join(Rails.root)
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
require 'rails/generators/rails/scaffold/scaffold_generator'
|
5
|
+
require 'generators/haml/scaffold/scaffold_generator'
|
6
|
+
require 'action_controller/test_case'
|
7
|
+
|
8
|
+
class Haml::Generators::ScaffoldTemplateContentsTest < Rails::Generators::TestCase
|
9
|
+
destination File.join(Rails.root)
|
10
|
+
tests Rails::Generators::ScaffoldGenerator
|
11
|
+
arguments %w(person name)
|
12
|
+
|
13
|
+
setup :prepare_destination
|
14
|
+
setup :copy_routes
|
15
|
+
|
16
|
+
def view_context
|
17
|
+
@view_context ||= begin
|
18
|
+
require Rails.root.join('app/controllers/people_controller')
|
19
|
+
|
20
|
+
controller = PeopleController.new
|
21
|
+
controller.set_request!(ActionDispatch::Request.empty)
|
22
|
+
controller.request.session = ActionController::TestSession.new
|
23
|
+
|
24
|
+
if controller.lookup_context.respond_to? :append_view_paths
|
25
|
+
controller.lookup_context.append_view_paths([Rails.root.join('app/views')])
|
26
|
+
else
|
27
|
+
controller.lookup_context.view_paths << Rails.root.join('app/views')
|
28
|
+
end
|
29
|
+
controller.instance_variable_set :@people, []
|
30
|
+
controller.instance_variable_set :@person, Person.new(1, 'Person 1')
|
31
|
+
|
32
|
+
controller.view_context
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def assert_html_content_with_erb_version(view, html)
|
37
|
+
view_context.lookup_context.handlers = [:erb]
|
38
|
+
erb_html = view_context.render(template: "people/#{view}")
|
39
|
+
|
40
|
+
assert_equal scrub(erb_html), scrub(html), "#{view} template result differs from the ERB version"
|
41
|
+
end
|
42
|
+
|
43
|
+
def scrub(html)
|
44
|
+
html = strip_whitespace html
|
45
|
+
strip_authenticity_token! html
|
46
|
+
html
|
47
|
+
end
|
48
|
+
|
49
|
+
def strip_whitespace(html)
|
50
|
+
html_doc = Nokogiri::HTML(html)
|
51
|
+
html_doc.xpath('//text()').each do |text_node|
|
52
|
+
text_node.remove if text_node.text.strip.empty?
|
53
|
+
text_node.content = text_node.text.strip
|
54
|
+
end
|
55
|
+
html_doc.to_html
|
56
|
+
end
|
57
|
+
|
58
|
+
def strip_authenticity_token!(html)
|
59
|
+
html.sub!(/(<input type="hidden" name="authenticity_token" value=").*?"/, '\1"')
|
60
|
+
html.sub!(/(<input autocomplete="off" name="authenticity_token" type="hidden" value=").*?"/, '\1"')
|
61
|
+
end
|
62
|
+
|
63
|
+
test 'should generate a set of templates that are 100% compatible with the original ERB templates' do
|
64
|
+
run_generator
|
65
|
+
run_generator default_arguments + %w(--template-engine haml)
|
66
|
+
|
67
|
+
%w(index edit new show).each do |view|
|
68
|
+
assert_file "app/views/people/#{view}.html.haml"
|
69
|
+
|
70
|
+
view_context.lookup_context.handlers = [:haml]
|
71
|
+
haml_html = view_context.render(template: "people/#{view}")
|
72
|
+
|
73
|
+
assert_html_content_with_erb_version view, haml_html
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|