design_system 0.15.1 → 0.15.2
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 +4 -4
- data/app/components/design_system/generic/code_component.rb +39 -0
- data/app/components/design_system/generic/fixed_elements_component.rb +54 -0
- data/app/components/design_system/govuk/code_component.rb +6 -0
- data/app/components/design_system/govuk/fixed_elements_component.rb +15 -0
- data/app/components/design_system/nhsuk/code_component.rb +6 -0
- data/app/components/design_system/nhsuk/fixed_elements_component.rb +6 -0
- data/app/helpers/design_system_helper.rb +8 -11
- data/lib/design_system/components/fixed_elements.rb +70 -0
- data/lib/design_system/generic.rb +0 -2
- data/lib/design_system/govuk/form_builder.rb +13 -10
- data/lib/design_system/govuk/test_helpers/form_builder_testable.rb +3 -1
- data/lib/design_system/govuk.rb +0 -2
- data/lib/design_system/nhsuk.rb +0 -2
- data/lib/design_system/version.rb +1 -1
- metadata +11 -17
- data/lib/design_system/generic/builders/base.rb +0 -19
- data/lib/design_system/generic/builders/code.rb +0 -23
- data/lib/design_system/generic/builders/elements/backlink.rb +0 -30
- data/lib/design_system/generic/builders/elements/breadcrumbs.rb +0 -25
- data/lib/design_system/generic/builders/elements/form.rb +0 -23
- data/lib/design_system/generic/builders/elements/headings.rb +0 -32
- data/lib/design_system/generic/builders/elements/lead_paragraph.rb +0 -27
- data/lib/design_system/generic/builders/fixed_elements.rb +0 -39
- data/lib/design_system/govuk/builders/code.rb +0 -11
- data/lib/design_system/govuk/builders/elements/headings.rb +0 -18
- data/lib/design_system/govuk/builders/fixed_elements.rb +0 -12
- data/lib/design_system/nhsuk/builders/code.rb +0 -11
- data/lib/design_system/nhsuk/builders/fixed_elements.rb +0 -11
- /data/public/design_system/static/{design_system-0.15.1 → design_system-0.15.2}/design_system.js +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c43b735d9c944d2aedef0fc9e19a29a42b88ec8df6bc2b193886a61627770e92
|
|
4
|
+
data.tar.gz: 9061dc3ebeccbe8f12b1d6badb9f72a22bfe42122842dce4cae364cbbc13095a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ee7e8d53fad7cf58b0afd77d5a6c915230c904df16da97a563fa0f82f5439049d1e43805f26c1d7e5aa9c8adf2de97411efd556fde84160048e8a51b80521cf5
|
|
7
|
+
data.tar.gz: d5ac0cbbb6629d1c0a756833510c4ecf97c18826eec8a779d941555e2a81a302d7cecfef5dab8e2e3aa5326937ec1651d9236b942d3d9cfb60af5f4fb21b853b
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
module DesignSystem
|
|
2
|
+
module Generic
|
|
3
|
+
# Renders a block of code with a copy button, used by ds_code. Brand
|
|
4
|
+
# subclasses inherit the markup unchanged.
|
|
5
|
+
class CodeComponent < DesignSystem::BaseComponent
|
|
6
|
+
def initialize(code:, language:)
|
|
7
|
+
super()
|
|
8
|
+
@code = code
|
|
9
|
+
@language = language
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
attr_reader :code, :language
|
|
13
|
+
|
|
14
|
+
def call
|
|
15
|
+
content_tag(:div, class: 'app-example__code', data: { controller: 'ds--clipboard' }) do
|
|
16
|
+
copy_button + scroll_area
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
def copy_button
|
|
23
|
+
content_tag(:button, 'Copy',
|
|
24
|
+
class: 'app-example__copy-button',
|
|
25
|
+
data: { action: 'click->ds--clipboard#copy', 'ds--clipboard-target': 'buttonText' })
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def scroll_area
|
|
29
|
+
content_tag(:div, class: 'app-example__scroll', tabindex: 0) do
|
|
30
|
+
content_tag(:pre, data: { 'ds--clipboard-target': 'source' }) do
|
|
31
|
+
content_tag(:code, code,
|
|
32
|
+
data: { controller: 'ds--code-highlight' },
|
|
33
|
+
class: "hljs language-#{language}")
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
module DesignSystem
|
|
2
|
+
module Generic
|
|
3
|
+
# Renders the main container of the fixed page elements declared via
|
|
4
|
+
# `ds_fixed_elements`: the main heading, lead paragraph and form. The
|
|
5
|
+
# backlink and breadcrumbs are placed in their own page slots by the
|
|
6
|
+
# helper. Brand subclasses override only the caption markup.
|
|
7
|
+
class FixedElementsComponent < DesignSystem::BaseComponent
|
|
8
|
+
def initialize(fixed_elements:)
|
|
9
|
+
super()
|
|
10
|
+
@fixed_elements = fixed_elements
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
attr_reader :fixed_elements
|
|
14
|
+
|
|
15
|
+
def call
|
|
16
|
+
content_tag(:div) do
|
|
17
|
+
safe_buffer = ActiveSupport::SafeBuffer.new
|
|
18
|
+
|
|
19
|
+
safe_buffer.concat(render_main_heading) if fixed_elements.main_heading_config
|
|
20
|
+
safe_buffer.concat(render_lead_paragraph) if fixed_elements.lead_paragraph_content
|
|
21
|
+
safe_buffer.concat(render_form) if fixed_elements.form_object
|
|
22
|
+
|
|
23
|
+
safe_buffer
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
def render_main_heading
|
|
30
|
+
config = fixed_elements.main_heading_config
|
|
31
|
+
safe_buffer = ActiveSupport::SafeBuffer.new
|
|
32
|
+
|
|
33
|
+
safe_buffer.concat(render_caption(config[:caption])) if config[:caption]
|
|
34
|
+
safe_buffer.concat(render(DesignSystem::Registry.component(brand, :heading).new(config[:text], level: 1)))
|
|
35
|
+
|
|
36
|
+
safe_buffer
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def render_caption(caption)
|
|
40
|
+
content_tag(:span, caption)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def render_lead_paragraph
|
|
44
|
+
# Lead paragraph is a large body paragraph used at the page top, once per page.
|
|
45
|
+
content_tag('p', fixed_elements.lead_paragraph_content, class: "#{brand}-body-l")
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def render_form
|
|
49
|
+
name = fixed_elements.form_object.class.name.underscore
|
|
50
|
+
helpers.render('form', name.to_sym => fixed_elements.form_object)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module DesignSystem
|
|
2
|
+
module Govuk
|
|
3
|
+
# GOV.UK fixed elements: renders the caption with its own modifier class.
|
|
4
|
+
class FixedElementsComponent < DesignSystem::Generic::FixedElementsComponent
|
|
5
|
+
private
|
|
6
|
+
|
|
7
|
+
# GOV.UK renders the caption before the main heading with its own
|
|
8
|
+
# modifier class. Keep the caption brief, preferably a single word or a
|
|
9
|
+
# short phrase.
|
|
10
|
+
def render_caption(caption)
|
|
11
|
+
content_tag(:span, caption, class: "#{brand}-caption-m")
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -8,24 +8,21 @@ module DesignSystemHelper
|
|
|
8
8
|
controller.send(:brand)
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
#
|
|
11
|
+
# Fixed page elements. Without a block, returns the collector (configure
|
|
12
|
+
# then call `render`). With a block, yields the collector and renders.
|
|
12
13
|
def ds_fixed_elements
|
|
13
|
-
|
|
14
|
+
fixed_elements = ::DesignSystem::Components::FixedElements.new(self)
|
|
15
|
+
return fixed_elements unless block_given?
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
instance.render
|
|
19
|
-
else
|
|
20
|
-
instance
|
|
21
|
-
end
|
|
17
|
+
yield fixed_elements
|
|
18
|
+
fixed_elements.render
|
|
22
19
|
end
|
|
23
20
|
|
|
24
21
|
def ds_form_builder
|
|
25
22
|
DesignSystem::Registry.form_builder(brand)
|
|
26
23
|
end
|
|
27
24
|
|
|
28
|
-
def ds_form_with(model:
|
|
25
|
+
def ds_form_with(model: false, scope: nil, url: nil, format: nil, **options, &)
|
|
29
26
|
form_with(model:, scope:, url:, format:, builder: ds_form_builder, **options, &)
|
|
30
27
|
end
|
|
31
28
|
|
|
@@ -172,6 +169,6 @@ module DesignSystemHelper
|
|
|
172
169
|
end
|
|
173
170
|
|
|
174
171
|
def ds_code(code, language)
|
|
175
|
-
DesignSystem::Registry.
|
|
172
|
+
render DesignSystem::Registry.component(brand, :code).new(code:, language:)
|
|
176
173
|
end
|
|
177
174
|
end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module DesignSystem
|
|
4
|
+
module Components
|
|
5
|
+
# Collects the fixed page elements declared via `ds_fixed_elements`
|
|
6
|
+
# (backlink, breadcrumbs, main heading, lead paragraph and form).
|
|
7
|
+
# Returned when the helper is called without a block so callers can
|
|
8
|
+
# configure it and call `render` themselves; with a block the helper
|
|
9
|
+
# yields this collector then calls `render`.
|
|
10
|
+
#
|
|
11
|
+
# The per-brand FixedElementsComponent turns the collected data into
|
|
12
|
+
# markup. Backlink/breadcrumbs use content_for on the view context
|
|
13
|
+
# (not inside the component, whose content_for uses a separate flow).
|
|
14
|
+
class FixedElements
|
|
15
|
+
attr_reader :backlink, :breadcrumbs, :main_heading_config, :lead_paragraph_content, :form_object
|
|
16
|
+
|
|
17
|
+
delegate :brand, to: :@view_context
|
|
18
|
+
|
|
19
|
+
def initialize(view_context)
|
|
20
|
+
@view_context = view_context
|
|
21
|
+
@breadcrumbs = []
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def backlink(label, path)
|
|
25
|
+
@backlink = { label: label || 'Back', path: }
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def breadcrumb(label, path)
|
|
29
|
+
@breadcrumbs << { label:, path: }
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def main_heading(text, caption: nil)
|
|
33
|
+
@main_heading_config = { text:, caption: }
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def lead_paragraph(text = nil, &block)
|
|
37
|
+
raise ArgumentError, 'Lead paragraph can only be used once per page' if @lead_paragraph_content
|
|
38
|
+
|
|
39
|
+
@lead_paragraph_content = block ? @view_context.capture(&block) : text
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def form(object)
|
|
43
|
+
@form_object = object
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def render
|
|
47
|
+
raise ArgumentError, 'Cannot use both backlink and breadcrumbs' if @backlink.present? && @breadcrumbs.present?
|
|
48
|
+
|
|
49
|
+
assign_slots
|
|
50
|
+
render_component(:fixed_elements, fixed_elements: self)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
private
|
|
54
|
+
|
|
55
|
+
def assign_slots
|
|
56
|
+
@view_context.content_for(:breadcrumbs) { render_component(:breadcrumbs, breadcrumbs:) } if @breadcrumbs.any?
|
|
57
|
+
|
|
58
|
+
return unless @backlink.present?
|
|
59
|
+
|
|
60
|
+
@view_context.content_for(:backlink) do
|
|
61
|
+
@view_context.link_to(@backlink[:label], @backlink[:path], class: "#{brand}-back-link")
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def render_component(name, **kwargs)
|
|
66
|
+
@view_context.render DesignSystem::Registry.component(brand, name).new(**kwargs)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
@@ -397,27 +397,30 @@ module DesignSystem
|
|
|
397
397
|
|
|
398
398
|
def translated_label_for_value(method, value)
|
|
399
399
|
# This method is used to translate the label for a given value
|
|
400
|
-
# Example: assign an alternative name for checkbox items
|
|
400
|
+
# Example: assign an alternative name for checkbox items via
|
|
401
|
+
# `helpers.options.<model>.<method>.<value>`.
|
|
401
402
|
method_and_value = "#{method}.#{value}"
|
|
402
403
|
translation = ActionView::Helpers::Tags::Translator
|
|
403
404
|
.new(object, object_name, method_and_value, scope: 'helpers.options')
|
|
404
405
|
.translate
|
|
405
406
|
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
#
|
|
409
|
-
#
|
|
410
|
-
#
|
|
411
|
-
if translation
|
|
407
|
+
# When no translation exists, ActionView's Translator falls back to
|
|
408
|
+
# `human_attribute_name`, whose output for dotted values differs between
|
|
409
|
+
# Rails versions (e.g. Rails 7.2+ returns "Role/made up..." for values
|
|
410
|
+
# ending in a dot). Recompute that exact fallback and, when the Translator
|
|
411
|
+
# returned it, use the literal value instead of the mangled humanization.
|
|
412
|
+
if translation.blank? || translation == human_attribute_name_fallback(method_and_value)
|
|
412
413
|
value.to_s
|
|
413
414
|
else
|
|
414
415
|
translation
|
|
415
416
|
end
|
|
416
417
|
end
|
|
417
418
|
|
|
418
|
-
def
|
|
419
|
-
|
|
420
|
-
|
|
419
|
+
def human_attribute_name_fallback(method_and_value)
|
|
420
|
+
model = object.respond_to?(:to_model) ? object.to_model : nil
|
|
421
|
+
return unless model && model.class.respond_to?(:human_attribute_name)
|
|
422
|
+
|
|
423
|
+
model.class.human_attribute_name(method_and_value)
|
|
421
424
|
end
|
|
422
425
|
|
|
423
426
|
# GOVUKDesignSystemFormBuilder::Base field_id method
|
|
@@ -69,7 +69,9 @@ module DesignSystem
|
|
|
69
69
|
assert_equal 'assistant[desired_filling][]', input['name']
|
|
70
70
|
assert_equal '', input['value']
|
|
71
71
|
assert_equal 'hidden', input['type']
|
|
72
|
-
|
|
72
|
+
# NB: the hidden field's `autocomplete="off"` is a Rails framework detail
|
|
73
|
+
# (Rails 8.1 drops it by default via remove_hidden_field_autocomplete), so
|
|
74
|
+
# it isn't asserted here.
|
|
73
75
|
|
|
74
76
|
assert_select("div.#{@brand}-checkboxes[data-module='#{@brand}-checkboxes']") do
|
|
75
77
|
assert_select("div.#{@brand}-checkboxes__item") do
|
data/lib/design_system/govuk.rb
CHANGED
data/lib/design_system/nhsuk.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: design_system
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.15.
|
|
4
|
+
version: 0.15.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Filis Liu
|
|
@@ -32,14 +32,14 @@ dependencies:
|
|
|
32
32
|
requirements:
|
|
33
33
|
- - ">="
|
|
34
34
|
- !ruby/object:Gem::Version
|
|
35
|
-
version: 7.
|
|
35
|
+
version: '7.2'
|
|
36
36
|
type: :runtime
|
|
37
37
|
prerelease: false
|
|
38
38
|
version_requirements: !ruby/object:Gem::Requirement
|
|
39
39
|
requirements:
|
|
40
40
|
- - ">="
|
|
41
41
|
- !ruby/object:Gem::Version
|
|
42
|
-
version: 7.
|
|
42
|
+
version: '7.2'
|
|
43
43
|
- !ruby/object:Gem::Dependency
|
|
44
44
|
name: stimulus-rails
|
|
45
45
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -401,8 +401,10 @@ files:
|
|
|
401
401
|
- app/components/design_system/generic/button_component.rb
|
|
402
402
|
- app/components/design_system/generic/callout_component.html.erb
|
|
403
403
|
- app/components/design_system/generic/callout_component.rb
|
|
404
|
+
- app/components/design_system/generic/code_component.rb
|
|
404
405
|
- app/components/design_system/generic/details_component.html.erb
|
|
405
406
|
- app/components/design_system/generic/details_component.rb
|
|
407
|
+
- app/components/design_system/generic/fixed_elements_component.rb
|
|
406
408
|
- app/components/design_system/generic/grid_component.html.erb
|
|
407
409
|
- app/components/design_system/generic/grid_component.rb
|
|
408
410
|
- app/components/design_system/generic/heading_component.rb
|
|
@@ -433,7 +435,9 @@ files:
|
|
|
433
435
|
- app/components/design_system/govuk/button_component.rb
|
|
434
436
|
- app/components/design_system/govuk/callout_component.html.erb
|
|
435
437
|
- app/components/design_system/govuk/callout_component.rb
|
|
438
|
+
- app/components/design_system/govuk/code_component.rb
|
|
436
439
|
- app/components/design_system/govuk/details_component.rb
|
|
440
|
+
- app/components/design_system/govuk/fixed_elements_component.rb
|
|
437
441
|
- app/components/design_system/govuk/grid_component.rb
|
|
438
442
|
- app/components/design_system/govuk/heading_component.rb
|
|
439
443
|
- app/components/design_system/govuk/inset_text_component.rb
|
|
@@ -456,7 +460,9 @@ files:
|
|
|
456
460
|
- app/components/design_system/nhsuk/breadcrumbs_component.rb
|
|
457
461
|
- app/components/design_system/nhsuk/button_component.rb
|
|
458
462
|
- app/components/design_system/nhsuk/callout_component.rb
|
|
463
|
+
- app/components/design_system/nhsuk/code_component.rb
|
|
459
464
|
- app/components/design_system/nhsuk/details_component.rb
|
|
465
|
+
- app/components/design_system/nhsuk/fixed_elements_component.rb
|
|
460
466
|
- app/components/design_system/nhsuk/grid_component.rb
|
|
461
467
|
- app/components/design_system/nhsuk/heading_component.rb
|
|
462
468
|
- app/components/design_system/nhsuk/inset_text_component.html.erb
|
|
@@ -494,6 +500,7 @@ files:
|
|
|
494
500
|
- lib/design_system.rb
|
|
495
501
|
- lib/design_system/all.rb
|
|
496
502
|
- lib/design_system/brand_derivable.rb
|
|
503
|
+
- lib/design_system/components/fixed_elements.rb
|
|
497
504
|
- lib/design_system/components/grid.rb
|
|
498
505
|
- lib/design_system/components/list.rb
|
|
499
506
|
- lib/design_system/components/summary_list.rb
|
|
@@ -501,28 +508,15 @@ files:
|
|
|
501
508
|
- lib/design_system/components/table.rb
|
|
502
509
|
- lib/design_system/engine.rb
|
|
503
510
|
- lib/design_system/generic.rb
|
|
504
|
-
- lib/design_system/generic/builders/base.rb
|
|
505
|
-
- lib/design_system/generic/builders/code.rb
|
|
506
|
-
- lib/design_system/generic/builders/elements/backlink.rb
|
|
507
|
-
- lib/design_system/generic/builders/elements/breadcrumbs.rb
|
|
508
|
-
- lib/design_system/generic/builders/elements/form.rb
|
|
509
|
-
- lib/design_system/generic/builders/elements/headings.rb
|
|
510
|
-
- lib/design_system/generic/builders/elements/lead_paragraph.rb
|
|
511
|
-
- lib/design_system/generic/builders/fixed_elements.rb
|
|
512
511
|
- lib/design_system/generic/builders/pagination_renderer.rb
|
|
513
512
|
- lib/design_system/generic/form_builder.rb
|
|
514
513
|
- lib/design_system/govuk.rb
|
|
515
|
-
- lib/design_system/govuk/builders/code.rb
|
|
516
|
-
- lib/design_system/govuk/builders/elements/headings.rb
|
|
517
|
-
- lib/design_system/govuk/builders/fixed_elements.rb
|
|
518
514
|
- lib/design_system/govuk/builders/pagination_renderer.rb
|
|
519
515
|
- lib/design_system/govuk/form_builder.rb
|
|
520
516
|
- lib/design_system/govuk/test_helpers/form_builder_assertions_helper.rb
|
|
521
517
|
- lib/design_system/govuk/test_helpers/form_builder_testable.rb
|
|
522
518
|
- lib/design_system/helpers/css_helper.rb
|
|
523
519
|
- lib/design_system/nhsuk.rb
|
|
524
|
-
- lib/design_system/nhsuk/builders/code.rb
|
|
525
|
-
- lib/design_system/nhsuk/builders/fixed_elements.rb
|
|
526
520
|
- lib/design_system/nhsuk/builders/pagination_renderer.rb
|
|
527
521
|
- lib/design_system/nhsuk/form_builder.rb
|
|
528
522
|
- lib/design_system/registry.rb
|
|
@@ -530,7 +524,7 @@ files:
|
|
|
530
524
|
- lib/tasks/design_system_tasks.rake
|
|
531
525
|
- lib/tasks/govuk.rake
|
|
532
526
|
- lib/tasks/nhsuk.rake
|
|
533
|
-
- public/design_system/static/design_system-0.15.
|
|
527
|
+
- public/design_system/static/design_system-0.15.2/design_system.js
|
|
534
528
|
- public/design_system/static/govuk-frontend-5.11.1/fonts/bold-affa96571d-v2.woff
|
|
535
529
|
- public/design_system/static/govuk-frontend-5.11.1/fonts/bold-b542beb274-v2.woff2
|
|
536
530
|
- public/design_system/static/govuk-frontend-5.11.1/fonts/light-94a07e06a1-v2.woff2
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module DesignSystem
|
|
4
|
-
module Generic
|
|
5
|
-
module Builders
|
|
6
|
-
# This is the base class for design system builders.
|
|
7
|
-
class Base
|
|
8
|
-
include DesignSystem::BrandDerivable
|
|
9
|
-
include DesignSystem::Helpers::CssHelper
|
|
10
|
-
|
|
11
|
-
delegate :button_tag, :capture, :content_for, :content_tag, :link_to, :link_to_unless_current, to: :@context
|
|
12
|
-
|
|
13
|
-
def initialize(context)
|
|
14
|
-
@context = context
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module DesignSystem
|
|
4
|
-
module Generic
|
|
5
|
-
module Builders
|
|
6
|
-
# Renders a code block with copy button.
|
|
7
|
-
class Code < Base
|
|
8
|
-
def render_code(code, language)
|
|
9
|
-
content_tag(:div, class: 'app-example__code', data: { controller: 'ds--clipboard' }) do
|
|
10
|
-
content_tag(:button, 'Copy', class: 'app-example__copy-button',
|
|
11
|
-
data: { action: 'click->ds--clipboard#copy', 'ds--clipboard-target': 'buttonText' }) +
|
|
12
|
-
content_tag(:div, class: 'app-example__scroll', tabindex: 0) do
|
|
13
|
-
content_tag(:pre, data: { 'ds--clipboard-target': 'source' }) do
|
|
14
|
-
content_tag(:code, code, data: { controller: 'ds--code-highlight' },
|
|
15
|
-
class: "hljs language-#{language}")
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module DesignSystem
|
|
4
|
-
module Generic
|
|
5
|
-
module Builders
|
|
6
|
-
module Elements
|
|
7
|
-
# This mixin module is used to provide back link.
|
|
8
|
-
module Backlink
|
|
9
|
-
def backlink(label, path)
|
|
10
|
-
@backlink = true
|
|
11
|
-
@label = label || 'Back'
|
|
12
|
-
@path = path
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
private
|
|
16
|
-
|
|
17
|
-
def content_for_backlink
|
|
18
|
-
content_for(:backlink) do
|
|
19
|
-
render_backlink
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def render_backlink
|
|
24
|
-
link_to(@label, @path, class: "#{brand}-back-link")
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
module DesignSystem
|
|
2
|
-
module Generic
|
|
3
|
-
module Builders
|
|
4
|
-
module Elements
|
|
5
|
-
# This mixin accumulates breadcrumbs and renders them into the
|
|
6
|
-
# :breadcrumbs content_for slot via the per-brand BreadcrumbsComponent.
|
|
7
|
-
module Breadcrumbs
|
|
8
|
-
def breadcrumb(label, path)
|
|
9
|
-
@breadcrumbs ||= []
|
|
10
|
-
@breadcrumbs << { label:, path: }
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
private
|
|
14
|
-
|
|
15
|
-
def content_for_breadcrumbs
|
|
16
|
-
content_for(:breadcrumbs) do
|
|
17
|
-
component = ::DesignSystem::Registry.component(brand, :breadcrumbs).new(breadcrumbs: @breadcrumbs)
|
|
18
|
-
@context.render(component)
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
module DesignSystem
|
|
2
|
-
module Generic
|
|
3
|
-
module Builders
|
|
4
|
-
module Elements
|
|
5
|
-
# This mixin module is used to provide a form.
|
|
6
|
-
module Form
|
|
7
|
-
def form(object)
|
|
8
|
-
@form_object = object
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
private
|
|
12
|
-
|
|
13
|
-
def render_form
|
|
14
|
-
name = @form_object.class.name.underscore
|
|
15
|
-
|
|
16
|
-
options = { name.to_sym => @context.instance_variable_get(:"@#{name}") }
|
|
17
|
-
@context.render('form', options)
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
module DesignSystem
|
|
2
|
-
module Generic
|
|
3
|
-
module Builders
|
|
4
|
-
module Elements
|
|
5
|
-
# This mixin module is used to provide page headings.
|
|
6
|
-
module Headings
|
|
7
|
-
def main_heading(text, caption: nil)
|
|
8
|
-
@main_heading = text
|
|
9
|
-
@caption = caption
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
private
|
|
13
|
-
|
|
14
|
-
def render_main_heading
|
|
15
|
-
safe_buffer = ActiveSupport::SafeBuffer.new
|
|
16
|
-
|
|
17
|
-
safe_buffer.concat(render_caption) if @caption
|
|
18
|
-
safe_buffer.concat(
|
|
19
|
-
DesignSystem::Registry.component(brand, :heading).new(@main_heading, level: 1).render_in(@context)
|
|
20
|
-
)
|
|
21
|
-
|
|
22
|
-
safe_buffer
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def render_caption
|
|
26
|
-
content_tag(:span, @caption)
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module DesignSystem
|
|
4
|
-
module Generic
|
|
5
|
-
module Builders
|
|
6
|
-
module Elements
|
|
7
|
-
# This mixin module is used to provide lead paragraphs.
|
|
8
|
-
module LeadParagraph
|
|
9
|
-
def lead_paragraph(text = nil, &)
|
|
10
|
-
raise ArgumentError, 'Lead paragraph can only be used once per page' if @lead_paragraph
|
|
11
|
-
|
|
12
|
-
@lead_paragraph = block_given? ? capture(&) : text
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
private
|
|
16
|
-
|
|
17
|
-
def render_lead_paragraph
|
|
18
|
-
# Lead paragraph is a large body paragraph that should be used at the page top and once per page.
|
|
19
|
-
return unless @lead_paragraph
|
|
20
|
-
|
|
21
|
-
content_tag('p', @lead_paragraph, class: "#{brand}-body-l")
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module DesignSystem
|
|
4
|
-
module Generic
|
|
5
|
-
module Builders
|
|
6
|
-
# This class is used to provide the generic fixed elements builder.
|
|
7
|
-
class FixedElements < Base
|
|
8
|
-
include Elements::Backlink
|
|
9
|
-
include Elements::Breadcrumbs
|
|
10
|
-
include Elements::Form
|
|
11
|
-
include Elements::Headings
|
|
12
|
-
include Elements::LeadParagraph
|
|
13
|
-
|
|
14
|
-
def render
|
|
15
|
-
raise ArgumentError, 'Cannot use both backlink and breadcrumbs' if @backlink && @breadcrumbs.present?
|
|
16
|
-
|
|
17
|
-
content_for_breadcrumbs if @breadcrumbs.present?
|
|
18
|
-
content_for_backlink if @backlink.present?
|
|
19
|
-
|
|
20
|
-
render_main_container do
|
|
21
|
-
safe_buffer = ActiveSupport::SafeBuffer.new
|
|
22
|
-
|
|
23
|
-
safe_buffer.concat(render_main_heading) if @main_heading
|
|
24
|
-
safe_buffer.concat(render_lead_paragraph) if @lead_paragraph
|
|
25
|
-
safe_buffer.concat(render_form) if @form_object
|
|
26
|
-
|
|
27
|
-
safe_buffer
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
private
|
|
32
|
-
|
|
33
|
-
def render_main_container(&)
|
|
34
|
-
content_tag(:div, &)
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
module DesignSystem
|
|
2
|
-
module Govuk
|
|
3
|
-
module Builders
|
|
4
|
-
module Elements
|
|
5
|
-
# This mixin module is used to provide GOV.UK page headings.
|
|
6
|
-
module Headings
|
|
7
|
-
private
|
|
8
|
-
|
|
9
|
-
# GOVUK renders caption before main heading.
|
|
10
|
-
# Keep the caption brief, preferably a single word or a short phrase
|
|
11
|
-
def render_caption
|
|
12
|
-
content_tag(:span, @caption, class: "#{brand}-caption-m")
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module DesignSystem
|
|
4
|
-
module Govuk
|
|
5
|
-
module Builders
|
|
6
|
-
# This class is used to provide the GOVUK fixed elements builder.
|
|
7
|
-
class FixedElements < ::DesignSystem::Generic::Builders::FixedElements
|
|
8
|
-
include Elements::Headings
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
end
|
/data/public/design_system/static/{design_system-0.15.1 → design_system-0.15.2}/design_system.js
RENAMED
|
File without changes
|