-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [#425] Add svg sprite addon * [#425] Add svgeez add on in place of svg sprite add on * [#425] add inline_svg gem for svgeez addon, move it to web variant * [#425] Add binary file and change wiki for svgeez addon * [#425] Fix lint * [#425] Update gemfile spec for svgeez addon * [#425] Change svgeez installation location in gemfile * [#425] Change svgeez gem location in gemfile * [#425] Add svgeez github wiki addon if .github directory exists * [#425] Remove unnecessary line from svgeez template * [#425] Add svg helper for svgeez addon * [#425] Fix lint * [#425] Modify svgeez addon test * [#425] Remove gemfile spec for svgeez * [#425] Fix lint * [#425] Change svgeez github wiki sidebar title * [#425] Add svgeez addon's gems inside development group * [#425] Change svgeez addon binary file * [#425] Change svgeez wiki file name * [#425] Remove empty line * [#425] Add inline_svg gem under production group
- Loading branch information
1 parent
613e39b
commit 6c8da12
Showing
9 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
.template/addons/svgeez/.github/wiki/Managing-SVG-Icons.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
From time to time, we need to add new SVG icons to the app. This document describes the steps to do that. | ||
|
||
## Gems | ||
The following 2 gems are used to handle SVG: | ||
- [svgeez](https://github.com/jgarber623/svgeez): for generating an SVG sprite from a folder of SVG icons. Requires Node.js and SVGO 1.3.2. | ||
- [inline_svg](https://github.com/jamesmartin/inline_svg): to use inline SVG for styling SVG with CSS | ||
|
||
## Node dependencies | ||
- [svgo](https://www.npmjs.com/package/svgo): Optimizes SVG sprite file size | ||
```sh | ||
npm -g install [email protected] | ||
``` | ||
|
||
## Add a new icon: | ||
- Export the SVG icon from Figma | ||
- Add the icon to `app/assets/images/icons` directory. | ||
- Run the following command to generate the new `app/assets/images/icon-sprite.svg` file which contains all of the icons in the `icons` directory | ||
```sh | ||
bin/svg-sprite | ||
``` | ||
|
||
## Use the new icon | ||
- Add the `icon-sprite.svg` file to the layout of the page | ||
```erb | ||
<body> | ||
<%= inline_svg_tag 'icon-sprite.svg' %> | ||
</body> | ||
``` | ||
- Use the `svg_tag` provided by the `SvgHelper` (app/helpers/svg_helper.rb) and provided `icon_id` matched with icon file name with prefix `icon-`: | ||
```erb | ||
<%= svg_tag icon_id: 'icon-[icon-file-name]', html: {} %> | ||
<!-- example: --> | ||
<%= svg_tag icon_id: 'icon-contacts', html: { class: 'icon' } %> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
if Dir.exist?('.github/wiki') | ||
use_source_path __dir__ | ||
|
||
copy_file 'Managing-SVG-Icons.md', '.github/wiki/Managing-SVG-Icons.md' | ||
|
||
# SVG Sprite | ||
insert_into_file '.github/wiki/_Sidebar.md', after: /## Operations.*\n/ do | ||
<<~RUBY | ||
- [[Managing SVG icons]] | ||
RUBY | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
# SVG Sprite | ||
insert_into_file 'Gemfile', after: /gem 'danger'.*\n/ do | ||
<<~RUBY | ||
gem 'svgeez' # Gem for generating an SVG sprite from a folder of SVG icons. | ||
RUBY | ||
end | ||
|
||
# SVG Sprite | ||
insert_into_file 'Gemfile', after: /gem 'bcrypt'.*\n/ do | ||
<<~RUBY | ||
gem 'inline_svg' # Use Inline SVG for styling SVG with CSS | ||
RUBY | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Generates an SVG sprite from a folder of SVG icons. | ||
# | ||
# Uses `svgeez` gem. | ||
# https://github.com/jgarber623/svgeez | ||
# | ||
# Usage | ||
# -s --source: Path to the folder of source SVGs (defaults to ./_svgeez). | ||
# -d --destination: Path to the destination file or folder (defaults to ./svgeez.svg) | ||
# --with-svgo: Optimize SVG sprite file with SVGO | ||
|
||
# Generate the sprite file which includes the `icon-` prefix | ||
bin/bundle exec svgeez build --prefix icon --source app/assets/images/icons/ --destination app/assets/images/icon-sprite.svg --with-svgo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
use_source_path __dir__ | ||
|
||
copy_file 'svg-sprite', 'bin/svg-sprite', mode: :preserve |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
module SvgHelper | ||
DEFAULT_SVG_ATTRIBUTES = { | ||
width: '16', | ||
height: '16' | ||
}.freeze | ||
|
||
def svg_tag(html: {}, icon_id: '') | ||
svg_attributes = DEFAULT_SVG_ATTRIBUTES.merge(html) | ||
|
||
tag.svg(tag.use(nil, 'xlink:href' => "##{icon_id}"), **svg_attributes) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
use_source_path __dir__ | ||
|
||
copy_file 'svg_helper.rb', 'app/helpers/svg_helper.rb' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# frozen_string_literal: true | ||
|
||
apply '.template/addons/svgeez/Gemfile.rb' | ||
apply '.template/addons/svgeez/bin/template.rb' | ||
apply '.template/addons/svgeez/.github/wiki/template.rb' | ||
apply '.template/addons/svgeez/helpers/template.rb' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters