Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save awjrichards-zz/3102170 to your computer and use it in GitHub Desktop.
Save awjrichards-zz/3102170 to your computer and use it in GitHub Desktop.
An attempt at using a template in formatUploadDescription()
diff --git a/assets/www/js/upload.js b/assets/www/js/upload.js
index 5074a0a..1576a8a 100644
--- a/assets/www/js/upload.js
+++ b/assets/www/js/upload.js
@@ -47,49 +47,45 @@ function dateYMD() {
}
function formatUploadDescription( monument, campaignConfig, username ) {
- var idTemplate = campaignConfig.idField,
- idField = idTemplate.replace( '$1', monument.id ),
- license = campaignConfig.defaultOwnWorkLicence, // note the typo in the API field
- ourCategories = [
+ var ourCategories = [
'Mobile upload',
'Uploaded with Android WLM App',
'UA: ' + navigator.userAgent.match( /Android (.*?)(?=\))/g )
],
- cats = campaignConfig.defaultCategories.
- concat( campaignConfig.autoCategories ).
- concat( ourCategories ),
- autoWikiText = campaignConfig.autoWikiText;
-
- var desc = '';
- desc += '=={{int:filedesc}}==\n';
- desc += '{{Information\n';
- desc += '|description=';
-
- desc += '{{' + monument.lang + '|1=' + monument.name + '}}\n';
- desc += idField + '\n';
-
- desc += '|date=' + dateYMD() + '\n';
- desc += '|source={{own}}\n';
- desc += '|author=[[User:' + username + ']]\n';
- desc += '|permission=\n';
- desc += '|other_versions=\n';
- desc += '|other_fields=\n';
- desc += '}}\n';
-
- desc += '\n';
-
- desc += '=={{int:license-header}}==\n';
- desc += '{{self|' + license + '}}\n';
-
- desc += '\n';
-
- if ( autoWikiText.length ) {
- desc += autoWikiText + '\n';
- }
-
- cats.forEach( function( cat ) {
- desc += '[[Category:' + cat + ']]\n';
- });
-
- return desc;
+ descData = {
+ idField: campaignConfig.idField.replace( '$1', monument.id ),
+ license: campaignConfig.defaultOwnWorkLicence, // note the typo in the API field
+ username: username,
+ autoWikiText: campaignConfig.autoWikiText,
+ cats: campaignConfig.defaultCategories.
+ concat( campaignConfig.autoCategories ).
+ concat( ourCategories ),
+ date: dateYMD()
+ },
+ desc = "\
+ =={{int:filedesc}}==\n \
+ {{Information\n \
+ |description={{<%= descData.description %>}}\n \
+ <%= idField %>\n \
+ |date=<%= descData.date %>\n \
+ |source={{own}}\n \
+ |author=[[User:<%= descData.username %>]]\n \
+ |permission=\n \
+ |other_versions=\n \
+ |other_fields=\n \
+ }}\n \
+ \n\
+ =={{int:license-header}}==\n \
+ {{self|<%= descData.license %>}}\n \
+ \n\
+ <% if (descData.autoWikiText.length) { %> \
+ <%= descData.autoWikiText %>\n \
+ <% } %> \
+ \
+ <% ._each( descData.cats, function( cat ) { %> \
+ [[Category:<%= cat %>]]\n \
+ <% }); %> \
+ ";
+
+ return ._template( desc, { descData: descData } );
}
@jdlrobson
Copy link

Add

<script type="text/html" id="foo">hello <%= photo.username %></script>

in index.html

and then here in here
templates.getTemplate( 'foo' )( { photo: { username: 'jon' } } )

shouldn't need any string concatenation! (this way someone could have an alternative index.html for their app which uses the same code base)

Talking to Yuvi we reckon we should not use upload.js - and instead have a photo.js - which creates a Photo function (but this conversation can wait)

@awjrichards-zz
Copy link
Author

Won't adding the template to index.html mean we're loading a bunch of unnecessary stuff when the app loads? Would it make sense to put this in a separate template?

@jdlrobson
Copy link

We're loading in the template in js anyway :) Also being an app page load problems go away...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment