tramway 1.0.1.1 → 1.0.1.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f08c30e491a7109c31b9ba788837d8430b259fda97062dcc4c2ae1bc8eaeb8aa
4
- data.tar.gz: ffebea9b1cbf0f4742e1b47731364883eef45da38704f6c02d35b840e71512e9
3
+ metadata.gz: 63be607c08e52f57b726d9f5c84f719febc22e35c0fb5d711f4c855268917203
4
+ data.tar.gz: 004a821c356a9f2e0e9503ddef030b3502510b4d9d9d72fe44ac1725443ee4b6
5
5
  SHA512:
6
- metadata.gz: 9b26e6aaaf7cbc5ed801bb1e8ab5167b639d9b39e3a6b670f22fe6754d7551d4a99d4f831e288066dafce3bd97cc92dc4ce45fa260d776bdd1f342710e01d907
7
- data.tar.gz: a6f348d9c58be6600540135dd3819832ccedbd86594c2dada9017833b0a9bc1a67e5e7297d8758cfcbfcdbcfee3226e7de28744674e50793faff94c99b05984b
6
+ metadata.gz: 0c53956b38f0110ea92c4d39e6c97e932534276a1d4d7cb11ca9087910ac4659861f3743c87416f480e57f5a3df3639434c7a5b7e921b80098e3efbf01b42c5a
7
+ data.tar.gz: b179d2f0c46930bdab407ac94a99f0eb33f361eb0833850ede97a6fcbdccba9090c68edbbbd453f6b318bc69f9c965b732f9f1d0a58f985e720bfae520646d14
data/README.md CHANGED
@@ -73,6 +73,8 @@ end
73
73
 
74
74
  ```ruby
75
75
  class UserDecorator < Tramway::BaseDecorator
76
+ delegate_attributes :email, :created_at
77
+
76
78
  def self.index_attributes
77
79
  [:id, :email, :created_at]
78
80
  end
@@ -137,12 +139,11 @@ Tramway.configure do |config|
137
139
  config.entities = [
138
140
  {
139
141
  name: :user,
140
- route: { namespace: :admin }
142
+ namespace: :admin
141
143
  }, # `/admin/users` link in the Tramway Navbar
142
144
  {
143
145
  name: :episodes,
144
146
  route: {
145
- namespace: :podcasts,
146
147
  route_method: :episodes
147
148
  }
148
149
  }, # `/podcasts/episodes` link in the Tramway Navbar
@@ -161,7 +162,7 @@ Tramway.configure do |config|
161
162
  config.entities = [
162
163
  {
163
164
  name: :campaign,
164
- route: { namespace: :admin },
165
+ namespace: :admin,
165
166
  pages: [
166
167
  {
167
168
  action: :index,
@@ -180,7 +181,7 @@ other pages continue to show every record unless another scope is specified.
180
181
 
181
182
  To render a show page for an entity, declare a `:show` action inside the `pages` array in
182
183
  `config/initializers/tramway.rb`. Tramway will generate the route and render a table using the attributes returned by the
183
- decorator's `self.show_attributes` method.
184
+ decorator's 'show_attributes` method.
184
185
 
185
186
  ```ruby
186
187
  Tramway.configure do |config|
@@ -198,7 +199,7 @@ end
198
199
 
199
200
  ```ruby
200
201
  class CampaignDecorator < Tramway::BaseDecorator
201
- def self.show_attributes
202
+ def show_attributes
202
203
  %i[name status starts_at]
203
204
  end
204
205
  end
