tramway 3.0.4 → 3.0.4.2

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: 8f1294b704f5b6bc2779d6eae4168a9c63508af6b485dfe267fa70a1b2ca786e
4
- data.tar.gz: 662bf3c75f819a46229a55cce0804b11a70511ade1ecbc08e8aa50a09d246381
3
+ metadata.gz: 6df450ba2be14dca796231458310c25cbbc33d51d39de0bbeb7af4d8c0fadba1
4
+ data.tar.gz: 26ded3945beb84b04c0ea7c7916a3a8b1bc9beb14e7df7886a8add7d1bebb983
5
5
  SHA512:
6
- metadata.gz: 90eb4ab0b7d5e871f904d320a42469ea92d35a83ebad3c014b167fe7b5294e7c046c1c0ebc41f64a09693794995e82641d69b3cb9d59d3e5183f5108ace44745
7
- data.tar.gz: 53bc0d610787669587ed26f4c6bbadce0c0e476ae34b8f4ea49128ad7e20265080d09abdf3726fea93aea1014a2a935b12077b6049c47fd46c199c044ad6872f
6
+ metadata.gz: 350d5eaf8eb2aadc8b458bc9834340ee34efe36ce4dbec2960214331b89e6979329b1c61c607b7cf64b595fb7c81e62959144d78708755c2e8964872f0f89dd2
7
+ data.tar.gz: 1d7215149e091f8b967fbee6471d68a77c90f57294022f66327626e300759ad31f01d4e30e019c1a17f571e7adba9f09f404089f0960bd129fc1c4918f0c86b7
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Tramway
2
2
  Unite Ruby on Rails brilliance. Streamline development with Tramway.
3
3
 
4
- Tramway ships with full CRUD (index, show, create, update, destroy) out of the box, and it includes a great AGENTS.md guide
5
- that helps you generate good, Tramway-native code with all the framework features.
4
+ Tramway ships with full CRUD (index, show, create, update, destroy) out of the box. Its install generator also adds a
5
+ Codex instruction that points agents to the Tramway skill for Tramway-native code generation.
6
6
 
