barnardos-ruby_design_system 0.1.0 → 0.1.1
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/README.md +31 -74
- data/lib/barnardos/ruby_design_system/component_helper.rb +30 -0
- data/lib/barnardos/ruby_design_system/inputs/collection_check_boxes_input.rb +16 -0
- data/lib/barnardos/ruby_design_system/inputs/collection_select_input.rb +16 -0
- data/lib/barnardos/ruby_design_system/inputs/string_input.rb +16 -0
- data/lib/barnardos/ruby_design_system/inputs/text_input.rb +16 -0
- data/lib/barnardos/ruby_design_system/version.rb +1 -1
- data/lib/generators/barnardos/install_generator.rb +2 -0
- data/lib/generators/barnardos/templates/inputs/collection_check_boxes_input.rb +4 -0
- data/lib/generators/barnardos/templates/inputs/collection_select_input.rb +4 -0
- data/lib/generators/barnardos/templates/inputs/string_input.rb +4 -0
- data/lib/generators/barnardos/templates/inputs/text_input.rb +4 -0
- data/lib/generators/barnardos/templates/postcss.config.js +2 -0
- metadata +24 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e03581346f2bd984e9f80cf1dcac60707ec00c32264bae1595ed0eab9bea9b8a
|
4
|
+
data.tar.gz: dacbc3dfd60c95e9d89b7057e368a5ad1f533b7719ea3a1260e9a603c4d49aa4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7dfd3577281af4df7a2f04e46d661293610ff3adcbde20d34fd2fc703549cd943f6226aeba3a9b8d99c18790530198828c1f1c9bf7e02bc1646d24dd858c88ba
|
7
|
+
data.tar.gz: 44405b41e33d7471323516b2885317187204e02ffac3d50474f5516f630a53add3d560b4123742ec37fd095f73199cf665723208ab07fc639b897a4d861272d8
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Barnardos::RubyDesignSystem
|
2
2
|
|
3
|
-
Tools for
|
3
|
+
Tools for applying Barnardo's Design System to Ruby projects.
|
4
4
|
|
5
5
|
The tools include helper methods and modification to simple form to make it Design System compliant.
|
6
6
|
|
@@ -16,11 +16,30 @@ And then execute:
|
|
16
16
|
|
17
17
|
$ bundle
|
18
18
|
|
19
|
-
|
19
|
+
With the gem install, a Rails generator is added that will set up the host app. To run the generator
|
20
|
+
execute the following at app root:
|
21
|
+
|
22
|
+
$ rails g barnardos:install
|
23
|
+
|
24
|
+
Then restart the server and the changes should take effect.
|
25
|
+
|
26
|
+
Have a look at `lib/generators/barnardos/install_generator.rb` for the details of the generator's actions.
|
27
|
+
|
28
|
+
As an outline it does the following:
|
29
|
+
|
30
|
+
### Installs the barnardos components in the webpaker environment
|
31
|
+
|
32
|
+
These provide the CSS and JS needed for the components to work properly
|
33
|
+
|
34
|
+
### Installs PostCSS
|
20
35
|
|
21
36
|
The CSS used in the Design System requires processing in JavaScript space by PostCSS.
|
22
37
|
|
23
|
-
|
38
|
+
The file `package.json` is updated to include declarations for PostCSS and related plugins.
|
39
|
+
|
40
|
+
The PostCSS configuration file `/postcss.config.js` is copied to root
|
41
|
+
|
42
|
+
#### Updates `/app/views/layouts/application.html.erb`
|
24
43
|
|
25
44
|
All CSS should be defined within the folder `app/javascript` so the `stylesheet_link_tag` declaration can be removed
|
26
45
|
from the application template. Also make sure that JavaScript is loaded here with `javascript_pack_tag`. For example:
|
@@ -29,69 +48,22 @@ from the application template. Also make sure that JavaScript is loaded here wit
|
|
29
48
|
<%= javascript_pack_tag 'application' %>
|
30
49
|
```
|
31
50
|
|
32
|
-
|
33
|
-
|
34
|
-
Update `package.json` to include declarations for PostCSS and related plugins.
|
35
|
-
|
36
|
-
Also while this file is being modified, add `@barnardos/components` which will make the Design System code
|
37
|
-
available.
|
51
|
+
### Sets up simple form to work with the design system
|
38
52
|
|
39
|
-
|
53
|
+
A set of classes are inserted into `app/inputs`. These modify the rails input classes so that when used
|
54
|
+
with simple_form, they create components that match the design system.
|
40
55
|
|
41
|
-
|
42
|
-
{
|
43
|
-
"name": "my_app",
|
44
|
-
"private": true,
|
45
|
-
"dependencies": {
|
46
|
-
"@barnardos/components": "^1.0.0",
|
47
|
-
"@rails/actioncable": "^6.0.0-alpha",
|
48
|
-
"@rails/activestorage": "^6.0.0-alpha",
|
49
|
-
"@rails/ujs": "^6.0.0-alpha",
|
50
|
-
"@rails/webpacker": "^4.0.7",
|
51
|
-
"polyfill-nodelist-foreach": "^1.0.1",
|
52
|
-
"postcss-browser-reporter": "^0.6.0",
|
53
|
-
"postcss-import": "^12.0.1",
|
54
|
-
"postcss-inline-svg": "^4.1.0",
|
55
|
-
"postcss-preset-env": "^6.7.0",
|
56
|
-
"postcss-reporter": "^6.0.1",
|
57
|
-
"postcss-svgo": "^4.0.2"
|
58
|
-
},
|
59
|
-
"version": "0.1.0",
|
60
|
-
"devDependencies": {
|
61
|
-
"webpack-dev-server": "^3.9.0"
|
62
|
-
}
|
63
|
-
}
|
64
|
-
```
|
56
|
+
## Using the components
|
65
57
|
|
66
|
-
|
58
|
+
### `app/helpers/application_helper.rb`
|
67
59
|
|
68
|
-
|
60
|
+
To use the helper methods defined in this gem, add the following to `ApplicationHelper`:
|
69
61
|
|
70
|
-
```
|
71
|
-
|
72
|
-
plugins: [
|
73
|
-
require("postcss-import"),
|
74
|
-
require("postcss-preset-env")({
|
75
|
-
autoprefixer: {},
|
76
|
-
features: {
|
77
|
-
"focus-within": true,
|
78
|
-
"nesting-rules": true,
|
79
|
-
"color-mod-function": {
|
80
|
-
unresolved: "warn"
|
81
|
-
},
|
82
|
-
"custom-properties": {
|
83
|
-
preserve: false,
|
84
|
-
warnings: true
|
85
|
-
}
|
86
|
-
}
|
87
|
-
}),
|
88
|
-
require("postcss-browser-reporter"),
|
89
|
-
require("postcss-reporter")
|
90
|
-
]
|
91
|
-
});
|
62
|
+
```ruby
|
63
|
+
include Barnardos::RubyDesignSystem::ComponentHelper
|
92
64
|
```
|
93
65
|
|
94
|
-
|
66
|
+
### `/app/javascript/packs/application.js`
|
95
67
|
|
96
68
|
For each Design System component you wish to use in the app, add a line to `application.js` in the form:
|
97
69
|
|
@@ -113,21 +85,6 @@ import "@barnardos/components/src/components/Title/index.css";
|
|
113
85
|
This will load the associated CSS where it can be processed by PostCSS. The list of imports can get quite long, so
|
114
86
|
placing them in alphabetical order is a good idea as it makes them a little easier to manage.
|
115
87
|
|
116
|
-
#### Complete PostCSS installation
|
117
|
-
|
118
|
-
The following two commands will clear out the current Webpacker setup and install the requires elements:
|
119
|
-
|
120
|
-
```bash
|
121
|
-
rake webpacker:clobber
|
122
|
-
yarn
|
123
|
-
```
|
124
|
-
|
125
|
-
Then restart the server and the changes should take effect.
|
126
|
-
|
127
|
-
## Usage
|
128
|
-
|
129
|
-
TODO: Write usage instructions here
|
130
|
-
|
131
88
|
## Development
|
132
89
|
|
133
90
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -1,6 +1,19 @@
|
|
1
1
|
module Barnardos
|
2
2
|
module RubyDesignSystem
|
3
|
+
# Provides helper methods available in the host app's server.
|
4
|
+
#
|
5
|
+
# Usage: Add the following to `/app/helpers/application_helper.rb` within the module `ApplicationHelper`:
|
6
|
+
#
|
7
|
+
# include Barnardos::RubyDesignSystem::ComponentHelper
|
8
|
+
#
|
3
9
|
module ComponentHelper
|
10
|
+
|
11
|
+
# Creates a ProminentLink Component.
|
12
|
+
#
|
13
|
+
# @param name [String] Link text that appears on page
|
14
|
+
# @param options Same as `link_to` see {https://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to Rails API}
|
15
|
+
# @param html_options [Hash] Also same as `link_to` with additional option `colour` which sets the ProminentLink colour
|
16
|
+
# @return [String] HTML anchor with class `ProminentLink` and optionally `ProminentLink--<colour>` if colour entered
|
4
17
|
def prominent_link(name = nil, options = nil, html_options = {}, &block)
|
5
18
|
colour = html_options.delete(:colour)
|
6
19
|
colour_class = colour && "ProminentLink--#{colour}"
|
@@ -8,20 +21,37 @@ module Barnardos
|
|
8
21
|
link_to(name, options, html_options, &block)
|
9
22
|
end
|
10
23
|
|
24
|
+
# Creates a SkipLink Component
|
25
|
+
#
|
26
|
+
# @param text [String] Link text that appears on page
|
27
|
+
# @param anchor [String] the anchor name that is the target for the skip link
|
28
|
+
# @return [String] HTML anchor with class `SkipLink`
|
11
29
|
def skip_link(text, anchor: '#main-anchor')
|
12
30
|
link_to text, anchor, class: 'SkipLink'
|
13
31
|
end
|
14
32
|
|
33
|
+
# Creates a Link Component
|
34
|
+
#
|
35
|
+
# All parameters are as `link_to` see {https://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to Rails API}
|
36
|
+
# @return [String] HTML anchor with class `Link`
|
15
37
|
def link(name = nil, options = nil, html_options = {}, &block)
|
16
38
|
html_options[:class] = [html_options[:class], 'Link'].flatten.compact
|
17
39
|
link_to(name, options, html_options, &block)
|
18
40
|
end
|
19
41
|
|
42
|
+
# Overrides the Rails helper method `link_to`
|
43
|
+
# Adds the `html_options` option `new_window` which changes the link so that it will link to a new window
|
44
|
+
# @return [String] HTML anchor with `target` set as `_blank` if html_options include `new_window: true`
|
20
45
|
def link_to(name = nil, options = nil, html_options = {}, &block)
|
21
46
|
html_options[:target] = '_blank' if html_options.delete(:new_window)
|
22
47
|
super
|
23
48
|
end
|
24
49
|
|
50
|
+
# Creates a FieldSet Component around passed in block. Also adds Fieldset-children inner wrapper around block
|
51
|
+
#
|
52
|
+
# @param legend [String] outputs into a Fieldset-legend component within the Fieldset if set
|
53
|
+
# @param hint [String] outputs into a Hint component within the Fieldset if set
|
54
|
+
# @return [String] HTML containing the passed in block wrapped by a Fieldset Component and sub components
|
25
55
|
def fieldset(legend: nil, hint: nil)
|
26
56
|
content_tag :fieldset, class: 'Fieldset' do
|
27
57
|
concat(content_tag(:legend, legend, class: 'Fieldset-legend')) if legend
|
@@ -3,6 +3,22 @@
|
|
3
3
|
module Barnardos
|
4
4
|
module RubyDesignSystem
|
5
5
|
module Inputs
|
6
|
+
# Overrides behaviour of the collection check boxes input in simple_form forms.
|
7
|
+
#
|
8
|
+
# Usage:
|
9
|
+
# Add the following class to the host project at app/inputs/collection_check_boxes_input.rb
|
10
|
+
#
|
11
|
+
# class CollectionCheckBoxesInput < Barnardos::RubyDesignSystem::Inputs::CollectionCheckBoxesInput; end
|
12
|
+
#
|
13
|
+
# With that in place, the following code will output a set of collection boxes wrapped in the required
|
14
|
+
# Design System components:
|
15
|
+
#
|
16
|
+
# <%= simple_form_for(foo) do |form| %>
|
17
|
+
# <%= form.association :bars, as: :check_boxes, wrapper: :in_fieldset, boolean_style: :inline %>
|
18
|
+
# <% end %>
|
19
|
+
#
|
20
|
+
# Where `foo` has_many `bars`
|
21
|
+
#
|
6
22
|
class CollectionCheckBoxesInput < SimpleForm::Inputs::CollectionCheckBoxesInput
|
7
23
|
def input(wrapper_options = nil)
|
8
24
|
input_html_classes.unshift('Switch-input')
|
@@ -3,6 +3,22 @@
|
|
3
3
|
module Barnardos
|
4
4
|
module RubyDesignSystem
|
5
5
|
module Inputs
|
6
|
+
# Overrides behaviour of the collection select input in simple_form forms.
|
7
|
+
#
|
8
|
+
# Usage:
|
9
|
+
# Add the following class to the host project at app/inputs/collection_select_input.rb
|
10
|
+
#
|
11
|
+
# class CollectionSelectInput < Barnardos::RubyDesignSystem::Inputs::CollectionSelectInput; end
|
12
|
+
#
|
13
|
+
# With that in place, the following code will output an HTML select input with class `Select` and wrapped in the
|
14
|
+
# required Design System components:
|
15
|
+
#
|
16
|
+
# <%= simple_form_for(foo) do |form| %>
|
17
|
+
# <%= form.association :bars, wrapper: :design_system_select %>
|
18
|
+
# <% end %>
|
19
|
+
#
|
20
|
+
# Where `foo` has_many `bars`
|
21
|
+
#
|
6
22
|
class CollectionSelectInput < SimpleForm::Inputs::CollectionSelectInput
|
7
23
|
def input(wrapper_options = nil)
|
8
24
|
input_html_classes.unshift('Select')
|
@@ -4,6 +4,22 @@ module Barnardos
|
|
4
4
|
module RubyDesignSystem
|
5
5
|
module Inputs
|
6
6
|
class StringInput < SimpleForm::Inputs::StringInput
|
7
|
+
# Overrides behaviour of the string input in simple_form forms.
|
8
|
+
#
|
9
|
+
# Usage:
|
10
|
+
# Add the following class to the host project at app/inputs/string_input.rb
|
11
|
+
#
|
12
|
+
# class StringInput < Barnardos::RubyDesignSystem::Inputs::StringInput; end
|
13
|
+
#
|
14
|
+
# With that in place, the following code will output a text input wrapped in the required
|
15
|
+
# Design System components:
|
16
|
+
#
|
17
|
+
# <%= simple_form_for(foo) do |form| %>
|
18
|
+
# <%= form.input :bar %>
|
19
|
+
# <% end %>
|
20
|
+
#
|
21
|
+
# Where `bar` is a string attribute of `foo`
|
22
|
+
#
|
7
23
|
def input(wrapper_options = nil)
|
8
24
|
input_html_classes.unshift('TextInput-input')
|
9
25
|
super
|
@@ -3,6 +3,22 @@
|
|
3
3
|
module Barnardos
|
4
4
|
module RubyDesignSystem
|
5
5
|
module Inputs
|
6
|
+
# Overrides behaviour of the text input in simple_form forms.
|
7
|
+
#
|
8
|
+
# Usage:
|
9
|
+
# Add the following class to the host project at app/inputs/text_input.rb
|
10
|
+
#
|
11
|
+
# class StringInput < Barnardos::RubyDesignSystem::Inputs::TextInput; end
|
12
|
+
#
|
13
|
+
# With that in place, the following code will output a textarea wrapped in the required
|
14
|
+
# Design System components:
|
15
|
+
#
|
16
|
+
# <%= simple_form_for(foo) do |form| %>
|
17
|
+
# <%= form.input :bar %>
|
18
|
+
# <% end %>
|
19
|
+
#
|
20
|
+
# Where `bar` is a text attribute of `foo`
|
21
|
+
#
|
6
22
|
class TextInput < SimpleForm::Inputs::TextInput
|
7
23
|
def input(wrapper_options = nil)
|
8
24
|
input_html_classes.unshift('TextArea-textarea')
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: barnardos-ruby_design_system
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob Nichols
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2020-01-
|
13
|
+
date: 2020-01-23 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: simple_form
|
@@ -58,16 +58,16 @@ dependencies:
|
|
58
58
|
name: bundler
|
59
59
|
requirement: !ruby/object:Gem::Requirement
|
60
60
|
requirements:
|
61
|
-
- - "
|
61
|
+
- - ">="
|
62
62
|
- !ruby/object:Gem::Version
|
63
|
-
version: '
|
63
|
+
version: '0'
|
64
64
|
type: :development
|
65
65
|
prerelease: false
|
66
66
|
version_requirements: !ruby/object:Gem::Requirement
|
67
67
|
requirements:
|
68
|
-
- - "
|
68
|
+
- - ">="
|
69
69
|
- !ruby/object:Gem::Version
|
70
|
-
version: '
|
70
|
+
version: '0'
|
71
71
|
- !ruby/object:Gem::Dependency
|
72
72
|
name: faker
|
73
73
|
requirement: !ruby/object:Gem::Requirement
|
@@ -166,6 +166,20 @@ dependencies:
|
|
166
166
|
- - "~>"
|
167
167
|
- !ruby/object:Gem::Version
|
168
168
|
version: 3.0.0
|
169
|
+
- !ruby/object:Gem::Dependency
|
170
|
+
name: yard
|
171
|
+
requirement: !ruby/object:Gem::Requirement
|
172
|
+
requirements:
|
173
|
+
- - "~>"
|
174
|
+
- !ruby/object:Gem::Version
|
175
|
+
version: '0.9'
|
176
|
+
type: :development
|
177
|
+
prerelease: false
|
178
|
+
version_requirements: !ruby/object:Gem::Requirement
|
179
|
+
requirements:
|
180
|
+
- - "~>"
|
181
|
+
- !ruby/object:Gem::Version
|
182
|
+
version: '0.9'
|
169
183
|
description: Includes helper methods and modification to simple form.
|
170
184
|
email:
|
171
185
|
- rob.nichols@barnardos.org.uk
|
@@ -187,6 +201,10 @@ files:
|
|
187
201
|
- lib/barnardos/ruby_design_system/version.rb
|
188
202
|
- lib/generators/barnardos/USAGE
|
189
203
|
- lib/generators/barnardos/install_generator.rb
|
204
|
+
- lib/generators/barnardos/templates/inputs/collection_check_boxes_input.rb
|
205
|
+
- lib/generators/barnardos/templates/inputs/collection_select_input.rb
|
206
|
+
- lib/generators/barnardos/templates/inputs/string_input.rb
|
207
|
+
- lib/generators/barnardos/templates/inputs/text_input.rb
|
190
208
|
- lib/generators/barnardos/templates/postcss.config.js
|
191
209
|
homepage: https://design-system.barnardos.org.uk
|
192
210
|
licenses:
|