I am using Backbone.js and RequireJs for a single page application.
When I run my karma tests, there is no css included. When debugging it is difficult to know what is going on or why something is not working because the html elements are not styled like they are in the production appplication.
Is is possible to inlcude css in the karma tests while debugging using webstorm?
I have already tried including all css in the files array
files: [
{pattern: 'app/css/*.css', included: false},
...
],
This is the css file that is included in index.html of the production application, there is nowhere in the karma configuration that I can find to add something like this.
<link rel="stylesheet" href="css/styles.css" />
I worked it out:
You need to add all your css to your karma.conf 'files' array.
files: [
{pattern: 'app/**/*.css', included: false},
...
],
Create a new module called test_css.js, the location of this file will depend on your folder structure. In here you need to programatically inject all your css files into your the current document.
define(function(require) {
"use strict";
require('jquery');
//Modify to suit your requirements
$('body').append('<link rel="stylesheet" href="/base/app/css/styles.css" />');
});
Include this module as part of the deps array in test-main.js
requirejs.config({
baseUrl: '/base/app/js',
paths: {
...
'test.css' : '../test_utils/test_css'
},
// ask Require.js to load these files (all our tests)
deps: ['test.css'].concat(tests),
// start test run, once Require.js is done
callback: window.__karma__.start
});
jax answer was very helpful.
Additionally, for those not using jQuery but d3.js, your test-css.js can look like this:
define([
'd3'
], function(d3) {
"use strict";
d3.select('body').append('link')
.attr('rel', 'stylesheet')
.attr('href', '/base/app/styles/mystyles.css');
});
I resolved a quite similar issue where my components were not appearing in Karma Test Runner by adding following to files key of karma.conf.js. I wanted Karma to automatically include the file so I set included to true.
.
.
.
files: [
{ pattern: 'node_modules/abc/abc.min.css', included:true, watched: false }
],
Upon doing this, I could then view my components in proper styling which made unit testing a lot faster and easier.
Related
I installed the TinyMCE editor on top of a fresh Connections 6.5.1 installation. While syntax highlighting using the codesample plugin is enabled out of the box, it works only for certain languages. I found the codesample_languages, which were overriden like described in this article.
externalPlugins: [{
name: "codesample",
url: "/connections/resources/web/tiny.editors.connections/tinymce/plugins/codesample/plugin.min.js",
settings: {
codesample_global_prismjs: true,
codesample_languages: [
{ text: 'ASP.NET (Core)', value: 'aspnet' },
{ text: 'Apache', value: 'apacheconf' },
{ text: 'Bash', value: 'bash' },
{ text: 'C#', value: 'csharp' },
{ text: 'C++', value: 'cpp' },
{ text: 'CSS', value: 'css' }
]
}
}
]
Now its possible to select them in the editor. But they don't work because the embedded PrismJS from the editor only support extend, insertBefore, DFS, markup, xml, html, mathml, svg, css, clike, javascript, js, c, csharp, cs, dotnet, cpp, java, markup-templating, php, python, py, ruby, rb.
So I loaded the missing plugins from a cdn, e.g. the batch plugin. Including it in header.jsp doesn't work because the Prism namespace is not initialized. In the footer.jsp it seems to have no effect, assuming that PrismJS is already initialized.
Customizing the webresource archive
PrismJS seems to be fetched from https://cnx65.internal/connections/resources/web/tiny.editors.connections/render/prism.js so I extracted tiny.editors.connections_4.2.1.1.jar in /opt/IBM/shared/provision/webresources, modified resources/render/prism.js and re-packed those folter:
[centos#cnx65 webresources]$ zip -r tiny.editors.connections_4.2.1.1.jar resources/render/
After restarting Common and Wiki (the application where I'm testing TinyMCE), there is still no syntax highlighting for Bash. Altough when I'm navigating to https://cnx65.internal/connections/resources/web/tiny.editors.connections/render/prism.js, I see the Bash plugin code which I have inserted. To see which languages are avaliable, I append
console.log(Object.keys(Prism.languages))
at the end of the file. This gave me an array containing bash. So the plugin is avaliable, but why doesn't TinyMCE show syntax highlighting?
PrismJS was not the problem: Connections changed the way how they use PrismJS. In the past, they just append the class so that we need to include prisms css/js files in the rendered page (e.g. header/footer.jsp). But it seems that since 6.5.1 (CR1), the TinyMCE editor calls PrismJS when a code block is changed. After pressing save, the editor places the entire parsed highlighted HTML with inline css in its HTML.
As a consequence, it's not enough to reload the rendered page in read mode because it was rendered before the lighlight plugin was added. The highlighting works when we click on edit and make a double click in the code block. Then click save in the code modal and also in the wiki page. Now it works:
Highlight in the editor, too
I found out that resources/render/prism.js is responsible for the readonly view, but not the editor itself. If we only add the plugin there, we get no highlighting in the edit view
To fix this, we need to edit resources/tinymce/tinymce-bundle.min.js inside the TinyMCE archive. Add the plugin JS code in the plugins section. For example, before Prism.languages.csharp=.... Now add the modified file to the archive
[centos#cnx65 webresources]$ sudo zip -r tiny.editors.connections_4.2.1.1.jar resources/tinymce/tinymce-bundle.min.js
and restart common + the application you're using (e.g. Wikis). Now the highlighting works both in the readonly view as well inside the editor:
So I have the following line in my Index and my app works perfectly.
<script src="/sap/bc/ui5_ui5/sap/project/util/moment.js"> </script>
<script src="/sap/bc/ui5_ui5/sap/project/util/moment-timezone-with-data-2010-2020.js"> </script>
But now my application is being called as a Component I need to move this to the Component section. But I'm unsure how to do this. I've tried a few things with no luck.
If I remove this line of code I get the same error in my application when its ran as a standalone as I do when I call it via the component, so I know this is the line of code that is missing. Any help would be appreciated.
There are multiple ways to include an external js library.
Include in the UI5 controller where you use the library.
sap.ui.define([ "sap/ui/core/mvc/Controller",
"<projectNameSpace>/<realtivePathofJSLibrarytoTheComponent>/moment.js"
], function(Controller){
.... Use momnet() here....
}
Include in the Component.js, as in 1. By this "moment" will be available through the app. Though the next option is preferred.
Mention in the manifest.json in your application (in manifest.json --> sap.ui5 --> resources). This option also allows
you to use "moment" throughout your app.
"sap.ui5": {
"resources": {
"js": [{
"uri": "/moment.js"
}]
} }
Use better the "resources" node in your manifest.json files like this:
"resources": {
"js": [ {
"uri": "URI/to/JS/file.js",
"name": "filename.js",
"version": "1.1.1"
}]
}
Or use JQuery.sap.require() in your init event in the Component.js file
jQuery.sap.require('namespace.folder.fileName')
There are two good posts you should read:
https://blogs.sap.com/2017/04/30/how-to-include-third-party-libraries-modules-in-sapui5/
https://blogs.sap.com/2016/10/29/sapui5-application-startup-performance-best-practices/
I've been trying to stop the latest version of Umbraco's tinyMCE editor from automatically stripping any script tags. This was working fine some months ago. Umbraco has not been updated to my knowledge.
I have tried a number of solutions, mostly summed up in this thread: https://our.umbraco.org/forum/using/ui-questions/48866-RTE-not-updating-to-show-new-HTML-tags-in-Umbraco-7
I have edited umbracoSettings.config
<content>
<TidyEditorContent>False</TidyEditorContent>
<errors>...
And have allowed all in validElements in tinyMceConfig.config
<validElements><![CDATA[*[*]]]></validElements>
Finally I changed wed.config in order to force Umbraco to reload.
I still cannot get the script tags to save?
Any suggestions appreciated.
First off, This Is A Very Bad Idea (tm) - don't do it - you'll open it up to all sorts of problems.
The better way to do it is develop a macro that takes a block of text as a parameter, and make that macro useable in the Richtext Edit control.
Your Macro Script can then render the input any way you want, including using script tags (which probably should be part of the macro script). This way you have complete control over what's rendered.
I know this is old but this works on all versions of 7+
To enable javascript to be added to the editor you need to change the following.
You need to replace some of the configs in the config > tinyMceConfig.config file
<![CDATA[+a[id|style|rel|data-id|data-udi|rev|charset|hreflang|dir|lang|tabindex|accesskey|type|name|href|target|title|class|onfocus|onblur|onclick|
ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup],-strong/-b[class|style],-em/-i[class|style],
-strike[class|style],-u[class|style],#p[id|style|dir|class|align],-ol[class|reversed|start|style|type],-ul[class|style],-li[class|style],br[class],
img[id|dir|lang|longdesc|usemap|style|class|src|onmouseover|onmouseout|border|alt=|title|hspace|vspace|width|height|align|umbracoorgwidth|umbracoorgheight|onresize|onresizestart|onresizeend|rel|data-id],
-sub[style|class],-sup[style|class],-blockquote[dir|style|class],-table[border=0|cellspacing|cellpadding|width|height|class|align|summary|style|dir|id|lang|bgcolor|background|bordercolor],
-tr[id|lang|dir|class|rowspan|width|height|align|valign|style|bgcolor|background|bordercolor],tbody[id|class],
thead[id|class],tfoot[id|class],#td[id|lang|dir|class|colspan|rowspan|width|height|align|valign|style|bgcolor|background|bordercolor|scope],
-th[id|lang|dir|class|colspan|rowspan|width|height|align|valign|style|scope],caption[id|lang|dir|class|style],-div[id|dir|class|align|style],
-span[class|align|style],-pre[class|align|style],address[class|align|style],-h1[id|dir|class|align|style],-h2[id|dir|class|align|style],
-h3[id|dir|class|align|style],-h4[id|dir|class|align|style],-h5[id|dir|class|align|style],-h6[id|style|dir|class|align|style],hr[class|style],small[class|style],
dd[id|class|title|style|dir|lang],dl[id|class|title|style|dir|lang],dt[id|class|title|style|dir|lang],object[class|id|width|height|codebase|*],
param[name|value|_value|class],embed[type|width|height|src|class|*],map[name|class],area[shape|coords|href|alt|target|class],bdo[class],button[class],iframe[*],script[language|type|src]]]>
</validElements>
<invalidElements>font</invalidElements>
<!-- this area is for custom config settings that should be added during TinyMCE initialization -->
<customConfig>
<!-- <config key="myKey">mySetting</config>-->
<config key="entity_encoding">raw</config>
<config key="codemirror">
{
"indentOnInit": false,
"path": "../../../../lib/codemirror",
"config": {
},
"jsFiles": [
],
"cssFiles": [
]
}
</config>
<config key="allow_script_urls">true</config>
I am using Sails JS and would like to access globals (sails.config.myGlobals) in my assets, currently in js files.
I would have hoped I there is a similar way like injecting in ejs files. But its not.
Any ideas? Do I have to do a Grunt task for that?
In your config folder create a config file for example MyConfig.js (name doesn't matter). Fill that config with something that you wanted like.
module.exports.myconfig = {
configA: 'this is config A'
}
Use that config in your controller, like.
showconfig: function(req, res){
res.view('viewname', {
config: sails.config.myconfig
});
}
Now in your EJS file that is called, by that example is viewName.ejs at views folder, you can use it like <% config.configA %>, and this is config A would be printed. Also if you want Front End js (in assets folder) able to read that value, just print it in script tag, like this.
<script>
global.configA = '<%= config.configA %>';
</script>
Or if you use front end framework library, it can be placed under some value, service, or factory, not making global variable dirty, so other JS are able to read that value.
I don't think this is possible with Sails.
However, what you can do is setting the variable in a ejs view file to access its value in your js asset file.
// someView.ejs
<script>
myGlobals = '<%= config.myGlobals %>';
</script>
I am using Aloha Editor for my website. I am new to Aloha Edior. I want to add Font Size, Font Family & Text Color plugins to my editor. I got the plugins from this link: http://blog.strouseconsulting.com/2012/06/aloha-plugins/
I am not sure how to use these plugins. Please, if anyone is familiar with Aloha Editor, help me in using these plugins.
Thnks in Advance.
NOTE: I placed the plugin files in the 'plugin' folder of the editor. Like this:
aloha->plugins->fontsize (folder name)
aloha->plugins->fontfamily (folder name)
aloha->plugins->colorselector (folder name)
And also wrote the script code this way:
<script type="text/javascript" src="js/aloha/lib/aloha.js"
data-aloha-plugins="common/ui,common/format,common/highlighteditables,common/link,common/align,common/list,colorselector,fontsize,fontfamily"></script>
I am getting the error in Console Log this way:
Uncaught Error: Script error-
http://requirejs.org/docs/errors.html#scripterror - require.js:1818
If you have added your plugins in the common folder, then your aloha plugin list should read:
<script type="text/javascript" src="js/aloha/lib/aloha.js"
data-aloha-plugins="common/ui,common/format,common/highlighteditables,common/link,common/align,common/list,common/colorselector,common/fontsize,common/fontfamily">
</script>
Then you will need to do some buttons in your aloha-config.js
For example, here is a sample:
(function(window, undefined) {
var Aloha = window.Aloha || (window.Aloha = {});
Aloha.settings = {
toolbar: {
tabs: [
{
label: 'custom',
showOn: {
scope: 'Aloha.continuoustext'
},
components: [['increase', 'decrease','fontfamily']]
},
Check Aloha for a working example of a config file, then you should be able to work out how to have the above sample: http://www.aloha-editor.org/howto-store-data-with-aloha-editor-ajax.php
Once you have created your aloha-config.js file, make sure to include it on your page.