I'd like to see the source code of elm-lang/core that is in use in my project.
My project has:
import Json.Decode exposing (..)
Right now elm compiler says
Cannot find variable `Json.Decode.Decoder`.
`Json.Decode` does not expose `Decoder`.
From github source I can see that it's exposing Decoder. Would like to see if I have the wrong version of Elm or something.
Just in case - my elm-package.json has
"dependencies": {...
"elm-lang/core": "5.1.1 <= v < 6.0.0",
...
},
"elm-version": "0.18.0 <= v < 0.19.0"
Your example use in the comments shows that you are using Decoder like this:
on "load" (Decode.Decoder (toString model.gifUrl)
That is indeed a compiler error. While the Json.Decode package exposes a Decoder type, it does not expose a Decoder constructor. This is known as an opaque type, meaning you can't construct a Decoder value yourself, but only by using functions from the Json.Decode package. Opaque types can be exposed by having a module defined like this:
module Foo exposing (MyOpaqueType)
You can specify which constructors are exposed in one of the following ways:
-- only exposes Constructor1 and Constructor2
module Foo exposing (MyType(Constructor1, Constructor2))
-- exposes all constructors of MyType
module Foo exposing (MyType(..))
By your example code, I am inferring that you want some Msg to occur when an image is fully loaded. If that were the case, then you could use something like this:
type Msg
= ...
| ImageLoaded String
viewImage model =
img [ src model.gifUrl, on "load" (Json.Decode.succeed (ImageLoaded model.gifUrl)) ] []
Here is an example of how to handle both the image load and error events.
Related
I'm parsing HTML in a StreamField's richtext element via get_context, and want to be able to test that the context I've made contains the relevant modifications. But I'm really struggling to create a mock/stub that has a populated StreamField.
I'm looking at https://docs.wagtail.io/en/stable/advanced_topics/testing.html but need to do more than just test whether creation succeeds and the rich_text function etc. don't seem to output in the right format for other matters (like appending to the body attribute); I've had a little success with making fixtures via dumpdata but they're breaking other tests (presumably due to making the database inconsistent or something)
Are there any good examples out there of tests pre-populating a StreamField?
... turns out it's remarkably simple, once it's been pointed out to you!
Once you've got your page (where pagetype is the module name and PageName the class name)
from modules.pagetype.models import PageName
page = PageName()
add some JSON to the StreamField object (here called body)
import json
page.body = json.dumps(
[
{"type": "rich_text", "value": "<h2>Hello, World!</h2>"},
{"type": "rich_text", "value": "<h4>Here's another field</h4>"}
]
)
You may then want to then publish the post and look at the output.
from django.test import Client
page.save_revision().publish()
rv = Client().get(page.url)
assert "something_about_my_output_html" in str(rv.rendered_content)
I'm looking for some cleanup of my knowledge. Within a project with complex module structure I'd like to keep the structure clean by building up structured namespace tree. Say, something like:
App
Config
Key
Node
Param
Type
MyType
Every entry under App::Config shall be contained in its own file. Always typing things like App::Config::Key is a time waste. is export doesn't have a parameter to declare the name which is to be exported. So, I finally came to the following solution:
Config.pm6:
unit module App::Config:ver<0.0.1>;
...
Key.pm6:
unit package App::Config;
class Key is export {
...
}
And it works as I want it:
use App::Config::Key;
say Key.^name; # App::Config::Key
The only question remains: a there any caveats? Any hidden side effects to know about?
Far as I can tell, the only problem seems to be you will only be able to recursively declare modules that way. Only one, at the top level, will be possible. See this (simplified) example:
lib/Packr/U/Packd.rakumod:
unit package Packr::U;
our class Pack'd is export {}
lib/Packr/U.rakumod:
unit module Packr::U;
lib/Packr/Packd.rakumod:
unit package Packr;
our class Pack'd is export {}
our class B::Pack'd is export {}
lib/Packr.rakumod:
unit module Packr::U;
And then the main program:
use Packr;
use Packr::U;
for (Packr::Pack'd Packr::B::Pack'd Packr::U::Pack'd ) -> \P {
say P.new().raku;
}
This fails in the last iterated class:
Could not find symbol '&Pack'd' in 'Packr::U'
I am new to the django framework. I currently started learning from an online video tutorial and I came across some errors. I have an app called groups which has two separate view files namely company and family. Due to that I have my groups/url file as this:
from django.urls import path, include, re_path
from . views import company
from . views import family
app_name = 'groups'
company_patterns = [
path('create/', company.Create.as_view(), name='create'),
re_path(r'^edit/(?P<slug>\w+)/$', company.Update.as_view(), name='update'),
path('<str:slug>/', company.Details.as_view(), name='detail'),
]
family_patterns = [
path('create/', family.Create.as_view(), name='create'),
path('edit/<str:slug>/', family.Update.as_view(), name='update'),
path('<str:slug>/', family.Details.as_view(), name='detail'),
]
urlpatterns = [
path('companies/', include(company_patterns, namespace='companies')),
path('families/', include(family_patterns, namespace='families')),
]
But anytime I run the application from my dashboard template. I get this error:
'Specifying a namespace in include() without providing an app_name '
django.core.exceptions.ImproperlyConfigured: Specifying a namespace in include() without providing an app_name is not supported. Set the app_name attribute in the included module, or pass a 2-tuple containing the list of patterns and app_name instead.
Please, can anyone assist me with further explanation and solution? thank you
define app_name in another urls.py file
Is there a way with traits to get all imported modules or some other way? As far as I can see "allMembers" will not include members imported.
What I want to achieve is to import all members from within imported modules, but it doesn't seem to be as easy as I thought. I can easily get the members I want if I specify the full modules imported, but not if I take the current module itself.
So my question is, is there a way in D to get the names of all modules that are imported, because that way I can create a dynamic way of using "allMembers" on the modules.
To demonstrate what I mean.
Let's say we have module a.
module a;
import b;
import c;
...
foreach (member; __traits(allMembers, a)) {
// members of b and c will not come here ...
}
Even if the imports of b and c are public, then they won't come.
What I want to be able to do is retrieve them there anyway.
If you import into a structure, then allMembers should work work; example:
( https://dpaste.dzfl.pl/629ff05bdab0 )
struct Packages {
import std_meta = std.meta;
import std_range = std.range;
import std_range_interfaces = std.range.interfaces;
import std_range_primitives = std.range.primitives;
import std_traits = std.traits;
};
void main() {
foreach (X; __traits(allMembers, Packages)) {
pragma(msg, __traits(allMembers, __traits(getMember, Packages, X)));
};
};
… with some caveats which I don't recall exactly right now.
If you also want the modules to be imported 'normally' you could generate string-mixins from a list of module names. There's probably a number of ways you could approach this. (I won't go into details unless someone specifically asks about it)
I used this technique to great effect in my std-underscore hack, with some help from __traits(compiles and __traits(getProtection. So you might want to check that out if you plan on doing something similar.
It's actually not as flimsy as you'd expect. I use std-underscore in every project now.
I have created an ontology using protege. Now I want to write a code to traverse ontology using dotNetRDF. By mean of traverse is displaying all classes, sub-classes etc.
I am using following code but it is giving exception **
The Namespace URI for the given Prefix 'owl' is not known by the
in-scope NamespaceMapper
OntologyGraph g = new OntologyGraph();
FileLoader.Load(g, "humanontordf.owl");
OntologyClass classOfClasses = g.CreateOntologyClass(g.CreateUriNode("owl:Class"));
//This iterates over the things that are a class
foreach (OntologyResource r in classOfClasses.Instances)
{
//Do what you want with the class
Console.WriteLine(r.ToString());
}
This code is base on answer given here (http://answers.semanticweb.com/questions/19984/dotnetrdf-list-all-ontology-classes)
Can anyone let me know what am I missing in above code? any good URL for tutorial on dotNetRDF?
The error message refers to the following part of your code:
g.CreateUriNode("owl:Class")
This uses a prefixed name as a shortcut for the full URI which requires the owl prefix to be defined in your graph.
If you are getting this then your RDF file does not include this, you can define this like so:
g.NamespaceMap.AddNamespace("prefix", new Uri("http://some/namespace/"));
I guess an OntologyGraph should really define the OWL namespace automatically, I'll add this in the next release.