haml-rails 2.1.0 → 3.1.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 +55 -32
- data/CHANGELOG.md +25 -0
- data/Gemfile +21 -0
- data/README.md +8 -3
- data/haml-rails.gemspec +4 -3
- data/lib/generators/haml/authentication/authentication_generator.rb +17 -0
- data/lib/generators/haml/authentication/templates/app/views/passwords/edit.html.haml +10 -0
- data/lib/generators/haml/authentication/templates/app/views/passwords/new.html.haml +8 -0
- data/lib/generators/haml/authentication/templates/app/views/sessions/new.html.haml +12 -0
- data/lib/generators/haml/controller/controller_generator.rb +2 -0
- data/lib/generators/haml/mailer/mailer_generator.rb +2 -0
- data/lib/generators/haml/scaffold/scaffold_generator.rb +25 -10
- 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/8_1/_form.html.haml +1 -0
- data/lib/generators/haml/scaffold/templates/8_1/edit.html.haml +1 -0
- data/lib/generators/haml/scaffold/templates/8_1/index.html.haml +1 -0
- data/lib/generators/haml/scaffold/templates/8_1/new.html.haml +1 -0
- data/lib/generators/haml/scaffold/templates/8_1/partial.html.haml +14 -0
- data/lib/generators/haml/scaffold/templates/8_1/show.html.haml +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 +12 -1
- data/lib/rails/generators/haml/application_layout/application_layout_generator.rb +8 -3
- data/test/fixtures/routes.rb +2 -0
- data/test/lib/generators/haml/controller_generator_test.rb +2 -0
- data/test/lib/generators/haml/mailer_generator_test.rb +2 -0
- data/test/lib/generators/haml/scaffold_generator_test.rb +2 -0
- data/test/lib/generators/haml/scaffold_template_contents_test.rb +76 -0
- data/test/lib/haml-rails/dependency_tracker_test.rb +60 -0
- data/test/test_helper.rb +30 -7
- metadata +224 -183
- data/Appraisals +0 -19
- data/gemfiles/rails_5_1.gemfile +0 -8
- data/gemfiles/rails_5_2.gemfile +0 -8
- data/gemfiles/rails_6_0.gemfile +0 -8
- data/gemfiles/rails_6_1.gemfile +0 -8
- data/gemfiles/rails_7_0.gemfile +0 -8
- 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
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
%p{id: "notice"}= notice
|
|
2
|
+
|
|
3
|
+
%h1 <%= plural_table_name.titleize %>
|
|
4
|
+
|
|
5
|
+
%table
|
|
6
|
+
%thead
|
|
7
|
+
%tr
|
|
8
|
+
<% attributes.reject(&:password_digest?).each do |attribute| -%>
|
|
9
|
+
%th <%= attribute.human_name %>
|
|
10
|
+
<% end -%>
|
|
11
|
+
%th{colspan: "3"}
|
|
12
|
+
|
|
13
|
+
%tbody
|
|
14
|
+
- @<%= plural_table_name %>.each do |<%= singular_table_name %>|
|
|
15
|
+
%tr
|
|
16
|
+
<% attributes.reject(&:password_digest?).each do |attribute| -%>
|
|
17
|
+
%td= <%= singular_table_name %>.<%= attribute.column_name %>
|
|
18
|
+
<% end -%>
|
|
19
|
+
%td= link_to 'Show', <%= model_resource_name %>
|
|
20
|
+
%td= link_to 'Edit', edit_<%= singular_route_name %>_path(<%= singular_table_name %>)
|
|
21
|
+
%td= link_to 'Destroy', <%= model_resource_name %>, method: :delete, data: { confirm: 'Are you sure?' }
|
|
22
|
+
|
|
23
|
+
%br
|
|
24
|
+
|
|
25
|
+
= link_to 'New <%= singular_table_name.titleize %>', new_<%= singular_route_name %>_path
|
|
@@ -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
|
+
../7_2/_form.html.haml
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
../7_2/edit.html.haml
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
../7_2/index.html.haml
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
../7_2/new.html.haml
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
%div{id: dom_id(<%= singular_name %>)}
|
|
2
|
+
<% attributes.reject(&:password_digest?).each do |attribute| -%>
|
|
3
|
+
%div
|
|
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 @@
|
|
|
1
|
+
../7_2/show.html.haml
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
8_1/_form.html.haml
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
8_1/edit.html.haml
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
8_1/index.html.haml
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
8_1/new.html.haml
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
8_1/partial.html.haml
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
8_1/show.html.haml
|
data/lib/haml-rails/version.rb
CHANGED
data/lib/haml-rails.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'haml'
|
|
2
4
|
require 'rails'
|
|
3
5
|
require 'haml/railtie'
|
|
@@ -29,7 +31,16 @@ module Haml
|
|
|
29
31
|
else
|
|
30
32
|
# will only apply if Rails 4, which includes 'action_view/dependency_tracker'
|
|
31
33
|
require 'action_view/dependency_tracker'
|
|
32
|
-
|
|
34
|
+
# RubyTracker (available since Rails 7.2) compiles the template
|
|
35
|
+
# to Ruby via its handler and parses that, so it detects render
|
|
36
|
+
# calls in Haml. Rails 8.1's ERBTracker only scans ERB `<% %>`
|
|
37
|
+
# tags and no longer sees Haml's `= render`.
|
|
38
|
+
tracker = if defined?(ActionView::DependencyTracker::RubyTracker)
|
|
39
|
+
ActionView::DependencyTracker::RubyTracker
|
|
40
|
+
else
|
|
41
|
+
ActionView::DependencyTracker::ERBTracker
|
|
42
|
+
end
|
|
43
|
+
ActionView::DependencyTracker.register_tracker :haml, tracker
|
|
33
44
|
ActionView::Base.cache_template_loading = false if ::Rails.env.development?
|
|
34
45
|
end
|
|
35
46
|
rescue
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'rails'
|
|
2
4
|
require 'shellwords'
|
|
3
5
|
|
|
@@ -15,11 +17,14 @@ module Haml
|
|
|
15
17
|
app_layout_to = ::Rails.root.join(HAML_LAYOUT_PATH).to_s
|
|
16
18
|
|
|
17
19
|
if File.exist?(app_layout_from)
|
|
18
|
-
|
|
19
20
|
if !File.exist?(app_layout_to)
|
|
20
21
|
`html2haml #{app_layout_from.shellescape} #{app_layout_to.shellescape}`
|
|
21
|
-
|
|
22
|
-
|
|
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
|
|
23
28
|
else
|
|
24
29
|
puts "Error! There is a file named app/views/layouts/application.html.haml already."
|
|
25
30
|
end
|
data/test/fixtures/routes.rb
CHANGED
|
@@ -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
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'test_helper'
|
|
4
|
+
require 'action_view/dependency_tracker'
|
|
5
|
+
|
|
6
|
+
# Touch ActionView::Base so haml-rails' `on_load(:action_view)` hook fires and
|
|
7
|
+
# registers the :haml tracker. In a real app this happens the first time a view
|
|
8
|
+
# renders; a bare tracker test never renders one, so we force the load here.
|
|
9
|
+
ActionView::Base
|
|
10
|
+
|
|
11
|
+
# Regression test for cache dependency detection on Haml templates.
|
|
12
|
+
#
|
|
13
|
+
# Rails 8.1 tightened ERBTracker to only match render calls inside ERB
|
|
14
|
+
# `<% %>` tags, which stopped it from seeing Haml's `= render` and silently
|
|
15
|
+
# broke fragment cache busting. haml-rails now registers RubyTracker (which
|
|
16
|
+
# compiles the template to Ruby before scanning) where it is available.
|
|
17
|
+
#
|
|
18
|
+
# This test asserts the behavior that actually matters: given a Haml template
|
|
19
|
+
# that renders partials, the registered tracker reports those partials as
|
|
20
|
+
# dependencies.
|
|
21
|
+
class DependencyTrackerTest < Minitest::Test
|
|
22
|
+
# Minimal stand-in for an ActionView::Template that exposes just what the
|
|
23
|
+
# dependency trackers touch: the Haml handler and the source.
|
|
24
|
+
class FakeTemplate
|
|
25
|
+
attr_reader :source, :handler
|
|
26
|
+
|
|
27
|
+
def initialize(source)
|
|
28
|
+
@source = source
|
|
29
|
+
@handler = ActionView::Template.handler_for_extension(:haml)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def identifier
|
|
33
|
+
'fake/template'
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def type
|
|
37
|
+
'text/html'
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def format
|
|
41
|
+
:html
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def find_dependencies(source)
|
|
46
|
+
ActionView::DependencyTracker.find_dependencies('things/index', FakeTemplate.new(source), nil)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def test_detects_a_rendered_partial
|
|
50
|
+
assert_includes find_dependencies(%(= render "shared/menu")), 'shared/menu'
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def test_detects_a_partial_rendered_with_explicit_option
|
|
54
|
+
assert_includes find_dependencies(%(= render partial: "posts/post")), 'posts/post'
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def test_detects_an_explicit_dependency_comment
|
|
58
|
+
assert_includes find_dependencies(%(-# Template Dependency: shared/menu)), 'shared/menu'
|
|
59
|
+
end
|
|
60
|
+
end
|
data/test/test_helper.rb
CHANGED
|
@@ -1,26 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'rubygems'
|
|
4
|
+
require 'bundler/setup'
|
|
5
|
+
require 'logger'
|
|
2
6
|
require 'minitest/autorun'
|
|
3
7
|
require 'action_pack'
|
|
4
8
|
require 'action_controller'
|
|
5
9
|
require 'action_view'
|
|
10
|
+
require 'active_model'
|
|
6
11
|
require 'rails'
|
|
7
12
|
require 'rails/generators'
|
|
8
13
|
require 'rails/generators/test_case'
|
|
9
14
|
Bundler.require(:default)
|
|
10
15
|
|
|
11
16
|
class TestApp < Rails::Application
|
|
12
|
-
config.root = File.dirname(__FILE__)
|
|
17
|
+
config.root = Pathname.new(File.expand_path(File.join(File.dirname(__FILE__), '..', 'tmp', 'rails')))
|
|
13
18
|
config.eager_load = false
|
|
14
19
|
end
|
|
15
20
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
@root ||= Pathname.new(File.expand_path(File.join(File.dirname(__FILE__), '..', 'tmp', 'rails')))
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
+
require 'action_controller/railtie'
|
|
22
|
+
require 'action_view/railtie'
|
|
21
23
|
|
|
22
24
|
TestApp.initialize!
|
|
23
25
|
|
|
26
|
+
Rails.application.routes.draw do
|
|
27
|
+
resources :people
|
|
28
|
+
end
|
|
29
|
+
|
|
24
30
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
|
25
31
|
|
|
26
32
|
module Haml
|
|
@@ -40,8 +46,25 @@ end
|
|
|
40
46
|
|
|
41
47
|
::Rails::Generators::TestCase.include Haml::Rails::GeneratorTestHelpers
|
|
42
48
|
|
|
49
|
+
class Person
|
|
50
|
+
include ActiveModel::Model
|
|
51
|
+
|
|
52
|
+
attr_accessor :id, :name
|
|
53
|
+
|
|
54
|
+
def initialize(id, name)
|
|
55
|
+
@id, @name = id, name
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def to_param
|
|
59
|
+
{id: @id}
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
class ApplicationController < ActionController::Base
|
|
64
|
+
end
|
|
65
|
+
|
|
43
66
|
# Remove tmp directory when test suite is completed
|
|
44
|
-
|
|
67
|
+
Minitest.after_run do
|
|
45
68
|
tmp_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'tmp'))
|
|
46
69
|
FileUtils.rm_r(tmp_dir)
|
|
47
70
|
end
|