7
7
  [![RubyGems Version](https://img.shields.io/gem/v/tramway.svg)](https://rubygems.org/gems/tramway)
8
8
  [![Tests](https://github.com/Purple-Magic/tramway/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/Purple-Magic/tramway/actions/workflows/test.yml)
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Tramway
4
+ module Table
5
+ # Helpers for extracting and normalizing visible table content cells from HTML fragments.
6
+ module ContentCells
7
+ private
8
+
9
+ def visible_cells_from(content)
10
+ fragment = Nokogiri::HTML.fragment(content)
11
+ parsed_cells = fragment.xpath(
12
+ './*[@class and contains(concat(" ", normalize-space(@class), " "), " div-table-cell ")]'
13
+ )
14
+
15
+ parsed_cells.each { |cell| remove_hidden_class!(cell) }
16
+ end
17
+
18
+ def remove_hidden_class!(node)
19
+ classes = node['class'].to_s.split
20
+ return if classes.empty?
21
+
22
+ node['class'] = classes.reject { |class_name| class_name == 'hidden' }.join(' ')
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,4 +1,5 @@
1
- %div{ class: "#{header_row_classes} md:grid-cols-#{columns_count}", aria: { label: "Table Header" }, role: "row" }
1
+ - parsed_cells = headers.any? ? nil : visible_cells_from(content)
2
+ %div{ class: "#{header_row_classes} md:grid-cols-#{columns_count(parsed_cells: parsed_cells)}", aria: { label: "Table Header" }, role: "row" }
2
3
  - if headers.any?
3
4
  - headers.each do |header|
4
5
  .div-table-cell{ class: header_cell_classes }
@@ -4,11 +4,17 @@ module Tramway
4
4
  module Table
5
5
  # Component for rendering a header in a table
6
6
  class HeaderComponent < Tramway::BaseComponent
7
+ include ContentCells
8
+
7
9
  option :headers, optional: true, default: -> { [] }
8
10
  option :columns, optional: true, default: -> { 3 }
9
11
 
10
- def columns_count
11
- headers.present? ? headers.size : columns
12
+ def columns_count(content = nil, parsed_cells: nil)
13
+ return headers.size if headers.present?
14
+ return parsed_cells.size if parsed_cells
15
+ return visible_cells_from(content).size if content.present?
16
+
17
+ columns
12
18
  end
13
19
 
14
20
  def header_row_classes
@@ -4,6 +4,8 @@ module Tramway
4
4
  module Table
5
5
  # Component for rendering a row in a table
6
6
  class RowComponent < Tramway::BaseComponent
7
+ include ContentCells
8
+
7
9
  option :cells, optional: true, default: -> { [] }
8
10
  option :href, optional: true
9
11
  option :preview, optional: true, default: -> { true }
@@ -58,22 +60,6 @@ module Tramway
58
60
 
59
61
  private
60
62
 
61
- def visible_cells_from(content)
62
- fragment = Nokogiri::HTML.fragment(content)
63
- parsed_cells = fragment.xpath(
64
- './*[@class and contains(concat(" ", normalize-space(@class), " "), " div-table-cell ")]'
65
- )
66
-
67
- parsed_cells.each { |cell| remove_hidden_class!(cell) }
68
- end
69
-
70
- def remove_hidden_class!(node)
71
- classes = node['class'].to_s.split
72
- return if classes.empty?
73
-
74
- node['class'] = classes.reject { |class_name| class_name == 'hidden' }.join(' ')
75
- end
76
-
77
63
  def ensure_view_context_accessor
78
64
  return if view_context.respond_to?(:tramway_inside_cell=)
79
65
 
data/docs/AGENTS.md CHANGED
@@ -32,7 +32,7 @@ Generated code should:
32
32
  bin/rails g tramway:install
33
33
  ```
34
34
 
35
- - The install generator appends missing gems, copies Tailwind safelist config, ensures `app/assets/tailwind/application.css` imports Tailwind, and writes an `AGENTS.md` guide in the project root.
35
+ - The install generator appends missing gems, copies Tailwind safelist config, ensures `app/assets/tailwind/application.css` imports Tailwind, and adds a Codex instruction to use or install `tramway-skill`.
36
36
 
37
37
  ---
38
38
 
@@ -2,7 +2,6 @@
2
2
 
3
3
  require 'rails/generators'
4
4
  require 'fileutils'
5
- require 'net/http'
6
5
 
7
6
  module Tramway
8
7
  module Generators
@@ -86,50 +85,9 @@ module Tramway
86
85
  @agents_file_path ||= File.join(destination_root, 'AGENTS.md')
87
86
  end
88
87
 
89
- def project_tramway_agents_path
90
- @project_tramway_agents_path ||= File.join(destination_root, 'docs/agents/tramway.md')
91
- end
92
-
93
- def agents_template_url
94
- 'https://raw.githubusercontent.com/Purple-Magic/tramway-skill/refs/heads/main/skills/tramway-skill/agents/tramway.md'
95
- end
96
-
97
- def agents_template_body
98
- return @agents_template_body if defined?(@agents_template_body)
99
-
100
- uri = URI.parse(agents_template_url)
101
- response = Net::HTTP.get_response(uri)
102
- body = response.body.to_s
103
- body = body.dup.force_encoding(Encoding::UTF_8)
104
- @agents_template_body = sanitize_agents_template_body(
105
- body.encode(Encoding::UTF_8, invalid: :replace, undef: :replace, replace: '')
106
- )
107
- end
108
-
109
- def sanitize_agents_template_body(content)
110
- stripped_content = content.strip
111
- section_pattern = /\A#{Regexp.escape(agents_section_start)}\s*\n?(.*?)\n?#{Regexp.escape(agents_section_end)}\s*\z/m # rubocop:disable Layout/LineLength
112
- match = stripped_content.match(section_pattern)
113
-
114
- return stripped_content unless match
115
-
116
- match[1].to_s.strip
117
- end
118
-
119
- def agents_section_start
120
- '## Start of Tramway AGENTS.md'
121
- end
122
-
123
- def agents_section_end
124
- '## End of Tramway AGENTS.md'
125
- end
126
-
127
- def agents_template
128
- @agents_template ||= [agents_section_start, agents_template_body.rstrip, agents_section_end].join("\n")
129
- end
130
-
131
- def agents_section_present?(content)
132
- content.include?(agents_section_start) && content.include?(agents_section_end)
88
+ def codex_agents_instruction
89
+ 'If you are Codex, use the tramway-skill skill for Tramway/Rails work in this project. ' \
90
+ 'If tramway-skill is not installed, install it from https://github.com/Purple-Magic/tramway-skill/.'
133
91
  end
134
92
 
135
93
  def create_tailwind_config
@@ -170,9 +128,9 @@ module Tramway
170
128
  line[/^\s*/] || ' '
171
129
  end
172
130
 
173
- def insert_agents_template(content)
131
+ def append_codex_agents_instruction(content)
174
132
  separator = agents_separator(content)
175
- "#{content}#{separator}#{agents_template}"
133
+ "#{content}#{separator}#{codex_agents_instruction}\n"
176
134
  end
177
135
 
178
136
  def agents_separator(content)
@@ -181,15 +139,6 @@ module Tramway
181
139
  content.end_with?("\n") ? "\n" : "\n\n"
182
140
  end
183
141
 
184
- def replace_agents_section(content)
185
- return insert_agents_template(content) unless agents_section_present?(content)
186
-
187
- content.sub(
188
- /#{Regexp.escape(agents_section_start)}.*?#{Regexp.escape(agents_section_end)}/m,
189
- agents_template
190
- )
191
- end
192
-
193
142
  # rubocop:disable Metrics/MethodLength
194
143
  def append_missing_imports(content)
195
144
  missing_imports = stimulus_controller_imports.reject { |line| content.include?(line) }
@@ -226,6 +175,12 @@ module Tramway
226
175
  updated << insertion
227
176
  updated
228
177
  end
178
+
179
+ def with_agents_update_fallback
180
+ yield
181
+ rescue StandardError => e
182
+ say_status(:warning, "Skipping AGENTS.md update: #{e.message}")
183
+ end
229
184
  end
230
185
  # rubocop:enable Metrics/ModuleLength
231
186
 
@@ -236,36 +191,19 @@ module Tramway
236
191
 
237
192
  desc 'Installs Tramway dependencies and Tailwind safelist configuration.'
238
193
 
239
- # rubocop:disable Metrics/MethodLength
240
194
  def ensure_agents_file
241
195
  with_agents_update_fallback do
242
- if File.exist?(project_tramway_agents_path)
243
- say_status(:info, "Skipping AGENTS.md update because #{project_tramway_agents_path} exists.")
244
- return
245
- end
246
-
247
- say_status(
248
- :info,
249
- "Tramway will replace the content between \"#{agents_section_start}\" and " \
250
- "\"#{agents_section_end}\" in AGENTS.md."
251
- )
252
-
253
- return create_file(agents_file_path, "#{agents_template}\n") unless File.exist?(agents_file_path)
196
+ return create_file(agents_file_path, "#{codex_agents_instruction}\n") unless File.exist?(agents_file_path)
254
197
 
255
198
  content = File.read(agents_file_path)
256
- updated = replace_agents_section(content)
199
+ return if content.include?(codex_agents_instruction)
200
+
201
+ updated = append_codex_agents_instruction(content)
257
202
  return if updated == content
258
203
 
259
204
  File.write(agents_file_path, updated, mode: 'w:UTF-8')
260
205
  end
261
206
  end
262
- # rubocop:enable Metrics/MethodLength
263
-
264
- def with_agents_update_fallback
265
- yield
266
- rescue StandardError => e
267
- say_status(:warning, "Skipping AGENTS.md update: #{e.message}")
268
- end
269
207
 
270
208
  def ensure_dependencies
271
209
  missing_dependencies = gem_dependencies.reject do |dependency|
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tramway
4
- VERSION = '3.0.4'
4
+ VERSION = '3.0.4.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: 3.0.4
4
+ version: 3.0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - kalashnikovisme
@@ -230,6 +230,7 @@ files:
230
230
  - app/components/tramway/pagination/prev_page_component.rb
231
231
  - app/components/tramway/table/cell_component.html.haml
232
232
  - app/components/tramway/table/cell_component.rb
233
+ - app/components/tramway/table/content_cells.rb
233
234
  - app/components/tramway/table/header_component.html.haml
234
235
  - app/components/tramway/table/header_component.rb
235
236
  - app/components/tramway/table/row/preview_component.html.haml