Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save awjrichards-zz/3102170 to your computer and use it in GitHub Desktop.

Select an option

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
Copy Markdown

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
Copy Markdown
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
Copy Markdown

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