news 2026/7/10 22:54:58

教程快速入门_tutorial-quickstart

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
教程快速入门_tutorial-quickstart

以下为本文档的中文说明

tutorial-quickstart 是一个面向 TutorialKit 框架的快速入门技能,提供从项目搭建、编写第一课到部署上线的端到端指南。该技能基于 Ruby 和 Rails 技术栈,使用 TutorialKit 和 WebAssembly 技术在浏览器中运行完整的 Rails 开发环境。其核心用途是帮助教育内容创作者和技术写作者快速创建交互式的 Rails 编程教程,让学习者在浏览器中直接编写和运行 Rails 代码,无需在本地搭建开发环境。该技能的核心特点包括:一键脚手架——使用 npx create-tutorialkit-rb 命令快速创建项目,支持交互式提示和 --defaults 跳过模式,可选择 Vercel、Netlify 或 Cloudflare 作为托管服务商。交互式学习环境——教程在浏览器中运行完整的 Rails 开发环境(基于 WebAssembly),学习者可以通过嵌入式终端和代码编辑器直接实操。预设的 rails-app 模板——包含完整的用户认证系统(基于 Rails 8 的认证生成器模式)、会话登录、快速登录功能(无需密码,一键登录)、CSS 设计系统(基于 BEM 命名规范和 CSS 自定义属性)、种子数据(预置演示用户)、布局组件(导航栏、Flash 消息、容器包装器)等开箱即用的功能。完整的课程体系支持——通过目录结构组织教程内容:根目录 meta.md 定义教程元数据,part 元数据定义章节,lesson 目录包含课程内容、起始代码、参考答案代码,支持 WebContainer 运行时配置、预览端口设置和命令执行顺序控制。品牌定制——支持自定义 Logo(亮色/暗色模式)、Favicon、强调色系统、OG Meta 社交分享图、标题栏和 GitHub 链接等外观元素。部署自动化——自动处理 WebContainer 必需的 COEP/COOP HTTP 头部配置。使用场景包括技术博主创建在线的 Rails 编程课程、企业内部搭建 Ruby 技术培训平台、开源项目制作交互式入门教程,以及教育机构开展远程编程教学。该技能与 tutorial-content-structure、tutorial-lesson-config 等配套技能协同工作。


Tutorial Quickstart

End-to-end guide: scaffold a project, write your first lesson, and deploy.

Step 1: Scaffold

npx create-tutorialkit-rb my-tutorial

The CLI prompts for:

PromptDefaultNotes
Tutorial namerandom (e.g., “fierce-turtle”)Used aspackage.jsonname
Directory./{name}Where files are created
Hosting providerSkipVercel, Netlify, or Cloudflare — adds COEP/COOP headers
Package managernpmnpm, yarn, pnpm, or bun
Init git repo?YesCreates initial commit
Edit Gemfile?YesOpensruby-wasm/Gemfilein$EDITOR

Skip all prompts with--defaults, or pass flags directly:

npx create-tutorialkit-rb my-tutorial-ppnpm--providernetlify--git

What Gets Created

my-tutorial/ ├── src/ │ ├── content/tutorial/ ← Your tutorial content goes here │ │ ├── meta.md ← Tutorial root config (already set up) │ │ └── 1-getting-started/ ← Sample part with starter lessons │ ├── templates/default/ ← WebContainer runtime (don't modify) │ └── components/ ← UI components ├── ruby-wasm/ │ └── Gemfile ← Add gems here, then rebuild WASM ├── bin/build-wasm ← Rebuilds the WASM binary ├── astro.config.ts └── package.json

Step 2: Add Your Gems

Editruby-wasm/Gemfileto include the gems your tutorial needs:

# ruby-wasm/Gemfilesource"https://rubygems.org"gem"wasmify-rails","~> 0.4.0"gem"rails","~> 8.0.0"# Your tutorial's gemsgem"action_policy"gem"devise"

Then build the WASM binary:

npmrun build:wasm# Takes up to 20 minutes on first run

Subsequent rebuilds are faster thanks to caching, but still take a few minutes.

Step 3: Start the Dev Server

npmrun dev# Starts at http://localhost:4321/

The sample tutorial loads immediately. You’ll see the starter lessons from the scaffold.

Step 4: Write Your First Lesson

4a. Create the Directory Structure

src/content/tutorial/ ├── meta.md ← Already exists (tutorial root) └── 1-basics/ ├── meta.md ← Part metadata └── 1-hello-rails/ ├── content.md ← Your lesson ├── _files/ ← Starting code │ └── workspace/ │ └── app/ │ └── controllers/ │ └── pages_controller.rb └── _solution/ ← Solution code └── workspace/ └── app/ └── controllers/ └── pages_controller.rb

4b. Write the Part Metadata

# src/content/tutorial/1-basics/meta.md---type:parttitle:The Basics---

4c. Write the Lesson

# src/content/tutorial/1-basics/1-hello-rails/content.md---type:lessontitle:Hello Railsfocus:/workspace/app/controllers/pages_controller.rbpreviews:[3000]mainCommand:['node scripts/rails.js server','Starting Rails server']prepareCommands:-['npm install','Preparing Ruby runtime']-['node scripts/rails.js db:prepare','Prepare development database']terminalBlockingPrepareCommandsCount:2custom:shell:workdir:'/workspace'---# Hello RailsOpen `app/controllers/pages_controller.rb` and add a `home` action:\\`\\`\\`ruby title="app/controllers/pages_controller.rb" ins={2-4}class PagesController < ApplicationController def homerender plain:"Hello from Rails on WebAssembly!"end end \\`\\`\\` Visit the preview to see your message.

4d. Add Starting Files

Put a skeleton file in_files/:

# _files/workspace/app/controllers/pages_controller.rbclassPagesController<ApplicationController# Add your action hereend

4e. Add

Solution Files

Put the completed code in_solution/:

# _solution/workspace/app/controllers/pages_controller.rbclassPagesController<ApplicationControllerdefhomerender plain:"Hello from Rails on WebAssembly!"endend

4f. Delete the Sample Content

Remove the scaffold’s starter lessons once you have your own:

rm-rfsrc/content/tutorial/1-getting-started/rm-rfsrc/content/tutorial/2-controllers/

Therails-appTemplate

The scaffold includes a pre-builtrails-apptemplate atsrc/templates/rails-app/with authentication, styling, and seed data ready to go. Most tutorials should extend this template rather than building from scratch.

What’s Included

  • Authentication— session-based login viaAuthenticationconcern (app/controllers/concerns/authentication.rb)
  • Quick login— password-free login buttons on the sign-in page for tutorial convenience
  • CSS design system— modern BEM-based stylesheet with CSS custom properties
  • Seed users— Alice and Bob created indb/seeds.rb
  • Layout— nav bar with brand, user name, login/logout; flash messages;.containerwrapper

Authentication Flow

The template uses Rails 8’s authentication generator pattern:

  • Authenticationconcern addsrequire_authenticationas abefore_action
  • Controllers opt out withallow_unauthenticated_access
  • Current.useris available everywhere viaCurrent.session.user
  • authenticated?helper works in both controllers and views

Quick loginlets tutorial users sign in with one click instead of typing credentials:

  • SessionsController#newpopulates@preauthenticate_users(all users by default)
  • SessionsController#preauthenticatelogs in by user ID (no password)
  • Thesessions/_preauthenticate_user.html.erbpartial renders each quick-login button
  • Route:post :preauthenticate, on: :collectionunderresource :session

To customize quick-login users in a lesson, override the sessions controller in_files/:

# _files/workspace/app/controllers/sessions_controller.rbclassSessionsController<ApplicationController allow_unauthenticated_access only:%i[new create preauthenticate]defnew# Show only specific users for this lesson@preauthenticate_users=User.where(role:"agent").order(:name)end# ... rest inherited from templateend

CSS Design System

The template’sapplication.cssuses pure CSS with custom properties and BEM naming. Use these classes in your lesson ERB files — no extra setup needed.

CSS Custom Properties (:rootvariables):

CategoryVariablesExample
Colors--color-primary,--color-danger,--color-success,--color-warning,--color-infocolor: var(--color-primary)
Text--color-text,--color-text-muted,--color-text-inversecolor: var(--color-text-muted)
Background--color-bg,--color-bg-white,--color-borderbackground: var(--color-bg)
Spacing--space-xsthrough--space-2xlpadding: var(--space-md)
Typography--font-sans,--font-mono,--font-size-smthrough--font-size-3xlfont-size: var(--font-size-lg)
Radius--radius-smthrough--radius-xlborder-radius: var(--radius-md)
Shadows--shadow-sm,--shadow-mdbox-shadow: var(--shadow-sm)

BEM Components:

ComponentClassesUsage
Button.btn,.btn--primary,.btn--danger,.btn--small,.btn--linkLinks, submits, actions
Input.input,.input--errorText fields, selects, textareas
Card.card,.card__header,.card__body,.card__footerContent containers
Alert.alert,.alert--error,.alert--success,.alert--info,.alert--warningFlash messages, notices
Badge.badge,.badge--primary,.badge--success,.badge--danger,.badge--warningStatus labels, role tags
Nav.nav,.nav__brand,.nav__link,.nav__userTop navigation (in layout)
Form
.form__group,.form__label,.form__hint,.form__errors,.form__actionsForm layout
Table.tableData tables with hover rows
Page header.page-headerTitle + action button row
Hero.hero,.hero__title,.hero__subtitle,.hero__actionsLanding/home pages
Quick login.quick-login,.quick-login__btn,.quick-login__name,.quick-login__emailSign-in page
Utility.text-muted,.text-sm,.mt-md,.mb-md,.inline-actions,.containerSpacing, text helpers

Customizing the Demo App for Your Domain

To turn the generic demo app into your tutorial’s domain (e.g., a Help Desk, a Store, etc.):

1. Rename the app moduleinconfig/application.rb:

moduleHelpdesk# was DemoAppclassApplication<Rails::Application

2. Add your models.Create migrations indb/migrate/and models inapp/models/. Updatedb/schema.rbto match.

3. Add controllers and views.Put CRUD controllers inapp/controllers/and ERB views inapp/views/. Use the BEM classes from the CSS design system.

4. Update routesinconfig/routes.rb.

5. Update seedsindb/seeds.rbwith domain-specific sample data. Keep the default passwords3cr3tfor all users so the quick-login flow works.

6. Update the layout— change the brand name inapp/views/layouts/application.html.erb, add nav links for your resources.

7. Update the home page— replace the hero content inapp/views/home/index.html.erb.

Step 5: Use a Template for Pre-Built State

If your lesson needs an existing Rails app (not just an empty workspace), create a template:

src/templates/my-app/ ├── .tk-config.json → { "extends": "../default" } └── workspace/ ├── app/ ├── config/ ├── db/ └── ...

Then reference it from your lesson’s_files/.tk-config.json:

{"extends":"../../../../../templates/my-app"}

See therails-file-managementskill for details on template inheritance.

Step 6: Deploy

Tutorials needCross-Origin-Embedder-PolicyandCross-Origin-Opener-Policyheaders for WebContainers to work. If you chose a hosting provider during scaffold, these are already configured.

Build for Production

npmrun build# Produces a static site in dist/

Manual Header Configuration

If you didn’t choose a provider during scaffold, add these headers to every response:

Cross-Origin-Embedder-Policy: require-corp Cross-Origin-Opener-Policy: same-origin
Vercel (vercel.json)
{"headers":[{"source":"/(.*)","headers":[{"key":"Cross-Origin-Embedder-Policy","value":"require-corp"},{"key":"Cross-Origin-Opener-Policy","value":"same-origin"}]}]}
Netlify (netlify.toml)
[[headers]] for = "/*" [headers.values] Cross-Origin-Embedder-Policy = "require-corp" Cross-Origin-Opener-Policy = "same-origin"
Cloudflare (public/_headers)
/* Cross-Origin-Embedder-Policy: require-corp Cross-Origin-Opener-Policy: same-origin

Customizing Look & Feel (Branding)

To match your tutorial’s branding to your project’s documentation site, update these files:

Logos

Replacepublic/logo.svg(light mode) andpublic/logo-dark.svg(dark mode) with your project’s logo SVG. Use a dark fill (e.g.,#0F4D8A) for the light-mode version and a light fill (e.g.,#E4E6E9) for the dark-mode version.

Title in Top Bar

Editsrc/components/TopBar.astro— add a<span>after the logo images inside the<a>tag:

<spanclass="ml-2 text-sm font-medium text-tk-elements-topBar-iconButton-iconColor whitespace-nowrap">Your Tutorial Title</span>

Favicon

Replacepublic/favicon.svgwith your project’s icon. Optionally add apublic/favicon.icofor broader browser support.

Accent Colors (UnoCSS Theme)

Override theaccentpalette inuno.config.tsto change buttons, links, active tabs, and badges site-wi
de:

import{defineConfig}from'@tutorialkit-rb/theme';exportdefaultdefineConfig({theme:{colors:{accent:{50:'#EFF6FF',100:'#E5F0FF',200:'#B6D4FF',300:'#75B5FF',400:'#4DA6FF',// dark mode accent500:'#0E7EF1',// primary interactive600:'#0F4D8A',// primary brand700:'#0C3F72',800:'#09325A',900:'#072848',950:'#041A30',},},},content:{pipeline:{include:'**'},},});

Generate your scale from your brand’s primary color. The600slot is the main brand color;500is for hover/interactive states;400is used in dark mode.

Component Hardcoded Colors

Some components use hardcoded Tailwind color classes instead of theme tokens. Search for and replace these:

  • src/components/HelpDropdown.tsx— Reload button usesbg-blue-600. Change tobg-accent-600 hover:bg-accent-700.
  • src/components/HeadTags.astro— Rails path link colors. Update hex values to match your brand.

Rails Demo App CSS

Update the primary color insrc/templates/rails-app/workspace/app/assets/stylesheets/application.css:

:root{--color-primary:#0F4D8A;/* your brand color */--color-primary-hover:#0C3F72;/* darker shade */--color-primary-light:#EFF6FF;/* tinted background */}

OG Meta (Social Sharing Image)

Add Open Graph meta tags so your tutorial shows a rich preview when shared on social media, Slack, etc.

1. Generate a cover image.Use a tool like myogimage.com to create a 1200×630 OG image with your tutorial title and branding.

2. Save it aspublic/cover.png.

3. Add themetakeyto your tutorial rootsrc/content/tutorial/meta.md:

---type:tutorialmeta:image:/cover.pngtitle:Your Tutorial Titledescription:|A short description of what your tutorial teaches# ... rest of frontmatter---

Themetafields map to standard OG tags (og:image,og:title,og:description) and are rendered in<head>automatically by TutorialKit.

GitHub Link

Update the repo URL insrc/components/GitHubLink.astro:

<ahref="https://github.com/your-org/your-repo"...>

Common Issues

ProblemCauseFix
build:wasmfailsMissing WASI SDK or build toolsCheckrbwasmprerequisites
Preview shows nothingServer not startedAddmainCommand: ['node scripts/rails.js server', ...]
Terminal stuck on “Preparing”WASM binary not builtRunnpm run build:wasmfirst
Files not appearing in editorWrong pathAll Rails files must be underworkspace/<app>/
Database emptyNodb:preparein prepareCommandsAdd['node scripts/rails.js db:prepare', '...']
Deploy fails with blank pageMissing COEP/COOP headersAdd headers per provider instructions above

Next Steps

Want to…See skill
Structure parts, chapters, lessonstutorial-content-structure
Configure frontmatter optionstutorial-lesson-config
Organize Rails files properlyrails-file-management
Check if a feature works in WASMrails-wasm-author-constraints
Get a recipe for a specific lesson typerails-lesson-recipes
48:T5d0,Use this skill whenever starting a new tutorial project, understanding the end-to-end
workflow from scaffold to deployment, or working with the rails-app template’s built-in
features. Trigger when the user says ‘new tutorial’, ‘create tutorial’, ‘getting started’,
‘npx create-tutorialkit-rb’, ‘scaffold’, ‘first lesson’, ‘deploy tutorial’, ‘build:wasm’,
‘COEP headers’, ‘COOP headers’, ‘hosting setup’, ‘CSS classes’, ‘BEM components’,
‘design system’, ‘application.css’, ‘quick login’, ‘preauthenticate’, 'authentication
setup’, ‘customize demo app’, ‘seed users’, ‘rails-app template’, ‘branding’, ‘logo’,
‘favicon’, ‘accent color’, ‘theme color’, ‘look and feel’, ‘customize colors’,
‘OG image’, ‘og:image’, ‘cover image’,
‘social preview’, ‘meta tags’, ‘og meta’, or asks
how to set up, build, style, brand, or deploy a Rails tutorial from scratch — even if
they don’t explicitly mention quickstart. This skill provides the exact CLI commands,
project structure, WASM build steps, rails-app template features (CSS design system,
authentication, quick login), branding customization (logos, favicons, accent colors,
top bar title, component colors, OG meta for social sharing), demo app customization
steps, deployment header configuration, and common issue troubleshooting. Do NOT attempt project setup or deployment without this skill. Do NOT
use for detailed frontmatter reference (use tutorial-lesson-config) or WASM compatibility
questions (use rails-wasm-author-constraints).
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/7/10 22:53:14

从 Ladybird 的转型看开源项目的“成人礼”:放弃 SVN 与 C++ 的背后逻辑

从 Ladybird 的转型看开源项目的“成人礼”&#xff1a;放弃 SVN 与 C 的背后逻辑 在开源浏览器的浩瀚星海中&#xff0c;有一个名字近期格外耀眼&#xff0c;它不是因为发布了什么惊天动地的新功能&#xff0c;而是因为它做出了一个令许多开发者咋舌的决定&#xff1a;推倒重来…

作者头像 李华
网站建设 2026/7/10 22:50:25

后端轻量化多平台电商比价监控系统|架构+源码+避坑

&#x1f4c1; 多平台比价系统工程目录&#xff08;开源自用版&#xff5c;无商业化模块&#xff09;剥离付费SDK、引流组件、商业部署模块&#xff0c;纯技术自研架构&#xff0c;适配个人技术实践、内部业务自用&#xff0c;遵循电商robots协议与开放平台规范&#xff0c;规避…

作者头像 李华
网站建设 2026/7/10 22:49:21

激光三角 光平面标定

零、简介激光三角系统光平面是什么&#xff1f;如图所示&#xff1a;红色的区域就是光平面那我们看下数学模型是啥为什么不能直接知道&#xff1f;因为&#xff1a;激光器安装以后&#xff1a;CameraLaser安装误差↓不知道真正光平面在哪里所以&#xff1a;必须标定。一、总概括…

作者头像 李华
网站建设 2026/7/10 22:48:36

KMP 正式支持 SwiftPM:CocoaPods 迁移配置指南

KMP 模块里 CocoaPods 如何依赖迁到 Swift Package Manager&#xff1f; 页面里的入口是 Junie Kotlin AI Skill&#xff0c;但迁移本身仍然要回到 Gradle、Xcode 和 Kotlin imports 这几个具体文件。 SwiftPM import 现在还是 Alpha&#xff0c;示例要求 KMP Gradle 插件使用…

作者头像 李华
网站建设 2026/7/10 22:48:04

仅影响左撇子的WordPress Bug,七年后终迎修复方案!

仅影响左撇子用户的WordPress Bug&#xff1a;七年后终迎修复方案&#xff01;真的&#xff0c;有些同胞&#xff08;包括男性和女性&#xff09;习惯与众不同。多数人会用右手拇指滑动屏幕&#xff0c;这正常且恰当&#xff0c;但有一小撮不幸的人习惯用左手。瞧&#xff0c;写…

作者头像 李华
网站建设 2026/7/10 22:48:06

网站建设公司选型核心逻辑解析,附10家优秀网站服务商推荐

在数字经济时代&#xff0c;企业官网已从简单的“形象展示窗口”升级为“业务增长引擎”。2026年行业数据显示&#xff0c;68%的企业因建站决策失误导致客户流失&#xff0c;而经过专业优化的网站能将转化率提升40%以上。 企业主在评估网站建设服务时&#xff0c;首要关注技术…

作者头像 李华