tramway 3.1.2.8 → 4.0

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 (36) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +76 -16
  3. data/app/assets/builds/tailwind.css +2 -0
  4. data/app/assets/javascripts/tramway/tramway.js +174 -1
  5. data/app/assets/stylesheets/font-awesome.css +2337 -0
  6. data/app/assets/tailwind/application.css +29 -0
  7. data/app/components/tramway/chat_component.html.haml +1 -1
  8. data/app/components/tramway/containers/main_component.rb +1 -3
  9. data/app/components/tramway/containers/narrow_component.rb +5 -4
  10. data/app/components/tramway/form/builder.rb +1 -2
  11. data/app/components/tramway/grid/card_component.html.haml +2 -0
  12. data/app/components/tramway/grid/card_component.rb +37 -0
  13. data/app/components/tramway/grid_component.html.haml +18 -0
  14. data/app/components/tramway/grid_component.rb +76 -0
  15. data/app/components/tramway/native_text_component.rb +1 -2
  16. data/app/components/tramway/nav/item_component.rb +4 -2
  17. data/app/components/tramway/navbar_component.html.haml +104 -110
  18. data/app/components/tramway/navbar_component.rb +84 -2
  19. data/app/components/tramway/table/cell_component.rb +9 -1
  20. data/app/components/tramway/table/header_component.rb +23 -2
  21. data/app/components/tramway/table/row_component.rb +27 -10
  22. data/app/components/tramway/table_component.rb +28 -1
  23. data/app/controllers/tramway/entities_controller.rb +6 -6
  24. data/app/views/tramway/layouts/application.html.haml +8 -6
  25. data/config/routes.rb +1 -2
  26. data/config/tailwind.config.js +57 -0
  27. data/lib/generators/tramway/install/font_awesome_helpers.rb +39 -0
  28. data/lib/generators/tramway/install/install_generator.rb +131 -65
  29. data/lib/generators/tramway/install/layout_helpers.rb +95 -0
  30. data/lib/tramway/engine.rb +12 -0
  31. data/lib/tramway/forms/validations.rb +1 -2
  32. data/lib/tramway/helpers/navbar_helper.rb +3 -1
  33. data/lib/tramway/helpers/table_helper.rb +27 -0
  34. data/lib/tramway/helpers/views_helper.rb +26 -2
  35. data/lib/tramway/version.rb +1 -1
  36. metadata +28 -4
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Tramway
4
+ module Generators
5
+ # Layout helpers for Tramway generator template updates.
6
+ module InstallGeneratorLayoutHelpers
7
+ private
8
+
9
+ def application_layout_haml_path
10
+ @application_layout_haml_path ||= File.join(destination_root, 'app/views/layouts/application.html.haml')
11
+ end
12
+
13
+ def application_layout_erb_path
14
+ @application_layout_erb_path ||= File.join(destination_root, 'app/views/layouts/application.html.erb')
15
+ end
16
+
17
+ def trix_haml_tags
18
+ " = stylesheet_link_tag \"trix\", \"data-turbo-track\": \"reload\"\n " \
19
+ "= javascript_include_tag \"trix\", \"data-turbo-track\": \"reload\", defer: true\n"
20
+ end
21
+
22
+ def trix_erb_tags
23
+ " <%= stylesheet_link_tag \"trix\", \"data-turbo-track\": \"reload\" %>\n " \
24
+ "<%= javascript_include_tag \"trix\", \"data-turbo-track\": \"reload\", defer: true %>\n"
25
+ end
26
+
27
+ def trix_already_present?(content)
28
+ content.include?('stylesheet_link_tag "trix"') || content.include?("stylesheet_link_tag 'trix'")
29
+ end
30
+
31
+ def font_awesome_already_present?(content)
32
+ content.include?('stylesheet_link_tag "font-awesome"') ||
33
+ content.include?("stylesheet_link_tag 'font-awesome'")
34
+ end
35
+
36
+ def navbar_sidebar_offset_class
37
+ 'md:pl-72 transition-all duration-300 ease-in-out'
38
+ end
39
+
40
+ def ensure_trix_in_haml_layout
41
+ content = File.read(application_layout_haml_path)
42
+ return if trix_already_present?(content)
43
+ return unless content.match?(/^\s+%body/)
44
+
45
+ updated = content.sub(/^(\s+%body)/, "#{trix_haml_tags}\\1")
46
+ File.write(application_layout_haml_path, updated)
47
+ end
48
+
49
+ def ensure_trix_in_erb_layout
50
+ content = File.read(application_layout_erb_path)
51
+ return if trix_already_present?(content)
52
+ return unless content.include?('</head>')
53
+
54
+ updated = content.sub('</head>', "#{trix_erb_tags} </head>")
55
+ File.write(application_layout_erb_path, updated)
56
+ end
57
+
58
+ def ensure_navbar_sidebar_offset
59
+ if File.exist?(application_layout_haml_path)
60
+ ensure_navbar_sidebar_offset_in_haml_layout
61
+ elsif File.exist?(application_layout_erb_path)
62
+ ensure_navbar_sidebar_offset_in_erb_layout
63
+ end
64
+ end
65
+
66
+ def ensure_navbar_sidebar_offset_in_haml_layout
67
+ content = File.read(application_layout_haml_path)
68
+ return if content.include?(navbar_sidebar_offset_class)
69
+ return unless content.match?(/= tramway_main_container(?: class: '[^']*')? do/)
70
+
71
+ File.write(
72
+ application_layout_haml_path,
73
+ content.sub(
74
+ /= tramway_main_container(?: class: '[^']*')? do/,
75
+ "= tramway_main_container class: '#{navbar_sidebar_offset_class}' do"
76
+ )
77
+ )
78
+ end
79
+
80
+ def ensure_navbar_sidebar_offset_in_erb_layout
81
+ content = File.read(application_layout_erb_path)
82
+ return if content.include?(navbar_sidebar_offset_class)
83
+ return unless content.match?(/<%= tramway_main_container(?: class: '[^']*')? do %>/)
84
+
85
+ File.write(
86
+ application_layout_erb_path,
87
+ content.sub(
88
+ /<%= tramway_main_container(?: class: '[^']*')? do %>/,
89
+ "<%= tramway_main_container class: '#{navbar_sidebar_offset_class}' do %>"
90
+ )
91
+ )
92
+ end
93
+ end
94
+ end
95
+ end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'font-awesome-rails'
4
+
3
5
  module Tramway
4
6
  # Rails plugin is the Engine
5
7
  #
@@ -17,8 +19,14 @@ module Tramway
17
19
  end
18
20
 
19
21
  initializer 'tramway.assets.precompile' do |app|
22
+ font_awesome_font_paths.each do |path|
23
+ path_string = path.to_s
24
+ app.config.assets.paths << path_string unless app.config.assets.paths.include?(path_string)
25
+ end
26
+
20
27
  app.config.assets.precompile += %w[
21
28
  tramway/tramway.js
29
+ font-awesome.css
22
30
  ]
23
31
  end
24
32
 
@@ -88,6 +96,10 @@ module Tramway
88
96
  end
89
97
  end
90
98
 
99
+ def font_awesome_font_paths
100
+ [FontAwesome::Rails::Engine.root.join('app/assets/fonts')]
101
+ end
102
+
91
103
  def configure_pagination
92
104
  ActiveSupport.on_load(:action_controller) do
93
105
  # Detecting tramway views path
@@ -16,11 +16,10 @@ module Tramway
16
16
  def __initialize_validations(_subclass); end
17
17
  end
18
18
 
19
- # rubocop:disable Naming/PredicateMethod
19
+ # rubocop:disable-next Naming/PredicateMethod
20
20
  def __apply_validations(_params)
21
21
  valid?
22
22
  end
23
- # rubocop:enable Naming/PredicateMethod
24
23
  end
25
24
  end
26
25
  end
@@ -6,11 +6,13 @@ module Tramway
6
6
  module Helpers
7
7
  # Provides navbar helpers for ActionView
8
8
  module NavbarHelper
9
- def tramway_navbar(with_entities: true, **options)
9
+ def tramway_navbar(with_entities: true, direction: :vertical, **options)
10
+ @tramway_navbar_direction = direction.presence&.to_sym || :vertical
10
11
  initialize_navbar(with_entities:)
11
12
 
12
13
  yield @navbar if block_given?
13
14
 
15
+ options[:direction] = direction if options[:direction].nil?
14
16
  assign_navbar_items(options)
15
17
 
16
18
  render_navbar_component(options)
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Tramway
4
+ module Helpers
5
+ # Provides size helpers for Tramway tables
6
+ module TableHelper
7
+ TABLE_SIZES = %i[small medium large].freeze
8
+
9
+ def tramway_table_size
10
+ context = tramway_table_context
11
+ return :medium unless context.respond_to?(:tramway_table_size)
12
+
13
+ TABLE_SIZES.include?(context.tramway_table_size) ? context.tramway_table_size : :medium
14
+ end
15
+
16
+ def normalize_table_size(size)
17
+ TABLE_SIZES.include?(size) ? size : :medium
18
+ end
19
+
20
+ def tramway_table_context
21
+ return __vc_original_view_context if respond_to?(:__vc_original_view_context)
22
+
23
+ view_context if respond_to?(:view_context)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,10 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'tramway/helpers/table_helper'
4
+
3
5
  module Tramway
4
6
  module Helpers
5
7
  # Provides view-oriented helpers for ActionView
6
8
  module ViewsHelper
7
9
  include Tramway::Helpers::ComponentHelper
10
+ include Tramway::Helpers::TableHelper
8
11
 
9
12
  FORM_SIZES = %i[small medium large].freeze
10
13
 
@@ -19,8 +22,16 @@ module Tramway
19
22
  ), &)