@@ -566,6 +567,10 @@ Read [behave_as_ar](https://github.com/Purple-Magic/tramway#behave_as_ar) sectio
566
567
 
567
568
  ### Tramway Navbar
568
569
 
570
+ #### Running tramway_navbar without arguments
571
+
572
+ When you call `tramway_navbar` without passing any arguments, it renders a navbar that lists buttons linking to all entities configured with a page index in `config/initializers/tramway.rb`.
573
+
569
574
  Tramway provides DSL for rendering Tailwind Navgiation bar.
570
575
 
571
576
  ```ruby
@@ -94,7 +94,7 @@ module Tailwinds
94
94
  end
95
95
 
96
96
  def get_value(attribute, options)
97
- options[:value] || (object.present? ? object.public_send(attribute) : nil)
97
+ options[:value] || object.presence&.public_send(attribute)
98
98
  end
99
99
 
100
100
  def default_options(attribute, options)
@@ -1,2 +1,3 @@
1
- %span.page.gap.px-3.py-2.text-sm.font-medium.text-purple-700.dark:text-white.sm:flex.hidden
2
- = helpers.t('views.pagination.truncate').html_safe
1
+ %div.flex.justify-end.mt-2
2
+ %span.page.gap.px-3.py-2.text-sm.font-medium.text-purple-700.dark:text-white.sm:flex.hidden
3
+ = helpers.t('views.pagination.truncate').html_safe
@@ -18,7 +18,7 @@
18
18
  You should fill class-level method `self.index_attributes` inside your
19
19
  = decorator
20
20
  - else
21
- = tramway_table do
21
+ = tramway_table class: 'mt-4' do
22
22
  = tramway_header headers: index_attributes.map { |attribute| @model_class.human_attribute_name(attribute) }
23
23
  - @entities.each do |item|
24
24
  = component 'tramway/entity', entity: @entity, item: item
@@ -1,5 +1,5 @@
1
1
  = tramway_container do
2
- %h1.text-2xl.font-bold.mb-4
2
+ %h1.text-4xl.font-bold.mb-4
3
3
  = @entity.title
4
4
 
5
5
  - if @entity.show_attributes.empty?
data/config/routes.rb CHANGED
@@ -12,10 +12,15 @@ Tramway::Engine.routes.draw do
12
12
  resource_name = segments.pop
13
13
 
14
14
  define_resource = proc do
15
- resources resource_name.pluralize.to_sym,
16
- only: entity.pages.map(&:action),
17
- controller: '/tramway/entities',
18
- defaults: { entity: entity }
15
+ entity.pages.each do |page|
16
+ case page.action
17
+ when 'index'
18
+ get resource_name.pluralize, to: '/tramway/entities#index', defaults: { entity: }, as: resource_name.pluralize
19
+ when 'show'
20
+ get "#{resource_name.pluralize}/:id", to: '/tramway/entities#show', defaults: { entity: },
21
+ as: resource_name.singularize
22
+ end
23
+ end
19
24
  end
20
25
 
21
26
  if segments.empty?
@@ -13,7 +13,8 @@ module Tramway
13
13
  attribute? :namespace, Types::Coercible::String
14
14
 
15
15
  # Route Struct contains implemented in Tramway CRUD and helpful routes for the entity
16
- RouteStruct = Struct.new(:index, :show)
16
+ ACTIONS = %i[index show].freeze
17
+ RouteStruct = Struct.new(*ACTIONS)
17
18
 
18
19
  # HumanName Struct contains human names forms for the entity
19
20
  HumanNameStruct = Struct.new(:single, :plural)
@@ -53,9 +54,9 @@ module Tramway
53
54
  end
54
55
 
55
56
  def route_helper_methods
56
- %i[index show].map do |action|
57
+ ACTIONS.map do |action|
57
58
  page(action).present? ? send("#{action}_helper_method") : nil
58
- end.compact
59
+ end
59
60
  end
60
61
 
61
62
  def build_helper_method(base_name, route: nil, namespace: nil, plural: false)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tramway
4
- VERSION = '1.0.1.1'
4
+ VERSION = '1.0.1.3'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tramway
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1.1
4
+ version: 1.0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - kalashnikovisme
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2025-11-08 00:00:00.000000000 Z
12
+ date: 2025-11-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: anyway_config