Get all available twig blocks names in runtime [closed] - symfony

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
Its posible get all available twig blocks names inside a block? how?

You can do it. There are two main parts in the workflow of any programming language or scripting language workflow, lexing and compiling. In the compiling part, the Twig builds the token tree and then compiles it into a HTML (Twig internals).
All of that is called inside Twig_Environment class, which is used as a service inside Symfony. So what you could do is override the Twig_Environment tokenize method and get all the tokens you need there. You can then override the original service with your own modified extension.
This is how you would be able to return all the token names. You can adapt this to suit your needs. You can also override render and/or parse methods if you need the token tree itself, or you can write your own more complex additional functionality which you could call from the template itself. The possibilities are endless. Just mind to keep your code separate from the original Twig implementation (use overrides) so that you can update more easily.

Related

Web API, where to put private methods? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
So I was wondering the other day, where to put private methods, that do some dirty work in Web API.
I need to extract certain things from JSON, methods will do the job and return some result.
So where do I keep those methods?
do I need to write a separate library (dll)?
or just do this stuff in the controller?
I don’t think it can have a single answer – it depends on…
If you think this private method can be reused from some other controller in future, better to have a separate class, if you think it can be reused from separate modules (not just from controllers), a separate class library project can be the answer.
But if you consider this private method is designed to support for a specific action of a controller, you can write within controller, before taking any decision a few more parameters to be considered like unit testability or slimness of API etc.
You should keep your controller thin as much as possible. You can move logic code to service package, for example JSONService class or JSONLib.
I often use following layout:
controller/
lib/
service/
model/

Golang Static vs dynamic binding for objects [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I have this application where requests are filtered based on the string in the struct and made to execute different functions.
My approach is to have a Map which maps the strings to the function pointers and execute them. However this approach is being contended by a teammate who wants to do this filtering by reflection. We are using Go and it is for monitoring the activity of our site.
Teammates approach: Use reflection to switch the object based on the string, pass the string to the function and let the function call the relevant function.
My approach: Simple map from string to functions
Any help is appreciated.
Downside of reflection based auto-discovery is that you forever have to be careful on what you add to the system because it can be automatically picked up.
vs map approach where you would need to explicitly expose each function.
Reflection is more cool and auto-magical, for sure. But auto-magical doesn't lend it self very well to security or long term maintainability.
Plus, a map[string]func(with specific signature) won't compile if you attempt register a non-matching function.
Where you will find stuff with reflection and then ponder why it's a runtime fail.

Can I write go library to be used from another languages? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm writing relatively small, but not simple networking library which is going to be used at least from C,java,python,ruby and C#. Is there a way to make go bindings to the other languages the way in can be done form C? If not is there other way?
Right now, you can't write libraries in Go that can be used in other languages. Go has a runtime environment that does a lot of things (like sheduling go-routines, collecting garbage) for you. This runtime environment is written under the assumption that it controls the whole program. This assumption does not hold if Go code would be used from inside another language, as the Go library cannot influence the binary that uses it.
I imagine that a JSON service would do what you describe.
Have a look at the json test for a simple example
It wouldnt matter what languages you used to set and get data from your app

handling of datetime objects by breeze [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
We use breeze with API controller.
I want display what dates we have in database to the end user without converting them into UTC.
Same in case if uses chooses any date in the UI it should be saved as it was selected.
I know that JSON.NET date serialization sucks. Also on DOM elements are bound to model properties and it is quite big job to convert date fields into string.
Can you please advise for a fix solution?
I did try implementing custom DateTimeConverterBase and hook it through GLOBAL.ASCX however for some reason my overwritten method does not invoke!
Any help would be appreciated.
Simplest way to do this might be to replace Breeze's breeze.DataType.parseDateFromServer method.
See the answer to this post for more information: breezejs-date-is-not-set-to-the-right-time

How to use flash.filesystem.FileStream [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Will
How to use flash.filesystem.FileStream ?
FileStream.as file Where?
The class flash.filesystem.FileStream is only available in Adobe AIR. It is not available in Flash Player in the browser. Furthermore, there is no FileStream.as available to read the source code because it is compiled into the runtime and probably written in a lower-level language like C++.
If you want to open a file in Flash Player in the browser, you should use flash.net.FileReference and call the browse() method to display a file dialog. Once the user selects a file, you'll receive Event.SELECT and you can call the load() method to get a ByteArray of data.
If you are targeting Adobe AIR, then the document Reading and writing files should provide you with all the information you need.
This is an AIR only class, so you have to be compiling to the AIR runtime to get it to work.

Resources