20
23
  end
21
24
 
22
- def tramway_table(**options, &)
23
- component 'tramway/table', options:, &
25
+ def tramway_table(size: :medium, **options, &)
26
+ component 'tramway/table', size: normalize_table_size(size), options:, &
27
+ end
28
+
29
+ def tramway_grid(rows:, columns:, outline: false, **options, &)
30
+ component 'tramway/grid', rows:, columns:, outline:, options:, &
31
+ end
32
+
33
+ def tramway_card(size: [1, 1], **options, &)
34
+ component 'tramway/grid/card', size:, options:, &
24
35
  end
25
36
 
26
37
  def tramway_header(headers: nil, columns: nil, **options, &)
@@ -63,6 +74,8 @@ module Tramway
63
74
  end
64
75
 
65
76
  def tramway_main_container(**options, &)
77
+ options[:id] ||= 'tramway-main-container'
78
+ options[:class] = tramway_main_container_classes(options[:class])
66
79
  component 'tramway/containers/main', options:, &
67
80
  end
68
81
 
@@ -102,6 +115,17 @@ module Tramway
102
115
  def normalize_form_size(size)
103
116
  FORM_SIZES.include?(size) ? size : :medium
104
117
  end
118
+
119
+ def tramway_main_container_classes(value)
120
+ classes = Array(value).flat_map { _1.to_s.split }
121
+
122
+ return classes.join(' ') if @tramway_navbar_direction.nil?
123
+
124
+ classes = classes.reject { _1.start_with?('md:pl-') || _1.start_with?('md:pr-') }
125
+ classes << 'md:pl-72' if @tramway_navbar_direction == :vertical
126
+
127
+ classes.join(' ')
128
+ end
105
129
  end
