I've been trying out material design for the first time and am struggling to get mixins for the tab-indicator to work. I'm new to this framework and using sass so I'm sure I'm missing something.
App.scss looks like this:
#use "#material/theme" with (
$primary: #33302d,
$secondary: #d6c266,
$on-primary: #d6d6d6,
$on-secondary: #000000,
);
#use '#material/button/mdc-button';
#use '#material/button';
#use "#material/icon-button";
#use "#material/top-app-bar/mdc-top-app-bar";
#use "#material/tab-bar/mdc-tab-bar";
#use "#material/tab-scroller/mdc-tab-scroller";
#use "#material/tab-indicator/mdc-tab-indicator";
#use "#material/tab/mdc-tab";
#include icon-button.core-styles;
body {
color: red;
margin: 0 0 0 0;
};
.mdc-tab-indicator {
#include underline-color(orange);
};
And when I compile the file, I keep getting the error:
ERROR in ./app.scss
Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
SassError: Undefined mixin.
╷
25 │ #include underline-color(orange);
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
╵
app.scss 25:5 root stylesheet
I'm not sure how to trouble-shoot this, as all the documentation I've found and other solutions (e.g. What does "use this SASS mixin" mean in the context of Material Design Components?) indicate this should work.
What's missing?
There are a number of problems here:
#use adds namespace to imported members, see #use docs. So you should prefix mixin with the namespace.
It is not recommended practice to name your class the same way as existing MDC class - .mdc-tab-indicator. Create new name and add it to your tab indicator html element.
MDC packages have two ways of including them into your SASS-file:
// This will add all mdc-tab-indicator classes to your CSS
#use "#material/tab-indicator/mdc-tab-indicator";
// This will include mixins and variables, but will not add classes to CSS.
// It is useful if your SASS is broken down into multiple smaller SASS files
// and you don't want duplicate mdc-tab-indicator CSS each time you add #use.
#use "#material/tab-indicator";
My guess is that you need both, since you need base mdc-tab-indicator CSS classes. Plus you want to use mixins to create customized tab indicator.
So the final result looks like this:
#use "#material/tab-indicator";
#use "#material/tab-indicator/mdc-tab-indicator";
.my-tab-indicator {
#include tab-indicator.underline-color(orange);
};
Related
I have a generated dart file in my project that has some unused methods -- these unused methods are causing the Dart Analysis server in Android Studio to give a warning about each unused method.
The warning looks like this:
info: The declaration '<method name>' isn't referenced. (unused_element at [<app name>] lib/Models/<file name>.g.dart:<line number of method>)
How does one suppress these warnings just for the generated file?
From Step 5 here (the whole article is well worth reading)
Warnings in generated files do not matter to you.
Generated files are out of your control. You shouldn’t edit them, and probably shouldn’t care about how the generated code looks like either.
As such, instead of polluting your IDE with tons of pointless warning, simply disabling the linter on generated files is enough. This can be done by adding some code to your analysis_options.yaml.
In our case, we will use both json_serializable and Freezed, so the code what we want to add is:
analyzer:
exclude:
# ignore warnings in files from json_serializable, built_value and most generators
- "**/*.g.dart"
# ignore warnings in files generated by Freezed specifically.
- "**/*.freezed.dart"
As a workaround it can be ignored with
// ignore: unused_element
_func_dart_complains_about() {}
or
// ignore_for_file: unused_element
...
_func_dart_complains_about() {}
This is a general issue with nested functions. If you're declaring a local function within a parent function, return the same function using a return statement for the parent function.
Like in the below example, if I wouldn't return max(); inside the parent void MainMax() I'd get the error The declaration '<method name>' isn't referenced. Do check and return proper nested functions.
void mainMax(int a, int b, int c) {
void max(){
if(a>b && a>c){
print (a);
} else if (b>a && b>c){
print (b);
} else{
print (c);
}
}
max();
}
I'm not sure if this extreme edge case or something but I cannot seem to find straight forward documentation on how to do this (or I'm just really not understanding what is available):
I am developing an ionic application and as part of that I need to use the ALKMaps JavaScript library (which is similar to Google Maps API). To do so, I created a local npm module and within that I created a alkmaps.d.ts file as recommended by https://www.typescriptlang.org/docs/handbook/declaration-files/by-example.html#objects-with-properties). However, I cannot seem to figure out how to properly import it into my angular code. The same document suggests that using <reference path=''> tags is not good but that is the only thing that seems to satisfy the tsc compiler.
My declaration file, alkmaps.d.ts, looks like (inside excluded for brevity):
declare namespace ALKMaps {
export class Map { ... }
...
}
And I was trying to import it into a file like:
import { ALKMaps } from 'alkmaps'; // Error: File '.../alkmaps.d.ts' is not a module
I also tried the following but got the same error.
import ALKMaps = require('alkmaps');
Using the reference tag seems to work within this module but then the project that utilizes this module still throws the "is not a module" error (that might warrant a separate question)
From https://github.com/Microsoft/TypeScript/issues/11420 I found the idea of using export = ALKMaps or export as namespace ALKMaps but adding those to my declaration file resulted in different errors instead.
Can anyone please explain in a straightforward way how to use declaration files representing external JS libraries in a typescript node module?
This is how I was able to get alkMaps into my Angular 2 app
Insert the script into the index.html file.
Declare an ALKMaps variable in the component that you are adding the map
imports .....
declare let ALKMaps : any;
#Component({
selector: 'show-map',
templateUrl: 'show-map.component.html'
})
export class ShowMapComponent implements Oninit{
map : any;
constructor() {
}
ngOnInit() {
ALKMaps.APIKey = "apiKey";
this.map = new ALKMaps.Map("map", {displayProjection: new ALKMaps.Projection("EPSG:4326")});
}
}
This will get the map to display and you can put different layers on the map, however the map does not display correctly. #Mike, if you were able to get further than this, will you please comment?
EDIT: The tiles on the image were elongated and not connected. After inspecting the css the main.css, after building, set a global property on the img element to:
img {
max-width:100%
}
The tiles for the map are originally set to 256% for the width. To correct the element, I changed the property for img in the style sheet.
show-map {
img {
max-width: 256%
}
}
I am using https://github.com/openstack/puppet-keystone to set up an OpenStack management/controller node. I need to add the 'glance' user to keystone. I want to try and do as much as I can in my hiera data so my manifest will be simple.
Here is my manifest:
class kilo2_keystone {
include controller_ceph
include keystone
include keystone::config
include keystone::user
# keystone_user { 'glance':
# ensure => present,
# }
}
The commented out section works, but I want to be able to do include keystone::user and supply the parameters in my hiera data like so:
keystone::user:
"%{hiera('glance_admin_user')}":
ensure: present
But when I run puppet agent -t on my node I get this error:
Could not find class ::keystone::user
The commented-out code declares a resource of type keystone_user, not a class. Presumably its type, keystone_user, is provided by the puppet-keystone module. The include() family of functions are for declaring classes, not resources, so they are inapplicable to keystone_user.
There is more than one way you could proceed. If you don't anticipate wanting to anything more complicated than declaring one or more keystone_users present, then I'd recommend giving your class a parameter for the user name(s), to which you can assign a value via Hiera:
class kilo2_keystone($usernames = []) {
include controller_ceph
include keystone
include keystone::config
keystone_user { $usernames:
ensure => present,
}
}
On the other hand, if you want to be able to declare multiple users, each with its own set of attributes, then the create_resources() function is probably the path of least resistance. You still want to parameterize your class so that it gets the data from Hiera via automated data binding, but now you want the data to be structured differently, as described in the create_resources() docs: as a hash mapping resource titles (usernames, in your case) to inner hashes of resource parameters to corresponding values.
For example, your class might look like this:
class kilo2_keystone($userdata = {}) {
include controller_ceph
include keystone
include keystone::config
create_resources('keystone_user', $userdata)
}
The corresponding data for this class might look like this:
kilo2_keystone::userdata:
glance:
ensure: present
enabled: true
another_user:
ensure: absent
Note also that you are placing your kilo2_keystone class in the top scope. You really ought to put it in a module and assign it to that module's namespace. The latter would look like this:
class mymodule::kilo2_keystone($userdata = {}) {
# ...
}
I'd like a (platform independent) way to list all classes from a package.
A possible way would be get a list of all classes known by Haxe, then filtering through it.
I made a macro to help with just this. It's in the compiletime haxelib.
haxelib install compiletime
And then add it to your build (hxml file):
-lib compiletime
And then use it to import your classes:
// All classes in this package, including sub packages.
var testcases = CompileTime.getAllClasses("my.package");
// All classes in this package, not including sub packages.
var testcases = CompileTime.getAllClasses("my.package",false);
// All classes that extend (or implement) TestCase
var testcases = CompileTime.getAllClasses(TestCase);
// All classes in a package that extend TestCase
var testcases = CompileTime.getAllClasses("my.package",TestCase);
And then you can iterate over them:
for ( testClass in testcases ) {
var test = Type.createInstance( testClass, [] );
}
Please note, if you never have "import some.package.SomeClass" in your code, that class will never be included, because of dead code elimination. So if you want to make sure it gets included, even if you never explicitly call it in your code, you can do something like this:
CompileTime.importPackage( "mygame.levels" );
CompileTime.getAllClasses( "mygame.levels", GameLevel );
How it works
CompileTime.getAllClasses is a macro, and what it does is:
Waits until compilation is finished, and we know all of the types / classes in our app.
Go through each one, and see if it is in the specified package
See also if it extends (or implements) the specified class/interface
If it does, add the class name to some special metadata - #classLists(...) metadata on the CompileTimeClassList file, containing the names of all the matching classes.
At runtime, use the metadata, together with Type.resolveClass(...) to create a list of all matching types.
This is one way to store and retrieve the information: https://gist.github.com/back2dos/c9410ed3ed476ecc1007
Beyond that you could use haxe -xml to get the type information you want, then transform it as needed (use the parser from haxe.rtti to handle the data) and embed the JSON encoded result with -resource theinfo.json (accessed through haxe.Resource).
As a side note: there are chances you'll be better off not having any automation and just add the classes to an array manually. Imagine you have somepackage.ClassA, somepackage.ClassB, ... then you can do
import somepackage.*;
//...
static var CLASSES:Array<Class<Dynamic>> = [ClassA, ClassB, ...];
It gives you more flexibility as whatever you want to do, you can always add 3rd party classes, which may not necessarily be in the same package and you can also choose to not use a class without having to delete it.
I am facing an issue in declaring a fucation in block which I have added . I am calling a function by including an file which ia placed in the theme. I have also tried it by placing out of the theme folder. The function is alredy being user in front page. But when I am using the same function in that block. The screen gets blank and nothing displays. some part of my block coding is written below. Please help me.
<?php
global $base_url;
include($_SERVER['DOCUMENT_ROOT']."/travellar/geoiploc.php"); // indluded file
$ip = "203.189.25.0"; // Australia IP test
$country_code = getCountryFromIP($ip, "code");
I've had no problems loading functions from modules into custom blocks, but I've never tried loading one from a theme before. It's not clear to me whether or not theme functions are loaded before the page content is loaded.
You might have to create a custom module or include file to hold the function. Check out the module_load_include() function for how to load a specific include file.
A custom module would be a good approach as it is loaded before the theme layer and can be accessed from almost anywhere in Drupal except other modules with a lower weight than the custom module. It is also likely to come in handy for hooks and other overrides.
However, if you must have it in the theme layer, another option is adding it to template.php of your theme which should make it available within page.tpl.php and such, but not blocks I don't believe.
/sites/all/modules/mymodule/mymodule.info
name = My Module
package = !
description = It is MY module, not yours!
core = 6.x
The package "!" will make this module appear at the top of the modules page
/sites/all/modules/mymodule/mymodule.module
<?php
// Load mymodule.morePHP.inc
module_load_include('inc', 'mymodule', 'mymodule.morePHP');
// A custom function
function mymodule_my_custom_function($args) {
/* do custom stuff here */
return 'output';
}
/sites/all/modules/mymodule/mymodule.morePHP.inc
<?php
// An included custom function
function mymodule_other_custom_stuff() {
}