standard_view 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d77953a7b6174e787d23b7365043de5d66d6da132966c8cff633baaf34816c1e
4
- data.tar.gz: 4ae2d31cdef290183334c5c5eec4f99c4354f25cafbe597c8d64147fdc3d2815
3
+ metadata.gz: 7aa2ea213099a10dc4cbc6ee2569b5ae9ee6f5f1241a2400fab425f36e045e07
4
+ data.tar.gz: a7bbfbdee602ab554a91fda869ff2f08f2fe3077260ca473eb967d134a72a683
5
5
  SHA512:
6
- metadata.gz: a6da9eb73ba75e2bf14c712ce20ef7ea477ddd0a104eeeea137e892ade3aad976941a6bf38ffcca7306d4dcba545e6de23aeb35ad5162e8d561eb4751e694e8b
7
- data.tar.gz: 27ec1334228e8dd1d56490fb40ec330f667c62a7972ad4011d9192607a156de02b3e7584170674e152c2defce97234a007ccac42ef1cc9c8d45bd6ae5a88fb59
6
+ metadata.gz: 99e998104b6fb9a16934278c777be8cb0d04e971271336b99cd5d7d68d698cc9791100c557c1337aa54cf9ce6f5e21045e121adb77369a54f0ff5152a36f569a
7
+ data.tar.gz: 01f5ac80bcd913f0e404362996f208046aea18284593df75f8200342d54c11cb349a8b576e4ff8b8b3c1e1504a1d39beb470a5fa1c2fdcc7375d0cd6a61d9a36
@@ -6,7 +6,14 @@ module StandardView
6
6
  ActiveSupport::StringInquirer.new action_name
7
7
  end
8
8
 
9
- def active_for(options = {})
9
+ def actionable_name
10
+ return "new" if action_name == "create"
11
+ return "edit" if action_name == "update"
12
+
13
+ action_name
14
+ end
15
+
16
+ def active_for(**options)
10
17
  "active" if on_page?(options)
11
18
  end
12
19
 
@@ -18,17 +25,16 @@ module StandardView
18
25
 
19
26
  def icon_for(reference, spin: false)
20
27
  reference = reference.icon if reference.respond_to?(:icon)
21
- definition = if reference.nil?
22
- {}
23
- elsif reference.respond_to?(:to_h)
24
- reference.to_h
25
- else
26
- I18n.t("icons.#{reference}", default: nil) || reference
27
- end
28
+ definition = icon_definition_for_reference(reference)
29
+ icon_tag(definition[:name], definition[:style], spin: spin)
30
+ end
28
31
 
32
+ def icon_definition_for_reference(reference)
33
+ definition = reference.to_h if reference.respond_to?(:to_h)
34
+ definition ||= I18n.t("icons.#{reference}", default: nil) || reference if reference.present?
35
+ definition ||= {}
29
36
  definition = { name: definition } if definition.present? && !definition.respond_to?(:fetch)
30
-
31
- icon_tag(definition[:name], definition[:style], spin: spin)
37
+ definition
32
38
  end
33
39
 
34
40
  def current_page
@@ -38,5 +44,13 @@ module StandardView
38
44
  def icon_tag(name = nil, style = nil, spin: false)
39
45
  content_tag(:i, "", class: "fa#{style || "s"} fa-#{name || "question"} #{"fa-spin" if spin}")
40
46
  end
47
+
48
+ def link_to_destroy_with_confirmation_for_record(record, extra_classes: "")
49
+ link_to t("common.destroy"),
50
+ record,
51
+ class: "btn btn-danger #{extra_classes}",
52
+ method: :delete,
53
+ data: { confirm: t("common.confirm_destroy") }
54
+ end
41
55
  end
42
56
  end
@@ -1,18 +1,21 @@
1
1
  <% cache material do %>
2
+ <% material_law = law(material) %>
3
+
4
+ <% unless content_for?(:attributes_action) %>
5
+ <% content_for(:attributes_action) do %>
6
+ <% if material_law.edit? %>
7
+ <%= link_to t("common.edit"), { action: :edit }, class: "btn btn-primary btn-sm float-right" %>
8
+ <% elsif material_law.destroy? %>
9
+ <%= link_to_destroy_with_confirmation_for_record(material, extra_classes: "btn-sm float-right") %>
10
+ <% end %>
11
+
12
+ <%= content_for(:extra_attributes_action) if content_for?(:extra_attributes_action) %>
13
+ <% end %>
14
+ <% end %>
15
+
2
16
  <div class="card">
