diff --git a/lib/templates/erb/controller/view.html.erb.tt b/lib/templates/erb/controller/view.html.erb.tt new file mode 100644 index 00000000..cc75205a --- /dev/null +++ b/lib/templates/erb/controller/view.html.erb.tt @@ -0,0 +1,3 @@ +<%- # License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later -%> +

<%= class_name %>#<%= @action %>

+

Find me in <%= @path %>

diff --git a/lib/templates/erb/mailer/layout.html.erb.tt b/lib/templates/erb/mailer/layout.html.erb.tt new file mode 100644 index 00000000..6e85ad7c --- /dev/null +++ b/lib/templates/erb/mailer/layout.html.erb.tt @@ -0,0 +1,14 @@ +<%- # License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later -%> + + + + + + + + + <%%= yield %> + + diff --git a/lib/templates/erb/mailer/layout.text.erb.tt b/lib/templates/erb/mailer/layout.text.erb.tt new file mode 100644 index 00000000..b4bae3aa --- /dev/null +++ b/lib/templates/erb/mailer/layout.text.erb.tt @@ -0,0 +1,2 @@ +<%- # License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later -%> +<%%= yield %> diff --git a/lib/templates/erb/mailer/view.html.erb.tt b/lib/templates/erb/mailer/view.html.erb.tt new file mode 100644 index 00000000..a430ca69 --- /dev/null +++ b/lib/templates/erb/mailer/view.html.erb.tt @@ -0,0 +1,6 @@ +<%- # License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later -%> +

<%= class_name %>#<%= @action %>

+ +

+ <%%= @greeting %>, find me in <%= @path %> +

diff --git a/lib/templates/erb/mailer/view.text.erb.tt b/lib/templates/erb/mailer/view.text.erb.tt new file mode 100644 index 00000000..4e048e81 --- /dev/null +++ b/lib/templates/erb/mailer/view.text.erb.tt @@ -0,0 +1,4 @@ +<%- # License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later -%> +<%= class_name %>#<%= @action %> + +<%%= @greeting %>, find me in <%= @path %> diff --git a/lib/templates/erb/scaffold/_form.html.erb.tt b/lib/templates/erb/scaffold/_form.html.erb.tt new file mode 100644 index 00000000..cca7eb77 --- /dev/null +++ b/lib/templates/erb/scaffold/_form.html.erb.tt @@ -0,0 +1,35 @@ +<%- # License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later -%> +<%%= form_with(model: <%= model_resource_name %>, local: true) do |form| %> + <%% if <%= singular_table_name %>.errors.any? %> +
+

<%%= pluralize(<%= singular_table_name %>.errors.count, "error") %> prohibited this <%= singular_table_name %> from being saved:

+ + +
+ <%% end %> + +<% attributes.each do |attribute| -%> +
+<% if attribute.password_digest? -%> + <%%= form.label :password %> + <%%= form.password_field :password %> +
+ +
+ <%%= form.label :password_confirmation %> + <%%= form.password_field :password_confirmation %> +<% else -%> + <%%= form.label :<%= attribute.column_name %> %> + <%%= form.<%= attribute.field_type %> :<%= attribute.column_name %> %> +<% end -%> +
+ +<% end -%> +
+ <%%= form.submit %> +
+<%% end %> diff --git a/lib/templates/erb/scaffold/edit.html.erb.tt b/lib/templates/erb/scaffold/edit.html.erb.tt new file mode 100644 index 00000000..cc231a9e --- /dev/null +++ b/lib/templates/erb/scaffold/edit.html.erb.tt @@ -0,0 +1,7 @@ +<%- # License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later -%> +

Editing <%= singular_table_name.titleize %>

+ +<%%= render 'form', <%= singular_table_name %>: @<%= singular_table_name %> %> + +<%%= link_to 'Show', @<%= singular_table_name %> %> | +<%%= link_to 'Back', <%= index_helper %>_path %> diff --git a/lib/templates/erb/scaffold/index.html.erb.tt b/lib/templates/erb/scaffold/index.html.erb.tt new file mode 100644 index 00000000..bfc59d77 --- /dev/null +++ b/lib/templates/erb/scaffold/index.html.erb.tt @@ -0,0 +1,32 @@ +<%- # License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later -%> +

<%%= notice %>

+ +

<%= plural_table_name.titleize %>

+ + + + +<% attributes.reject(&:password_digest?).each do |attribute| -%> + +<% end -%> + + + + + + <%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %> + +<% attributes.reject(&:password_digest?).each do |attribute| -%> + +<% end -%> + + + + + <%% end %> + +
<%= attribute.human_name %>
<%%= <%= singular_table_name %>.<%= attribute.name %> %><%%= link_to 'Show', <%= model_resource_name %> %><%%= link_to 'Edit', edit_<%= singular_route_name %>_path(<%= singular_table_name %>) %><%%= link_to 'Destroy', <%= model_resource_name %>, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%%= link_to 'New <%= singular_table_name.titleize %>', new_<%= singular_route_name %>_path %> diff --git a/lib/templates/erb/scaffold/new.html.erb.tt b/lib/templates/erb/scaffold/new.html.erb.tt new file mode 100644 index 00000000..9ed89340 --- /dev/null +++ b/lib/templates/erb/scaffold/new.html.erb.tt @@ -0,0 +1,6 @@ +<%- # License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later -%> +

New <%= singular_table_name.titleize %>

