Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible add a transformation without any associated attribute? #36

Closed
andrewaguiar opened this issue May 16, 2016 · 3 comments
Closed

Comments

@andrewaguiar
Copy link
Contributor

Is it possible add a transformation without any associated attribute? For instance, I would like to add a transformation to every svg without a specific attribute eg:

InlineSvg.configure do |config|
  # Is it possible
  config.add_custom_transformation(transform: SetFocusableToFalseTransform)
end

and the transformation

class SetFocusableToFalseTransform < InlineSvg::CustomTransformation
  def transform(doc)
    svg = doc.at_css('svg')
    svg['focusable'] = 'false'
    doc
  end
end

Thanks

@jamesmartin
Copy link
Owner

jamesmartin commented May 17, 2016

Is it possible add a transformation without any associated attribute?

@andrewaguiar No, sorry. It's not possible, but I'm open to changing the gem to accommodate "static" custom transformations.

As a workaround I suggest rewriting your transformation like this:

class SetFocusableTransform < InlineSvg::CustomTransformation
  def transform(doc)
    svg = doc.at_css('svg')
    svg['focusable'] = !!value.to_s
    doc
  end
end

Configure it like this:

InlineSvg.configure do |config|
  config.add_custom_transformation(attribute: :focusable, transform: SetFocusableToFalseTransform)
end

And use it like this:

inline_svg('some-document.svg', focusable: true)
inline_svg('some-document.svg', focusable: false)

@andrewaguiar
Copy link
Contributor Author

@jamesmartin I sent a PR with an implementation of somthing that can be used to do this #37

Thanks

@jamesmartin
Copy link
Owner

Fixed in v0.8.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants