tramway 0.5.1 → 0.5.1.2

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: fbd54b0a803c53d12e50ec585a805ca39dc56b0551e12fa2de66514a9166b750
4
- data.tar.gz: 7db6cfe3b24afaed951ac2ca2b52eb65d38bf0bdb49d6625f8508fa2dc594e52
3
+ metadata.gz: f2716febb35463e08d23262e008c607f0114f5cc49d1734ecbed30c3133e9e06
4
+ data.tar.gz: 408cfb199f328e21f03f2d99eb04c6a16d5eb875709dede6c2a71292ebb7647b
5
5
  SHA512:
6
- metadata.gz: a4d807fffc40d7e2cdfd9fec0b513f39f4a4338cd9ea1718d4ece1d0587bc1d86aa26112688ec9fb5e108ed1a04fac01f7f79ae7852f105fb132e4b9361550a3
7
- data.tar.gz: 45ac2aec489c85b212938ae99456fe8e5fc54f804cc9525aee1f034c5586d0e080e3c58fd9593f3779aabce5f2c5941ff36198183e81880f23f5d3a4b871aa98
6
+ metadata.gz: bf77038d704285581baf87b69900c4af9ecf06c6cf5b158c68062ce92c7c8414f3b3e9a1bc77eafe730dfe709b432ba4c5633ba162873d67ec8e7e26004aac7e
7
+ data.tar.gz: 3ea8c39ac64b9571779c8684d209188c5255c9820967eddfd528f0f5d4d3d66ff0645fd2e62d3906501b432d48393d1cfa7a99a23bda9bdf3382fa8aa3293ff7
data/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
  Unite Ruby on Rails brilliance. Streamline development with Tramway.
3
3
 
