Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f9e486c

Browse files
committed
Extract SVG images
Several affordances throughout the application are visualized through [`<svg>` elements][mdn-svg]. Prior to this commit, they were declared directly in the template HTML. Some of the application's iconography was shared across several parts of the interface. For instance, the commit history's `<summary>` element in mobile dimensions shared the same icon `<svg>` elements as the file diff's `<summary>` element. To re-use the shared elements, this commit adds a dependency on the [`middleman-inline_svg` gem][middleman-inline_svg], which reads files from the `source/images` directory and renders the contents of files inline as HTML, similar to what was done before. The main value that `middleman-inline_svg` provides is that it affords an opportunity for the rendering context to insert HTML attributes (like [`class`][class] and [`role`][role]) or an SVG [`<title>` element][svg-title]. To that end, this commit also [configures the extension][configuration] to specify [`role="img"`][role-img] for each SVG, since each collection of elements represents a single entity. [mdn-svg]: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/svg [middleman-inline_svg]: https://github.com/thoughtbot/middleman-inline_svg#usage [class]: https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/class [role]: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles [svg-title]: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/title [configuration]: https://github.com/thoughtbot/middleman-inline_svg#configuration [role-img]: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/Role_Img
1 parent 06969aa commit f9e486c

6 files changed

Lines changed: 15 additions & 6 deletions

File tree

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ source 'https://rubygems.org'
33
gem 'git'
44
gem 'middleman', '~> 4.2'
55
gem 'middleman-aria_current'
6+
gem 'middleman-inline_svg'
67
gem 'middleman-syntax'
78
gem 'redcarpet'
89
gem 'tzinfo-data', platforms: [:mswin, :mingw, :jruby, :x64_mingw]

Gemfile.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ GEM
8181
servolux
8282
tilt (~> 2.0.9)
8383
uglifier (~> 3.0)
84+
middleman-inline_svg (0.1.2)
85+
middleman-core (>= 3.4.1)
86+
nokogiri (>= 1.8)
8487
middleman-syntax (3.2.0)
8588
middleman-core (>= 3.2)
8689
rouge (~> 3.2)
@@ -149,6 +152,7 @@ DEPENDENCIES
149152
git
150153
middleman (~> 4.2)
151154
middleman-aria_current
155+
middleman-inline_svg
152156
middleman-syntax
153157
minitest-around
154158
redcarpet

config.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
command: build? ? "yarn build" : "yarn start",
1515
source: "tmp/dist",
1616
latency: 1
17+
activate :inline_svg do |config|
18+
config.defaults = {
19+
role: "img",
20+
}
21+
end
1722
activate :syntax
1823

1924
set :markdown_engine, :redcarpet

source/commits/_file.html.erb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
<details id="<%= name %>" <%= ("open" if expanded) %> class="border-l border-r">
22
<summary class="border-b cursor-pointer list-style-none p-4 outline-none">
3-
<svg class="h-8 mr-4 inline transform rotate-90 open:-rotate-90" viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
4-
<path fill-rule="evenodd" d="M4.646 1.646a.5.5 0 01.708 0l6 6a.5.5 0 010 .708l-6 6a.5.5 0 01-.708-.708L10.293 8 4.646 2.354a.5.5 0 010-.708z" clip-rule="evenodd"/>
5-
</svg>
3+
<%= inline_svg("caret-right.svg", class: "h-8 mr-4 inline transform rotate-90 open:-rotate-90") %>
64

75
<code class="break-all"><%= name %></code>
86
</summary>

source/images/caret-right.svg

Lines changed: 3 additions & 0 deletions
Loading

source/layouts/layout.erb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@
4242
<span class="sr-only open:hidden">Expand History</span>
4343
<span class="sr-only hidden open:initial">Collapse History</span>
4444
<div class="md:h-screen-fit flex flex-col border-b border-t h-8 w-full justify-center md:w-8 md:border-r md:border-l md:border-t-0 open:absolute inset-x-0 bottom-0 top-auto md:top-0 md:left-auto">
45-
<svg class="transform rotate-90 open:-rotate-90 md:rotate-0 md:open:rotate-180" viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
46-
<path fill-rule="evenodd" d="M4.646 1.646a.5.5 0 01.708 0l6 6a.5.5 0 010 .708l-6 6a.5.5 0 01-.708-.708L10.293 8 4.646 2.354a.5.5 0 010-.708z" clip-rule="evenodd"/>
47-
</svg>
45+
<%= inline_svg("caret-right.svg", class: "transform rotate-90 open:-rotate-90 md:rotate-0 md:open:rotate-180") %>
4846
</div>
4947
</summary>
5048

0 commit comments

Comments
 (0)