T4MVC using with external javascript files - t4mvc

Is it possible to use T4MVC in an external js file?
I include a js file in my cshtml file
and in MyScript.js i have the following in a function
#Url.Action(MVC.MyController.MyAction())
but it never get compiled to its Action name (thought that runat server would do that trick but it didn't)
what am i missing? I am also using chirpy if there is something that it can do to help...
thanks

T4MvcJs will help you handle that case.
It generates a .js file which you can use in your external js-scripts.
Using it is a lot like T4Mvc: MvcActions.User.Index() will give you "/user/index".

This is more of a general MVC question than T4MVC. T4MVC simplifies how you call #Url.Action, but whether you use T4MVC or not, you won't be able to have server code in a plain .js file.
However, there are some solutions around, like Using Inline C# inside Javascript File in MVC Framework

Related

Tutorial: How to use Zend i18n

I would like to use Zend Translation to translate my app into various languages. The problem I face is finding a tutorial that explains how to set it up clearly and without any ambiguity.
This is what I currently have:
In the language file I have:
And in my view I am calling:
<?php echo $this->translate('Skeleton Application') ?>
And I am expecting the output: "hello"
Instead the text: "Skeleton Application" is returned.
Now I assume I need to do some configuration to set this all up such as setting locale etc. However, I can not find any documentation on this or what to do and where...
In Application.Config.php the following modules are included:
Zend\I18n',
'Zend\Mvc\I18n',
Any help on this would be great!
You have everything setup right. Both modules are indeed required as one is the actual translator, and the other one is the integration in Zend MVC (view helpers and all).
In terms of what's not working, it is not ZF related, but rather po/mo related. The translation file you are editing is the .po file, the human readable format, which then needs to be compiled into a .mo file, a binary that is going to be used by your system.
In your specific case, you are missing the compilation to binary step, hence the value not changing (as the .mo file has not changed).
You can either use a command line tool for that compilation, or use a tool such as poeditor on you machine to edit your translation files.

Can't set breakpoint in PHPStorm

Everything works fine except template files. If there are some HTML in the code breakpoints just don't add.
How do I debug PHP code in template files?
I have PHPStorm 9.0 and Xdebug 2.2.3
Somewhere along the line of code execution, a template engine is called from your controller or framework. That would be where you would set a breakpoint; then use step into... to see how your template file is being handled by the template engine itself. This is a tedious process, but depending on the framework you're using, may be your only alternative.
Having said that, I would actually recommend separating concerns by executing all PHP code in your controllers or source files; and then passing those values on to the template as simple variables or code snippets for rendering. This follows a similar convention to "dependency injection" and will make your template files easier to compose and troubleshoot.

Documenting autogenerated code (NSManageObjects) with Doxygen

Im about to documentate a library I have that uses NSManageObjects using Doxygen. Since NSManageObjects are autogenerated from the data model, if I change something in the model, the file containing the modified managedobject is going to be generated again.
I donĀ“t want to rewrite documentation everytime a change is made in the model.
Do you know any way to accomplish this?
Thanks.
I found out how to achieve it. Doxygen allow you to document classes from other files. There is no need to do it in the .h.
Doxygen parses the .h file and he creates the documentation skeleton for that class. Then you can add documentation from any other custom file.
The problem is that you have to manually specify some labels in order to link the information from the .doc file with the class declared in the .h file.
Please see:
Doxygen documentation at other places
and this: Properties not being documented
Should be enough to get an idea of how I did managed to do it.

Configuring ScriptSharp to generate .js as embedded assembly resource in Visual Studio

I can't seem to understand how it works.
I see there is an option /assembly available to the Script# compiler which procuces a .dll file with the .js file as a resource. Here is an example from http://www.nikhilk.net/ScriptSharpIntro.aspx:
ssc /ref:sscorlib.dll /ref:Script.ScriptFX.Core.dll /debug /assembly:HelloWorld.dll /out:HelloWorld.js HelloWorld.cs
Can I get the same result using Script# Visual Studio templates? How do I enable this option for my Script# project?
There isn't a way to produce an assembly with script embedded in it.
I think the /assembly flag might be a remnant, or is there primarily for the script# compiler to know where the assembly produced from the same code as produced by the c# compiler exists.
If you want to embed the script in that assembly, you'll need to do a two pass c# build - in pass 1, there is a placeholder script, and then in pass 2, the real generated script.
Alternatively I can think of some approaches involving ildasm, add script resource reference, and then ilasm'ing to get back a new assembly.
What is your scenario? I am curious. I've debated whether to make the two pass build be supported out of the box... but never gotten around to it, since the embedding a script was a nice-to-have.

Visual Studio Language Service with C# intellisense

Last year I wrote a Language Service for Visual Studio which added syntax highlighting for NHaml files: http://github.com/snappycode/hamleditor.
To clarify, NHaml is a html template language that can mix in code elements like an aspx file can. This plugin adds support to the IDE for editing NHaml files, but basically only adds syntax highlighting.
I was wondering if anyone knows how to add inline c# intellisense to the service like you get now in an aspx file. I'm hoping that would be possible without doing the whole c# grammar myself specific for the plugin.
Has anyone written a language service that mixes languages?
UPDATE:
It looks like the spark view engine guys have made some inroads here, I am investigating their implementation
I checked the Spark View Engine, and they seem to have made a generic ATL stuff (called SparkLanguagePackageLib), that in fact seems to be not containiag anything Spark specific. It seems to be just a generic C# intellisense library that needs the following:
The original code
The C# source that gets generated from the original code
The position mappings between the two (for example the code on line 2 pos 5 gets mapped in the output to line 4 pos 10, etc.)
Some other things, like Paintings(?)
And after that you can call:
events.OnGenerated(
primaryText, // original source code
entry.SourceCode, // generated sourcecode
cMappings, // mappings between the two
ref mappings[0], // ?
cPaints, // ?
ref paints[0]); // ?
I've tried to find Spark-specific stuff in that C++ library, but I couldn't find anything: everythig spark-related is split to a separate C# code file. I think this is good, because:
You don't need to edit the C++ files
If the spark view engine's intellisense support is installed it can be used by other view engines too
You only need to create a class, that maps between the original nhaml file and it's generated C# counterpart.
Btw. Are you still working on this NHaml Intellisense library? If not I'll try to patch their implementation in hope it can be converted to NHaml easily.
this looks like it might help
http://www.codeproject.com/KB/recipes/VSLanguageService.aspx
I finally managed to modify the code to support NHaml. It wasn't that hard at all. Unfortunately the original NHaml library doesn't support everything that was needed, so I had to create a new parser for NHaml. It doesn't support all of the constructs, but it supports most of them (enough to make NHaml programming easier)
Download: http://github.com/sztupy/nhamlsense
Screencast: http://www.youtube.com/watch?v=8jTZ2zC9eYc
You can easily add keywords by creating or modifying a usertype.dat file. Check here for some directions on attaching to specific file extentions. That might get you at least part of the way, without redoing the complete c# syntax.
(In fact, I'm not sure what you mean exactly by 'syntax highlighting' in this context. I'm sure, for instance, you get brace-match highlighting for free in the editor).

Resources