tramway 0.2.1.3 → 0.2.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: c2ed52c776d761d5afe99a7d31c99084191c032af8f35c13a49f1d3f6155d01f
4
- data.tar.gz: e6cee0a18222ae4d3a99f63a8b8959bfaec6dab11107006040451254c14aa4b4
3
+ metadata.gz: 12b9bb73f91f5c694ee64efaa36d66a5ee68c6b41066a5e775b42e4ba81678d4
4
+ data.tar.gz: 79c240ff539d4762fb8a2c4b3fe29ff05805c2699e12225d53038fafb53c5a1d
5
5
  SHA512:
6
- metadata.gz: 676f475214beb3bab65636d145bf797d48efadf0519294c2551b26caf58c47270238fce3f2a3bb72953a9a8d55708aa88fc4cda61deed86d60cd82f8cbc47bf8
7
- data.tar.gz: 3f5847c31384d66b892ab8eddec5a730579cd0fcebbf85302316b8f98c00677b7ff3b2c778cdb22e39427c7a3f10baa73c74599c7237c06c9b6a2c24c68fec60
6
+ metadata.gz: 5ccd8cdeb8bb8b9df08d4885ff473e68ef7a29f5980460050e52db4d7b7b758da170cabece248f78589dbc102d47f1ae4c3ee1410d50d8103cbb4ffc549d0a2e
7
+ data.tar.gz: 58c752011aa51d3c0afd9e074380411657a390b0a09568226de9d4c38b033d1b9b23f172b27af2a3ae137bc342185fad3736085412025d66cac4dab68e4ff994
data/README.md CHANGED
@@ -11,11 +11,26 @@ gem "view_component"
11
11
 
12
12
  ## Usage
13
13
 
