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

Allow for optional attributes in script tag #1

Closed
gsick opened this issue Feb 5, 2014 · 3 comments
Closed

Allow for optional attributes in script tag #1

gsick opened this issue Feb 5, 2014 · 3 comments

Comments

@gsick
Copy link

gsick commented Feb 5, 2014

Hi,

It would be nice to have 'options' for the final script file to be able to add 'defer' or 'async' attributes.
More generic, be able to add 'attr'='value' in the script tag.

Thx

@VFK
Copy link
Owner

VFK commented Feb 6, 2014

I actually thought about it many times and the situation is ambiguous. The plugin is called "gulp-html-replace", right? The initial idea was to give users more freedom. I mean not just add attributes but to be able to change default script templates. Like, you think that "rel" attribute in css tag needs to be after "href"? Here, do that. Want to add text instead of script? Make a template. Need to remove attribute instead of adding? Make a template without it. It could be really cool and powerful on the one hand, but i'm scared it could turn your clean code into a mess. I mean the template option will be optional of course, but anyway...
What do you think?

@gsick
Copy link
Author

gsick commented Feb 6, 2014

I like this plugin because it does just what I need (except more control on script tag).
Yes, the situation is ambiguous because the plugin force you to use its own syntax for css and script tag.It is not a replace, it is more for change dev html file into prod html file (rename ccs and script by their build name).
I make the assumption that the code in the gulp file (client side) should stay simple.
For only one css or script file it should just replace the value of 'src' and 'href' attribute....
but for many script or css, if you want to keep some attribute of the original tag you need options,
specifiq rules and it will become a mess (both side, plugin and client).

if you want full template with full freedom, it should be something like that:
htmlreplace({'html': 'tpl/file.html'})
...
if .html
replace the block by the content of 'file.html'
end
...
But in this case, I will still need to change the 'src' att in the script tag in the 'file.html'..

One simple solution could be to add the html replace stuff and add the ability with an option
to override the default script or css template in the 'block.js' file:
{'script':'<script type="text/javascript" src=""></script>'} -> for example if I want use html4 syntax..
As it you keep the default behaviour and add more flexibility.

I hope this is understandable ;)

@VFK
Copy link
Owner

VFK commented Feb 6, 2014

I updated the plugin, now you can change the templates. Please refer to readme file.
As a tradeoff your gulpfile will be less beautiful, but the plugin now can meet the most needs i think.
It's backward compatible and should solve your problem, so i'm closing this issue. Feel free to open new issue if you have suggestions on syntax, i'll continue to think about cleaner ways to do it anyway.

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