Skip to content

Frontend

Server HTML render करता है; Turbo उसे SPA जैसा अनुभव देता है; Stimulus छोटे-छोटे behaviors जोड़ता है; daisyUI components देता है। Replay pages की तुलना visible text से करता है, इसलिए हर content और हर flow बनाए रखें; markup आपकी मर्ज़ी का है।

Setup (ज़्यादातर काम front-door कर देता है)

  • app/assets/tailwind/application.css:
    css
    @import "tailwindcss";
    @plugin "./daisyui.mjs" { themes: light --default, dark --prefersdark; }
    
    daisyui.mjs और daisyui-theme.mjs इसके बगल में रहते हैं (daisyUI releases से download किए गए; Tailwind का standalone CLI इन्हें बिना Node के load करता है)। Views edit करते समय bin/dev (या bin/rails tailwindcss:watch) चलाएँ।
  • Theme: layout में <html data-theme="light">; theme switcher एक Stimulus controller है जो document.documentElement.dataset.theme set करता है और उसे cookie में store करता है।
  • Layout: original के links के साथ daisyUI navbar (या side navigation के लिए drawer), container mx-auto p-4 के साथ main, flash messages alert alert-success / alert-error के रूप में।

Mapping

Original Rails
Page / route component (React, Vue, Angular, Svelte, Next.js page) Controller action + app/views/<resource>/<action>.html.erb
दोबारा इस्तेमाल होने वाला component (<ProductCard>) Partial _product_card.html.erb (या logic के साथ दोहराए जाने पर ViewComponent)
Props Partial locals: render "product_card", product: p
Client router links (<Link>, router.push) link_to / button_to; SPA navigation Turbo Drive करता है
सिर्फ़ UI state के लिए useState / ref (open, tab, toggle) static values और targets वाला Stimulus controller
Fetch करके render (useEffect(fetch), SWR, React Query) Server पर render करें; lazy हिस्से <turbo-frame src=... loading="lazy"> में
Client-side submit + JSON API वाला form form_with model:; errors status: :unprocessable_entity के साथ फिर से render होते हैं
Optimistic update / live list Turbo Stream response (turbo_stream.append/replace/remove)
WebSocket / polling updates turbo_stream_from @room + model पर broadcasts_to (Action Cable)
Modal Stimulus controller से खुलने वाला daisyUI modal (<dialog>), content turbo-frame id="modal" में
Infinite scroll / "load more" अगले page के लिए loading="lazy" वाला Turbo Frame
Debounced search-as-you-type Stimulus controller जो 300 ms बाद form submit करता है; results Turbo Frame में
Client-side validation (zod, yup) ActiveModel validations, HTML5 required/pattern; daisyUI validator class
CSS modules / styled-components / Bootstrap classes Tailwind utilities + daisyUI components
Global store (Redux, Pinia, Context) Server ही store है; हर user की state के लिए session; cross-controller UI के लिए Stimulus outlets
i18n strings config/locales/*.yml + t(".key")
Server templates (Jinja, Thymeleaf, Blade, EJS, Razor, Go templates) ERB: {{ x }} -> <%= x %>, {% for %} -> <% each do %>, blocks/sections -> content_for / yield, includes -> partials

किन daisyUI components का इस्तेमाल करें

btn (btn-primary, btn-ghost, btn-sm), card (card-body, card-title, card-actions), navbar, menu, drawer, table (table-zebra), badge, alert, modal, tabs, dropdown, fieldset + label के साथ input/select/textarea (daisyUI 5), grouped buttons और pagination के लिए join, dashboards के लिए stat, wizards के लिए steps, flash के लिए toast, lazy frames के लिए skeleton और loading।

Rules

  • Original जैसे ही URLs, वही page titles (content_for :title), वही headings, labels, button text, table columns और empty states: replay text जाँचता है।
  • Forms उन्हीं paths पर उन्हीं field names के साथ post करते हैं, जब तक कोई ADR कुछ और न कहे; name attributes रखें ताकि recorded POST cases चलते रहें।
  • Original ने पहली load पर जो कुछ दिखाया, वह सब server-render करें; सिर्फ़ वही चीज़ें lazy frames बनती हैं जो original में lazy थीं।
  • Accessibility: असली <button>/<a>, <label for>, Turbo Stream targets पर aria-live, modals में focus ले जाएँ। सही element इस्तेमाल करने पर daisyUI components accessible होते हैं।
  • कोई inline <script> नहीं। Behavior app/javascript/controllers/*_controller.js में जाता है (bin/rails generate stimulus name), importmap से pinned।
  • जिस भी flow में JavaScript behavior है, उसके लिए system tests (bin/rails generate system_test)।
इस page को GitHub पर edit करें →