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
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
LivingDesignSystem.configure do |config|
|
|
2
|
+
# Controller the design system's controllers inherit from. Its layout, before_actions
|
|
3
|
+
# and helpers apply to every design system page.
|
|
4
|
+
# config.parent_controller = "ApplicationController"
|
|
5
|
+
|
|
6
|
+
# Layout for design system pages. Leave nil to inherit the parent controller's layout.
|
|
7
|
+
# config.layout = nil
|
|
8
|
+
|
|
9
|
+
# Heading on the design system's index page, and the navigation heading over the pages.
|
|
10
|
+
# config.title = "Design System"
|
|
11
|
+
# config.pages_heading = "Foundations"
|
|
12
|
+
|
|
13
|
+
# Directories (relative to Rails.root) searched for components, and the filename
|
|
14
|
+
# suffix a file needs to be listed.
|
|
15
|
+
# config.component_paths = ["app/components"]
|
|
16
|
+
# config.component_suffix = "_component"
|
|
17
|
+
|
|
18
|
+
# Components to leave out, named with or without the suffix.
|
|
19
|
+
# config.exclude_components = ["application"]
|
|
20
|
+
|
|
21
|
+
# View prefix (under app/views) holding hand-written pages. Files starting with an
|
|
22
|
+
# underscore are partials and aren't listed.
|
|
23
|
+
# config.pages_path = "design_system/pages"
|
|
24
|
+
|
|
25
|
+
# Pages to list first, in this order. The rest follow alphabetically.
|
|
26
|
+
# config.page_order = []
|
|
27
|
+
|
|
28
|
+
# Rouge theme for example source code.
|
|
29
|
+
# config.highlight_theme = "monokai.sublime"
|
|
30
|
+
|
|
31
|
+
# Callable that turns a component's description and @note into HTML (trusted as is).
|
|
32
|
+
# Leave nil to show each paragraph as plain text.
|
|
33
|
+
# config.markdown = ->(text) { Commonmarker.to_html(text) }
|
|
34
|
+
|
|
35
|
+
# A file the gem keeps with every example's source, for CSS tools like Tailwind that skip
|
|
36
|
+
# Ruby comments when they scan for class names. Add it to Tailwind with @source.
|
|
37
|
+
# config.example_sources_path = Rails.root.join("tmp/living_design_system/examples.html") if Rails.env.development?
|
|
38
|
+
|
|
39
|
+
# Show a failing example's error in its place instead of raising. Defaults to on in
|
|
40
|
+
# development only.
|
|
41
|
+
# config.rescue_example_errors = Rails.env.development?
|
|
42
|
+
end
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
module LivingDesignSystem
|
|
2
|
+
class Catalog
|
|
3
|
+
INDEX_PAGE = "index"
|
|
4
|
+
|
|
5
|
+
Component = Struct.new(:file_name, :path, :class_name)
|
|
6
|
+
|
|
7
|
+
attr_reader :config, :root
|
|
8
|
+
|
|
9
|
+
def initialize(config: LivingDesignSystem.config, root: Rails.root)
|
|
10
|
+
@config = config
|
|
11
|
+
@root = root
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# Components by name: their path under a component directory, without the suffix
|
|
15
|
+
# ("forms/field" for app/components/forms/field_component.rb).
|
|
16
|
+
def component_names
|
|
17
|
+
components.keys
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def component_path(name)
|
|
21
|
+
components[name.to_s]&.path
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# The component's file name without ".rb" ("forms/field_component"), which names its class.
|
|
25
|
+
def component_file_name(name)
|
|
26
|
+
components[name.to_s]&.file_name
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def component_class_name(name)
|
|
30
|
+
components[name.to_s]&.class_name
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Pages named in `page_order` come first, in that order, then the rest alphabetically.
|
|
34
|
+
def page_names
|
|
35
|
+
@page_names ||= begin
|
|
36
|
+
names = page_files.excluding(INDEX_PAGE)
|
|
37
|
+
order = Array(config.page_order).map(&:to_s)
|
|
38
|
+
names.sort_by { |name| [order.index(name) || order.size, name] }
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def page?(name)
|
|
43
|
+
page_names.include?(name.to_s)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Whether the app has its own index page, shown at the design system's root.
|
|
47
|
+
def index_page?
|
|
48
|
+
page_files.include?(INDEX_PAGE)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
private
|
|
52
|
+
|
|
53
|
+
def components
|
|
54
|
+
@components ||= config.component_paths.each_with_object({}) do |base, components|
|
|
55
|
+
base_dir = root.join(base)
|
|
56
|
+
base_dir.glob("**/[!_]*#{config.component_suffix}.rb").each do |file|
|
|
57
|
+
file_name = file.relative_path_from(base_dir).to_s.delete_suffix(".rb")
|
|
58
|
+
name = file_name.delete_suffix(config.component_suffix)
|
|
59
|
+
next if excluded?(name, file_name)
|
|
60
|
+
|
|
61
|
+
components[name] ||= Component.new(file_name, file.to_s, class_name_for(file, file_name))
|
|
62
|
+
end
|
|
63
|
+
end.sort.to_h
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# The class a file defines, as the app's autoloader names it. That respects a namespace
|
|
67
|
+
# given to a directory (Phlex puts app/components under `Components`) and the app's
|
|
68
|
+
# inflections. Files the autoloader doesn't manage fall back to their path.
|
|
69
|
+
def class_name_for(file, file_name)
|
|
70
|
+
loader = Rails.autoloaders.main
|
|
71
|
+
(loader.cpath_expected_at(file.to_s) if loader.respond_to?(:cpath_expected_at)) || file_name.camelize
|
|
72
|
+
rescue NameError
|
|
73
|
+
file_name.camelize
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# Exclusions can be given with or without the suffix ("application" or "application_component").
|
|
77
|
+
def excluded?(*names)
|
|
78
|
+
names.intersect?(Array(config.exclude_components).map(&:to_s))
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def page_files
|
|
82
|
+
@page_files ||= begin
|
|
83
|
+
base_dir = root.join("app/views", config.pages_path)
|
|
84
|
+
base_dir.glob("**/[!_]*.html.*").map { |file| file.relative_path_from(base_dir).to_s.sub(/\.html\..*\z/, "") }.uniq.sort
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
module LivingDesignSystem
|
|
2
|
+
class ComponentDoc
|
|
3
|
+
# YARD's registry is global, and app servers render pages on several threads.
|
|
4
|
+
YARD_LOCK = Mutex.new
|
|
5
|
+
|
|
6
|
+
# Splats and blocks aren't arguments people pass by name, so the table leaves them out.
|
|
7
|
+
SKIPPED_PARAMETER_KINDS = %i[rest keyrest block nokey].freeze
|
|
8
|
+
|
|
9
|
+
attr_reader :name, :file_name, :path, :view_context
|
|
10
|
+
|
|
11
|
+
# `name` is the component's name in the catalog and its URLs ("forms/field"). `file_name`
|
|
12
|
+
# is its file without ".rb" ("forms/field_component"), and defaults to `name`. `class_name`
|
|
13
|
+
# defaults to the class that file name spells ("Forms::FieldComponent").
|
|
14
|
+
def initialize(name, path:, view_context:, file_name: name, class_name: nil)
|
|
15
|
+
@name = name
|
|
16
|
+
@file_name = file_name
|
|
17
|
+
@class_name = class_name
|
|
18
|
+
@path = path
|
|
19
|
+
@view_context = view_context
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.yard_object(path, object_path)
|
|
23
|
+
YARD_LOCK.synchronize do
|
|
24
|
+
YARD.parse(path)
|
|
25
|
+
YARD::Registry.at(object_path)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def class_name
|
|
30
|
+
@class_name ||= file_name.camelize
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def description
|
|
34
|
+
docstring.to_s
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def note
|
|
38
|
+
docstring.tag(:note)&.text
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def arguments
|
|
42
|
+
parameters = initialize_method.parameters.reject { |parameter| SKIPPED_PARAMETER_KINDS.include?(parameter.first) }
|
|
43
|
+
return [] if parameters.empty?
|
|
44
|
+
|
|
45
|
+
param_tags = docstring.tags(:param) + inherited_param_tags
|
|
46
|
+
parameters.map do |kind, arg_name|
|
|
47
|
+
arg_name = arg_name.to_s
|
|
48
|
+
Argument.new(
|
|
49
|
+
name: arg_name,
|
|
50
|
+
required: %i[req keyreq].include?(kind),
|
|
51
|
+
default_source: default_sources[arg_name],
|
|
52
|
+
doc_tag: param_tags.detect { |tag| tag.name == arg_name },
|
|
53
|
+
constant_scopes: [component_class, initialize_method.owner].uniq,
|
|
54
|
+
view_context: view_context
|
|
55
|
+
)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# The @param descriptions as written (ERB), without rendering them.
|
|
60
|
+
def param_texts
|
|
61
|
+
docstring.tags(:param).map(&:text)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Whether the component declares its slots (ViewComponent's renders_one and renders_many).
|
|
65
|
+
def slots?
|
|
66
|
+
component_class.respond_to?(:registered_slots)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def slots
|
|
70
|
+
return [] unless slots?
|
|
71
|
+
|
|
72
|
+
component_class.registered_slots.map { |slot_name, options| Slot.new(slot_name, options) }
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def examples
|
|
76
|
+
@examples ||= begin
|
|
77
|
+
slugs = Hash.new(0)
|
|
78
|
+
docstring.tags(:example).map do |tag|
|
|
79
|
+
example = Example.new(tag.name, tag.text)
|
|
80
|
+
slugs[example.slug] += 1
|
|
81
|
+
example.slug = "#{example.slug}-#{slugs[example.slug]}" if slugs[example.slug] > 1
|
|
82
|
+
example
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def example(slug)
|
|
88
|
+
examples.detect { |example| example.slug == slug.to_s }
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
private
|
|
92
|
+
|
|
93
|
+
def component_class
|
|
94
|
+
@component_class ||= class_name.constantize
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def doc
|
|
98
|
+
@doc ||= self.class.yard_object(path, class_name)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def docstring
|
|
102
|
+
doc ? doc.docstring : YARD::Docstring.new("")
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def initialize_method
|
|
106
|
+
@initialize_method ||= component_class.instance_method(:initialize)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# A component can inherit its initialize (and the @param docs for it) from its superclass.
|
|
110
|
+
def inherited?
|
|
111
|
+
initialize_method.owner != component_class
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def inherited_param_tags
|
|
115
|
+
return [] unless inherited? && initialize_source
|
|
116
|
+
|
|
117
|
+
self.class.yard_object(initialize_source, initialize_method.owner.name)&.tags(:param) || []
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def initialize_source
|
|
121
|
+
initialize_method.source_location&.first
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
# Each argument's default as written in the source ("DEFAULT_STYLE", ":md", "nil").
|
|
125
|
+
def default_sources
|
|
126
|
+
@default_sources ||= begin
|
|
127
|
+
constructor = self.class.yard_object(initialize_source, "#{initialize_method.owner.name}#initialize") if initialize_source
|
|
128
|
+
(constructor&.parameters || []).to_h { |param, default| [param.to_s.delete_suffix(":").delete_prefix("*").delete_prefix("&"), default] }
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
class Argument
|
|
133
|
+
CONSTANT = /\A(::)?[A-Z]\w*(::[A-Z]\w*)*\z/
|
|
134
|
+
|
|
135
|
+
attr_reader :name, :doc_tag, :view_context
|
|
136
|
+
|
|
137
|
+
def initialize(name:, required:, default_source:, doc_tag:, constant_scopes:, view_context:)
|
|
138
|
+
@name = name
|
|
139
|
+
@required = required
|
|
140
|
+
@default_source = default_source
|
|
141
|
+
@doc_tag = doc_tag
|
|
142
|
+
@constant_scopes = constant_scopes
|
|
143
|
+
@view_context = view_context
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def required?
|
|
147
|
+
@required
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def type
|
|
151
|
+
doc_tag&.types&.join(", ").presence
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def description
|
|
155
|
+
return "Undocumented" unless doc_tag
|
|
156
|
+
|
|
157
|
+
view_context.render inline: doc_tag.text
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
# The default value, with constants resolved ("DEFAULT_STYLE" shows as ":primary").
|
|
161
|
+
def default
|
|
162
|
+
return "Required" if required?
|
|
163
|
+
return if @default_source.nil?
|
|
164
|
+
|
|
165
|
+
constant = resolve_constant(@default_source)
|
|
166
|
+
view_context.pretty_value(constant.nil? ? @default_source : constant)
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
private
|
|
170
|
+
|
|
171
|
+
def resolve_constant(source)
|
|
172
|
+
return unless source.match?(CONSTANT)
|
|
173
|
+
|
|
174
|
+
@constant_scopes.filter_map(&:name).each do |scope|
|
|
175
|
+
constant = "#{scope}::#{source}".safe_constantize
|
|
176
|
+
return constant unless constant.nil?
|
|
177
|
+
end
|
|
178
|
+
source.safe_constantize
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
class Slot
|
|
183
|
+
attr_reader :name, :options
|
|
184
|
+
|
|
185
|
+
def initialize(name, options)
|
|
186
|
+
@name = name
|
|
187
|
+
@options = options
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
def macro
|
|
191
|
+
options[:collection] ? "renders_many" : "renders_one"
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
# An @example: its title and its ERB source.
|
|
196
|
+
class Example
|
|
197
|
+
attr_reader :title, :source
|
|
198
|
+
attr_writer :slug
|
|
199
|
+
|
|
200
|
+
def initialize(title, source)
|
|
201
|
+
@title = title.to_s.strip
|
|
202
|
+
@source = source
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
def slug
|
|
206
|
+
@slug ||= title.parameterize.presence || "example"
|
|
207
|
+
end
|
|
208
|
+
end
|
|
209
|
+
end
|
|
210
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module LivingDesignSystem
|
|
2
|
+
class Configuration
|
|
3
|
+
attr_accessor :parent_controller, :layout, :title, :pages_heading, :component_paths, :component_suffix,
|
|
4
|
+
:exclude_components, :pages_path, :page_order, :highlight_theme, :markdown, :example_sources_path
|
|
5
|
+
attr_writer :rescue_example_errors
|
|
6
|
+
|
|
7
|
+
def initialize
|
|
8
|
+
@parent_controller = "ApplicationController"
|
|
9
|
+
@layout = nil
|
|
10
|
+
@title = "Design System"
|
|
11
|
+
@pages_heading = "Foundations"
|
|
12
|
+
@component_paths = ["app/components"]
|
|
13
|
+
@component_suffix = "_component"
|
|
14
|
+
@exclude_components = []
|
|
15
|
+
@pages_path = "design_system/pages"
|
|
16
|
+
@page_order = []
|
|
17
|
+
@highlight_theme = "monokai.sublime"
|
|
18
|
+
@markdown = nil
|
|
19
|
+
@example_sources_path = nil
|
|
20
|
+
@rescue_example_errors = nil
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Whether a failing example shows its error in its place (the rest of the page still
|
|
24
|
+
# renders) instead of raising. Unless set, it's on in development only, so tests catch it.
|
|
25
|
+
def rescue_example_errors
|
|
26
|
+
@rescue_example_errors.nil? ? Rails.env.development? : @rescue_example_errors
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module LivingDesignSystem
|
|
2
|
+
class Engine < ::Rails::Engine
|
|
3
|
+
engine_name "living_design_system"
|
|
4
|
+
|
|
5
|
+
initializer "living_design_system.routing" do
|
|
6
|
+
ActionDispatch::Routing::Mapper.include(LivingDesignSystem::Routing)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
# Keeps the example sources file current: at boot, and in development whenever code reloads.
|
|
10
|
+
config.to_prepare do
|
|
11
|
+
LivingDesignSystem::ExampleSources.write if LivingDesignSystem.config.example_sources_path
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
rake_tasks do
|
|
15
|
+
namespace :living_design_system do
|
|
16
|
+
desc "Write every example's source to config.example_sources_path, for CSS tools that skip Ruby comments"
|
|
17
|
+
task example_sources: :environment do
|
|
18
|
+
LivingDesignSystem::ExampleSources.write
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module LivingDesignSystem
|
|
2
|
+
# Every example's source (and @param text) in one file. CSS tools that scan files for class
|
|
3
|
+
# names, like Tailwind, skip Ruby comments, so classes used only in examples would otherwise
|
|
4
|
+
# get no CSS. Set `example_sources_path` and point the tool at that file.
|
|
5
|
+
module ExampleSources
|
|
6
|
+
def self.write(path = LivingDesignSystem.config.example_sources_path, catalog: Catalog.new)
|
|
7
|
+
return unless path
|
|
8
|
+
|
|
9
|
+
path = Pathname(path)
|
|
10
|
+
contents = sources(catalog).join("\n")
|
|
11
|
+
return if path.exist? && path.read == contents
|
|
12
|
+
|
|
13
|
+
path.dirname.mkpath
|
|
14
|
+
path.write(contents)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.sources(catalog)
|
|
18
|
+
catalog.component_names.flat_map do |name|
|
|
19
|
+
doc = ComponentDoc.new(name, class_name: catalog.component_class_name(name), path: catalog.component_path(name), view_context: nil)
|
|
20
|
+
doc.examples.map(&:source) + doc.param_texts
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
module LivingDesignSystem
|
|
2
|
+
class NavLink
|
|
3
|
+
attr_reader :title, :url, :children
|
|
4
|
+
|
|
5
|
+
def initialize(title:, url: nil, children: [])
|
|
6
|
+
@title = title
|
|
7
|
+
@url = url
|
|
8
|
+
@children = children
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# Links for names like "forms/field", nested by directory. Sorted by title unless `sort: false`,
|
|
12
|
+
# which keeps the names' order (directories after the links).
|
|
13
|
+
def self.tree(names, title_suffix: nil, path_prefix: nil, sort: true, &url_for)
|
|
14
|
+
links = []
|
|
15
|
+
directories = {}
|
|
16
|
+
|
|
17
|
+
names.each do |name|
|
|
18
|
+
directory, remaining = name.to_s.split("/", 2)
|
|
19
|
+
|
|
20
|
+
if remaining
|
|
21
|
+
(directories[directory] ||= []) << remaining
|
|
22
|
+
else
|
|
23
|
+
links << new(
|
|
24
|
+
title: name.to_s.delete_suffix(title_suffix.to_s).titleize,
|
|
25
|
+
url: url_for.call([path_prefix, name].compact.join("/"))
|
|
26
|
+
)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
directories.each do |directory, nested_names|
|
|
31
|
+
links << new(
|
|
32
|
+
title: directory.titleize,
|
|
33
|
+
children: tree(nested_names, title_suffix: title_suffix, path_prefix: [path_prefix, directory].compact.join("/"), sort: sort, &url_for)
|
|
34
|
+
)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
sort ? links.sort_by { |link| link.title.downcase } : links
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module LivingDesignSystem
|
|
2
|
+
module Routing
|
|
3
|
+
def mount_living_design_system(at: "/design-system")
|
|
4
|
+
get at, to: "living_design_system/pages#index", as: :design_system
|
|
5
|
+
|
|
6
|
+
scope path: at, module: "living_design_system", as: :design_system do
|
|
7
|
+
get "components/*id/examples/:example", to: "components#example", as: :component_example
|
|
8
|
+
get "components/*id", to: "components#show", as: :component
|
|
9
|
+
get "*id", to: "pages#show", as: :page
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/* Text and fonts inherit from the app. Set these variables in the app's CSS to restyle the rest. */
|
|
2
|
+
.lds-page-title { font-size: 1.5rem; line-height: 2rem; font-weight: 700; margin: 0 0 0.5rem; }
|
|
3
|
+
.lds-section-title { font-size: 1.125rem; line-height: 1.75rem; font-weight: 600; margin: 1.5rem 0 0.5rem; }
|
|
4
|
+
.lds-description p, .lds-note p { margin: 0 0 0.75rem; max-width: 70ch; }
|
|
5
|
+
.lds-note { margin-top: 0.75rem; padding-left: 0.75rem; border-left: 3px solid var(--lds-border-color, #d4d4d4); color: var(--lds-muted-color, #525252); }
|
|
6
|
+
|
|
7
|
+
.lds-args-scroll { overflow-x: auto; }
|
|
8
|
+
.lds-args { border-collapse: collapse; text-align: left; }
|
|
9
|
+
.lds-args th { padding: 0.375rem 1.25rem 0.375rem 0.375rem; font-weight: 500; color: var(--lds-muted-color, #525252); }
|
|
10
|
+
.lds-args td { padding: 0.375rem 1.25rem 0.375rem 0.375rem; border-top: 1px solid var(--lds-border-color, #d4d4d4); border-bottom: 1px solid var(--lds-border-color, #d4d4d4); vertical-align: top; }
|
|
11
|
+
.lds-args td:last-child, .lds-args th:last-child { padding-right: 0.375rem; }
|
|
12
|
+
|
|
13
|
+
.lds-slot { margin: 0 0 0.375rem; }
|
|
14
|
+
.lds-slot-name { font-weight: 500; }
|
|
15
|
+
|
|
16
|
+
.lds-example { margin-top: 1.5rem; scroll-margin-top: 1.5rem; }
|
|
17
|
+
.lds-example-title { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; font-weight: 500; margin: 0 0 0.5rem; }
|
|
18
|
+
.lds-example-link { display: inline-flex; color: var(--lds-link-color, inherit); opacity: 0.6; }
|
|
19
|
+
.lds-example-link:hover, .lds-example-link:focus-visible { opacity: 1; }
|
|
20
|
+
.lds-example-frame { border: 1px solid var(--lds-border-color, #d4d4d4); border-radius: var(--lds-radius, 0.5rem); }
|
|
21
|
+
/* No overflow clipping here, so dropdowns and popovers in examples open as they do in the app. */
|
|
22
|
+
.lds-example-preview { background: var(--lds-preview-background, transparent); padding: var(--lds-preview-padding, 2rem); border-radius: var(--lds-radius, 0.5rem) var(--lds-radius, 0.5rem) 0 0; }
|
|
23
|
+
.lds-example-error { color: var(--lds-error-color, #b91c1c); }
|
|
24
|
+
.lds-example-error p { margin: 0 0 0.5rem; }
|
|
25
|
+
.lds-example-error pre { margin: 0; white-space: pre-wrap; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.875rem; }
|
|
26
|
+
.lds-code { margin: 0; padding: 1rem; overflow-x: auto; border-top: 1px solid var(--lds-border-color, #d4d4d4); border-radius: 0 0 var(--lds-radius, 0.5rem) var(--lds-radius, 0.5rem); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.875rem; line-height: 1.4; white-space: pre; }
|
|
27
|
+
|
|
28
|
+
.lds-nav-heading { font-weight: 500; margin: 0.625rem 0 0.25rem; color: var(--lds-muted-color, #525252); }
|
|
29
|
+
.lds-nav-list { list-style: none; margin: 0 0 0 0.75rem; padding: 0; }
|
|
30
|
+
.lds-nav-list a { color: inherit; text-decoration: none; }
|
|
31
|
+
.lds-nav-list a:hover { text-decoration: underline; }
|
|
32
|
+
.lds-nav-list a[aria-current="page"] { font-weight: 600; }
|
|
33
|
+
.lds-nav-list summary { cursor: pointer; }
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require "rouge"
|
|
2
|
+
require "yard"
|
|
3
|
+
|
|
4
|
+
require "living_design_system/version"
|
|
5
|
+
require "living_design_system/configuration"
|
|
6
|
+
require "living_design_system/catalog"
|
|
7
|
+
require "living_design_system/component_doc"
|
|
8
|
+
require "living_design_system/example_sources"
|
|
9
|
+
require "living_design_system/nav_link"
|
|
10
|
+
require "living_design_system/routing"
|
|
11
|
+
require "living_design_system/engine"
|
|
12
|
+
|
|
13
|
+
module LivingDesignSystem
|
|
14
|
+
class << self
|
|
15
|
+
def config
|
|
16
|
+
@config ||= Configuration.new
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def configure
|
|
20
|
+
yield config
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# The gem's styles, in a cascade layer so any of the app's own (unlayered) CSS overrides them.
|
|
24
|
+
def stylesheet
|
|
25
|
+
@stylesheet ||= [
|
|
26
|
+
"@layer living-design-system {",
|
|
27
|
+
File.read(File.expand_path("living_design_system/styles.css", __dir__)),
|
|
28
|
+
Rouge::Theme.find(config.highlight_theme).render(scope: ".lds-code"),
|
|
29
|
+
"}"
|
|
30
|
+
].join("\n")
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: living_design_system
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Andrew Havens
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: actionpack
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '7.1'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '7.1'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: railties
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '7.1'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '7.1'
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: rouge
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '4.0'
|
|
47
|
+
- - "<"
|
|
48
|
+
- !ruby/object:Gem::Version
|
|
49
|
+
version: '6.0'
|
|
50
|
+
type: :runtime
|
|
51
|
+
prerelease: false
|
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
53
|
+
requirements:
|
|
54
|
+
- - ">="
|
|
55
|
+
- !ruby/object:Gem::Version
|
|
56
|
+
version: '4.0'
|
|
57
|
+
- - "<"
|
|
58
|
+
- !ruby/object:Gem::Version
|
|
59
|
+
version: '6.0'
|
|
60
|
+
- !ruby/object:Gem::Dependency
|
|
61
|
+
name: yard
|
|
62
|
+
requirement: !ruby/object:Gem::Requirement
|
|
63
|
+
requirements:
|
|
64
|
+
- - "~>"
|
|
65
|
+
- !ruby/object:Gem::Version
|
|
66
|
+
version: '0.9'
|
|
67
|
+
type: :runtime
|
|
68
|
+
prerelease: false
|
|
69
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
70
|
+
requirements:
|
|
71
|
+
- - "~>"
|
|
72
|
+
- !ruby/object:Gem::Version
|
|
73
|
+
version: '0.9'
|
|
74
|
+
description: 'Write an example in a comment above a component and get a page that
|
|
75
|
+
renders it live inside your app, with its source and a table of its arguments. No
|
|
76
|
+
preview files, and nothing to keep in sync: pages are built from the @example, @param
|
|
77
|
+
and @note tags on the components themselves. Works with ViewComponent and Phlex.'
|
|
78
|
+
email:
|
|
79
|
+
- email@andrewhavens.com
|
|
80
|
+
executables: []
|
|
81
|
+
extensions: []
|
|
82
|
+
extra_rdoc_files: []
|
|
83
|
+
files:
|
|
84
|
+
- CHANGELOG.md
|
|
85
|
+
- LICENSE.txt
|
|
86
|
+
- README.md
|
|
87
|
+
- app/controllers/living_design_system/application_controller.rb
|
|
88
|
+
- app/controllers/living_design_system/components_controller.rb
|
|
89
|
+
- app/controllers/living_design_system/pages_controller.rb
|
|
90
|
+
- app/helpers/living_design_system/docs_helper.rb
|
|
91
|
+
- app/helpers/living_design_system/navigation_helper.rb
|
|
92
|
+
- app/views/living_design_system/components/example.html.erb
|
|
93
|
+
- app/views/living_design_system/components/show.html.erb
|
|
94
|
+
- app/views/living_design_system/pages/index.html.erb
|
|
95
|
+
- app/views/living_design_system/shared/_nav_link.html.erb
|
|
96
|
+
- app/views/living_design_system/shared/_navigation.html.erb
|
|
97
|
+
- lib/generators/living_design_system/install/install_generator.rb
|
|
98
|
+
- lib/generators/living_design_system/install/templates/getting_started.html.erb
|
|
99
|
+
- lib/generators/living_design_system/install/templates/initializer.rb
|
|
100
|
+
- lib/living_design_system.rb
|
|
101
|
+
- lib/living_design_system/catalog.rb
|
|
102
|
+
- lib/living_design_system/component_doc.rb
|
|
103
|
+
- lib/living_design_system/configuration.rb
|
|
104
|
+
- lib/living_design_system/engine.rb
|
|
105
|
+
- lib/living_design_system/example_sources.rb
|
|
106
|
+
- lib/living_design_system/nav_link.rb
|
|
107
|
+
- lib/living_design_system/routing.rb
|
|
108
|
+
- lib/living_design_system/styles.css
|
|
109
|
+
- lib/living_design_system/version.rb
|
|
110
|
+
homepage: https://github.com/andrewhavens/living_design_system
|
|
111
|
+
licenses:
|
|
112
|
+
- MIT
|
|
113
|
+
metadata:
|
|
114
|
+
source_code_uri: https://github.com/andrewhavens/living_design_system
|
|
115
|
+
changelog_uri: https://github.com/andrewhavens/living_design_system/blob/main/CHANGELOG.md
|
|
116
|
+
bug_tracker_uri: https://github.com/andrewhavens/living_design_system/issues
|
|
117
|
+
rdoc_options: []
|
|
118
|
+
require_paths:
|
|
119
|
+
- lib
|
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
121
|
+
requirements:
|
|
122
|
+
- - ">="
|
|
123
|
+
- !ruby/object:Gem::Version
|
|
124
|
+
version: '3.2'
|
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
|
+
requirements:
|
|
127
|
+
- - ">="
|
|
128
|
+
- !ruby/object:Gem::Version
|
|
129
|
+
version: '0'
|
|
130
|
+
requirements: []
|
|
131
|
+
rubygems_version: 4.0.22
|
|
132
|
+
specification_version: 4
|
|
133
|
+
summary: A living design system for Rails, generated from the comment blocks above
|
|
134
|
+
your components.
|
|
135
|
+
test_files: []
|