Setting id dynamically in jade / id interpolation - node.js

I've tried all the permutations I can think of but alas with no success.
I am trying to set an id dynamically in a jade template.
#{page.name}(data-role= 'page', data-theme= 'c', data-url='#{"#"+page.name}')
I wondering if it's actually possible.
Anyone know how to do this?
If some one knows, please help me out - before all my hair falls out :(

For anyone looking for the answer to this:
Answered kindly by TJ the developer of express.
div(id=myPassedId),
div##{myPassedID}( isn't supported because it would be super ugly

The suggestions here did not work in my scenario...
The format that worked for me:
x-task-id!="<%= id %>"
Ugly, but functional.

Nowadays you can also use a template literal:
- const page = { name: 'foo' }
#{page.name}(data-role="page" data-theme="c" data-url=`#${page.name}`)
Output (using Pug 2.0.4):
<foo data-role="page" data-theme="c" data-url="#foo"></foo>

Related

Azure Bot Framework - Wrap card action and button text

I’m having an issue where buttons and actions in hero and adaptive cards won’t wrap text. I have searched the internet and everyone is mentioning a webchat.js and botchat.js files that can be adjusted to fix this. I can’t seem to find those in my code. Has the name changed? I know botchat was changed to webchat. Would anyone happen to know where to fix this in the Basic Bot NodeJS implementation SDK V4?
Assuming you are using webchat, you could use plain css. This worked for me:
.ac-pushButton > div {
white-space: normal !important;
}
I was able to find an answer in node_modules > wordwrap. There is a function that you can call in there to wrap any text you'd like. Thank you #Hessel for the help.
var wrap = require('wordwrap')(70);
return CardFactory.heroCard(
'',
answer,
CardFactory.images([]),
CardFactory.actions([
{
type: 'postBack',
title: wrap(YOUR_TEXT),
value: YOUR_VALUE
}
])
);

Calabash iOS - How to clear text in a webview

clear_text doesn't work for me when testing a webview. Does anyone know of a different method for webview/cordova apps? The locator I'm using is "webView css:'input#username'" but that seems to be fine as enter_text is working.
Any suggestions?
Thanks,
Lewis.
Thanks but set_text("webView css:'input#username'", "") didn't work. I ended up using the solution you mentioned here
Thanks.
set_text("webView css:'input#username'", "")
You might also try using the WebView JavaScript API
When I had a similar problem, I ended up using something like this :
Then /^I clear a field with "([^\"]*)" text$/ do |name|
name = set_value name
element = query("UITextFieldLabel text: '#{name}'")[0]
touch(element)
wait_for_keyboard
name.to_s.split('').each do |c|
keyboard_enter_char 'Delete'
end
end
Details are in here: Clear field with calabash-ios

My spanish text is not being decoded on my Ionic Hybrid App

I'm using code like {{user.city}} in one of my templates to pull data from my MySQL DB on my Ionic Hybrid App.
On my frontend, For a value like
Bogotá
I get
Bogot&aacute
I made sure to set my DB collation to utf8_unicode_ci.
I tried searching and it seems I need to decode the entities, but I haven't been able to do so.I tried using:
<div ng-bind-html={{user.city}}></div>
Please bare in mind I have several values like this, not only one.
I'm also using an Ionic App I got from a code market, and I'm not very ionic-savvy, so if you could provide detail I would be very grateful!
Thanks!
David
You must encode the locations in php.
Then in your controller:
$http.get("path").success(function(response) {
var res =response.results;
var locationtext =[];
for (key in res){
//in this case your locationsTEXT is the locations from the API
locationtext.push(JSON.parse(res[key].locationsTEXT));
}
$scope.city = locationtext;
}
In view:
<ion-list>
<ion-item ng-repeat="point in city track by $index">
<p>{{point}}</p>
</ion-item>
</ion-list>
Keep in mind that, above code is a general solution. You must adapt this code according to your variables and needs.
Hope this helps!

Pluralization in mongoose/angular

I have an issue with pluralization in Mongoose that Im sure is easy to fix but I cant figure it out myself.
So, I have a Model called "Eventinstance" and a controller called "eventinstances". Either mongoose or angular is doing something with the pluralization on this.
When I have link like this (via Angular in a view):
(<a href="" ng-click="remove(eventinstance)" >Remove</a>)
It does a DELETE to: http://localhost.com/eventinstances?eventinstancesId=5278fb0792b06cad0d000002 ---404 (Not Found)
When it should go to: http://localhost.com/eventinstances/5278fb0792b06cad0d000002
What do you think could be causing this?
Many thanks,
kseudo
This is wrong declaration of your resource in Angular.
Declare it:
$resource('http://localhost.com/eventinstances/:id', {id: '#eventinstancesId'});
not as
$resource('http://localhost.com/eventinstances/');
If you omit :id in your declaration, eventinstancesId is appended as parameter after ? in your URL.
More info: $resource

Mongoid pagination

I tried
#posts = Post.page(params[:page]).per_page(10)
and
#posts = Post.paginate(:page => 1, :per_page => 10)
but neither method works
undefined method `page' for Post:Class
undefined method `paginate' for Post:Class
How do you do pagination with mongoid?
You should use Kaminari https://github.com/amatsuda/kaminari
This works fine for me:
#posts = Post.paginate(:page => 1, :limit => 10).desc(:_id)
desc(:_id) is added so that latest posts could be listed first.
Still using will_paginate is also okay.
This thread has same issue: undefined method `paginate' for Array on Rails 3 with mongoid
The main point to fix the error is to add this line before the controller call paginate library:
require 'will_paginate/array'
It should be added to default config file if you use mongoid for the whole project.
Hope the explanation helpful.
Reference from origin gem source: https://github.com/mislav/will_paginate/wiki/Backwards-incompatibility at "WillPaginate::Collection" section.
P/S: this is just a work around if your query is not very large. If you want better performance, let's try mongoid-pagination gem, custom will_pagination gem or another pagination gem which supported Mongoid like kaminari.
A bit late, but for anyone else looking, I found 'will_paginate_mongoid'
https://github.com/lucasas/will_paginate_mongoid
Really straight forward and lets you simply do
collection.skip(20).limit(10)
Use the following gem.
Very helpful.
https://github.com/lucasas/will_paginate_mongoid
To update a bit the answers, now exists the Pagy gem, also much more performant (cpu/mem) than will_paginate and kaminari. This is a migration guide
silly thing, but it worked for me in sinatra after i added require 'mongoid-pagination'
to app.rb
Posting several years later, in case someone else faces the same challenge.
kaminari-mongoid was released in 2016, and is currently maintained.
https://github.com/kaminari/kaminari-mongoid
All the goodness of Kaminiari for Mongoid, including appropriate handling of Mongoid::Criteria results, which was possibly the cause of the OP's error.

Resources