### Install templates-rails Gem
Source: https://github.com/ancez/templates-rails/blob/master/README.md
Instructions for installing the templates-rails gem for development environments. This involves adding the gem to your Gemfile and running bundle install, or installing it directly using the gem install command.
```ruby
gem 'templates-rails'
```
--------------------------------
### Create Templates Directory and Example Template
Source: https://context7.com/ancez/templates-rails/llms.txt
Set up the necessary directory structure and create an example .html.erb template file within app/views/templates. This template will be accessible via the gem's interface.
```bash
# Create templates directory
mkdir -p app/views/templates
# Create an example template
cat > app/views/templates/example.html.erb << 'EOF'
<% provide(:title, 'Example Template') %>
<%= link_to 'Home', root_path %>
<%= image_tag 'logo.png', alt: 'Logo', class: 'logo' %>
<%= content_tag :div, class: 'card-body' do %>
Card Title
Card content with Rails helpers.
<%= button_to 'Action', '#', method: :post, class: 'btn' %>
<% end %>
Current time: <%= Time.current.strftime('%Y-%m-%d %H:%M') %>
<%= javascript_include_tag 'application' %>
```
--------------------------------
### Nested Directory Structure for Templates in ERB
Source: https://context7.com/ancez/templates-rails/llms.txt
Illustrates organizing templates into nested directories, such as `app/views/templates/users/`. This allows for better structure based on features or sections. The example shows `profile.html.erb` and `settings.html.erb` within the `users` directory.
```erb
# app/views/templates/users/profile.html.erb
<% provide(:title, 'User Profile') %>
Homepage Content
This template uses a partial for navigation.
```
--------------------------------
### Test Navigation to Specific Template (RSpec)
Source: https://context7.com/ancez/templates-rails/llms.txt
This RSpec feature test confirms that users can navigate from the templates index page to a specific template's detail view by clicking a link. It checks for the presence of the expected content on the target template page.
```ruby
require 'rails_helper'
RSpec.describe 'Templates functionality', type: :feature do
it 'navigates to a specific template' do
visit '/templates'
click_link 'Example'
expect(page).to have_content 'Example Template'
end
end
```
--------------------------------
### Test Template Index Page Display (RSpec)
Source: https://context7.com/ancez/templates-rails/llms.txt
This RSpec feature test verifies that the main templates index page is displayed correctly and contains the expected 'Templates' heading. It ensures basic accessibility of the template listing.
```ruby
require 'rails_helper'
RSpec.describe 'Templates functionality', type: :feature do
it 'displays the templates index page' do
visit '/templates'
expect(page).to have_content 'Templates'
end
end
```
--------------------------------
### Template with Custom Application Layout Override
Source: https://context7.com/ancez/templates-rails/llms.txt
This section indicates the possibility of overriding the default application layout for specific templates. The code snippet itself is not provided, but the context implies that a template can specify a different layout using `render layout: '...'`.
```erb
# Example for overriding layout:
# render "templates/my_template", layout: 'custom_layout'
# Or within the template file itself, if the layout is specified in the controller.
```
--------------------------------
### Configure Parent Controller Inheritance
Source: https://context7.com/ancez/templates-rails/llms.txt
Set the parent controller for the Templates engine in the development environment configuration. This allows customization for standard Rails apps, apps without ApplicationController, or tenant-based apps with custom base controllers.
```ruby
# config/environments/development.rb
Rails.application.configure do
# For standard Rails apps
Templates.parent_controller = 'ApplicationController'
# For apps without ApplicationController
Templates.parent_controller = 'ActionController::Base'
# For tenant-based apps with custom base controller
Templates.parent_controller = 'TenantController'
end
```
--------------------------------
### Admin Dashboard View in ERB
Source: https://context7.com/ancez/templates-rails/llms.txt
Defines the structure for an admin dashboard using ERB. It sets page titles and layout overrides, includes a sidebar navigation, and displays a user data table. This view is intended to be rendered with a specific admin layout.
```erb
<% provide(:title, 'Admin Dashboard') %>
<% provide(:layout_override, 'admin') %>