Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
rolemodel_rails (0.22.0)
rolemodel_rails (0.23.0)

GEM
remote: https://rubygems.org/
Expand Down
4 changes: 2 additions & 2 deletions lib/generators/rolemodel/all_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ def run_all_the_generators
generate 'rolemodel:saas:all'
generate 'rolemodel:mailers'
generate 'rolemodel:linters:all'
generate 'rolemodel:modals'
generate 'rolemodel:ui_components:all'
generate 'rolemodel:source_map'
generate 'rolemodel:good_job'
generate 'rolemodel:kaminari'
generate 'rolemodel:editors'
generate 'rolemodel:tailored_select'
# generate 'rolemodel:tailored_select' # Not production ready
generate 'rolemodel:lograge'
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rolemodel/saas/devise/devise_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def modify_existing_files
inject_into_file 'app/models/user.rb', after: /devise\s+:.*\n.*\n/ do
optimize_indentation <<~'RUBY', 2

enum role: { user: 'user', admin: 'admin' }
enum :role, { user: 'user', admin: 'admin' }

belongs_to :organization, inverse_of: :users
accepts_nested_attributes_for :organization
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
.app__login
= simple_form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post, class: 'card card--login' }) do |f|
.card__header
= image_tag asset_path('logo.png') # TODO: Replace with your own logo
/ TODO: Replace with your own logo
= image_tag asset_path('/logo.png')
.card__body
= f.input :email, required: true, autofocus: true, autocomplete: "email", input_html: { value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) }
.card__footer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
.app__login
= simple_form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put, class: 'card card--login' }) do |f|
.card__header
= image_tag asset_path('logo.png') # TODO: Replace with your own logo
/ TODO: Replace with your own logo
= image_tag asset_path('/logo.png')
.card__body
= f.hidden_field :reset_password_token
= f.input :password, label: t(".new_password", default: "New password"), required: true, autofocus: true, autocomplete: "new-password", hint: (@minimum_password_length ? t("devise.shared.minimum_password_length", count: @minimum_password_length, default: "(%{count} characters minimum)") : nil)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
.app__login
= simple_form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post, class: 'card card--login' }) do |f|
.card__header
= image_tag asset_path('logo.png') # TODO: Replace with your own logo
/ TODO: Replace with your own logo
= image_tag asset_path('/logo.png')
.card__body
= f.input :email, required: true, autofocus: true, autocomplete: "email"
.card__footer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
.app__login
= simple_form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put, class: 'card card--login' }) do |f|
.card__header
= image_tag asset_path('logo.png') # TODO: Replace with your own logo
/ TODO: Replace with your own logo
= image_tag asset_path('/logo.png')
.card__body
= f.input :first_name, required: true, autofocus: true, autocomplete: "first_name"
= f.input :last_name, required: true, autocomplete: "last_name"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
.app__login
= simple_form_for(resource, as: resource_name, url: registration_path(resource_name), html: { class: 'card card--login' }) do |f|
.card__header
= image_tag asset_path('logo.png') # TODO: Replace with your own logo
/ TODO: Replace with your own logo
= image_tag asset_path('/logo.png')
.card__body
= f.input :first_name, required: true, autofocus: true
= f.input :last_name, required: true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
.app__login
= simple_form_for(resource, as: resource_name, url: session_path(resource_name), html: { class: 'card card--login' }) do |f|
.card__header
= image_tag asset_path('logo.png') # TODO: Replace with your own logo
/ TODO: Replace with your own logo
= image_tag asset_path('/logo.png')
.card__body
= f.input :email, required: true, autofocus: true, autocomplete: "email"
= f.input :password, required: true, autocomplete: "current-password"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
.app__login
= simple_form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post, class: 'card card--login' }) do |f|
.card__header
= image_tag asset_path('logo.png') # TODO: Replace with your own logo
/ TODO: Replace with your own logo
= image_tag asset_path('/logo.png')
.card__body
= f.input :email, autofocus: true, autocomplete: "email"
.card__footer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ def add_files
directory 'app/inputs'
copy_file 'config/initializers/simple_form.rb'
copy_file 'config/locales/simple_form.en.yml'
copy_file 'lib/templates/slim/scaffold/_form.html.slim'

# Because directory 'lib/templates/slim/scaffold' will try to parse the
# template files rather than just copy them.
Pathname.new(self.class.source_root).glob('lib/templates/slim/scaffold/*.tt').each do |tt|
copy_file tt, tt.relative_path_from(self.class.source_root)
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
config.boolean_style = :inline

# Default class for buttons
config.button_class = 'btn'
config.button_class = 'btn btn--primary'

# Method used to tidy up errors. Specify any Rails Array method.
# :first lists the first message for each field.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
-# locals: (<%= singular_table_name %>:)

= simple_form_for(@<%= singular_table_name %>) do |f|
= f.error_notification
= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present?
Expand All @@ -6,5 +8,5 @@
= f.<%= attribute.reference? ? :association : :input %> :<%= attribute.name %>
<%- end -%>

.form__actions
.flex.justify-end
= f.button :submit
4 changes: 4 additions & 0 deletions lib/generators/rolemodel/slim/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
## What you get

