Skip to content

Commit

Permalink
[#492] Update template code and slim template index file
Browse files Browse the repository at this point in the history
  • Loading branch information
khangbui22 committed Mar 6, 2024
1 parent 56bd163 commit 6742028
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .template/addons/crud/lib/template.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

def copy_template_files
copy_non_tt_files
copy_tt_files
end

def copy_non_tt_files
# The reason we are excluding .tt files is because
# this directory method will actually apply the template and remove the .tt extension in the destination
directory 'lib/templates', exclude_pattern: /.*\.tt$/
end

def copy_tt_files
src_path = File.join(__dir__, 'templates')
dst_path = 'lib/templates'

Dir.glob("#{src_path}/**/*.tt").sort.each do |file_source|
relative_path = file_source.gsub("#{src_path}/", "")

copy_file(file_source, File.join(dst_path, relative_path))
end
end

copy_template_files
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
h1 <%= human_name.pluralize %>

#<%= plural_table_name %>
table.table.table-hover.table-responsive
thead
tr
<% attributes.each do |attribute| -%>
th <%= attribute.human_name %>
<% end -%>
th colspan="3"
tbody
- @<%= plural_table_name %>.each do |<%= singular_table_name %>|
tr
<% attributes.each do |attribute| -%>
td = <%= singular_table_name %>.<%= attribute.name %>
<% end -%>
td = link_to 'Show', <%= singular_table_name %>, class: 'btn btn-info'
td = link_to 'Edit', edit_<%= singular_table_name %>_path(<%= singular_table_name %>), class: 'btn btn-primary'
td = link_to 'Destroy', <%= singular_table_name %>, data: { turbo_method: :delete, confirm: 'Are you sure' }, class: 'btn btn-danger'

= link_to "New <%= human_name.downcase %>", <%= new_helper(type: :path) %>, class: 'btn btn-success'
2 changes: 2 additions & 0 deletions .template/addons/crud/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@
@import 'layouts';
SCSS
end

apply 'lib/template.rb'
4 changes: 4 additions & 0 deletions .template/spec/addons/variants/web/crud/template_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@
it 'creates app/views/layouts/application.html.slim' do
expect(file('app/views/layouts/application.html.slim')).to exist
end

it 'creates lib/templates/slim/scaffold/index.html.slim' do
expect(file('lib/templates/slim/scaffold/index.html.slim')).to exist
end
end

0 comments on commit 6742028

Please sign in to comment.