Domanda

Looking for a way to add a custom timestamp(and maybe some extra info) inside a CSS/HTML file everytime you save the file. Is there an extention for brackets, sublime or dreamweaver that does this, Or perhaps some other way to do this?

Thanks

È stato utile?

Soluzione

I think this post will give you a Sublime Text plugin that should do what you ask.

Altri suggerimenti

In Brackets, you can configure the snippets extension to insert a timestamp manually, like the answer above for Sublime. Here's how: https://stackoverflow.com/a/18844762/1172352.

Similar to the Sublime answer, it would be a bit trickier to do it automatically every time you save. There's not yet a clean hook in Brackets for pre-save processing. Several extensions get around this by listening for a post-save event and saving quickly a second time. You could probably write a timestamp-auto-inserter extension by borrowing their code for that pattern.

Anything that runs automatically would also need a little extra code to find the old timestamp and replace it -- both the snippets solution here and the Sublime solution above just insert the timestamp wherever the cursor/selection is. A regular expression should do the trick for detection.

You'd also want to screen out other file types. Bringing it all together, it would look something like this for Brackets:

function documentSavedHandler(event, doc) {
    // TODO: need a little extra code here to ignore save events triggered
    // by ourself, to avoid infinite loop

    var langId = doc.getLanguage().getId();
    if (langId === "html" || langId === "css") {
        var pos = /* use regexp to find old timestamp */;
        doc.replaceRange(timestampStr, posStart, posEnd);
        CommandManager.execute(Commands.FILE_SAVE);
    }
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top