3
17
  <div class="card-header">
4
- <%# if content_for?(:attributes_action) %>
5
- <%#= content_for(:attributes_action) %>
6
- <%# else %>
7
- <%# if controller.action_methods.include?("edit") && (!record.respond_to?(:editable?) || record.editable?) %>
8
- <%#= link_to t("edit"), { action: :edit }, class: "btn btn-primary btn-sm float-right" %>
9
- <%# elsif controller.action_methods.include? "destroy" %>
10
- <%# if (!record.respond_to?(:destroyable?) || record.destroyable?) %>
11
- <%#= link_to t("destroy"), record, class: "btn btn-danger btn-sm float-right", method: :delete, data: { confirm: t("confirm_destroy") } %>
12
- <%# end %>
13
- <%# end %>
14
- <%#= content_for(:extra_attributes_action) if content_for?(:extra_attributes_action) %>
15
- <%# end %>
18
+ <%= content_for(:attributes_action) %>
16
19
 
17
20
  <h4 class="mb-0"><%= t(".title") %></h4>
18
21
  </div>
@@ -0,0 +1 @@
1
+ <%= render "standard_view/edit", record: @record %>
@@ -0,0 +1 @@
1
+ <%= render "standard_view/new", record: @record %>
@@ -0,0 +1,15 @@
1
+ <%# For the good-spirited and impossibly lazy developer, we attempt to jump-start with no code, assuming conventions. %>
2
+ <% if local_assigns[:material].nil? %>
3
+ <% record = "#{controller_name.singularize.camelize}".constantize.find(params[:id]) if local_assigns[:record].nil? %>
4
+ <% material = Material::Base.for(record) %>
5
+ <% end %>
6
+
7
+ <%# Title must remain outside the cache block or it will not be assigned properly (since it affects the page layout) %>
8
+ <% content_for(:title) { material.title } %>
9
+ <%= content_tag :main, id: "#{material.parameterized_title}-edit", class: "container" do %>
10
+ <header>
11
+ <%= render "standard_view/breadcrumbs", material: material %>
12
+ </header>
13
+
14
+ <%= render "standard_view/model_form", material: material %>
15
+ <% end %>
@@ -37,8 +37,8 @@
37
37
  <header>
38
38
  <%= render "standard_view/breadcrumbs", material: list if list.parent? %>
39
39
 
40
- <% if on_page?(action: :index) %>
41
- <%= link_to t("common.new"), { action: :new }, class: "btn btn-primary btn-lg float-right" if list_law.new? %>
40
+ <% if on_page?(action: :index) && list_law.new? %>
41
+ <%= link_to t("common.new"), { action: :new }, class: "btn btn-primary btn-lg float-right" %>
42
42
  <% end %>
43
43
 
44
44
  <%= content_tag(:h5, class: "text-muted") { heading_for_model(list.parent) } if list.parent? %>
@@ -0,0 +1,27 @@
1
+ <% material_law = law(material) %>
2
+ <%= simple_form_for [ material.parent, material ], wrapper: :horizontal_form do |form| %>
3
+ <div class="card">
4
+ <div class="card-header">
5
+ <h4 class="mb-0"><%= t(".#{actionable_name}.title", title: material.title) %></h4>
6
+ </div>
7
+ <div class="card-body">
8
+ <% if lookup_context.template_exists?("form_fields", controller_name, true) %>
9
+ <%= render "form_fields", form: form %>
10
+ <% end %>
11
+
12
+ <% if lookup_context.template_exists?("#{actionable_name}_form_fields", controller_name, true) %>
13
+ <%= render "#{actionable_name}_form_fields", form: form %>
14
+ <% end %>
15
+ </div>
16
+ <div class="card-footer">
17
+ <div class="row">
18
+ <div class="col-6">
19
+ <%= link_to_destroy_with_confirmation_for_record(material) if material.persisted? && material_law.destroy? %>
20
+ </div>
21
+ <div class="col-6 text-right">
22
+ <%= form.button :submit, class: "btn-primary" %>
23
+ </div>
24
+ </div>
25
+ </div>
26
+ </div>
27
+ <% end %>
@@ -0,0 +1,15 @@
1
+ <%# For the good-spirited and impossibly lazy developer, we attempt to jump-start with no code, assuming conventions. %>
2
+ <% if local_assigns[:material].nil? %>
3
+ <% record = "#{controller_name.singularize.camelize}".constantize.new if local_assigns[:record].nil? %>
4
+ <% material = Material::Base.for(record) %>
5
+ <% end %>
6
+
7
+ <%# Title must remain outside the cache block or it will not be assigned properly (since it affects the page layout) %>
8
+ <% content_for(:title) { material.title } %>
9
+ <%= content_tag :main, id: "#{material.parameterized_title}-new", class: "container" do %>
10
+ <header>
11
+ <%= render "standard_view/breadcrumbs", material: material %>
12
+ </header>
13
+
14
+ <%= render "standard_view/model_form", material: material %>
15
+ <% end %>
@@ -1,12 +1,28 @@
1
1
  en:
