I'm using bottle with beaker as session middleware. I'd like to include my session object in all my mako templates without specifying it when rendering:
Instead of this:
return mako_template("myView", {
"session" : bottle.request.environ.get('beaker.session')
})
just do this:
return mako_template("myView")
Is this possible? If so, how?
I don't know about Mako templates, but for Bottle SimpleTemplates you can use BaseTemplate.default:
bottle.BaseTemplate.defaults['session'] = bottle.request.environ.get('beaker.session')
However, since you are setting that at application instantiation time, bottle.request may not be valid. So you may need to turn it into something that does lazy evaluation when the value is requested.
Perhaps BaseTemplate.defaults gets fed into the Mako templates, or maybe Mako provides a similar mechanism for setting the defaults?
I hope this helps point you in the right direction.
Related
just out of curiosity:
As you all might or might know, it is possible to set a custom BE logo with $GLOBALS['TBE_STYLES']['logo'] = '../fileadmin/mylogo.png'; in typo3conf/extTables.php.
This behavior is working since old v4.x times.
But I just read that extTables will be deprecated in v8.x.
I tried to find a simple solution to this (one that keeps that one-line simplicity and does NOT require me to create&install an extension!)
I moved this line to typo3conf/AdditionalConfiguration.php,
but it does not work from there.
Why?
What would be necessary to make this line work within typo3conf/AdditionalConfiguration.php ?
In TYPO3 8.x you'll be able to change a backend logo via EXT:backend, so you should stick to that approach. Read more in release notes.
UPDATE.
To answer your question, why TBE_STYLES defined in AdditionalConfiguration are ignored: take a look at unsetReservedGlobalVariables() method from \TYPO3\CMS\Core\Core\Bootstrap class. It is executed after all the configuration is initialized (Local and Additional are merged and populated) and explicitly calls unset($GLOBALS['TBE_STYLES']);.
I am opening Word from a web page in IE using Javascript as follows:
var objword = new ActiveXObject("Word.Application");
This works very well for me. However, I'd like to pass in some additional arguments, or set something on the objword object which is returned, which I can then access from my Word Add-in ThisAddIn_Startup method.
I see on the objword object I have full access to the object model of the Word Application, although I can't find a good place to put a string simple property.
I've considered adding a dummy style or task pane or something which would carry the information I want, and which I could remove once I'd extracted the data from it. But this seems like a bit of a hack.
I'm looking for something like the 'Tag' property which seems to crop up all over the place when working on objects in the Office Object Model world. There's no 'Tag' property available on the Word.Application object, unfortunately.
One solution to your problem is to expose a method from your addin that you are going to call from JavaScript. A sample how this can be achieved can be found in a blog post by Andrew Whitechapel:
Passing Objects to Exposed Add-in Methods
Change Application.Caption? (Hack!)
Is there any way to have a user defined parameter in a file and then have the dist.ini set the value for the parameter. For example, a file might contain {{$THE_ANSWER}} and the dist.ini file would provide a value like THE_ANSWER = 42? I'm pretty new to using dist::zilla to work with perl distributions, and I'm having problems understanding how it treats files as templates. There seem to be only a couple of hard-codeed parameters, varying by plugin, that can be used for any file. One such parameter is the {{$NEXT}} variable made available by [NextRelease] in the Changes file.
I read through the tutorials and searched the modules on CPAN and can't figure out if this is even possible. It is not an acceptable work-around to use the [GenerateFile] plugin to put the whole file in the dist.ini file. Besides a lack of flexibility and just plain ugliness, it doesn't seem possible to add lines with leading white-space that way.
What I would do is use a stash or plugin to store the variables. Stashes are like plugins, but they don't do anything but store data, and they can be put into your global configuration as well as your dist.ini.
[%Vars]
favorite_pie = pumpkin
Then you can get at them like this:
$zilla->stash_named('%Vars')->favorite_pie
This assumes that you've made Dist::Zilla::Stash::Vars and given it a favorite_pie attribute.
You could make a totally generic stash, though, which accepts anything as a key. For that, I'd look at the source of Dist::Zilla::Plugin::Prereqs, which allows arbitrary configuration options and shoves them into a hash attribute in its BUILDSARGS method.
You could make that Dist::Zilla::Stash::Generic, and then register it as many times as you want for different reasons:
[%Generic / Pies]
favorite = pumpkin
hated = rhubarb
firstever = quince
[%Generic / Passwords]
pause = PeasAreDelicious
google = secret
reddit = SecretPeasAreDelicious
...then, as needed, say in templates...
{{ $zilla->stash_named('Passwords')->get_var('pause' }}
If I was making a lot of files that used this sort of generic thing, I'd pass their Text::Template instance a closure called get_password like this:
get_password => sub { $zilla->stash_named('Passwords')->get_var($_[0]) }
Then your template could include:
Login with: {{ get_password("pause") }}
This answer obviously leaves some source digging for you, but I think it should point at all the pieces I'd use to do what you want.
Working with Rails 3.1 (rc5), and I'm noticing that any coffeescript file I include rails (or sprockets) is adding in initializing javascript at the top and bottom. In other words, a blank .js.coffee file gets outputted looking like this:
(function() {
}).call(this);
This is irritating because it screws up my javascript scope (unless I really don't know what I'm doing). I generally separate all of my javascript classes into separate files and I believe that having that function code wrapping my classes just puts them out of scope from one another. Or, atleast, I can't seem to access them as I am continually getting undefined errors.
Is there a way to override this? It seems like this file in sprockets has to do with adding this code:
https://github.com/sstephenson/sprockets/blob/master/lib/sprockets/jst_processor.rb
I understand that wrapping everything in a function might seem like an added convenience as then nothing is ran until DOM is loaded, but as far as I can tell it just messes up my scope.
Are you intending to put your objects into the global scope? I think CoffeeScript usually wraps code in anonymous functions so that it doesn't accidentally leak variables into the global scope. If there's not a way to turn it off, your best bet would probably be to specifically add anything you want to be in the global scope to the window object:
window.myGlobal = myGlobal;
It seems to be a javascript best practice these days to put code inside a function scope and be explicit about adding objects to the global scope, and it's something I usually see CoffeeScript do automatically.
You don't want to put everything into the global scope. You want a module or module like system where you can namespace things so you don't colide with other libraries. Have a read of
https://github.com/jashkenas/coffee-script/wiki/Easy-modules-with-coffeescript
I'm writing a series of related mod_perl handlers for various login-related functions in Apache, so my Apache config file looks like this (for example)
PerlAccessHandler MyApache::MyAccess
PerlAuthenHandler MyApache::MyAuthen
PerlAuthzHandler MyApache::MyAuthz
Each of the modules (MyAccess, MyAuthen, MyAuthz) defines a
sub handler() {}
Which mod_perl calls at the relevant point in the processing of the request.
What I'd like to know is whether there is a way of doing this with one Perl module rather than three (it's just tidier and less work for users to install one module instead of 3)?
Is there some way to define the name of the handler method, perhaps. Or is there a way of detecting from within the handler() code which sort of handling I'm supposed to be doing?
It appears from the mod_perl 2.0 docs that you can use the "method" syntax to do what you're wanting (I've not tested this):
PerlAccessHandler MyApache::MyLoginModule->access_handler
PerlAuthenHandler MyApache::MyLoginModule->authen_handler
PerlAuthzHandler MyApache::MyLoginModule->authz_handler
I believe this will cause mod_perl to call each of the named methods in a static way on your MyApache::MyLoginModule class.
You can also create an object to be used when calling a handler method if you want to:
<Perl>
use MyApache::MyLoginModule;
$MyApache::MyLoginModule::access = MyApache::MyLoginModule->new(phase => 'access');
$MyApache::MyLoginModule::authen = MyApache::MyLoginModule->new(phase => 'authen');
$MyApache::MyLoginModule::authz = MyApache::MyLoginModule->new(phase => 'authz');
</Perl>
PerlAccessHandler $MyApache::MyLoginModule::access->handler
PerlAuthenHandler $MyApache::MyLoginModule::authen->handler
PerlAuthzHandler $MyApache::MyLoginModule::authz->handler
This approach would allow you to have a single handler method that could have different behavior based on the properties of the object set up upon object creation.
Disclaimer: It's been a while since I've worked with this part of mod_perl configuration so your results may vary!
Looks like one possibility might be using the push_handlers() call and setting up the handlers in code rather than in the apache conf file
See here: http://tinyurl.com/bwdeew