Pre-process files before open and save


#1

Hi there!
I have a question, about “what i can do in package”.
To understand what i want, i have created two illustrations.

Here a file’s [header.css, footer.css, navigation.css]
And i want to glue them in one (tmp.css), and then open in ATOM.
While editing, i want to save the result, and to do this, i need to split code and saved it to right file.

And all of this i want do in background of editor.

That’s why i need pre-process files.
But with this ‘coffee’ i don’t really understand where i need to search :frowning:
Any help is appreciated :slight_smile:


#2

The big challenge here is not intercepting open and save … it is correctly assembling and disassembling the temporary file. Do you have that code done?

The open part is easy, just show a file list and allow the user to select an arbitrary number of files, assemble them into a temp file and tell Atom to open it. The save part is also easy, there is a “saved” event … whenever it is raised, disassemble the contents of the temporary file and update the component files.

So it isn’t “pre-processing” really … it’s just “processing” :grinning:


#3

hm…is this is assembling?

i can take code:

header.css

.header
{
	color: red;
}

footer.css

.footer
{
	display: inline-block;
}

navigation.css

.navigation
{
	width: 100px;
}

and convert to:

tmp.css

// begin - header.css
.header
{
	color: red;
}
// end - header.css

// begin - footer.css
.footer
{
	display: inline-block;
}
// end - footer.css

// begin - navigation.css
.navigation
{
	width: 100px;
}
// end - navigation.css

the ‘begin’ and ‘end’ comments are ‘non-editable’.
And when i save - i split code by regexp and get the path to files.

you can try demo with ace editor