14
+ ### Tramway Entities
15
+
16
+ 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.
17
+
18
+ #### Define entity for Tramway
19
+
20
+ *config/initializers/tramway.rb*
21
+ ```ruby
22
+ Tramway.configure do |config|
23
+ config.entities = [ :user, :podcast, :episode ] # entities based on models User, Podcast and Episode are defined
24
+ end
25
+ ```
26
+
27
+ By default, links to the Tramway Entities index page are rendered in [Tramway Navbar](https://github.com/Purple-Magic/tramway#tramway-navbar).
28
+
14
29
  ### Tailwind components
15
30
 
16
31
  Tramway uses [Tailwind](https://tailwindcss.com/) by default. All UI helpers are implemented with [ViewComponent](https://github.com/viewcomponent/view_component).
17
32
 
18
- ### Decorators
33
+ ### Tramway Decorators
19
34
 
20
35
  Tramway provides convenient decorators for your objects. **NOTE:** This is not the decorator pattern in its usual representation.
21
36
 
@@ -65,8 +80,7 @@ def show
65
80
  end
66
81
  ```
67
82
 
68
-
69
- ### Navbar
83
+ ### Tramway Navbar
70
84
 
71
85
  Tramway provides DSL for rendering Tailwind Navgiation bar.
72
86
 
@@ -97,6 +111,8 @@ background:
97
111
  intensity: Color intensity. Range: **100..950**. Used by Tailwind. Not supported in case of using HEX color in the background.color
98
112
  ```
99
113
 
114
+ **NOTE:** `tramway_navbar` method called without arguments and block of code will render only [Tramway Entities](https://github.com/Purple-Magic/tramway#tramway-entities) links on the left.
115
+
100
116
  #### nav.left and nav.right
101
117
 
102
118
  Tramway navbar provides `left` and `right` methods that puts items to left and right part of navbar.
@@ -1,14 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'tramway/decorators/collection_decorator'
4
- require 'tramway/utils/decorators/render'
4
+ require 'tramway/utils/render'
5
5
 
6
6
  module Tramway
7
7
  # Provides decorate function for Tramway projects
8
8
  #
9
9
  class BaseDecorator
10
10
  include Tramway::Decorators::CollectionDecorators
11
- include Tramway::Utils::Decorators::Render
11
+ include Tramway::Utils::Render
12
12
 
13
13
  attr_reader :object
14
14
 
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'singleton'
4
+ require 'tramway/configs/entity'
5
+
6
+ module Tramway
7
+ # Basic configuration of Tramway
8
+ #
9
+ class Config
10
+ include Singleton
11
+
12
+ def initialize
13
+ @entities = []
14
+ end
15
+
16
+ def entities=(collection)
17
+ @entities = collection.map do |entity|
18
+ Tramway::Configs::Entity.new(name: entity)
19
+ end
20
+ end
21
+
22
+ attr_reader :entities
23
+ end
24
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Tramway
4
+ module Configs
5
+ # Tramway is entity based framework
6
+ #
7
+ class Entity
8
+ attr_reader :name
9
+
10
+ def initialize(name:)
11
+ @name = name.to_s
12
+ end
13
+
14
+ def routes
15
+ underscored_name = name.parameterize.pluralize.underscore
16
+
17
+ OpenStruct.new index: Rails.application.routes.url_helpers.public_send("#{underscored_name}_path")
18
+ end
19
+
20
+ def human_name
21
+ OpenStruct.new single: name.capitalize, plural: name.pluralize.capitalize
22
+ end
23
+ end
24
+ end
25
+ end
@@ -7,13 +7,11 @@ module Tramway
7
7
  # Providing navbar helpers for ActionView
8
8
  module NavbarHelper
9
9
  def tramway_navbar(**options)
10
- if block_given?
11
- initialize_navbar
10
+ initialize_navbar
12
11
 
13
- yield @navbar
12
+ yield @navbar if block_given?
14
13
 
15
- assign_navbar_items(options)
16
- end
14
+ assign_navbar_items(options)
17
15
 
18
16
  render_navbar_component(options)
19
17
  end
@@ -21,7 +19,7 @@ module Tramway
21
19
  private
22
20
 
23
21
  def initialize_navbar
24
- @navbar = Tramway::Navbar.new(self)
22
+ @navbar = Tramway::Navbar.new self
25
23
  end
26
24
 
27
25
  def assign_navbar_items(options)
@@ -3,18 +3,23 @@
3
3
  module Tramway
4
4
  # Navbar object provides left and right elements
5
5
  class Navbar
6
- attr_reader :items
6
+ attr_reader :items, :context
7
7
 
8
8
  def initialize(context)
9
- @items = {}
10
9
  @context = context
10
+ @items = { left: [], right: [] }
11
11
  @filling = nil
12
+
13
+ entities = Tramway.config.entities
14
+
15
+ return unless entities.any?
16
+
17
+ preset_left entities
12
18
  end
13
19
 
14
20
  def left
15
21
  return unless block_given?
16
22
 
17
- @items[:left] = []
18
23
  filling_side(:left)
19
24
  yield self
20
25
  reset_filling
@@ -23,7 +28,6 @@ module Tramway
23
28
  def right
24
29
  return unless block_given?
25
30
 
26
- @items[:right] = []
27
31
  filling_side(:right)
28
32
  yield self
29
33
  reset_filling
@@ -43,6 +47,18 @@ module Tramway
43
47
 
44
48
  private
45
49
 
50
+ def preset_left(entities)
51
+ filling_side :left
52
+
53
+ entities.each do |entity|
54
+ entity.to_s.pluralize
55
+
56
+ item entity.human_name.plural, entity.routes.index
57
+ end
58
+
59
+ reset_filling
60
+ end
61
+
46
62
  def provided_url_and_block?(url)
47
63
  url.present? && block_given?
48
64
  end
@@ -57,12 +73,14 @@ module Tramway
57
73
 
58
74
  def render_ignoring_block(text_or_url, url, options)
59
75
  options.merge!(href: url)
60
- @context.render(Tailwinds::Nav::ItemComponent.new(**options)) { text_or_url }
76
+
77
+ context.render(Tailwinds::Nav::ItemComponent.new(**options)) { text_or_url }
61
78
  end
62
79
 
63
80
  def render_using_block(text_or_url, options, &block)
64
81
  options.merge!(href: text_or_url)
65
- @context.render(Tailwinds::Nav::ItemComponent.new(**options), &block)
82
+
83
+ context.render(Tailwinds::Nav::ItemComponent.new(**options), &block)
66
84
  end
67
85
  end
68
86
  end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Tramway
4
+ module Utils
5
+ # Provides helper method render that depends on ActionController::Base.render method
6
+ #
7
+ module Render
8
+ def render(*args, &)
9
+ ActionController::Base.render(*args, &)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tramway
4
- VERSION = '0.2.1.3'
4
+ VERSION = '0.2.2'
5
5
  end
data/lib/tramway.rb CHANGED
@@ -3,9 +3,19 @@
3
3
  require 'tramway/version'
4
4
  require 'tramway/engine'
5
5
  require 'tramway/base_decorator'
6
+ require 'tramway/config'
6
7
  require 'view_component/compiler'
7
8
  require 'view_component/engine'
8
9
 
9
10
  # Core module for the whole gem
10
11
  module Tramway
12
+ module_function
13
+
14
+ def configure(&)
15
+ yield config
16
+ end
17
+
18
+ def config
19
+ Tramway::Config.instance
20
+ end
11
21
  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.2.1.3
4
+ version: 0.2.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: 2023-07-22 00:00:00.000000000 Z
12
+ date: 2023-07-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: haml-rails
@@ -88,13 +88,15 @@ files:
88
88
  - lib/tasks/tramway_tasks.rake
89
89
  - lib/tramway.rb
90
90
  - lib/tramway/base_decorator.rb
91
+ - lib/tramway/config.rb
92
+ - lib/tramway/configs/entity.rb
91
93
  - lib/tramway/decorators/class_helper.rb
92
94
  - lib/tramway/decorators/collection_decorator.rb
93
95
  - lib/tramway/engine.rb
94
96
  - lib/tramway/helpers/decorate_helper.rb
95
97
  - lib/tramway/helpers/navbar_helper.rb
96
98
  - lib/tramway/navbar.rb
97
- - lib/tramway/utils/decorators/render.rb
99
+ - lib/tramway/utils/render.rb
98
100
  - lib/tramway/version.rb
99
101
  homepage: https://github.com/purple-magic/tramway
100
102
  licenses:
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Tramway
4
- module Utils
5
- module Decorators
6
- # Provides helper method render that depends on ActionController::Base.render method
7
- #
8
- module Render
9
- def render(*args)
10
- ActionController::Base.render(*args, layout: false)
11
- end
12
- end
13
- end
14
- end
15
- end