2
2
  common:
3
3
  new: New
4
+ edit: Edit
4
5
  overview: Overview
6
+ destroy: Destroy
7
+ confirm_destroy: Are you sure you want to destroy this? This cannot be undone!
8
+ record_created: "%{model_name} created successfully."
9
+ record_updated: "%{model_name} updated successfully."
10
+ record_destroyed: "%{model_name} destroyed successfully."
11
+ error_destroying_record: "%{model_name} could not be destroyed!"
5
12
  application:
6
13
  title: Example Title
7
14
  separator: "|"
8
15
  brand: Example Brand
9
16
  attributes_card:
10
17
  title: Attributes
18
+ standard_view:
19
+ paginated_collection:
20
+ empty: There are no records.
21
+ filtered_out: There are no records matching the current filter.
22
+ model_form:
23
+ new:
24
+ title: New %{title}
25
+ edit:
26
+ title: Edit %{title}
11
27
  icons:
12
28
  masthead_nav_menu: user
@@ -0,0 +1,9 @@
1
+ en:
2
+ simple_form:
3
+ "yes": "Yes"
4
+ "no": "No"
5
+ required:
6
+ text: required
7
+ mark: '*'
8
+ error_notification:
9
+ default_message: "Please review the problems below:"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StandardView
4
- VERSION = "0.1.4"
4
+ VERSION = "0.1.5"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: standard_view
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Garside
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-10 00:00:00.000000000 Z
11
+ date: 2020-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -30,7 +30,7 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.3.2
33
+ version: 0.3.4
34
34
  - - "<"
35
35
  - !ruby/object:Gem::Version
36
36
  version: '1.0'
@@ -40,7 +40,7 @@ dependencies:
40
40
  requirements:
41
41
  - - ">="
42
42
  - !ruby/object:Gem::Version
43
- version: 0.3.2
43
+ version: 0.3.4
44
44
  - - "<"
45
45
  - !ruby/object:Gem::Version
46
46
  version: '1.0'
@@ -288,14 +288,19 @@ files:
288
288
  - app/views/application/_standard_stylesheets.html.erb
289
289
  - app/views/application/_stylesheet_font_awesome.html.erb
290
290
  - app/views/application/_stylesheets.html.erb
291
+ - app/views/application/edit.html.erb
291
292
  - app/views/application/index.html.erb
293
+ - app/views/application/new.html.erb
292
294
  - app/views/application/show.html.erb
293
295
  - app/views/layouts/standard_view/application.html.erb
294
296
  - app/views/standard_view/_breadcrumbs.html.erb
297
+ - app/views/standard_view/_edit.html.erb
295
298
  - app/views/standard_view/_index.html.erb
296
299
  - app/views/standard_view/_list_item.html.erb
300
+ - app/views/standard_view/_model_form.html.erb
297
301
  - app/views/standard_view/_navigation_aside.html.erb
298
302
  - app/views/standard_view/_navigation_tabs.html.erb
303
+ - app/views/standard_view/_new.html.erb
299
304
  - app/views/standard_view/_page_content.html.erb
300
305
  - app/views/standard_view/_paginated_collection.html.erb
301
306
  - app/views/standard_view/_show.html.erb
@@ -304,6 +309,7 @@ files:
304
309
  - config/initializers/simple_form_bootstrap.rb
305
310
  - config/initializers/will_paginate.rb
306
311
  - config/locales/en.yml
312
+ - config/locales/simple_form.en.yml
307
313
  - config/routes.rb
308
314
  - lib/standard_view.rb
309
315
  - lib/standard_view/engine.rb