Change phpbb3.1 style to twig syntax - twig

Recording to this, version 3.1 of phpBB should parse their old syntax to twig style now. I would like to use the parsed twig files to create a new style. I guess they can be found in the cache folder, but thats not very comfortable to reuse.
So Iam looking for the method that parses the old style to the knew one and to use it on the original files. I couldn't find it yet by just crawling through the sourcecode.

I found it myself. Its in the phpBB3/phpbb/template/twig/lexer.php file.
To use the class standalone, just remove
extends \Twig_Lexer
and replace
return parent::tokenize($code, $filename);
by
return $code;
Then you can run
$lexer = new lexer();
echo $lexer->tokenize($originalTemplateCode);
//returns template-code in twig-style syntax
Of course, thats a dirty hacked solution, but as long you only need it once to change the basic style for using it, its ok to do so

Related

Having problems decompiling class files

I have been working on a game for a while now and i tried to make this game as easy to understand as possible and easy to change as well by using one variable in a few places and not write the variables value in each place so that if i decide to change the value i wont have to change it every where, i will just have to change the value of the variable.
Two days ago i formatted my computer and saved in my external Hard Drive a .Jar file of the
game and the Eclipse(Coding environment) folder in where i THOUGHT the game source should be located at but it wasn't thus losing my source code.
I was very upset but then I remembered that you can decompile a jar file.
I searched for a decompiler and found the jd gui decompiler opened my jar file and i was happy
to see that its actually works but then... I noticed that the code is alliiiiitle bit different.
The compiler added tons of this. all the classes which doesn't matter to me.
Then i noticed that every where there was a double type number it added a .0 and a D
at the end of the number and even is some places where i had for example 0.7 i saw that there is 0.699999996 which again doesn't really matter, not a big deal.
But then i noticed that in all the places where i had a final variable it changed it to its value (Example : supposed to be : numRowsToDraw = Panel.WIDTH / tileHeight + 2;
what it is now : numRowsToDraw = 768 / tileHeight + 2;)
which ruined all the easy to change aspect of the program and i didn't want to change
the numbers back to the variable in all the places there should be a variable because it will take a lot of work.
So my question is : Is there a decompiler which doesn't change your code?
If there is can you tell me the name of it?
THANKS!
Oh and i forgot to mention that i tried afterwards the JAD decompiler which did the same thing...
No, there is not. Decompilation can never get back source level constructs like comments or the particular formatting of literals. But I'm sure there are automated source formatting tools out there that let you do stuff like remove Ds on double literals.

How do you delete or rename content parts in Orchard?

I gave a content part a wrong name and I want to rename it. I tried renaming the classes and all calls of it in the solution to no avail. I even tried deleting entries from the ShellFeatures table and the table generated by Migrations itself, but that just made things worse. Now the whole module's features aren't being recognized. Anyone tried this before?
I know this is an old question but I just had to tackle this and this is the first result I landed on from Google.
You can delete the ContentPart and add it again using migrations for example:
public int UpdateFrom3() {
// remove the AccreditationsPart part cleanly
ContentDefinitionManager.DeletePartDefinition(typeof (AccreditationsPart).Name);
enter code here
// re-add the AccreditationsPart again
ContentDefinitionManager.AlterPartDefinition(typeof (AccreditationsPart).Name,
cfg = > cfg
.Attachable()
.WithDescription("Adds a row of configurable accreditations to the content type"));
return 4;
}
You would need to customise the update numbers to fit your current migrations.cs and also change the AlterPartDefinition to match whatever you want it to be.
WARNING: This is only intended for fixing problems that you catch straight away. When you delete the part in the first section of the migration you will lose any associated data. If you already have the code running in production then you will have to use a different approach.

How to use jcurses from groovy

I just tried to use JCurses from within Groovy, but I always get the following exception:
Caused by: java.lang.NullPointerException at
jcurses.system.Toolkit.getLibraryPath(Toolkit.java:97) at
jcurses.system.Toolkit.<clinit>(Toolkit.java:37)
Toolkit.java:37 :
String url = ClassLoader.getSystemClassLoader()\
.getResource("jcurses/system/Toolkit.class").toString();
Google told me that it could have to do with spaces within the classpath (windows), but moving the library and even using the classes instead of the .jar file was not successful.
It seems to be possible - pleac for groovy references JCurses: http://pleac.sourceforge.net/pleac_groovy/userinterfaces.html
Another way to clear the screen from within a Groovy shell script would also solve my problem. :-)
As jline is bundled with Groovy, can't you use the class jline.ANSIBuffer.ANSICodes (as is shows in the page you linked to)
print jline.ANSIBuffer.ANSICodes.clrscr()
You might also need to do:
print jline.ANSIBuffer.ANSICodes.gotoxy( 1, 1 )
If you want the cursor to go back to the top of the screen
To draw coloured text, you can do:
println new jline.ANSIBuffer().append( 'Some ' )
.red( 'Red' )
.append( ' text' )
.toString()
The root problem is most likely that jcurses.jar was not being found on your classpath, causing ClassLoader.getSystemClassLoader().getResource("jcurses/system/Toolkit.class") to return null.
There's a related problem you can run into if it can't find the C library containing the native code (libjcurses.so or libjcurses64.so on linux). It expects the C libary to be in the same folder where it found jcurses.jar. If it's not there, you'll get:
java.lang.RuntimeException: couldn't find jcurses library
found another trivial way to clear the screen :-)
print "\n"*80

Getting echofunc.vim to work

I came across echofunc.vim today (from a link in SO). Since I'm rubbish at remembering the order of function parameters, it looked like a very useful tool for me.
But the documentation is a bit lean on installation! And I've not been able to find any supplementary resources on the internet.
I'm trying to get it running on a RHEL box. I've copied the script into ~/.vim/plugin/echofunc.vim however no prompt when I type in a function name followed by '('. I've tried adding
let g:EchoFuncLangsUsed = ["php","java","cpp"]
to my .vimrc - still no prompting.
I'm guessing it needs to read from a dictionary somewhere - although there is a file in /usr/share/vim/vim70/ftplugin/php.vim, this is the RH default and does not include an explicit function list.
I'm not too bothered about getting hints on the functions/methods I've defined - just trying to get hints for the built-in functions. I can see there is a dictionary file available here which appears to provide the resources required for echofunc.vim, I can't see how I set this up.
TIA,
It expects a tags file, the last line of the description describes exactly how to generate it:
ctags -R --fields=+lS .
It works here with PHP but not with JS. Your mileage may vary.
I didn't know about this plugin, thanks for the info.
You should try phpcomplete.vim, it shows a prototype of the current function in a scratchpad. It is PHP only, though.

How to copy a folder, with exclusions, with native groovy?

This is easy enough to implement (will do it now unless someone answers real quick), but I'd always rather reuse than implement.
How can one recursively copy a folder in groovy, while excluding some folders/paths? I know this can be done with ant, but I think a simple native groovy code is nice to have as well.
Posting the code to use AntBuilder (Linked to from my comment above) in case the page disappears at a later date:
new AntBuilder().copy(todir: "dstFolder") {
fileset(dir : "srcFolder") {
include(name:"**/*.java")
exclude(name:"**/*Test.java")
}
}
Not sure if you meant that for some reaon you wanted to avoid using Ant completely however...

Resources