-
-
Notifications
You must be signed in to change notification settings - Fork 317
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generates view partials for menus rails g alchemy:menus
- Loading branch information
Showing
11 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../base' | ||
|
||
module Alchemy | ||
module Generators | ||
class MenusGenerator < Base | ||
desc "This generator generates Alchemy menu partials." | ||
source_root File.expand_path('templates', __dir__) | ||
|
||
def create_partials | ||
menus = Alchemy::Node.roots | ||
return unless menus | ||
|
||
menus.each do |menu| | ||
conditional_template "wrapper.html.#{template_engine}", | ||
"app/views/#{menu.view_folder_name}/_wrapper.html.#{template_engine}" | ||
conditional_template "node.html.#{template_engine}", | ||
"app/views/#{menu.view_folder_name}/_node.html.#{template_engine}" | ||
end | ||
end | ||
end | ||
end | ||
end |
17 changes: 17 additions & 0 deletions
17
lib/rails/generators/alchemy/menus/templates/node.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<%%= content_tag :li, class: ['nav-item', node.children.any? ? 'dropdown' : nil].compact do %> | ||
<%%= link_to_if node.url, | ||
node.name, | ||
@preview_mode ? 'javascript: void(0)' : node.url, | ||
class: ['nav-link', current_page?(node.url) ? 'active' : nil].compact, | ||
title: node.title, | ||
target: node.external? ? '_blank' : nil, | ||
rel: node.nofollow? ? 'nofollow' : nil %> | ||
<%% if node.children.any? %> | ||
<ul class="dropdown-menu"> | ||
<%%= render partial: options[:node_partial_name], | ||
collection: node.children.includes(:page, :children), | ||
locals: { options: options }, | ||
as: 'node' %> | ||
</ul> | ||
<%% end %> | ||
<%% end %> |
15 changes: 15 additions & 0 deletions
15
lib/rails/generators/alchemy/menus/templates/node.html.haml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
= content_tag :li, | ||
class: ['nav-item', node.children.any? ? 'dropdown' : nil].compact do | ||
= link_to_if node.url, | ||
node.name, | ||
@preview_mode ? 'javascript: void(0)' : node.url, | ||
class: ['nav-link', current_page?(node.url) ? 'active' : nil].compact, | ||
title: node.title, | ||
target: node.external? ? '_blank' : nil, | ||
rel: node.nofollow? ? 'nofollow' : nil | ||
- if node.children.any? | ||
%ul.dropdown-menu | ||
= render partial: options[:node_partial_name], | ||
collection: node.children.includes(:page, :children), | ||
locals: { options: options }, | ||
as: 'node' |
15 changes: 15 additions & 0 deletions
15
lib/rails/generators/alchemy/menus/templates/node.html.slim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
= content_tag :li, | ||
class: ['nav-item', node.children.any? ? 'dropdown' : nil].compact do | ||
= link_to_if node.url, | ||
node.name, | ||
@preview_mode ? 'javascript: void(0)' : node.url, | ||
class: ['nav-link', current_page?(node.url) ? 'active' : nil].compact, | ||
title: node.title, | ||
target: node.external? ? '_blank' : nil, | ||
rel: node.nofollow? ? 'nofollow' : nil | ||
- if node.children.any? | ||
ul.dropdown-menu | ||
= render partial: options[:node_partial_name], | ||
collection: node.children.includes(:page, :children), | ||
locals: { options: options }, | ||
as: 'node' |
6 changes: 6 additions & 0 deletions
6
lib/rails/generators/alchemy/menus/templates/wrapper.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<ul class="nav"> | ||
<%%= render partial: options[:node_partial_name], | ||
collection: node.children.includes(:page, :children), | ||
locals: { options: options }, | ||
as: 'node' %> | ||
</ul> |
5 changes: 5 additions & 0 deletions
5
lib/rails/generators/alchemy/menus/templates/wrapper.html.haml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
%ul.nav | ||
= render partial: options[:node_partial_name], | ||
collection: node.children.includes(:page, :children), | ||
locals: { options: options }, | ||
as: 'node' %> |
5 changes: 5 additions & 0 deletions
5
lib/rails/generators/alchemy/menus/templates/wrapper.html.slim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
ul.nav | ||
= render partial: options[:node_partial_name], | ||
collection: node.children.includes(:page, :children), | ||
locals: { options: options }, | ||
as: 'node' %> |
17 changes: 17 additions & 0 deletions
17
spec/dummy/app/views/alchemy/menus/footer_navigation/_node.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<%= content_tag :li, class: ['nav-item', node.children.any? ? 'dropdown' : nil].compact do %> | ||
<%= link_to_if node.url, | ||
node.name, | ||
@preview_mode ? 'javascript: void(0)' : node.url, | ||
class: ['nav-link', current_page?(node.url) ? 'active' : nil].compact, | ||
title: node.title, | ||
target: node.external? ? '_blank' : nil, | ||
rel: node.nofollow? ? 'nofollow' : nil %> | ||
<% if node.children.any? %> | ||
<ul class="dropdown-menu"> | ||
<%= render partial: options[:node_partial_name], | ||
collection: node.children.includes(:page, :children), | ||
locals: { options: options }, | ||
as: 'node' %> | ||
</ul> | ||
<% end %> | ||
<% end %> |
6 changes: 6 additions & 0 deletions
6
spec/dummy/app/views/alchemy/menus/footer_navigation/_wrapper.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<ul class="nav"> | ||
<%= render partial: options[:node_partial_name], | ||
collection: node.children.includes(:page, :children), | ||
locals: { options: options }, | ||
as: 'node' %> | ||
</ul> |
17 changes: 17 additions & 0 deletions
17
spec/dummy/app/views/alchemy/menus/main_navigation/_node.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<%= content_tag :li, class: ['nav-item', node.children.any? ? 'dropdown' : nil].compact do %> | ||
<%= link_to_if node.url, | ||
node.name, | ||
@preview_mode ? 'javascript: void(0)' : node.url, | ||
class: ['nav-link', current_page?(node.url) ? 'active' : nil].compact, | ||
title: node.title, | ||
target: node.external? ? '_blank' : nil, | ||
rel: node.nofollow? ? 'nofollow' : nil %> | ||
<% if node.children.any? %> | ||
<ul class="dropdown-menu"> | ||
<%= render partial: options[:node_partial_name], | ||
collection: node.children.includes(:page, :children), | ||
locals: { options: options }, | ||
as: 'node' %> | ||
</ul> | ||
<% end %> | ||
<% end %> |
6 changes: 6 additions & 0 deletions
6
spec/dummy/app/views/alchemy/menus/main_navigation/_wrapper.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<ul class="nav"> | ||
<%= render partial: options[:node_partial_name], | ||
collection: node.children.includes(:page, :children), | ||
locals: { options: options }, | ||
as: 'node' %> | ||
</ul> |