* [Slim](https://github.com/slim-template/slim)
* [Slim Rails](https://github.com/slim-template/slim-rails)
* Slim scaffold generation templates

Adds template files for use when running the rails scaffold command. E.G. `rails generate scaffold demo name:string description:string`. This will generate slim files utilizing Optics styling for the basic CRUD pages. Your app can further customize them by editing the `.tt` files in `lib/templates/slim/scaffold`
12 changes: 12 additions & 0 deletions lib/generators/rolemodel/slim/slim_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,21 @@ def add_slim
bundle_command 'add slim'
end

def add_slim_rails
bundle_command 'add slim-rails'
end

def replace_erb_layout
remove_file 'app/views/layouts/application.html.erb'
template 'app/views/layouts/application.html.slim'
end

def copy_templates
# Because directory 'lib/templates/slim/scaffold' will try to parse the
# template files rather than just copy them.
Pathname.new(self.class.source_root).glob('lib/templates/slim/scaffold/*.tt').each do |tt|
copy_file tt, tt.relative_path_from(self.class.source_root)
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
- content_for :title, "Editing <%= human_name.downcase %>"

nav.breadcrumbs.breadcrumbs--large.margin-y-md
= link_to "<%= human_name.pluralize %>", <%= index_helper(type: :path) %>, class: "breadcrumbs__link"
.breadcrumbs__separator = icon('chevron_right')
= link_to "<%= human_name.pluralize %>", <%= model_resource_name(prefix: "@") %>, class: "breadcrumbs__link"
.breadcrumbs__separator = icon('chevron_right')
span.breadcrumbs__text Editing <%= human_name.downcase %>

.card
.card__header
h1 Editing <%= human_name.downcase %>
.divider
.card__body
= render "form", <%= singular_table_name %>: @<%= singular_table_name %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
- content_for :title, "<%= human_name.pluralize %>"

header.content-header
.content-header__details
h1.content-header__title <%= human_name.pluralize %>

.content-header__aside
= link_to <%= new_helper(type: :path) %>, class: 'btn btn--primary' do
= icon('add')
| New <%= human_name.downcase %>

.flex.flex-col.gap-md#<%= plural_table_name %>
= render @<%= plural_table_name %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
- content_for :title, "New <%= human_name.downcase %>"

nav.breadcrumbs.breadcrumbs--large.margin-y-md
= link_to "<%= human_name.pluralize %>", <%= index_helper(type: :path) %>, class: "breadcrumbs__link"
.breadcrumbs__separator = icon('chevron_right')
span.breadcrumbs__text New <%= human_name.downcase %>

.card
.card__header
h1 New <%= human_name.downcase %>
.divider
.card__body
= render "form", <%= singular_table_name %>: @<%= singular_table_name %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-# locals: (<%= singular_table_name %>:)

.card.card--padded id=dom_id(<%= singular_name %>)
.flex.items-center.justify-between
.text-pair
span.text-pair__title = <%= singular_table_name %>.name

= link_to <%= singular_name %>, class: "btn btn--small btn--icon btn--pill btn--no-border" do
= icon('chevron_right')
span.sr-only View <%= human_name.downcase %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
nav.breadcrumbs.breadcrumbs--large.margin-y-md
= link_to "<%= human_name.pluralize %>", <%= index_helper(type: :path) %>, class: "breadcrumbs__link"
.breadcrumbs__separator = icon('chevron_right')
span.breadcrumbs__text = @<%= singular_table_name %>.name

header.content-header
.content-header__details
h1.content-header__title = @<%= singular_table_name %>.name

.content-header__aside
= link_to <%= edit_helper(type: :path) %>, class: 'btn btn--icon' do
= icon('edit')
span.sr-only Edit <%= human_name.downcase %>

= button_to @<%= singular_table_name %>, form: { data: { turbo_confirm: 'Are you sure?' } }, class: "btn btn--destructive btn--icon", method: :delete do
= icon('delete')
span.sr-only Destroy this <%= human_name.downcase %>

.flex.flex-col.gap-md
<% attributes.reject(&:password_digest?).each do |attribute| -%>
.text-pair.text-pair--inline
span.text-pair__title <%= attribute.human_name %>:
span.text-pair__subtitle
<% if attribute.attachment? -%>
= link_to @<%= singular_name %>.<%= attribute.column_name %>.filename, <%= singular_name %>.<%= attribute.column_name %> if <%= singular_name %>.<%= attribute.column_name %>.attached?
<% elsif attribute.attachments? -%>
<%% @<%= singular_name %>.<%= attribute.column_name %>.each do |<%= attribute.singular_name %>| %>
div = link_to <%= attribute.singular_name %>.filename, <%= attribute.singular_name %>
<%% end %>
<% else -%>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to take rich text into account here and in the form

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just copied the default rails scaffold and adapted to slim. https://github.com/rails/rails/blob/main/railties/lib/rails/generators/erb/scaffold/templates/partial.html.erb.tt

Could be a future improvement

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My expectation is that every project is going to want to customize these templates immediately. But also that over time with lots of use, we'll find commonality to upstream.

= @<%= singular_name %>.<%= attribute.column_name %>
<% end -%>
<% end -%>
2 changes: 1 addition & 1 deletion lib/generators/rolemodel/ui_components/all_generator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Rolemodel
module Saas
module UiComponents
class AllGenerator < Rails::Generators::Base
source_root File.expand_path('templates', __dir__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
.confirm-dialog__footer
button#confirm-cancel.confirm-cancel.btn
| Cancel
button#confirm-accept.btn-destructive
button#confirm-accept.btn.btn--destructive
| Yes, I'm Sure
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
nav.navbar.navbar--primary
= link_to root_path, class: "navbar__brand" do
= image_tag "logo.png", alt: "Logo", class: "navbar__logo"
= image_tag "/logo.png", alt: "Logo", class: "navbar__logo"

- if user_signed_in?
.navbar__content.navbar__content--justify-start
Expand Down
2 changes: 1 addition & 1 deletion lib/rolemodel_rails/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module RolemodelRails
VERSION = '0.22.0'
VERSION = '0.23.0'
end