Class: DocsKit::Generators::PageGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/docs_kit/page/page_generator.rb

Overview

rails g docs_kit:page TITLE --group=GROUP

Scaffolds one docs page — the Phlex page class AND its one-line registry entry, both derived from the title — so adding a page is one command plus writing content, not the old ceremony (a 4-level-nested class in one file plus a hand-synced registry line in another, either half easy to forget).

rails g docs_kit:page "Getting Started" --group=Guide
→ app/views/docs/pages/getting_started.rb  (compact class form)
→ injects `page "Getting Started", group: "Guide"` into Doc

Every derivation is overridable: --slug, --view, --eyebrow, --registry. A legacy hash-entries registry is left untouched (an instruction is printed instead of corrupting it), and re-running is idempotent.

Instance Method Summary collapse

Instance Method Details

#create_page_fileObject



39
40
41
# File 'lib/generators/docs_kit/page/page_generator.rb', line 39

def create_page_file
  template "page.rb.erb", "app/views/docs/pages/#{view_name.underscore}.rb"
end

#register_pageObject



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/generators/docs_kit/page/page_generator.rb', line 43

def register_page
  path = registry_path
  rel = relative(path)
  line = registry_line
  return say_status(:skip, "#{rel} not found — add `#{line}` manually", :yellow) unless File.exist?(path)

  source = File.read(path)
  return say_status(:skip, legacy_instruction(rel), :yellow) if legacy_entries?(source)
  return say_status(:identical, "#{rel} already registers #{title.inspect}", :blue) if source.include?(line)

  inject_into_file path, "  #{line}\n", after: registry_anchor(source)
end