Where are Freemarker Functions set? - freemarker

I have not used Freemarker before and inherited some templates that won't compile. I have narrowed down the line that is causing problems to:
${text('Text and {0}', 'More Text')}
Where does this text() function come from? I understand that its trying to return the second string injected into the first like: "Text and More Text".
Here is the error:
FreeMarker template error:
For "...(...)" callee: Expected a method, but this has evaluated to an extended_hash (wrapper: f.t.SimpleHash):
modernizr-2.6.2.js is the only javascript imported.
Any ideas why this line is causing problems and where this function should be declared??

It can come from a few places:
From the data-model (one of the parameters you pass to Template.process)
From a shared variable, which is added to the Configuration singleton.
From an #include-d template (or from the template you are in), via #function text or #assign text = ... (or #global text = ...)
From an #import-ed template via #global text = ... (highly unlikely...)
But one potentially interesting thing is that the error says that text does exist, but it's a hash (a Map-like thing), not a callable thing. Maybe something that's also called text shadows the good text? What does ${.data_model.text('Text and {0}', 'More Text')} say?
You mention a JavaScript file. FreeMarker has nothing to do with JavaScript (and it runs on the server, inside the JVM).

Related

DialogFlow CX inline system functions not working in text fulfillment

I would like to generate dynamic text without the need to create webhooks whenever possible. I understand that the only way to create dynamic text is by either creating different routes depending on parameters or by using inline system functions like $sys.func.ADD(1, 2) within text fulfillments.
But inline system functions like $sys.func.ADD(1, 2) do not work for me if used in text fulfillments. System functions just don't get executed for me. I.e. instead of uttering "3" my bot just utters "$sys.func.ADD(1, 2)" as a result of a test fulfillemnt. What am I doing wrong here? Does anybody have an example for using inline system functions in text fulfillment?
Thanks!
To resolve this issue, you need to check the result of system functions in order to identify the error that occurred.
For the system function $sys.func.ADD, when using it as a text response in your fulfillment, you need to convert it to type STRING to be embedded in text since the output of this system function returns a type DOUBLE.
You can convert the output of the $sys.func.ADD function to STRING by creating a nested function in your text response and utilizing the $sys.func.TO_TEXT which converts a value of other types to string.
Here’s an example for reference:

Module variable documentation error

I get the following error while documenting a module variable json_class_index (See source), which does not have a docstring.
The generated documentation seems to be fine. What is a good fix?
reading sources... [100%] sanskrit_data_schema_common
/home/vvasuki/sanskrit_data/sanskrit_data/schema/common.py:docstring of sanskrit_data.schema.common.json_class_index:3: WARNING: Unexpected indentation.
/home/vvasuki/sanskrit_data/sanskrit_data/schema/common.py:docstring of sanskrit_data.schema.common.json_class_index:4: WARNING: Block quote ends without a blank line; unexpected unindent.
/home/vvasuki/sanskrit_data/sanskrit_data/schema/common.py:docstring of sanskrit_data.schema.common.json_class_index:7: WARNING: Unexpected indentation.
/home/vvasuki/sanskrit_data/sanskrit_data/schema/common.py:docstring of sanskrit_data.schema.common.json_class_index:8: WARNING: Inline strong start-string without end-string.
Edit:
PS: Note that removing the below docstring makes the error disappear, so it seems to be the thing to fix.
.. autodata:: json_class_index
:annotation: Maps jsonClass values to Python object names. Useful for (de)serialization. Updated using update_json_class_index() calls at the end of each module file (such as this one) whose classes may be serialized.
The warning messages indicate that the reStructuredText syntax of your docstrings is not valid and needs to be corrected.
Additionally your source code does not comply with PEP 8. Indentation should be 4 spaces, but your code uses 2, which might cause problems with Sphinx.
First make your code compliant with PEP 8 indentation.
Second, you must have two lines separating whatever precedes info field lists and the info field lists themselves.
Third, if the warnings persist, then look at the line numbers in the warnings—3, 4, 7, and 8—and the warnings themselves. It appears that the warnings correspond to this block of code:
#classmethod
def make_from_dict(cls, input_dict):
"""Defines *our* canonical way of constructing a JSON object from a dict.
All other deserialization methods should use this.
Note that this assumes that json_class_index is populated properly!
- ``from sanskrit_data.schema import *`` before using this should take care of it.
:param input_dict:
:return: A subclass of JsonObject
"""
Try this instead, post-PEP-8-ification, which should correct most of the warnings caused by faulty white space in your docstring:
#classmethod
def make_from_dict(cls, input_dict):
"""
Defines *our* canonical way of constructing a JSON object from a dict.
All other deserialization methods should use this.
Note that this assumes that json_class_index is populated properly!
- ``from sanskrit_data.schema import *`` before using this should take care of it.
:param input_dict:
:return: A subclass of JsonObject
"""
This style is acceptable according to PEP 257. The indentation is visually and vertically consistent, where the triple quotes vertically align with the left indentation. I think it's easier to read.
The fix was to add a docstring for the variable as follows:
#: Maps jsonClass values to Python object names. Useful for (de)serialization. Updated using update_json_class_index() calls at the end of each module file (such as this one) whose classes may be serialized.
json_class_index = {}

Sinatra dynamic template name

