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

Option to pass styles through the style attribute #32

Open
harrisjose opened this issue Nov 3, 2016 · 4 comments
Open

Option to pass styles through the style attribute #32

harrisjose opened this issue Nov 3, 2016 · 4 comments

Comments

@harrisjose
Copy link

Would be helpful in cases where we need to style the svg using dynamically generated values or values from an external source..

@rlivsey
Copy link
Member

rlivsey commented Nov 3, 2016

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?

@harrisjose
Copy link
Author

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.

@harrisjose
Copy link
Author

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?

@harrisjose
Copy link
Author

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 ?

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