living_design_system 0.1.0
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 +7 -0
- data/CHANGELOG.md +17 -0
- data/LICENSE.txt +21 -0
- data/README.md +314 -0
- data/app/controllers/living_design_system/application_controller.rb +13 -0
- data/app/controllers/living_design_system/components_controller.rb +33 -0
- data/app/controllers/living_design_system/pages_controller.rb +14 -0
- data/app/helpers/living_design_system/docs_helper.rb +66 -0
- data/app/helpers/living_design_system/navigation_helper.rb +19 -0
- data/app/views/living_design_system/components/example.html.erb +2 -0
- data/app/views/living_design_system/components/show.html.erb +64 -0
- data/app/views/living_design_system/pages/index.html.erb +5 -0
- data/app/views/living_design_system/shared/_nav_link.html.erb +12 -0
- data/app/views/living_design_system/shared/_navigation.html.erb +15 -0
- data/lib/generators/living_design_system/install/install_generator.rb +23 -0
- data/lib/generators/living_design_system/install/templates/getting_started.html.erb +20 -0
- data/lib/generators/living_design_system/install/templates/initializer.rb +42 -0
- data/lib/living_design_system/catalog.rb +88 -0
- data/lib/living_design_system/component_doc.rb +210 -0
- data/lib/living_design_system/configuration.rb +29 -0
- data/lib/living_design_system/engine.rb +23 -0
- data/lib/living_design_system/example_sources.rb +24 -0
- data/lib/living_design_system/nav_link.rb +40 -0
- data/lib/living_design_system/routing.rb +13 -0
- data/lib/living_design_system/styles.css +33 -0
- data/lib/living_design_system/version.rb +3 -0
- data/lib/living_design_system.rb +33 -0
- metadata +135 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 421bae3686aa0ed348865fc0a0d030c75683f8215ddae56124c2fcfe63f91923
|
|
4
|
+
data.tar.gz: 74d4f274a30fd3b3059259b20ad3d197bfd550a50132c0fee3a4900929cacd37
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 570a5fd14e065138b7eb15c55103de9297e73b55474df7707bc46bd269a585202098a31e3eee4b2ac1b641b173b15f58df935ec0da665517e965d93285ad7828
|
|
7
|
+
data.tar.gz: 0e90b1112bdd986a1f230d878c93796f69be2a8230404272f51dbc8bdc3b356b2787e43821128698048b7fe92b032375367baf56e0c5c417dce760d679e6bc45
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0 (2026-12-05)
|
|
4
|
+
|
|
5
|
+
The first release.
|
|
6
|
+
|
|
7
|
+
- Component pages generated from the comment block above each component: its description,
|
|
8
|
+
`@note`, `@example`s rendered live with their source, and an arguments table built from
|
|
9
|
+
`initialize` and `@param`.
|
|
10
|
+
- Works with ViewComponent and Phlex components, and depends on neither.
|
|
11
|
+
- Pages for the parts of a design system that aren't a single component, written as
|
|
12
|
+
ordinary views.
|
|
13
|
+
- Examples render inline in the app's own layout, and each has a page of its own.
|
|
14
|
+
- `mount_living_design_system` route macro and an install generator.
|
|
15
|
+
- Navigation partial and helpers for the app's own layout.
|
|
16
|
+
- A scoped stylesheet in a cascade layer, with CSS variables to restyle it.
|
|
17
|
+
- `example_sources_path`, a file of every example's source for Tailwind to scan.
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Andrew Havens
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
# Living Design System
|
|
2
|
+
|
|
3
|
+
A living design system for Rails, generated from the comment blocks above your components.
|
|
4
|
+
|
|
5
|
+
Write an example in a comment, and you get a page that renders it live inside your app,
|
|
6
|
+
with its source and a table of the component's arguments. There are no preview files to
|
|
7
|
+
write and nothing to keep in sync, because each page is built from the component itself.
|
|
8
|
+
|
|
9
|
+
| ViewComponent and plain CSS | Phlex and Tailwind |
|
|
10
|
+
| --- | --- |
|
|
11
|
+
|  |  |
|
|
12
|
+
|
|
13
|
+
The same pages in two different apps. Each takes its layout, fonts and colors from the
|
|
14
|
+
app it runs in, and both are in this repository (see Development).
|
|
15
|
+
|
|
16
|
+
## It takes one comment
|
|
17
|
+
|
|
18
|
+
```ruby
|
|
19
|
+
# Buttons start an action: saving a form, opening a dialog, moving to the next step.
|
|
20
|
+
#
|
|
21
|
+
# @note Use one primary button per view.
|
|
22
|
+
#
|
|
23
|
+
# @example Primary and secondary
|
|
24
|
+
# <%= render(ButtonComponent.new) { "Save changes" } %>
|
|
25
|
+
# <%= render(ButtonComponent.new(variant: :secondary)) { "Cancel" } %>
|
|
26
|
+
#
|
|
27
|
+
# @example Disabled
|
|
28
|
+
# <%= render(ButtonComponent.new(disabled: true)) { "Save changes" } %>
|
|
29
|
+
#
|
|
30
|
+
# @param variant [Symbol] <%= one_of(ButtonComponent::VARIANTS) %>
|
|
31
|
+
# @param disabled [Boolean] Dims the button and stops it responding
|
|
32
|
+
class ButtonComponent < ViewComponent::Base
|
|
33
|
+
VARIANTS = %i[primary secondary ghost danger].freeze
|
|
34
|
+
DEFAULT_VARIANT = :primary
|
|
35
|
+
|
|
36
|
+
def initialize(variant: DEFAULT_VARIANT, disabled: false)
|
|
37
|
+
# ...
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Open `/design-system/components/button`, and that comment is a page:
|
|
41
|
+
|
|
42
|
+
- the description and the note
|
|
43
|
+
- each example, rendered live, with its highlighted source underneath
|
|
44
|
+
- every argument to `initialize`, with its type, its description, and its default read
|
|
45
|
+
from the code (`:primary`, not `DEFAULT_VARIANT`)
|
|
46
|
+
- the component's slots
|
|
47
|
+
|
|
48
|
+
These are standard [YARD](https://yardoc.org) tags, so there's no new syntax to learn, and
|
|
49
|
+
an example is the same ERB you'd write in a view.
|
|
50
|
+
|
|
51
|
+
## Why it works this way
|
|
52
|
+
|
|
53
|
+
- **No preview files.** An example lives in the comment above the class it documents.
|
|
54
|
+
There's no second file for each component, and no preview class to write just to look
|
|
55
|
+
at one.
|
|
56
|
+
- **It can't go stale.** Examples render from the code that ships, and arguments and
|
|
57
|
+
defaults are read from `initialize`. Rename an argument and its page changes. Break an
|
|
58
|
+
example and a test that visits its page fails.
|
|
59
|
+
- **It looks like your app.** Examples render inline, in your own layout, with your CSS,
|
|
60
|
+
helpers and controller stack. There are no iframes.
|
|
61
|
+
- **There's room for the rest.** Color, typography and anything else that isn't a single
|
|
62
|
+
component go in pages, which are ordinary views that can render live components too.
|
|
63
|
+
|
|
64
|
+
It works with [ViewComponent](https://viewcomponent.org) and [Phlex](https://www.phlex.fun)
|
|
65
|
+
components, and depends on neither. It needs Ruby 3.2 or later and Rails 7.1 or later, and
|
|
66
|
+
is tested with ViewComponent 3 and 4 and Phlex 2.
|
|
67
|
+
|
|
68
|
+
## Getting started
|
|
69
|
+
|
|
70
|
+
```ruby
|
|
71
|
+
# Gemfile
|
|
72
|
+
gem "living_design_system"
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
```sh
|
|
76
|
+
bundle install
|
|
77
|
+
bin/rails generate living_design_system:install
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Then open `/design-system`. Every component in `app/components` is already listed, with
|
|
81
|
+
its arguments and slots. Add an `@example` to one and reload to see it render.
|
|
82
|
+
|
|
83
|
+
The generator:
|
|
84
|
+
|
|
85
|
+
- adds `config/initializers/living_design_system.rb`, with every option commented out
|
|
86
|
+
- adds `mount_living_design_system at: "/design-system" if Rails.env.local?` to `config/routes.rb`,
|
|
87
|
+
so it's served in development and test only
|
|
88
|
+
- creates `app/views/design_system/pages/` with a starter page
|
|
89
|
+
|
|
90
|
+
To serve it elsewhere, such as on staging or behind a login, change the condition to suit
|
|
91
|
+
your app. To set it up by hand, add the route line yourself:
|
|
92
|
+
|
|
93
|
+
```ruby
|
|
94
|
+
Rails.application.routes.draw do
|
|
95
|
+
mount_living_design_system at: "/design-system" if Rails.env.local?
|
|
96
|
+
end
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Documenting a component
|
|
100
|
+
|
|
101
|
+
A component's page is at `/design-system/components/button`: its path under
|
|
102
|
+
`app/components`, without the suffix. Everything on it comes from the class and the
|
|
103
|
+
comment above it:
|
|
104
|
+
|
|
105
|
+
- **Description and `@note`.** The comment's opening text, and one note that stands out
|
|
106
|
+
from it. Paragraphs, or Markdown with a `markdown` renderer (see Configuration).
|
|
107
|
+
- **`@example Title`.** Rendered live, with its highlighted source underneath. Write as
|
|
108
|
+
many as you like.
|
|
109
|
+
- **`@param name [Type] Description`.** Adds a type and a description to an argument. The
|
|
110
|
+
table lists every `initialize` parameter people pass by name (splats and blocks are left
|
|
111
|
+
out), documented or not. Defaults come from the source and are resolved through the
|
|
112
|
+
component's constants, and parameters without one show "Required". A component that
|
|
113
|
+
inherits `initialize` shows its superclass's arguments and `@param`s.
|
|
114
|
+
- **Slots.** Every `renders_one` and `renders_many`, with nothing to write.
|
|
115
|
+
|
|
116
|
+
`@param` descriptions and examples are ERB. These helpers are available in them:
|
|
117
|
+
|
|
118
|
+
- `one_of(values)` renders "One of :a, :b, or :c." from an Array or Hash.
|
|
119
|
+
- `pretty_value(value)` renders a symbol as `:sym` and `nil` as `nil`.
|
|
120
|
+
|
|
121
|
+
Examples run in a real request, so `params`, `url_for(sort: :name)` and `form_with` (with no `url:`) all point back at the component's page.
|
|
122
|
+
|
|
123
|
+
### Phlex
|
|
124
|
+
|
|
125
|
+
Phlex components are documented the same way. Their files have no suffix and their classes
|
|
126
|
+
sit under a namespace, so tell the design system which files to list:
|
|
127
|
+
|
|
128
|
+
```ruby
|
|
129
|
+
LivingDesignSystem.configure do |config|
|
|
130
|
+
config.component_suffix = "" # app/components/button.rb, not button_component.rb
|
|
131
|
+
config.exclude_components = ["base"] # Components::Base
|
|
132
|
+
end
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
A component's class comes from your app's autoloader, so `app/components/button.rb` is
|
|
136
|
+
documented as `Components::Button` when that's how the directory is set up. Two things
|
|
137
|
+
differ from ViewComponent:
|
|
138
|
+
|
|
139
|
+
- Examples and `@param` text are still ERB, so an example renders a component the way an
|
|
140
|
+
ERB view would: `<%= render(Components::Button.new) { "Save" } %>`.
|
|
141
|
+
- Phlex doesn't declare slots, so the page has no Slots section.
|
|
142
|
+
|
|
143
|
+
### Examples render in your app, not in a frame
|
|
144
|
+
|
|
145
|
+
Examples render inline, inside your layout, so they look the way they do in your app.
|
|
146
|
+
Resize the window or open the page on a phone to see them respond: there are no
|
|
147
|
+
iframes or simulated widths.
|
|
148
|
+
|
|
149
|
+
Every example also has its own page (`/design-system/components/button/examples/primary`,
|
|
150
|
+
from its title), linked from the icon at the end of its title row. It renders the example by itself in your layout,
|
|
151
|
+
like any other page of your app.
|
|
152
|
+
|
|
153
|
+
For a component that opens over the page, like a dialog or a slide-over, write the example
|
|
154
|
+
the way people will use it: the link or button that opens it, along with the component.
|
|
155
|
+
The example then shows the component in context, and stays out of the way until someone
|
|
156
|
+
opens it.
|
|
157
|
+
|
|
158
|
+
When an example raises, development shows the error in that example's place and renders
|
|
159
|
+
the rest of the page (see `rescue_example_errors`). Elsewhere it raises, so a test that
|
|
160
|
+
visits each component page catches broken examples.
|
|
161
|
+
|
|
162
|
+
## Pages
|
|
163
|
+
|
|
164
|
+
Every view in `app/views/design_system/pages` (except `_partials`) is listed under
|
|
165
|
+
"Foundations" (or `pages_heading`). Pages are ordinary views, so they can render live
|
|
166
|
+
components alongside the prose.
|
|
167
|
+
|
|
168
|
+
They're listed alphabetically, after any named in `page_order`. An `index` page, if you write one, replaces the default index (the title and navigation)
|
|
169
|
+
at the design system's root, and isn't listed with the other pages.
|
|
170
|
+
|
|
171
|
+
## Configuration
|
|
172
|
+
|
|
173
|
+
```ruby
|
|
174
|
+
LivingDesignSystem.configure do |config|
|
|
175
|
+
config.parent_controller = "DesignSystemController" # default "ApplicationController"
|
|
176
|
+
config.layout = nil # nil inherits the parent controller's layout
|
|
177
|
+
config.title = "Acme Design System" # default "Design System"
|
|
178
|
+
config.pages_heading = "Foundations" # navigation heading over the pages
|
|
179
|
+
config.component_paths = ["app/components"]
|
|
180
|
+
config.component_suffix = "_component"
|
|
181
|
+
config.exclude_components = ["application"] # with or without the suffix
|
|
182
|
+
config.pages_path = "design_system/pages" # under app/views
|
|
183
|
+
config.page_order = ["introduction"] # pages listed first, in this order; the rest follow alphabetically
|
|
184
|
+
config.highlight_theme = "monokai.sublime" # any Rouge theme
|
|
185
|
+
config.markdown = ->(text) { Commonmarker.to_html(text) } # descriptions and notes; output is trusted HTML
|
|
186
|
+
config.rescue_example_errors = Rails.env.development? # the default
|
|
187
|
+
config.example_sources_path = nil # a file of every example's source, for Tailwind (see Styling)
|
|
188
|
+
end
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
`parent_controller` is how the design system runs inside your app. Authentication,
|
|
192
|
+
`before_action`s, helpers and the layout all come from it. Point it at a small
|
|
193
|
+
controller of your own to add behavior just for the design system, such as its own layout
|
|
194
|
+
or a check on who can see it:
|
|
195
|
+
|
|
196
|
+
```ruby
|
|
197
|
+
class DesignSystemController < ApplicationController
|
|
198
|
+
layout "design_system"
|
|
199
|
+
before_action :require_staff
|
|
200
|
+
|
|
201
|
+
private
|
|
202
|
+
|
|
203
|
+
def require_staff
|
|
204
|
+
head :not_found unless current_user&.staff?
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
The gem's own code lives in the `LivingDesignSystem` module, so a `DesignSystem`
|
|
210
|
+
namespace in your app (for components or demo pages) stays yours.
|
|
211
|
+
|
|
212
|
+
## Navigation in your own layout
|
|
213
|
+
|
|
214
|
+
The index page lists every page and component. To put the same tree in your layout's
|
|
215
|
+
sidebar, render `living_design_system/shared/navigation`, or build your own markup from
|
|
216
|
+
`design_system_page_links` and `design_system_component_links`. Each returns `NavLink`s
|
|
217
|
+
with `title`, `url` and `children`. Both helpers work from any controller, as long as it
|
|
218
|
+
includes all helpers (Rails' default `include_all_helpers`).
|
|
219
|
+
|
|
220
|
+
## Styling
|
|
221
|
+
|
|
222
|
+
The gem's views use their own small, scoped stylesheet (`.lds-*` classes), so they don't
|
|
223
|
+
depend on Tailwind or an asset pipeline. Text inherits your app's fonts and colors, and
|
|
224
|
+
examples sit on your page's own background. The stylesheet is in a cascade layer
|
|
225
|
+
(`living-design-system`), so any rule in your own CSS outside a layer overrides it. Or set
|
|
226
|
+
these CSS variables:
|
|
227
|
+
|
|
228
|
+
```css
|
|
229
|
+
:root {
|
|
230
|
+
--lds-border-color: #d4d4d4;
|
|
231
|
+
--lds-muted-color: #525252; /* navigation headings, table headers, notes */
|
|
232
|
+
--lds-link-color: inherit; /* the icon linking to an example's own page */
|
|
233
|
+
--lds-radius: 0.5rem; /* example frames */
|
|
234
|
+
--lds-preview-background: transparent;
|
|
235
|
+
--lds-preview-padding: 2rem;
|
|
236
|
+
--lds-error-color: #b91c1c; /* an example's error, in development */
|
|
237
|
+
}
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
Code takes its colors from `highlight_theme`.
|
|
241
|
+
|
|
242
|
+
### Tailwind and other class scanners
|
|
243
|
+
|
|
244
|
+
Tailwind finds the classes to generate by scanning your files, but it skips Ruby comments,
|
|
245
|
+
so a class used only in an example gets no CSS. Set `example_sources_path`, and the gem
|
|
246
|
+
keeps a file there with every example's source (and `@param` text): at boot, and in
|
|
247
|
+
development whenever code reloads. Point Tailwind at it (an explicit `@source` is scanned
|
|
248
|
+
even when the file is gitignored):
|
|
249
|
+
|
|
250
|
+
```ruby
|
|
251
|
+
config.example_sources_path = Rails.root.join("tmp/living_design_system/examples.html") if Rails.env.development?
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
```css
|
|
255
|
+
/* app/assets/tailwind/application.css */
|
|
256
|
+
@source "../../../tmp/living_design_system/examples.html";
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
In development, Tailwind's watcher picks up the change, so a new class appears on the next
|
|
260
|
+
reload. The watcher only follows the file if it exists when the watcher starts, so before
|
|
261
|
+
the first run, and before any one-off build, write it with
|
|
262
|
+
`bin/rails living_design_system:example_sources`.
|
|
263
|
+
|
|
264
|
+
## Overriding views
|
|
265
|
+
|
|
266
|
+
To change a view, copy it to the same path in your app, for example
|
|
267
|
+
`app/views/living_design_system/components/show.html.erb`.
|
|
268
|
+
|
|
269
|
+
## Why a route macro and not `mount`
|
|
270
|
+
|
|
271
|
+
`mount_living_design_system` draws the design system's routes into your app's route set.
|
|
272
|
+
It doesn't mount a separate Rack engine. That keeps both kinds of URL generation working
|
|
273
|
+
while the design system renders inside your layout:
|
|
274
|
+
|
|
275
|
+
- **Your route helpers in the layout** (`root_path`, `new_user_session_path`, …) keep generating your app's URLs.
|
|
276
|
+
- **Current-page URLs from examples** (`form_with` with no `url:`, `url_for(params.merge(...))`, sort and pagination links) point back at the component's page.
|
|
277
|
+
|
|
278
|
+
A mounted engine breaks one or the other. The route helpers are `design_system_path`,
|
|
279
|
+
`design_system_page_path(name)`, `design_system_component_path(name)` and
|
|
280
|
+
`design_system_component_example_path(name, example_slug)`.
|
|
281
|
+
|
|
282
|
+
## Where this fits
|
|
283
|
+
|
|
284
|
+
- **Design files** (Figma and similar) show the system as designed: intent, exploration and
|
|
285
|
+
what's coming next.
|
|
286
|
+
- **The living design system** shows the system as built: what developers can use right
|
|
287
|
+
now, and how it really looks. When it differs from the design files, that's a
|
|
288
|
+
conversation to have, not a conflict between tools.
|
|
289
|
+
- **Docs written for AI agents**, such as `DESIGN.md`, tell coding agents which rules to
|
|
290
|
+
follow. The living design system shows people what those agents have to work with.
|
|
291
|
+
|
|
292
|
+
## Development
|
|
293
|
+
|
|
294
|
+
```sh
|
|
295
|
+
bundle install
|
|
296
|
+
bundle exec rake # specs + standardrb
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
The specs run against a dummy app in `spec/dummy`, which is kept plain and holds the awkward
|
|
300
|
+
cases the specs need.
|
|
301
|
+
|
|
302
|
+
To see the gem working, run one of the demo apps. Each is a small design system with
|
|
303
|
+
styled components and foundation pages:
|
|
304
|
+
|
|
305
|
+
```sh
|
|
306
|
+
bundle exec rake demo_vc # demo_vc/: ViewComponent and plain CSS, at http://localhost:3000
|
|
307
|
+
bundle exec rake demo_phlex # demo_phlex/: Phlex and Tailwind, at http://localhost:3001
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
Set `PORT` to use another port.
|
|
311
|
+
|
|
312
|
+
## License
|
|
313
|
+
|
|
314
|
+
MIT. See [LICENSE.txt](LICENSE.txt).
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module LivingDesignSystem
|
|
2
|
+
class ApplicationController < LivingDesignSystem.config.parent_controller.constantize
|
|
3
|
+
helper DocsHelper, NavigationHelper
|
|
4
|
+
|
|
5
|
+
layout LivingDesignSystem.config.layout if LivingDesignSystem.config.layout
|
|
6
|
+
|
|
7
|
+
private
|
|
8
|
+
|
|
9
|
+
def catalog
|
|
10
|
+
@catalog ||= Catalog.new
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module LivingDesignSystem
|
|
2
|
+
class ComponentsController < ApplicationController
|
|
3
|
+
before_action :set_component
|
|
4
|
+
before_action :set_example, only: :example
|
|
5
|
+
|
|
6
|
+
def show
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
# One example on its own page.
|
|
10
|
+
def example
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
private
|
|
14
|
+
|
|
15
|
+
def set_component
|
|
16
|
+
path = catalog.component_path(params[:id])
|
|
17
|
+
return head :not_found unless path
|
|
18
|
+
|
|
19
|
+
@component = ComponentDoc.new(
|
|
20
|
+
params[:id],
|
|
21
|
+
file_name: catalog.component_file_name(params[:id]),
|
|
22
|
+
class_name: catalog.component_class_name(params[:id]),
|
|
23
|
+
path: path,
|
|
24
|
+
view_context: view_context
|
|
25
|
+
)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def set_example
|
|
29
|
+
@example = @component.example(params[:example])
|
|
30
|
+
head :not_found unless @example
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module LivingDesignSystem
|
|
2
|
+
class PagesController < ApplicationController
|
|
3
|
+
# The app's own index page when it has one, otherwise the title and navigation.
|
|
4
|
+
def index
|
|
5
|
+
render template: "#{LivingDesignSystem.config.pages_path}/#{Catalog::INDEX_PAGE}" if catalog.index_page?
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def show
|
|
9
|
+
return head :not_found unless catalog.page?(params[:id])
|
|
10
|
+
|
|
11
|
+
render template: "#{LivingDesignSystem.config.pages_path}/#{params[:id]}"
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
module LivingDesignSystem
|
|
2
|
+
module DocsHelper
|
|
3
|
+
def one_of(enumerable)
|
|
4
|
+
values =
|
|
5
|
+
case enumerable
|
|
6
|
+
when Hash
|
|
7
|
+
enumerable.map do |key, value|
|
|
8
|
+
"#{pretty_value(key)} (#{pretty_value(value)})"
|
|
9
|
+
end
|
|
10
|
+
else
|
|
11
|
+
enumerable.map do |key|
|
|
12
|
+
pretty_value(key)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
"One of #{values.to_sentence(two_words_connector: " or ", last_word_connector: ", or ")}.".html_safe
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def pretty_value(val)
|
|
20
|
+
case val
|
|
21
|
+
when nil
|
|
22
|
+
"nil"
|
|
23
|
+
when Symbol
|
|
24
|
+
":#{val}"
|
|
25
|
+
else
|
|
26
|
+
val.to_s
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def design_system_highlight(source)
|
|
31
|
+
Rouge::Formatters::HTML.new.format(Rouge::Lexers::ERB.new.lex(source.to_s)).html_safe
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Long-form text from a comment (a description or @note), through the configured Markdown
|
|
35
|
+
# renderer, whose output is trusted as HTML. Without one, each paragraph becomes a <p>.
|
|
36
|
+
def design_system_markdown(text)
|
|
37
|
+
return if text.blank?
|
|
38
|
+
|
|
39
|
+
if (markdown = LivingDesignSystem.config.markdown)
|
|
40
|
+
markdown.call(text.to_s).to_s.html_safe
|
|
41
|
+
else
|
|
42
|
+
safe_join(text.to_s.split(/\n\s*\n/).map { |paragraph| tag.p(paragraph.squish) })
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Renders an example's ERB. With rescue_example_errors on, a failing example shows its
|
|
47
|
+
# error in its place, so the rest of the page still renders.
|
|
48
|
+
def design_system_example(example)
|
|
49
|
+
render inline: example.source
|
|
50
|
+
rescue => error
|
|
51
|
+
raise unless LivingDesignSystem.config.rescue_example_errors
|
|
52
|
+
|
|
53
|
+
failure = error.cause || error
|
|
54
|
+
tag.div(class: "lds-example-error", role: "alert") do
|
|
55
|
+
tag.p(tag.strong(failure.class.name)) + tag.pre(failure.message)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def design_system_styles_tag
|
|
60
|
+
return if @design_system_styles_rendered
|
|
61
|
+
|
|
62
|
+
@design_system_styles_rendered = true
|
|
63
|
+
tag.style(LivingDesignSystem.stylesheet.html_safe, nonce: content_security_policy_nonce)
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module LivingDesignSystem
|
|
2
|
+
module NavigationHelper
|
|
3
|
+
def design_system_component_links
|
|
4
|
+
@design_system_component_links ||= NavLink.tree(design_system_catalog.component_names) do |name|
|
|
5
|
+
design_system_component_path(name)
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def design_system_page_links
|
|
10
|
+
@design_system_page_links ||= NavLink.tree(design_system_catalog.page_names, sort: false) do |name|
|
|
11
|
+
design_system_page_path(name)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def design_system_catalog
|
|
16
|
+
@design_system_catalog ||= Catalog.new
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
<% content_for :title, @component.class_name %>
|
|
2
|
+
<%= design_system_styles_tag %>
|
|
3
|
+
|
|
4
|
+
<h1 class="lds-page-title"><%= @component.class_name %></h1>
|
|
5
|
+
<div class="lds-description"><%= design_system_markdown(@component.description) %></div>
|
|
6
|
+
<% if @component.note.present? %>
|
|
7
|
+
<div class="lds-note"><%= design_system_markdown(@component.note) %></div>
|
|
8
|
+
<% end %>
|
|
9
|
+
|
|
10
|
+
<h2 class="lds-section-title">Arguments</h2>
|
|
11
|
+
<% if @component.arguments.empty? %>
|
|
12
|
+
<p>None</p>
|
|
13
|
+
<% else %>
|
|
14
|
+
<div class="lds-args-scroll">
|
|
15
|
+
<table class="lds-args">
|
|
16
|
+
<tr>
|
|
17
|
+
<th>Name</th>
|
|
18
|
+
<th>Type</th>
|
|
19
|
+
<th>Default</th>
|
|
20
|
+
<th>Description</th>
|
|
21
|
+
</tr>
|
|
22
|
+
<% @component.arguments.each do |arg| %>
|
|
23
|
+
<tr>
|
|
24
|
+
<td><code><%= arg.name %></code></td>
|
|
25
|
+
<td><%= arg.type %></td>
|
|
26
|
+
<td><%= arg.default %></td>
|
|
27
|
+
<td><%= arg.description %></td>
|
|
28
|
+
</tr>
|
|
29
|
+
<% end %>
|
|
30
|
+
</table>
|
|
31
|
+
</div>
|
|
32
|
+
<% end %>
|
|
33
|
+
|
|
34
|
+
<% if @component.slots? %>
|
|
35
|
+
<h2 class="lds-section-title">Slots</h2>
|
|
36
|
+
<% if @component.slots.empty? %>
|
|
37
|
+
<p>None</p>
|
|
38
|
+
<% end %>
|
|
39
|
+
<% @component.slots.each do |slot| %>
|
|
40
|
+
<p class="lds-slot"><%= slot.macro %> <span class="lds-slot-name">:<%= slot.name %></span></p>
|
|
41
|
+
<% end %>
|
|
42
|
+
<% end %>
|
|
43
|
+
|
|
44
|
+
<h2 class="lds-section-title">Examples</h2>
|
|
45
|
+
<% if @component.examples.empty? %>
|
|
46
|
+
<p>No documented examples</p>
|
|
47
|
+
<% end %>
|
|
48
|
+
<% @component.examples.each do |example| %>
|
|
49
|
+
<% example_path = design_system_component_example_path(@component.name, example.slug) %>
|
|
50
|
+
<section class="lds-example" id="example-<%= example.slug %>">
|
|
51
|
+
<h3 class="lds-example-title">
|
|
52
|
+
<%= example.title %>
|
|
53
|
+
<%= link_to example_path, class: "lds-example-link", title: "Open on its own page", "aria-label": "Open #{example.title} on its own page" do %>
|
|
54
|
+
<svg viewBox="0 0 24 24" width="1em" height="1em" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M14 5h5v5M19 5l-8 8M11 7H6a1 1 0 0 0-1 1v10a1 1 0 0 0 1 1h10a1 1 0 0 0 1-1v-5" /></svg>
|
|
55
|
+
<% end %>
|
|
56
|
+
</h3>
|
|
57
|
+
<div class="lds-example-frame">
|
|
58
|
+
<div class="lds-example-preview">
|
|
59
|
+
<%= design_system_example(example) %>
|
|
60
|
+
</div>
|
|
61
|
+
<pre class="lds-code"><code><%= design_system_highlight(example.source) %></code></pre>
|
|
62
|
+
</div>
|
|
63
|
+
</section>
|
|
64
|
+
<% end %>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<li>
|
|
2
|
+
<% if link.children.any? %>
|
|
3
|
+
<details open>
|
|
4
|
+
<summary><%= link.title %></summary>
|
|
5
|
+
<ul class="lds-nav-list">
|
|
6
|
+
<%= render partial: "living_design_system/shared/nav_link", collection: link.children, as: :link %>
|
|
7
|
+
</ul>
|
|
8
|
+
</details>
|
|
9
|
+
<% else %>
|
|
10
|
+
<%= link_to link.title, link.url, "aria-current": ("page" if current_page?(link.url)) %>
|
|
11
|
+
<% end %>
|
|
12
|
+
</li>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<%= design_system_styles_tag %>
|
|
2
|
+
|
|
3
|
+
<nav class="lds-nav" aria-label="<%= LivingDesignSystem.config.title %>">
|
|
4
|
+
<% if design_system_page_links.any? %>
|
|
5
|
+
<h4 class="lds-nav-heading"><%= LivingDesignSystem.config.pages_heading %></h4>
|
|
6
|
+
<ul class="lds-nav-list">
|
|
7
|
+
<%= render partial: "living_design_system/shared/nav_link", collection: design_system_page_links, as: :link %>
|
|
8
|
+
</ul>
|
|
9
|
+
<% end %>
|
|
10
|
+
|
|
11
|
+
<h4 class="lds-nav-heading">Components</h4>
|
|
12
|
+
<ul class="lds-nav-list">
|
|
13
|
+
<%= render partial: "living_design_system/shared/nav_link", collection: design_system_component_links, as: :link %>
|
|
14
|
+
</ul>
|
|
15
|
+
</nav>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require "rails/generators"
|
|
2
|
+
|
|
3
|
+
module LivingDesignSystem
|
|
4
|
+
module Generators
|
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
|
6
|
+
source_root File.expand_path("templates", __dir__)
|
|
7
|
+
|
|
8
|
+
class_option :path, type: :string, default: "/design-system", desc: "Path to serve the design system at"
|
|
9
|
+
|
|
10
|
+
def create_initializer
|
|
11
|
+
copy_file "initializer.rb", "config/initializers/living_design_system.rb"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def add_routes
|
|
15
|
+
route %(mount_living_design_system at: "#{options[:path]}" if Rails.env.local?)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def create_pages_folder
|
|
19
|
+
copy_file "getting_started.html.erb", "app/views/design_system/pages/getting_started.html.erb"
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<h1>Getting Started</h1>
|
|
2
|
+
|
|
3
|
+
<p>
|
|
4
|
+
Every view in <code>app/views/design_system/pages</code> shows up as a page in the design system.
|
|
5
|
+
Use pages for foundations that aren't a single component, like color, typography, or form layout.
|
|
6
|
+
</p>
|
|
7
|
+
|
|
8
|
+
<p>
|
|
9
|
+
Components are documented from the YARD comment above their class:
|
|
10
|
+
</p>
|
|
11
|
+
|
|
12
|
+
<pre><code>
|
|
13
|
+
# A button for primary and secondary actions.
|
|
14
|
+
#
|
|
15
|
+
# @example Primary
|
|
16
|
+
# <%= render(ButtonComponent.new(style: :primary)) { "Save" } %>
|
|
17
|
+
#
|
|
18
|
+
# @param style [Symbol] <%= one_of(ButtonComponent::STYLE_OPTIONS) %>
|
|
19
|
+
class ButtonComponent < ViewComponent::Base
|
|
20
|
+
</code></pre>
|