4
4
  * [Installation](https://github.com/Purple-Magic/tramway#installation)
5
+ * [Getting Started](https://github.com/Purple-Magic/tramway?tab=readme-ov-file#getting-started)
5
6
  * [Usage](https://github.com/Purple-Magic/tramway#usage)
6
7
  * [Tramway Entities](https://github.com/Purple-Magic/tramway#tramway-entities)
7
8
  * [Tramway Decorators](https://github.com/Purple-Magic/tramway#tramway-decorators)
@@ -17,6 +18,8 @@ Add this line to your application's Gemfile:
17
18
 
18
19
  ```ruby
19
20
  gem "tramway"
21
+ gem "haml-rails"
22
+ gem "kaminari"
20
23
  gem "view_component"
21
24
  ```
22
25
 
@@ -26,8 +29,71 @@ OR
26
29
  bundle add tramway view_component
27
30
  ```
28
31
 
32
+ ## Getting Started
33
+
34
+ **Step 1**
35
+
36
+ *config/initializers/tramway.rb*
37
+ ```ruby
38
+ Tramway.configure do |config|
39
+ config.entities = [
40
+ {
41
+ name: :user,
42
+ pages: [:index],
43
+ }
44
+ ]
45
+ end
46
+ ```
47
+
48
+ **Step 2**
49
+
50
+ *config/routes.rb*
51
+
52
+ ```ruby
53
+ Rails.application.routes.draw do
54
+ mount Tramway::Engine, at: '/'
55
+ end
56
+ ```
57
+
58
+ **Step 3**
59
+
60
+ ```ruby
61
+ class UserDecorator < Tramway::BaseDecorator
62
+ def self.list_attributes
63
+ [:id, :email, :created_at]
64
+ end
65
+ end
66
+ ```
67
+
68
+ **Step 4**
69
+
70
+ Copy this [file](https://github.com/Purple-Magic/tramway/blob/main/config/tailwind.config.js) to config/tailwind.config.js
71
+
72
+
73
+ **Step 5**
74
+
75
+ Run tailwincss-rails compiler
76
+
77
+
78
+ ```bash
79
+ bin/rails tailwindcss:build
80
+ ```
81
+
82
+ **Step 6**
83
+
84
+ Run your server
85
+
86
+ ```bash
87
+ bundle exec rails s
88
+ ```
89
+
90
+ **Step 7**
91
+
92
+ Open [http://localhost:3000/users](http://localhost:3000/users)
93
+
29
94
  ## Usage
30
95
 
96
+
31
97
  ### Tramway Entities
32
98
 
33
99
  Tramway is an entity-based framework. **Entity** is the class on whose objects actions be applied: _index, show, create, update, and destroy_. Tramway will support numerous classes as entities. For now, Entity could be only **ActiveRecord::Base** class.
@@ -3,7 +3,7 @@
3
3
  - cols = cells.count.times.map { |item| "1fr" }.join(",")
4
4
 
5
5
  -# desktop view
6
- = row_tag class: "div-table-row block grid gap-4 bg-white border-b dark:bg-gray-800 dark:border-gray-700 grid-cols-[#{cols}]" do
6
+ = row_tag class: "div-table-row block grid gap-4 bg-white border-b dark:bg-gray-800 dark:border-gray-700 cursor-pointer hover:bg-purple-100 grid-cols-[#{cols}]" do
7
7
  - cells.each do |(_, value)|
8
8
  .div-table-cell.px-6.py-4.font-medium.text-gray-900.whitespace-nowrap.dark:text-white.sm:text-xs.text-base
9
9
  = value
@@ -3,6 +3,10 @@
3
3
  module Tramway
4
4
  # Main controller for entities pages
5
5
  class EntitiesController < Tramway.config.application_controller.constantize
6
+ prepend_view_path "#{Gem::Specification.find_by_name('tramway').gem_dir}/app/views"
7
+
8
+ layout 'tramway/layouts/application'
9
+
6
10
  helper Tramway::ApplicationHelper
7
11
  include Rails.application.routes.url_helpers
8
12
 
@@ -13,7 +17,7 @@ module Tramway
13
17
  private
14
18
 
15
19
  def model_class
16
- @model_class ||= params[:entity].classify.constantize
20
+ @model_class ||= params[:entity][:name].classify.constantize
17
21
  end
18
22
  end
19
23
  end
@@ -1,7 +1,7 @@
1
1
  - decorator = Tramway::Decorators::NameBuilder.default_decorator_class_name(@model_class)
2
2
  - list_attributes = decorator.constantize.list_attributes
3
3
 
4
- .w-full
4
+ .mt-8{ class: 'w-2/3' }
5
5
  - content_for :title, page_title
6
6
 
7
7
  .flex.justify-between.items-center.md:mt-4.mt-2
@@ -16,10 +16,10 @@
16
16
  You should fill class-level method `self.list_attributes` inside your
17
17
  = decorator
18
18
 
19
- = component 'tailwinds/table' do
20
- = component 'tailwinds/table/header', headers: list_attributes.map { |attribute| @model_class.human_attribute_name(attribute) }
21
- - @entities.each do |item|
22
- = render 'entity', entity: item
19
+ = component 'tailwinds/table' do
20
+ = component 'tailwinds/table/header', headers: list_attributes.map { |attribute| @model_class.human_attribute_name(attribute) }
21
+ - @entities.each do |item|
22
+ = render 'entity', entity: item
23
23
 
24
- .flex.mt-4
25
- = paginate @entities
24
+ .flex.mt-4
25
+ = paginate @entities
@@ -0,0 +1,26 @@
1
+ %html
2
+ %head
3
+ %title= content_for(:title) || "Tramway"
4
+ %meta{name: "viewport", content: "width=device-width,initial-scale=1"}
5
+ %meta{name: "apple-mobile-web-app-capable", content: "yes"}
6
+ %meta{name: "mobile-web-app-capable", content: "yes"}
7
+ = csrf_meta_tags
8
+ = csp_meta_tag
9
+
10
+ = yield :head
11
+
12
+ / Enable PWA manifest for installable apps (make sure to enable in config/routes.rb too!)
13
+ / = tag.link rel: "manifest", href: pwa_manifest_path(format: :json)
14
+
15
+ %link{rel: "icon", href: "/icon.png", type: "image/png"}
16
+ %link{rel: "icon", href: "/icon.svg", type: "image/svg+xml"}
17
+ %link{rel: "apple-touch-icon", href: "/icon.png"}
18
+
19
+ / Includes all stylesheet files in app/assets/stylesheets
20
+ = stylesheet_link_tag "tailwind", "data-turbo-track": "reload"
21
+
22
+ %body.bg-gray-100
23
+ = tramway_navbar title: 'Tramway'
24
+
25
+ .container.mx-auto.p-4.flex.align-center.justify-center
26
+ = yield
data/config/routes.rb CHANGED
@@ -2,6 +2,29 @@
2
2
 
3
3
  Tramway::Engine.routes.draw do
4
4
  Tramway.config.entities.each do |entity|
5
- resources entity.name.pluralize.to_sym, only: entity.pages, controller: :entities, defaults: { entity: entity.name }
5
+ define_resource = lambda do |resource_name, entity| # rubocop:disable Lint/ShadowingOuterLocalVariable
6
+ resources resource_name.pluralize.to_sym,
7
+ only: [:index],
8
+ controller: '/tramway/entities',
9
+ defaults: { entity: }
10
+ end
11
+
12
+ if entity.name.include?('/')
13
+ *namespaces, resource_name = entity.name.split('/')
14
+
15
+ define_namespace = lambda do |index|
16
+ namespace namespaces[index].to_sym do
17
+ if namespaces[index] == namespaces.last
18
+ define_resource.call(resource_name, entity)
19
+ else
20
+ define_namespace.call(namespaces[index + 1])
21
+ end
22
+ end
23
+ end
24
+
25
+ define_namespace.call(0)
26
+ else
27
+ define_resource.call(entity.name, entity)
28
+ end
6
29
  end
7
30
  end
@@ -0,0 +1,61 @@
1
+ const defaultTheme = require('tailwindcss/defaultTheme');
2
+
3
+ module.exports = {
4
+ darkMode: 'class',
5
+ content: [
6
+ './public/*.html',
7
+ './app/components/**/*.html.haml',
8
+ './app/helpers/**/*.rb',
9
+ './app/javascript/**/*.js',
10
+ './app/views/**/*.{erb,haml,html,slim}'
11
+ ],
12
+ theme: {
13
+ extend: {
14
+ screens: {
15
+ ...defaultTheme.screens,
16
+ },
17
+ },
18
+ },
19
+ safelist: [
20
+ 'div-table',
21
+ 'div-table-row',
22
+ 'div-table-cell',
23
+ 'hidden',
24
+ 'text-xl',
25
+ 'text-4xl',
26
+ 'font-bold',
27
+ 'xl:hidden',
28
+ 'grid-cols-[1fr]',
29
+ 'grid-cols-[1fr,1fr]',
30
+ 'grid-cols-[1fr,1fr,1fr]',
31
+ 'grid-cols-[1fr,1fr,1fr,1fr]',
32
+ 'grid-cols-[1fr,1fr,1fr,1fr,1fr]',
33
+ 'grid-cols-[1fr,1fr,1fr,1fr,1fr,1fr]',
34
+ 'grid-cols-[1fr,1fr,1fr,1fr,1fr,1fr,1fr]',
35
+ 'grid-cols-[1fr,1fr,1fr,1fr,1fr,1fr,1fr,1fr]',
36
+ 'grid-cols-[1fr,1fr,1fr,1fr,1fr,1fr,1fr,1fr,1fr]',
37
+ 'grid-cols-[1fr,1fr,1fr,1fr,1fr,1fr,1fr,1fr,1fr,1fr]',
38
+ 'text-right',
39
+ 'w-2/3',
40
+ 'flex',
41
+ // multiselect styles
42
+ 'absolute', 'shadow', 'top-100', 'z-40', 'w-full', 'lef-0', 'rounded', 'max-h-select', 'overflow-y-auto', 'cursor-pointer', 'rounded-t', 'border-b', 'hover:bg-teal-100', 'items-center', 'border-transparent', 'border-l-2,', 'relative', 'hover:border-teal-100', 'leading-6', 'bg-transparent', 'appearance-none', 'outline-none', 'h-full' , 'justify-center', 'm-1', 'font-medium', 'rounded-full', 'text-teal-700', 'bg-teal-100', 'border', 'border-teal-300', 'text-xs', 'font-normal', 'leading-none', 'max-w-full', 'flex-initial', 'flex-auto', 'flex-row-reverse',, 'flex-col', 'min-w-96', 'w-fit', 'flex-wrap', 'w-8', 'border-l',
43
+ {
44
+ pattern: /(text|bg|border)-(purple|blue|gray|yellow|red|white|green)-\d+/,
45
+ variants: ['dark', 'focus', 'hover', 'dark:hover'],
46
+ },
47
+ {
48
+ pattern: /(text|bg)-(purple|blue|gray|yellow|red|white)/,
49
+ variants: ['dark', 'focus', 'hover', 'dark:hover'],
50
+ },
51
+ {
52
+ pattern: /(m|p)(l|r|b|t|x|y)-\d+/
53
+ },
54
+ ],
55
+ plugins: [
56
+ require('@tailwindcss/forms'),
57
+ require('@tailwindcss/aspect-ratio'),
58
+ require('@tailwindcss/typography'),
59
+ require('@tailwindcss/container-queries'),
60
+ ],
61
+ };
@@ -57,5 +57,24 @@ module Tramway
57
57
  end
58
58
 
59
59
  def show_path = nil
60
+
61
+ # :reek:ManualDispatch { enabled: false } because there is the idea to manual dispatch
62
+ def method_missing(method_name, *, &)
63
+ url_helpers = Rails.application.routes.url_helpers
64
+
65
+ if method_name.to_s.end_with?('_path', '_url')
66
+ return url_helpers.public_send(method_name, *, &) if url_helpers.respond_to?(method_name)
67
+
68
+ raise NoMethodError, "undefined method `#{method_name}` for #{self}" unless respond_to_missing?(method_name)
69
+
70
+ end
71
+
72
+ super
73
+ end
74
+
75
+ # :reek:BooleanParameter { enabled: false } because it's a part of the duck-typing
76
+ def respond_to_missing?(method_name, include_private = false)
77
+ method_name.to_s.end_with?('_path', '_url') || super
78
+ end
60
79
  end
61
80
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tramway
4
- VERSION = '0.5.1'
4
+ VERSION = '0.5.1.2'
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: 0.5.1
4
+ version: 0.5.1.2
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-01-14 00:00:00.000000000 Z
12
+ date: 2025-01-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: anyway_config
@@ -67,6 +67,20 @@ dependencies:
67
67
  - - ">="
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: kaminari
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
70
84
  - !ruby/object:Gem::Dependency
71
85
  name: rails
72
86
  requirement: !ruby/object:Gem::Requirement
@@ -177,7 +191,9 @@ files:
177
191
  - app/views/kaminari/_prev_page.html.haml
178
192
  - app/views/tramway/entities/_entity.html.haml
179
193
  - app/views/tramway/entities/index.html.haml
194
+ - app/views/tramway/layouts/application.html.haml
180
195
  - config/routes.rb
196
+ - config/tailwind.config.js
181
197
  - lib/rules/turbo_html_attributes_rules.rb
182
198
  - lib/tasks/tramway_tasks.rake
183
199
  - lib/tramway.rb