-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from RadiusNetworks/custom-templates
Radius Custom Templates
- Loading branch information
Showing
9 changed files
with
200 additions
and
1 deletion.
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
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 |
---|---|---|
@@ -1 +1,11 @@ | ||
require "radius/rails" | ||
|
||
module Radius | ||
module Rails | ||
class Railtie < ::Rails::Railtie | ||
config.app_generators do |g| | ||
g.templates.unshift File.expand_path('templates', __dir__) | ||
end | ||
end | ||
end | ||
end |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module Radius | ||
module Rails | ||
VERSION = "2.0.0" | ||
VERSION = "2.1.0" | ||
end | ||
end |
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,67 @@ | ||
# frozen_string_literal: true | ||
|
||
<% if namespaced? -%> | ||
require_dependency "<%= namespaced_path %>/application_controller" | ||
|
||
<% end -%> | ||
<% module_namespacing do -%> | ||
class <%= controller_class_name %>Controller < ApplicationController | ||
before_action :set_<%= singular_table_name %>, only: %i[show edit update destroy] | ||
|
||
def index | ||
@<%= plural_table_name %> = <%= singular_table_name.capitalize %>.accessible_by_user(current_user).all | ||
end | ||
|
||
def show | ||
end | ||
|
||
def new | ||
@<%= singular_table_name %> = <%= orm_class.build(class_name) %> | ||
end | ||
|
||
def edit | ||
end | ||
|
||
def create | ||
@<%= singular_table_name %> = <%= orm_class.build(class_name, "#{singular_table_name}_params") %> | ||
|
||
if @<%= orm_instance.save %> | ||
redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully created.'" %> | ||
else | ||
render :new | ||
end | ||
end | ||
|
||
def update | ||
if @<%= orm_instance.update("#{singular_table_name}_params") %> | ||
redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully updated.'" %> | ||
else | ||
render :edit | ||
end | ||
end | ||
|
||
def destroy | ||
@<%= orm_instance.destroy %>! | ||
redirect_to <%= index_helper %>_url, notice: <%= "'#{human_name} was successfully destroyed.'" %> | ||
end | ||
|
||
private | ||
|
||
def set_<%= singular_table_name %> | ||
@<%= singular_table_name %> = <%= singular_table_name.capitalize %>.accessible_by_user(current_user).find(params[:id]) | ||
end | ||
|
||
def <%= "#{singular_table_name}_params" %> | ||
<%- if attributes_names.empty? -%> | ||
params.fetch(:<%= singular_table_name %>, {}) | ||
<%- else -%> | ||
params.require(:<%= singular_table_name %>) | ||
.permit( | ||
<% attributes_names.each do |name| -%> | ||
:<%= name %>, | ||
<% end -%> | ||
) | ||
<%- end -%> | ||
end | ||
end | ||
<% end -%> |
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,37 @@ | ||
= form_for @<%= singular_table_name %> do |f| | ||
.row | ||
.col-sm-12.col-md-10.col-lg-8 | ||
.panel.panel-default | ||
|
||
.panel-body | ||
= render "layouts/partials/form_errors", resource: @<%= singular_table_name %> | ||
<% attributes.each do |attribute| -%> | ||
.form-group.has-feedback | ||
<% if attribute.password_digest? -%> | ||
= f.label :password | ||
= f.password_field :password, class: "form-control" | ||
.form-group.has-feedback | ||
= f.label :password_confirmation | ||
= f.password_field :password_confirmation, class: "form-control" | ||
<% else -%> | ||
= f.label :<%= attribute.column_name %> | ||
<% case attribute.field_type -%> | ||
<% when :check_box -%> | ||
.checkbox.c-checkbox.mt0 | ||
label | ||
= f.check_box :<%= attribute.column_name %>, class: 'form-control' | ||
span.fa.fa-check | ||
<% when :datetime_select -%> | ||
.datepicker.input-group.date | ||
= f.text_field :<%= attribute.column_name %>, class: 'form-control' | ||
span.input-group-addon | ||
span.fa.fa-calendar | ||
<% else -%> | ||
= f.<%= attribute.field_type %> :<%= attribute.column_name %>, class: "form-control" | ||
<% end -%> | ||
<% end -%> | ||
<% end -%> | ||
|
||
.panel-footer | ||
= f.submit class: "btn btn-sm pull-right btn-primary" | ||
= link_to 'Cancel', <%= index_helper %>_url, class: "btn btn-sm btn-default" |
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,10 @@ | ||
.content-heading | ||
| Edit <%= singular_table_name.titleize %> | ||
|
||
ol.breadcrumb | ||
li | ||
= link_to "<%= plural_table_name.titleize %>", <%= index_helper %>_url | ||
li | ||
= link_to "Back", @<%= singular_table_name %> | ||
|
||
= render partial: 'form' |
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,32 @@ | ||
.content-heading | ||
.btn-toolbar.pull-right | ||
= link_to 'New <%= singular_table_name.titleize %>', new_<%= singular_table_name %>_path, class: 'btn btn-sm btn-success', title: "Create new <%= singular_table_name %>" | ||
| <%= plural_table_name.titleize %> | ||
|
||
ol.breadcrumb | ||
li = link_to '<%= plural_table_name.titleize %>', <%= index_helper %>_path | ||
|
||
.row | ||
.col-lg-12 | ||
.panel.panel-default | ||
.panel-heading | ||
.table-responsive | ||
table.table.table-hover.table-generic | ||
thead | ||
tr | ||
<% attributes.reject(&:password_digest?).each do |attribute| -%> | ||
th <%= attribute.human_name %> | ||
<% end -%> | ||
th | ||
th | ||
th | ||
|
||
tbody | ||
- @<%= plural_table_name %>.each do |<%= singular_table_name %>| | ||
tr | ||
<% attributes.reject(&:password_digest?).each do |attribute| -%> | ||
td = <%= singular_table_name %>.<%= attribute.name %> | ||
<% end -%> | ||
td = link_to 'Show', <%= singular_table_name %> | ||
td = link_to 'Edit', edit_<%= singular_table_name %>_path(<%= singular_table_name %>) | ||
td = link_to 'Destroy', <%= singular_table_name %>, method: :delete, data: { confirm: 'Are you sure?' } |
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,8 @@ | ||
.content-heading | ||
| New <%= singular_table_name.titleize %> | ||
|
||
ol.breadcrumb | ||
li | ||
= link_to "<%= plural_table_name.titleize %>", <%= index_helper %>_url | ||
|
||
= render partial: 'form' |
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,18 @@ | ||
.content-heading | ||
.btn-toolbar.pull-right | ||
= link_to "Edit", edit_<%= singular_table_name %>_path(@<%= singular_table_name %>), class: 'btn btn-sm btn-info' | ||
| <%= singular_table_name.titleize %> | ||
|
||
ol.breadcrumb | ||
li | ||
= link_to "<%= plural_table_name.titleize %>", <%= index_helper %>_url | ||
|
||
.row | ||
.col-sm-12.col-md-10.col-lg-8 | ||
.panel.panel-default | ||
.panel-body | ||
<% attributes.each do |attribute| -%> | ||
p | ||
strong <%= attribute.human_name %>: | ||
= @<%= singular_table_name %>.<%= attribute.name %> | ||
<% end -%> |