I just started checking out sinatra for a project, and I started playing around with HAML.
However, I've run in to an issue -- I have a path with a splat that needs to point to an HAML file with a name the same as the text splatted out of the url, however, any string passed to the [haml] template method is treated as an inline template, and not a filename.
There is no documentation that would suggest there is a way to do this. The only solution I can think of is reading to full text of the necessary template file and passing it to the HAML function; however, such a solution is incredibly cumbersome.
Example
get '/stpl/*.haml' do |page|
haml page # <--- `page' is treated as an inline template
end
Whilst this functionality is expected when one reads the documentation, there is no other means, it would seem, to accomplish what I need.
If you pass a symbol to haml, it will look in views for the matching file, so you can do this instead:
get '/stpl/*.haml' do |page|
haml page.to_sym # attempts to get views/<page>.haml
end

Xcode 3.2 Debug: Seeing whats in an array?

Whilst debugging in Xcode_3.1.2 I am pretty sure I could see the contents of my NSString arrays. However after upgrading to 3.2 I only see the following ...
I know I can print the object in (gdb) using "po planetArray" or simply click in the debugger and "print description to console" I am just curious, as I am sure it worked prior to upgrading. Anyone know anything about this?
cheers gary
edit: data formatters is on and it shows what you see above ...
This is because GDB acts as if the variable you are viewing is out of scope while it really just is confused about what each part function or method call of the data formatter is returning (the data formatter is the "{(unichar *)Xcode_CFStringSummary($VAR, $ID)}:s" part you are seeing.
When you are debugging and you are in a method where you know a local variable must be in scope right now, open the debugger window and the area where you can see "Variable", "Value" and "Summary" column titles double click the "Summary" row entry for the variable you are interested in and enter the following (for array types like NSArray or NSCFArray):
"{(int)[$VAR count]} objects {(NSString *)[(NSArray *)$VAR description]}:s"
then press return. You have now overwritten the default data formatter provided by Xcode's GDB extension (to be found in various plists at "/Developer/Library/Xcode/CustomDataViews/") with your own data formatter string.
Your own overrides are saved at "~/Library/Application Support/Developer/Shared/Xcode/CustomDataViews/CustomDataViews.plist" and if you want to have the Apple default data formatter back just double click the row for a variable of the same type and delete whatever is there.
The nitty-gritty details: In the custom expression above the "{}" construct tells GDB to execute a command (as if you where executing it from GDB's debugger command line, which means the same restrictions apply: you need to specify the return type in cast parens in front of every function or method which returns something). The ":s" behind the closing curly brace tells Xcode and GDB to reference the "Summary" column. Also valid would be ":v" which references the "Value" column which most of the time is just the pointer value. Everything that is outside of the curly braces is shown verbatim.
Unfortuntely curly braces can't be nested which invalidates ternary operator conditionals.
So with the above data formatter you should see the following for an empty NSArray:
"0 objects (\n)"
If you want to write your own data formatters as GDB extensions (equivalent to specifying a function akin to Xcode_CFStringSummary above) you can do so. Take a look at the following header: "/Developer/Applications/Xcode.app/Contents/PlugIns/GDBMIDebugging.xcplugin/Contents/Headers/DataFormatterPlugin.h"
it will tell you all you need to know. But it can be hard to get it right. It might be easier and less error prone to just define another method on your class and call that from the data formatter string instead of "description".
In the Run > Variables View menu in Xcode, is "Use Data Formatters" enabled?
I am not sure if this helps but if you select the array value to wish to see in the debugger window and the go to the Menu : Run > Variables View > View Variable As
you can change it from "NSCFString *" to "NSString *". You then see the value so "Planet_1" for example.
Cheers,
Kevin

Why can't I retrieve "contents" of a note item in Yojimbo, but I can retrieve the "content"?

A note item in Yojimbo's Applescript dictionary is defined as:
note item n [inh. database item] : A note item.
elements
contained by application.
properties
encrypted (boolean, r/o) : Is the note is encrypted?
contents (text) : The contents of the note. syn content
If this note is encrypted, the contents property is only readable
if permitted by the current security policies.
responds to
append, prepend.
In an attempt to export my data, I've been poking around with AppleScript, learning the language, etc, and currently have this:
tell application "Yojimbo"
repeat with EachNote in (note items in library)
display dialog (content of EachNote) as string
end repeat
end tell
What's confusing me is that, though the class defines the property "contents", I have to use "content" to retrieve the contents. Using "contents" results in this error:
Can’t make «class YNot» id "A0C9E19E-3106-44F9-97A6-A1A74AD77948"
of application "Yojimbo" into type string.
I'm assuming the "syn content" means it's a synonym, thus I should be able to use "content" and "contents" interchangeably. But apparently the synonym works, but the original does not...?
Also, more simply, why do the contents have to be coerced into a string? If I look at the properties on the object (via: (properties of EachNote) as string ), "contents" is a double-quoted string, though I realize this isn't necessarily "proof" that it's a string.
I'm still starting with AppleScript, so if I'm making a n00bish mistake, feel free to slap.
For others who find a similar confusion, I found help here: http://groups.google.com/group/yojimbo-talk/browse_thread/thread/d04f42db335c77e7
So all props go to Jim for being awesome!
The basics:
contents of an object is different than contents of a variable containing an object.
contents of a variable containing an object returns the object, not the object's contents, unlike every other property. Other properties return the property of the object in the variable, as expected.
This means, to get the contents of an object inside a variable, you need to use contents of contents of variable.
As demonstrated here, on my blog, yes, this is extremely strange. While var == var and var == contents of var, var != contents of (contents of var), so Applescript does indeed violate the identity principle for "contents" in this specific case. It does not chain this effect, though, so you shouldn't need to use contents of three layers deep (it'll work the same as two)
contents of contents of var works on objects as well, so it's always safe to use.
Many dictionaries use content as a synonym of contents, which avoids this whole problem. If desired, use content of var, and it'll work like other properties, always returning the object's content instead of the object.

Resources