template formatting - allow readable format - intellij-idea

I'm creating some apache velocity templates and formatting the code(intellij Idea) breaks the template, because the text parts of the template are automatically indented.
When there's only a single line of the output text, then the indent is not preserved in the output:
#macro(body)
#if(${someCondition})
Hello
#end
#end
The output is:
Hello
The problem with multiline text output is this:
#macro(body)
#if(${someCondition})
Hello
World
#end
#end
And the output:
Hello
World
Is there some way to strip the indent of the text part based on the sorrounding code? I'd like to avoid ugly formatted templates like this:
#macro(body)
#if(${someCondition})
Hello
World
#end
#end
The code which uses the template:
final VelocityEngine engine = new VelocityEngine();
engine.init();
final VelocityContext context = new VelocityContext();
//put variables into context
engine.evaluate(context, outputWriter, "LOG", inputString);
Maybe there's something I can put into VelolocityContext, but I wasn't able to find it.

Related

Code styling without modifying the binaries

On the WebStorm for example and I believe in any Intellij product.
You can easily refeactor the code and style it as you like from the setting 'Code Style'.
But, the styling and refactoring actually change the binaries of the file.
for example if you decide you want new line after { it will add \n in each place.
I want to know if it possible to only visually display those different to the coder.
If I'm coding like this:
var func = function()
{
// Blah
}
And another programmer on the team code like this:
var func = function() {
// Blah
}
and also if I code like this:
var text = "";
and the other like this:
var text = '';
The thing is that I don't really care how it would actually be like in the saved file. I only care how it would be displayed to the programmer.
It is possible to achieve this ?
Simple answer: No. That's because coding rules exist and besides things like changed binaries you have the problem of version control as well. which style of your code should be versioned? While VCS' are able to deal with different line endings, what you ask for isn't supported anywhere.

How can I call a command from an scriptable application using Scripting Bridge?

I'm developing an application which needs to work with the Apple version of MS-Word using Scripting Bridge . I need to call a command of MS-Word defined in its sdef file but I can't figure out how to do it.
The definition of the command in the sdef file
<command name="reset" code="sTXTmFBr" description="Removes paragraph formatting that differs from the underlying style. For example, if you manually right align a paragraph and the underlying style has a different alignment, the reset method changes the alignment to match the style formatting.">
<direct-parameter type="4046"/>
</command>
and its definition in the header file
#interface WordApplication : SBApplication
...
- (void) reset:(Word4046)x; // Removes paragraph formatting that differs from the underlying style. For example, if you manually right align a paragraph and the underlying style has a different alignment, the reset method changes the alignment to match the style formatting.
...
#end
The definition of the type of the direct-parameter in the sdef file:
<enumeration name="4046" code="4046">
<enumerator name="paragraph" code="cpar"/>
<enumerator name="paragraph format" code="w136"/>
</enumeration>
and its definition in the header file
enum Word4046 {
Word4046Paragraph = 'cpar',
Word4046ParagraphFormat = 'w136'
};
typedef enum Word4046 Word4046;
The definition of the class of the object I want to reset:
<class name="paragraph format" code="w136" description="Represents all the formatting for a paragraph." inherits="base object" plural="paragraph formats">
...
</class>
and its definition in the header file
// Represents all the formatting for a paragraph.
#interface WordParagraphFormat : WordBaseObject
...
#end
The only way my app compiles and doesn't crash is:
WordApplication *sbApplication; // SBObject which represents Word App
WordParagraphFormat *sbParagraph; // SBObject which represents a paragraph format
[sbApplication reset:Word4046ParagraphFormat]
but it obviously does nothing because I'm not specifying the object I want to reset but the type of that object.
How can I reset the sbParagraph object?
Thanks.

Create new paragraph with Docx4j

I'm having problem creating a Paragraph with docx4j. Well, actually not the paragraph itself, but it's contents. I'm putting together a new document from paragraphs (actually "blocks" made of paragraphs) and everything is working fine. I'm appending them to a list, and when all needed paragraphs are there, I assemble the document. Now, between these blocks, I need new paragraphs, with custom text added. I'm using this function to create the paragraph:
private P createParagraph(String content) {
P result = factory.createP();
R run = factory.createR();
Text text = factory.createText();
text.setValue(content);
run.getContent().add(text);
result.getContent().add(run);
System.out.println("HEADER : " + result.toString());
return result;
}
The print only prints "HEADER : ", the result.toString() is an empty string. Why is that?
BONUS question : I did not want to open a new thread for this. Is it possible, to add an id for a paragraph, which will appear in the generated html? (like p id="xyz" ...>
Thank you very much!
If you want to see the XML your P object will become, use:
System.out.println(
XmlUtils.marshaltoString(result, true, true) );
org.docx4j.wml.P is a class generated by JAXB's xjc.
There are a couple of plugins listed at https://java.net/projects/jaxb2-commons/pages/Home which we could have used to generate a toString method, but we didn't.
If you want the text content of the paragraph, you can use TextUtils

Path of current template file within Velocity

Suppose I have the following templates:
.../main.vm
.../sections/footer.vm
Suppose main.vm looks like this:
Hello world, this is the main template, it's name is $name
This template also has the following footer:
#parse("sections/footer.vm")
And suppose footer.vm looks like this:
Hi there, I'm the footer! My file name is $name!
I would like for $name in main.vm to be "main.vm", and $name in footer.vm to be "sections/footer.vm". Is something like this possible?
Not unless you override the behavior of #parse, or provide your own parsing macro or directive which does something like:
#macro(include $templateName)
#set($name = $templateName)
#parse($templateName)
#end

NSLocalizableString not found my key

I'm developing iPad international application.
I'm using methods NSLocalizableString to translate my application.
I have added keyword manually in my Localizable.strings in English and in French named "Orders" with value.
When I call my method NSLocalizableString with the keyword, it didn't found my keyword and don't apply the translation.
For keyword above and below, it's working perfectly.
Some code parts :
**Localizable.strings**
/* Change datas */
"ChangeDatas" = "Modifier les données";
/* Orders */
"Orders" = "Détails de votre commande";
/* Label */
"SomeLabel" = "Label";
**file.m**
//Work fine
NSLog(#"My data translation : %#", NSLocalizedString(#"ChangeDatas", #"Change datas"));
//Don't work
NSLog(#"My orders translation : %#", NSLocalizedString(#"Orders", #"Orders"));
Are you sure your editor was working in the right encoding? Also, with the correct line endings?
It can't hurt to check your .strings file with the plutil command.
Are you sure you've edited the .strings file for the same language/locale that you're using at runtime?