+ +<%%= render 'form', <%= singular_table_name %>: @<%= singular_table_name %> %> + +<%%= link_to 'Back', <%= index_helper %>_path %> diff --git a/lib/templates/erb/scaffold/show.html.erb.tt b/lib/templates/erb/scaffold/show.html.erb.tt new file mode 100644 index 00000000..e938f045 --- /dev/null +++ b/lib/templates/erb/scaffold/show.html.erb.tt @@ -0,0 +1,12 @@ +<%- # License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later -%> +

<%%= notice %>

+ +<% attributes.reject(&:password_digest?).each do |attribute| -%> +

+ <%= attribute.human_name %>: + <%%= @<%= singular_table_name %>.<%= attribute.name %> %> +

+ +<% end -%> +<%%= link_to 'Edit', edit_<%= singular_table_name %>_path(@<%= singular_table_name %>) %> | +<%%= link_to 'Back', <%= index_helper %>_path %> diff --git a/lib/templates/rails/assets/javascript.js b/lib/templates/rails/assets/javascript.js new file mode 100644 index 00000000..80d5ae04 --- /dev/null +++ b/lib/templates/rails/assets/javascript.js @@ -0,0 +1,3 @@ +// License: LGPL-3.0-or-later +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/lib/templates/rails/assets/stylesheet.css b/lib/templates/rails/assets/stylesheet.css new file mode 100644 index 00000000..72b4231a --- /dev/null +++ b/lib/templates/rails/assets/stylesheet.css @@ -0,0 +1,5 @@ +/* License: LGPL-3.0-or-later */ +/* + Place all the styles related to the matching controller here. + They will automatically be included in application.css. +*/ diff --git a/lib/templates/rails/scaffold_controller/api_controller.rb.tt b/lib/templates/rails/scaffold_controller/api_controller.rb.tt new file mode 100644 index 00000000..e8f83972 --- /dev/null +++ b/lib/templates/rails/scaffold_controller/api_controller.rb.tt @@ -0,0 +1,64 @@ +# frozen_string_literal: true + +# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later +<% 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: [:show, :update, :destroy] + + # GET <%= route_url %> + def index + @<%= plural_table_name %> = <%= orm_class.all(class_name) %> + + render json: <%= "@#{plural_table_name}" %> + end + + # GET <%= route_url %>/1 + def show + render json: <%= "@#{singular_table_name}" %> + end + + # POST <%= route_url %> + def create + @<%= singular_table_name %> = <%= orm_class.build(class_name, "#{singular_table_name}_params") %> + + if @<%= orm_instance.save %> + render json: <%= "@#{singular_table_name}" %>, status: :created, location: <%= "@#{singular_table_name}" %> + else + render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity + end + end + + # PATCH/PUT <%= route_url %>/1 + def update + if @<%= orm_instance.update("#{singular_table_name}_params") %> + render json: <%= "@#{singular_table_name}" %> + else + render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity + end + end + + # DELETE <%= route_url %>/1 + def destroy + @<%= orm_instance.destroy %> + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_<%= singular_table_name %> + @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %> + end + + # Only allow a trusted parameter "white list" through. + def <%= "#{singular_table_name}_params" %> + <%- if attributes_names.empty? -%> + params.fetch(:<%= singular_table_name %>, {}) + <%- else -%> + params.require(:<%= singular_table_name %>).permit(<%= attributes_names.map { |name| ":#{name}" }.join(', ') %>) + <%- end -%> + end +end +<% end -%> diff --git a/lib/templates/rails/scaffold_controller/controller.rb.tt b/lib/templates/rails/scaffold_controller/controller.rb.tt new file mode 100644 index 00000000..a25273b7 --- /dev/null +++ b/lib/templates/rails/scaffold_controller/controller.rb.tt @@ -0,0 +1,71 @@ +# frozen_string_literal: true + +# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later +<% 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: [:show, :edit, :update, :destroy] + + # GET <%= route_url %> + def index + @<%= plural_table_name %> = <%= orm_class.all(class_name) %> + end + + # GET <%= route_url %>/1 + def show + end + + # GET <%= route_url %>/new + def new + @<%= singular_table_name %> = <%= orm_class.build(class_name) %> + end + + # GET <%= route_url %>/1/edit + def edit + end + + # POST <%= route_url %> + def create + @<%= singular_table_name %> = <%= orm_class.build(class_name, "#{singular_table_name}_params") %> + + if @<%= orm_instance.save %> + redirect_to <%= redirect_resource_name %>, notice: <%= "'#{human_name} was successfully created.'" %> + else + render :new + end + end + + # PATCH/PUT <%= route_url %>/1 + def update + if @<%= orm_instance.update("#{singular_table_name}_params") %> + redirect_to <%= redirect_resource_name %>, notice: <%= "'#{human_name} was successfully updated.'" %> + else + render :edit + end + end + + # DELETE <%= route_url %>/1 + def destroy + @<%= orm_instance.destroy %> + redirect_to <%= index_helper %>_url, notice: <%= "'#{human_name} was successfully destroyed.'" %> + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_<%= singular_table_name %> + @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %> + end + + # Only allow a trusted parameter "white list" through. + def <%= "#{singular_table_name}_params" %> + <%- if attributes_names.empty? -%> + params.fetch(:<%= singular_table_name %>, {}) + <%- else -%> + params.require(:<%= singular_table_name %>).permit(<%= attributes_names.map { |name| ":#{name}" }.join(', ') %>) + <%- end -%> + end +end +<% end -%>