106
130
  end
107
131
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tramway
4
- VERSION = '3.1.2.8'
4
+ VERSION = '4.0'
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: 3.1.2.8
4
+ version: '4.0'
5
5
  platform: ruby
6
6
  authors:
7
7
  - kalashnikovisme
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: font-awesome-rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: haml-rails
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -86,7 +100,7 @@ dependencies:
86
100
  requirements:
87
101
  - - ">="
88
102
  - !ruby/object:Gem::Version
89
- version: '7'
103
+ version: '8'
90
104
  - - "<"
91
105
  - !ruby/object:Gem::Version
92
106
  version: '9'
@@ -96,7 +110,7 @@ dependencies:
96
110
  requirements:
97
111
  - - ">="
98
112
  - !ruby/object:Gem::Version
99
- version: '7'
113
+ version: '8'
100
114
  - - "<"
101
115
  - !ruby/object:Gem::Version
102
116
  version: '9'
@@ -138,7 +152,10 @@ files:
138
152
  - MIT-LICENSE
139
153
  - README.md
140
154
  - Rakefile
155
+ - app/assets/builds/tailwind.css
141
156
  - app/assets/javascripts/tramway/tramway.js
157
+ - app/assets/stylesheets/font-awesome.css
158
+ - app/assets/tailwind/application.css
142
159
  - app/components/tailwind_component.html.haml
143
160
  - app/components/tailwind_component.rb
144
161
  - app/components/tramway/actions_buttons_container_component.html.haml
@@ -207,6 +224,10 @@ files:
207
224
  - app/components/tramway/form/tramway_select/selected_item_template_component.rb
208
225
  - app/components/tramway/form/tramway_select_component.html.haml
209
226
  - app/components/tramway/form/tramway_select_component.rb
227
+ - app/components/tramway/grid/card_component.html.haml
228
+ - app/components/tramway/grid/card_component.rb
229
+ - app/components/tramway/grid_component.html.haml
230
+ - app/components/tramway/grid_component.rb
210
231
  - app/components/tramway/native_text_component.html.haml
211
232
  - app/components/tramway/native_text_component.rb
212
233
  - app/components/tramway/nav/item/button_component.html.haml
@@ -266,7 +287,9 @@ files:
266
287
  - config/routes.rb
267
288
  - config/tailwind.config.js
268
289
  - docs/AGENTS.md
290
+ - lib/generators/tramway/install/font_awesome_helpers.rb
269
291
  - lib/generators/tramway/install/install_generator.rb
292
+ - lib/generators/tramway/install/layout_helpers.rb
270
293
  - lib/kaminari/helpers/tag.rb
271
294
  - lib/rules/turbo_html_attributes_rules.rb
272
295
  - lib/tasks/tramway_tasks.rake
@@ -296,6 +319,7 @@ files:
296
319
  - lib/tramway/helpers/form_helper.rb
297
320
  - lib/tramway/helpers/navbar_helper.rb
298
321
  - lib/tramway/helpers/routes_helper.rb
322
+ - lib/tramway/helpers/table_helper.rb
299
323
  - lib/tramway/helpers/views_helper.rb
300
324
  - lib/tramway/navbar.rb
301
325
  - lib/tramway/searchable.rb
@@ -326,7 +350,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
326
350
  - !ruby/object:Gem::Version
327
351
  version: '0'
328
352
  requirements: []
329
- rubygems_version: 4.0.16
353
+ rubygems_version: 4.0.20
330
354
  specification_version: 4
331
355
  summary: Tramway Rails Engine
332
356
  test_files: []