I want to use the rule new as shown in some of the documentation examples, but I get the error:
ERROR: rule "new" unknown in module "Jamfile<path/to/my/module>"
What module should I import to access this rule ?
You need to import the class module.
Because class is also a language keyword you need to use quotes:
import "class" ;
then you can use class.new in your code
Related
If I declare a class C in a given module, how can it be re-used in a different module?
For instance, a module declares and uses the following:
declare class IRecord<T: Object> {
constructor(irecordValues: $Shape<T>): void;
inspect(): string;
}
However, in a separate module I would like to do the equivalent to:
import type { IRecord } from 'other-module';
declare class IRecordState<T: Object, J: Object> extends IRecord<{
}
Unfortunately, it is illegal to export the class declaration above and I cannot create an actual (IRecord) class because it exists as an untyped entity. Is the only way to go to create a .flow.js module?
I solved this by moving the class type declaration into a separate .js.flow module and placing this in a directory specifically for flow type-related declarations. Also had to tweak flow's configuration file so as to instruct it to include these extra declarations. Configuring flow was straightforward and required creating a .flowconfig file in the project's root with the following setting:
[include]
flow-typed
... where flow-typed is the directory containing flow type declarations.
Now the class declaration is available throughout the project which makes reusing it possible, however the global presence of this declaration (and others that may be added) is undesirable.
Is it possible to export and import Flow type definitions in CommonJS world similarly to ES6 like type imports/exports?
There is no CommonJS-style require for Flow, but Flow's import type/export type syntax can be used alongside CommonJS require calls.
Though the syntax looks similar, import type and export type are not actual JavaScript import/export statements. They must be stripped from your code before your code can be run in current browsers. If you use Babel to compile your code, for example, you use the transform-flow-strip-types plugin to strip Flow types and type imports/exports.
I have few module namespace xquery files which were used in multiple files. I want to have the namespaces in one common xquery file and import that file whereever I want to use.
Say for example,
I have process-lib.xqy, util-lib.xqy and query-lib.xqy.
I used to import these in multiple files like following,
import module namespace util = "util" at "util-lib.xqy";
import module namespace process = "process" at "process-lib.xqy";
import module namespace query = "query" at "query-lib.xqy";
Now I tried to use them in one common file named as common-import.xqy and import this file in multiple files.
when I tried this approach,
import module namespace common-import= "common-import" at "common-import.xqy";
It throws exception as prefix util has no namespace binding.
How to achieve this?
This is not possible, at least not in the way you want to do it and rightfully so. The XQuery spec doesn't allow this:
Module imports are not transitive—that is, importing a module provides access only to function and variable declarations contained directly in the imported module. For example, if module A imports module B, and module B imports module C, module A does not have access to the functions and variables declared in module C.
This is a deliberate design decision. If you want to have access in this way you could write a wrapper function for each function you want to access, e.g. in your common-import.xqy file you could have:
declare function common-import:test() {
util:test()
};
But of course this can require a tremendous amount of wrapper functions. I would recommend you stick simply to inserting all required libraries. I see no benefit in doing otherwise.
The .is_folderish attribute is used in many places. For example when setting an object as the default view or when activating discussions on an object.
My first question is how to check is an object has that attribute set. I tried using the bin/instance debug with something like this:
>>> app.site.news.is_folderish
...
AttributeError: is_folderish
I imagine that I can't reach attributes on that way because app.site.news is a wrapper to the object that has that attribute.
My second question is how to add that attribute to a new Dexterity object. I suppose I can do it using the code below (but I can't test it before the my first question is resolved).
from zope import schema
from plone.dexterity.content import Item
class IHorse(form.Schema):
...
class Horse(Item):
def __init__(self):
super(Horse, self).__init__(id)
is_folderish = False
But I'm not sure about how both classes could be linked.
You don't need to add is_folderish to your types; it is an index in the catalog, and Dexterity types already have the proper attribute for that index, isPrincipiaFolderish.
If you do need to add attributes to content types, you can either use an event subscriber or create a custom subclass of plone.dexterity.content.Item:
subscribers can listen for the IObjectCreatedEvent event:
from zope.app.container.interfaces import IObjectAddedEvent
#grok.subscribe(IYourDexterityType, IObjectCreatedEvent)
def add_foo_attribute(obj, event):
obj.foo = 'baz'
custom content classes need to be registered in your type XML:
from plone.dexterity.content import Item
class MyItem(Item):
"""A custom content class"""
...
then in your Dexterity FTI XML file, add a klass property:
<property name="klass">my.package.myitem.MyItem</property>
I am trying to add an external library (PHP Simple DOM Parser, http://simplehtmldom.sourceforge.net/index.htm) to a Symfony2 project. I took a tutorial that explains how to include third party libraries to Symfony2 http://www.kiwwito.com/article/add-third-party-libraries-to-symfony-2.
I set up a class file like:
# vendor/phpsimpledom/lib/Phpsimpledom/simple_html_dom.php
require_once __DIR__.'/src/simple_html_dom.php';
class Phpsimpledom_Phpsimpledom extends simple_html_dom_node {
}
and registered my class in my Autoloader (autoload.php):
$loader->registerNamespaces(array(
...
'Phpsimpledom' => __DIR__.'/../vendor/phpsimpledom/lib/',
...
),));
I am trying to call:
$phpsimpledom = new \Phpsimpledom();
but this throughs me an error (Fatal error: Class 'simple_html_dom_node' not found).
However: The main file of the library (simple_html_dom.php) consists of functions that do not belong to a class.
When I try to use the file directly, it also doesn't work:
$loader->registerNamespaces(array(
...
'Phpsimpledom' => __DIR__.'/../vendor/phpsimpledom/lib/Phpsimpledom/src/simple_html_dom.php',
...
),));
Any hints?
THANKS!
You're trying to register a namespace but your class has no namespace. Try adding a namespace to it or use RegisterPrefixes().
BTW: did you know that one of the Symfony components is basically doing the same thing as php simpledom? It's called DomCrawler and it has a support for both xpath and CSS selectors.
I'm new to Symfony2 but as i can see, you are not respecting the PSR for autoloader.
I'm presumable thinking you should do:
# /vendor/phpsimpledom/lib/Phpsimpledom/Phpsimpledom.php
require_once __DIR__.'/src/simple_html_dom.php';
class Phpsimpledom_Phpsimpledom extends simple_html_dom_node {
}
Note that the correct filename would be /vendor/phpsimpledom/lib/Phpsimpledom/Phpsimpledom.php as the call must include the namespace to work.
Hope it works now.