bjornbjorn / snippetssync.ee2_addon

Save snippets as files during development
http://wedoaddons.com
21 stars 8 forks source link

prefix #10

Closed robsonsobral closed 10 years ago

robsonsobral commented 10 years ago

What do you think about to add a config variable for adding a prefix to snippets and global_variables? I thinking about something to save files as browse-happy, but to call them as {gv:browse_happy}.

bjornbjorn commented 10 years ago

Yes, that would be useful I agree. I'll add it to the pipeline.

robsonsobral commented 10 years ago

Do you want me to code this for you? I can do tomorrow and send you a pull request. Which names do you want for the variables?

bjornbjorn commented 10 years ago

Sure, feel free to contribute it if you wish!

Ideally, I think this setting should be empty. I personally use sn for snippets and gv for global variables, but I don't mind calling my files sn_global_footer.html etc. either ... I see that it will be handy in your case though with {gv: .. etc

One issue you must consider when implementing though is a case where the user has already synced 10 snippets e.g. and then set the prefix - then the old snippets need to be removed before syncing.

robsonsobral commented 10 years ago

I'm sorry.

I'm asking about the name of the config variables. What do you think about snippetssync_snippets_prefix and snippetssync_global_variables_prefix?

So, you can set them by this way:

$config['snippetssync_snippets_prefix'] = 'sn_';
$config['snippetssync_global_variables_prefix'] = 'gv_';
bjornbjorn commented 10 years ago

Ah! .. yes those names are fine!:)

robsonsobral commented 10 years ago

Unfortunately, for me, : isn't an allowed character:

{"error":"<p>The name you submitted may only contain alpha-numeric characters, underscores, and dashes<\/p>"}

We could override this, but I don't believe this is a good idea.

Unfortunately, for you, I don't believe that to remove old snippets is a good idea either. I was checking the code and the cost would be at least one new query for every snippet or global_variable.

Plus, somebody could want to set prefixes for the snippets and global_variables to be edited as files and other ones to be edited just on CP, for a client to fill an address or something like that. Now, imagine if a prefixed and a non prefixed global variable share the same name. Boom!

I'm testing the code.