![Maven Central Adds Sigstore Signature Validation](https://cdn.sanity.io/images/cgdhsj6q/production/7da3bc8a946cfb5df15d7fcf49767faedc72b483-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
A Rails plugin for turning a directory of svg images into a bunch of <symbol>
tags in a sprite sheet and using them by reference. The main advantage of using <symbol>
is that you can define a viewBox for each element, which means it's possible to reuse and resize them and still make them occupy the space you'd expect them to. A common use case would be icons.
Put the gem in your Gemfile
and run bundle install
:
gem "scavenger"
Create a folder called app/assets/svg
and put your svg images there.
Add the following to views/layouts/application.html.erb
:
<%= svg_sprite_sheet %>
Now you can refer to your svg images by their name, so if you have hejsna.svg
sitting in your svg directory, you can make it show up by writing <%= svg "hejsna" %>
.
svg
helperScavenger works by inserting svg tags with references to ids defined in the sprite sheet. There is nothing inherently special about these svg tags, so if you want to add classes or attributes to them in the usual Rails fashion, you can: <%= svg "hejsna", class: "foo", style: "width:100px" %>
.
Scavenger comes with a dependency-free javascript for fetching and injecting the sprite sheet into the DOM. This is a good idea since the sprite sheet can be served from your reverse proxy and cached by the browser. Extra useful if you have a lot of symbols and don't want to bloat every page, but the downside is that users may experience a brief flash of missing icons. To use this javascript, remove the <%= svg_sprite_sheet %>
helper from your layout and instead include the javascript in your application.js
like so:
//= require scavenger
You can configure Scavenger to do your bidding. Create a file called config/initializers/scavenger.rb
and put your configuration there.
Default is app/assets/svg
but it can be changed with the following directive:
Scavenger::Config.svg_directory = Rails.root.join("app", "assets", "my_directory")
Default is app/assets/images/sprite.svg
but it can be changed with the following directive:
Scavenger::Config.sprite_path = Rails.root.join("app", "assets", "my_directory", "my_file.svg")
The svg references will get their name as the default classname, so hejsna.svg
will be inserted like this: <svg class="hejsna">
. If you want a prefix, for instance icon-
, put Scavenger::Config.class_prefix = "icon-"
in your configuration file and the svg will look like this instead: <svg class="icon-hejsna">
.
Default is "xMinYMin meet"
but it can be changed with the following directive:
Scavenger::Config.aspect_ratio = "xMaxYMax meet"
A full list of options for this directive can be found here.
Scavenger uses a basic built-in compressor. It will remove comments, non-significant whitespace, and ids from your files. Since every svg lives as a symbol
within the sprite sheet, all <defs>
tags and everything in them will be removed. Tools (like Sketch) will sometimes export your files with references inside a <defs>
tag, and use really generic ids like path-1
. That poses a problem for us since there's only one global <defs>
tag within an svg, and ids are global to the html document. We've experimented with some workarounds but nothing satisfactory, so the solution for now is to manually fix any svgs that use <defs>
tags in this way before placing them in the svg directory.
I'm Johan Halse and I work for illustrious Swedish developers Varvet. You should hire us if you need well-made, quality software!
FAQs
Unknown package
We found that scavenger demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.