Opened 4 months ago

Last modified 3 days ago

#23263 new enhancement

Move Media's backbone template regexes

Reported by: markjaquith Owned by:
Priority: normal Milestone: Future Release
Component: Template Version: 3.5
Severity: normal Keywords: has-patch
Cc:

Description

Media has custom Backbone templating (because PHP is stupid and sometimes parses <% %> as PHP code — I know, I know). That templating should be available elsewhere instead of being specific to media.

		template: _.memoize( function( id ) {
			var compiled,
				options = {
					evaluate:    /<#([\s\S]+?)#>/g,
					interpolate: /\{\{\{([\s\S]+?)\}\}\}/g,
					escape:      /\{\{([^\}]+?)\}\}(?!\})/g,
					variable:    'data'
				};

			return function( data ) {
				compiled = compiled || _.template( $( '#tmpl-' + id ).html(), null, options );
				return compiled( data );
			};
		})

Attachments (4)

23263.diff (2.5 KB) - added by wonderboymusic 3 months ago.
23263.2.diff (1.9 KB) - added by wonderboymusic 3 months ago.
23263.3.diff (5.8 KB) - added by wonderboymusic 3 months ago.
23263.4.diff (6.8 KB) - added by wonderboymusic 3 months ago.

Download all attachments as: .zip

Change History (13)

Originally discussed in #22344 and implemented in r22415.

Last edited 4 months ago by rmccue (previous) (diff)

comment:2 follow-up: ↓ 3   wonderboymusic3 months ago

  • Keywords has-patch added; needs-patch removed

Seems like this needs to load every time we load Backbone, and it itself requires Underscore, otherwise I couldn't find a great place to load it. Introduces wp.template func in JS

comment:3 in reply to: ↑ 2   rmccue3 months ago

Replying to wonderboymusic:

Seems like this needs to load every time we load Backbone, and it itself requires Underscore, otherwise I couldn't find a great place to load it. Introduces wp.template func in JS

Patch still includes references to revisions.js and wp-jquery-ui-slider.js, otherwise looks good.

comment:4 follow-up: ↓ 5   wonderboymusic3 months ago

Latest patch gets rid of cruff and removes the template func from media

comment:5 in reply to: ↑ 4   rmccue3 months ago

Replying to wonderboymusic:

Latest patch gets rid of cruff and removes the template func from media

I think we should just set media.template = wp.template to maintain backwards compatibility here. I know that people are already using media-related JS in the wild, probably including this, so we don't want to break that too much.

Any chance of getting this committed? I just ran into this again and I want to avoid loading the media models on the front end.

comment:7 follow-up: ↓ 8   nacin6 weeks ago

This was committed in [23506/trunk/wp-includes/js/template.js] — but media went untouched, so that should be updated. I agree with media.template = wp.template.

Also, does anyone else think that wp.template is far too generic for what this is? wp.backboneTemplate? wp.backbone.template? Is there something else that might end up being a part of a wp.backbone object that could justify that?

comment:8 in reply to: ↑ 7   rmccue6 weeks ago

Replying to nacin:

This was committed in [23506/trunk/wp-includes/js/template.js] — but media went untouched, so that should be updated. I agree with media.template = wp.template.

Aha, missed that, thanks.

Also, does anyone else think that wp.template is far too generic for what this is? wp.backboneTemplate? wp.backbone.template? Is there something else that might end up being a part of a wp.backbone object that could justify that?

The original is actually _.template, so wp._.template or wp.underscore.template seems more appropriate. With that in mind, there's basically no reason to override any other Underscore.js function that I can think of.

With Backbone, I could see a custom Backbone.sync which uses admin-ajax.php instead. At the moment it's doing it at a deeper level (jQuery.ajax is replaced by wp.media.ajax) and each model appears to have its own sync code instead.

comment:9   ryan3 days ago

  • Milestone changed from 3.6 to Future Release
Note: See TracTickets for help on using tickets.