GithubHelp home page GithubHelp logo

Comments (4)

rlivsey avatar rlivsey commented on June 12, 2024

I'd be happy to accept a PR for this.

An aside, I do wonder if this should be converted to be a component with tagName: 'svg'using positional parameters vs a helper then we'd get all this stuff for free?

from ember-inline-svg.

harrisjose avatar harrisjose commented on June 12, 2024

Converting it into a component seems like a cool idea. Would be happy to play around with this over the weekend, if no one else is working on it.

from ember-inline-svg.

harrisjose avatar harrisjose commented on June 12, 2024

A couple of questions, regarding converting this into a component.

I understand we'd use the component tagName property and strip the tag, but then we would need to add back all the attributes that were specified on the tag, wouldn't we? What would be the best way to go about this?

from ember-inline-svg.

harrisjose avatar harrisjose commented on June 12, 2024

I played around with this and here's a hacky version that works....

export default Ember.Component.extend({
attributeBindings: ['style'],
tagName: 'svg',
path: null,
content: null,

init() {
this._super(...arguments);
let path = this.get('path');
var jsonPath = dottify(path);

var svg = Ember.get(SVGs, jsonPath);

if (typeof svg === "undefined" && /\.svg$/.test(path)) {
  svg = Ember.get(SVGs, jsonPath.slice(0, -4));
}
Ember.assert("No SVG found for "+path, svg);

let attrs = Ember.$(svg)[0].attributes;
for (var i = 0; i < attrs.length; i++) {
  //push attribute name in to attr binding array
  this.get('attributeBindings').push(attrs[i].name);
  //set attribute as a prop
  this.set(attrs[i].name, attrs[i].value);
}
//set the contents of the svg to a prop and use that in the template
this.set('content', Ember.String.htmlSafe(Ember.$(svg).html()));
}
}).reopenClass({
positionalParams: ['path']
});

Can you let me know what changes i need to make, so that i can send a pr...
I'm also on the fence about how we should handle attribute bindings...do I explicitly specify everything like I've done for the style attribute ?

from ember-inline-svg.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.