trek 0.1.19 → 0.1.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/app/components/trek/dashboard/analytics_component/analytics_component.css +4 -0
  4. data/app/components/trek/dashboard/analytics_component/analytics_component.html.slim +2 -0
  5. data/app/components/trek/dashboard/analytics_component/analytics_component.js +1 -0
  6. data/app/components/trek/dashboard/analytics_component.rb +7 -0
  7. data/app/components/trek/form/actions_component.rb +1 -1
  8. data/app/components/trek/form/content_editor_component/extensions/image_block.js +1 -8
  9. data/app/components/trek/form/content_editor_component/extensions/prompts_block.js +1 -8
  10. data/app/components/trek/list/item_component.rb +2 -1
  11. data/app/controllers/concerns/trek/model.rb +15 -1
  12. data/app/controllers/concerns/trek/redirections.rb +1 -1
  13. data/app/controllers/concerns/trek/reorderable.rb +2 -2
  14. data/app/controllers/concerns/trek/scopes.rb +55 -0
  15. data/app/views/trek/shared/_resource_heading.html.slim +1 -1
  16. data/app/views/trek/shared/_resource_index_heading.html.slim +1 -1
  17. data/lib/generators/trek/scaffold_generator.rb +24 -6
  18. data/lib/generators/trek/templates/controllers/admin/scaffold_controller.rb.tt +6 -0
  19. data/lib/generators/trek/templates/controllers/admin/users_controller.rb +1 -1
  20. data/lib/generators/trek/templates/locales/scaffold/admin.en.yml.tt +1 -1
  21. data/lib/generators/trek/templates/locales/scaffold/admin.other.yml.tt +1 -1
  22. data/lib/generators/trek/templates/locales/scaffold/model.en.yml.tt +2 -2
  23. data/lib/generators/trek/templates/locales/scaffold/model.other.yml.tt +2 -2
  24. data/lib/generators/trek/templates/policies/admin/scaffold_policy.rb.tt +7 -1
  25. data/lib/generators/trek/templates/views/admin/fragments/_form.html.slim +1 -1
  26. data/lib/generators/trek/templates/views/admin/fragments/index.html.slim +1 -1
  27. data/lib/generators/trek/templates/views/admin/menu_nodes/_form.html.slim +1 -1
  28. data/lib/generators/trek/templates/views/admin/pages/_form.html.slim +1 -1
  29. data/lib/generators/trek/templates/views/admin/pages/index.html.slim +1 -1
  30. data/lib/generators/trek/templates/views/admin/scaffold/_form.html.slim.tt +1 -1
  31. data/lib/generators/trek/templates/views/admin/users/index.html.slim +1 -1
  32. data/lib/trek/version.rb +1 -1
  33. data/package.json +1 -1
  34. metadata +6 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c361aedf0c96319053cdbb1e2d80ac77248791c84fedd2f0bb49e89b3d6afa7f
4
- data.tar.gz: 40fd5afd6fa1cd82f8095e2164d46f5943c0a723fe79878e4046cb576bb3eba0
3
+ metadata.gz: 8836f5f71ee9aeae0475df30e1e941038aeac1d3ba5a1f0a8bc548ddf87cedff
4
+ data.tar.gz: 2b07e244708e2e9a6258d9d352f04fc03bba3777e11b2a6ae3a7ad7e0e100fd5
5
5
  SHA512:
6
- metadata.gz: 37c0db5305f16dfc336b2e9383bb03997dc6613c77a0c797648dd3a77ed2f0300028330b4eae72d2775dbfc407e260b3f8b8877cd3e0c3120b884447b53235cc
7
- data.tar.gz: 7a7d98baf92ad4bed55736607976a73af61696381b90252e3f0f63a691dfb31f5b959982c5570a452ec004199c92ea344a12116904049d7dba315c57c6d3b9ff
6
+ metadata.gz: 568c5f70e0482e4ef6c86e66d4ffe46bc5828848c28ec8646129468bbc4db60c362fb3ddd4bee9ba9e747fffc5d24385f3198876bc8a3dc9031658c3eb1dc380
7
+ data.tar.gz: 322f0ab2ab3fc8d3bef7cabc8fadbd750b43b790163e9abf915c7bb8766c594bec7161980695e020e6d0e8b7a3e8e4a6c47309edefea2a2df72bd1918a8ffe77
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- trek (0.1.19)
4
+ trek (0.1.20)
5
5
  action_policy (~> 0.6)
6
6
  actioncable
7
7
  acts_as_list (~> 1.1)
@@ -0,0 +1,4 @@
1
+ .root {
2
+ display: block;
3
+ max-width: 120rem;
4
+ }
@@ -0,0 +1,2 @@
1
+ div(class=root_class)
2
+ div(class=class_for("info")) = section
@@ -0,0 +1 @@
1
+ import "./analytics_component.css";
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Trek
4
+ class Dashboard::AnalyticsComponent < Trek::Component
5
+ renders_one :section, Trek::Dashboard::SectionComponent
6
+ end
7
+ end
@@ -14,7 +14,7 @@ module Trek
14
14
 
15
15
  with_button(
16
16
  text: helpers.t("admin.actions.delete"),
17
- to: [:admin, object],
17
+ to: [:admin, *helpers.model_element_route[0...-1], object],
18
18
  method: :delete,
19
19
  data: {
20
20
  turbo_confirm: helpers.t("admin.#{model_collection}.destroy.confirm")
@@ -48,14 +48,7 @@ export default Node.create({
48
48
  },
49
49
 
50
50
  addNodeView() {
51
- return ({
52
- editor,
53
- node,
54
- getPos,
55
- HTMLAttributes,
56
- decorations,
57
- extension,
58
- }) => {
51
+ return ({ node }) => {
59
52
  const dom = document.createElement("image-block");
60
53
  const params = attributesToParams(node.attrs);
61
54
 
@@ -45,14 +45,7 @@ export default Node.create({
45
45
  },
46
46
 
47
47
  addNodeView() {
48
- return ({
49
- editor,
50
- node,
51
- getPos,
52
- HTMLAttributes,
53
- decorations,
54
- extension,
55
- }) => {
48
+ return ({ node }) => {
56
49
  const dom = document.createElement("prompts-block");
57
50
  const params = attributesToParams(node.attrs);
58
51
 
@@ -27,8 +27,9 @@ module Trek
27
27
 
28
28
  def item_link
29
29
  [
30
- (action == :show) ? nil : action,
30
+ ((action == :show) ? nil : action),
31
31
  :admin,
32
+ *helpers.model_element_route[0...-1],
32
33
  item
33
34
  ].compact
34
35
  end
@@ -5,7 +5,7 @@ module Trek
5
5
  included do
6
6
  delegate :model_name, to: :model
7
7
 
8
- helper_attr :model, :model_name, :model_collection, :model_element, :model_intro
8
+ helper_attr :model, :model_name, :model_collection, :model_collection_route, :model_element, :model_element_route, :model_intro
9
9
  end
10
10
 
11
11
  def model
@@ -20,10 +20,24 @@ module Trek
20
20
  model_name.collection.to_sym
21
21
  end
22
22
 
23
+ # Returns model collection as an array of symbols for route building.
24
+ # For namespaced models like Missive::List, returns [:missive, :lists].
25
+ # For non-namespaced models like Page, returns [:pages].
26
+ def model_collection_route
27
+ model_name.collection.split("/").map(&:to_sym)
28
+ end
29
+
23
30
  def model_element
24
31
  model_name.element.to_sym
25
32
  end
26
33
 
34
+ # Returns model element as an array of symbols for route building.
35
+ # For namespaced models like Missive::List, returns [:missive, :list].
36
+ # For non-namespaced models like Page, returns [:page].
37
+ def model_element_route
38
+ model_name.element.split("/").map(&:to_sym)
39
+ end
40
+
27
41
  def model_intro(action: nil)
28
42
  action ||= @object&.new_record? ? "new" : "edit"
29
43
  t("admin.#{model_collection}.#{action}.intro")
@@ -17,7 +17,7 @@ module Trek
17
17
  end
18
18
 
19
19
  def success_redirect
20
- [:admin, model_collection]
20
+ [:admin, *model_collection_route]
21
21
  end
22
22
  end
23
23
  end
@@ -31,7 +31,7 @@ module Trek
31
31
  end
32
32
 
33
33
  def reorder_path
34
- [:reorder, :admin, model_collection]
34
+ [:reorder, :admin, *model_collection_route]
35
35
  end
36
36
 
37
37
  def reorder_params
@@ -39,7 +39,7 @@ module Trek
39
39
  end
40
40
 
41
41
  def reorder_success_redirect
42
- [:admin, model_collection]
42
+ [:admin, *model_collection_route]
43
43
  end
44
44
 
45
45
  def reorder_notice
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Trek
4
+ module Scopes
5
+ extend ActiveSupport::Concern
6
+
7
+ def apply_scopes(scope, filters)
8
+ return scope if filters.blank?
9
+
10
+ filters.each do |filter, value|
11
+ next if value.blank?
12
+
13
+ scope = scope.public_send(filter) if scope.respond_to?(filter)
14
+ end
15
+
16
+ scope
17
+ end
18
+
19
+ def apply_scopes!
20
+ @unscoped_objects = @objects
21
+ @objects = apply_scopes(@objects, params[:scopes])
22
+ scope_counts
23
+ end
24
+
25
+ included do
26
+ helper_method :available_scopes
27
+ helper_method :scope_params
28
+ helper_method :unscoped_objects
29
+ helper_method :scope_counts
30
+ end
31
+
32
+ def unscoped_objects
33
+ @unscoped_objects || @objects
34
+ end
35
+
36
+ def scope_counts
37
+ @scope_counts ||= begin
38
+ Prosopite.pause if defined?(Prosopite)
39
+ available_scopes.index_with do |scope|
40
+ unscoped_objects.except(:limit, :offset).public_send(scope).count
41
+ end
42
+ ensure
43
+ Prosopite.resume if defined?(Prosopite)
44
+ end
45
+ end
46
+
47
+ def available_scopes
48
+ []
49
+ end
50
+
51
+ def scope_params
52
+ params[:scopes]&.permit(*available_scopes)
53
+ end
54
+ end
55
+ end
@@ -4,7 +4,7 @@
4
4
  ) do |c|
5
5
  ruby:
6
6
  c.with_button(
7
- href: [:admin, model_collection],
7
+ href: [:admin, *model_collection_route],
8
8
  text: t("admin.actions.cancel"),
9
9
  )
10
10
 
@@ -27,7 +27,7 @@
27
27
 
28
28
  if allowed_to?(:new?, model)
29
29
  c.with_button(
30
- href: [:new, :admin, model_element],
30
+ href: [:new, :admin, *model_element_route],
31
31
  text: i18n_resource_label(:new, model),
32
32
  ) do |b|
33
33
  b.with_icon("trek/add")
@@ -32,13 +32,13 @@ module Trek
32
32
 
33
33
  def create_controller
34
34
  template "controllers/admin/scaffold_controller.rb",
35
- "app/controllers/admin/#{plural_name}_controller.rb"
35
+ "app/controllers/admin/#{namespaced_plural}_controller.rb"
36
36
  end
37
37
 
38
38
  def create_views
39
39
  %w[index edit new _form show].each do |view|
40
40
  template "views/admin/scaffold/#{view}.html.slim",
41
- "app/views/admin/#{plural_name}/#{view}.html.slim"
41
+ "app/views/admin/#{namespaced_plural}/#{view}.html.slim"
42
42
  end
43
43
  end
44
44
 
@@ -56,6 +56,12 @@ module Trek
56
56
  # post :reorder, on: :collection
57
57
  end
58
58
  RUBY
59
+
60
+ if model_namespaces.any?
61
+ # Wrap resources in nested namespaces for namespaced models
62
+ model_namespaces.each { |ns| route_code = "namespace :#{ns} do\n #{route_code.gsub("\n", "\n ")}\nend" }
63
+ end
64
+
59
65
  route route_code, namespace: :admin
60
66
  end
61
67
 
@@ -94,8 +100,8 @@ module Trek
94
100
  def cleanup
95
101
  return if I18n.available_locales.include?(:en)
96
102
 
97
- File.delete(model_locale_file(:en))
98
- File.delete(admin_locale_file(:en))
103
+ FileUtils.rm_f(model_locale_file(:en))
104
+ FileUtils.rm_f(admin_locale_file(:en))
99
105
  end
100
106
 
101
107
  private
@@ -147,11 +153,23 @@ module Trek
147
153
  end
148
154
 
149
155
  def model_locale_file(locale)
150
- "config/locales/models/#{singular_name}.#{locale}.yml"
156
+ "config/locales/models/#{file_path}.#{locale}.yml"
151
157
  end
152
158
 
153
159
  def admin_locale_file(locale)
154
- "config/locales/admin/#{singular_name}.#{locale}.yml"
160
+ "config/locales/admin/#{file_path}.#{locale}.yml"
161
+ end
162
+
163
+ # Returns namespace segments from file_path (e.g., ["missive"] for "missive/list")
164
+ def model_namespaces
165
+ file_path.split("/")[0...-1]
166
+ end
167
+
168
+ # Returns the pluralized path preserving namespaces (e.g., "missive/lists" for "missive/list")
169
+ def namespaced_plural
170
+ parts = file_path.split("/")
171
+ parts[-1] = parts[-1].pluralize
172
+ parts.join("/")
155
173
  end
156
174
  end
157
175
  end
@@ -1,4 +1,7 @@
1
1
  module Admin
2
+ <% model_namespaces.each do |ns| -%>
3
+ module <%= ns.camelize %>
4
+ <% end -%>
2
5
  class <%= controller_class_name %>Controller < Trek::ResourceController
3
6
  # include Trek::Pagination
4
7
 
@@ -8,4 +11,7 @@ module Admin
8
11
  <%= class_name %>
9
12
  end
10
13
  end
14
+ <% model_namespaces.each do |_ns| -%>
15
+ end
16
+ <% end -%>
11
17
  end
@@ -13,7 +13,7 @@ module Admin
13
13
 
14
14
  def success_redirect
15
15
  if allowed_to?(:index?, @object)
16
- [:admin, model_collection]
16
+ [:admin, *model_collection_route]
17
17
  elsif allowed_to?(:show?, @object)
18
18
  [:admin, @object]
19
19
  else
@@ -1,6 +1,6 @@
1
1
  en:
2
2
  admin:
3
- <%= plural_name %>:
3
+ <%= namespaced_plural %>:
4
4
  create:
5
5
  success: <%= human_name %> added
6
6
  destroy:
@@ -1,6 +1,6 @@
1
1
  <%= @locale %>:
2
2
  admin:
3
- <%= plural_name %>:
3
+ <%= namespaced_plural %>:
4
4
  create:
5
5
  success:
6
6
  destroy:
@@ -1,11 +1,11 @@
1
1
  en:
2
2
  activerecord:
3
3
  models:
4
- <%= singular_name %>:
4
+ <%= file_path %>:
5
5
  gender: 'n'
6
6
  one: <%= human_name %>
7
7
  other: <%= plural_name.humanize %>
8
8
  attributes:
9
- <%= singular_name %>:<%- attributes.each do |attr| %>
9
+ <%= file_path %>:<%- attributes.each do |attr| %>
10
10
  <%= attr.name %>: <%= attr.name.humanize -%>
11
11
  <% end %>
@@ -1,12 +1,12 @@
1
1
  <%= @locale %>:
2
2
  activerecord:
3
3
  models:
4
- <%= singular_name %>:
4
+ <%= file_path %>:
5
5
  gender: # "n", "m", "f"
6
6
  one:
7
7
  other:
8
8
  attributes:
9
- <%= singular_name %>:
9
+ <%= file_path %>:
10
10
  <%- attributes.each do |attr| -%>
11
11
  <%= attr.name %>:
12
12
  <%- end -%>
@@ -1,5 +1,8 @@
1
1
  module Admin
2
- class <%= class_name %>Policy < Trek::ResourcePolicy
2
+ <% model_namespaces.each do |ns| -%>
3
+ module <%= ns.camelize %>
4
+ <% end -%>
5
+ class <%= class_name.demodulize %>Policy < Trek::ResourcePolicy
3
6
  def index?
4
7
  user.privileged?
5
8
  end
@@ -36,4 +39,7 @@ module Admin
36
39
  relation.none
37
40
  end
38
41
  end
42
+ <% model_namespaces.each do |_ns| -%>
43
+ end
44
+ <% end -%>
39
45
  end
@@ -19,7 +19,7 @@
19
19
  = render Trek::Form::ActionsComponent.new do |c|
20
20
  ruby:
21
21
  c.with_button(
22
- href: [:admin, model_collection],
22
+ href: [:admin, *model_collection_route],
23
23
  text: t("admin.actions.cancel"),
24
24
  )
25
25
 
@@ -5,7 +5,7 @@
5
5
  ruby:
6
6
  if allowed_to?(:new?, model)
7
7
  c.with_button(
8
- href: [:new, :admin, model_element],
8
+ href: [:new, :admin, *model_element_route],
9
9
  text: i18n_resource_label(:new, model),
10
10
  ) do |b|
11
11
  b.with_icon("trek/add")
@@ -8,7 +8,7 @@
8
8
  = render Trek::Form::ActionsComponent.new do |c|
9
9
  ruby:
10
10
  c.with_button(
11
- href: [:admin, model_collection],
11
+ href: [:admin, *model_collection_route],
12
12
  text: t("admin.actions.cancel"),
13
13
  )
14
14
 
@@ -92,7 +92,7 @@
92
92
  = render Trek::Form::ActionsComponent.new do |c|
93
93
  ruby:
94
94
  c.with_button(
95
- href: [:admin, model_collection],
95
+ href: [:admin, *model_collection_route],
96
96
  text: t("admin.actions.cancel"),
97
97
  )
98
98
 
@@ -26,7 +26,7 @@
26
26
 
27
27
  if allowed_to?(:new?, model)
28
28
  c.with_button(
29
- href: [:new, :admin, model_element],
29
+ href: [:new, :admin, *model_element_route],
30
30
  text: i18n_resource_label(:new, model),
31
31
  ) do |b|
32
32
  b.with_icon("trek/add")
@@ -11,7 +11,7 @@
11
11
  = render Trek::Form::ActionsComponent.new do |c|
12
12
  ruby:
13
13
  c.with_button(
14
- href: [:admin, model_collection],
14
+ href: [:admin, *model_collection_route],
15
15
  text: t("admin.actions.cancel"),
16
16
  )
17
17
 
@@ -5,7 +5,7 @@
5
5
  ruby:
6
6
  if allowed_to?(:new?, model)
7
7
  c.with_button(
8
- href: [:new, :admin, model_element],
8
+ href: [:new, :admin, *model_element_route],
9
9
  text: i18n_resource_label(:new, model),
10
10
  ) do |b|
11
11
  b.with_icon("trek/add")
data/lib/trek/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Trek
4
- VERSION = "0.1.19"
4
+ VERSION = "0.1.20"
5
5
  end
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etaminstudio/trek",
3
- "version": "0.1.19",
3
+ "version": "0.1.20",
4
4
  "description": "A modern CMS for Ruby on Rails",
5
5
  "main": "app/javascript/trek.js",
6
6
  "repository": {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trek
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.19
4
+ version: 0.1.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mohamed Bengrich
@@ -503,6 +503,10 @@ files:
503
503
  - app/components/trek/button_group_component/button_group_component.css
504
504
  - app/components/trek/button_group_component/button_group_component.js
505
505
  - app/components/trek/component.rb
506
+ - app/components/trek/dashboard/analytics_component.rb
507
+ - app/components/trek/dashboard/analytics_component/analytics_component.css
508
+ - app/components/trek/dashboard/analytics_component/analytics_component.html.slim
509
+ - app/components/trek/dashboard/analytics_component/analytics_component.js
506
510
  - app/components/trek/dashboard/section_component.rb
507
511
  - app/components/trek/dashboard/section_component/section_component.css
508
512
  - app/components/trek/dashboard/section_component/section_component.html.slim
@@ -638,6 +642,7 @@ files:
638
642
  - app/controllers/concerns/trek/pagination.rb
639
643
  - app/controllers/concerns/trek/redirections.rb
640
644
  - app/controllers/concerns/trek/reorderable.rb
645
+ - app/controllers/concerns/trek/scopes.rb
641
646
  - app/controllers/trek/base_controller.rb
642
647
  - app/controllers/trek/panels/base_controller.rb
643
648
  - app/controllers/trek/panels/images_controller.rb