Module: JsxRosetta::PagesRouting

Defined in:
lib/jsx_rosetta/pages_routing.rb

Overview

Walks a Next.js-style ‘pages/` directory tree and produces a Rails `config/routes.rb` skeleton.

The route table is derived from path shape alone — no JS parsing. Next.js filesystem routing is fully encoded in directory layout, so the input here is ‘Dir.glob` plus the file extension filter.

Slice 1 of plans/nextjs_pages_to_rails.md: routes only. No file moves, no controller skeletons, no class renames.

Defined Under Namespace

Modules: ControllerEmitter, Emitter, Naming, Scanner Classes: ControllerFile, HrefRewriter, Route, Skipped

Constant Summary collapse

SKIPPED_LEAVES =
{
  "_document" => "Next.js HTML document — typically subsumed by Rails layout"
}.freeze
ERROR_PAGE_LEAVES =

Next.js error pages — leaf names that map to an ‘errors` controller with a standard action name. Routed via `config.exceptions_app` in Rails, not via the regular draw block.

{
  "_error" => "fallback",
  "404" => "not_found",
  "500" => "internal_server_error"
}.freeze
LAYOUT_LEAVES =

Leaf names that resolve to a Rails application layout, not a page. ‘_app.tsx` lands as `app/views/layouts/<action>.rb`. `_document.tsx` stays in SKIPPED_LEAVES — Rails owns the surrounding HTML scaffold.

{
  "_app" => "application"
}.freeze
DEFAULT_EXTENSIONS =
%w[.tsx .jsx].freeze

Class Method Summary collapse

Class Method Details

.emit(routes:, skipped:, source_dir:, generated_at: nil) ⇒ Object



74
75
76
# File 'lib/jsx_rosetta/pages_routing.rb', line 74

def self.emit(routes:, skipped:, source_dir:, generated_at: nil)
  Emitter.emit(routes: routes, skipped: skipped, source_dir: source_dir, generated_at: generated_at)
end

.emit_controllers(routes:) ⇒ Object



78
79
80
# File 'lib/jsx_rosetta/pages_routing.rb', line 78

def self.emit_controllers(routes:)
  ControllerEmitter.emit(routes: routes)
end

.scan(dir, extensions: DEFAULT_EXTENSIONS) ⇒ Object



70
71
72
# File 'lib/jsx_rosetta/pages_routing.rb', line 70

def self.scan(dir, extensions: DEFAULT_EXTENSIONS)
  Scanner.scan(dir, extensions: extensions)
end