I`ve just updated my GAE Go SDK to the newest release. I ran the gofix
on my code, but there were still some errors. The code used to look:
AnkietaTemp = template.New(nil)
err := AnkietaTemp.ParseFile("ankieta/ankieta.html")
but now passing nil doesn't seem to work, so I replaced it into:
AnkietaTemp = template.New("")
_, err := AnkietaTemp.ParseFile("ankieta/ankieta.html")
Tried running my app, but in HTML source I get:
<td width="400"><img src="images/{.section One}{#}{.end}"
alt="images/{.section One}{#}{.end}" width="100%"/></td>
Instead of a neat reference to an image file.
What is the proper way to parse the template files now, after the
update?
In the new template package the template tag syntax changed, as you can see in the documentation. E.g. dot (.) is used instead of # for referencing the "current" item and the template tags are indicated with two curly braces instead of one.
Edit: Oh, and there's no .section tag any more. You didn't provide the structure you pass to template's Execute() method so I can't provide details on how mitigate that exactly, but I guess you can use {{with}} tag like {{with One}}{.}{{end}} or maybe {{.One}}.
Related
I'm looking to add segment analytics to my JupyterLab extension. No worries if you've never heard of a JupyterLab extension - the best way to think about it: I get control over a single node in the DOM where I can place some HTML, so I'm doing the following:
function Welcome(props) {return <h1>Hello</h1>;}
ReactDOM.render(<Welcome/>, dom_element_i_control)
This all works fine - I'm now looking to add some analytics code to this. For example, I'd like to be able to:
See when my code is rendered
See when someone interacts with my rendered element (e.g. if there was a button in the Welcome function, when the user clicked on it).
However, segment is a JS library that is delivered as a script that you load into a webpage at the top in a string tag like:
<script>
!function(){var analytics=window.analytics=window.analytics||[];if(!analytics.initialize)if(analytics.invoked)window.console&&console.error&&...}}();
</script>
Where would I even put this code? I don't have control over the larger page + HTML, so I'm not sure where I can slap this so I can start using analytics.
Thanks for any information!
My workaround:
Instead of using the above linked segment script, I used the analytics-node package from segment.
I create an Analytics object right before ReactDOM.render - and then can use it wherever I want :)
Note that this will not work for anyone who uses an add blocker, obviously!
I've deployed my Hugo website using Netlify, but after my latest changes I keep getting the same error that is as follows:
Failed during stage 'deploying site': Invalid filename 'tags/c#/page/1/index.html'. Deployed filenames cannot contain # or ? characters
I can't find any file in my repository that contains such a path and my index.html doesn't contain any of those invalid characters either. I have attempted to revert the changes but I still receive the same deployment error.
Where should I be looking in my repo files to diagnose this problem?
That is pointing to an auto-generated file that lists those pages that have 'C#' as a tag in the front matter. So look for pages that have something like:
tags: [ 'C#']
in it.
In order fix, you will need to change the tag to 'c-sharp' or something similar.
Or - check that preserveTaxonomyNames is not in your site.yml (or is set to false).
This error happens when we use C# tag or other that contains # in our post/markdown because Hugo will generate static files in public folder according to the tag such as tags/c#/index.xml.
We certainly can replace with other tag like C-Sharp or similar but if we still want to see C# tag in our post there is a workaround for that.
After replacing the tag with C-Sharp for example.
tags: ["C-Sharp"]
We need to override html file where this new tag will appear, then replace following code
{{ . }}
with
{{ replace . "-Sharp" "#" }}
Please notice we replace -Sharp with # so that C# will still appear on our post but the url will be [your-site]/tags/c-sharp/ and Hugo won't generate tags/c#/index.xml in public folder. Therefore, we can avoid the error.
This is summarized from here.
I was watching some videos on Egghead.io about AngularJS. The creator of the videos uses Webstorm (and, I believe, works for them). One feature I noticed is that he can set different syntax highlighting within different scopes or quotation marks. So, in code like the following (from an AngularJS directive)
return {
template: '<div>something</div>',
// ^^^ these guys ^^^
}
...he can get the inside of the quotation marks to highlight as HTML.
I use Sublime Text 2, and am fairly wedded to it. Is there an existing feature/plugin for Sublime that could handle a case like this? If not, is something like this technically possible using the Sublime Text 2 API?
I don't think it's built in, but it's certainly possible. I've been doing some work with graphviz and wanted to do something similar. Labels can be generated with html like syntax. Anyways, I played around with the .tmLanguage file and added a new pattern to match the context where html like entries were valid (I look for label = <). The patterns I used for the captures aren't that good, but it works for fine for me. This give me the following, which I think is similar to what you are looking for.
I don't know anything about AngularJS, so I can't help you with anything specific to that, but it is certainly possible. Note that in the image below, the last <table></table> are just to show that highlighting doesn't occur there.
Edit:
Forgot to include this in the original post, but here is my updated tmLangauage file. That first pattern is what I added(link). I used PlistJsonConverter to go from JSON to plist, then saved the file as .tmLanguage. Hope this helps.
#skuroda is right, I implemented #skuroda's code with an additional plugin to easily edit HTML within an AngularJS directive JS file. The result is HTML syntax highlighting within a directive JS file and additional functionality to remove string related delimiters while editing templates.... Sublime AngularJS HTML Template Plugin
I'm trying to play around with a backbone app that was made with an older version of underscore (1.2.0) inside a newer rails app that has a more recent version of underscore loaded (the underscore that comes with the current version of backbone-on-rails gem), so this is a backwards compatibility issue, which I can't figure out even with the help of the changelog http://underscorejs.org/#changelog, however, it's happening when I'm trying to save data.
Context:
A Company, created by the Companies collection, is trying to save (with the setBucket function) the id of the Bucket it is contained in (see code below).
This is the error I get when I try to save data.
Error
<error>
_.extend
_.clone
_.extend.toJSON
_.extend.save
_.extend.update
Backbone.sync
_.extend.sync
_.extend.save
window.Company.Backbone.Model.extend.setBucket
window.AppView.Backbone.View.extend.createCompanyOnEnter
jQuery.event.dispatch
elemData.handle.eventHandle
Source Code
...(code ommitted)...
var company = Companies.create({text: text}); #this works. company is created
company.setBucket(initialBucket.id); #this triggers the error
....(code ommitted)
setBucket: function(bucketId) {
this.save({bucket: bucketId}, {silent: true}); #the function that's not working
You can run two versions of Underscore simultaneously. Simply load your version of Underscore on the page first, then add this line:
var underscore = _.noConflict();
to alias your version of Underscore to the underscore variable (you can of course use a different alias if you prefer). Then run a find/replace on all of your existing Underscore-using code to replace "_" with "underscore" (or your alias).
Finally, load your Rails app and it version of Underscore to the page. It will get the _ alias, and your code can use its version without impacting your library's version.
* EDIT *
Ok, here's a little more background. In Javascript (just as in Ruby I believe) functions are first-class objects. This means that _ isn't technically the Underscore function itself, it's just a variable that points to the "true" Underscore function (which is itself an object). This also means that you can make aliases to functions the same way you do with any other variable. Just as you can do: var a = 5; var b = a you can also do var b = _; and then you could do b.map() or whatever. Well, almost; because Underscore keeps an internal reference to Underscore, you need to update it, which is where noConflict comes in; that code really should have been: var b = _.noConflict();
By the way, it also means you can go the other direction and change _, if you want: _ = alert; _('hello world').
So, what's currently happening with you is that you bring in Underscore on to your page. Presumably you're doing this by putting an <script src='underscore.js'></script> in your main html.erb file. This brings in Underscore version #1. Then you load your Rails app; I'm not sure exactly how this is working, as it depends on your app, but somehow that app is putting another script tag on the page, pointing to Underscore version #2.
This is a problem, because Underscore version #2 just replaced your version #1 (the same way I replaced _ with alert just now). This breaks your code. You could fix it by just adding your <script> tag after the one from your Rails app. This would restore version #1 and fix your code ... but break your app's code.
What you really want is for your code to use version #1 and your app's code to use version #2. Which is where my original answer comes in: by re-aliasing version #1 of _ to underscore (or anything else), your Rails app can keep referencing version #2 as _, and your code can keep using version #1 as underscore.
It sounds like a dumb question and FAQ as well, but I truly don't see any reason not to be able to run it.
I try to run a imagerotator with SWFObject and that's the error I get. I do include properly the swfobject.js file (accessible via the direct url) and I pass the parameters through an XML file which loads independently fine as well. I do use version 2.2.
Here there is my SWF call:
<div id="slide1">Get the Flash Player to see this rotator.</div>
<div id="rotator"></div>
<script type="text/javascript">
var s1 = new SWFObject("/admin/cms/imagerotator.swf","rotator","606","199","5");
s1.addVariable("file","imagerotator.php");
s1.addParam("allowfullscreen","false");
s1.addVariable("linkfromdisplay", "false");
s1.addVariable("transition","lines");//bgfade,blocks,bubbles,circles,fade,flash,fluids,lines,random,slowfade
s1.addVariable("rotatetime","5");
s1.addVariable("overstretch","false");
s1.addVariable("backcolor","0xFFFFFF");// change if its helps to fit better in design (optional)
s1.addVariable("shuffle","false");
s1.addParam("wmode", "transparent");
s1.addVariable("showicons","false");
s1.addVariable("shownavigation","false");
s1.write("slide1");
</script>
I doubt that this usage of the SWFobject is completely inappropriate for this version, although I use a sample code of a CMS including this exact version of the library.
The implementation changed:
1) Your problem is described (and solved) here.
2) Check the original docs here.
Basically you need to use swfobject.embedSWF(...) now instead of var x = new swfobject(...)
In any case, Google is your friend on this one ;)